Front end of the Slack clone application.

platform-browser.js 125KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. import { CommonModule, DOCUMENT, PlatformLocation, ɵPLATFORM_BROWSER_ID, ɵparseCookieValue } from '@angular/common';
  7. import { APP_ID, APP_INITIALIZER, ApplicationInitStatus, ApplicationModule, ApplicationRef, ErrorHandler, Inject, Injectable, InjectionToken, Injector, NgModule, NgProbeToken, NgZone, Optional, PLATFORM_ID, PLATFORM_INITIALIZER, RendererFactory2, RendererStyleFlags2, Sanitizer, SecurityContext, SkipSelf, Testability, Version, ViewEncapsulation, createPlatformFactory, getDebugNode, isDevMode, platformCore, setTestabilityGetter, ɵglobal } from '@angular/core';
  8. /**
  9. * @fileoverview added by tsickle
  10. * @suppress {checkTypes} checked by tsc
  11. */
  12. /**
  13. * @license
  14. * Copyright Google Inc. All Rights Reserved.
  15. *
  16. * Use of this source code is governed by an MIT-style license that can be
  17. * found in the LICENSE file at https://angular.io/license
  18. */
  19. let _DOM = /** @type {?} */ ((null));
  20. /**
  21. * @return {?}
  22. */
  23. function getDOM() {
  24. return _DOM;
  25. }
  26. /**
  27. * @param {?} adapter
  28. * @return {?}
  29. */
  30. /**
  31. * @param {?} adapter
  32. * @return {?}
  33. */
  34. function setRootDomAdapter(adapter) {
  35. if (!_DOM) {
  36. _DOM = adapter;
  37. }
  38. }
  39. /**
  40. * Provides DOM operations in an environment-agnostic way.
  41. *
  42. * \@security Tread carefully! Interacting with the DOM directly is dangerous and
  43. * can introduce XSS risks.
  44. * @abstract
  45. */
  46. class DomAdapter {
  47. constructor() {
  48. this.resourceLoaderType = /** @type {?} */ ((null));
  49. }
  50. /**
  51. * Maps attribute names to their corresponding property names for cases
  52. * where attribute name doesn't match property name.
  53. * @return {?}
  54. */
  55. get attrToPropMap() { return this._attrToPropMap; }
  56. /**
  57. * @param {?} value
  58. * @return {?}
  59. */
  60. set attrToPropMap(value) { this._attrToPropMap = value; }
  61. }
  62. /**
  63. * @fileoverview added by tsickle
  64. * @suppress {checkTypes} checked by tsc
  65. */
  66. /**
  67. * @license
  68. * Copyright Google Inc. All Rights Reserved.
  69. *
  70. * Use of this source code is governed by an MIT-style license that can be
  71. * found in the LICENSE file at https://angular.io/license
  72. */
  73. /**
  74. * Provides DOM operations in any browser environment.
  75. *
  76. * \@security Tread carefully! Interacting with the DOM directly is dangerous and
  77. * can introduce XSS risks.
  78. * @abstract
  79. */
  80. class GenericBrowserDomAdapter extends DomAdapter {
  81. constructor() {
  82. super();
  83. this._animationPrefix = null;
  84. this._transitionEnd = null;
  85. try {
  86. const /** @type {?} */ element = this.createElement('div', document);
  87. if (this.getStyle(element, 'animationName') != null) {
  88. this._animationPrefix = '';
  89. }
  90. else {
  91. const /** @type {?} */ domPrefixes = ['Webkit', 'Moz', 'O', 'ms'];
  92. for (let /** @type {?} */ i = 0; i < domPrefixes.length; i++) {
  93. if (this.getStyle(element, domPrefixes[i] + 'AnimationName') != null) {
  94. this._animationPrefix = '-' + domPrefixes[i].toLowerCase() + '-';
  95. break;
  96. }
  97. }
  98. }
  99. const /** @type {?} */ transEndEventNames = {
  100. WebkitTransition: 'webkitTransitionEnd',
  101. MozTransition: 'transitionend',
  102. OTransition: 'oTransitionEnd otransitionend',
  103. transition: 'transitionend'
  104. };
  105. Object.keys(transEndEventNames).forEach((key) => {
  106. if (this.getStyle(element, key) != null) {
  107. this._transitionEnd = transEndEventNames[key];
  108. }
  109. });
  110. }
  111. catch (/** @type {?} */ e) {
  112. this._animationPrefix = null;
  113. this._transitionEnd = null;
  114. }
  115. }
  116. /**
  117. * @param {?} el
  118. * @return {?}
  119. */
  120. getDistributedNodes(el) { return (/** @type {?} */ (el)).getDistributedNodes(); }
  121. /**
  122. * @param {?} el
  123. * @param {?} baseUrl
  124. * @param {?} href
  125. * @return {?}
  126. */
  127. resolveAndSetHref(el, baseUrl, href) {
  128. el.href = href == null ? baseUrl : baseUrl + '/../' + href;
  129. }
  130. /**
  131. * @return {?}
  132. */
  133. supportsDOMEvents() { return true; }
  134. /**
  135. * @return {?}
  136. */
  137. supportsNativeShadowDOM() {
  138. return typeof (/** @type {?} */ (document.body)).createShadowRoot === 'function';
  139. }
  140. /**
  141. * @return {?}
  142. */
  143. getAnimationPrefix() { return this._animationPrefix ? this._animationPrefix : ''; }
  144. /**
  145. * @return {?}
  146. */
  147. getTransitionEnd() { return this._transitionEnd ? this._transitionEnd : ''; }
  148. /**
  149. * @return {?}
  150. */
  151. supportsAnimation() {
  152. return this._animationPrefix != null && this._transitionEnd != null;
  153. }
  154. }
  155. /**
  156. * @fileoverview added by tsickle
  157. * @suppress {checkTypes} checked by tsc
  158. */
  159. /**
  160. * @license
  161. * Copyright Google Inc. All Rights Reserved.
  162. *
  163. * Use of this source code is governed by an MIT-style license that can be
  164. * found in the LICENSE file at https://angular.io/license
  165. */
  166. const _attrToPropMap = {
  167. 'class': 'className',
  168. 'innerHtml': 'innerHTML',
  169. 'readonly': 'readOnly',
  170. 'tabindex': 'tabIndex',
  171. };
  172. const DOM_KEY_LOCATION_NUMPAD = 3;
  173. // Map to convert some key or keyIdentifier values to what will be returned by getEventKey
  174. const _keyMap = {
  175. // The following values are here for cross-browser compatibility and to match the W3C standard
  176. // cf http://www.w3.org/TR/DOM-Level-3-Events-key/
  177. '\b': 'Backspace',
  178. '\t': 'Tab',
  179. '\x7F': 'Delete',
  180. '\x1B': 'Escape',
  181. 'Del': 'Delete',
  182. 'Esc': 'Escape',
  183. 'Left': 'ArrowLeft',
  184. 'Right': 'ArrowRight',
  185. 'Up': 'ArrowUp',
  186. 'Down': 'ArrowDown',
  187. 'Menu': 'ContextMenu',
  188. 'Scroll': 'ScrollLock',
  189. 'Win': 'OS'
  190. };
  191. // There is a bug in Chrome for numeric keypad keys:
  192. // https://code.google.com/p/chromium/issues/detail?id=155654
  193. // 1, 2, 3 ... are reported as A, B, C ...
  194. const _chromeNumKeyPadMap = {
  195. 'A': '1',
  196. 'B': '2',
  197. 'C': '3',
  198. 'D': '4',
  199. 'E': '5',
  200. 'F': '6',
  201. 'G': '7',
  202. 'H': '8',
  203. 'I': '9',
  204. 'J': '*',
  205. 'K': '+',
  206. 'M': '-',
  207. 'N': '.',
  208. 'O': '/',
  209. '\x60': '0',
  210. '\x90': 'NumLock'
  211. };
  212. let nodeContains;
  213. if (ɵglobal['Node']) {
  214. nodeContains = ɵglobal['Node'].prototype.contains || function (node) {
  215. return !!(this.compareDocumentPosition(node) & 16);
  216. };
  217. }
  218. /**
  219. * A `DomAdapter` powered by full browser DOM APIs.
  220. *
  221. * \@security Tread carefully! Interacting with the DOM directly is dangerous and
  222. * can introduce XSS risks.
  223. */
  224. class BrowserDomAdapter extends GenericBrowserDomAdapter {
  225. /**
  226. * @param {?} templateHtml
  227. * @return {?}
  228. */
  229. parse(templateHtml) { throw new Error('parse not implemented'); }
  230. /**
  231. * @return {?}
  232. */
  233. static makeCurrent() { setRootDomAdapter(new BrowserDomAdapter()); }
  234. /**
  235. * @param {?} element
  236. * @param {?} name
  237. * @return {?}
  238. */
  239. hasProperty(element, name) { return name in element; }
  240. /**
  241. * @param {?} el
  242. * @param {?} name
  243. * @param {?} value
  244. * @return {?}
  245. */
  246. setProperty(el, name, value) { (/** @type {?} */ (el))[name] = value; }
  247. /**
  248. * @param {?} el
  249. * @param {?} name
  250. * @return {?}
  251. */
  252. getProperty(el, name) { return (/** @type {?} */ (el))[name]; }
  253. /**
  254. * @param {?} el
  255. * @param {?} methodName
  256. * @param {?} args
  257. * @return {?}
  258. */
  259. invoke(el, methodName, args) { (/** @type {?} */ (el))[methodName](...args); }
  260. /**
  261. * @param {?} error
  262. * @return {?}
  263. */
  264. logError(error) {
  265. if (window.console) {
  266. if (console.error) {
  267. console.error(error);
  268. }
  269. else {
  270. console.log(error);
  271. }
  272. }
  273. }
  274. /**
  275. * @param {?} error
  276. * @return {?}
  277. */
  278. log(error) {
  279. if (window.console) {
  280. window.console.log && window.console.log(error);
  281. }
  282. }
  283. /**
  284. * @param {?} error
  285. * @return {?}
  286. */
  287. logGroup(error) {
  288. if (window.console) {
  289. window.console.group && window.console.group(error);
  290. }
  291. }
  292. /**
  293. * @return {?}
  294. */
  295. logGroupEnd() {
  296. if (window.console) {
  297. window.console.groupEnd && window.console.groupEnd();
  298. }
  299. }
  300. /**
  301. * @return {?}
  302. */
  303. get attrToPropMap() { return _attrToPropMap; }
  304. /**
  305. * @param {?} nodeA
  306. * @param {?} nodeB
  307. * @return {?}
  308. */
  309. contains(nodeA, nodeB) { return nodeContains.call(nodeA, nodeB); }
  310. /**
  311. * @param {?} el
  312. * @param {?} selector
  313. * @return {?}
  314. */
  315. querySelector(el, selector) { return el.querySelector(selector); }
  316. /**
  317. * @param {?} el
  318. * @param {?} selector
  319. * @return {?}
  320. */
  321. querySelectorAll(el, selector) { return el.querySelectorAll(selector); }
  322. /**
  323. * @param {?} el
  324. * @param {?} evt
  325. * @param {?} listener
  326. * @return {?}
  327. */
  328. on(el, evt, listener) { el.addEventListener(evt, listener, false); }
  329. /**
  330. * @param {?} el
  331. * @param {?} evt
  332. * @param {?} listener
  333. * @return {?}
  334. */
  335. onAndCancel(el, evt, listener) {
  336. el.addEventListener(evt, listener, false);
  337. // Needed to follow Dart's subscription semantic, until fix of
  338. // https://code.google.com/p/dart/issues/detail?id=17406
  339. return () => { el.removeEventListener(evt, listener, false); };
  340. }
  341. /**
  342. * @param {?} el
  343. * @param {?} evt
  344. * @return {?}
  345. */
  346. dispatchEvent(el, evt) { el.dispatchEvent(evt); }
  347. /**
  348. * @param {?} eventType
  349. * @return {?}
  350. */
  351. createMouseEvent(eventType) {
  352. const /** @type {?} */ evt = this.getDefaultDocument().createEvent('MouseEvent');
  353. evt.initEvent(eventType, true, true);
  354. return evt;
  355. }
  356. /**
  357. * @param {?} eventType
  358. * @return {?}
  359. */
  360. createEvent(eventType) {
  361. const /** @type {?} */ evt = this.getDefaultDocument().createEvent('Event');
  362. evt.initEvent(eventType, true, true);
  363. return evt;
  364. }
  365. /**
  366. * @param {?} evt
  367. * @return {?}
  368. */
  369. preventDefault(evt) {
  370. evt.preventDefault();
  371. evt.returnValue = false;
  372. }
  373. /**
  374. * @param {?} evt
  375. * @return {?}
  376. */
  377. isPrevented(evt) {
  378. return evt.defaultPrevented || evt.returnValue != null && !evt.returnValue;
  379. }
  380. /**
  381. * @param {?} el
  382. * @return {?}
  383. */
  384. getInnerHTML(el) { return el.innerHTML; }
  385. /**
  386. * @param {?} el
  387. * @return {?}
  388. */
  389. getTemplateContent(el) {
  390. return 'content' in el && this.isTemplateElement(el) ? (/** @type {?} */ (el)).content : null;
  391. }
  392. /**
  393. * @param {?} el
  394. * @return {?}
  395. */
  396. getOuterHTML(el) { return el.outerHTML; }
  397. /**
  398. * @param {?} node
  399. * @return {?}
  400. */
  401. nodeName(node) { return node.nodeName; }
  402. /**
  403. * @param {?} node
  404. * @return {?}
  405. */
  406. nodeValue(node) { return node.nodeValue; }
  407. /**
  408. * @param {?} node
  409. * @return {?}
  410. */
  411. type(node) { return node.type; }
  412. /**
  413. * @param {?} node
  414. * @return {?}
  415. */
  416. content(node) {
  417. if (this.hasProperty(node, 'content')) {
  418. return (/** @type {?} */ (node)).content;
  419. }
  420. else {
  421. return node;
  422. }
  423. }
  424. /**
  425. * @param {?} el
  426. * @return {?}
  427. */
  428. firstChild(el) { return el.firstChild; }
  429. /**
  430. * @param {?} el
  431. * @return {?}
  432. */
  433. nextSibling(el) { return el.nextSibling; }
  434. /**
  435. * @param {?} el
  436. * @return {?}
  437. */
  438. parentElement(el) { return el.parentNode; }
  439. /**
  440. * @param {?} el
  441. * @return {?}
  442. */
  443. childNodes(el) { return el.childNodes; }
  444. /**
  445. * @param {?} el
  446. * @return {?}
  447. */
  448. childNodesAsList(el) {
  449. const /** @type {?} */ childNodes = el.childNodes;
  450. const /** @type {?} */ res = new Array(childNodes.length);
  451. for (let /** @type {?} */ i = 0; i < childNodes.length; i++) {
  452. res[i] = childNodes[i];
  453. }
  454. return res;
  455. }
  456. /**
  457. * @param {?} el
  458. * @return {?}
  459. */
  460. clearNodes(el) {
  461. while (el.firstChild) {
  462. el.removeChild(el.firstChild);
  463. }
  464. }
  465. /**
  466. * @param {?} el
  467. * @param {?} node
  468. * @return {?}
  469. */
  470. appendChild(el, node) { el.appendChild(node); }
  471. /**
  472. * @param {?} el
  473. * @param {?} node
  474. * @return {?}
  475. */
  476. removeChild(el, node) { el.removeChild(node); }
  477. /**
  478. * @param {?} el
  479. * @param {?} newChild
  480. * @param {?} oldChild
  481. * @return {?}
  482. */
  483. replaceChild(el, newChild, oldChild) { el.replaceChild(newChild, oldChild); }
  484. /**
  485. * @param {?} node
  486. * @return {?}
  487. */
  488. remove(node) {
  489. if (node.parentNode) {
  490. node.parentNode.removeChild(node);
  491. }
  492. return node;
  493. }
  494. /**
  495. * @param {?} parent
  496. * @param {?} ref
  497. * @param {?} node
  498. * @return {?}
  499. */
  500. insertBefore(parent, ref, node) { parent.insertBefore(node, ref); }
  501. /**
  502. * @param {?} parent
  503. * @param {?} ref
  504. * @param {?} nodes
  505. * @return {?}
  506. */
  507. insertAllBefore(parent, ref, nodes) {
  508. nodes.forEach((n) => parent.insertBefore(n, ref));
  509. }
  510. /**
  511. * @param {?} parent
  512. * @param {?} ref
  513. * @param {?} node
  514. * @return {?}
  515. */
  516. insertAfter(parent, ref, node) { parent.insertBefore(node, ref.nextSibling); }
  517. /**
  518. * @param {?} el
  519. * @param {?} value
  520. * @return {?}
  521. */
  522. setInnerHTML(el, value) { el.innerHTML = value; }
  523. /**
  524. * @param {?} el
  525. * @return {?}
  526. */
  527. getText(el) { return el.textContent; }
  528. /**
  529. * @param {?} el
  530. * @param {?} value
  531. * @return {?}
  532. */
  533. setText(el, value) { el.textContent = value; }
  534. /**
  535. * @param {?} el
  536. * @return {?}
  537. */
  538. getValue(el) { return el.value; }
  539. /**
  540. * @param {?} el
  541. * @param {?} value
  542. * @return {?}
  543. */
  544. setValue(el, value) { el.value = value; }
  545. /**
  546. * @param {?} el
  547. * @return {?}
  548. */
  549. getChecked(el) { return el.checked; }
  550. /**
  551. * @param {?} el
  552. * @param {?} value
  553. * @return {?}
  554. */
  555. setChecked(el, value) { el.checked = value; }
  556. /**
  557. * @param {?} text
  558. * @return {?}
  559. */
  560. createComment(text) { return this.getDefaultDocument().createComment(text); }
  561. /**
  562. * @param {?} html
  563. * @return {?}
  564. */
  565. createTemplate(html) {
  566. const /** @type {?} */ t = this.getDefaultDocument().createElement('template');
  567. t.innerHTML = html;
  568. return t;
  569. }
  570. /**
  571. * @param {?} tagName
  572. * @param {?=} doc
  573. * @return {?}
  574. */
  575. createElement(tagName, doc) {
  576. doc = doc || this.getDefaultDocument();
  577. return doc.createElement(tagName);
  578. }
  579. /**
  580. * @param {?} ns
  581. * @param {?} tagName
  582. * @param {?=} doc
  583. * @return {?}
  584. */
  585. createElementNS(ns, tagName, doc) {
  586. doc = doc || this.getDefaultDocument();
  587. return doc.createElementNS(ns, tagName);
  588. }
  589. /**
  590. * @param {?} text
  591. * @param {?=} doc
  592. * @return {?}
  593. */
  594. createTextNode(text, doc) {
  595. doc = doc || this.getDefaultDocument();
  596. return doc.createTextNode(text);
  597. }
  598. /**
  599. * @param {?} attrName
  600. * @param {?} attrValue
  601. * @param {?=} doc
  602. * @return {?}
  603. */
  604. createScriptTag(attrName, attrValue, doc) {
  605. doc = doc || this.getDefaultDocument();
  606. const /** @type {?} */ el = /** @type {?} */ (doc.createElement('SCRIPT'));
  607. el.setAttribute(attrName, attrValue);
  608. return el;
  609. }
  610. /**
  611. * @param {?} css
  612. * @param {?=} doc
  613. * @return {?}
  614. */
  615. createStyleElement(css, doc) {
  616. doc = doc || this.getDefaultDocument();
  617. const /** @type {?} */ style = /** @type {?} */ (doc.createElement('style'));
  618. this.appendChild(style, this.createTextNode(css, doc));
  619. return style;
  620. }
  621. /**
  622. * @param {?} el
  623. * @return {?}
  624. */
  625. createShadowRoot(el) { return (/** @type {?} */ (el)).createShadowRoot(); }
  626. /**
  627. * @param {?} el
  628. * @return {?}
  629. */
  630. getShadowRoot(el) { return (/** @type {?} */ (el)).shadowRoot; }
  631. /**
  632. * @param {?} el
  633. * @return {?}
  634. */
  635. getHost(el) { return (/** @type {?} */ (el)).host; }
  636. /**
  637. * @param {?} node
  638. * @return {?}
  639. */
  640. clone(node) { return node.cloneNode(true); }
  641. /**
  642. * @param {?} element
  643. * @param {?} name
  644. * @return {?}
  645. */
  646. getElementsByClassName(element, name) {
  647. return element.getElementsByClassName(name);
  648. }
  649. /**
  650. * @param {?} element
  651. * @param {?} name
  652. * @return {?}
  653. */
  654. getElementsByTagName(element, name) {
  655. return element.getElementsByTagName(name);
  656. }
  657. /**
  658. * @param {?} element
  659. * @return {?}
  660. */
  661. classList(element) { return Array.prototype.slice.call(element.classList, 0); }
  662. /**
  663. * @param {?} element
  664. * @param {?} className
  665. * @return {?}
  666. */
  667. addClass(element, className) { element.classList.add(className); }
  668. /**
  669. * @param {?} element
  670. * @param {?} className
  671. * @return {?}
  672. */
  673. removeClass(element, className) { element.classList.remove(className); }
  674. /**
  675. * @param {?} element
  676. * @param {?} className
  677. * @return {?}
  678. */
  679. hasClass(element, className) {
  680. return element.classList.contains(className);
  681. }
  682. /**
  683. * @param {?} element
  684. * @param {?} styleName
  685. * @param {?} styleValue
  686. * @return {?}
  687. */
  688. setStyle(element, styleName, styleValue) {
  689. element.style[styleName] = styleValue;
  690. }
  691. /**
  692. * @param {?} element
  693. * @param {?} stylename
  694. * @return {?}
  695. */
  696. removeStyle(element, stylename) {
  697. // IE requires '' instead of null
  698. // see https://github.com/angular/angular/issues/7916
  699. element.style[stylename] = '';
  700. }
  701. /**
  702. * @param {?} element
  703. * @param {?} stylename
  704. * @return {?}
  705. */
  706. getStyle(element, stylename) { return element.style[stylename]; }
  707. /**
  708. * @param {?} element
  709. * @param {?} styleName
  710. * @param {?=} styleValue
  711. * @return {?}
  712. */
  713. hasStyle(element, styleName, styleValue) {
  714. const /** @type {?} */ value = this.getStyle(element, styleName) || '';
  715. return styleValue ? value == styleValue : value.length > 0;
  716. }
  717. /**
  718. * @param {?} element
  719. * @return {?}
  720. */
  721. tagName(element) { return element.tagName; }
  722. /**
  723. * @param {?} element
  724. * @return {?}
  725. */
  726. attributeMap(element) {
  727. const /** @type {?} */ res = new Map();
  728. const /** @type {?} */ elAttrs = element.attributes;
  729. for (let /** @type {?} */ i = 0; i < elAttrs.length; i++) {
  730. const /** @type {?} */ attrib = elAttrs.item(i);
  731. res.set(attrib.name, attrib.value);
  732. }
  733. return res;
  734. }
  735. /**
  736. * @param {?} element
  737. * @param {?} attribute
  738. * @return {?}
  739. */
  740. hasAttribute(element, attribute) {
  741. return element.hasAttribute(attribute);
  742. }
  743. /**
  744. * @param {?} element
  745. * @param {?} ns
  746. * @param {?} attribute
  747. * @return {?}
  748. */
  749. hasAttributeNS(element, ns, attribute) {
  750. return element.hasAttributeNS(ns, attribute);
  751. }
  752. /**
  753. * @param {?} element
  754. * @param {?} attribute
  755. * @return {?}
  756. */
  757. getAttribute(element, attribute) {
  758. return element.getAttribute(attribute);
  759. }
  760. /**
  761. * @param {?} element
  762. * @param {?} ns
  763. * @param {?} name
  764. * @return {?}
  765. */
  766. getAttributeNS(element, ns, name) {
  767. return element.getAttributeNS(ns, name);
  768. }
  769. /**
  770. * @param {?} element
  771. * @param {?} name
  772. * @param {?} value
  773. * @return {?}
  774. */
  775. setAttribute(element, name, value) { element.setAttribute(name, value); }
  776. /**
  777. * @param {?} element
  778. * @param {?} ns
  779. * @param {?} name
  780. * @param {?} value
  781. * @return {?}
  782. */
  783. setAttributeNS(element, ns, name, value) {
  784. element.setAttributeNS(ns, name, value);
  785. }
  786. /**
  787. * @param {?} element
  788. * @param {?} attribute
  789. * @return {?}
  790. */
  791. removeAttribute(element, attribute) { element.removeAttribute(attribute); }
  792. /**
  793. * @param {?} element
  794. * @param {?} ns
  795. * @param {?} name
  796. * @return {?}
  797. */
  798. removeAttributeNS(element, ns, name) {
  799. element.removeAttributeNS(ns, name);
  800. }
  801. /**
  802. * @param {?} el
  803. * @return {?}
  804. */
  805. templateAwareRoot(el) { return this.isTemplateElement(el) ? this.content(el) : el; }
  806. /**
  807. * @return {?}
  808. */
  809. createHtmlDocument() {
  810. return document.implementation.createHTMLDocument('fakeTitle');
  811. }
  812. /**
  813. * @return {?}
  814. */
  815. getDefaultDocument() { return document; }
  816. /**
  817. * @param {?} el
  818. * @return {?}
  819. */
  820. getBoundingClientRect(el) {
  821. try {
  822. return el.getBoundingClientRect();
  823. }
  824. catch (/** @type {?} */ e) {
  825. return { top: 0, bottom: 0, left: 0, right: 0, width: 0, height: 0 };
  826. }
  827. }
  828. /**
  829. * @param {?} doc
  830. * @return {?}
  831. */
  832. getTitle(doc) { return doc.title; }
  833. /**
  834. * @param {?} doc
  835. * @param {?} newTitle
  836. * @return {?}
  837. */
  838. setTitle(doc, newTitle) { doc.title = newTitle || ''; }
  839. /**
  840. * @param {?} n
  841. * @param {?} selector
  842. * @return {?}
  843. */
  844. elementMatches(n, selector) {
  845. if (this.isElementNode(n)) {
  846. return n.matches && n.matches(selector) ||
  847. n.msMatchesSelector && n.msMatchesSelector(selector) ||
  848. n.webkitMatchesSelector && n.webkitMatchesSelector(selector);
  849. }
  850. return false;
  851. }
  852. /**
  853. * @param {?} el
  854. * @return {?}
  855. */
  856. isTemplateElement(el) {
  857. return this.isElementNode(el) && el.nodeName === 'TEMPLATE';
  858. }
  859. /**
  860. * @param {?} node
  861. * @return {?}
  862. */
  863. isTextNode(node) { return node.nodeType === Node.TEXT_NODE; }
  864. /**
  865. * @param {?} node
  866. * @return {?}
  867. */
  868. isCommentNode(node) { return node.nodeType === Node.COMMENT_NODE; }
  869. /**
  870. * @param {?} node
  871. * @return {?}
  872. */
  873. isElementNode(node) { return node.nodeType === Node.ELEMENT_NODE; }
  874. /**
  875. * @param {?} node
  876. * @return {?}
  877. */
  878. hasShadowRoot(node) {
  879. return node.shadowRoot != null && node instanceof HTMLElement;
  880. }
  881. /**
  882. * @param {?} node
  883. * @return {?}
  884. */
  885. isShadowRoot(node) { return node instanceof DocumentFragment; }
  886. /**
  887. * @param {?} node
  888. * @return {?}
  889. */
  890. importIntoDoc(node) { return document.importNode(this.templateAwareRoot(node), true); }
  891. /**
  892. * @param {?} node
  893. * @return {?}
  894. */
  895. adoptNode(node) { return document.adoptNode(node); }
  896. /**
  897. * @param {?} el
  898. * @return {?}
  899. */
  900. getHref(el) { return /** @type {?} */ ((el.getAttribute('href'))); }
  901. /**
  902. * @param {?} event
  903. * @return {?}
  904. */
  905. getEventKey(event) {
  906. let /** @type {?} */ key = event.key;
  907. if (key == null) {
  908. key = event.keyIdentifier;
  909. // keyIdentifier is defined in the old draft of DOM Level 3 Events implemented by Chrome and
  910. // Safari cf
  911. // http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/events.html#Events-KeyboardEvents-Interfaces
  912. if (key == null) {
  913. return 'Unidentified';
  914. }
  915. if (key.startsWith('U+')) {
  916. key = String.fromCharCode(parseInt(key.substring(2), 16));
  917. if (event.location === DOM_KEY_LOCATION_NUMPAD && _chromeNumKeyPadMap.hasOwnProperty(key)) {
  918. // There is a bug in Chrome for numeric keypad keys:
  919. // https://code.google.com/p/chromium/issues/detail?id=155654
  920. // 1, 2, 3 ... are reported as A, B, C ...
  921. key = (/** @type {?} */ (_chromeNumKeyPadMap))[key];
  922. }
  923. }
  924. }
  925. return _keyMap[key] || key;
  926. }
  927. /**
  928. * @param {?} doc
  929. * @param {?} target
  930. * @return {?}
  931. */
  932. getGlobalEventTarget(doc, target) {
  933. if (target === 'window') {
  934. return window;
  935. }
  936. if (target === 'document') {
  937. return doc;
  938. }
  939. if (target === 'body') {
  940. return doc.body;
  941. }
  942. return null;
  943. }
  944. /**
  945. * @return {?}
  946. */
  947. getHistory() { return window.history; }
  948. /**
  949. * @return {?}
  950. */
  951. getLocation() { return window.location; }
  952. /**
  953. * @param {?} doc
  954. * @return {?}
  955. */
  956. getBaseHref(doc) {
  957. const /** @type {?} */ href = getBaseElementHref();
  958. return href == null ? null : relativePath(href);
  959. }
  960. /**
  961. * @return {?}
  962. */
  963. resetBaseElement() { baseElement = null; }
  964. /**
  965. * @return {?}
  966. */
  967. getUserAgent() { return window.navigator.userAgent; }
  968. /**
  969. * @param {?} element
  970. * @param {?} name
  971. * @param {?} value
  972. * @return {?}
  973. */
  974. setData(element, name, value) {
  975. this.setAttribute(element, 'data-' + name, value);
  976. }
  977. /**
  978. * @param {?} element
  979. * @param {?} name
  980. * @return {?}
  981. */
  982. getData(element, name) {
  983. return this.getAttribute(element, 'data-' + name);
  984. }
  985. /**
  986. * @param {?} element
  987. * @return {?}
  988. */
  989. getComputedStyle(element) { return getComputedStyle(element); }
  990. /**
  991. * @return {?}
  992. */
  993. supportsWebAnimation() {
  994. return typeof (/** @type {?} */ (Element)).prototype['animate'] === 'function';
  995. }
  996. /**
  997. * @return {?}
  998. */
  999. performanceNow() {
  1000. // performance.now() is not available in all browsers, see
  1001. // http://caniuse.com/#search=performance.now
  1002. return window.performance && window.performance.now ? window.performance.now() :
  1003. new Date().getTime();
  1004. }
  1005. /**
  1006. * @return {?}
  1007. */
  1008. supportsCookies() { return true; }
  1009. /**
  1010. * @param {?} name
  1011. * @return {?}
  1012. */
  1013. getCookie(name) { return ɵparseCookieValue(document.cookie, name); }
  1014. /**
  1015. * @param {?} name
  1016. * @param {?} value
  1017. * @return {?}
  1018. */
  1019. setCookie(name, value) {
  1020. // document.cookie is magical, assigning into it assigns/overrides one cookie value, but does
  1021. // not clear other cookies.
  1022. document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);
  1023. }
  1024. }
  1025. let baseElement = null;
  1026. /**
  1027. * @return {?}
  1028. */
  1029. function getBaseElementHref() {
  1030. if (!baseElement) {
  1031. baseElement = /** @type {?} */ ((document.querySelector('base')));
  1032. if (!baseElement) {
  1033. return null;
  1034. }
  1035. }
  1036. return baseElement.getAttribute('href');
  1037. }
  1038. // based on urlUtils.js in AngularJS 1
  1039. let urlParsingNode;
  1040. /**
  1041. * @param {?} url
  1042. * @return {?}
  1043. */
  1044. function relativePath(url) {
  1045. if (!urlParsingNode) {
  1046. urlParsingNode = document.createElement('a');
  1047. }
  1048. urlParsingNode.setAttribute('href', url);
  1049. return (urlParsingNode.pathname.charAt(0) === '/') ? urlParsingNode.pathname :
  1050. '/' + urlParsingNode.pathname;
  1051. }
  1052. /**
  1053. * @fileoverview added by tsickle
  1054. * @suppress {checkTypes} checked by tsc
  1055. */
  1056. /**
  1057. * @license
  1058. * Copyright Google Inc. All Rights Reserved.
  1059. *
  1060. * Use of this source code is governed by an MIT-style license that can be
  1061. * found in the LICENSE file at https://angular.io/license
  1062. */
  1063. /**
  1064. * A DI Token representing the main rendering context. In a browser this is the DOM Document.
  1065. *
  1066. * Note: Document might not be available in the Application Context when Application and Rendering
  1067. * Contexts are not the same (e.g. when running the application into a Web Worker).
  1068. *
  1069. * @deprecated import from `\@angular/common` instead.
  1070. */
  1071. const DOCUMENT$1 = DOCUMENT;
  1072. /**
  1073. * @fileoverview added by tsickle
  1074. * @suppress {checkTypes} checked by tsc
  1075. */
  1076. /**
  1077. * @license
  1078. * Copyright Google Inc. All Rights Reserved.
  1079. *
  1080. * Use of this source code is governed by an MIT-style license that can be
  1081. * found in the LICENSE file at https://angular.io/license
  1082. */
  1083. /**
  1084. * @return {?}
  1085. */
  1086. function supportsState() {
  1087. return !!window.history.pushState;
  1088. }
  1089. /**
  1090. * @fileoverview added by tsickle
  1091. * @suppress {checkTypes} checked by tsc
  1092. */
  1093. /**
  1094. * @license
  1095. * Copyright Google Inc. All Rights Reserved.
  1096. *
  1097. * Use of this source code is governed by an MIT-style license that can be
  1098. * found in the LICENSE file at https://angular.io/license
  1099. */
  1100. /**
  1101. * `PlatformLocation` encapsulates all of the direct calls to platform APIs.
  1102. * This class should not be used directly by an application developer. Instead, use
  1103. * {\@link Location}.
  1104. */
  1105. class BrowserPlatformLocation extends PlatformLocation {
  1106. /**
  1107. * @param {?} _doc
  1108. */
  1109. constructor(_doc) {
  1110. super();
  1111. this._doc = _doc;
  1112. this._init();
  1113. }
  1114. /**
  1115. * \@internal
  1116. * @return {?}
  1117. */
  1118. _init() {
  1119. (/** @type {?} */ (this)).location = getDOM().getLocation();
  1120. this._history = getDOM().getHistory();
  1121. }
  1122. /**
  1123. * @return {?}
  1124. */
  1125. getBaseHrefFromDOM() { return /** @type {?} */ ((getDOM().getBaseHref(this._doc))); }
  1126. /**
  1127. * @param {?} fn
  1128. * @return {?}
  1129. */
  1130. onPopState(fn) {
  1131. getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('popstate', fn, false);
  1132. }
  1133. /**
  1134. * @param {?} fn
  1135. * @return {?}
  1136. */
  1137. onHashChange(fn) {
  1138. getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('hashchange', fn, false);
  1139. }
  1140. /**
  1141. * @return {?}
  1142. */
  1143. get pathname() { return this.location.pathname; }
  1144. /**
  1145. * @return {?}
  1146. */
  1147. get search() { return this.location.search; }
  1148. /**
  1149. * @return {?}
  1150. */
  1151. get hash() { return this.location.hash; }
  1152. /**
  1153. * @param {?} newPath
  1154. * @return {?}
  1155. */
  1156. set pathname(newPath) { this.location.pathname = newPath; }
  1157. /**
  1158. * @param {?} state
  1159. * @param {?} title
  1160. * @param {?} url
  1161. * @return {?}
  1162. */
  1163. pushState(state, title, url) {
  1164. if (supportsState()) {
  1165. this._history.pushState(state, title, url);
  1166. }
  1167. else {
  1168. this.location.hash = url;
  1169. }
  1170. }
  1171. /**
  1172. * @param {?} state
  1173. * @param {?} title
  1174. * @param {?} url
  1175. * @return {?}
  1176. */
  1177. replaceState(state, title, url) {
  1178. if (supportsState()) {
  1179. this._history.replaceState(state, title, url);
  1180. }
  1181. else {
  1182. this.location.hash = url;
  1183. }
  1184. }
  1185. /**
  1186. * @return {?}
  1187. */
  1188. forward() { this._history.forward(); }
  1189. /**
  1190. * @return {?}
  1191. */
  1192. back() { this._history.back(); }
  1193. }
  1194. BrowserPlatformLocation.decorators = [
  1195. { type: Injectable },
  1196. ];
  1197. /** @nocollapse */
  1198. BrowserPlatformLocation.ctorParameters = () => [
  1199. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT$1,] },] },
  1200. ];
  1201. /**
  1202. * @fileoverview added by tsickle
  1203. * @suppress {checkTypes} checked by tsc
  1204. */
  1205. /**
  1206. * @license
  1207. * Copyright Google Inc. All Rights Reserved.
  1208. *
  1209. * Use of this source code is governed by an MIT-style license that can be
  1210. * found in the LICENSE file at https://angular.io/license
  1211. */
  1212. /**
  1213. * A service that can be used to get and add meta tags.
  1214. *
  1215. * \@experimental
  1216. */
  1217. class Meta {
  1218. /**
  1219. * @param {?} _doc
  1220. */
  1221. constructor(_doc) {
  1222. this._doc = _doc;
  1223. this._dom = getDOM();
  1224. }
  1225. /**
  1226. * @param {?} tag
  1227. * @param {?=} forceCreation
  1228. * @return {?}
  1229. */
  1230. addTag(tag, forceCreation = false) {
  1231. if (!tag)
  1232. return null;
  1233. return this._getOrCreateElement(tag, forceCreation);
  1234. }
  1235. /**
  1236. * @param {?} tags
  1237. * @param {?=} forceCreation
  1238. * @return {?}
  1239. */
  1240. addTags(tags, forceCreation = false) {
  1241. if (!tags)
  1242. return [];
  1243. return tags.reduce((result, tag) => {
  1244. if (tag) {
  1245. result.push(this._getOrCreateElement(tag, forceCreation));
  1246. }
  1247. return result;
  1248. }, []);
  1249. }
  1250. /**
  1251. * @param {?} attrSelector
  1252. * @return {?}
  1253. */
  1254. getTag(attrSelector) {
  1255. if (!attrSelector)
  1256. return null;
  1257. return this._dom.querySelector(this._doc, `meta[${attrSelector}]`) || null;
  1258. }
  1259. /**
  1260. * @param {?} attrSelector
  1261. * @return {?}
  1262. */
  1263. getTags(attrSelector) {
  1264. if (!attrSelector)
  1265. return [];
  1266. const /** @type {?} */ list = this._dom.querySelectorAll(this._doc, `meta[${attrSelector}]`);
  1267. return list ? [].slice.call(list) : [];
  1268. }
  1269. /**
  1270. * @param {?} tag
  1271. * @param {?=} selector
  1272. * @return {?}
  1273. */
  1274. updateTag(tag, selector) {
  1275. if (!tag)
  1276. return null;
  1277. selector = selector || this._parseSelector(tag);
  1278. const /** @type {?} */ meta = /** @type {?} */ ((this.getTag(selector)));
  1279. if (meta) {
  1280. return this._setMetaElementAttributes(tag, meta);
  1281. }
  1282. return this._getOrCreateElement(tag, true);
  1283. }
  1284. /**
  1285. * @param {?} attrSelector
  1286. * @return {?}
  1287. */
  1288. removeTag(attrSelector) { this.removeTagElement(/** @type {?} */ ((this.getTag(attrSelector)))); }
  1289. /**
  1290. * @param {?} meta
  1291. * @return {?}
  1292. */
  1293. removeTagElement(meta) {
  1294. if (meta) {
  1295. this._dom.remove(meta);
  1296. }
  1297. }
  1298. /**
  1299. * @param {?} meta
  1300. * @param {?=} forceCreation
  1301. * @return {?}
  1302. */
  1303. _getOrCreateElement(meta, forceCreation = false) {
  1304. if (!forceCreation) {
  1305. const /** @type {?} */ selector = this._parseSelector(meta);
  1306. const /** @type {?} */ elem = /** @type {?} */ ((this.getTag(selector)));
  1307. // It's allowed to have multiple elements with the same name so it's not enough to
  1308. // just check that element with the same name already present on the page. We also need to
  1309. // check if element has tag attributes
  1310. if (elem && this._containsAttributes(meta, elem))
  1311. return elem;
  1312. }
  1313. const /** @type {?} */ element = /** @type {?} */ (this._dom.createElement('meta'));
  1314. this._setMetaElementAttributes(meta, element);
  1315. const /** @type {?} */ head = this._dom.getElementsByTagName(this._doc, 'head')[0];
  1316. this._dom.appendChild(head, element);
  1317. return element;
  1318. }
  1319. /**
  1320. * @param {?} tag
  1321. * @param {?} el
  1322. * @return {?}
  1323. */
  1324. _setMetaElementAttributes(tag, el) {
  1325. Object.keys(tag).forEach((prop) => this._dom.setAttribute(el, prop, tag[prop]));
  1326. return el;
  1327. }
  1328. /**
  1329. * @param {?} tag
  1330. * @return {?}
  1331. */
  1332. _parseSelector(tag) {
  1333. const /** @type {?} */ attr = tag.name ? 'name' : 'property';
  1334. return `${attr}="${tag[attr]}"`;
  1335. }
  1336. /**
  1337. * @param {?} tag
  1338. * @param {?} elem
  1339. * @return {?}
  1340. */
  1341. _containsAttributes(tag, elem) {
  1342. return Object.keys(tag).every((key) => this._dom.getAttribute(elem, key) === tag[key]);
  1343. }
  1344. }
  1345. Meta.decorators = [
  1346. { type: Injectable },
  1347. ];
  1348. /** @nocollapse */
  1349. Meta.ctorParameters = () => [
  1350. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT$1,] },] },
  1351. ];
  1352. /**
  1353. * @fileoverview added by tsickle
  1354. * @suppress {checkTypes} checked by tsc
  1355. */
  1356. /**
  1357. * @license
  1358. * Copyright Google Inc. All Rights Reserved.
  1359. *
  1360. * Use of this source code is governed by an MIT-style license that can be
  1361. * found in the LICENSE file at https://angular.io/license
  1362. */
  1363. /**
  1364. * An id that identifies a particular application being bootstrapped, that should
  1365. * match across the client/server boundary.
  1366. */
  1367. const TRANSITION_ID = new InjectionToken('TRANSITION_ID');
  1368. /**
  1369. * @param {?} transitionId
  1370. * @param {?} document
  1371. * @param {?} injector
  1372. * @return {?}
  1373. */
  1374. function appInitializerFactory(transitionId, document, injector) {
  1375. return () => {
  1376. // Wait for all application initializers to be completed before removing the styles set by
  1377. // the server.
  1378. injector.get(ApplicationInitStatus).donePromise.then(() => {
  1379. const /** @type {?} */ dom = getDOM();
  1380. const /** @type {?} */ styles = Array.prototype.slice.apply(dom.querySelectorAll(document, `style[ng-transition]`));
  1381. styles.filter(el => dom.getAttribute(el, 'ng-transition') === transitionId)
  1382. .forEach(el => dom.remove(el));
  1383. });
  1384. };
  1385. }
  1386. const SERVER_TRANSITION_PROVIDERS = [
  1387. {
  1388. provide: APP_INITIALIZER,
  1389. useFactory: appInitializerFactory,
  1390. deps: [TRANSITION_ID, DOCUMENT$1, Injector],
  1391. multi: true
  1392. },
  1393. ];
  1394. /**
  1395. * @fileoverview added by tsickle
  1396. * @suppress {checkTypes} checked by tsc
  1397. */
  1398. /**
  1399. * @license
  1400. * Copyright Google Inc. All Rights Reserved.
  1401. *
  1402. * Use of this source code is governed by an MIT-style license that can be
  1403. * found in the LICENSE file at https://angular.io/license
  1404. */
  1405. class BrowserGetTestability {
  1406. /**
  1407. * @return {?}
  1408. */
  1409. static init() { setTestabilityGetter(new BrowserGetTestability()); }
  1410. /**
  1411. * @param {?} registry
  1412. * @return {?}
  1413. */
  1414. addToWindow(registry) {
  1415. ɵglobal['getAngularTestability'] = (elem, findInAncestors = true) => {
  1416. const /** @type {?} */ testability = registry.findTestabilityInTree(elem, findInAncestors);
  1417. if (testability == null) {
  1418. throw new Error('Could not find testability for element.');
  1419. }
  1420. return testability;
  1421. };
  1422. ɵglobal['getAllAngularTestabilities'] = () => registry.getAllTestabilities();
  1423. ɵglobal['getAllAngularRootElements'] = () => registry.getAllRootElements();
  1424. const /** @type {?} */ whenAllStable = (callback /** TODO #9100 */) => {
  1425. const /** @type {?} */ testabilities = ɵglobal['getAllAngularTestabilities']();
  1426. let /** @type {?} */ count = testabilities.length;
  1427. let /** @type {?} */ didWork = false;
  1428. const /** @type {?} */ decrement = function (didWork_ /** TODO #9100 */) {
  1429. didWork = didWork || didWork_;
  1430. count--;
  1431. if (count == 0) {
  1432. callback(didWork);
  1433. }
  1434. };
  1435. testabilities.forEach(function (testability /** TODO #9100 */) {
  1436. testability.whenStable(decrement);
  1437. });
  1438. };
  1439. if (!ɵglobal['frameworkStabilizers']) {
  1440. ɵglobal['frameworkStabilizers'] = [];
  1441. }
  1442. ɵglobal['frameworkStabilizers'].push(whenAllStable);
  1443. }
  1444. /**
  1445. * @param {?} registry
  1446. * @param {?} elem
  1447. * @param {?} findInAncestors
  1448. * @return {?}
  1449. */
  1450. findTestabilityInTree(registry, elem, findInAncestors) {
  1451. if (elem == null) {
  1452. return null;
  1453. }
  1454. const /** @type {?} */ t = registry.getTestability(elem);
  1455. if (t != null) {
  1456. return t;
  1457. }
  1458. else if (!findInAncestors) {
  1459. return null;
  1460. }
  1461. if (getDOM().isShadowRoot(elem)) {
  1462. return this.findTestabilityInTree(registry, getDOM().getHost(elem), true);
  1463. }
  1464. return this.findTestabilityInTree(registry, getDOM().parentElement(elem), true);
  1465. }
  1466. }
  1467. /**
  1468. * @fileoverview added by tsickle
  1469. * @suppress {checkTypes} checked by tsc
  1470. */
  1471. /**
  1472. * @license
  1473. * Copyright Google Inc. All Rights Reserved.
  1474. *
  1475. * Use of this source code is governed by an MIT-style license that can be
  1476. * found in the LICENSE file at https://angular.io/license
  1477. */
  1478. /**
  1479. * A service that can be used to get and set the title of a current HTML document.
  1480. *
  1481. * Since an Angular application can't be bootstrapped on the entire HTML document (`<html>` tag)
  1482. * it is not possible to bind to the `text` property of the `HTMLTitleElement` elements
  1483. * (representing the `<title>` tag). Instead, this service can be used to set and get the current
  1484. * title value.
  1485. *
  1486. * \@experimental
  1487. */
  1488. class Title {
  1489. /**
  1490. * @param {?} _doc
  1491. */
  1492. constructor(_doc) {
  1493. this._doc = _doc;
  1494. }
  1495. /**
  1496. * Get the title of the current HTML document.
  1497. * @return {?}
  1498. */
  1499. getTitle() { return getDOM().getTitle(this._doc); }
  1500. /**
  1501. * Set the title of the current HTML document.
  1502. * @param {?} newTitle
  1503. * @return {?}
  1504. */
  1505. setTitle(newTitle) { getDOM().setTitle(this._doc, newTitle); }
  1506. }
  1507. Title.decorators = [
  1508. { type: Injectable },
  1509. ];
  1510. /** @nocollapse */
  1511. Title.ctorParameters = () => [
  1512. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT$1,] },] },
  1513. ];
  1514. /**
  1515. * @fileoverview added by tsickle
  1516. * @suppress {checkTypes} checked by tsc
  1517. */
  1518. /**
  1519. * @license
  1520. * Copyright Google Inc. All Rights Reserved.
  1521. *
  1522. * Use of this source code is governed by an MIT-style license that can be
  1523. * found in the LICENSE file at https://angular.io/license
  1524. */
  1525. /**
  1526. * @param {?} input
  1527. * @return {?}
  1528. */
  1529. /**
  1530. * @param {?} input
  1531. * @return {?}
  1532. */
  1533. /**
  1534. * Exports the value under a given `name` in the global property `ng`. For example `ng.probe` if
  1535. * `name` is `'probe'`.
  1536. * @param {?} name Name under which it will be exported. Keep in mind this will be a property of the
  1537. * global `ng` object.
  1538. * @param {?} value The value to export.
  1539. * @return {?}
  1540. */
  1541. function exportNgVar(name, value) {
  1542. if (typeof COMPILED === 'undefined' || !COMPILED) {
  1543. // Note: we can't export `ng` when using closure enhanced optimization as:
  1544. // - closure declares globals itself for minified names, which sometimes clobber our `ng` global
  1545. // - we can't declare a closure extern as the namespace `ng` is already used within Google
  1546. // for typings for angularJS (via `goog.provide('ng....')`).
  1547. const /** @type {?} */ ng = ɵglobal['ng'] = (/** @type {?} */ (ɵglobal['ng'])) || {};
  1548. ng[name] = value;
  1549. }
  1550. }
  1551. /**
  1552. * @fileoverview added by tsickle
  1553. * @suppress {checkTypes} checked by tsc
  1554. */
  1555. /**
  1556. * @license
  1557. * Copyright Google Inc. All Rights Reserved.
  1558. *
  1559. * Use of this source code is governed by an MIT-style license that can be
  1560. * found in the LICENSE file at https://angular.io/license
  1561. */
  1562. const CORE_TOKENS = {
  1563. 'ApplicationRef': ApplicationRef,
  1564. 'NgZone': NgZone,
  1565. };
  1566. const INSPECT_GLOBAL_NAME = 'probe';
  1567. const CORE_TOKENS_GLOBAL_NAME = 'coreTokens';
  1568. /**
  1569. * Returns a {\@link DebugElement} for the given native DOM element, or
  1570. * null if the given native element does not have an Angular view associated
  1571. * with it.
  1572. * @param {?} element
  1573. * @return {?}
  1574. */
  1575. function inspectNativeElement(element) {
  1576. return getDebugNode(element);
  1577. }
  1578. /**
  1579. * @param {?} coreTokens
  1580. * @return {?}
  1581. */
  1582. function _createNgProbe(coreTokens) {
  1583. exportNgVar(INSPECT_GLOBAL_NAME, inspectNativeElement);
  1584. exportNgVar(CORE_TOKENS_GLOBAL_NAME, Object.assign({}, CORE_TOKENS, _ngProbeTokensToMap(coreTokens || [])));
  1585. return () => inspectNativeElement;
  1586. }
  1587. /**
  1588. * @param {?} tokens
  1589. * @return {?}
  1590. */
  1591. function _ngProbeTokensToMap(tokens) {
  1592. return tokens.reduce((prev, t) => (prev[t.name] = t.token, prev), {});
  1593. }
  1594. /**
  1595. * Providers which support debugging Angular applications (e.g. via `ng.probe`).
  1596. */
  1597. const ELEMENT_PROBE_PROVIDERS = [
  1598. {
  1599. provide: APP_INITIALIZER,
  1600. useFactory: _createNgProbe,
  1601. deps: [
  1602. [NgProbeToken, new Optional()],
  1603. ],
  1604. multi: true,
  1605. },
  1606. ];
  1607. /**
  1608. * @fileoverview added by tsickle
  1609. * @suppress {checkTypes} checked by tsc
  1610. */
  1611. /**
  1612. * @license
  1613. * Copyright Google Inc. All Rights Reserved.
  1614. *
  1615. * Use of this source code is governed by an MIT-style license that can be
  1616. * found in the LICENSE file at https://angular.io/license
  1617. */
  1618. /**
  1619. * \@stable
  1620. */
  1621. const EVENT_MANAGER_PLUGINS = new InjectionToken('EventManagerPlugins');
  1622. /**
  1623. * \@stable
  1624. */
  1625. class EventManager {
  1626. /**
  1627. * @param {?} plugins
  1628. * @param {?} _zone
  1629. */
  1630. constructor(plugins, _zone) {
  1631. this._zone = _zone;
  1632. this._eventNameToPlugin = new Map();
  1633. plugins.forEach(p => p.manager = this);
  1634. this._plugins = plugins.slice().reverse();
  1635. }
  1636. /**
  1637. * @param {?} element
  1638. * @param {?} eventName
  1639. * @param {?} handler
  1640. * @return {?}
  1641. */
  1642. addEventListener(element, eventName, handler) {
  1643. const /** @type {?} */ plugin = this._findPluginFor(eventName);
  1644. return plugin.addEventListener(element, eventName, handler);
  1645. }
  1646. /**
  1647. * @param {?} target
  1648. * @param {?} eventName
  1649. * @param {?} handler
  1650. * @return {?}
  1651. */
  1652. addGlobalEventListener(target, eventName, handler) {
  1653. const /** @type {?} */ plugin = this._findPluginFor(eventName);
  1654. return plugin.addGlobalEventListener(target, eventName, handler);
  1655. }
  1656. /**
  1657. * @return {?}
  1658. */
  1659. getZone() { return this._zone; }
  1660. /**
  1661. * \@internal
  1662. * @param {?} eventName
  1663. * @return {?}
  1664. */
  1665. _findPluginFor(eventName) {
  1666. const /** @type {?} */ plugin = this._eventNameToPlugin.get(eventName);
  1667. if (plugin) {
  1668. return plugin;
  1669. }
  1670. const /** @type {?} */ plugins = this._plugins;
  1671. for (let /** @type {?} */ i = 0; i < plugins.length; i++) {
  1672. const /** @type {?} */ plugin = plugins[i];
  1673. if (plugin.supports(eventName)) {
  1674. this._eventNameToPlugin.set(eventName, plugin);
  1675. return plugin;
  1676. }
  1677. }
  1678. throw new Error(`No event manager plugin found for event ${eventName}`);
  1679. }
  1680. }
  1681. EventManager.decorators = [
  1682. { type: Injectable },
  1683. ];
  1684. /** @nocollapse */
  1685. EventManager.ctorParameters = () => [
  1686. { type: Array, decorators: [{ type: Inject, args: [EVENT_MANAGER_PLUGINS,] },] },
  1687. { type: NgZone, },
  1688. ];
  1689. /**
  1690. * @abstract
  1691. */
  1692. class EventManagerPlugin {
  1693. /**
  1694. * @param {?} _doc
  1695. */
  1696. constructor(_doc) {
  1697. this._doc = _doc;
  1698. }
  1699. /**
  1700. * @param {?} element
  1701. * @param {?} eventName
  1702. * @param {?} handler
  1703. * @return {?}
  1704. */
  1705. addGlobalEventListener(element, eventName, handler) {
  1706. const /** @type {?} */ target = getDOM().getGlobalEventTarget(this._doc, element);
  1707. if (!target) {
  1708. throw new Error(`Unsupported event target ${target} for event ${eventName}`);
  1709. }
  1710. return this.addEventListener(target, eventName, handler);
  1711. }
  1712. }
  1713. /**
  1714. * @fileoverview added by tsickle
  1715. * @suppress {checkTypes} checked by tsc
  1716. */
  1717. /**
  1718. * @license
  1719. * Copyright Google Inc. All Rights Reserved.
  1720. *
  1721. * Use of this source code is governed by an MIT-style license that can be
  1722. * found in the LICENSE file at https://angular.io/license
  1723. */
  1724. class SharedStylesHost {
  1725. constructor() {
  1726. /**
  1727. * \@internal
  1728. */
  1729. this._stylesSet = new Set();
  1730. }
  1731. /**
  1732. * @param {?} styles
  1733. * @return {?}
  1734. */
  1735. addStyles(styles) {
  1736. const /** @type {?} */ additions = new Set();
  1737. styles.forEach(style => {
  1738. if (!this._stylesSet.has(style)) {
  1739. this._stylesSet.add(style);
  1740. additions.add(style);
  1741. }
  1742. });
  1743. this.onStylesAdded(additions);
  1744. }
  1745. /**
  1746. * @param {?} additions
  1747. * @return {?}
  1748. */
  1749. onStylesAdded(additions) { }
  1750. /**
  1751. * @return {?}
  1752. */
  1753. getAllStyles() { return Array.from(this._stylesSet); }
  1754. }
  1755. SharedStylesHost.decorators = [
  1756. { type: Injectable },
  1757. ];
  1758. /** @nocollapse */
  1759. SharedStylesHost.ctorParameters = () => [];
  1760. class DomSharedStylesHost extends SharedStylesHost {
  1761. /**
  1762. * @param {?} _doc
  1763. */
  1764. constructor(_doc) {
  1765. super();
  1766. this._doc = _doc;
  1767. this._hostNodes = new Set();
  1768. this._styleNodes = new Set();
  1769. this._hostNodes.add(_doc.head);
  1770. }
  1771. /**
  1772. * @param {?} styles
  1773. * @param {?} host
  1774. * @return {?}
  1775. */
  1776. _addStylesToHost(styles, host) {
  1777. styles.forEach((style) => {
  1778. const /** @type {?} */ styleEl = this._doc.createElement('style');
  1779. styleEl.textContent = style;
  1780. this._styleNodes.add(host.appendChild(styleEl));
  1781. });
  1782. }
  1783. /**
  1784. * @param {?} hostNode
  1785. * @return {?}
  1786. */
  1787. addHost(hostNode) {
  1788. this._addStylesToHost(this._stylesSet, hostNode);
  1789. this._hostNodes.add(hostNode);
  1790. }
  1791. /**
  1792. * @param {?} hostNode
  1793. * @return {?}
  1794. */
  1795. removeHost(hostNode) { this._hostNodes.delete(hostNode); }
  1796. /**
  1797. * @param {?} additions
  1798. * @return {?}
  1799. */
  1800. onStylesAdded(additions) {
  1801. this._hostNodes.forEach(hostNode => this._addStylesToHost(additions, hostNode));
  1802. }
  1803. /**
  1804. * @return {?}
  1805. */
  1806. ngOnDestroy() { this._styleNodes.forEach(styleNode => getDOM().remove(styleNode)); }
  1807. }
  1808. DomSharedStylesHost.decorators = [
  1809. { type: Injectable },
  1810. ];
  1811. /** @nocollapse */
  1812. DomSharedStylesHost.ctorParameters = () => [
  1813. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT$1,] },] },
  1814. ];
  1815. /**
  1816. * @fileoverview added by tsickle
  1817. * @suppress {checkTypes} checked by tsc
  1818. */
  1819. /**
  1820. * @license
  1821. * Copyright Google Inc. All Rights Reserved.
  1822. *
  1823. * Use of this source code is governed by an MIT-style license that can be
  1824. * found in the LICENSE file at https://angular.io/license
  1825. */
  1826. const NAMESPACE_URIS = {
  1827. 'svg': 'http://www.w3.org/2000/svg',
  1828. 'xhtml': 'http://www.w3.org/1999/xhtml',
  1829. 'xlink': 'http://www.w3.org/1999/xlink',
  1830. 'xml': 'http://www.w3.org/XML/1998/namespace',
  1831. 'xmlns': 'http://www.w3.org/2000/xmlns/',
  1832. };
  1833. const COMPONENT_REGEX = /%COMP%/g;
  1834. const COMPONENT_VARIABLE = '%COMP%';
  1835. const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`;
  1836. const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`;
  1837. /**
  1838. * @param {?} componentShortId
  1839. * @return {?}
  1840. */
  1841. function shimContentAttribute(componentShortId) {
  1842. return CONTENT_ATTR.replace(COMPONENT_REGEX, componentShortId);
  1843. }
  1844. /**
  1845. * @param {?} componentShortId
  1846. * @return {?}
  1847. */
  1848. function shimHostAttribute(componentShortId) {
  1849. return HOST_ATTR.replace(COMPONENT_REGEX, componentShortId);
  1850. }
  1851. /**
  1852. * @param {?} compId
  1853. * @param {?} styles
  1854. * @param {?} target
  1855. * @return {?}
  1856. */
  1857. function flattenStyles(compId, styles, target) {
  1858. for (let /** @type {?} */ i = 0; i < styles.length; i++) {
  1859. let /** @type {?} */ style = styles[i];
  1860. if (Array.isArray(style)) {
  1861. flattenStyles(compId, style, target);
  1862. }
  1863. else {
  1864. style = style.replace(COMPONENT_REGEX, compId);
  1865. target.push(style);
  1866. }
  1867. }
  1868. return target;
  1869. }
  1870. /**
  1871. * @param {?} eventHandler
  1872. * @return {?}
  1873. */
  1874. function decoratePreventDefault(eventHandler) {
  1875. return (event) => {
  1876. const /** @type {?} */ allowDefaultBehavior = eventHandler(event);
  1877. if (allowDefaultBehavior === false) {
  1878. // TODO(tbosch): move preventDefault into event plugins...
  1879. event.preventDefault();
  1880. event.returnValue = false;
  1881. }
  1882. };
  1883. }
  1884. class DomRendererFactory2 {
  1885. /**
  1886. * @param {?} eventManager
  1887. * @param {?} sharedStylesHost
  1888. */
  1889. constructor(eventManager, sharedStylesHost) {
  1890. this.eventManager = eventManager;
  1891. this.sharedStylesHost = sharedStylesHost;
  1892. this.rendererByCompId = new Map();
  1893. this.defaultRenderer = new DefaultDomRenderer2(eventManager);
  1894. }
  1895. /**
  1896. * @param {?} element
  1897. * @param {?} type
  1898. * @return {?}
  1899. */
  1900. createRenderer(element, type) {
  1901. if (!element || !type) {
  1902. return this.defaultRenderer;
  1903. }
  1904. switch (type.encapsulation) {
  1905. case ViewEncapsulation.Emulated: {
  1906. let /** @type {?} */ renderer = this.rendererByCompId.get(type.id);
  1907. if (!renderer) {
  1908. renderer =
  1909. new EmulatedEncapsulationDomRenderer2(this.eventManager, this.sharedStylesHost, type);
  1910. this.rendererByCompId.set(type.id, renderer);
  1911. }
  1912. (/** @type {?} */ (renderer)).applyToHost(element);
  1913. return renderer;
  1914. }
  1915. case ViewEncapsulation.Native:
  1916. return new ShadowDomRenderer(this.eventManager, this.sharedStylesHost, element, type);
  1917. default: {
  1918. if (!this.rendererByCompId.has(type.id)) {
  1919. const /** @type {?} */ styles = flattenStyles(type.id, type.styles, []);
  1920. this.sharedStylesHost.addStyles(styles);
  1921. this.rendererByCompId.set(type.id, this.defaultRenderer);
  1922. }
  1923. return this.defaultRenderer;
  1924. }
  1925. }
  1926. }
  1927. /**
  1928. * @return {?}
  1929. */
  1930. begin() { }
  1931. /**
  1932. * @return {?}
  1933. */
  1934. end() { }
  1935. }
  1936. DomRendererFactory2.decorators = [
  1937. { type: Injectable },
  1938. ];
  1939. /** @nocollapse */
  1940. DomRendererFactory2.ctorParameters = () => [
  1941. { type: EventManager, },
  1942. { type: DomSharedStylesHost, },
  1943. ];
  1944. class DefaultDomRenderer2 {
  1945. /**
  1946. * @param {?} eventManager
  1947. */
  1948. constructor(eventManager) {
  1949. this.eventManager = eventManager;
  1950. this.data = Object.create(null);
  1951. }
  1952. /**
  1953. * @return {?}
  1954. */
  1955. destroy() { }
  1956. /**
  1957. * @param {?} name
  1958. * @param {?=} namespace
  1959. * @return {?}
  1960. */
  1961. createElement(name, namespace) {
  1962. if (namespace) {
  1963. return document.createElementNS(NAMESPACE_URIS[namespace], name);
  1964. }
  1965. return document.createElement(name);
  1966. }
  1967. /**
  1968. * @param {?} value
  1969. * @return {?}
  1970. */
  1971. createComment(value) { return document.createComment(value); }
  1972. /**
  1973. * @param {?} value
  1974. * @return {?}
  1975. */
  1976. createText(value) { return document.createTextNode(value); }
  1977. /**
  1978. * @param {?} parent
  1979. * @param {?} newChild
  1980. * @return {?}
  1981. */
  1982. appendChild(parent, newChild) { parent.appendChild(newChild); }
  1983. /**
  1984. * @param {?} parent
  1985. * @param {?} newChild
  1986. * @param {?} refChild
  1987. * @return {?}
  1988. */
  1989. insertBefore(parent, newChild, refChild) {
  1990. if (parent) {
  1991. parent.insertBefore(newChild, refChild);
  1992. }
  1993. }
  1994. /**
  1995. * @param {?} parent
  1996. * @param {?} oldChild
  1997. * @return {?}
  1998. */
  1999. removeChild(parent, oldChild) {
  2000. if (parent) {
  2001. parent.removeChild(oldChild);
  2002. }
  2003. }
  2004. /**
  2005. * @param {?} selectorOrNode
  2006. * @return {?}
  2007. */
  2008. selectRootElement(selectorOrNode) {
  2009. let /** @type {?} */ el = typeof selectorOrNode === 'string' ? document.querySelector(selectorOrNode) :
  2010. selectorOrNode;
  2011. if (!el) {
  2012. throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
  2013. }
  2014. el.textContent = '';
  2015. return el;
  2016. }
  2017. /**
  2018. * @param {?} node
  2019. * @return {?}
  2020. */
  2021. parentNode(node) { return node.parentNode; }
  2022. /**
  2023. * @param {?} node
  2024. * @return {?}
  2025. */
  2026. nextSibling(node) { return node.nextSibling; }
  2027. /**
  2028. * @param {?} el
  2029. * @param {?} name
  2030. * @param {?} value
  2031. * @param {?=} namespace
  2032. * @return {?}
  2033. */
  2034. setAttribute(el, name, value, namespace) {
  2035. if (namespace) {
  2036. name = `${namespace}:${name}`;
  2037. const /** @type {?} */ namespaceUri = NAMESPACE_URIS[namespace];
  2038. if (namespaceUri) {
  2039. el.setAttributeNS(namespaceUri, name, value);
  2040. }
  2041. else {
  2042. el.setAttribute(name, value);
  2043. }
  2044. }
  2045. else {
  2046. el.setAttribute(name, value);
  2047. }
  2048. }
  2049. /**
  2050. * @param {?} el
  2051. * @param {?} name
  2052. * @param {?=} namespace
  2053. * @return {?}
  2054. */
  2055. removeAttribute(el, name, namespace) {
  2056. if (namespace) {
  2057. const /** @type {?} */ namespaceUri = NAMESPACE_URIS[namespace];
  2058. if (namespaceUri) {
  2059. el.removeAttributeNS(namespaceUri, name);
  2060. }
  2061. else {
  2062. el.removeAttribute(`${namespace}:${name}`);
  2063. }
  2064. }
  2065. else {
  2066. el.removeAttribute(name);
  2067. }
  2068. }
  2069. /**
  2070. * @param {?} el
  2071. * @param {?} name
  2072. * @return {?}
  2073. */
  2074. addClass(el, name) { el.classList.add(name); }
  2075. /**
  2076. * @param {?} el
  2077. * @param {?} name
  2078. * @return {?}
  2079. */
  2080. removeClass(el, name) { el.classList.remove(name); }
  2081. /**
  2082. * @param {?} el
  2083. * @param {?} style
  2084. * @param {?} value
  2085. * @param {?} flags
  2086. * @return {?}
  2087. */
  2088. setStyle(el, style, value, flags) {
  2089. if (flags & RendererStyleFlags2.DashCase) {
  2090. el.style.setProperty(style, value, !!(flags & RendererStyleFlags2.Important) ? 'important' : '');
  2091. }
  2092. else {
  2093. el.style[style] = value;
  2094. }
  2095. }
  2096. /**
  2097. * @param {?} el
  2098. * @param {?} style
  2099. * @param {?} flags
  2100. * @return {?}
  2101. */
  2102. removeStyle(el, style, flags) {
  2103. if (flags & RendererStyleFlags2.DashCase) {
  2104. el.style.removeProperty(style);
  2105. }
  2106. else {
  2107. // IE requires '' instead of null
  2108. // see https://github.com/angular/angular/issues/7916
  2109. el.style[style] = '';
  2110. }
  2111. }
  2112. /**
  2113. * @param {?} el
  2114. * @param {?} name
  2115. * @param {?} value
  2116. * @return {?}
  2117. */
  2118. setProperty(el, name, value) {
  2119. checkNoSyntheticProp(name, 'property');
  2120. el[name] = value;
  2121. }
  2122. /**
  2123. * @param {?} node
  2124. * @param {?} value
  2125. * @return {?}
  2126. */
  2127. setValue(node, value) { node.nodeValue = value; }
  2128. /**
  2129. * @param {?} target
  2130. * @param {?} event
  2131. * @param {?} callback
  2132. * @return {?}
  2133. */
  2134. listen(target, event, callback) {
  2135. checkNoSyntheticProp(event, 'listener');
  2136. if (typeof target === 'string') {
  2137. return /** @type {?} */ (this.eventManager.addGlobalEventListener(target, event, decoratePreventDefault(callback)));
  2138. }
  2139. return /** @type {?} */ ((this.eventManager.addEventListener(target, event, decoratePreventDefault(callback))));
  2140. }
  2141. }
  2142. const AT_CHARCODE = '@'.charCodeAt(0);
  2143. /**
  2144. * @param {?} name
  2145. * @param {?} nameKind
  2146. * @return {?}
  2147. */
  2148. function checkNoSyntheticProp(name, nameKind) {
  2149. if (name.charCodeAt(0) === AT_CHARCODE) {
  2150. throw new Error(`Found the synthetic ${nameKind} ${name}. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application.`);
  2151. }
  2152. }
  2153. class EmulatedEncapsulationDomRenderer2 extends DefaultDomRenderer2 {
  2154. /**
  2155. * @param {?} eventManager
  2156. * @param {?} sharedStylesHost
  2157. * @param {?} component
  2158. */
  2159. constructor(eventManager, sharedStylesHost, component) {
  2160. super(eventManager);
  2161. this.component = component;
  2162. const /** @type {?} */ styles = flattenStyles(component.id, component.styles, []);
  2163. sharedStylesHost.addStyles(styles);
  2164. this.contentAttr = shimContentAttribute(component.id);
  2165. this.hostAttr = shimHostAttribute(component.id);
  2166. }
  2167. /**
  2168. * @param {?} element
  2169. * @return {?}
  2170. */
  2171. applyToHost(element) { super.setAttribute(element, this.hostAttr, ''); }
  2172. /**
  2173. * @param {?} parent
  2174. * @param {?} name
  2175. * @return {?}
  2176. */
  2177. createElement(parent, name) {
  2178. const /** @type {?} */ el = super.createElement(parent, name);
  2179. super.setAttribute(el, this.contentAttr, '');
  2180. return el;
  2181. }
  2182. }
  2183. class ShadowDomRenderer extends DefaultDomRenderer2 {
  2184. /**
  2185. * @param {?} eventManager
  2186. * @param {?} sharedStylesHost
  2187. * @param {?} hostEl
  2188. * @param {?} component
  2189. */
  2190. constructor(eventManager, sharedStylesHost, hostEl, component) {
  2191. super(eventManager);
  2192. this.sharedStylesHost = sharedStylesHost;
  2193. this.hostEl = hostEl;
  2194. this.component = component;
  2195. this.shadowRoot = (/** @type {?} */ (hostEl)).createShadowRoot();
  2196. this.sharedStylesHost.addHost(this.shadowRoot);
  2197. const /** @type {?} */ styles = flattenStyles(component.id, component.styles, []);
  2198. for (let /** @type {?} */ i = 0; i < styles.length; i++) {
  2199. const /** @type {?} */ styleEl = document.createElement('style');
  2200. styleEl.textContent = styles[i];
  2201. this.shadowRoot.appendChild(styleEl);
  2202. }
  2203. }
  2204. /**
  2205. * @param {?} node
  2206. * @return {?}
  2207. */
  2208. nodeOrShadowRoot(node) { return node === this.hostEl ? this.shadowRoot : node; }
  2209. /**
  2210. * @return {?}
  2211. */
  2212. destroy() { this.sharedStylesHost.removeHost(this.shadowRoot); }
  2213. /**
  2214. * @param {?} parent
  2215. * @param {?} newChild
  2216. * @return {?}
  2217. */
  2218. appendChild(parent, newChild) {
  2219. return super.appendChild(this.nodeOrShadowRoot(parent), newChild);
  2220. }
  2221. /**
  2222. * @param {?} parent
  2223. * @param {?} newChild
  2224. * @param {?} refChild
  2225. * @return {?}
  2226. */
  2227. insertBefore(parent, newChild, refChild) {
  2228. return super.insertBefore(this.nodeOrShadowRoot(parent), newChild, refChild);
  2229. }
  2230. /**
  2231. * @param {?} parent
  2232. * @param {?} oldChild
  2233. * @return {?}
  2234. */
  2235. removeChild(parent, oldChild) {
  2236. return super.removeChild(this.nodeOrShadowRoot(parent), oldChild);
  2237. }
  2238. /**
  2239. * @param {?} node
  2240. * @return {?}
  2241. */
  2242. parentNode(node) {
  2243. return this.nodeOrShadowRoot(super.parentNode(this.nodeOrShadowRoot(node)));
  2244. }
  2245. }
  2246. /**
  2247. * @fileoverview added by tsickle
  2248. * @suppress {checkTypes} checked by tsc
  2249. */
  2250. /**
  2251. * @license
  2252. * Copyright Google Inc. All Rights Reserved.
  2253. *
  2254. * Use of this source code is governed by an MIT-style license that can be
  2255. * found in the LICENSE file at https://angular.io/license
  2256. */
  2257. const ɵ0 = function (v) {
  2258. return '__zone_symbol__' + v;
  2259. };
  2260. /**
  2261. * Detect if Zone is present. If it is then use simple zone aware 'addEventListener'
  2262. * since Angular can do much more
  2263. * efficient bookkeeping than Zone can, because we have additional information. This speeds up
  2264. * addEventListener by 3x.
  2265. */
  2266. const __symbol__ = (typeof Zone !== 'undefined') && (/** @type {?} */ (Zone))['__symbol__'] || ɵ0;
  2267. const ADD_EVENT_LISTENER = __symbol__('addEventListener');
  2268. const REMOVE_EVENT_LISTENER = __symbol__('removeEventListener');
  2269. const symbolNames = {};
  2270. const FALSE = 'FALSE';
  2271. const ANGULAR = 'ANGULAR';
  2272. const NATIVE_ADD_LISTENER = 'addEventListener';
  2273. const NATIVE_REMOVE_LISTENER = 'removeEventListener';
  2274. // use the same symbol string which is used in zone.js
  2275. const stopSymbol = '__zone_symbol__propagationStopped';
  2276. const stopMethodSymbol = '__zone_symbol__stopImmediatePropagation';
  2277. const blackListedEvents = (typeof Zone !== 'undefined') && (/** @type {?} */ (Zone))[__symbol__('BLACK_LISTED_EVENTS')];
  2278. let blackListedMap;
  2279. if (blackListedEvents) {
  2280. blackListedMap = {};
  2281. blackListedEvents.forEach(eventName => { blackListedMap[eventName] = eventName; });
  2282. }
  2283. const isBlackListedEvent = function (eventName) {
  2284. if (!blackListedMap) {
  2285. return false;
  2286. }
  2287. return blackListedMap.hasOwnProperty(eventName);
  2288. };
  2289. // a global listener to handle all dom event,
  2290. // so we do not need to create a closure everytime
  2291. const globalListener = function (event) {
  2292. const /** @type {?} */ symbolName = symbolNames[event.type];
  2293. if (!symbolName) {
  2294. return;
  2295. }
  2296. const /** @type {?} */ taskDatas = this[symbolName];
  2297. if (!taskDatas) {
  2298. return;
  2299. }
  2300. const /** @type {?} */ args = [event];
  2301. if (taskDatas.length === 1) {
  2302. // if taskDatas only have one element, just invoke it
  2303. const /** @type {?} */ taskData = taskDatas[0];
  2304. if (taskData.zone !== Zone.current) {
  2305. // only use Zone.run when Zone.current not equals to stored zone
  2306. return taskData.zone.run(taskData.handler, this, args);
  2307. }
  2308. else {
  2309. return taskData.handler.apply(this, args);
  2310. }
  2311. }
  2312. else {
  2313. // copy tasks as a snapshot to avoid event handlers remove
  2314. // itself or others
  2315. const /** @type {?} */ copiedTasks = taskDatas.slice();
  2316. for (let /** @type {?} */ i = 0; i < copiedTasks.length; i++) {
  2317. // if other listener call event.stopImmediatePropagation
  2318. // just break
  2319. if ((/** @type {?} */ (event))[stopSymbol] === true) {
  2320. break;
  2321. }
  2322. const /** @type {?} */ taskData = copiedTasks[i];
  2323. if (taskData.zone !== Zone.current) {
  2324. // only use Zone.run when Zone.current not equals to stored zone
  2325. taskData.zone.run(taskData.handler, this, args);
  2326. }
  2327. else {
  2328. taskData.handler.apply(this, args);
  2329. }
  2330. }
  2331. }
  2332. };
  2333. class DomEventsPlugin extends EventManagerPlugin {
  2334. /**
  2335. * @param {?} doc
  2336. * @param {?} ngZone
  2337. */
  2338. constructor(doc, ngZone) {
  2339. super(doc);
  2340. this.ngZone = ngZone;
  2341. this.patchEvent();
  2342. }
  2343. /**
  2344. * @return {?}
  2345. */
  2346. patchEvent() {
  2347. if (!Event || !Event.prototype) {
  2348. return;
  2349. }
  2350. if ((/** @type {?} */ (Event.prototype))[stopMethodSymbol]) {
  2351. // already patched by zone.js
  2352. return;
  2353. }
  2354. const /** @type {?} */ delegate = (/** @type {?} */ (Event.prototype))[stopMethodSymbol] =
  2355. Event.prototype.stopImmediatePropagation;
  2356. Event.prototype.stopImmediatePropagation = function () {
  2357. if (this) {
  2358. this[stopSymbol] = true;
  2359. }
  2360. // should call native delegate in case
  2361. // in some enviroment part of the application
  2362. // will not use the patched Event
  2363. delegate && delegate.apply(this, arguments);
  2364. };
  2365. }
  2366. /**
  2367. * @param {?} eventName
  2368. * @return {?}
  2369. */
  2370. supports(eventName) { return true; }
  2371. /**
  2372. * @param {?} element
  2373. * @param {?} eventName
  2374. * @param {?} handler
  2375. * @return {?}
  2376. */
  2377. addEventListener(element, eventName, handler) {
  2378. /**
  2379. * This code is about to add a listener to the DOM. If Zone.js is present, than
  2380. * `addEventListener` has been patched. The patched code adds overhead in both
  2381. * memory and speed (3x slower) than native. For this reason if we detect that
  2382. * Zone.js is present we use a simple version of zone aware addEventListener instead.
  2383. * The result is faster registration and the zone will be restored.
  2384. * But ZoneSpec.onScheduleTask, ZoneSpec.onInvokeTask, ZoneSpec.onCancelTask
  2385. * will not be invoked
  2386. * We also do manual zone restoration in element.ts renderEventHandlerClosure method.
  2387. *
  2388. * NOTE: it is possible that the element is from different iframe, and so we
  2389. * have to check before we execute the method.
  2390. */
  2391. const /** @type {?} */ self = this;
  2392. const /** @type {?} */ zoneJsLoaded = element[ADD_EVENT_LISTENER];
  2393. let /** @type {?} */ callback = /** @type {?} */ (handler);
  2394. // if zonejs is loaded and current zone is not ngZone
  2395. // we keep Zone.current on target for later restoration.
  2396. if (zoneJsLoaded && (!NgZone.isInAngularZone() || isBlackListedEvent(eventName))) {
  2397. let /** @type {?} */ symbolName = symbolNames[eventName];
  2398. if (!symbolName) {
  2399. symbolName = symbolNames[eventName] = __symbol__(ANGULAR + eventName + FALSE);
  2400. }
  2401. let /** @type {?} */ taskDatas = (/** @type {?} */ (element))[symbolName];
  2402. const /** @type {?} */ globalListenerRegistered = taskDatas && taskDatas.length > 0;
  2403. if (!taskDatas) {
  2404. taskDatas = (/** @type {?} */ (element))[symbolName] = [];
  2405. }
  2406. const /** @type {?} */ zone = isBlackListedEvent(eventName) ? Zone.root : Zone.current;
  2407. if (taskDatas.length === 0) {
  2408. taskDatas.push({ zone: zone, handler: callback });
  2409. }
  2410. else {
  2411. let /** @type {?} */ callbackRegistered = false;
  2412. for (let /** @type {?} */ i = 0; i < taskDatas.length; i++) {
  2413. if (taskDatas[i].handler === callback) {
  2414. callbackRegistered = true;
  2415. break;
  2416. }
  2417. }
  2418. if (!callbackRegistered) {
  2419. taskDatas.push({ zone: zone, handler: callback });
  2420. }
  2421. }
  2422. if (!globalListenerRegistered) {
  2423. element[ADD_EVENT_LISTENER](eventName, globalListener, false);
  2424. }
  2425. }
  2426. else {
  2427. element[NATIVE_ADD_LISTENER](eventName, callback, false);
  2428. }
  2429. return () => this.removeEventListener(element, eventName, callback);
  2430. }
  2431. /**
  2432. * @param {?} target
  2433. * @param {?} eventName
  2434. * @param {?} callback
  2435. * @return {?}
  2436. */
  2437. removeEventListener(target, eventName, callback) {
  2438. let /** @type {?} */ underlyingRemove = target[REMOVE_EVENT_LISTENER];
  2439. // zone.js not loaded, use native removeEventListener
  2440. if (!underlyingRemove) {
  2441. return target[NATIVE_REMOVE_LISTENER].apply(target, [eventName, callback, false]);
  2442. }
  2443. let /** @type {?} */ symbolName = symbolNames[eventName];
  2444. let /** @type {?} */ taskDatas = symbolName && target[symbolName];
  2445. if (!taskDatas) {
  2446. // addEventListener not using patched version
  2447. // just call native removeEventListener
  2448. return target[NATIVE_REMOVE_LISTENER].apply(target, [eventName, callback, false]);
  2449. }
  2450. // fix issue 20532, should be able to remove
  2451. // listener which was added inside of ngZone
  2452. let /** @type {?} */ found = false;
  2453. for (let /** @type {?} */ i = 0; i < taskDatas.length; i++) {
  2454. // remove listener from taskDatas if the callback equals
  2455. if (taskDatas[i].handler === callback) {
  2456. found = true;
  2457. taskDatas.splice(i, 1);
  2458. break;
  2459. }
  2460. }
  2461. if (found) {
  2462. if (taskDatas.length === 0) {
  2463. // all listeners are removed, we can remove the globalListener from target
  2464. underlyingRemove.apply(target, [eventName, globalListener, false]);
  2465. }
  2466. }
  2467. else {
  2468. // not found in taskDatas, the callback may be added inside of ngZone
  2469. // use native remove listener to remove the calback
  2470. target[NATIVE_REMOVE_LISTENER].apply(target, [eventName, callback, false]);
  2471. }
  2472. }
  2473. }
  2474. DomEventsPlugin.decorators = [
  2475. { type: Injectable },
  2476. ];
  2477. /** @nocollapse */
  2478. DomEventsPlugin.ctorParameters = () => [
  2479. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT$1,] },] },
  2480. { type: NgZone, },
  2481. ];
  2482. /**
  2483. * @fileoverview added by tsickle
  2484. * @suppress {checkTypes} checked by tsc
  2485. */
  2486. /**
  2487. * @license
  2488. * Copyright Google Inc. All Rights Reserved.
  2489. *
  2490. * Use of this source code is governed by an MIT-style license that can be
  2491. * found in the LICENSE file at https://angular.io/license
  2492. */
  2493. const EVENT_NAMES = {
  2494. // pan
  2495. 'pan': true,
  2496. 'panstart': true,
  2497. 'panmove': true,
  2498. 'panend': true,
  2499. 'pancancel': true,
  2500. 'panleft': true,
  2501. 'panright': true,
  2502. 'panup': true,
  2503. 'pandown': true,
  2504. // pinch
  2505. 'pinch': true,
  2506. 'pinchstart': true,
  2507. 'pinchmove': true,
  2508. 'pinchend': true,
  2509. 'pinchcancel': true,
  2510. 'pinchin': true,
  2511. 'pinchout': true,
  2512. // press
  2513. 'press': true,
  2514. 'pressup': true,
  2515. // rotate
  2516. 'rotate': true,
  2517. 'rotatestart': true,
  2518. 'rotatemove': true,
  2519. 'rotateend': true,
  2520. 'rotatecancel': true,
  2521. // swipe
  2522. 'swipe': true,
  2523. 'swipeleft': true,
  2524. 'swiperight': true,
  2525. 'swipeup': true,
  2526. 'swipedown': true,
  2527. // tap
  2528. 'tap': true,
  2529. };
  2530. /**
  2531. * A DI token that you can use to provide{\@link HammerGestureConfig} to Angular. Use it to configure
  2532. * Hammer gestures.
  2533. *
  2534. * \@experimental
  2535. */
  2536. const HAMMER_GESTURE_CONFIG = new InjectionToken('HammerGestureConfig');
  2537. /**
  2538. * @record
  2539. */
  2540. /**
  2541. * \@experimental
  2542. */
  2543. class HammerGestureConfig {
  2544. constructor() {
  2545. this.events = [];
  2546. this.overrides = {};
  2547. }
  2548. /**
  2549. * @param {?} element
  2550. * @return {?}
  2551. */
  2552. buildHammer(element) {
  2553. const /** @type {?} */ mc = new Hammer(element);
  2554. mc.get('pinch').set({ enable: true });
  2555. mc.get('rotate').set({ enable: true });
  2556. for (const /** @type {?} */ eventName in this.overrides) {
  2557. mc.get(eventName).set(this.overrides[eventName]);
  2558. }
  2559. return mc;
  2560. }
  2561. }
  2562. HammerGestureConfig.decorators = [
  2563. { type: Injectable },
  2564. ];
  2565. /** @nocollapse */
  2566. HammerGestureConfig.ctorParameters = () => [];
  2567. class HammerGesturesPlugin extends EventManagerPlugin {
  2568. /**
  2569. * @param {?} doc
  2570. * @param {?} _config
  2571. */
  2572. constructor(doc, _config) {
  2573. super(doc);
  2574. this._config = _config;
  2575. }
  2576. /**
  2577. * @param {?} eventName
  2578. * @return {?}
  2579. */
  2580. supports(eventName) {
  2581. if (!EVENT_NAMES.hasOwnProperty(eventName.toLowerCase()) && !this.isCustomEvent(eventName)) {
  2582. return false;
  2583. }
  2584. if (!(/** @type {?} */ (window)).Hammer) {
  2585. throw new Error(`Hammer.js is not loaded, can not bind ${eventName} event`);
  2586. }
  2587. return true;
  2588. }
  2589. /**
  2590. * @param {?} element
  2591. * @param {?} eventName
  2592. * @param {?} handler
  2593. * @return {?}
  2594. */
  2595. addEventListener(element, eventName, handler) {
  2596. const /** @type {?} */ zone = this.manager.getZone();
  2597. eventName = eventName.toLowerCase();
  2598. return zone.runOutsideAngular(() => {
  2599. // Creating the manager bind events, must be done outside of angular
  2600. const /** @type {?} */ mc = this._config.buildHammer(element);
  2601. const /** @type {?} */ callback = function (eventObj) {
  2602. zone.runGuarded(function () { handler(eventObj); });
  2603. };
  2604. mc.on(eventName, callback);
  2605. return () => mc.off(eventName, callback);
  2606. });
  2607. }
  2608. /**
  2609. * @param {?} eventName
  2610. * @return {?}
  2611. */
  2612. isCustomEvent(eventName) { return this._config.events.indexOf(eventName) > -1; }
  2613. }
  2614. HammerGesturesPlugin.decorators = [
  2615. { type: Injectable },
  2616. ];
  2617. /** @nocollapse */
  2618. HammerGesturesPlugin.ctorParameters = () => [
  2619. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT$1,] },] },
  2620. { type: HammerGestureConfig, decorators: [{ type: Inject, args: [HAMMER_GESTURE_CONFIG,] },] },
  2621. ];
  2622. /**
  2623. * @fileoverview added by tsickle
  2624. * @suppress {checkTypes} checked by tsc
  2625. */
  2626. /**
  2627. * @license
  2628. * Copyright Google Inc. All Rights Reserved.
  2629. *
  2630. * Use of this source code is governed by an MIT-style license that can be
  2631. * found in the LICENSE file at https://angular.io/license
  2632. */
  2633. const MODIFIER_KEYS = ['alt', 'control', 'meta', 'shift'];
  2634. const ɵ0$1 = (event) => event.altKey;
  2635. const ɵ1$1 = (event) => event.ctrlKey;
  2636. const ɵ2$1 = (event) => event.metaKey;
  2637. const ɵ3 = (event) => event.shiftKey;
  2638. const MODIFIER_KEY_GETTERS = {
  2639. 'alt': ɵ0$1,
  2640. 'control': ɵ1$1,
  2641. 'meta': ɵ2$1,
  2642. 'shift': ɵ3
  2643. };
  2644. /**
  2645. * \@experimental
  2646. */
  2647. class KeyEventsPlugin extends EventManagerPlugin {
  2648. /**
  2649. * @param {?} doc
  2650. */
  2651. constructor(doc) { super(doc); }
  2652. /**
  2653. * @param {?} eventName
  2654. * @return {?}
  2655. */
  2656. supports(eventName) { return KeyEventsPlugin.parseEventName(eventName) != null; }
  2657. /**
  2658. * @param {?} element
  2659. * @param {?} eventName
  2660. * @param {?} handler
  2661. * @return {?}
  2662. */
  2663. addEventListener(element, eventName, handler) {
  2664. const /** @type {?} */ parsedEvent = /** @type {?} */ ((KeyEventsPlugin.parseEventName(eventName)));
  2665. const /** @type {?} */ outsideHandler = KeyEventsPlugin.eventCallback(parsedEvent['fullKey'], handler, this.manager.getZone());
  2666. return this.manager.getZone().runOutsideAngular(() => {
  2667. return getDOM().onAndCancel(element, parsedEvent['domEventName'], outsideHandler);
  2668. });
  2669. }
  2670. /**
  2671. * @param {?} eventName
  2672. * @return {?}
  2673. */
  2674. static parseEventName(eventName) {
  2675. const /** @type {?} */ parts = eventName.toLowerCase().split('.');
  2676. const /** @type {?} */ domEventName = parts.shift();
  2677. if ((parts.length === 0) || !(domEventName === 'keydown' || domEventName === 'keyup')) {
  2678. return null;
  2679. }
  2680. const /** @type {?} */ key = KeyEventsPlugin._normalizeKey(/** @type {?} */ ((parts.pop())));
  2681. let /** @type {?} */ fullKey = '';
  2682. MODIFIER_KEYS.forEach(modifierName => {
  2683. const /** @type {?} */ index = parts.indexOf(modifierName);
  2684. if (index > -1) {
  2685. parts.splice(index, 1);
  2686. fullKey += modifierName + '.';
  2687. }
  2688. });
  2689. fullKey += key;
  2690. if (parts.length != 0 || key.length === 0) {
  2691. // returning null instead of throwing to let another plugin process the event
  2692. return null;
  2693. }
  2694. const /** @type {?} */ result = {};
  2695. result['domEventName'] = domEventName;
  2696. result['fullKey'] = fullKey;
  2697. return result;
  2698. }
  2699. /**
  2700. * @param {?} event
  2701. * @return {?}
  2702. */
  2703. static getEventFullKey(event) {
  2704. let /** @type {?} */ fullKey = '';
  2705. let /** @type {?} */ key = getDOM().getEventKey(event);
  2706. key = key.toLowerCase();
  2707. if (key === ' ') {
  2708. key = 'space'; // for readability
  2709. }
  2710. else if (key === '.') {
  2711. key = 'dot'; // because '.' is used as a separator in event names
  2712. }
  2713. MODIFIER_KEYS.forEach(modifierName => {
  2714. if (modifierName != key) {
  2715. const /** @type {?} */ modifierGetter = MODIFIER_KEY_GETTERS[modifierName];
  2716. if (modifierGetter(event)) {
  2717. fullKey += modifierName + '.';
  2718. }
  2719. }
  2720. });
  2721. fullKey += key;
  2722. return fullKey;
  2723. }
  2724. /**
  2725. * @param {?} fullKey
  2726. * @param {?} handler
  2727. * @param {?} zone
  2728. * @return {?}
  2729. */
  2730. static eventCallback(fullKey, handler, zone) {
  2731. return (event /** TODO #9100 */) => {
  2732. if (KeyEventsPlugin.getEventFullKey(event) === fullKey) {
  2733. zone.runGuarded(() => handler(event));
  2734. }
  2735. };
  2736. }
  2737. /**
  2738. * \@internal
  2739. * @param {?} keyName
  2740. * @return {?}
  2741. */
  2742. static _normalizeKey(keyName) {
  2743. // TODO: switch to a Map if the mapping grows too much
  2744. switch (keyName) {
  2745. case 'esc':
  2746. return 'escape';
  2747. default:
  2748. return keyName;
  2749. }
  2750. }
  2751. }
  2752. KeyEventsPlugin.decorators = [
  2753. { type: Injectable },
  2754. ];
  2755. /** @nocollapse */
  2756. KeyEventsPlugin.ctorParameters = () => [
  2757. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT$1,] },] },
  2758. ];
  2759. /**
  2760. * @fileoverview added by tsickle
  2761. * @suppress {checkTypes} checked by tsc
  2762. */
  2763. /**
  2764. * @license
  2765. * Copyright Google Inc. All Rights Reserved.
  2766. *
  2767. * Use of this source code is governed by an MIT-style license that can be
  2768. * found in the LICENSE file at https://angular.io/license
  2769. */
  2770. /**
  2771. * This helper class is used to get hold of an inert tree of DOM elements containing dirty HTML
  2772. * that needs sanitizing.
  2773. * Depending upon browser support we must use one of three strategies for doing this.
  2774. * Support: Safari 10.x -> XHR strategy
  2775. * Support: Firefox -> DomParser strategy
  2776. * Default: InertDocument strategy
  2777. */
  2778. class InertBodyHelper {
  2779. /**
  2780. * @param {?} defaultDoc
  2781. * @param {?} DOM
  2782. */
  2783. constructor(defaultDoc, DOM) {
  2784. this.defaultDoc = defaultDoc;
  2785. this.DOM = DOM;
  2786. const /** @type {?} */ inertDocument = this.DOM.createHtmlDocument();
  2787. this.inertBodyElement = inertDocument.body;
  2788. if (this.inertBodyElement == null) {
  2789. // usually there should be only one body element in the document, but IE doesn't have any, so
  2790. // we need to create one.
  2791. const /** @type {?} */ inertHtml = this.DOM.createElement('html', inertDocument);
  2792. this.inertBodyElement = this.DOM.createElement('body', inertDocument);
  2793. this.DOM.appendChild(inertHtml, this.inertBodyElement);
  2794. this.DOM.appendChild(inertDocument, inertHtml);
  2795. }
  2796. this.DOM.setInnerHTML(this.inertBodyElement, '<svg><g onload="this.parentNode.remove()"></g></svg>');
  2797. if (this.inertBodyElement.querySelector && !this.inertBodyElement.querySelector('svg')) {
  2798. // We just hit the Safari 10.1 bug - which allows JS to run inside the SVG G element
  2799. // so use the XHR strategy.
  2800. this.getInertBodyElement = this.getInertBodyElement_XHR;
  2801. return;
  2802. }
  2803. this.DOM.setInnerHTML(this.inertBodyElement, '<svg><p><style><img src="</style><img src=x onerror=alert(1)//">');
  2804. if (this.inertBodyElement.querySelector && this.inertBodyElement.querySelector('svg img')) {
  2805. // We just hit the Firefox bug - which prevents the inner img JS from being sanitized
  2806. // so use the DOMParser strategy, if it is available.
  2807. // If the DOMParser is not available then we are not in Firefox (Server/WebWorker?) so we
  2808. // fall through to the default strategy below.
  2809. if (isDOMParserAvailable()) {
  2810. this.getInertBodyElement = this.getInertBodyElement_DOMParser;
  2811. return;
  2812. }
  2813. }
  2814. // None of the bugs were hit so it is safe for us to use the default InertDocument strategy
  2815. this.getInertBodyElement = this.getInertBodyElement_InertDocument;
  2816. }
  2817. /**
  2818. * Use XHR to create and fill an inert body element (on Safari 10.1)
  2819. * See
  2820. * https://github.com/cure53/DOMPurify/blob/a992d3a75031cb8bb032e5ea8399ba972bdf9a65/src/purify.js#L439-L449
  2821. * @param {?} html
  2822. * @return {?}
  2823. */
  2824. getInertBodyElement_XHR(html) {
  2825. // We add these extra elements to ensure that the rest of the content is parsed as expected
  2826. // e.g. leading whitespace is maintained and tags like `<meta>` do not get hoisted to the
  2827. // `<head>` tag.
  2828. html = '<body><remove></remove>' + html + '</body>';
  2829. try {
  2830. html = encodeURI(html);
  2831. }
  2832. catch (/** @type {?} */ e) {
  2833. return null;
  2834. }
  2835. const /** @type {?} */ xhr = new XMLHttpRequest();
  2836. xhr.responseType = 'document';
  2837. xhr.open('GET', 'data:text/html;charset=utf-8,' + html, false);
  2838. xhr.send(null);
  2839. const /** @type {?} */ body = xhr.response.body;
  2840. body.removeChild(/** @type {?} */ ((body.firstChild)));
  2841. return body;
  2842. }
  2843. /**
  2844. * Use DOMParser to create and fill an inert body element (on Firefox)
  2845. * See https://github.com/cure53/DOMPurify/releases/tag/0.6.7
  2846. *
  2847. * @param {?} html
  2848. * @return {?}
  2849. */
  2850. getInertBodyElement_DOMParser(html) {
  2851. // We add these extra elements to ensure that the rest of the content is parsed as expected
  2852. // e.g. leading whitespace is maintained and tags like `<meta>` do not get hoisted to the
  2853. // `<head>` tag.
  2854. html = '<body><remove></remove>' + html + '</body>';
  2855. try {
  2856. const /** @type {?} */ body = /** @type {?} */ (new (/** @type {?} */ (window))
  2857. .DOMParser()
  2858. .parseFromString(html, 'text/html')
  2859. .body);
  2860. body.removeChild(/** @type {?} */ ((body.firstChild)));
  2861. return body;
  2862. }
  2863. catch (/** @type {?} */ e) {
  2864. return null;
  2865. }
  2866. }
  2867. /**
  2868. * Use an HTML5 `template` element, if supported, or an inert body element created via
  2869. * `createHtmlDocument` to create and fill an inert DOM element.
  2870. * This is the default sane strategy to use if the browser does not require one of the specialised
  2871. * strategies above.
  2872. * @param {?} html
  2873. * @return {?}
  2874. */
  2875. getInertBodyElement_InertDocument(html) {
  2876. // Prefer using <template> element if supported.
  2877. const /** @type {?} */ templateEl = this.DOM.createElement('template');
  2878. if ('content' in templateEl) {
  2879. this.DOM.setInnerHTML(templateEl, html);
  2880. return templateEl;
  2881. }
  2882. this.DOM.setInnerHTML(this.inertBodyElement, html);
  2883. // Support: IE 9-11 only
  2884. // strip custom-namespaced attributes on IE<=11
  2885. if (this.defaultDoc.documentMode) {
  2886. this.stripCustomNsAttrs(this.inertBodyElement);
  2887. }
  2888. return this.inertBodyElement;
  2889. }
  2890. /**
  2891. * When IE9-11 comes across an unknown namespaced attribute e.g. 'xlink:foo' it adds 'xmlns:ns1'
  2892. * attribute to declare ns1 namespace and prefixes the attribute with 'ns1' (e.g.
  2893. * 'ns1:xlink:foo').
  2894. *
  2895. * This is undesirable since we don't want to allow any of these custom attributes. This method
  2896. * strips them all.
  2897. * @param {?} el
  2898. * @return {?}
  2899. */
  2900. stripCustomNsAttrs(el) {
  2901. this.DOM.attributeMap(el).forEach((_, attrName) => {
  2902. if (attrName === 'xmlns:ns1' || attrName.indexOf('ns1:') === 0) {
  2903. this.DOM.removeAttribute(el, attrName);
  2904. }
  2905. });
  2906. for (const /** @type {?} */ n of this.DOM.childNodesAsList(el)) {
  2907. if (this.DOM.isElementNode(n))
  2908. this.stripCustomNsAttrs(/** @type {?} */ (n));
  2909. }
  2910. }
  2911. }
  2912. /**
  2913. * We need to determine whether the DOMParser exists in the global context.
  2914. * The try-catch is because, on some browsers, trying to access this property
  2915. * on window can actually throw an error.
  2916. *
  2917. * @suppress {uselessCode}
  2918. * @return {?}
  2919. */
  2920. function isDOMParserAvailable() {
  2921. try {
  2922. return !!(/** @type {?} */ (window)).DOMParser;
  2923. }
  2924. catch (/** @type {?} */ e) {
  2925. return false;
  2926. }
  2927. }
  2928. /**
  2929. * @fileoverview added by tsickle
  2930. * @suppress {checkTypes} checked by tsc
  2931. */
  2932. /**
  2933. * @license
  2934. * Copyright Google Inc. All Rights Reserved.
  2935. *
  2936. * Use of this source code is governed by an MIT-style license that can be
  2937. * found in the LICENSE file at https://angular.io/license
  2938. */
  2939. /**
  2940. * A pattern that recognizes a commonly useful subset of URLs that are safe.
  2941. *
  2942. * This regular expression matches a subset of URLs that will not cause script
  2943. * execution if used in URL context within a HTML document. Specifically, this
  2944. * regular expression matches if (comment from here on and regex copied from
  2945. * Soy's EscapingConventions):
  2946. * (1) Either a protocol in a whitelist (http, https, mailto or ftp).
  2947. * (2) or no protocol. A protocol must be followed by a colon. The below
  2948. * allows that by allowing colons only after one of the characters [/?#].
  2949. * A colon after a hash (#) must be in the fragment.
  2950. * Otherwise, a colon after a (?) must be in a query.
  2951. * Otherwise, a colon after a single solidus (/) must be in a path.
  2952. * Otherwise, a colon after a double solidus (//) must be in the authority
  2953. * (before port).
  2954. *
  2955. * The pattern disallows &, used in HTML entity declarations before
  2956. * one of the characters in [/?#]. This disallows HTML entities used in the
  2957. * protocol name, which should never happen, e.g. "h&#116;tp" for "http".
  2958. * It also disallows HTML entities in the first path part of a relative path,
  2959. * e.g. "foo&lt;bar/baz". Our existing escaping functions should not produce
  2960. * that. More importantly, it disallows masking of a colon,
  2961. * e.g. "javascript&#58;...".
  2962. *
  2963. * This regular expression was taken from the Closure sanitization library.
  2964. */
  2965. const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file):|[^&:/?#]*(?:[/?#]|$))/gi;
  2966. /**
  2967. * A pattern that matches safe data URLs. Only matches image, video and audio types.
  2968. */
  2969. const DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[a-z0-9+\/]+=*$/i;
  2970. /**
  2971. * @param {?} url
  2972. * @return {?}
  2973. */
  2974. function sanitizeUrl(url) {
  2975. url = String(url);
  2976. if (url.match(SAFE_URL_PATTERN) || url.match(DATA_URL_PATTERN))
  2977. return url;
  2978. if (isDevMode()) {
  2979. getDOM().log(`WARNING: sanitizing unsafe URL value ${url} (see http://g.co/ng/security#xss)`);
  2980. }
  2981. return 'unsafe:' + url;
  2982. }
  2983. /**
  2984. * @param {?} srcset
  2985. * @return {?}
  2986. */
  2987. function sanitizeSrcset(srcset) {
  2988. srcset = String(srcset);
  2989. return srcset.split(',').map((srcset) => sanitizeUrl(srcset.trim())).join(', ');
  2990. }
  2991. /**
  2992. * @fileoverview added by tsickle
  2993. * @suppress {checkTypes} checked by tsc
  2994. */
  2995. /**
  2996. * @license
  2997. * Copyright Google Inc. All Rights Reserved.
  2998. *
  2999. * Use of this source code is governed by an MIT-style license that can be
  3000. * found in the LICENSE file at https://angular.io/license
  3001. */
  3002. /**
  3003. * @param {?} tags
  3004. * @return {?}
  3005. */
  3006. function tagSet(tags) {
  3007. const /** @type {?} */ res = {};
  3008. for (const /** @type {?} */ t of tags.split(','))
  3009. res[t] = true;
  3010. return res;
  3011. }
  3012. /**
  3013. * @param {...?} sets
  3014. * @return {?}
  3015. */
  3016. function merge(...sets) {
  3017. const /** @type {?} */ res = {};
  3018. for (const /** @type {?} */ s of sets) {
  3019. for (const /** @type {?} */ v in s) {
  3020. if (s.hasOwnProperty(v))
  3021. res[v] = true;
  3022. }
  3023. }
  3024. return res;
  3025. }
  3026. // Good source of info about elements and attributes
  3027. // http://dev.w3.org/html5/spec/Overview.html#semantics
  3028. // http://simon.html5.org/html-elements
  3029. // Safe Void Elements - HTML5
  3030. // http://dev.w3.org/html5/spec/Overview.html#void-elements
  3031. const VOID_ELEMENTS = tagSet('area,br,col,hr,img,wbr');
  3032. // Elements that you can, intentionally, leave open (and which close themselves)
  3033. // http://dev.w3.org/html5/spec/Overview.html#optional-tags
  3034. const OPTIONAL_END_TAG_BLOCK_ELEMENTS = tagSet('colgroup,dd,dt,li,p,tbody,td,tfoot,th,thead,tr');
  3035. const OPTIONAL_END_TAG_INLINE_ELEMENTS = tagSet('rp,rt');
  3036. const OPTIONAL_END_TAG_ELEMENTS = merge(OPTIONAL_END_TAG_INLINE_ELEMENTS, OPTIONAL_END_TAG_BLOCK_ELEMENTS);
  3037. // Safe Block Elements - HTML5
  3038. const BLOCK_ELEMENTS = merge(OPTIONAL_END_TAG_BLOCK_ELEMENTS, tagSet('address,article,' +
  3039. 'aside,blockquote,caption,center,del,details,dialog,dir,div,dl,figure,figcaption,footer,h1,h2,h3,h4,h5,' +
  3040. 'h6,header,hgroup,hr,ins,main,map,menu,nav,ol,pre,section,summary,table,ul'));
  3041. // Inline Elements - HTML5
  3042. const INLINE_ELEMENTS = merge(OPTIONAL_END_TAG_INLINE_ELEMENTS, tagSet('a,abbr,acronym,audio,b,' +
  3043. 'bdi,bdo,big,br,cite,code,del,dfn,em,font,i,img,ins,kbd,label,map,mark,picture,q,ruby,rp,rt,s,' +
  3044. 'samp,small,source,span,strike,strong,sub,sup,time,track,tt,u,var,video'));
  3045. const VALID_ELEMENTS = merge(VOID_ELEMENTS, BLOCK_ELEMENTS, INLINE_ELEMENTS, OPTIONAL_END_TAG_ELEMENTS);
  3046. // Attributes that have href and hence need to be sanitized
  3047. const URI_ATTRS = tagSet('background,cite,href,itemtype,longdesc,poster,src,xlink:href');
  3048. // Attributes that have special href set hence need to be sanitized
  3049. const SRCSET_ATTRS = tagSet('srcset');
  3050. const HTML_ATTRS = tagSet('abbr,accesskey,align,alt,autoplay,axis,bgcolor,border,cellpadding,cellspacing,class,clear,color,cols,colspan,' +
  3051. 'compact,controls,coords,datetime,default,dir,download,face,headers,height,hidden,hreflang,hspace,' +
  3052. 'ismap,itemscope,itemprop,kind,label,lang,language,loop,media,muted,nohref,nowrap,open,preload,rel,rev,role,rows,rowspan,rules,' +
  3053. 'scope,scrolling,shape,size,sizes,span,srclang,start,summary,tabindex,target,title,translate,type,usemap,' +
  3054. 'valign,value,vspace,width');
  3055. // NB: This currently consciously doesn't support SVG. SVG sanitization has had several security
  3056. // issues in the past, so it seems safer to leave it out if possible. If support for binding SVG via
  3057. // innerHTML is required, SVG attributes should be added here.
  3058. // NB: Sanitization does not allow <form> elements or other active elements (<button> etc). Those
  3059. // can be sanitized, but they increase security surface area without a legitimate use case, so they
  3060. // are left out here.
  3061. const VALID_ATTRS = merge(URI_ATTRS, SRCSET_ATTRS, HTML_ATTRS);
  3062. /**
  3063. * SanitizingHtmlSerializer serializes a DOM fragment, stripping out any unsafe elements and unsafe
  3064. * attributes.
  3065. */
  3066. class SanitizingHtmlSerializer {
  3067. constructor() {
  3068. this.sanitizedSomething = false;
  3069. this.buf = [];
  3070. this.DOM = getDOM();
  3071. }
  3072. /**
  3073. * @param {?} el
  3074. * @return {?}
  3075. */
  3076. sanitizeChildren(el) {
  3077. // This cannot use a TreeWalker, as it has to run on Angular's various DOM adapters.
  3078. // However this code never accesses properties off of `document` before deleting its contents
  3079. // again, so it shouldn't be vulnerable to DOM clobbering.
  3080. let /** @type {?} */ current = /** @type {?} */ ((this.DOM.firstChild(el)));
  3081. while (current) {
  3082. if (this.DOM.isElementNode(current)) {
  3083. this.startElement(/** @type {?} */ (current));
  3084. }
  3085. else if (this.DOM.isTextNode(current)) {
  3086. this.chars(/** @type {?} */ ((this.DOM.nodeValue(current))));
  3087. }
  3088. else {
  3089. // Strip non-element, non-text nodes.
  3090. this.sanitizedSomething = true;
  3091. }
  3092. if (this.DOM.firstChild(current)) {
  3093. current = /** @type {?} */ ((this.DOM.firstChild(current)));
  3094. continue;
  3095. }
  3096. while (current) {
  3097. // Leaving the element. Walk up and to the right, closing tags as we go.
  3098. if (this.DOM.isElementNode(current)) {
  3099. this.endElement(/** @type {?} */ (current));
  3100. }
  3101. let /** @type {?} */ next = this.checkClobberedElement(current, /** @type {?} */ ((this.DOM.nextSibling(current))));
  3102. if (next) {
  3103. current = next;
  3104. break;
  3105. }
  3106. current = this.checkClobberedElement(current, /** @type {?} */ ((this.DOM.parentElement(current))));
  3107. }
  3108. }
  3109. return this.buf.join('');
  3110. }
  3111. /**
  3112. * @param {?} element
  3113. * @return {?}
  3114. */
  3115. startElement(element) {
  3116. const /** @type {?} */ tagName = this.DOM.nodeName(element).toLowerCase();
  3117. if (!VALID_ELEMENTS.hasOwnProperty(tagName)) {
  3118. this.sanitizedSomething = true;
  3119. return;
  3120. }
  3121. this.buf.push('<');
  3122. this.buf.push(tagName);
  3123. this.DOM.attributeMap(element).forEach((value, attrName) => {
  3124. const /** @type {?} */ lower = attrName.toLowerCase();
  3125. if (!VALID_ATTRS.hasOwnProperty(lower)) {
  3126. this.sanitizedSomething = true;
  3127. return;
  3128. }
  3129. // TODO(martinprobst): Special case image URIs for data:image/...
  3130. if (URI_ATTRS[lower])
  3131. value = sanitizeUrl(value);
  3132. if (SRCSET_ATTRS[lower])
  3133. value = sanitizeSrcset(value);
  3134. this.buf.push(' ');
  3135. this.buf.push(attrName);
  3136. this.buf.push('="');
  3137. this.buf.push(encodeEntities(value));
  3138. this.buf.push('"');
  3139. });
  3140. this.buf.push('>');
  3141. }
  3142. /**
  3143. * @param {?} current
  3144. * @return {?}
  3145. */
  3146. endElement(current) {
  3147. const /** @type {?} */ tagName = this.DOM.nodeName(current).toLowerCase();
  3148. if (VALID_ELEMENTS.hasOwnProperty(tagName) && !VOID_ELEMENTS.hasOwnProperty(tagName)) {
  3149. this.buf.push('</');
  3150. this.buf.push(tagName);
  3151. this.buf.push('>');
  3152. }
  3153. }
  3154. /**
  3155. * @param {?} chars
  3156. * @return {?}
  3157. */
  3158. chars(chars) { this.buf.push(encodeEntities(chars)); }
  3159. /**
  3160. * @param {?} node
  3161. * @param {?} nextNode
  3162. * @return {?}
  3163. */
  3164. checkClobberedElement(node, nextNode) {
  3165. if (nextNode && this.DOM.contains(node, nextNode)) {
  3166. throw new Error(`Failed to sanitize html because the element is clobbered: ${this.DOM.getOuterHTML(node)}`);
  3167. }
  3168. return nextNode;
  3169. }
  3170. }
  3171. // Regular Expressions for parsing tags and attributes
  3172. const SURROGATE_PAIR_REGEXP = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  3173. // ! to ~ is the ASCII range.
  3174. const NON_ALPHANUMERIC_REGEXP = /([^\#-~ |!])/g;
  3175. /**
  3176. * Escapes all potentially dangerous characters, so that the
  3177. * resulting string can be safely inserted into attribute or
  3178. * element text.
  3179. * @param {?} value
  3180. * @return {?}
  3181. */
  3182. function encodeEntities(value) {
  3183. return value.replace(/&/g, '&amp;')
  3184. .replace(SURROGATE_PAIR_REGEXP, function (match) {
  3185. const /** @type {?} */ hi = match.charCodeAt(0);
  3186. const /** @type {?} */ low = match.charCodeAt(1);
  3187. return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';';
  3188. })
  3189. .replace(NON_ALPHANUMERIC_REGEXP, function (match) { return '&#' + match.charCodeAt(0) + ';'; })
  3190. .replace(/</g, '&lt;')
  3191. .replace(/>/g, '&gt;');
  3192. }
  3193. let inertBodyHelper;
  3194. /**
  3195. * Sanitizes the given unsafe, untrusted HTML fragment, and returns HTML text that is safe to add to
  3196. * the DOM in a browser environment.
  3197. * @param {?} defaultDoc
  3198. * @param {?} unsafeHtmlInput
  3199. * @return {?}
  3200. */
  3201. function sanitizeHtml(defaultDoc, unsafeHtmlInput) {
  3202. const /** @type {?} */ DOM = getDOM();
  3203. let /** @type {?} */ inertBodyElement = null;
  3204. try {
  3205. inertBodyHelper = inertBodyHelper || new InertBodyHelper(defaultDoc, DOM);
  3206. // Make sure unsafeHtml is actually a string (TypeScript types are not enforced at runtime).
  3207. let /** @type {?} */ unsafeHtml = unsafeHtmlInput ? String(unsafeHtmlInput) : '';
  3208. inertBodyElement = inertBodyHelper.getInertBodyElement(unsafeHtml);
  3209. // mXSS protection. Repeatedly parse the document to make sure it stabilizes, so that a browser
  3210. // trying to auto-correct incorrect HTML cannot cause formerly inert HTML to become dangerous.
  3211. let /** @type {?} */ mXSSAttempts = 5;
  3212. let /** @type {?} */ parsedHtml = unsafeHtml;
  3213. do {
  3214. if (mXSSAttempts === 0) {
  3215. throw new Error('Failed to sanitize html because the input is unstable');
  3216. }
  3217. mXSSAttempts--;
  3218. unsafeHtml = parsedHtml;
  3219. parsedHtml = DOM.getInnerHTML(inertBodyElement);
  3220. inertBodyElement = inertBodyHelper.getInertBodyElement(unsafeHtml);
  3221. } while (unsafeHtml !== parsedHtml);
  3222. const /** @type {?} */ sanitizer = new SanitizingHtmlSerializer();
  3223. const /** @type {?} */ safeHtml = sanitizer.sanitizeChildren(DOM.getTemplateContent(inertBodyElement) || inertBodyElement);
  3224. if (isDevMode() && sanitizer.sanitizedSomething) {
  3225. DOM.log('WARNING: sanitizing HTML stripped some content (see http://g.co/ng/security#xss).');
  3226. }
  3227. return safeHtml;
  3228. }
  3229. finally {
  3230. // In case anything goes wrong, clear out inertElement to reset the entire DOM structure.
  3231. if (inertBodyElement) {
  3232. const /** @type {?} */ parent = DOM.getTemplateContent(inertBodyElement) || inertBodyElement;
  3233. for (const /** @type {?} */ child of DOM.childNodesAsList(parent)) {
  3234. DOM.removeChild(parent, child);
  3235. }
  3236. }
  3237. }
  3238. }
  3239. /**
  3240. * @fileoverview added by tsickle
  3241. * @suppress {checkTypes} checked by tsc
  3242. */
  3243. /**
  3244. * @license
  3245. * Copyright Google Inc. All Rights Reserved.
  3246. *
  3247. * Use of this source code is governed by an MIT-style license that can be
  3248. * found in the LICENSE file at https://angular.io/license
  3249. */
  3250. /**
  3251. * Regular expression for safe style values.
  3252. *
  3253. * Quotes (" and ') are allowed, but a check must be done elsewhere to ensure they're balanced.
  3254. *
  3255. * ',' allows multiple values to be assigned to the same property (e.g. background-attachment or
  3256. * font-family) and hence could allow multiple values to get injected, but that should pose no risk
  3257. * of XSS.
  3258. *
  3259. * The function expression checks only for XSS safety, not for CSS validity.
  3260. *
  3261. * This regular expression was taken from the Closure sanitization library, and augmented for
  3262. * transformation values.
  3263. */
  3264. const VALUES = '[-,."\'%_!# a-zA-Z0-9]+';
  3265. const TRANSFORMATION_FNS = '(?:matrix|translate|scale|rotate|skew|perspective)(?:X|Y|3d)?';
  3266. const COLOR_FNS = '(?:rgb|hsl)a?';
  3267. const GRADIENTS = '(?:repeating-)?(?:linear|radial)-gradient';
  3268. const CSS3_FNS = '(?:calc|attr)';
  3269. const FN_ARGS = '\\([-0-9.%, #a-zA-Z]+\\)';
  3270. const SAFE_STYLE_VALUE = new RegExp(`^(${VALUES}|` +
  3271. `(?:${TRANSFORMATION_FNS}|${COLOR_FNS}|${GRADIENTS}|${CSS3_FNS})` +
  3272. `${FN_ARGS})$`, 'g');
  3273. /**
  3274. * Matches a `url(...)` value with an arbitrary argument as long as it does
  3275. * not contain parentheses.
  3276. *
  3277. * The URL value still needs to be sanitized separately.
  3278. *
  3279. * `url(...)` values are a very common use case, e.g. for `background-image`. With carefully crafted
  3280. * CSS style rules, it is possible to construct an information leak with `url` values in CSS, e.g.
  3281. * by observing whether scroll bars are displayed, or character ranges used by a font face
  3282. * definition.
  3283. *
  3284. * Angular only allows binding CSS values (as opposed to entire CSS rules), so it is unlikely that
  3285. * binding a URL value without further cooperation from the page will cause an information leak, and
  3286. * if so, it is just a leak, not a full blown XSS vulnerability.
  3287. *
  3288. * Given the common use case, low likelihood of attack vector, and low impact of an attack, this
  3289. * code is permissive and allows URLs that sanitize otherwise.
  3290. */
  3291. const URL_RE = /^url\(([^)]+)\)$/;
  3292. /**
  3293. * Checks that quotes (" and ') are properly balanced inside a string. Assumes
  3294. * that neither escape (\) nor any other character that could result in
  3295. * breaking out of a string parsing context are allowed;
  3296. * see http://www.w3.org/TR/css3-syntax/#string-token-diagram.
  3297. *
  3298. * This code was taken from the Closure sanitization library.
  3299. * @param {?} value
  3300. * @return {?}
  3301. */
  3302. function hasBalancedQuotes(value) {
  3303. let /** @type {?} */ outsideSingle = true;
  3304. let /** @type {?} */ outsideDouble = true;
  3305. for (let /** @type {?} */ i = 0; i < value.length; i++) {
  3306. const /** @type {?} */ c = value.charAt(i);
  3307. if (c === '\'' && outsideDouble) {
  3308. outsideSingle = !outsideSingle;
  3309. }
  3310. else if (c === '"' && outsideSingle) {
  3311. outsideDouble = !outsideDouble;
  3312. }
  3313. }
  3314. return outsideSingle && outsideDouble;
  3315. }
  3316. /**
  3317. * Sanitizes the given untrusted CSS style property value (i.e. not an entire object, just a single
  3318. * value) and returns a value that is safe to use in a browser environment.
  3319. * @param {?} value
  3320. * @return {?}
  3321. */
  3322. function sanitizeStyle(value) {
  3323. value = String(value).trim(); // Make sure it's actually a string.
  3324. if (!value)
  3325. return '';
  3326. // Single url(...) values are supported, but only for URLs that sanitize cleanly. See above for
  3327. // reasoning behind this.
  3328. const /** @type {?} */ urlMatch = value.match(URL_RE);
  3329. if ((urlMatch && sanitizeUrl(urlMatch[1]) === urlMatch[1]) ||
  3330. value.match(SAFE_STYLE_VALUE) && hasBalancedQuotes(value)) {
  3331. return value; // Safe style values.
  3332. }
  3333. if (isDevMode()) {
  3334. getDOM().log(`WARNING: sanitizing unsafe style value ${value} (see http://g.co/ng/security#xss).`);
  3335. }
  3336. return 'unsafe';
  3337. }
  3338. /**
  3339. * @fileoverview added by tsickle
  3340. * @suppress {checkTypes} checked by tsc
  3341. */
  3342. /**
  3343. * @license
  3344. * Copyright Google Inc. All Rights Reserved.
  3345. *
  3346. * Use of this source code is governed by an MIT-style license that can be
  3347. * found in the LICENSE file at https://angular.io/license
  3348. */
  3349. /**
  3350. * Marker interface for a value that's safe to use in a particular context.
  3351. *
  3352. * \@stable
  3353. * @record
  3354. */
  3355. /**
  3356. * Marker interface for a value that's safe to use as HTML.
  3357. *
  3358. * \@stable
  3359. * @record
  3360. */
  3361. /**
  3362. * Marker interface for a value that's safe to use as style (CSS).
  3363. *
  3364. * \@stable
  3365. * @record
  3366. */
  3367. /**
  3368. * Marker interface for a value that's safe to use as JavaScript.
  3369. *
  3370. * \@stable
  3371. * @record
  3372. */
  3373. /**
  3374. * Marker interface for a value that's safe to use as a URL linking to a document.
  3375. *
  3376. * \@stable
  3377. * @record
  3378. */
  3379. /**
  3380. * Marker interface for a value that's safe to use as a URL to load executable code from.
  3381. *
  3382. * \@stable
  3383. * @record
  3384. */
  3385. /**
  3386. * DomSanitizer helps preventing Cross Site Scripting Security bugs (XSS) by sanitizing
  3387. * values to be safe to use in the different DOM contexts.
  3388. *
  3389. * For example, when binding a URL in an `<a [href]="someValue">` hyperlink, `someValue` will be
  3390. * sanitized so that an attacker cannot inject e.g. a `javascript:` URL that would execute code on
  3391. * the website.
  3392. *
  3393. * In specific situations, it might be necessary to disable sanitization, for example if the
  3394. * application genuinely needs to produce a `javascript:` style link with a dynamic value in it.
  3395. * Users can bypass security by constructing a value with one of the `bypassSecurityTrust...`
  3396. * methods, and then binding to that value from the template.
  3397. *
  3398. * These situations should be very rare, and extraordinary care must be taken to avoid creating a
  3399. * Cross Site Scripting (XSS) security bug!
  3400. *
  3401. * When using `bypassSecurityTrust...`, make sure to call the method as early as possible and as
  3402. * close as possible to the source of the value, to make it easy to verify no security bug is
  3403. * created by its use.
  3404. *
  3405. * It is not required (and not recommended) to bypass security if the value is safe, e.g. a URL that
  3406. * does not start with a suspicious protocol, or an HTML snippet that does not contain dangerous
  3407. * code. The sanitizer leaves safe values intact.
  3408. *
  3409. * \@security Calling any of the `bypassSecurityTrust...` APIs disables Angular's built-in
  3410. * sanitization for the value passed in. Carefully check and audit all values and code paths going
  3411. * into this call. Make sure any user data is appropriately escaped for this security context.
  3412. * For more detail, see the [Security Guide](http://g.co/ng/security).
  3413. *
  3414. * \@stable
  3415. * @abstract
  3416. */
  3417. class DomSanitizer {
  3418. }
  3419. class DomSanitizerImpl extends DomSanitizer {
  3420. /**
  3421. * @param {?} _doc
  3422. */
  3423. constructor(_doc) {
  3424. super();
  3425. this._doc = _doc;
  3426. }
  3427. /**
  3428. * @param {?} ctx
  3429. * @param {?} value
  3430. * @return {?}
  3431. */
  3432. sanitize(ctx, value) {
  3433. if (value == null)
  3434. return null;
  3435. switch (ctx) {
  3436. case SecurityContext.NONE:
  3437. return /** @type {?} */ (value);
  3438. case SecurityContext.HTML:
  3439. if (value instanceof SafeHtmlImpl)
  3440. return value.changingThisBreaksApplicationSecurity;
  3441. this.checkNotSafeValue(value, 'HTML');
  3442. return sanitizeHtml(this._doc, String(value));
  3443. case SecurityContext.STYLE:
  3444. if (value instanceof SafeStyleImpl)
  3445. return value.changingThisBreaksApplicationSecurity;
  3446. this.checkNotSafeValue(value, 'Style');
  3447. return sanitizeStyle(/** @type {?} */ (value));
  3448. case SecurityContext.SCRIPT:
  3449. if (value instanceof SafeScriptImpl)
  3450. return value.changingThisBreaksApplicationSecurity;
  3451. this.checkNotSafeValue(value, 'Script');
  3452. throw new Error('unsafe value used in a script context');
  3453. case SecurityContext.URL:
  3454. if (value instanceof SafeResourceUrlImpl || value instanceof SafeUrlImpl) {
  3455. // Allow resource URLs in URL contexts, they are strictly more trusted.
  3456. return value.changingThisBreaksApplicationSecurity;
  3457. }
  3458. this.checkNotSafeValue(value, 'URL');
  3459. return sanitizeUrl(String(value));
  3460. case SecurityContext.RESOURCE_URL:
  3461. if (value instanceof SafeResourceUrlImpl) {
  3462. return value.changingThisBreaksApplicationSecurity;
  3463. }
  3464. this.checkNotSafeValue(value, 'ResourceURL');
  3465. throw new Error('unsafe value used in a resource URL context (see http://g.co/ng/security#xss)');
  3466. default:
  3467. throw new Error(`Unexpected SecurityContext ${ctx} (see http://g.co/ng/security#xss)`);
  3468. }
  3469. }
  3470. /**
  3471. * @param {?} value
  3472. * @param {?} expectedType
  3473. * @return {?}
  3474. */
  3475. checkNotSafeValue(value, expectedType) {
  3476. if (value instanceof SafeValueImpl) {
  3477. throw new Error(`Required a safe ${expectedType}, got a ${value.getTypeName()} ` +
  3478. `(see http://g.co/ng/security#xss)`);
  3479. }
  3480. }
  3481. /**
  3482. * @param {?} value
  3483. * @return {?}
  3484. */
  3485. bypassSecurityTrustHtml(value) { return new SafeHtmlImpl(value); }
  3486. /**
  3487. * @param {?} value
  3488. * @return {?}
  3489. */
  3490. bypassSecurityTrustStyle(value) { return new SafeStyleImpl(value); }
  3491. /**
  3492. * @param {?} value
  3493. * @return {?}
  3494. */
  3495. bypassSecurityTrustScript(value) { return new SafeScriptImpl(value); }
  3496. /**
  3497. * @param {?} value
  3498. * @return {?}
  3499. */
  3500. bypassSecurityTrustUrl(value) { return new SafeUrlImpl(value); }
  3501. /**
  3502. * @param {?} value
  3503. * @return {?}
  3504. */
  3505. bypassSecurityTrustResourceUrl(value) {
  3506. return new SafeResourceUrlImpl(value);
  3507. }
  3508. }
  3509. DomSanitizerImpl.decorators = [
  3510. { type: Injectable },
  3511. ];
  3512. /** @nocollapse */
  3513. DomSanitizerImpl.ctorParameters = () => [
  3514. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT$1,] },] },
  3515. ];
  3516. /**
  3517. * @abstract
  3518. */
  3519. class SafeValueImpl {
  3520. /**
  3521. * @param {?} changingThisBreaksApplicationSecurity
  3522. */
  3523. constructor(changingThisBreaksApplicationSecurity) {
  3524. // empty
  3525. this.changingThisBreaksApplicationSecurity = changingThisBreaksApplicationSecurity;
  3526. }
  3527. /**
  3528. * @return {?}
  3529. */
  3530. toString() {
  3531. return `SafeValue must use [property]=binding: ${this.changingThisBreaksApplicationSecurity}` +
  3532. ` (see http://g.co/ng/security#xss)`;
  3533. }
  3534. }
  3535. class SafeHtmlImpl extends SafeValueImpl {
  3536. /**
  3537. * @return {?}
  3538. */
  3539. getTypeName() { return 'HTML'; }
  3540. }
  3541. class SafeStyleImpl extends SafeValueImpl {
  3542. /**
  3543. * @return {?}
  3544. */
  3545. getTypeName() { return 'Style'; }
  3546. }
  3547. class SafeScriptImpl extends SafeValueImpl {
  3548. /**
  3549. * @return {?}
  3550. */
  3551. getTypeName() { return 'Script'; }
  3552. }
  3553. class SafeUrlImpl extends SafeValueImpl {
  3554. /**
  3555. * @return {?}
  3556. */
  3557. getTypeName() { return 'URL'; }
  3558. }
  3559. class SafeResourceUrlImpl extends SafeValueImpl {
  3560. /**
  3561. * @return {?}
  3562. */
  3563. getTypeName() { return 'ResourceURL'; }
  3564. }
  3565. /**
  3566. * @fileoverview added by tsickle
  3567. * @suppress {checkTypes} checked by tsc
  3568. */
  3569. /**
  3570. * @license
  3571. * Copyright Google Inc. All Rights Reserved.
  3572. *
  3573. * Use of this source code is governed by an MIT-style license that can be
  3574. * found in the LICENSE file at https://angular.io/license
  3575. */
  3576. const INTERNAL_BROWSER_PLATFORM_PROVIDERS = [
  3577. { provide: PLATFORM_ID, useValue: ɵPLATFORM_BROWSER_ID },
  3578. { provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true },
  3579. { provide: PlatformLocation, useClass: BrowserPlatformLocation, deps: [DOCUMENT$1] },
  3580. { provide: DOCUMENT$1, useFactory: _document, deps: [] },
  3581. ];
  3582. /**
  3583. * \@security Replacing built-in sanitization providers exposes the application to XSS risks.
  3584. * Attacker-controlled data introduced by an unsanitized provider could expose your
  3585. * application to XSS risks. For more detail, see the [Security Guide](http://g.co/ng/security).
  3586. * \@experimental
  3587. */
  3588. const BROWSER_SANITIZATION_PROVIDERS = [
  3589. { provide: Sanitizer, useExisting: DomSanitizer },
  3590. { provide: DomSanitizer, useClass: DomSanitizerImpl, deps: [DOCUMENT$1] },
  3591. ];
  3592. /**
  3593. * \@stable
  3594. */
  3595. const platformBrowser = createPlatformFactory(platformCore, 'browser', INTERNAL_BROWSER_PLATFORM_PROVIDERS);
  3596. /**
  3597. * @return {?}
  3598. */
  3599. function initDomAdapter() {
  3600. BrowserDomAdapter.makeCurrent();
  3601. BrowserGetTestability.init();
  3602. }
  3603. /**
  3604. * @return {?}
  3605. */
  3606. function errorHandler() {
  3607. return new ErrorHandler();
  3608. }
  3609. /**
  3610. * @return {?}
  3611. */
  3612. function _document() {
  3613. return document;
  3614. }
  3615. /**
  3616. * The ng module for the browser.
  3617. *
  3618. * \@stable
  3619. */
  3620. class BrowserModule {
  3621. /**
  3622. * @param {?} parentModule
  3623. */
  3624. constructor(parentModule) {
  3625. if (parentModule) {
  3626. throw new Error(`BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.`);
  3627. }
  3628. }
  3629. /**
  3630. * Configures a browser-based application to transition from a server-rendered app, if
  3631. * one is present on the page. The specified parameters must include an application id,
  3632. * which must match between the client and server applications.
  3633. *
  3634. * \@experimental
  3635. * @param {?} params
  3636. * @return {?}
  3637. */
  3638. static withServerTransition(params) {
  3639. return {
  3640. ngModule: BrowserModule,
  3641. providers: [
  3642. { provide: APP_ID, useValue: params.appId },
  3643. { provide: TRANSITION_ID, useExisting: APP_ID },
  3644. SERVER_TRANSITION_PROVIDERS,
  3645. ],
  3646. };
  3647. }
  3648. }
  3649. BrowserModule.decorators = [
  3650. { type: NgModule, args: [{
  3651. providers: [
  3652. BROWSER_SANITIZATION_PROVIDERS,
  3653. { provide: ErrorHandler, useFactory: errorHandler, deps: [] },
  3654. { provide: EVENT_MANAGER_PLUGINS, useClass: DomEventsPlugin, multi: true },
  3655. { provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true },
  3656. { provide: EVENT_MANAGER_PLUGINS, useClass: HammerGesturesPlugin, multi: true },
  3657. { provide: HAMMER_GESTURE_CONFIG, useClass: HammerGestureConfig },
  3658. DomRendererFactory2,
  3659. { provide: RendererFactory2, useExisting: DomRendererFactory2 },
  3660. { provide: SharedStylesHost, useExisting: DomSharedStylesHost },
  3661. DomSharedStylesHost,
  3662. Testability,
  3663. EventManager,
  3664. ELEMENT_PROBE_PROVIDERS,
  3665. Meta,
  3666. Title,
  3667. ],
  3668. exports: [CommonModule, ApplicationModule]
  3669. },] },
  3670. ];
  3671. /** @nocollapse */
  3672. BrowserModule.ctorParameters = () => [
  3673. { type: BrowserModule, decorators: [{ type: Optional }, { type: SkipSelf },] },
  3674. ];
  3675. /**
  3676. * @fileoverview added by tsickle
  3677. * @suppress {checkTypes} checked by tsc
  3678. */
  3679. /**
  3680. * @license
  3681. * Copyright Google Inc. All Rights Reserved.
  3682. *
  3683. * Use of this source code is governed by an MIT-style license that can be
  3684. * found in the LICENSE file at https://angular.io/license
  3685. */
  3686. const win = typeof window !== 'undefined' && window || /** @type {?} */ ({});
  3687. /**
  3688. * @fileoverview added by tsickle
  3689. * @suppress {checkTypes} checked by tsc
  3690. */
  3691. /**
  3692. * @license
  3693. * Copyright Google Inc. All Rights Reserved.
  3694. *
  3695. * Use of this source code is governed by an MIT-style license that can be
  3696. * found in the LICENSE file at https://angular.io/license
  3697. */
  3698. class ChangeDetectionPerfRecord {
  3699. /**
  3700. * @param {?} msPerTick
  3701. * @param {?} numTicks
  3702. */
  3703. constructor(msPerTick, numTicks) {
  3704. this.msPerTick = msPerTick;
  3705. this.numTicks = numTicks;
  3706. }
  3707. }
  3708. /**
  3709. * Entry point for all Angular profiling-related debug tools. This object
  3710. * corresponds to the `ng.profiler` in the dev console.
  3711. */
  3712. class AngularProfiler {
  3713. /**
  3714. * @param {?} ref
  3715. */
  3716. constructor(ref) { this.appRef = ref.injector.get(ApplicationRef); }
  3717. /**
  3718. * Exercises change detection in a loop and then prints the average amount of
  3719. * time in milliseconds how long a single round of change detection takes for
  3720. * the current state of the UI. It runs a minimum of 5 rounds for a minimum
  3721. * of 500 milliseconds.
  3722. *
  3723. * Optionally, a user may pass a `config` parameter containing a map of
  3724. * options. Supported options are:
  3725. *
  3726. * `record` (boolean) - causes the profiler to record a CPU profile while
  3727. * it exercises the change detector. Example:
  3728. *
  3729. * ```
  3730. * ng.profiler.timeChangeDetection({record: true})
  3731. * ```
  3732. * @param {?} config
  3733. * @return {?}
  3734. */
  3735. timeChangeDetection(config) {
  3736. const /** @type {?} */ record = config && config['record'];
  3737. const /** @type {?} */ profileName = 'Change Detection';
  3738. // Profiler is not available in Android browsers, nor in IE 9 without dev tools opened
  3739. const /** @type {?} */ isProfilerAvailable = win.console.profile != null;
  3740. if (record && isProfilerAvailable) {
  3741. win.console.profile(profileName);
  3742. }
  3743. const /** @type {?} */ start = getDOM().performanceNow();
  3744. let /** @type {?} */ numTicks = 0;
  3745. while (numTicks < 5 || (getDOM().performanceNow() - start) < 500) {
  3746. this.appRef.tick();
  3747. numTicks++;
  3748. }
  3749. const /** @type {?} */ end = getDOM().performanceNow();
  3750. if (record && isProfilerAvailable) {
  3751. // need to cast to <any> because type checker thinks there's no argument
  3752. // while in fact there is:
  3753. //
  3754. // https://developer.mozilla.org/en-US/docs/Web/API/Console/profileEnd
  3755. (/** @type {?} */ (win.console.profileEnd))(profileName);
  3756. }
  3757. const /** @type {?} */ msPerTick = (end - start) / numTicks;
  3758. win.console.log(`ran ${numTicks} change detection cycles`);
  3759. win.console.log(`${msPerTick.toFixed(2)} ms per check`);
  3760. return new ChangeDetectionPerfRecord(msPerTick, numTicks);
  3761. }
  3762. }
  3763. /**
  3764. * @fileoverview added by tsickle
  3765. * @suppress {checkTypes} checked by tsc
  3766. */
  3767. /**
  3768. * @license
  3769. * Copyright Google Inc. All Rights Reserved.
  3770. *
  3771. * Use of this source code is governed by an MIT-style license that can be
  3772. * found in the LICENSE file at https://angular.io/license
  3773. */
  3774. const PROFILER_GLOBAL_NAME = 'profiler';
  3775. /**
  3776. * Enabled Angular debug tools that are accessible via your browser's
  3777. * developer console.
  3778. *
  3779. * Usage:
  3780. *
  3781. * 1. Open developer console (e.g. in Chrome Ctrl + Shift + j)
  3782. * 1. Type `ng.` (usually the console will show auto-complete suggestion)
  3783. * 1. Try the change detection profiler `ng.profiler.timeChangeDetection()`
  3784. * then hit Enter.
  3785. *
  3786. * \@experimental All debugging apis are currently experimental.
  3787. * @template T
  3788. * @param {?} ref
  3789. * @return {?}
  3790. */
  3791. function enableDebugTools(ref) {
  3792. exportNgVar(PROFILER_GLOBAL_NAME, new AngularProfiler(ref));
  3793. return ref;
  3794. }
  3795. /**
  3796. * Disables Angular tools.
  3797. *
  3798. * \@experimental All debugging apis are currently experimental.
  3799. * @return {?}
  3800. */
  3801. function disableDebugTools() {
  3802. exportNgVar(PROFILER_GLOBAL_NAME, null);
  3803. }
  3804. /**
  3805. * @fileoverview added by tsickle
  3806. * @suppress {checkTypes} checked by tsc
  3807. */
  3808. /**
  3809. * @license
  3810. * Copyright Google Inc. All Rights Reserved.
  3811. *
  3812. * Use of this source code is governed by an MIT-style license that can be
  3813. * found in the LICENSE file at https://angular.io/license
  3814. */
  3815. /**
  3816. * @param {?} text
  3817. * @return {?}
  3818. */
  3819. function escapeHtml(text) {
  3820. const /** @type {?} */ escapedText = {
  3821. '&': '&a;',
  3822. '"': '&q;',
  3823. '\'': '&s;',
  3824. '<': '&l;',
  3825. '>': '&g;',
  3826. };
  3827. return text.replace(/[&"'<>]/g, s => escapedText[s]);
  3828. }
  3829. /**
  3830. * @param {?} text
  3831. * @return {?}
  3832. */
  3833. function unescapeHtml(text) {
  3834. const /** @type {?} */ unescapedText = {
  3835. '&a;': '&',
  3836. '&q;': '"',
  3837. '&s;': '\'',
  3838. '&l;': '<',
  3839. '&g;': '>',
  3840. };
  3841. return text.replace(/&[^;]+;/g, s => unescapedText[s]);
  3842. }
  3843. /**
  3844. * Create a `StateKey<T>` that can be used to store value of type T with `TransferState`.
  3845. *
  3846. * Example:
  3847. *
  3848. * ```
  3849. * const COUNTER_KEY = makeStateKey<number>('counter');
  3850. * let value = 10;
  3851. *
  3852. * transferState.set(COUNTER_KEY, value);
  3853. * ```
  3854. *
  3855. * \@experimental
  3856. * @template T
  3857. * @param {?} key
  3858. * @return {?}
  3859. */
  3860. function makeStateKey(key) {
  3861. return /** @type {?} */ (key);
  3862. }
  3863. /**
  3864. * A key value store that is transferred from the application on the server side to the application
  3865. * on the client side.
  3866. *
  3867. * `TransferState` will be available as an injectable token. To use it import
  3868. * `ServerTransferStateModule` on the server and `BrowserTransferStateModule` on the client.
  3869. *
  3870. * The values in the store are serialized/deserialized using JSON.stringify/JSON.parse. So only
  3871. * boolean, number, string, null and non-class objects will be serialized and deserialzied in a
  3872. * non-lossy manner.
  3873. *
  3874. * \@experimental
  3875. */
  3876. class TransferState {
  3877. constructor() {
  3878. this.store = {};
  3879. this.onSerializeCallbacks = {};
  3880. }
  3881. /**
  3882. * \@internal
  3883. * @param {?} initState
  3884. * @return {?}
  3885. */
  3886. static init(initState) {
  3887. const /** @type {?} */ transferState = new TransferState();
  3888. transferState.store = initState;
  3889. return transferState;
  3890. }
  3891. /**
  3892. * Get the value corresponding to a key. Return `defaultValue` if key is not found.
  3893. * @template T
  3894. * @param {?} key
  3895. * @param {?} defaultValue
  3896. * @return {?}
  3897. */
  3898. get(key, defaultValue) {
  3899. return this.store[key] !== undefined ? /** @type {?} */ (this.store[key]) : defaultValue;
  3900. }
  3901. /**
  3902. * Set the value corresponding to a key.
  3903. * @template T
  3904. * @param {?} key
  3905. * @param {?} value
  3906. * @return {?}
  3907. */
  3908. set(key, value) { this.store[key] = value; }
  3909. /**
  3910. * Remove a key from the store.
  3911. * @template T
  3912. * @param {?} key
  3913. * @return {?}
  3914. */
  3915. remove(key) { delete this.store[key]; }
  3916. /**
  3917. * Test whether a key exists in the store.
  3918. * @template T
  3919. * @param {?} key
  3920. * @return {?}
  3921. */
  3922. hasKey(key) { return this.store.hasOwnProperty(key); }
  3923. /**
  3924. * Register a callback to provide the value for a key when `toJson` is called.
  3925. * @template T
  3926. * @param {?} key
  3927. * @param {?} callback
  3928. * @return {?}
  3929. */
  3930. onSerialize(key, callback) {
  3931. this.onSerializeCallbacks[key] = callback;
  3932. }
  3933. /**
  3934. * Serialize the current state of the store to JSON.
  3935. * @return {?}
  3936. */
  3937. toJson() {
  3938. // Call the onSerialize callbacks and put those values into the store.
  3939. for (const /** @type {?} */ key in this.onSerializeCallbacks) {
  3940. if (this.onSerializeCallbacks.hasOwnProperty(key)) {
  3941. try {
  3942. this.store[key] = this.onSerializeCallbacks[key]();
  3943. }
  3944. catch (/** @type {?} */ e) {
  3945. console.warn('Exception in onSerialize callback: ', e);
  3946. }
  3947. }
  3948. }
  3949. return JSON.stringify(this.store);
  3950. }
  3951. }
  3952. TransferState.decorators = [
  3953. { type: Injectable },
  3954. ];
  3955. /** @nocollapse */
  3956. TransferState.ctorParameters = () => [];
  3957. /**
  3958. * @param {?} doc
  3959. * @param {?} appId
  3960. * @return {?}
  3961. */
  3962. function initTransferState(doc, appId) {
  3963. // Locate the script tag with the JSON data transferred from the server.
  3964. // The id of the script tag is set to the Angular appId + 'state'.
  3965. const /** @type {?} */ script = doc.getElementById(appId + '-state');
  3966. let /** @type {?} */ initialState = {};
  3967. if (script && script.textContent) {
  3968. try {
  3969. initialState = JSON.parse(unescapeHtml(script.textContent));
  3970. }
  3971. catch (/** @type {?} */ e) {
  3972. console.warn('Exception while restoring TransferState for app ' + appId, e);
  3973. }
  3974. }
  3975. return TransferState.init(initialState);
  3976. }
  3977. /**
  3978. * NgModule to install on the client side while using the `TransferState` to transfer state from
  3979. * server to client.
  3980. *
  3981. * \@experimental
  3982. */
  3983. class BrowserTransferStateModule {
  3984. }
  3985. BrowserTransferStateModule.decorators = [
  3986. { type: NgModule, args: [{
  3987. providers: [{ provide: TransferState, useFactory: initTransferState, deps: [DOCUMENT$1, APP_ID] }],
  3988. },] },
  3989. ];
  3990. /** @nocollapse */
  3991. BrowserTransferStateModule.ctorParameters = () => [];
  3992. /**
  3993. * @fileoverview added by tsickle
  3994. * @suppress {checkTypes} checked by tsc
  3995. */
  3996. /**
  3997. * @license
  3998. * Copyright Google Inc. All Rights Reserved.
  3999. *
  4000. * Use of this source code is governed by an MIT-style license that can be
  4001. * found in the LICENSE file at https://angular.io/license
  4002. */
  4003. /**
  4004. * Predicates for use with {\@link DebugElement}'s query functions.
  4005. *
  4006. * \@experimental All debugging apis are currently experimental.
  4007. */
  4008. class By {
  4009. /**
  4010. * Match all elements.
  4011. *
  4012. * ## Example
  4013. *
  4014. * {\@example platform-browser/dom/debug/ts/by/by.ts region='by_all'}
  4015. * @return {?}
  4016. */
  4017. static all() { return (debugElement) => true; }
  4018. /**
  4019. * Match elements by the given CSS selector.
  4020. *
  4021. * ## Example
  4022. *
  4023. * {\@example platform-browser/dom/debug/ts/by/by.ts region='by_css'}
  4024. * @param {?} selector
  4025. * @return {?}
  4026. */
  4027. static css(selector) {
  4028. return (debugElement) => {
  4029. return debugElement.nativeElement != null ?
  4030. getDOM().elementMatches(debugElement.nativeElement, selector) :
  4031. false;
  4032. };
  4033. }
  4034. /**
  4035. * Match elements that have the given directive present.
  4036. *
  4037. * ## Example
  4038. *
  4039. * {\@example platform-browser/dom/debug/ts/by/by.ts region='by_directive'}
  4040. * @param {?} type
  4041. * @return {?}
  4042. */
  4043. static directive(type) {
  4044. return (debugElement) => /** @type {?} */ ((debugElement.providerTokens)).indexOf(type) !== -1;
  4045. }
  4046. }
  4047. /**
  4048. * @fileoverview added by tsickle
  4049. * @suppress {checkTypes} checked by tsc
  4050. */
  4051. /**
  4052. * @license
  4053. * Copyright Google Inc. All Rights Reserved.
  4054. *
  4055. * Use of this source code is governed by an MIT-style license that can be
  4056. * found in the LICENSE file at https://angular.io/license
  4057. */
  4058. /**
  4059. * @fileoverview added by tsickle
  4060. * @suppress {checkTypes} checked by tsc
  4061. */
  4062. /**
  4063. * @license
  4064. * Copyright Google Inc. All Rights Reserved.
  4065. *
  4066. * Use of this source code is governed by an MIT-style license that can be
  4067. * found in the LICENSE file at https://angular.io/license
  4068. */
  4069. /**
  4070. * \@stable
  4071. */
  4072. const VERSION = new Version('5.2.11');
  4073. /**
  4074. * @fileoverview added by tsickle
  4075. * @suppress {checkTypes} checked by tsc
  4076. */
  4077. /**
  4078. * @license
  4079. * Copyright Google Inc. All Rights Reserved.
  4080. *
  4081. * Use of this source code is governed by an MIT-style license that can be
  4082. * found in the LICENSE file at https://angular.io/license
  4083. */
  4084. /**
  4085. * @fileoverview added by tsickle
  4086. * @suppress {checkTypes} checked by tsc
  4087. */
  4088. /**
  4089. * @license
  4090. * Copyright Google Inc. All Rights Reserved.
  4091. *
  4092. * Use of this source code is governed by an MIT-style license that can be
  4093. * found in the LICENSE file at https://angular.io/license
  4094. */
  4095. /**
  4096. * @module
  4097. * @description
  4098. * Entry point for all public APIs of this package.
  4099. */
  4100. // This file only reexports content of the `src` folder. Keep it that way.
  4101. /**
  4102. * @fileoverview added by tsickle
  4103. * @suppress {checkTypes} checked by tsc
  4104. */
  4105. /**
  4106. * Generated bundle index. Do not edit.
  4107. */
  4108. export { BrowserModule, platformBrowser, Meta, Title, disableDebugTools, enableDebugTools, BrowserTransferStateModule, TransferState, makeStateKey, By, DOCUMENT$1 as DOCUMENT, EVENT_MANAGER_PLUGINS, EventManager, HAMMER_GESTURE_CONFIG, HammerGestureConfig, DomSanitizer, VERSION, BROWSER_SANITIZATION_PROVIDERS as ɵBROWSER_SANITIZATION_PROVIDERS, INTERNAL_BROWSER_PLATFORM_PROVIDERS as ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS, initDomAdapter as ɵinitDomAdapter, BrowserDomAdapter as ɵBrowserDomAdapter, BrowserPlatformLocation as ɵBrowserPlatformLocation, TRANSITION_ID as ɵTRANSITION_ID, BrowserGetTestability as ɵBrowserGetTestability, escapeHtml as ɵescapeHtml, ELEMENT_PROBE_PROVIDERS as ɵELEMENT_PROBE_PROVIDERS, DomAdapter as ɵDomAdapter, getDOM as ɵgetDOM, setRootDomAdapter as ɵsetRootDomAdapter, DomRendererFactory2 as ɵDomRendererFactory2, NAMESPACE_URIS as ɵNAMESPACE_URIS, flattenStyles as ɵflattenStyles, shimContentAttribute as ɵshimContentAttribute, shimHostAttribute as ɵshimHostAttribute, DomEventsPlugin as ɵDomEventsPlugin, HammerGesturesPlugin as ɵHammerGesturesPlugin, KeyEventsPlugin as ɵKeyEventsPlugin, DomSharedStylesHost as ɵDomSharedStylesHost, SharedStylesHost as ɵSharedStylesHost, _document as ɵb, errorHandler as ɵa, GenericBrowserDomAdapter as ɵi, SERVER_TRANSITION_PROVIDERS as ɵg, appInitializerFactory as ɵf, initTransferState as ɵc, _createNgProbe as ɵh, EventManagerPlugin as ɵd, DomSanitizerImpl as ɵe };
  4109. //# sourceMappingURL=platform-browser.js.map