vue.common.js 135 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461
  1. 'use strict';
  2. /* */
  3. /**
  4. * Convert a value to a string that is actually rendered.
  5. */
  6. function _toString (val) {
  7. return val == null
  8. ? ''
  9. : typeof val === 'object'
  10. ? JSON.stringify(val, null, 2)
  11. : String(val)
  12. }
  13. /**
  14. * Convert a input value to a number for persistence.
  15. * If the conversion fails, return original string.
  16. */
  17. function toNumber (val) {
  18. var n = parseFloat(val, 10)
  19. return (n || n === 0) ? n : val
  20. }
  21. /**
  22. * Make a map and return a function for checking if a key
  23. * is in that map.
  24. */
  25. function makeMap (
  26. str,
  27. expectsLowerCase
  28. ) {
  29. var map = Object.create(null)
  30. var list = str.split(',')
  31. for (var i = 0; i < list.length; i++) {
  32. map[list[i]] = true
  33. }
  34. return expectsLowerCase
  35. ? function (val) { return map[val.toLowerCase()]; }
  36. : function (val) { return map[val]; }
  37. }
  38. /**
  39. * Check if a tag is a built-in tag.
  40. */
  41. var isBuiltInTag = makeMap('slot,component', true)
  42. /**
  43. * Remove an item from an array
  44. */
  45. function remove (arr, item) {
  46. if (arr.length) {
  47. var index = arr.indexOf(item)
  48. if (index > -1) {
  49. return arr.splice(index, 1)
  50. }
  51. }
  52. }
  53. /**
  54. * Check whether the object has the property.
  55. */
  56. var hasOwnProperty = Object.prototype.hasOwnProperty
  57. function hasOwn (obj, key) {
  58. return hasOwnProperty.call(obj, key)
  59. }
  60. /**
  61. * Check if value is primitive
  62. */
  63. function isPrimitive (value) {
  64. return typeof value === 'string' || typeof value === 'number'
  65. }
  66. /**
  67. * Create a cached version of a pure function.
  68. */
  69. function cached (fn) {
  70. var cache = Object.create(null)
  71. return function cachedFn (str) {
  72. var hit = cache[str]
  73. return hit || (cache[str] = fn(str))
  74. }
  75. }
  76. /**
  77. * Camelize a hyphen-delmited string.
  78. */
  79. var camelizeRE = /-(\w)/g
  80. var camelize = cached(function (str) {
  81. return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })
  82. })
  83. /**
  84. * Capitalize a string.
  85. */
  86. var capitalize = cached(function (str) {
  87. return str.charAt(0).toUpperCase() + str.slice(1)
  88. })
  89. /**
  90. * Hyphenate a camelCase string.
  91. */
  92. var hyphenateRE = /([^-])([A-Z])/g
  93. var hyphenate = cached(function (str) {
  94. return str
  95. .replace(hyphenateRE, '$1-$2')
  96. .replace(hyphenateRE, '$1-$2')
  97. .toLowerCase()
  98. })
  99. /**
  100. * Simple bind, faster than native
  101. */
  102. function bind (fn, ctx) {
  103. function boundFn (a) {
  104. var l = arguments.length
  105. return l
  106. ? l > 1
  107. ? fn.apply(ctx, arguments)
  108. : fn.call(ctx, a)
  109. : fn.call(ctx)
  110. }
  111. // record original fn length
  112. boundFn._length = fn.length
  113. return boundFn
  114. }
  115. /**
  116. * Convert an Array-like object to a real Array.
  117. */
  118. function toArray (list, start) {
  119. start = start || 0
  120. var i = list.length - start
  121. var ret = new Array(i)
  122. while (i--) {
  123. ret[i] = list[i + start]
  124. }
  125. return ret
  126. }
  127. /**
  128. * Mix properties into target object.
  129. */
  130. function extend (to, _from) {
  131. for (var key in _from) {
  132. to[key] = _from[key]
  133. }
  134. return to
  135. }
  136. /**
  137. * Quick object check - this is primarily used to tell
  138. * Objects from primitive values when we know the value
  139. * is a JSON-compliant type.
  140. */
  141. function isObject (obj) {
  142. return obj !== null && typeof obj === 'object'
  143. }
  144. /**
  145. * Strict object type check. Only returns true
  146. * for plain JavaScript objects.
  147. */
  148. var toString = Object.prototype.toString
  149. var OBJECT_STRING = '[object Object]'
  150. function isPlainObject (obj) {
  151. return toString.call(obj) === OBJECT_STRING
  152. }
  153. /**
  154. * Merge an Array of Objects into a single Object.
  155. */
  156. function toObject (arr) {
  157. var res = {}
  158. for (var i = 0; i < arr.length; i++) {
  159. if (arr[i]) {
  160. extend(res, arr[i])
  161. }
  162. }
  163. return res
  164. }
  165. /**
  166. * Perform no operation.
  167. */
  168. function noop () {}
  169. /**
  170. * Always return false.
  171. */
  172. var no = function () { return false; }
  173. /**
  174. * Generate a static keys string from compiler modules.
  175. */
  176. function genStaticKeys (modules) {
  177. return modules.reduce(function (keys, m) {
  178. return keys.concat(m.staticKeys || [])
  179. }, []).join(',')
  180. }
  181. /* */
  182. var config = {
  183. /**
  184. * Option merge strategies (used in core/util/options)
  185. */
  186. optionMergeStrategies: Object.create(null),
  187. /**
  188. * Whether to suppress warnings.
  189. */
  190. silent: false,
  191. /**
  192. * Whether to enable devtools
  193. */
  194. devtools: process.env.NODE_ENV !== 'production',
  195. /**
  196. * Error handler for watcher errors
  197. */
  198. errorHandler: null,
  199. /**
  200. * Ignore certain custom elements
  201. */
  202. ignoredElements: null,
  203. /**
  204. * Custom user key aliases for v-on
  205. */
  206. keyCodes: Object.create(null),
  207. /**
  208. * Check if a tag is reserved so that it cannot be registered as a
  209. * component. This is platform-dependent and may be overwritten.
  210. */
  211. isReservedTag: no,
  212. /**
  213. * Check if a tag is an unknown element.
  214. * Platform-dependent.
  215. */
  216. isUnknownElement: no,
  217. /**
  218. * Get the namespace of an element
  219. */
  220. getTagNamespace: noop,
  221. /**
  222. * Check if an attribute must be bound using property, e.g. value
  223. * Platform-dependent.
  224. */
  225. mustUseProp: no,
  226. /**
  227. * List of asset types that a component can own.
  228. */
  229. _assetTypes: [
  230. 'component',
  231. 'directive',
  232. 'filter'
  233. ],
  234. /**
  235. * List of lifecycle hooks.
  236. */
  237. _lifecycleHooks: [
  238. 'beforeCreate',
  239. 'created',
  240. 'beforeMount',
  241. 'mounted',
  242. 'beforeUpdate',
  243. 'updated',
  244. 'beforeDestroy',
  245. 'destroyed',
  246. 'activated',
  247. 'deactivated'
  248. ],
  249. /**
  250. * Max circular updates allowed in a scheduler flush cycle.
  251. */
  252. _maxUpdateCount: 100,
  253. /**
  254. * Server rendering?
  255. */
  256. _isServer: process.env.VUE_ENV === 'server'
  257. }
  258. /* */
  259. /**
  260. * Check if a string starts with $ or _
  261. */
  262. function isReserved (str) {
  263. var c = (str + '').charCodeAt(0)
  264. return c === 0x24 || c === 0x5F
  265. }
  266. /**
  267. * Define a property.
  268. */
  269. function def (obj, key, val, enumerable) {
  270. Object.defineProperty(obj, key, {
  271. value: val,
  272. enumerable: !!enumerable,
  273. writable: true,
  274. configurable: true
  275. })
  276. }
  277. /**
  278. * Parse simple path.
  279. */
  280. var bailRE = /[^\w\.\$]/
  281. function parsePath (path) {
  282. if (bailRE.test(path)) {
  283. return
  284. } else {
  285. var segments = path.split('.')
  286. return function (obj) {
  287. for (var i = 0; i < segments.length; i++) {
  288. if (!obj) return
  289. obj = obj[segments[i]]
  290. }
  291. return obj
  292. }
  293. }
  294. }
  295. /* */
  296. /* global MutationObserver */
  297. // can we use __proto__?
  298. var hasProto = '__proto__' in {}
  299. // Browser environment sniffing
  300. var inBrowser =
  301. typeof window !== 'undefined' &&
  302. Object.prototype.toString.call(window) !== '[object Object]'
  303. // detect devtools
  304. var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__
  305. // UA sniffing for working around browser-specific quirks
  306. var UA = inBrowser && window.navigator.userAgent.toLowerCase()
  307. var isIos = UA && /(iphone|ipad|ipod|ios)/i.test(UA)
  308. var iosVersionMatch = UA && isIos && UA.match(/os ([\d_]+)/)
  309. var iosVersion = iosVersionMatch && iosVersionMatch[1].split('_')
  310. // MutationObserver is unreliable in iOS 9.3 UIWebView
  311. // detecting it by checking presence of IndexedDB
  312. // ref #3027
  313. var hasMutationObserverBug =
  314. iosVersion &&
  315. Number(iosVersion[0]) >= 9 &&
  316. Number(iosVersion[1]) >= 3 &&
  317. !window.indexedDB
  318. /**
  319. * Defer a task to execute it asynchronously. Ideally this
  320. * should be executed as a microtask, so we leverage
  321. * MutationObserver if it's available, and fallback to
  322. * setTimeout(0).
  323. *
  324. * @param {Function} cb
  325. * @param {Object} ctx
  326. */
  327. var nextTick = (function () {
  328. var callbacks = []
  329. var pending = false
  330. var timerFunc
  331. function nextTickHandler () {
  332. pending = false
  333. var copies = callbacks.slice(0)
  334. callbacks = []
  335. for (var i = 0; i < copies.length; i++) {
  336. copies[i]()
  337. }
  338. }
  339. /* istanbul ignore else */
  340. if (typeof MutationObserver !== 'undefined' && !hasMutationObserverBug) {
  341. var counter = 1
  342. var observer = new MutationObserver(nextTickHandler)
  343. var textNode = document.createTextNode(String(counter))
  344. observer.observe(textNode, {
  345. characterData: true
  346. })
  347. timerFunc = function () {
  348. counter = (counter + 1) % 2
  349. textNode.data = String(counter)
  350. }
  351. } else {
  352. // webpack attempts to inject a shim for setImmediate
  353. // if it is used as a global, so we have to work around that to
  354. // avoid bundling unnecessary code.
  355. var context = inBrowser
  356. ? window
  357. : typeof global !== 'undefined' ? global : {}
  358. timerFunc = context.setImmediate || setTimeout
  359. }
  360. return function (cb, ctx) {
  361. var func = ctx
  362. ? function () { cb.call(ctx) }
  363. : cb
  364. callbacks.push(func)
  365. if (pending) return
  366. pending = true
  367. timerFunc(nextTickHandler, 0)
  368. }
  369. })()
  370. var _Set
  371. /* istanbul ignore if */
  372. if (typeof Set !== 'undefined' && /native code/.test(Set.toString())) {
  373. // use native Set when available.
  374. _Set = Set
  375. } else {
  376. // a non-standard Set polyfill that only works with primitive keys.
  377. _Set = (function () {
  378. function Set () {
  379. this.set = Object.create(null)
  380. }
  381. Set.prototype.has = function has (key) {
  382. return this.set[key] !== undefined
  383. };
  384. Set.prototype.add = function add (key) {
  385. this.set[key] = 1
  386. };
  387. Set.prototype.clear = function clear () {
  388. this.set = Object.create(null)
  389. };
  390. return Set;
  391. }())
  392. }
  393. /* not type checking this file because flow doesn't play well with Proxy */
  394. var hasProxy;
  395. var proxyHandlers;
  396. var initProxy;
  397. if (process.env.NODE_ENV !== 'production') {
  398. var allowedGlobals = makeMap(
  399. 'Infinity,undefined,NaN,isFinite,isNaN,' +
  400. 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
  401. 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
  402. 'require' // for Webpack/Browserify
  403. )
  404. hasProxy =
  405. typeof Proxy !== 'undefined' &&
  406. Proxy.toString().match(/native code/)
  407. proxyHandlers = {
  408. has: function has (target, key) {
  409. var has = key in target
  410. var isAllowed = allowedGlobals(key) || key.charAt(0) === '_'
  411. if (!has && !isAllowed) {
  412. warn(
  413. "Property or method \"" + key + "\" is not defined on the instance but " +
  414. "referenced during render. Make sure to declare reactive data " +
  415. "properties in the data option.",
  416. target
  417. )
  418. }
  419. return has || !isAllowed
  420. }
  421. }
  422. initProxy = function initProxy (vm) {
  423. if (hasProxy) {
  424. vm._renderProxy = new Proxy(vm, proxyHandlers)
  425. } else {
  426. vm._renderProxy = vm
  427. }
  428. }
  429. }
  430. /* */
  431. var uid$2 = 0
  432. /**
  433. * A dep is an observable that can have multiple
  434. * directives subscribing to it.
  435. */
  436. var Dep = function Dep () {
  437. this.id = uid$2++
  438. this.subs = []
  439. };
  440. Dep.prototype.addSub = function addSub (sub) {
  441. this.subs.push(sub)
  442. };
  443. Dep.prototype.removeSub = function removeSub (sub) {
  444. remove(this.subs, sub)
  445. };
  446. Dep.prototype.depend = function depend () {
  447. if (Dep.target) {
  448. Dep.target.addDep(this)
  449. }
  450. };
  451. Dep.prototype.notify = function notify () {
  452. // stablize the subscriber list first
  453. var subs = this.subs.slice()
  454. for (var i = 0, l = subs.length; i < l; i++) {
  455. subs[i].update()
  456. }
  457. };
  458. // the current target watcher being evaluated.
  459. // this is globally unique because there could be only one
  460. // watcher being evaluated at any time.
  461. Dep.target = null
  462. var targetStack = []
  463. function pushTarget (_target) {
  464. if (Dep.target) targetStack.push(Dep.target)
  465. Dep.target = _target
  466. }
  467. function popTarget () {
  468. Dep.target = targetStack.pop()
  469. }
  470. /* */
  471. var queue = []
  472. var has = {}
  473. var circular = {}
  474. var waiting = false
  475. var flushing = false
  476. var index = 0
  477. /**
  478. * Reset the scheduler's state.
  479. */
  480. function resetSchedulerState () {
  481. queue.length = 0
  482. has = {}
  483. if (process.env.NODE_ENV !== 'production') {
  484. circular = {}
  485. }
  486. waiting = flushing = false
  487. }
  488. /**
  489. * Flush both queues and run the watchers.
  490. */
  491. function flushSchedulerQueue () {
  492. flushing = true
  493. // Sort queue before flush.
  494. // This ensures that:
  495. // 1. Components are updated from parent to child. (because parent is always
  496. // created before the child)
  497. // 2. A component's user watchers are run before its render watcher (because
  498. // user watchers are created before the render watcher)
  499. // 3. If a component is destroyed during a parent component's watcher run,
  500. // its watchers can be skipped.
  501. queue.sort(function (a, b) { return a.id - b.id; })
  502. // do not cache length because more watchers might be pushed
  503. // as we run existing watchers
  504. for (index = 0; index < queue.length; index++) {
  505. var watcher = queue[index]
  506. var id = watcher.id
  507. has[id] = null
  508. watcher.run()
  509. // in dev build, check and stop circular updates.
  510. if (process.env.NODE_ENV !== 'production' && has[id] != null) {
  511. circular[id] = (circular[id] || 0) + 1
  512. if (circular[id] > config._maxUpdateCount) {
  513. warn(
  514. 'You may have an infinite update loop ' + (
  515. watcher.user
  516. ? ("in watcher with expression \"" + (watcher.expression) + "\"")
  517. : "in a component render function."
  518. ),
  519. watcher.vm
  520. )
  521. break
  522. }
  523. }
  524. }
  525. // devtool hook
  526. /* istanbul ignore if */
  527. if (devtools && config.devtools) {
  528. devtools.emit('flush')
  529. }
  530. resetSchedulerState()
  531. }
  532. /**
  533. * Push a watcher into the watcher queue.
  534. * Jobs with duplicate IDs will be skipped unless it's
  535. * pushed when the queue is being flushed.
  536. */
  537. function queueWatcher (watcher) {
  538. var id = watcher.id
  539. if (has[id] == null) {
  540. has[id] = true
  541. if (!flushing) {
  542. queue.push(watcher)
  543. } else {
  544. // if already flushing, splice the watcher based on its id
  545. // if already past its id, it will be run next immediately.
  546. var i = queue.length - 1
  547. while (i >= 0 && queue[i].id > watcher.id) {
  548. i--
  549. }
  550. queue.splice(Math.max(i, index) + 1, 0, watcher)
  551. }
  552. // queue the flush
  553. if (!waiting) {
  554. waiting = true
  555. nextTick(flushSchedulerQueue)
  556. }
  557. }
  558. }
  559. /* */
  560. var uid$1 = 0
  561. /**
  562. * A watcher parses an expression, collects dependencies,
  563. * and fires callback when the expression value changes.
  564. * This is used for both the $watch() api and directives.
  565. */
  566. var Watcher = function Watcher (
  567. vm,
  568. expOrFn,
  569. cb,
  570. options
  571. ) {
  572. if ( options === void 0 ) options = {};
  573. this.vm = vm
  574. vm._watchers.push(this)
  575. // options
  576. this.deep = !!options.deep
  577. this.user = !!options.user
  578. this.lazy = !!options.lazy
  579. this.sync = !!options.sync
  580. this.expression = expOrFn.toString()
  581. this.cb = cb
  582. this.id = ++uid$1 // uid for batching
  583. this.active = true
  584. this.dirty = this.lazy // for lazy watchers
  585. this.deps = []
  586. this.newDeps = []
  587. this.depIds = new _Set()
  588. this.newDepIds = new _Set()
  589. // parse expression for getter
  590. if (typeof expOrFn === 'function') {
  591. this.getter = expOrFn
  592. } else {
  593. this.getter = parsePath(expOrFn)
  594. if (!this.getter) {
  595. this.getter = function () {}
  596. process.env.NODE_ENV !== 'production' && warn(
  597. "Failed watching path: \"" + expOrFn + "\" " +
  598. 'Watcher only accepts simple dot-delimited paths. ' +
  599. 'For full control, use a function instead.',
  600. vm
  601. )
  602. }
  603. }
  604. this.value = this.lazy
  605. ? undefined
  606. : this.get()
  607. };
  608. /**
  609. * Evaluate the getter, and re-collect dependencies.
  610. */
  611. Watcher.prototype.get = function get () {
  612. pushTarget(this)
  613. var value = this.getter.call(this.vm, this.vm)
  614. // "touch" every property so they are all tracked as
  615. // dependencies for deep watching
  616. if (this.deep) {
  617. traverse(value)
  618. }
  619. popTarget()
  620. this.cleanupDeps()
  621. return value
  622. };
  623. /**
  624. * Add a dependency to this directive.
  625. */
  626. Watcher.prototype.addDep = function addDep (dep) {
  627. var id = dep.id
  628. if (!this.newDepIds.has(id)) {
  629. this.newDepIds.add(id)
  630. this.newDeps.push(dep)
  631. if (!this.depIds.has(id)) {
  632. dep.addSub(this)
  633. }
  634. }
  635. };
  636. /**
  637. * Clean up for dependency collection.
  638. */
  639. Watcher.prototype.cleanupDeps = function cleanupDeps () {
  640. var this$1 = this;
  641. var i = this.deps.length
  642. while (i--) {
  643. var dep = this$1.deps[i]
  644. if (!this$1.newDepIds.has(dep.id)) {
  645. dep.removeSub(this$1)
  646. }
  647. }
  648. var tmp = this.depIds
  649. this.depIds = this.newDepIds
  650. this.newDepIds = tmp
  651. this.newDepIds.clear()
  652. tmp = this.deps
  653. this.deps = this.newDeps
  654. this.newDeps = tmp
  655. this.newDeps.length = 0
  656. };
  657. /**
  658. * Subscriber interface.
  659. * Will be called when a dependency changes.
  660. */
  661. Watcher.prototype.update = function update () {
  662. /* istanbul ignore else */
  663. if (this.lazy) {
  664. this.dirty = true
  665. } else if (this.sync) {
  666. this.run()
  667. } else {
  668. queueWatcher(this)
  669. }
  670. };
  671. /**
  672. * Scheduler job interface.
  673. * Will be called by the scheduler.
  674. */
  675. Watcher.prototype.run = function run () {
  676. if (this.active) {
  677. var value = this.get()
  678. if (
  679. value !== this.value ||
  680. // Deep watchers and watchers on Object/Arrays should fire even
  681. // when the value is the same, because the value may
  682. // have mutated.
  683. isObject(value) ||
  684. this.deep
  685. ) {
  686. // set new value
  687. var oldValue = this.value
  688. this.value = value
  689. if (this.user) {
  690. try {
  691. this.cb.call(this.vm, value, oldValue)
  692. } catch (e) {
  693. process.env.NODE_ENV !== 'production' && warn(
  694. ("Error in watcher \"" + (this.expression) + "\""),
  695. this.vm
  696. )
  697. /* istanbul ignore else */
  698. if (config.errorHandler) {
  699. config.errorHandler.call(null, e, this.vm)
  700. } else {
  701. throw e
  702. }
  703. }
  704. } else {
  705. this.cb.call(this.vm, value, oldValue)
  706. }
  707. }
  708. }
  709. };
  710. /**
  711. * Evaluate the value of the watcher.
  712. * This only gets called for lazy watchers.
  713. */
  714. Watcher.prototype.evaluate = function evaluate () {
  715. this.value = this.get()
  716. this.dirty = false
  717. };
  718. /**
  719. * Depend on all deps collected by this watcher.
  720. */
  721. Watcher.prototype.depend = function depend () {
  722. var this$1 = this;
  723. var i = this.deps.length
  724. while (i--) {
  725. this$1.deps[i].depend()
  726. }
  727. };
  728. /**
  729. * Remove self from all dependencies' subcriber list.
  730. */
  731. Watcher.prototype.teardown = function teardown () {
  732. var this$1 = this;
  733. if (this.active) {
  734. // remove self from vm's watcher list
  735. // this is a somewhat expensive operation so we skip it
  736. // if the vm is being destroyed or is performing a v-for
  737. // re-render (the watcher list is then filtered by v-for).
  738. if (!this.vm._isBeingDestroyed && !this.vm._vForRemoving) {
  739. remove(this.vm._watchers, this)
  740. }
  741. var i = this.deps.length
  742. while (i--) {
  743. this$1.deps[i].removeSub(this$1)
  744. }
  745. this.active = false
  746. }
  747. };
  748. /**
  749. * Recursively traverse an object to evoke all converted
  750. * getters, so that every nested property inside the object
  751. * is collected as a "deep" dependency.
  752. */
  753. var seenObjects = new _Set()
  754. function traverse (val, seen) {
  755. var i, keys
  756. if (!seen) {
  757. seen = seenObjects
  758. seen.clear()
  759. }
  760. var isA = Array.isArray(val)
  761. var isO = isObject(val)
  762. if ((isA || isO) && Object.isExtensible(val)) {
  763. if (val.__ob__) {
  764. var depId = val.__ob__.dep.id
  765. if (seen.has(depId)) {
  766. return
  767. } else {
  768. seen.add(depId)
  769. }
  770. }
  771. if (isA) {
  772. i = val.length
  773. while (i--) traverse(val[i], seen)
  774. } else if (isO) {
  775. keys = Object.keys(val)
  776. i = keys.length
  777. while (i--) traverse(val[keys[i]], seen)
  778. }
  779. }
  780. }
  781. /*
  782. * not type checking this file because flow doesn't play well with
  783. * dynamically accessing methods on Array prototype
  784. */
  785. var arrayProto = Array.prototype
  786. var arrayMethods = Object.create(arrayProto)
  787. /**
  788. * Intercept mutating methods and emit events
  789. */
  790. ;[
  791. 'push',
  792. 'pop',
  793. 'shift',
  794. 'unshift',
  795. 'splice',
  796. 'sort',
  797. 'reverse'
  798. ]
  799. .forEach(function (method) {
  800. // cache original method
  801. var original = arrayProto[method]
  802. def(arrayMethods, method, function mutator () {
  803. var arguments$1 = arguments;
  804. // avoid leaking arguments:
  805. // http://jsperf.com/closure-with-arguments
  806. var i = arguments.length
  807. var args = new Array(i)
  808. while (i--) {
  809. args[i] = arguments$1[i]
  810. }
  811. var result = original.apply(this, args)
  812. var ob = this.__ob__
  813. var inserted
  814. switch (method) {
  815. case 'push':
  816. inserted = args
  817. break
  818. case 'unshift':
  819. inserted = args
  820. break
  821. case 'splice':
  822. inserted = args.slice(2)
  823. break
  824. }
  825. if (inserted) ob.observeArray(inserted)
  826. // notify change
  827. ob.dep.notify()
  828. return result
  829. })
  830. })
  831. /* */
  832. var arrayKeys = Object.getOwnPropertyNames(arrayMethods)
  833. /**
  834. * By default, when a reactive property is set, the new value is
  835. * also converted to become reactive. However when passing down props,
  836. * we don't want to force conversion because the value may be a nested value
  837. * under a frozen data structure. Converting it would defeat the optimization.
  838. */
  839. var observerState = {
  840. shouldConvert: true,
  841. isSettingProps: false
  842. }
  843. /**
  844. * Observer class that are attached to each observed
  845. * object. Once attached, the observer converts target
  846. * object's property keys into getter/setters that
  847. * collect dependencies and dispatches updates.
  848. */
  849. var Observer = function Observer (value) {
  850. this.value = value
  851. this.dep = new Dep()
  852. this.vmCount = 0
  853. def(value, '__ob__', this)
  854. if (Array.isArray(value)) {
  855. var augment = hasProto
  856. ? protoAugment
  857. : copyAugment
  858. augment(value, arrayMethods, arrayKeys)
  859. this.observeArray(value)
  860. } else {
  861. this.walk(value)
  862. }
  863. };
  864. /**
  865. * Walk through each property and convert them into
  866. * getter/setters. This method should only be called when
  867. * value type is Object.
  868. */
  869. Observer.prototype.walk = function walk (obj) {
  870. var keys = Object.keys(obj)
  871. for (var i = 0; i < keys.length; i++) {
  872. defineReactive(obj, keys[i], obj[keys[i]])
  873. }
  874. };
  875. /**
  876. * Observe a list of Array items.
  877. */
  878. Observer.prototype.observeArray = function observeArray (items) {
  879. for (var i = 0, l = items.length; i < l; i++) {
  880. observe(items[i])
  881. }
  882. };
  883. // helpers
  884. /**
  885. * Augment an target Object or Array by intercepting
  886. * the prototype chain using __proto__
  887. */
  888. function protoAugment (target, src) {
  889. /* eslint-disable no-proto */
  890. target.__proto__ = src
  891. /* eslint-enable no-proto */
  892. }
  893. /**
  894. * Augment an target Object or Array by defining
  895. * hidden properties.
  896. *
  897. * istanbul ignore next
  898. */
  899. function copyAugment (target, src, keys) {
  900. for (var i = 0, l = keys.length; i < l; i++) {
  901. var key = keys[i]
  902. def(target, key, src[key])
  903. }
  904. }
  905. /**
  906. * Attempt to create an observer instance for a value,
  907. * returns the new observer if successfully observed,
  908. * or the existing observer if the value already has one.
  909. */
  910. function observe (value) {
  911. if (!isObject(value)) {
  912. return
  913. }
  914. var ob
  915. if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  916. ob = value.__ob__
  917. } else if (
  918. observerState.shouldConvert &&
  919. !config._isServer &&
  920. (Array.isArray(value) || isPlainObject(value)) &&
  921. Object.isExtensible(value) &&
  922. !value._isVue
  923. ) {
  924. ob = new Observer(value)
  925. }
  926. return ob
  927. }
  928. /**
  929. * Define a reactive property on an Object.
  930. */
  931. function defineReactive (
  932. obj,
  933. key,
  934. val,
  935. customSetter
  936. ) {
  937. var dep = new Dep()
  938. var property = Object.getOwnPropertyDescriptor(obj, key)
  939. if (property && property.configurable === false) {
  940. return
  941. }
  942. // cater for pre-defined getter/setters
  943. var getter = property && property.get
  944. var setter = property && property.set
  945. var childOb = observe(val)
  946. Object.defineProperty(obj, key, {
  947. enumerable: true,
  948. configurable: true,
  949. get: function reactiveGetter () {
  950. var value = getter ? getter.call(obj) : val
  951. if (Dep.target) {
  952. dep.depend()
  953. if (childOb) {
  954. childOb.dep.depend()
  955. }
  956. if (Array.isArray(value)) {
  957. for (var e, i = 0, l = value.length; i < l; i++) {
  958. e = value[i]
  959. e && e.__ob__ && e.__ob__.dep.depend()
  960. }
  961. }
  962. }
  963. return value
  964. },
  965. set: function reactiveSetter (newVal) {
  966. var value = getter ? getter.call(obj) : val
  967. if (newVal === value) {
  968. return
  969. }
  970. if (process.env.NODE_ENV !== 'production' && customSetter) {
  971. customSetter()
  972. }
  973. if (setter) {
  974. setter.call(obj, newVal)
  975. } else {
  976. val = newVal
  977. }
  978. childOb = observe(newVal)
  979. dep.notify()
  980. }
  981. })
  982. }
  983. /**
  984. * Set a property on an object. Adds the new property and
  985. * triggers change notification if the property doesn't
  986. * already exist.
  987. */
  988. function set (obj, key, val) {
  989. if (Array.isArray(obj)) {
  990. obj.splice(key, 1, val)
  991. return val
  992. }
  993. if (hasOwn(obj, key)) {
  994. obj[key] = val
  995. return
  996. }
  997. var ob = obj.__ob__
  998. if (obj._isVue || (ob && ob.vmCount)) {
  999. process.env.NODE_ENV !== 'production' && warn(
  1000. 'Avoid adding reactive properties to a Vue instance or its root $data ' +
  1001. 'at runtime - declare it upfront in the data option.'
  1002. )
  1003. return
  1004. }
  1005. if (!ob) {
  1006. obj[key] = val
  1007. return
  1008. }
  1009. defineReactive(ob.value, key, val)
  1010. ob.dep.notify()
  1011. return val
  1012. }
  1013. /**
  1014. * Delete a property and trigger change if necessary.
  1015. */
  1016. function del (obj, key) {
  1017. var ob = obj.__ob__
  1018. if (obj._isVue || (ob && ob.vmCount)) {
  1019. process.env.NODE_ENV !== 'production' && warn(
  1020. 'Avoid deleting properties on a Vue instance or its root $data ' +
  1021. '- just set it to null.'
  1022. )
  1023. return
  1024. }
  1025. if (!hasOwn(obj, key)) {
  1026. return
  1027. }
  1028. delete obj[key]
  1029. if (!ob) {
  1030. return
  1031. }
  1032. ob.dep.notify()
  1033. }
  1034. /* */
  1035. function initState (vm) {
  1036. vm._watchers = []
  1037. initProps(vm)
  1038. initData(vm)
  1039. initComputed(vm)
  1040. initMethods(vm)
  1041. initWatch(vm)
  1042. }
  1043. function initProps (vm) {
  1044. var props = vm.$options.props
  1045. var propsData = vm.$options.propsData
  1046. if (props) {
  1047. var keys = vm.$options._propKeys = Object.keys(props)
  1048. var isRoot = !vm.$parent
  1049. // root instance props should be converted
  1050. observerState.shouldConvert = isRoot
  1051. var loop = function ( i ) {
  1052. var key = keys[i]
  1053. /* istanbul ignore else */
  1054. if (process.env.NODE_ENV !== 'production') {
  1055. defineReactive(vm, key, validateProp(key, props, propsData, vm), function () {
  1056. if (vm.$parent && !observerState.isSettingProps) {
  1057. warn(
  1058. "Avoid mutating a prop directly since the value will be " +
  1059. "overwritten whenever the parent component re-renders. " +
  1060. "Instead, use a data or computed property based on the prop's " +
  1061. "value. Prop being mutated: \"" + key + "\"",
  1062. vm
  1063. )
  1064. }
  1065. })
  1066. } else {
  1067. defineReactive(vm, key, validateProp(key, props, propsData, vm))
  1068. }
  1069. };
  1070. for (var i = 0; i < keys.length; i++) loop( i );
  1071. observerState.shouldConvert = true
  1072. }
  1073. }
  1074. function initData (vm) {
  1075. var data = vm.$options.data
  1076. data = vm._data = typeof data === 'function'
  1077. ? data.call(vm)
  1078. : data || {}
  1079. if (!isPlainObject(data)) {
  1080. data = {}
  1081. process.env.NODE_ENV !== 'production' && warn(
  1082. 'data functions should return an object.',
  1083. vm
  1084. )
  1085. }
  1086. // proxy data on instance
  1087. var keys = Object.keys(data)
  1088. var props = vm.$options.props
  1089. var i = keys.length
  1090. while (i--) {
  1091. if (props && hasOwn(props, keys[i])) {
  1092. process.env.NODE_ENV !== 'production' && warn(
  1093. "The data property \"" + (keys[i]) + "\" is already declared as a prop. " +
  1094. "Use prop default value instead.",
  1095. vm
  1096. )
  1097. } else {
  1098. proxy(vm, keys[i])
  1099. }
  1100. }
  1101. // observe data
  1102. observe(data)
  1103. data.__ob__ && data.__ob__.vmCount++
  1104. }
  1105. var computedSharedDefinition = {
  1106. enumerable: true,
  1107. configurable: true,
  1108. get: noop,
  1109. set: noop
  1110. }
  1111. function initComputed (vm) {
  1112. var computed = vm.$options.computed
  1113. if (computed) {
  1114. for (var key in computed) {
  1115. var userDef = computed[key]
  1116. if (typeof userDef === 'function') {
  1117. computedSharedDefinition.get = makeComputedGetter(userDef, vm)
  1118. computedSharedDefinition.set = noop
  1119. } else {
  1120. computedSharedDefinition.get = userDef.get
  1121. ? userDef.cache !== false
  1122. ? makeComputedGetter(userDef.get, vm)
  1123. : bind(userDef.get, vm)
  1124. : noop
  1125. computedSharedDefinition.set = userDef.set
  1126. ? bind(userDef.set, vm)
  1127. : noop
  1128. }
  1129. Object.defineProperty(vm, key, computedSharedDefinition)
  1130. }
  1131. }
  1132. }
  1133. function makeComputedGetter (getter, owner) {
  1134. var watcher = new Watcher(owner, getter, noop, {
  1135. lazy: true
  1136. })
  1137. return function computedGetter () {
  1138. if (watcher.dirty) {
  1139. watcher.evaluate()
  1140. }
  1141. if (Dep.target) {
  1142. watcher.depend()
  1143. }
  1144. return watcher.value
  1145. }
  1146. }
  1147. function initMethods (vm) {
  1148. var methods = vm.$options.methods
  1149. if (methods) {
  1150. for (var key in methods) {
  1151. if (methods[key] != null) {
  1152. vm[key] = bind(methods[key], vm)
  1153. } else if (process.env.NODE_ENV !== 'production') {
  1154. warn(("Method \"" + key + "\" is undefined in options."), vm)
  1155. }
  1156. }
  1157. }
  1158. }
  1159. function initWatch (vm) {
  1160. var watch = vm.$options.watch
  1161. if (watch) {
  1162. for (var key in watch) {
  1163. var handler = watch[key]
  1164. if (Array.isArray(handler)) {
  1165. for (var i = 0; i < handler.length; i++) {
  1166. createWatcher(vm, key, handler[i])
  1167. }
  1168. } else {
  1169. createWatcher(vm, key, handler)
  1170. }
  1171. }
  1172. }
  1173. }
  1174. function createWatcher (vm, key, handler) {
  1175. var options
  1176. if (isPlainObject(handler)) {
  1177. options = handler
  1178. handler = handler.handler
  1179. }
  1180. if (typeof handler === 'string') {
  1181. handler = vm[handler]
  1182. }
  1183. vm.$watch(key, handler, options)
  1184. }
  1185. function stateMixin (Vue) {
  1186. // flow somehow has problems with directly declared definition object
  1187. // when using Object.defineProperty, so we have to procedurally build up
  1188. // the object here.
  1189. var dataDef = {}
  1190. dataDef.get = function () {
  1191. return this._data
  1192. }
  1193. if (process.env.NODE_ENV !== 'production') {
  1194. dataDef.set = function (newData) {
  1195. warn(
  1196. 'Avoid replacing instance root $data. ' +
  1197. 'Use nested data properties instead.',
  1198. this
  1199. )
  1200. }
  1201. }
  1202. Object.defineProperty(Vue.prototype, '$data', dataDef)
  1203. Vue.prototype.$set = set
  1204. Vue.prototype.$delete = del
  1205. Vue.prototype.$watch = function (
  1206. expOrFn,
  1207. cb,
  1208. options
  1209. ) {
  1210. var vm = this
  1211. options = options || {}
  1212. options.user = true
  1213. var watcher = new Watcher(vm, expOrFn, cb, options)
  1214. if (options.immediate) {
  1215. cb.call(vm, watcher.value)
  1216. }
  1217. return function unwatchFn () {
  1218. watcher.teardown()
  1219. }
  1220. }
  1221. }
  1222. function proxy (vm, key) {
  1223. if (!isReserved(key)) {
  1224. Object.defineProperty(vm, key, {
  1225. configurable: true,
  1226. enumerable: true,
  1227. get: function proxyGetter () {
  1228. return vm._data[key]
  1229. },
  1230. set: function proxySetter (val) {
  1231. vm._data[key] = val
  1232. }
  1233. })
  1234. }
  1235. }
  1236. /* */
  1237. var VNode = function VNode (
  1238. tag,
  1239. data,
  1240. children,
  1241. text,
  1242. elm,
  1243. ns,
  1244. context,
  1245. componentOptions
  1246. ) {
  1247. this.tag = tag
  1248. this.data = data
  1249. this.children = children
  1250. this.text = text
  1251. this.elm = elm
  1252. this.ns = ns
  1253. this.context = context
  1254. this.key = data && data.key
  1255. this.componentOptions = componentOptions
  1256. this.child = undefined
  1257. this.parent = undefined
  1258. this.raw = false
  1259. this.isStatic = false
  1260. this.isRootInsert = true
  1261. this.isComment = false
  1262. this.isCloned = false
  1263. // apply construct hook.
  1264. // this is applied during render, before patch happens.
  1265. // unlike other hooks, this is applied on both client and server.
  1266. var constructHook = data && data.hook && data.hook.construct
  1267. if (constructHook) {
  1268. constructHook(this)
  1269. }
  1270. };
  1271. var emptyVNode = function () {
  1272. var node = new VNode()
  1273. node.text = ''
  1274. node.isComment = true
  1275. return node
  1276. }
  1277. // optimized shallow clone
  1278. // used for static nodes and slot nodes because they may be reused across
  1279. // multiple renders, cloning them avoids errors when DOM manipulations rely
  1280. // on their elm reference.
  1281. function cloneVNode (vnode) {
  1282. var cloned = new VNode(
  1283. vnode.tag,
  1284. vnode.data,
  1285. vnode.children,
  1286. vnode.text,
  1287. vnode.elm,
  1288. vnode.ns,
  1289. vnode.context,
  1290. vnode.componentOptions
  1291. )
  1292. cloned.isStatic = vnode.isStatic
  1293. cloned.key = vnode.key
  1294. cloned.isCloned = true
  1295. return cloned
  1296. }
  1297. function cloneVNodes (vnodes) {
  1298. var res = new Array(vnodes.length)
  1299. for (var i = 0; i < vnodes.length; i++) {
  1300. res[i] = cloneVNode(vnodes[i])
  1301. }
  1302. return res
  1303. }
  1304. /* */
  1305. function normalizeChildren (
  1306. children,
  1307. ns,
  1308. nestedIndex
  1309. ) {
  1310. if (isPrimitive(children)) {
  1311. return [createTextVNode(children)]
  1312. }
  1313. if (Array.isArray(children)) {
  1314. var res = []
  1315. for (var i = 0, l = children.length; i < l; i++) {
  1316. var c = children[i]
  1317. var last = res[res.length - 1]
  1318. // nested
  1319. if (Array.isArray(c)) {
  1320. res.push.apply(res, normalizeChildren(c, ns, i))
  1321. } else if (isPrimitive(c)) {
  1322. if (last && last.text) {
  1323. last.text += String(c)
  1324. } else if (c !== '') {
  1325. // convert primitive to vnode
  1326. res.push(createTextVNode(c))
  1327. }
  1328. } else if (c instanceof VNode) {
  1329. if (c.text && last && last.text) {
  1330. last.text += c.text
  1331. } else {
  1332. // inherit parent namespace
  1333. if (ns) {
  1334. applyNS(c, ns)
  1335. }
  1336. // default key for nested array children (likely generated by v-for)
  1337. if (c.key == null && nestedIndex != null) {
  1338. c.key = "__vlist_" + nestedIndex + "_" + i + "__"
  1339. }
  1340. res.push(c)
  1341. }
  1342. }
  1343. }
  1344. return res
  1345. }
  1346. }
  1347. function createTextVNode (val) {
  1348. return new VNode(undefined, undefined, undefined, String(val))
  1349. }
  1350. function applyNS (vnode, ns) {
  1351. if (vnode.tag && !vnode.ns) {
  1352. vnode.ns = ns
  1353. if (vnode.children) {
  1354. for (var i = 0, l = vnode.children.length; i < l; i++) {
  1355. applyNS(vnode.children[i], ns)
  1356. }
  1357. }
  1358. }
  1359. }
  1360. function getFirstComponentChild (children) {
  1361. return children && children.filter(function (c) { return c && c.componentOptions; })[0]
  1362. }
  1363. function mergeVNodeHook (def, key, hook) {
  1364. var oldHook = def[key]
  1365. if (oldHook) {
  1366. var injectedHash = def.__injected || (def.__injected = {})
  1367. if (!injectedHash[key]) {
  1368. injectedHash[key] = true
  1369. def[key] = function () {
  1370. oldHook.apply(this, arguments)
  1371. hook.apply(this, arguments)
  1372. }
  1373. }
  1374. } else {
  1375. def[key] = hook
  1376. }
  1377. }
  1378. function updateListeners (
  1379. on,
  1380. oldOn,
  1381. add,
  1382. remove
  1383. ) {
  1384. var name, cur, old, fn, event, capture
  1385. for (name in on) {
  1386. cur = on[name]
  1387. old = oldOn[name]
  1388. if (!cur) {
  1389. process.env.NODE_ENV !== 'production' && warn(
  1390. ("Handler for event \"" + name + "\" is undefined.")
  1391. )
  1392. } else if (!old) {
  1393. capture = name.charAt(0) === '!'
  1394. event = capture ? name.slice(1) : name
  1395. if (Array.isArray(cur)) {
  1396. add(event, (cur.invoker = arrInvoker(cur)), capture)
  1397. } else {
  1398. if (!cur.invoker) {
  1399. fn = cur
  1400. cur = on[name] = {}
  1401. cur.fn = fn
  1402. cur.invoker = fnInvoker(cur)
  1403. }
  1404. add(event, cur.invoker, capture)
  1405. }
  1406. } else if (cur !== old) {
  1407. if (Array.isArray(old)) {
  1408. old.length = cur.length
  1409. for (var i = 0; i < old.length; i++) old[i] = cur[i]
  1410. on[name] = old
  1411. } else {
  1412. old.fn = cur
  1413. on[name] = old
  1414. }
  1415. }
  1416. }
  1417. for (name in oldOn) {
  1418. if (!on[name]) {
  1419. event = name.charAt(0) === '!' ? name.slice(1) : name
  1420. remove(event, oldOn[name].invoker)
  1421. }
  1422. }
  1423. }
  1424. function arrInvoker (arr) {
  1425. return function (ev) {
  1426. var arguments$1 = arguments;
  1427. var single = arguments.length === 1
  1428. for (var i = 0; i < arr.length; i++) {
  1429. single ? arr[i](ev) : arr[i].apply(null, arguments$1)
  1430. }
  1431. }
  1432. }
  1433. function fnInvoker (o) {
  1434. return function (ev) {
  1435. var single = arguments.length === 1
  1436. single ? o.fn(ev) : o.fn.apply(null, arguments)
  1437. }
  1438. }
  1439. /* */
  1440. var activeInstance = null
  1441. function initLifecycle (vm) {
  1442. var options = vm.$options
  1443. // locate first non-abstract parent
  1444. var parent = options.parent
  1445. if (parent && !options.abstract) {
  1446. while (parent.$options.abstract && parent.$parent) {
  1447. parent = parent.$parent
  1448. }
  1449. parent.$children.push(vm)
  1450. }
  1451. vm.$parent = parent
  1452. vm.$root = parent ? parent.$root : vm
  1453. vm.$children = []
  1454. vm.$refs = {}
  1455. vm._watcher = null
  1456. vm._inactive = false
  1457. vm._isMounted = false
  1458. vm._isDestroyed = false
  1459. vm._isBeingDestroyed = false
  1460. }
  1461. function lifecycleMixin (Vue) {
  1462. Vue.prototype._mount = function (
  1463. el,
  1464. hydrating
  1465. ) {
  1466. var vm = this
  1467. vm.$el = el
  1468. if (!vm.$options.render) {
  1469. vm.$options.render = emptyVNode
  1470. if (process.env.NODE_ENV !== 'production') {
  1471. /* istanbul ignore if */
  1472. if (vm.$options.template) {
  1473. warn(
  1474. 'You are using the runtime-only build of Vue where the template ' +
  1475. 'option is not available. Either pre-compile the templates into ' +
  1476. 'render functions, or use the compiler-included build.',
  1477. vm
  1478. )
  1479. } else {
  1480. warn(
  1481. 'Failed to mount component: template or render function not defined.',
  1482. vm
  1483. )
  1484. }
  1485. }
  1486. }
  1487. callHook(vm, 'beforeMount')
  1488. vm._watcher = new Watcher(vm, function () {
  1489. vm._update(vm._render(), hydrating)
  1490. }, noop)
  1491. hydrating = false
  1492. // root instance, call mounted on self
  1493. // mounted is called for child components in its inserted hook
  1494. if (vm.$root === vm) {
  1495. vm._isMounted = true
  1496. callHook(vm, 'mounted')
  1497. }
  1498. return vm
  1499. }
  1500. Vue.prototype._update = function (vnode, hydrating) {
  1501. var vm = this
  1502. if (vm._isMounted) {
  1503. callHook(vm, 'beforeUpdate')
  1504. }
  1505. var prevEl = vm.$el
  1506. var prevActiveInstance = activeInstance
  1507. activeInstance = vm
  1508. var prevVnode = vm._vnode
  1509. vm._vnode = vnode
  1510. if (!prevVnode) {
  1511. // Vue.prototype.__patch__ is injected in entry points
  1512. // based on the rendering backend used.
  1513. vm.$el = vm.__patch__(vm.$el, vnode, hydrating)
  1514. } else {
  1515. vm.$el = vm.__patch__(prevVnode, vnode)
  1516. }
  1517. activeInstance = prevActiveInstance
  1518. // update __vue__ reference
  1519. if (prevEl) {
  1520. prevEl.__vue__ = null
  1521. }
  1522. if (vm.$el) {
  1523. vm.$el.__vue__ = vm
  1524. }
  1525. // if parent is an HOC, update its $el as well
  1526. if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) {
  1527. vm.$parent.$el = vm.$el
  1528. }
  1529. if (vm._isMounted) {
  1530. callHook(vm, 'updated')
  1531. }
  1532. }
  1533. Vue.prototype._updateFromParent = function (
  1534. propsData,
  1535. listeners,
  1536. parentVnode,
  1537. renderChildren
  1538. ) {
  1539. var vm = this
  1540. var hasChildren = !!(vm.$options._renderChildren || renderChildren)
  1541. vm.$options._parentVnode = parentVnode
  1542. vm.$options._renderChildren = renderChildren
  1543. // update props
  1544. if (propsData && vm.$options.props) {
  1545. observerState.shouldConvert = false
  1546. if (process.env.NODE_ENV !== 'production') {
  1547. observerState.isSettingProps = true
  1548. }
  1549. var propKeys = vm.$options._propKeys || []
  1550. for (var i = 0; i < propKeys.length; i++) {
  1551. var key = propKeys[i]
  1552. vm[key] = validateProp(key, vm.$options.props, propsData, vm)
  1553. }
  1554. observerState.shouldConvert = true
  1555. if (process.env.NODE_ENV !== 'production') {
  1556. observerState.isSettingProps = false
  1557. }
  1558. }
  1559. // update listeners
  1560. if (listeners) {
  1561. var oldListeners = vm.$options._parentListeners
  1562. vm.$options._parentListeners = listeners
  1563. vm._updateListeners(listeners, oldListeners)
  1564. }
  1565. // resolve slots + force update if has children
  1566. if (hasChildren) {
  1567. vm.$slots = resolveSlots(renderChildren)
  1568. vm.$forceUpdate()
  1569. }
  1570. }
  1571. Vue.prototype.$forceUpdate = function () {
  1572. var vm = this
  1573. if (vm._watcher) {
  1574. vm._watcher.update()
  1575. }
  1576. }
  1577. Vue.prototype.$destroy = function () {
  1578. var vm = this
  1579. if (vm._isBeingDestroyed) {
  1580. return
  1581. }
  1582. callHook(vm, 'beforeDestroy')
  1583. vm._isBeingDestroyed = true
  1584. // remove self from parent
  1585. var parent = vm.$parent
  1586. if (parent && !parent._isBeingDestroyed && !vm.$options.abstract) {
  1587. remove(parent.$children, vm)
  1588. }
  1589. // teardown watchers
  1590. if (vm._watcher) {
  1591. vm._watcher.teardown()
  1592. }
  1593. var i = vm._watchers.length
  1594. while (i--) {
  1595. vm._watchers[i].teardown()
  1596. }
  1597. // remove reference from data ob
  1598. // frozen object may not have observer.
  1599. if (vm._data.__ob__) {
  1600. vm._data.__ob__.vmCount--
  1601. }
  1602. // call the last hook...
  1603. vm._isDestroyed = true
  1604. callHook(vm, 'destroyed')
  1605. // turn off all instance listeners.
  1606. vm.$off()
  1607. // remove __vue__ reference
  1608. if (vm.$el) {
  1609. vm.$el.__vue__ = null
  1610. }
  1611. }
  1612. }
  1613. function callHook (vm, hook) {
  1614. var handlers = vm.$options[hook]
  1615. if (handlers) {
  1616. for (var i = 0, j = handlers.length; i < j; i++) {
  1617. handlers[i].call(vm)
  1618. }
  1619. }
  1620. vm.$emit('hook:' + hook)
  1621. }
  1622. /* */
  1623. var hooks = { init: init, prepatch: prepatch, insert: insert, destroy: destroy }
  1624. var hooksToMerge = Object.keys(hooks)
  1625. function createComponent (
  1626. Ctor,
  1627. data,
  1628. context,
  1629. children,
  1630. tag
  1631. ) {
  1632. if (!Ctor) {
  1633. return
  1634. }
  1635. if (isObject(Ctor)) {
  1636. Ctor = Vue.extend(Ctor)
  1637. }
  1638. if (typeof Ctor !== 'function') {
  1639. if (process.env.NODE_ENV !== 'production') {
  1640. warn(("Invalid Component definition: " + (String(Ctor))), context)
  1641. }
  1642. return
  1643. }
  1644. // async component
  1645. if (!Ctor.cid) {
  1646. if (Ctor.resolved) {
  1647. Ctor = Ctor.resolved
  1648. } else {
  1649. Ctor = resolveAsyncComponent(Ctor, function () {
  1650. // it's ok to queue this on every render because
  1651. // $forceUpdate is buffered by the scheduler.
  1652. context.$forceUpdate()
  1653. })
  1654. if (!Ctor) {
  1655. // return nothing if this is indeed an async component
  1656. // wait for the callback to trigger parent update.
  1657. return
  1658. }
  1659. }
  1660. }
  1661. data = data || {}
  1662. // extract props
  1663. var propsData = extractProps(data, Ctor)
  1664. // functional component
  1665. if (Ctor.options.functional) {
  1666. return createFunctionalComponent(Ctor, propsData, data, context, children)
  1667. }
  1668. // extract listeners, since these needs to be treated as
  1669. // child component listeners instead of DOM listeners
  1670. var listeners = data.on
  1671. // replace with listeners with .native modifier
  1672. data.on = data.nativeOn
  1673. if (Ctor.options.abstract) {
  1674. // abstract components do not keep anything
  1675. // other than props & listeners
  1676. data = {}
  1677. }
  1678. // merge component management hooks onto the placeholder node
  1679. mergeHooks(data)
  1680. // return a placeholder vnode
  1681. var name = Ctor.options.name || tag
  1682. var vnode = new VNode(
  1683. ("vue-component-" + (Ctor.cid) + (name ? ("-" + name) : '')),
  1684. data, undefined, undefined, undefined, undefined, context,
  1685. { Ctor: Ctor, propsData: propsData, listeners: listeners, tag: tag, children: children }
  1686. )
  1687. return vnode
  1688. }
  1689. function createFunctionalComponent (
  1690. Ctor,
  1691. propsData,
  1692. data,
  1693. context,
  1694. children
  1695. ) {
  1696. var props = {}
  1697. var propOptions = Ctor.options.props
  1698. if (propOptions) {
  1699. for (var key in propOptions) {
  1700. props[key] = validateProp(key, propOptions, propsData)
  1701. }
  1702. }
  1703. return Ctor.options.render.call(
  1704. null,
  1705. context.$createElement,
  1706. {
  1707. props: props,
  1708. data: data,
  1709. parent: context,
  1710. children: normalizeChildren(children),
  1711. slots: function () { return resolveSlots(children); }
  1712. }
  1713. )
  1714. }
  1715. function createComponentInstanceForVnode (
  1716. vnode, // we know it's MountedComponentVNode but flow doesn't
  1717. parent // activeInstance in lifecycle state
  1718. ) {
  1719. var vnodeComponentOptions = vnode.componentOptions
  1720. var options = {
  1721. _isComponent: true,
  1722. parent: parent,
  1723. propsData: vnodeComponentOptions.propsData,
  1724. _componentTag: vnodeComponentOptions.tag,
  1725. _parentVnode: vnode,
  1726. _parentListeners: vnodeComponentOptions.listeners,
  1727. _renderChildren: vnodeComponentOptions.children
  1728. }
  1729. // check inline-template render functions
  1730. var inlineTemplate = vnode.data.inlineTemplate
  1731. if (inlineTemplate) {
  1732. options.render = inlineTemplate.render
  1733. options.staticRenderFns = inlineTemplate.staticRenderFns
  1734. }
  1735. return new vnodeComponentOptions.Ctor(options)
  1736. }
  1737. function init (vnode, hydrating) {
  1738. if (!vnode.child || vnode.child._isDestroyed) {
  1739. var child = vnode.child = createComponentInstanceForVnode(vnode, activeInstance)
  1740. child.$mount(hydrating ? vnode.elm : undefined, hydrating)
  1741. }
  1742. }
  1743. function prepatch (
  1744. oldVnode,
  1745. vnode
  1746. ) {
  1747. var options = vnode.componentOptions
  1748. var child = vnode.child = oldVnode.child
  1749. child._updateFromParent(
  1750. options.propsData, // updated props
  1751. options.listeners, // updated listeners
  1752. vnode, // new parent vnode
  1753. options.children // new children
  1754. )
  1755. }
  1756. function insert (vnode) {
  1757. if (!vnode.child._isMounted) {
  1758. vnode.child._isMounted = true
  1759. callHook(vnode.child, 'mounted')
  1760. }
  1761. if (vnode.data.keepAlive) {
  1762. vnode.child._inactive = false
  1763. callHook(vnode.child, 'activated')
  1764. }
  1765. }
  1766. function destroy (vnode) {
  1767. if (!vnode.child._isDestroyed) {
  1768. if (!vnode.data.keepAlive) {
  1769. vnode.child.$destroy()
  1770. } else {
  1771. vnode.child._inactive = true
  1772. callHook(vnode.child, 'deactivated')
  1773. }
  1774. }
  1775. }
  1776. function resolveAsyncComponent (
  1777. factory,
  1778. cb
  1779. ) {
  1780. if (factory.requested) {
  1781. // pool callbacks
  1782. factory.pendingCallbacks.push(cb)
  1783. } else {
  1784. factory.requested = true
  1785. var cbs = factory.pendingCallbacks = [cb]
  1786. var sync = true
  1787. var resolve = function (res) {
  1788. if (isObject(res)) {
  1789. res = Vue.extend(res)
  1790. }
  1791. // cache resolved
  1792. factory.resolved = res
  1793. // invoke callbacks only if this is not a synchronous resolve
  1794. // (async resolves are shimmed as synchronous during SSR)
  1795. if (!sync) {
  1796. for (var i = 0, l = cbs.length; i < l; i++) {
  1797. cbs[i](res)
  1798. }
  1799. }
  1800. }
  1801. var reject = function (reason) {
  1802. process.env.NODE_ENV !== 'production' && warn(
  1803. "Failed to resolve async component: " + (String(factory)) +
  1804. (reason ? ("\nReason: " + reason) : '')
  1805. )
  1806. }
  1807. var res = factory(resolve, reject)
  1808. // handle promise
  1809. if (res && typeof res.then === 'function' && !factory.resolved) {
  1810. res.then(resolve, reject)
  1811. }
  1812. sync = false
  1813. // return in case resolved synchronously
  1814. return factory.resolved
  1815. }
  1816. }
  1817. function extractProps (data, Ctor) {
  1818. // we are only extrating raw values here.
  1819. // validation and default values are handled in the child
  1820. // component itself.
  1821. var propOptions = Ctor.options.props
  1822. if (!propOptions) {
  1823. return
  1824. }
  1825. var res = {}
  1826. var attrs = data.attrs;
  1827. var props = data.props;
  1828. var domProps = data.domProps;
  1829. if (attrs || props || domProps) {
  1830. for (var key in propOptions) {
  1831. var altKey = hyphenate(key)
  1832. checkProp(res, props, key, altKey, true) ||
  1833. checkProp(res, attrs, key, altKey) ||
  1834. checkProp(res, domProps, key, altKey)
  1835. }
  1836. }
  1837. return res
  1838. }
  1839. function checkProp (
  1840. res,
  1841. hash,
  1842. key,
  1843. altKey,
  1844. preserve
  1845. ) {
  1846. if (hash) {
  1847. if (hasOwn(hash, key)) {
  1848. res[key] = hash[key]
  1849. if (!preserve) {
  1850. delete hash[key]
  1851. }
  1852. return true
  1853. } else if (hasOwn(hash, altKey)) {
  1854. res[key] = hash[altKey]
  1855. if (!preserve) {
  1856. delete hash[altKey]
  1857. }
  1858. return true
  1859. }
  1860. }
  1861. return false
  1862. }
  1863. function mergeHooks (data) {
  1864. if (!data.hook) {
  1865. data.hook = {}
  1866. }
  1867. for (var i = 0; i < hooksToMerge.length; i++) {
  1868. var key = hooksToMerge[i]
  1869. var fromParent = data.hook[key]
  1870. var ours = hooks[key]
  1871. data.hook[key] = fromParent ? mergeHook$1(ours, fromParent) : ours
  1872. }
  1873. }
  1874. function mergeHook$1 (a, b) {
  1875. // since all hooks have at most two args, use fixed args
  1876. // to avoid having to use fn.apply().
  1877. return function (_, __) {
  1878. a(_, __)
  1879. b(_, __)
  1880. }
  1881. }
  1882. /* */
  1883. // wrapper function for providing a more flexible interface
  1884. // without getting yelled at by flow
  1885. function createElement (
  1886. tag,
  1887. data,
  1888. children
  1889. ) {
  1890. if (data && (Array.isArray(data) || typeof data !== 'object')) {
  1891. children = data
  1892. data = undefined
  1893. }
  1894. // make sure to use real instance instead of proxy as context
  1895. return _createElement(this._self, tag, data, children)
  1896. }
  1897. function _createElement (
  1898. context,
  1899. tag,
  1900. data,
  1901. children
  1902. ) {
  1903. if (data && data.__ob__) {
  1904. process.env.NODE_ENV !== 'production' && warn(
  1905. "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" +
  1906. 'Always create fresh vnode data objects in each render!',
  1907. context
  1908. )
  1909. return
  1910. }
  1911. if (!tag) {
  1912. // in case of component :is set to falsy value
  1913. return emptyVNode()
  1914. }
  1915. if (typeof tag === 'string') {
  1916. var Ctor
  1917. var ns = config.getTagNamespace(tag)
  1918. if (config.isReservedTag(tag)) {
  1919. // platform built-in elements
  1920. return new VNode(
  1921. tag, data, normalizeChildren(children, ns),
  1922. undefined, undefined, ns, context
  1923. )
  1924. } else if ((Ctor = resolveAsset(context.$options, 'components', tag))) {
  1925. // component
  1926. return createComponent(Ctor, data, context, children, tag)
  1927. } else {
  1928. // unknown or unlisted namespaced elements
  1929. // check at runtime because it may get assigned a namespace when its
  1930. // parent normalizes children
  1931. return new VNode(
  1932. tag, data, normalizeChildren(children, ns),
  1933. undefined, undefined, ns, context
  1934. )
  1935. }
  1936. } else {
  1937. // direct component options / constructor
  1938. return createComponent(tag, data, context, children)
  1939. }
  1940. }
  1941. /* */
  1942. function initRender (vm) {
  1943. vm.$vnode = null // the placeholder node in parent tree
  1944. vm._vnode = null // the root of the child tree
  1945. vm._staticTrees = null
  1946. vm.$slots = resolveSlots(vm.$options._renderChildren)
  1947. // bind the public createElement fn to this instance
  1948. // so that we get proper render context inside it.
  1949. vm.$createElement = bind(createElement, vm)
  1950. if (vm.$options.el) {
  1951. vm.$mount(vm.$options.el)
  1952. }
  1953. }
  1954. function renderMixin (Vue) {
  1955. Vue.prototype.$nextTick = function (fn) {
  1956. nextTick(fn, this)
  1957. }
  1958. Vue.prototype._render = function () {
  1959. var vm = this
  1960. var ref = vm.$options;
  1961. var render = ref.render;
  1962. var staticRenderFns = ref.staticRenderFns;
  1963. var _parentVnode = ref._parentVnode;
  1964. if (vm._isMounted) {
  1965. // clone slot nodes on re-renders
  1966. for (var key in vm.$slots) {
  1967. vm.$slots[key] = cloneVNodes(vm.$slots[key])
  1968. }
  1969. }
  1970. if (staticRenderFns && !vm._staticTrees) {
  1971. vm._staticTrees = []
  1972. }
  1973. // set parent vnode. this allows render functions to have access
  1974. // to the data on the placeholder node.
  1975. vm.$vnode = _parentVnode
  1976. // render self
  1977. var vnode
  1978. try {
  1979. vnode = render.call(vm._renderProxy, vm.$createElement)
  1980. } catch (e) {
  1981. if (process.env.NODE_ENV !== 'production') {
  1982. warn(("Error when rendering " + (formatComponentName(vm)) + ":"))
  1983. }
  1984. /* istanbul ignore else */
  1985. if (config.errorHandler) {
  1986. config.errorHandler.call(null, e, vm)
  1987. } else {
  1988. if (config._isServer) {
  1989. throw e
  1990. } else {
  1991. setTimeout(function () { throw e }, 0)
  1992. }
  1993. }
  1994. // return previous vnode to prevent render error causing blank component
  1995. vnode = vm._vnode
  1996. }
  1997. // return empty vnode in case the render function errored out
  1998. if (!(vnode instanceof VNode)) {
  1999. if (process.env.NODE_ENV !== 'production' && Array.isArray(vnode)) {
  2000. warn(
  2001. 'Multiple root nodes returned from render function. Render function ' +
  2002. 'should return a single root node.',
  2003. vm
  2004. )
  2005. }
  2006. vnode = emptyVNode()
  2007. }
  2008. // set parent
  2009. vnode.parent = _parentVnode
  2010. return vnode
  2011. }
  2012. // shorthands used in render functions
  2013. Vue.prototype._h = createElement
  2014. // toString for mustaches
  2015. Vue.prototype._s = _toString
  2016. // number conversion
  2017. Vue.prototype._n = toNumber
  2018. // empty vnode
  2019. Vue.prototype._e = emptyVNode
  2020. // render static tree by index
  2021. Vue.prototype._m = function renderStatic (
  2022. index,
  2023. isInFor
  2024. ) {
  2025. var tree = this._staticTrees[index]
  2026. // if has already-rendered static tree and not inside v-for,
  2027. // we can reuse the same tree by doing a shallow clone.
  2028. if (tree && !isInFor) {
  2029. return Array.isArray(tree)
  2030. ? cloneVNodes(tree)
  2031. : cloneVNode(tree)
  2032. }
  2033. // otherwise, render a fresh tree.
  2034. tree = this._staticTrees[index] = this.$options.staticRenderFns[index].call(this._renderProxy)
  2035. if (Array.isArray(tree)) {
  2036. for (var i = 0; i < tree.length; i++) {
  2037. tree[i].isStatic = true
  2038. tree[i].key = "__static__" + index + "_" + i
  2039. }
  2040. } else {
  2041. tree.isStatic = true
  2042. tree.key = "__static__" + index
  2043. }
  2044. return tree
  2045. }
  2046. // filter resolution helper
  2047. var identity = function (_) { return _; }
  2048. Vue.prototype._f = function resolveFilter (id) {
  2049. return resolveAsset(this.$options, 'filters', id, true) || identity
  2050. }
  2051. // render v-for
  2052. Vue.prototype._l = function renderList (
  2053. val,
  2054. render
  2055. ) {
  2056. var ret, i, l, keys, key
  2057. if (Array.isArray(val)) {
  2058. ret = new Array(val.length)
  2059. for (i = 0, l = val.length; i < l; i++) {
  2060. ret[i] = render(val[i], i)
  2061. }
  2062. } else if (typeof val === 'number') {
  2063. ret = new Array(val)
  2064. for (i = 0; i < val; i++) {
  2065. ret[i] = render(i + 1, i)
  2066. }
  2067. } else if (isObject(val)) {
  2068. keys = Object.keys(val)
  2069. ret = new Array(keys.length)
  2070. for (i = 0, l = keys.length; i < l; i++) {
  2071. key = keys[i]
  2072. ret[i] = render(val[key], key, i)
  2073. }
  2074. }
  2075. return ret
  2076. }
  2077. // renderSlot
  2078. Vue.prototype._t = function (
  2079. name,
  2080. fallback
  2081. ) {
  2082. var slotNodes = this.$slots[name]
  2083. // warn duplicate slot usage
  2084. if (slotNodes && process.env.NODE_ENV !== 'production') {
  2085. slotNodes._rendered && warn(
  2086. "Duplicate presence of slot \"" + name + "\" found in the same render tree " +
  2087. "- this will likely cause render errors.",
  2088. this
  2089. )
  2090. slotNodes._rendered = true
  2091. }
  2092. return slotNodes || fallback
  2093. }
  2094. // apply v-bind object
  2095. Vue.prototype._b = function bindProps (
  2096. vnode,
  2097. value,
  2098. asProp) {
  2099. if (value) {
  2100. if (!isObject(value)) {
  2101. process.env.NODE_ENV !== 'production' && warn(
  2102. 'v-bind without argument expects an Object or Array value',
  2103. this
  2104. )
  2105. } else {
  2106. if (Array.isArray(value)) {
  2107. value = toObject(value)
  2108. }
  2109. var data = vnode.data
  2110. for (var key in value) {
  2111. if (key === 'class' || key === 'style') {
  2112. data[key] = value[key]
  2113. } else {
  2114. var hash = asProp || config.mustUseProp(key)
  2115. ? data.domProps || (data.domProps = {})
  2116. : data.attrs || (data.attrs = {})
  2117. hash[key] = value[key]
  2118. }
  2119. }
  2120. }
  2121. }
  2122. }
  2123. // expose v-on keyCodes
  2124. Vue.prototype._k = function getKeyCodes (key) {
  2125. return config.keyCodes[key]
  2126. }
  2127. }
  2128. function resolveSlots (
  2129. renderChildren
  2130. ) {
  2131. var slots = {}
  2132. if (!renderChildren) {
  2133. return slots
  2134. }
  2135. var children = normalizeChildren(renderChildren) || []
  2136. var defaultSlot = []
  2137. var name, child
  2138. for (var i = 0, l = children.length; i < l; i++) {
  2139. child = children[i]
  2140. if (child.data && (name = child.data.slot)) {
  2141. delete child.data.slot
  2142. var slot = (slots[name] || (slots[name] = []))
  2143. if (child.tag === 'template') {
  2144. slot.push.apply(slot, child.children)
  2145. } else {
  2146. slot.push(child)
  2147. }
  2148. } else {
  2149. defaultSlot.push(child)
  2150. }
  2151. }
  2152. // ignore single whitespace
  2153. if (defaultSlot.length && !(
  2154. defaultSlot.length === 1 &&
  2155. (defaultSlot[0].text === ' ' || defaultSlot[0].isComment)
  2156. )) {
  2157. slots.default = defaultSlot
  2158. }
  2159. return slots
  2160. }
  2161. /* */
  2162. function initEvents (vm) {
  2163. vm._events = Object.create(null)
  2164. // init parent attached events
  2165. var listeners = vm.$options._parentListeners
  2166. var on = bind(vm.$on, vm)
  2167. var off = bind(vm.$off, vm)
  2168. vm._updateListeners = function (listeners, oldListeners) {
  2169. updateListeners(listeners, oldListeners || {}, on, off)
  2170. }
  2171. if (listeners) {
  2172. vm._updateListeners(listeners)
  2173. }
  2174. }
  2175. function eventsMixin (Vue) {
  2176. Vue.prototype.$on = function (event, fn) {
  2177. var vm = this
  2178. ;(vm._events[event] || (vm._events[event] = [])).push(fn)
  2179. return vm
  2180. }
  2181. Vue.prototype.$once = function (event, fn) {
  2182. var vm = this
  2183. function on () {
  2184. vm.$off(event, on)
  2185. fn.apply(vm, arguments)
  2186. }
  2187. on.fn = fn
  2188. vm.$on(event, on)
  2189. return vm
  2190. }
  2191. Vue.prototype.$off = function (event, fn) {
  2192. var vm = this
  2193. // all
  2194. if (!arguments.length) {
  2195. vm._events = Object.create(null)
  2196. return vm
  2197. }
  2198. // specific event
  2199. var cbs = vm._events[event]
  2200. if (!cbs) {
  2201. return vm
  2202. }
  2203. if (arguments.length === 1) {
  2204. vm._events[event] = null
  2205. return vm
  2206. }
  2207. // specific handler
  2208. var cb
  2209. var i = cbs.length
  2210. while (i--) {
  2211. cb = cbs[i]
  2212. if (cb === fn || cb.fn === fn) {
  2213. cbs.splice(i, 1)
  2214. break
  2215. }
  2216. }
  2217. return vm
  2218. }
  2219. Vue.prototype.$emit = function (event) {
  2220. var vm = this
  2221. var cbs = vm._events[event]
  2222. if (cbs) {
  2223. cbs = cbs.length > 1 ? toArray(cbs) : cbs
  2224. var args = toArray(arguments, 1)
  2225. for (var i = 0, l = cbs.length; i < l; i++) {
  2226. cbs[i].apply(vm, args)
  2227. }
  2228. }
  2229. return vm
  2230. }
  2231. }
  2232. /* */
  2233. var uid = 0
  2234. function initMixin (Vue) {
  2235. Vue.prototype._init = function (options) {
  2236. var vm = this
  2237. // a uid
  2238. vm._uid = uid++
  2239. // a flag to avoid this being observed
  2240. vm._isVue = true
  2241. // merge options
  2242. if (options && options._isComponent) {
  2243. // optimize internal component instantiation
  2244. // since dynamic options merging is pretty slow, and none of the
  2245. // internal component options needs special treatment.
  2246. initInternalComponent(vm, options)
  2247. } else {
  2248. vm.$options = mergeOptions(
  2249. resolveConstructorOptions(vm),
  2250. options || {},
  2251. vm
  2252. )
  2253. }
  2254. /* istanbul ignore else */
  2255. if (process.env.NODE_ENV !== 'production') {
  2256. initProxy(vm)
  2257. } else {
  2258. vm._renderProxy = vm
  2259. }
  2260. // expose real self
  2261. vm._self = vm
  2262. initLifecycle(vm)
  2263. initEvents(vm)
  2264. callHook(vm, 'beforeCreate')
  2265. initState(vm)
  2266. callHook(vm, 'created')
  2267. initRender(vm)
  2268. }
  2269. function initInternalComponent (vm, options) {
  2270. var opts = vm.$options = Object.create(resolveConstructorOptions(vm))
  2271. // doing this because it's faster than dynamic enumeration.
  2272. opts.parent = options.parent
  2273. opts.propsData = options.propsData
  2274. opts._parentVnode = options._parentVnode
  2275. opts._parentListeners = options._parentListeners
  2276. opts._renderChildren = options._renderChildren
  2277. opts._componentTag = options._componentTag
  2278. if (options.render) {
  2279. opts.render = options.render
  2280. opts.staticRenderFns = options.staticRenderFns
  2281. }
  2282. }
  2283. function resolveConstructorOptions (vm) {
  2284. var Ctor = vm.constructor
  2285. var options = Ctor.options
  2286. if (Ctor.super) {
  2287. var superOptions = Ctor.super.options
  2288. var cachedSuperOptions = Ctor.superOptions
  2289. if (superOptions !== cachedSuperOptions) {
  2290. // super option changed
  2291. Ctor.superOptions = superOptions
  2292. options = Ctor.options = mergeOptions(superOptions, Ctor.extendOptions)
  2293. if (options.name) {
  2294. options.components[options.name] = Ctor
  2295. }
  2296. }
  2297. }
  2298. return options
  2299. }
  2300. }
  2301. function Vue (options) {
  2302. this._init(options)
  2303. }
  2304. initMixin(Vue)
  2305. stateMixin(Vue)
  2306. eventsMixin(Vue)
  2307. lifecycleMixin(Vue)
  2308. renderMixin(Vue)
  2309. var warn
  2310. var formatComponentName
  2311. if (process.env.NODE_ENV !== 'production') {
  2312. var hasConsole = typeof console !== 'undefined'
  2313. warn = function (msg, vm) {
  2314. if (hasConsole && (!config.silent)) {
  2315. console.error("[Vue warn]: " + msg + " " + (
  2316. vm ? formatLocation(formatComponentName(vm)) : ''
  2317. ))
  2318. }
  2319. }
  2320. formatComponentName = function (vm) {
  2321. if (vm.$root === vm) {
  2322. return 'root instance'
  2323. }
  2324. var name = vm._isVue
  2325. ? vm.$options.name || vm.$options._componentTag
  2326. : vm.name
  2327. return name ? ("component <" + name + ">") : "anonymous component"
  2328. }
  2329. var formatLocation = function (str) {
  2330. if (str === 'anonymous component') {
  2331. str += " - use the \"name\" option for better debugging messages."
  2332. }
  2333. return ("(found in " + str + ")")
  2334. }
  2335. }
  2336. /* */
  2337. /**
  2338. * Option overwriting strategies are functions that handle
  2339. * how to merge a parent option value and a child option
  2340. * value into the final value.
  2341. */
  2342. var strats = config.optionMergeStrategies
  2343. /**
  2344. * Options with restrictions
  2345. */
  2346. if (process.env.NODE_ENV !== 'production') {
  2347. strats.el = strats.propsData = function (parent, child, vm, key) {
  2348. if (!vm) {
  2349. warn(
  2350. "option \"" + key + "\" can only be used during instance " +
  2351. 'creation with the `new` keyword.'
  2352. )
  2353. }
  2354. return defaultStrat(parent, child)
  2355. }
  2356. strats.name = function (parent, child, vm) {
  2357. if (vm && child) {
  2358. warn(
  2359. 'options "name" can only be used as a component definition option, ' +
  2360. 'not during instance creation.'
  2361. )
  2362. }
  2363. return defaultStrat(parent, child)
  2364. }
  2365. }
  2366. /**
  2367. * Helper that recursively merges two data objects together.
  2368. */
  2369. function mergeData (to, from) {
  2370. var key, toVal, fromVal
  2371. for (key in from) {
  2372. toVal = to[key]
  2373. fromVal = from[key]
  2374. if (!hasOwn(to, key)) {
  2375. set(to, key, fromVal)
  2376. } else if (isObject(toVal) && isObject(fromVal)) {
  2377. mergeData(toVal, fromVal)
  2378. }
  2379. }
  2380. return to
  2381. }
  2382. /**
  2383. * Data
  2384. */
  2385. strats.data = function (
  2386. parentVal,
  2387. childVal,
  2388. vm
  2389. ) {
  2390. if (!vm) {
  2391. // in a Vue.extend merge, both should be functions
  2392. if (!childVal) {
  2393. return parentVal
  2394. }
  2395. if (typeof childVal !== 'function') {
  2396. process.env.NODE_ENV !== 'production' && warn(
  2397. 'The "data" option should be a function ' +
  2398. 'that returns a per-instance value in component ' +
  2399. 'definitions.',
  2400. vm
  2401. )
  2402. return parentVal
  2403. }
  2404. if (!parentVal) {
  2405. return childVal
  2406. }
  2407. // when parentVal & childVal are both present,
  2408. // we need to return a function that returns the
  2409. // merged result of both functions... no need to
  2410. // check if parentVal is a function here because
  2411. // it has to be a function to pass previous merges.
  2412. return function mergedDataFn () {
  2413. return mergeData(
  2414. childVal.call(this),
  2415. parentVal.call(this)
  2416. )
  2417. }
  2418. } else if (parentVal || childVal) {
  2419. return function mergedInstanceDataFn () {
  2420. // instance merge
  2421. var instanceData = typeof childVal === 'function'
  2422. ? childVal.call(vm)
  2423. : childVal
  2424. var defaultData = typeof parentVal === 'function'
  2425. ? parentVal.call(vm)
  2426. : undefined
  2427. if (instanceData) {
  2428. return mergeData(instanceData, defaultData)
  2429. } else {
  2430. return defaultData
  2431. }
  2432. }
  2433. }
  2434. }
  2435. /**
  2436. * Hooks and param attributes are merged as arrays.
  2437. */
  2438. function mergeHook (
  2439. parentVal,
  2440. childVal
  2441. ) {
  2442. return childVal
  2443. ? parentVal
  2444. ? parentVal.concat(childVal)
  2445. : Array.isArray(childVal)
  2446. ? childVal
  2447. : [childVal]
  2448. : parentVal
  2449. }
  2450. config._lifecycleHooks.forEach(function (hook) {
  2451. strats[hook] = mergeHook
  2452. })
  2453. /**
  2454. * Assets
  2455. *
  2456. * When a vm is present (instance creation), we need to do
  2457. * a three-way merge between constructor options, instance
  2458. * options and parent options.
  2459. */
  2460. function mergeAssets (parentVal, childVal) {
  2461. var res = Object.create(parentVal || null)
  2462. return childVal
  2463. ? extend(res, childVal)
  2464. : res
  2465. }
  2466. config._assetTypes.forEach(function (type) {
  2467. strats[type + 's'] = mergeAssets
  2468. })
  2469. /**
  2470. * Watchers.
  2471. *
  2472. * Watchers hashes should not overwrite one
  2473. * another, so we merge them as arrays.
  2474. */
  2475. strats.watch = function (parentVal, childVal) {
  2476. /* istanbul ignore if */
  2477. if (!childVal) return parentVal
  2478. if (!parentVal) return childVal
  2479. var ret = {}
  2480. extend(ret, parentVal)
  2481. for (var key in childVal) {
  2482. var parent = ret[key]
  2483. var child = childVal[key]
  2484. if (parent && !Array.isArray(parent)) {
  2485. parent = [parent]
  2486. }
  2487. ret[key] = parent
  2488. ? parent.concat(child)
  2489. : [child]
  2490. }
  2491. return ret
  2492. }
  2493. /**
  2494. * Other object hashes.
  2495. */
  2496. strats.props =
  2497. strats.methods =
  2498. strats.computed = function (parentVal, childVal) {
  2499. if (!childVal) return parentVal
  2500. if (!parentVal) return childVal
  2501. var ret = Object.create(null)
  2502. extend(ret, parentVal)
  2503. extend(ret, childVal)
  2504. return ret
  2505. }
  2506. /**
  2507. * Default strategy.
  2508. */
  2509. var defaultStrat = function (parentVal, childVal) {
  2510. return childVal === undefined
  2511. ? parentVal
  2512. : childVal
  2513. }
  2514. /**
  2515. * Make sure component options get converted to actual
  2516. * constructors.
  2517. */
  2518. function normalizeComponents (options) {
  2519. if (options.components) {
  2520. var components = options.components
  2521. var def
  2522. for (var key in components) {
  2523. var lower = key.toLowerCase()
  2524. if (isBuiltInTag(lower) || config.isReservedTag(lower)) {
  2525. process.env.NODE_ENV !== 'production' && warn(
  2526. 'Do not use built-in or reserved HTML elements as component ' +
  2527. 'id: ' + key
  2528. )
  2529. continue
  2530. }
  2531. def = components[key]
  2532. if (isPlainObject(def)) {
  2533. components[key] = Vue.extend(def)
  2534. }
  2535. }
  2536. }
  2537. }
  2538. /**
  2539. * Ensure all props option syntax are normalized into the
  2540. * Object-based format.
  2541. */
  2542. function normalizeProps (options) {
  2543. var props = options.props
  2544. if (!props) return
  2545. var res = {}
  2546. var i, val, name
  2547. if (Array.isArray(props)) {
  2548. i = props.length
  2549. while (i--) {
  2550. val = props[i]
  2551. if (typeof val === 'string') {
  2552. name = camelize(val)
  2553. res[name] = { type: null }
  2554. } else if (process.env.NODE_ENV !== 'production') {
  2555. warn('props must be strings when using array syntax.')
  2556. }
  2557. }
  2558. } else if (isPlainObject(props)) {
  2559. for (var key in props) {
  2560. val = props[key]
  2561. name = camelize(key)
  2562. res[name] = isPlainObject(val)
  2563. ? val
  2564. : { type: val }
  2565. }
  2566. }
  2567. options.props = res
  2568. }
  2569. /**
  2570. * Normalize raw function directives into object format.
  2571. */
  2572. function normalizeDirectives (options) {
  2573. var dirs = options.directives
  2574. if (dirs) {
  2575. for (var key in dirs) {
  2576. var def = dirs[key]
  2577. if (typeof def === 'function') {
  2578. dirs[key] = { bind: def, update: def }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. /**
  2584. * Merge two option objects into a new one.
  2585. * Core utility used in both instantiation and inheritance.
  2586. */
  2587. function mergeOptions (
  2588. parent,
  2589. child,
  2590. vm
  2591. ) {
  2592. normalizeComponents(child)
  2593. normalizeProps(child)
  2594. normalizeDirectives(child)
  2595. var extendsFrom = child.extends
  2596. if (extendsFrom) {
  2597. parent = typeof extendsFrom === 'function'
  2598. ? mergeOptions(parent, extendsFrom.options, vm)
  2599. : mergeOptions(parent, extendsFrom, vm)
  2600. }
  2601. if (child.mixins) {
  2602. for (var i = 0, l = child.mixins.length; i < l; i++) {
  2603. var mixin = child.mixins[i]
  2604. if (mixin.prototype instanceof Vue) {
  2605. mixin = mixin.options
  2606. }
  2607. parent = mergeOptions(parent, mixin, vm)
  2608. }
  2609. }
  2610. var options = {}
  2611. var key
  2612. for (key in parent) {
  2613. mergeField(key)
  2614. }
  2615. for (key in child) {
  2616. if (!hasOwn(parent, key)) {
  2617. mergeField(key)
  2618. }
  2619. }
  2620. function mergeField (key) {
  2621. var strat = strats[key] || defaultStrat
  2622. options[key] = strat(parent[key], child[key], vm, key)
  2623. }
  2624. return options
  2625. }
  2626. /**
  2627. * Resolve an asset.
  2628. * This function is used because child instances need access
  2629. * to assets defined in its ancestor chain.
  2630. */
  2631. function resolveAsset (
  2632. options,
  2633. type,
  2634. id,
  2635. warnMissing
  2636. ) {
  2637. /* istanbul ignore if */
  2638. if (typeof id !== 'string') {
  2639. return
  2640. }
  2641. var assets = options[type]
  2642. var res = assets[id] ||
  2643. // camelCase ID
  2644. assets[camelize(id)] ||
  2645. // Pascal Case ID
  2646. assets[capitalize(camelize(id))]
  2647. if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
  2648. warn(
  2649. 'Failed to resolve ' + type.slice(0, -1) + ': ' + id,
  2650. options
  2651. )
  2652. }
  2653. return res
  2654. }
  2655. /* */
  2656. function validateProp (
  2657. key,
  2658. propOptions,
  2659. propsData,
  2660. vm
  2661. ) {
  2662. /* istanbul ignore if */
  2663. if (!propsData) return
  2664. var prop = propOptions[key]
  2665. var absent = !hasOwn(propsData, key)
  2666. var value = propsData[key]
  2667. // handle boolean props
  2668. if (getType(prop.type) === 'Boolean') {
  2669. if (absent && !hasOwn(prop, 'default')) {
  2670. value = false
  2671. } else if (value === '' || value === hyphenate(key)) {
  2672. value = true
  2673. }
  2674. }
  2675. // check default value
  2676. if (value === undefined) {
  2677. value = getPropDefaultValue(vm, prop, key)
  2678. // since the default value is a fresh copy,
  2679. // make sure to observe it.
  2680. var prevShouldConvert = observerState.shouldConvert
  2681. observerState.shouldConvert = true
  2682. observe(value)
  2683. observerState.shouldConvert = prevShouldConvert
  2684. }
  2685. if (process.env.NODE_ENV !== 'production') {
  2686. assertProp(prop, key, value, vm, absent)
  2687. }
  2688. return value
  2689. }
  2690. /**
  2691. * Get the default value of a prop.
  2692. */
  2693. function getPropDefaultValue (vm, prop, name) {
  2694. // no default, return undefined
  2695. if (!hasOwn(prop, 'default')) {
  2696. return undefined
  2697. }
  2698. var def = prop.default
  2699. // warn against non-factory defaults for Object & Array
  2700. if (isObject(def)) {
  2701. process.env.NODE_ENV !== 'production' && warn(
  2702. 'Invalid default value for prop "' + name + '": ' +
  2703. 'Props with type Object/Array must use a factory function ' +
  2704. 'to return the default value.',
  2705. vm
  2706. )
  2707. }
  2708. // call factory function for non-Function types
  2709. return typeof def === 'function' && prop.type !== Function
  2710. ? def.call(vm)
  2711. : def
  2712. }
  2713. /**
  2714. * Assert whether a prop is valid.
  2715. */
  2716. function assertProp (
  2717. prop,
  2718. name,
  2719. value,
  2720. vm,
  2721. absent
  2722. ) {
  2723. if (prop.required && absent) {
  2724. warn(
  2725. 'Missing required prop: "' + name + '"',
  2726. vm
  2727. )
  2728. return
  2729. }
  2730. if (value == null && !prop.required) {
  2731. return
  2732. }
  2733. var type = prop.type
  2734. var valid = !type || type === true
  2735. var expectedTypes = []
  2736. if (type) {
  2737. if (!Array.isArray(type)) {
  2738. type = [type]
  2739. }
  2740. for (var i = 0; i < type.length && !valid; i++) {
  2741. var assertedType = assertType(value, type[i])
  2742. expectedTypes.push(assertedType.expectedType)
  2743. valid = assertedType.valid
  2744. }
  2745. }
  2746. if (!valid) {
  2747. warn(
  2748. 'Invalid prop: type check failed for prop "' + name + '".' +
  2749. ' Expected ' + expectedTypes.map(capitalize).join(', ') +
  2750. ', got ' + Object.prototype.toString.call(value).slice(8, -1) + '.',
  2751. vm
  2752. )
  2753. return
  2754. }
  2755. var validator = prop.validator
  2756. if (validator) {
  2757. if (!validator(value)) {
  2758. warn(
  2759. 'Invalid prop: custom validator check failed for prop "' + name + '".',
  2760. vm
  2761. )
  2762. }
  2763. }
  2764. }
  2765. /**
  2766. * Assert the type of a value
  2767. */
  2768. function assertType (value, type) {
  2769. var valid
  2770. var expectedType = getType(type)
  2771. if (expectedType === 'String') {
  2772. valid = typeof value === (expectedType = 'string')
  2773. } else if (expectedType === 'Number') {
  2774. valid = typeof value === (expectedType = 'number')
  2775. } else if (expectedType === 'Boolean') {
  2776. valid = typeof value === (expectedType = 'boolean')
  2777. } else if (expectedType === 'Function') {
  2778. valid = typeof value === (expectedType = 'function')
  2779. } else if (expectedType === 'Object') {
  2780. valid = isPlainObject(value)
  2781. } else if (expectedType === 'Array') {
  2782. valid = Array.isArray(value)
  2783. } else {
  2784. valid = value instanceof type
  2785. }
  2786. return {
  2787. valid: valid,
  2788. expectedType: expectedType
  2789. }
  2790. }
  2791. /**
  2792. * Use function string name to check built-in types,
  2793. * because a simple equality check will fail when running
  2794. * across different vms / iframes.
  2795. */
  2796. function getType (fn) {
  2797. var match = fn && fn.toString().match(/^\s*function (\w+)/)
  2798. return match && match[1]
  2799. }
  2800. var util = Object.freeze({
  2801. defineReactive: defineReactive,
  2802. _toString: _toString,
  2803. toNumber: toNumber,
  2804. makeMap: makeMap,
  2805. isBuiltInTag: isBuiltInTag,
  2806. remove: remove,
  2807. hasOwn: hasOwn,
  2808. isPrimitive: isPrimitive,
  2809. cached: cached,
  2810. camelize: camelize,
  2811. capitalize: capitalize,
  2812. hyphenate: hyphenate,
  2813. bind: bind,
  2814. toArray: toArray,
  2815. extend: extend,
  2816. isObject: isObject,
  2817. isPlainObject: isPlainObject,
  2818. toObject: toObject,
  2819. noop: noop,
  2820. no: no,
  2821. genStaticKeys: genStaticKeys,
  2822. isReserved: isReserved,
  2823. def: def,
  2824. parsePath: parsePath,
  2825. hasProto: hasProto,
  2826. inBrowser: inBrowser,
  2827. devtools: devtools,
  2828. UA: UA,
  2829. nextTick: nextTick,
  2830. get _Set () { return _Set; },
  2831. mergeOptions: mergeOptions,
  2832. resolveAsset: resolveAsset,
  2833. get warn () { return warn; },
  2834. get formatComponentName () { return formatComponentName; },
  2835. validateProp: validateProp
  2836. });
  2837. /* */
  2838. function initUse (Vue) {
  2839. Vue.use = function (plugin) {
  2840. /* istanbul ignore if */
  2841. if (plugin.installed) {
  2842. return
  2843. }
  2844. // additional parameters
  2845. var args = toArray(arguments, 1)
  2846. args.unshift(this)
  2847. if (typeof plugin.install === 'function') {
  2848. plugin.install.apply(plugin, args)
  2849. } else {
  2850. plugin.apply(null, args)
  2851. }
  2852. plugin.installed = true
  2853. return this
  2854. }
  2855. }
  2856. /* */
  2857. function initMixin$1 (Vue) {
  2858. Vue.mixin = function (mixin) {
  2859. Vue.options = mergeOptions(Vue.options, mixin)
  2860. }
  2861. }
  2862. /* */
  2863. function initExtend (Vue) {
  2864. /**
  2865. * Each instance constructor, including Vue, has a unique
  2866. * cid. This enables us to create wrapped "child
  2867. * constructors" for prototypal inheritance and cache them.
  2868. */
  2869. Vue.cid = 0
  2870. var cid = 1
  2871. /**
  2872. * Class inheritance
  2873. */
  2874. Vue.extend = function (extendOptions) {
  2875. extendOptions = extendOptions || {}
  2876. var Super = this
  2877. var isFirstExtend = Super.cid === 0
  2878. if (isFirstExtend && extendOptions._Ctor) {
  2879. return extendOptions._Ctor
  2880. }
  2881. var name = extendOptions.name || Super.options.name
  2882. if (process.env.NODE_ENV !== 'production') {
  2883. if (!/^[a-zA-Z][\w-]*$/.test(name)) {
  2884. warn(
  2885. 'Invalid component name: "' + name + '". Component names ' +
  2886. 'can only contain alphanumeric characaters and the hyphen.'
  2887. )
  2888. name = null
  2889. }
  2890. }
  2891. var Sub = function VueComponent (options) {
  2892. this._init(options)
  2893. }
  2894. Sub.prototype = Object.create(Super.prototype)
  2895. Sub.prototype.constructor = Sub
  2896. Sub.cid = cid++
  2897. Sub.options = mergeOptions(
  2898. Super.options,
  2899. extendOptions
  2900. )
  2901. Sub['super'] = Super
  2902. // allow further extension
  2903. Sub.extend = Super.extend
  2904. // create asset registers, so extended classes
  2905. // can have their private assets too.
  2906. config._assetTypes.forEach(function (type) {
  2907. Sub[type] = Super[type]
  2908. })
  2909. // enable recursive self-lookup
  2910. if (name) {
  2911. Sub.options.components[name] = Sub
  2912. }
  2913. // keep a reference to the super options at extension time.
  2914. // later at instantiation we can check if Super's options have
  2915. // been updated.
  2916. Sub.superOptions = Super.options
  2917. Sub.extendOptions = extendOptions
  2918. // cache constructor
  2919. if (isFirstExtend) {
  2920. extendOptions._Ctor = Sub
  2921. }
  2922. return Sub
  2923. }
  2924. }
  2925. /* */
  2926. function initAssetRegisters (Vue) {
  2927. /**
  2928. * Create asset registration methods.
  2929. */
  2930. config._assetTypes.forEach(function (type) {
  2931. Vue[type] = function (
  2932. id,
  2933. definition
  2934. ) {
  2935. if (!definition) {
  2936. return this.options[type + 's'][id]
  2937. } else {
  2938. /* istanbul ignore if */
  2939. if (process.env.NODE_ENV !== 'production') {
  2940. if (type === 'component' && config.isReservedTag(id)) {
  2941. warn(
  2942. 'Do not use built-in or reserved HTML elements as component ' +
  2943. 'id: ' + id
  2944. )
  2945. }
  2946. }
  2947. if (type === 'component' && isPlainObject(definition)) {
  2948. definition.name = definition.name || id
  2949. definition = Vue.extend(definition)
  2950. }
  2951. if (type === 'directive' && typeof definition === 'function') {
  2952. definition = { bind: definition, update: definition }
  2953. }
  2954. this.options[type + 's'][id] = definition
  2955. return definition
  2956. }
  2957. }
  2958. })
  2959. }
  2960. var KeepAlive = {
  2961. name: 'keep-alive',
  2962. abstract: true,
  2963. created: function created () {
  2964. this.cache = Object.create(null)
  2965. },
  2966. render: function render () {
  2967. var vnode = getFirstComponentChild(this.$slots.default)
  2968. if (vnode && vnode.componentOptions) {
  2969. var opts = vnode.componentOptions
  2970. var key = vnode.key == null
  2971. // same constructor may get registered as different local components
  2972. // so cid alone is not enough (#3269)
  2973. ? opts.Ctor.cid + '::' + opts.tag
  2974. : vnode.key
  2975. if (this.cache[key]) {
  2976. vnode.child = this.cache[key].child
  2977. } else {
  2978. this.cache[key] = vnode
  2979. }
  2980. vnode.data.keepAlive = true
  2981. }
  2982. return vnode
  2983. },
  2984. destroyed: function destroyed () {
  2985. var this$1 = this;
  2986. for (var key in this.cache) {
  2987. var vnode = this$1.cache[key]
  2988. callHook(vnode.child, 'deactivated')
  2989. vnode.child.$destroy()
  2990. }
  2991. }
  2992. }
  2993. var builtInComponents = {
  2994. KeepAlive: KeepAlive
  2995. }
  2996. /* */
  2997. function initGlobalAPI (Vue) {
  2998. // config
  2999. var configDef = {}
  3000. configDef.get = function () { return config; }
  3001. if (process.env.NODE_ENV !== 'production') {
  3002. configDef.set = function () {
  3003. warn(
  3004. 'Do not replace the Vue.config object, set individual fields instead.'
  3005. )
  3006. }
  3007. }
  3008. Object.defineProperty(Vue, 'config', configDef)
  3009. Vue.util = util
  3010. Vue.set = set
  3011. Vue.delete = del
  3012. Vue.nextTick = nextTick
  3013. Vue.options = Object.create(null)
  3014. config._assetTypes.forEach(function (type) {
  3015. Vue.options[type + 's'] = Object.create(null)
  3016. })
  3017. extend(Vue.options.components, builtInComponents)
  3018. initUse(Vue)
  3019. initMixin$1(Vue)
  3020. initExtend(Vue)
  3021. initAssetRegisters(Vue)
  3022. }
  3023. initGlobalAPI(Vue)
  3024. Object.defineProperty(Vue.prototype, '$isServer', {
  3025. get: function () { return config._isServer; }
  3026. })
  3027. Vue.version = '2.0.0-rc.6'
  3028. /* */
  3029. // attributes that should be using props for binding
  3030. var mustUseProp = makeMap('value,selected,checked,muted')
  3031. var isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck')
  3032. var isBooleanAttr = makeMap(
  3033. 'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' +
  3034. 'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' +
  3035. 'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' +
  3036. 'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' +
  3037. 'required,reversed,scoped,seamless,selected,sortable,translate,' +
  3038. 'truespeed,typemustmatch,visible'
  3039. )
  3040. var isAttr = makeMap(
  3041. 'accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' +
  3042. 'autofocus,autoplay,autosave,bgcolor,border,buffered,challenge,charset,' +
  3043. 'checked,cite,class,code,codebase,color,cols,colspan,content,http-equiv,' +
  3044. 'name,contenteditable,contextmenu,controls,coords,data,datetime,default,' +
  3045. 'defer,dir,dirname,disabled,download,draggable,dropzone,enctype,method,for,' +
  3046. 'form,formaction,headers,<th>,height,hidden,high,href,hreflang,http-equiv,' +
  3047. 'icon,id,ismap,itemprop,keytype,kind,label,lang,language,list,loop,low,' +
  3048. 'manifest,max,maxlength,media,method,GET,POST,min,multiple,email,file,' +
  3049. 'muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,' +
  3050. 'preload,radiogroup,readonly,rel,required,reversed,rows,rowspan,sandbox,' +
  3051. 'scope,scoped,seamless,selected,shape,size,type,text,password,sizes,span,' +
  3052. 'spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,' +
  3053. 'target,title,type,usemap,value,width,wrap'
  3054. )
  3055. var xlinkNS = 'http://www.w3.org/1999/xlink'
  3056. var isXlink = function (name) {
  3057. return name.charAt(5) === ':' && name.slice(0, 5) === 'xlink'
  3058. }
  3059. var getXlinkProp = function (name) {
  3060. return isXlink(name) ? name.slice(6, name.length) : ''
  3061. }
  3062. var isFalsyAttrValue = function (val) {
  3063. return val == null || val === false
  3064. }
  3065. /* */
  3066. function genClassForVnode (vnode) {
  3067. var data = vnode.data
  3068. var parentNode = vnode
  3069. var childNode = vnode
  3070. while (childNode.child) {
  3071. childNode = childNode.child._vnode
  3072. if (childNode.data) {
  3073. data = mergeClassData(childNode.data, data)
  3074. }
  3075. }
  3076. while ((parentNode = parentNode.parent)) {
  3077. if (parentNode.data) {
  3078. data = mergeClassData(data, parentNode.data)
  3079. }
  3080. }
  3081. return genClassFromData(data)
  3082. }
  3083. function mergeClassData (child, parent) {
  3084. return {
  3085. staticClass: concat(child.staticClass, parent.staticClass),
  3086. class: child.class
  3087. ? [child.class, parent.class]
  3088. : parent.class
  3089. }
  3090. }
  3091. function genClassFromData (data) {
  3092. var dynamicClass = data.class
  3093. var staticClass = data.staticClass
  3094. if (staticClass || dynamicClass) {
  3095. return concat(staticClass, stringifyClass(dynamicClass))
  3096. }
  3097. /* istanbul ignore next */
  3098. return ''
  3099. }
  3100. function concat (a, b) {
  3101. return a ? b ? (a + ' ' + b) : a : (b || '')
  3102. }
  3103. function stringifyClass (value) {
  3104. var res = ''
  3105. if (!value) {
  3106. return res
  3107. }
  3108. if (typeof value === 'string') {
  3109. return value
  3110. }
  3111. if (Array.isArray(value)) {
  3112. var stringified
  3113. for (var i = 0, l = value.length; i < l; i++) {
  3114. if (value[i]) {
  3115. if ((stringified = stringifyClass(value[i]))) {
  3116. res += stringified + ' '
  3117. }
  3118. }
  3119. }
  3120. return res.slice(0, -1)
  3121. }
  3122. if (isObject(value)) {
  3123. for (var key in value) {
  3124. if (value[key]) res += key + ' '
  3125. }
  3126. return res.slice(0, -1)
  3127. }
  3128. /* istanbul ignore next */
  3129. return res
  3130. }
  3131. /* */
  3132. var namespaceMap = {
  3133. svg: 'http://www.w3.org/2000/svg',
  3134. math: 'http://www.w3.org/1998/Math/MathML'
  3135. }
  3136. var isHTMLTag = makeMap(
  3137. 'html,body,base,head,link,meta,style,title,' +
  3138. 'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +
  3139. 'div,dd,dl,dt,figcaption,figure,hr,img,li,main,ol,p,pre,ul,' +
  3140. 'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' +
  3141. 's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' +
  3142. 'embed,object,param,source,canvas,script,noscript,del,ins,' +
  3143. 'caption,col,colgroup,table,thead,tbody,td,th,tr,' +
  3144. 'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +
  3145. 'output,progress,select,textarea,' +
  3146. 'details,dialog,menu,menuitem,summary,' +
  3147. 'content,element,shadow,template'
  3148. )
  3149. var isUnaryTag = makeMap(
  3150. 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
  3151. 'link,meta,param,source,track,wbr',
  3152. true
  3153. )
  3154. // Elements that you can, intentionally, leave open
  3155. // (and which close themselves)
  3156. var canBeLeftOpenTag = makeMap(
  3157. 'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source',
  3158. true
  3159. )
  3160. // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
  3161. // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
  3162. var isNonPhrasingTag = makeMap(
  3163. 'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +
  3164. 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +
  3165. 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +
  3166. 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +
  3167. 'title,tr,track',
  3168. true
  3169. )
  3170. // this map is intentionally selective, only covering SVG elements that may
  3171. // contain child elements.
  3172. var isSVG = makeMap(
  3173. 'svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font,' +
  3174. 'font-face,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' +
  3175. 'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view',
  3176. true
  3177. )
  3178. var isReservedTag = function (tag) {
  3179. return isHTMLTag(tag) || isSVG(tag)
  3180. }
  3181. function getTagNamespace (tag) {
  3182. if (isSVG(tag)) {
  3183. return 'svg'
  3184. }
  3185. // basic support for MathML
  3186. // note it doesn't support other MathML elements being component roots
  3187. if (tag === 'math') {
  3188. return 'math'
  3189. }
  3190. }
  3191. var unknownElementCache = Object.create(null)
  3192. function isUnknownElement (tag) {
  3193. /* istanbul ignore if */
  3194. if (!inBrowser) {
  3195. return true
  3196. }
  3197. if (isReservedTag(tag)) {
  3198. return false
  3199. }
  3200. tag = tag.toLowerCase()
  3201. /* istanbul ignore if */
  3202. if (unknownElementCache[tag] != null) {
  3203. return unknownElementCache[tag]
  3204. }
  3205. var el = document.createElement(tag)
  3206. if (tag.indexOf('-') > -1) {
  3207. // http://stackoverflow.com/a/28210364/1070244
  3208. return (unknownElementCache[tag] = (
  3209. el.constructor === window.HTMLUnknownElement ||
  3210. el.constructor === window.HTMLElement
  3211. ))
  3212. } else {
  3213. return (unknownElementCache[tag] = /HTMLUnknownElement/.test(el.toString()))
  3214. }
  3215. }
  3216. /* */
  3217. var UA$1 = inBrowser && window.navigator.userAgent.toLowerCase()
  3218. var isIE = UA$1 && /msie|trident/.test(UA$1)
  3219. var isIE9 = UA$1 && UA$1.indexOf('msie 9.0') > 0
  3220. var isAndroid = UA$1 && UA$1.indexOf('android') > 0
  3221. /**
  3222. * Query an element selector if it's not an element already.
  3223. */
  3224. function query (el) {
  3225. if (typeof el === 'string') {
  3226. var selector = el
  3227. el = document.querySelector(el)
  3228. if (!el) {
  3229. process.env.NODE_ENV !== 'production' && warn(
  3230. 'Cannot find element: ' + selector
  3231. )
  3232. return document.createElement('div')
  3233. }
  3234. }
  3235. return el
  3236. }
  3237. /* */
  3238. function createElement$1 (tagName) {
  3239. return document.createElement(tagName)
  3240. }
  3241. function createElementNS (namespace, tagName) {
  3242. return document.createElementNS(namespaceMap[namespace], tagName)
  3243. }
  3244. function createTextNode (text) {
  3245. return document.createTextNode(text)
  3246. }
  3247. function createComment (text) {
  3248. return document.createComment(text)
  3249. }
  3250. function insertBefore (parentNode, newNode, referenceNode) {
  3251. parentNode.insertBefore(newNode, referenceNode)
  3252. }
  3253. function removeChild (node, child) {
  3254. node.removeChild(child)
  3255. }
  3256. function appendChild (node, child) {
  3257. node.appendChild(child)
  3258. }
  3259. function parentNode (node) {
  3260. return node.parentNode
  3261. }
  3262. function nextSibling (node) {
  3263. return node.nextSibling
  3264. }
  3265. function tagName (node) {
  3266. return node.tagName
  3267. }
  3268. function setTextContent (node, text) {
  3269. node.textContent = text
  3270. }
  3271. function childNodes (node) {
  3272. return node.childNodes
  3273. }
  3274. function setAttribute (node, key, val) {
  3275. node.setAttribute(key, val)
  3276. }
  3277. var nodeOps = Object.freeze({
  3278. createElement: createElement$1,
  3279. createElementNS: createElementNS,
  3280. createTextNode: createTextNode,
  3281. createComment: createComment,
  3282. insertBefore: insertBefore,
  3283. removeChild: removeChild,
  3284. appendChild: appendChild,
  3285. parentNode: parentNode,
  3286. nextSibling: nextSibling,
  3287. tagName: tagName,
  3288. setTextContent: setTextContent,
  3289. childNodes: childNodes,
  3290. setAttribute: setAttribute
  3291. });
  3292. /* */
  3293. var ref = {
  3294. create: function create (_, vnode) {
  3295. registerRef(vnode)
  3296. },
  3297. update: function update (oldVnode, vnode) {
  3298. if (oldVnode.data.ref !== vnode.data.ref) {
  3299. registerRef(oldVnode, true)
  3300. registerRef(vnode)
  3301. }
  3302. },
  3303. destroy: function destroy (vnode) {
  3304. registerRef(vnode, true)
  3305. }
  3306. }
  3307. function registerRef (vnode, isRemoval) {
  3308. var key = vnode.data.ref
  3309. if (!key) return
  3310. var vm = vnode.context
  3311. var ref = vnode.child || vnode.elm
  3312. var refs = vm.$refs
  3313. if (isRemoval) {
  3314. if (Array.isArray(refs[key])) {
  3315. remove(refs[key], ref)
  3316. } else if (refs[key] === ref) {
  3317. refs[key] = undefined
  3318. }
  3319. } else {
  3320. if (vnode.data.refInFor) {
  3321. if (Array.isArray(refs[key])) {
  3322. refs[key].push(ref)
  3323. } else {
  3324. refs[key] = [ref]
  3325. }
  3326. } else {
  3327. refs[key] = ref
  3328. }
  3329. }
  3330. }
  3331. /**
  3332. * Virtual DOM patching algorithm based on Snabbdom by
  3333. * Simon Friis Vindum (@paldepind)
  3334. * Licensed under the MIT License
  3335. * https://github.com/paldepind/snabbdom/blob/master/LICENSE
  3336. *
  3337. * modified by Evan You (@yyx990803)
  3338. *
  3339. /*
  3340. * Not type-checking this because this file is perf-critical and the cost
  3341. * of making flow understand it is not worth it.
  3342. */
  3343. var emptyData = {}
  3344. var emptyNode = new VNode('', emptyData, [])
  3345. var hooks$1 = ['create', 'update', 'postpatch', 'remove', 'destroy']
  3346. function isUndef (s) {
  3347. return s == null
  3348. }
  3349. function isDef (s) {
  3350. return s != null
  3351. }
  3352. function sameVnode (vnode1, vnode2) {
  3353. return (
  3354. vnode1.key === vnode2.key &&
  3355. vnode1.tag === vnode2.tag &&
  3356. vnode1.isComment === vnode2.isComment &&
  3357. !vnode1.data === !vnode2.data
  3358. )
  3359. }
  3360. function createKeyToOldIdx (children, beginIdx, endIdx) {
  3361. var i, key
  3362. var map = {}
  3363. for (i = beginIdx; i <= endIdx; ++i) {
  3364. key = children[i].key
  3365. if (isDef(key)) map[key] = i
  3366. }
  3367. return map
  3368. }
  3369. function createPatchFunction (backend) {
  3370. var i, j
  3371. var cbs = {}
  3372. var modules = backend.modules;
  3373. var nodeOps = backend.nodeOps;
  3374. for (i = 0; i < hooks$1.length; ++i) {
  3375. cbs[hooks$1[i]] = []
  3376. for (j = 0; j < modules.length; ++j) {
  3377. if (modules[j][hooks$1[i]] !== undefined) cbs[hooks$1[i]].push(modules[j][hooks$1[i]])
  3378. }
  3379. }
  3380. function emptyNodeAt (elm) {
  3381. return new VNode(nodeOps.tagName(elm).toLowerCase(), {}, [], undefined, elm)
  3382. }
  3383. function createRmCb (childElm, listeners) {
  3384. function remove () {
  3385. if (--remove.listeners === 0) {
  3386. removeElement(childElm)
  3387. }
  3388. }
  3389. remove.listeners = listeners
  3390. return remove
  3391. }
  3392. function removeElement (el) {
  3393. var parent = nodeOps.parentNode(el)
  3394. nodeOps.removeChild(parent, el)
  3395. }
  3396. function createElm (vnode, insertedVnodeQueue, nested) {
  3397. var i
  3398. var data = vnode.data
  3399. vnode.isRootInsert = !nested
  3400. if (isDef(data)) {
  3401. if (isDef(i = data.hook) && isDef(i = i.init)) i(vnode)
  3402. // after calling the init hook, if the vnode is a child component
  3403. // it should've created a child instance and mounted it. the child
  3404. // component also has set the placeholder vnode's elm.
  3405. // in that case we can just return the element and be done.
  3406. if (isDef(i = vnode.child)) {
  3407. initComponent(vnode, insertedVnodeQueue)
  3408. return vnode.elm
  3409. }
  3410. }
  3411. var children = vnode.children
  3412. var tag = vnode.tag
  3413. if (isDef(tag)) {
  3414. if (process.env.NODE_ENV !== 'production') {
  3415. if (
  3416. !vnode.ns &&
  3417. !(config.ignoredElements && config.ignoredElements.indexOf(tag) > -1) &&
  3418. config.isUnknownElement(tag)
  3419. ) {
  3420. warn(
  3421. 'Unknown custom element: <' + tag + '> - did you ' +
  3422. 'register the component correctly? For recursive components, ' +
  3423. 'make sure to provide the "name" option.',
  3424. vnode.context
  3425. )
  3426. }
  3427. }
  3428. vnode.elm = vnode.ns
  3429. ? nodeOps.createElementNS(vnode.ns, tag)
  3430. : nodeOps.createElement(tag)
  3431. setScope(vnode)
  3432. createChildren(vnode, children, insertedVnodeQueue)
  3433. if (isDef(data)) {
  3434. invokeCreateHooks(vnode, insertedVnodeQueue)
  3435. }
  3436. } else if (vnode.isComment) {
  3437. vnode.elm = nodeOps.createComment(vnode.text)
  3438. } else {
  3439. vnode.elm = nodeOps.createTextNode(vnode.text)
  3440. }
  3441. return vnode.elm
  3442. }
  3443. function createChildren (vnode, children, insertedVnodeQueue) {
  3444. if (Array.isArray(children)) {
  3445. for (var i = 0; i < children.length; ++i) {
  3446. nodeOps.appendChild(vnode.elm, createElm(children[i], insertedVnodeQueue, true))
  3447. }
  3448. } else if (isPrimitive(vnode.text)) {
  3449. nodeOps.appendChild(vnode.elm, nodeOps.createTextNode(vnode.text))
  3450. }
  3451. }
  3452. function isPatchable (vnode) {
  3453. while (vnode.child) {
  3454. vnode = vnode.child._vnode
  3455. }
  3456. return isDef(vnode.tag)
  3457. }
  3458. function invokeCreateHooks (vnode, insertedVnodeQueue) {
  3459. for (var i$1 = 0; i$1 < cbs.create.length; ++i$1) {
  3460. cbs.create[i$1](emptyNode, vnode)
  3461. }
  3462. i = vnode.data.hook // Reuse variable
  3463. if (isDef(i)) {
  3464. if (i.create) i.create(emptyNode, vnode)
  3465. if (i.insert) insertedVnodeQueue.push(vnode)
  3466. }
  3467. }
  3468. function initComponent (vnode, insertedVnodeQueue) {
  3469. if (vnode.data.pendingInsert) {
  3470. insertedVnodeQueue.push.apply(insertedVnodeQueue, vnode.data.pendingInsert)
  3471. }
  3472. vnode.elm = vnode.child.$el
  3473. if (isPatchable(vnode)) {
  3474. invokeCreateHooks(vnode, insertedVnodeQueue)
  3475. setScope(vnode)
  3476. } else {
  3477. // empty component root.
  3478. // skip all element-related modules except for ref (#3455)
  3479. registerRef(vnode)
  3480. // make sure to invoke the insert hook
  3481. insertedVnodeQueue.push(vnode)
  3482. }
  3483. }
  3484. // set scope id attribute for scoped CSS.
  3485. // this is implemented as a special case to avoid the overhead
  3486. // of going through the normal attribute patching process.
  3487. function setScope (vnode) {
  3488. var i
  3489. if (isDef(i = vnode.context) && isDef(i = i.$options._scopeId)) {
  3490. nodeOps.setAttribute(vnode.elm, i, '')
  3491. }
  3492. if (isDef(i = activeInstance) &&
  3493. i !== vnode.context &&
  3494. isDef(i = i.$options._scopeId)) {
  3495. nodeOps.setAttribute(vnode.elm, i, '')
  3496. }
  3497. }
  3498. function addVnodes (parentElm, before, vnodes, startIdx, endIdx, insertedVnodeQueue) {
  3499. for (; startIdx <= endIdx; ++startIdx) {
  3500. nodeOps.insertBefore(parentElm, createElm(vnodes[startIdx], insertedVnodeQueue), before)
  3501. }
  3502. }
  3503. function invokeDestroyHook (vnode) {
  3504. var i, j
  3505. var data = vnode.data
  3506. if (isDef(data)) {
  3507. if (isDef(i = data.hook) && isDef(i = i.destroy)) i(vnode)
  3508. for (i = 0; i < cbs.destroy.length; ++i) cbs.destroy[i](vnode)
  3509. }
  3510. if (isDef(i = vnode.child) && !data.keepAlive) {
  3511. invokeDestroyHook(i._vnode)
  3512. }
  3513. if (isDef(i = vnode.children)) {
  3514. for (j = 0; j < vnode.children.length; ++j) {
  3515. invokeDestroyHook(vnode.children[j])
  3516. }
  3517. }
  3518. }
  3519. function removeVnodes (parentElm, vnodes, startIdx, endIdx) {
  3520. for (; startIdx <= endIdx; ++startIdx) {
  3521. var ch = vnodes[startIdx]
  3522. if (isDef(ch)) {
  3523. if (isDef(ch.tag)) {
  3524. removeAndInvokeRemoveHook(ch)
  3525. invokeDestroyHook(ch)
  3526. } else { // Text node
  3527. nodeOps.removeChild(parentElm, ch.elm)
  3528. }
  3529. }
  3530. }
  3531. }
  3532. function removeAndInvokeRemoveHook (vnode, rm) {
  3533. if (rm || isDef(vnode.data)) {
  3534. var listeners = cbs.remove.length + 1
  3535. if (!rm) {
  3536. // directly removing
  3537. rm = createRmCb(vnode.elm, listeners)
  3538. } else {
  3539. // we have a recursively passed down rm callback
  3540. // increase the listeners count
  3541. rm.listeners += listeners
  3542. }
  3543. // recursively invoke hooks on child component root node
  3544. if (isDef(i = vnode.child) && isDef(i = i._vnode) && isDef(i.data)) {
  3545. removeAndInvokeRemoveHook(i, rm)
  3546. }
  3547. for (i = 0; i < cbs.remove.length; ++i) {
  3548. cbs.remove[i](vnode, rm)
  3549. }
  3550. if (isDef(i = vnode.data.hook) && isDef(i = i.remove)) {
  3551. i(vnode, rm)
  3552. } else {
  3553. rm()
  3554. }
  3555. } else {
  3556. removeElement(vnode.elm)
  3557. }
  3558. }
  3559. function updateChildren (parentElm, oldCh, newCh, insertedVnodeQueue, removeOnly) {
  3560. var oldStartIdx = 0
  3561. var newStartIdx = 0
  3562. var oldEndIdx = oldCh.length - 1
  3563. var oldStartVnode = oldCh[0]
  3564. var oldEndVnode = oldCh[oldEndIdx]
  3565. var newEndIdx = newCh.length - 1
  3566. var newStartVnode = newCh[0]
  3567. var newEndVnode = newCh[newEndIdx]
  3568. var oldKeyToIdx, idxInOld, elmToMove, before
  3569. // removeOnly is a special flag used only by <transition-group>
  3570. // to ensure removed elements stay in correct relative positions
  3571. // during leaving transitions
  3572. var canMove = !removeOnly
  3573. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  3574. if (isUndef(oldStartVnode)) {
  3575. oldStartVnode = oldCh[++oldStartIdx] // Vnode has been moved left
  3576. } else if (isUndef(oldEndVnode)) {
  3577. oldEndVnode = oldCh[--oldEndIdx]
  3578. } else if (sameVnode(oldStartVnode, newStartVnode)) {
  3579. patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue)
  3580. oldStartVnode = oldCh[++oldStartIdx]
  3581. newStartVnode = newCh[++newStartIdx]
  3582. } else if (sameVnode(oldEndVnode, newEndVnode)) {
  3583. patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue)
  3584. oldEndVnode = oldCh[--oldEndIdx]
  3585. newEndVnode = newCh[--newEndIdx]
  3586. } else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right
  3587. patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue)
  3588. canMove && nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm))
  3589. oldStartVnode = oldCh[++oldStartIdx]
  3590. newEndVnode = newCh[--newEndIdx]
  3591. } else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left
  3592. patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue)
  3593. canMove && nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm)
  3594. oldEndVnode = oldCh[--oldEndIdx]
  3595. newStartVnode = newCh[++newStartIdx]
  3596. } else {
  3597. if (isUndef(oldKeyToIdx)) oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx)
  3598. idxInOld = isDef(newStartVnode.key) ? oldKeyToIdx[newStartVnode.key] : null
  3599. if (isUndef(idxInOld)) { // New element
  3600. nodeOps.insertBefore(parentElm, createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm)
  3601. newStartVnode = newCh[++newStartIdx]
  3602. } else {
  3603. elmToMove = oldCh[idxInOld]
  3604. /* istanbul ignore if */
  3605. if (process.env.NODE_ENV !== 'production' && !elmToMove) {
  3606. warn(
  3607. 'It seems there are duplicate keys that is causing an update error. ' +
  3608. 'Make sure each v-for item has a unique key.'
  3609. )
  3610. }
  3611. if (elmToMove.tag !== newStartVnode.tag) {
  3612. // same key but different element. treat as new element
  3613. nodeOps.insertBefore(parentElm, createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm)
  3614. newStartVnode = newCh[++newStartIdx]
  3615. } else {
  3616. patchVnode(elmToMove, newStartVnode, insertedVnodeQueue)
  3617. oldCh[idxInOld] = undefined
  3618. canMove && nodeOps.insertBefore(parentElm, newStartVnode.elm, oldStartVnode.elm)
  3619. newStartVnode = newCh[++newStartIdx]
  3620. }
  3621. }
  3622. }
  3623. }
  3624. if (oldStartIdx > oldEndIdx) {
  3625. before = isUndef(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm
  3626. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx, insertedVnodeQueue)
  3627. } else if (newStartIdx > newEndIdx) {
  3628. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx)
  3629. }
  3630. }
  3631. function patchVnode (oldVnode, vnode, insertedVnodeQueue, removeOnly) {
  3632. if (oldVnode === vnode) {
  3633. return
  3634. }
  3635. // reuse element for static trees.
  3636. // note we only do this if the vnode is cloned -
  3637. // if the new node is not cloned it means the render functions have been
  3638. // reset by the hot-reload-api and we need to do a proper re-render.
  3639. if (vnode.isStatic &&
  3640. oldVnode.isStatic &&
  3641. vnode.key === oldVnode.key &&
  3642. vnode.isCloned) {
  3643. vnode.elm = oldVnode.elm
  3644. return
  3645. }
  3646. var i, hook
  3647. var hasData = isDef(i = vnode.data)
  3648. if (hasData && isDef(hook = i.hook) && isDef(i = hook.prepatch)) {
  3649. i(oldVnode, vnode)
  3650. }
  3651. var elm = vnode.elm = oldVnode.elm
  3652. var oldCh = oldVnode.children
  3653. var ch = vnode.children
  3654. if (hasData && isPatchable(vnode)) {
  3655. for (i = 0; i < cbs.update.length; ++i) cbs.update[i](oldVnode, vnode)
  3656. if (isDef(hook) && isDef(i = hook.update)) i(oldVnode, vnode)
  3657. }
  3658. if (isUndef(vnode.text)) {
  3659. if (isDef(oldCh) && isDef(ch)) {
  3660. if (oldCh !== ch) updateChildren(elm, oldCh, ch, insertedVnodeQueue, removeOnly)
  3661. } else if (isDef(ch)) {
  3662. if (isDef(oldVnode.text)) nodeOps.setTextContent(elm, '')
  3663. addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue)
  3664. } else if (isDef(oldCh)) {
  3665. removeVnodes(elm, oldCh, 0, oldCh.length - 1)
  3666. } else if (isDef(oldVnode.text)) {
  3667. nodeOps.setTextContent(elm, '')
  3668. }
  3669. } else if (oldVnode.text !== vnode.text) {
  3670. nodeOps.setTextContent(elm, vnode.text)
  3671. }
  3672. if (hasData) {
  3673. for (i = 0; i < cbs.postpatch.length; ++i) cbs.postpatch[i](oldVnode, vnode)
  3674. if (isDef(hook) && isDef(i = hook.postpatch)) i(oldVnode, vnode)
  3675. }
  3676. }
  3677. function invokeInsertHook (vnode, queue, initial) {
  3678. // delay insert hooks for component root nodes, invoke them after the
  3679. // element is really inserted
  3680. if (initial && vnode.parent) {
  3681. vnode.parent.data.pendingInsert = queue
  3682. } else {
  3683. for (var i = 0; i < queue.length; ++i) {
  3684. queue[i].data.hook.insert(queue[i])
  3685. }
  3686. }
  3687. }
  3688. var bailed = false
  3689. function hydrate (elm, vnode, insertedVnodeQueue) {
  3690. if (process.env.NODE_ENV !== 'production') {
  3691. if (!assertNodeMatch(elm, vnode)) {
  3692. return false
  3693. }
  3694. }
  3695. vnode.elm = elm
  3696. var tag = vnode.tag;
  3697. var data = vnode.data;
  3698. var children = vnode.children;
  3699. if (isDef(data)) {
  3700. if (isDef(i = data.hook) && isDef(i = i.init)) i(vnode, true /* hydrating */)
  3701. if (isDef(i = vnode.child)) {
  3702. // child component. it should have hydrated its own tree.
  3703. initComponent(vnode, insertedVnodeQueue)
  3704. return true
  3705. }
  3706. }
  3707. if (isDef(tag)) {
  3708. if (isDef(children)) {
  3709. var childNodes = nodeOps.childNodes(elm)
  3710. // empty element, allow client to pick up and populate children
  3711. if (!childNodes.length) {
  3712. createChildren(vnode, children, insertedVnodeQueue)
  3713. } else {
  3714. var childrenMatch = true
  3715. if (childNodes.length !== children.length) {
  3716. childrenMatch = false
  3717. } else {
  3718. for (var i$1 = 0; i$1 < children.length; i$1++) {
  3719. if (!hydrate(childNodes[i$1], children[i$1], insertedVnodeQueue)) {
  3720. childrenMatch = false
  3721. break
  3722. }
  3723. }
  3724. }
  3725. if (!childrenMatch) {
  3726. if (process.env.NODE_ENV !== 'production' &&
  3727. typeof console !== 'undefined' &&
  3728. !bailed) {
  3729. bailed = true
  3730. console.warn('Parent: ', elm)
  3731. console.warn('Mismatching childNodes vs. VNodes: ', childNodes, children)
  3732. }
  3733. return false
  3734. }
  3735. }
  3736. }
  3737. if (isDef(data)) {
  3738. invokeCreateHooks(vnode, insertedVnodeQueue)
  3739. }
  3740. }
  3741. return true
  3742. }
  3743. function assertNodeMatch (node, vnode) {
  3744. if (vnode.tag) {
  3745. return (
  3746. vnode.tag.indexOf('vue-component') === 0 ||
  3747. vnode.tag === nodeOps.tagName(node).toLowerCase()
  3748. )
  3749. } else {
  3750. return _toString(vnode.text) === node.data
  3751. }
  3752. }
  3753. return function patch (oldVnode, vnode, hydrating, removeOnly) {
  3754. var elm, parent
  3755. var isInitialPatch = false
  3756. var insertedVnodeQueue = []
  3757. if (!oldVnode) {
  3758. // empty mount, create new root element
  3759. isInitialPatch = true
  3760. createElm(vnode, insertedVnodeQueue)
  3761. } else {
  3762. var isRealElement = isDef(oldVnode.nodeType)
  3763. if (!isRealElement && sameVnode(oldVnode, vnode)) {
  3764. patchVnode(oldVnode, vnode, insertedVnodeQueue, removeOnly)
  3765. } else {
  3766. if (isRealElement) {
  3767. // mounting to a real element
  3768. // check if this is server-rendered content and if we can perform
  3769. // a successful hydration.
  3770. if (oldVnode.nodeType === 1 && oldVnode.hasAttribute('server-rendered')) {
  3771. oldVnode.removeAttribute('server-rendered')
  3772. hydrating = true
  3773. }
  3774. if (hydrating) {
  3775. if (hydrate(oldVnode, vnode, insertedVnodeQueue)) {
  3776. invokeInsertHook(vnode, insertedVnodeQueue, true)
  3777. return oldVnode
  3778. } else if (process.env.NODE_ENV !== 'production') {
  3779. warn(
  3780. 'The client-side rendered virtual DOM tree is not matching ' +
  3781. 'server-rendered content. This is likely caused by incorrect ' +
  3782. 'HTML markup, for example nesting block-level elements inside ' +
  3783. '<p>, or missing <tbody>. Bailing hydration and performing ' +
  3784. 'full client-side render.'
  3785. )
  3786. }
  3787. }
  3788. // either not server-rendered, or hydration failed.
  3789. // create an empty node and replace it
  3790. oldVnode = emptyNodeAt(oldVnode)
  3791. }
  3792. elm = oldVnode.elm
  3793. parent = nodeOps.parentNode(elm)
  3794. createElm(vnode, insertedVnodeQueue)
  3795. // component root element replaced.
  3796. // update parent placeholder node element.
  3797. if (vnode.parent) {
  3798. vnode.parent.elm = vnode.elm
  3799. if (isPatchable(vnode)) {
  3800. for (var i = 0; i < cbs.create.length; ++i) {
  3801. cbs.create[i](emptyNode, vnode.parent)
  3802. }
  3803. }
  3804. }
  3805. if (parent !== null) {
  3806. nodeOps.insertBefore(parent, vnode.elm, nodeOps.nextSibling(elm))
  3807. removeVnodes(parent, [oldVnode], 0, 0)
  3808. } else if (isDef(oldVnode.tag)) {
  3809. invokeDestroyHook(oldVnode)
  3810. }
  3811. }
  3812. }
  3813. invokeInsertHook(vnode, insertedVnodeQueue, isInitialPatch)
  3814. return vnode.elm
  3815. }
  3816. }
  3817. /* */
  3818. var directives = {
  3819. create: function bindDirectives (oldVnode, vnode) {
  3820. var hasInsert = false
  3821. forEachDirective(oldVnode, vnode, function (def, dir) {
  3822. callHook$1(def, dir, 'bind', vnode, oldVnode)
  3823. if (def.inserted) {
  3824. hasInsert = true
  3825. }
  3826. })
  3827. if (hasInsert) {
  3828. mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', function () {
  3829. applyDirectives(oldVnode, vnode, 'inserted')
  3830. })
  3831. }
  3832. },
  3833. update: function updateDirectives (oldVnode, vnode) {
  3834. applyDirectives(oldVnode, vnode, 'update')
  3835. // if old vnode has directives but new vnode doesn't
  3836. // we need to teardown the directives on the old one.
  3837. if (oldVnode.data.directives && !vnode.data.directives) {
  3838. applyDirectives(oldVnode, oldVnode, 'unbind')
  3839. }
  3840. },
  3841. postpatch: function postupdateDirectives (oldVnode, vnode) {
  3842. applyDirectives(oldVnode, vnode, 'componentUpdated')
  3843. },
  3844. destroy: function unbindDirectives (vnode) {
  3845. applyDirectives(vnode, vnode, 'unbind')
  3846. }
  3847. }
  3848. var emptyModifiers = Object.create(null)
  3849. function forEachDirective (
  3850. oldVnode,
  3851. vnode,
  3852. fn
  3853. ) {
  3854. var dirs = vnode.data.directives
  3855. if (dirs) {
  3856. for (var i = 0; i < dirs.length; i++) {
  3857. var dir = dirs[i]
  3858. var def = resolveAsset(vnode.context.$options, 'directives', dir.name, true)
  3859. if (def) {
  3860. var oldDirs = oldVnode && oldVnode.data.directives
  3861. if (oldDirs) {
  3862. dir.oldValue = oldDirs[i].value
  3863. }
  3864. if (!dir.modifiers) {
  3865. dir.modifiers = emptyModifiers
  3866. }
  3867. fn(def, dir)
  3868. }
  3869. }
  3870. }
  3871. }
  3872. function applyDirectives (
  3873. oldVnode,
  3874. vnode,
  3875. hook
  3876. ) {
  3877. forEachDirective(oldVnode, vnode, function (def, dir) {
  3878. callHook$1(def, dir, hook, vnode, oldVnode)
  3879. })
  3880. }
  3881. function callHook$1 (def, dir, hook, vnode, oldVnode) {
  3882. var fn = def && def[hook]
  3883. if (fn) {
  3884. fn(vnode.elm, dir, vnode, oldVnode)
  3885. }
  3886. }
  3887. var baseModules = [
  3888. ref,
  3889. directives
  3890. ]
  3891. /* */
  3892. function updateAttrs (oldVnode, vnode) {
  3893. if (!oldVnode.data.attrs && !vnode.data.attrs) {
  3894. return
  3895. }
  3896. var key, cur, old
  3897. var elm = vnode.elm
  3898. var oldAttrs = oldVnode.data.attrs || {}
  3899. var attrs = vnode.data.attrs || {}
  3900. // clone observed objects, as the user probably wants to mutate it
  3901. if (attrs.__ob__) {
  3902. attrs = vnode.data.attrs = extend({}, attrs)
  3903. }
  3904. for (key in attrs) {
  3905. cur = attrs[key]
  3906. old = oldAttrs[key]
  3907. if (old !== cur) {
  3908. setAttr(elm, key, cur)
  3909. }
  3910. }
  3911. for (key in oldAttrs) {
  3912. if (attrs[key] == null) {
  3913. if (isXlink(key)) {
  3914. elm.removeAttributeNS(xlinkNS, getXlinkProp(key))
  3915. } else if (!isEnumeratedAttr(key)) {
  3916. elm.removeAttribute(key)
  3917. }
  3918. }
  3919. }
  3920. }
  3921. function setAttr (el, key, value) {
  3922. if (isBooleanAttr(key)) {
  3923. // set attribute for blank value
  3924. // e.g. <option disabled>Select one</option>
  3925. if (isFalsyAttrValue(value)) {
  3926. el.removeAttribute(key)
  3927. } else {
  3928. el.setAttribute(key, key)
  3929. }
  3930. } else if (isEnumeratedAttr(key)) {
  3931. el.setAttribute(key, isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true')
  3932. } else if (isXlink(key)) {
  3933. if (isFalsyAttrValue(value)) {
  3934. el.removeAttributeNS(xlinkNS, getXlinkProp(key))
  3935. } else {
  3936. el.setAttributeNS(xlinkNS, key, value)
  3937. }
  3938. } else {
  3939. if (isFalsyAttrValue(value)) {
  3940. el.removeAttribute(key)
  3941. } else {
  3942. el.setAttribute(key, value)
  3943. }
  3944. }
  3945. }
  3946. var attrs = {
  3947. create: updateAttrs,
  3948. update: updateAttrs
  3949. }
  3950. /* */
  3951. function updateClass (oldVnode, vnode) {
  3952. var el = vnode.elm
  3953. var data = vnode.data
  3954. var oldData = oldVnode.data
  3955. if (!data.staticClass && !data.class &&
  3956. (!oldData || (!oldData.staticClass && !oldData.class))) {
  3957. return
  3958. }
  3959. var cls = genClassForVnode(vnode)
  3960. // handle transition classes
  3961. var transitionClass = el._transitionClasses
  3962. if (transitionClass) {
  3963. cls = concat(cls, stringifyClass(transitionClass))
  3964. }
  3965. // set the class
  3966. if (cls !== el._prevClass) {
  3967. el.setAttribute('class', cls)
  3968. el._prevClass = cls
  3969. }
  3970. }
  3971. var klass = {
  3972. create: updateClass,
  3973. update: updateClass
  3974. }
  3975. // skip type checking this file because we need to attach private properties
  3976. // to elements
  3977. function updateDOMListeners (oldVnode, vnode) {
  3978. if (!oldVnode.data.on && !vnode.data.on) {
  3979. return
  3980. }
  3981. var on = vnode.data.on || {}
  3982. var oldOn = oldVnode.data.on || {}
  3983. var add = vnode.elm._v_add || (vnode.elm._v_add = function (event, handler, capture) {
  3984. vnode.elm.addEventListener(event, handler, capture)
  3985. })
  3986. var remove = vnode.elm._v_remove || (vnode.elm._v_remove = function (event, handler) {
  3987. vnode.elm.removeEventListener(event, handler)
  3988. })
  3989. updateListeners(on, oldOn, add, remove)
  3990. }
  3991. var events = {
  3992. create: updateDOMListeners,
  3993. update: updateDOMListeners
  3994. }
  3995. /* */
  3996. function updateDOMProps (oldVnode, vnode) {
  3997. if (!oldVnode.data.domProps && !vnode.data.domProps) {
  3998. return
  3999. }
  4000. var key, cur
  4001. var elm = vnode.elm
  4002. var oldProps = oldVnode.data.domProps || {}
  4003. var props = vnode.data.domProps || {}
  4004. // clone observed objects, as the user probably wants to mutate it
  4005. if (props.__ob__) {
  4006. props = vnode.data.domProps = extend({}, props)
  4007. }
  4008. for (key in oldProps) {
  4009. if (props[key] == null) {
  4010. elm[key] = undefined
  4011. }
  4012. }
  4013. for (key in props) {
  4014. // ignore children if the node has textContent or innerHTML,
  4015. // as these will throw away existing DOM nodes and cause removal errors
  4016. // on subsequent patches (#3360)
  4017. if ((key === 'textContent' || key === 'innerHTML') && vnode.children) {
  4018. vnode.children.length = 0
  4019. }
  4020. cur = props[key]
  4021. if (key === 'value') {
  4022. // store value as _value as well since
  4023. // non-string values will be stringified
  4024. elm._value = cur
  4025. // avoid resetting cursor position when value is the same
  4026. var strCur = cur == null ? '' : String(cur)
  4027. if (elm.value !== strCur) {
  4028. elm.value = strCur
  4029. }
  4030. } else {
  4031. elm[key] = cur
  4032. }
  4033. }
  4034. }
  4035. var domProps = {
  4036. create: updateDOMProps,
  4037. update: updateDOMProps
  4038. }
  4039. /* */
  4040. var prefixes = ['Webkit', 'Moz', 'ms']
  4041. var testEl
  4042. var normalize = cached(function (prop) {
  4043. testEl = testEl || document.createElement('div')
  4044. prop = camelize(prop)
  4045. if (prop !== 'filter' && (prop in testEl.style)) {
  4046. return prop
  4047. }
  4048. var upper = prop.charAt(0).toUpperCase() + prop.slice(1)
  4049. for (var i = 0; i < prefixes.length; i++) {
  4050. var prefixed = prefixes[i] + upper
  4051. if (prefixed in testEl.style) {
  4052. return prefixed
  4053. }
  4054. }
  4055. })
  4056. function updateStyle (oldVnode, vnode) {
  4057. if ((!oldVnode.data || !oldVnode.data.style) && !vnode.data.style) {
  4058. return
  4059. }
  4060. var cur, name
  4061. var el = vnode.elm
  4062. var oldStyle = oldVnode.data.style || {}
  4063. var style = vnode.data.style || {}
  4064. // handle string
  4065. if (typeof style === 'string') {
  4066. el.style.cssText = style
  4067. return
  4068. }
  4069. var needClone = style.__ob__
  4070. // handle array syntax
  4071. if (Array.isArray(style)) {
  4072. style = vnode.data.style = toObject(style)
  4073. }
  4074. // clone the style for future updates,
  4075. // in case the user mutates the style object in-place.
  4076. if (needClone) {
  4077. style = vnode.data.style = extend({}, style)
  4078. }
  4079. for (name in oldStyle) {
  4080. if (!style[name]) {
  4081. el.style[normalize(name)] = ''
  4082. }
  4083. }
  4084. for (name in style) {
  4085. cur = style[name]
  4086. if (cur !== oldStyle[name]) {
  4087. // ie9 setting to null has no effect, must use empty string
  4088. el.style[normalize(name)] = cur || ''
  4089. }
  4090. }
  4091. }
  4092. var style = {
  4093. create: updateStyle,
  4094. update: updateStyle
  4095. }
  4096. /* */
  4097. /**
  4098. * Add class with compatibility for SVG since classList is not supported on
  4099. * SVG elements in IE
  4100. */
  4101. function addClass (el, cls) {
  4102. /* istanbul ignore else */
  4103. if (el.classList) {
  4104. if (cls.indexOf(' ') > -1) {
  4105. cls.split(/\s+/).forEach(function (c) { return el.classList.add(c); })
  4106. } else {
  4107. el.classList.add(cls)
  4108. }
  4109. } else {
  4110. var cur = ' ' + el.getAttribute('class') + ' '
  4111. if (cur.indexOf(' ' + cls + ' ') < 0) {
  4112. el.setAttribute('class', (cur + cls).trim())
  4113. }
  4114. }
  4115. }
  4116. /**
  4117. * Remove class with compatibility for SVG since classList is not supported on
  4118. * SVG elements in IE
  4119. */
  4120. function removeClass (el, cls) {
  4121. /* istanbul ignore else */
  4122. if (el.classList) {
  4123. if (cls.indexOf(' ') > -1) {
  4124. cls.split(/\s+/).forEach(function (c) { return el.classList.remove(c); })
  4125. } else {
  4126. el.classList.remove(cls)
  4127. }
  4128. } else {
  4129. var cur = ' ' + el.getAttribute('class') + ' '
  4130. var tar = ' ' + cls + ' '
  4131. while (cur.indexOf(tar) >= 0) {
  4132. cur = cur.replace(tar, ' ')
  4133. }
  4134. el.setAttribute('class', cur.trim())
  4135. }
  4136. }
  4137. /* */
  4138. var hasTransition = inBrowser && !isIE9
  4139. var TRANSITION = 'transition'
  4140. var ANIMATION = 'animation'
  4141. // Transition property/event sniffing
  4142. var transitionProp = 'transition'
  4143. var transitionEndEvent = 'transitionend'
  4144. var animationProp = 'animation'
  4145. var animationEndEvent = 'animationend'
  4146. if (hasTransition) {
  4147. /* istanbul ignore if */
  4148. if (window.ontransitionend === undefined &&
  4149. window.onwebkittransitionend !== undefined) {
  4150. transitionProp = 'WebkitTransition'
  4151. transitionEndEvent = 'webkitTransitionEnd'
  4152. }
  4153. if (window.onanimationend === undefined &&
  4154. window.onwebkitanimationend !== undefined) {
  4155. animationProp = 'WebkitAnimation'
  4156. animationEndEvent = 'webkitAnimationEnd'
  4157. }
  4158. }
  4159. var raf = (inBrowser && window.requestAnimationFrame) || setTimeout
  4160. function nextFrame (fn) {
  4161. raf(function () {
  4162. raf(fn)
  4163. })
  4164. }
  4165. function addTransitionClass (el, cls) {
  4166. (el._transitionClasses || (el._transitionClasses = [])).push(cls)
  4167. addClass(el, cls)
  4168. }
  4169. function removeTransitionClass (el, cls) {
  4170. if (el._transitionClasses) {
  4171. remove(el._transitionClasses, cls)
  4172. }
  4173. removeClass(el, cls)
  4174. }
  4175. function whenTransitionEnds (
  4176. el,
  4177. expectedType,
  4178. cb
  4179. ) {
  4180. var ref = getTransitionInfo(el, expectedType);
  4181. var type = ref.type;
  4182. var timeout = ref.timeout;
  4183. var propCount = ref.propCount;
  4184. if (!type) return cb()
  4185. var event = type === TRANSITION ? transitionEndEvent : animationEndEvent
  4186. var ended = 0
  4187. var end = function () {
  4188. el.removeEventListener(event, onEnd)
  4189. cb()
  4190. }
  4191. var onEnd = function (e) {
  4192. if (e.target === el) {
  4193. if (++ended >= propCount) {
  4194. end()
  4195. }
  4196. }
  4197. }
  4198. setTimeout(function () {
  4199. if (ended < propCount) {
  4200. end()
  4201. }
  4202. }, timeout + 1)
  4203. el.addEventListener(event, onEnd)
  4204. }
  4205. var transformRE = /\b(transform|all)(,|$)/
  4206. function getTransitionInfo (el, expectedType) {
  4207. var styles = window.getComputedStyle(el)
  4208. var transitioneDelays = styles[transitionProp + 'Delay'].split(', ')
  4209. var transitionDurations = styles[transitionProp + 'Duration'].split(', ')
  4210. var transitionTimeout = getTimeout(transitioneDelays, transitionDurations)
  4211. var animationDelays = styles[animationProp + 'Delay'].split(', ')
  4212. var animationDurations = styles[animationProp + 'Duration'].split(', ')
  4213. var animationTimeout = getTimeout(animationDelays, animationDurations)
  4214. var type
  4215. var timeout = 0
  4216. var propCount = 0
  4217. /* istanbul ignore if */
  4218. if (expectedType === TRANSITION) {
  4219. if (transitionTimeout > 0) {
  4220. type = TRANSITION
  4221. timeout = transitionTimeout
  4222. propCount = transitionDurations.length
  4223. }
  4224. } else if (expectedType === ANIMATION) {
  4225. if (animationTimeout > 0) {
  4226. type = ANIMATION
  4227. timeout = animationTimeout
  4228. propCount = animationDurations.length
  4229. }
  4230. } else {
  4231. timeout = Math.max(transitionTimeout, animationTimeout)
  4232. type = timeout > 0
  4233. ? transitionTimeout > animationTimeout
  4234. ? TRANSITION
  4235. : ANIMATION
  4236. : null
  4237. propCount = type
  4238. ? type === TRANSITION
  4239. ? transitionDurations.length
  4240. : animationDurations.length
  4241. : 0
  4242. }
  4243. var hasTransform =
  4244. type === TRANSITION &&
  4245. transformRE.test(styles[transitionProp + 'Property'])
  4246. return {
  4247. type: type,
  4248. timeout: timeout,
  4249. propCount: propCount,
  4250. hasTransform: hasTransform
  4251. }
  4252. }
  4253. function getTimeout (delays, durations) {
  4254. return Math.max.apply(null, durations.map(function (d, i) {
  4255. return toMs(d) + toMs(delays[i])
  4256. }))
  4257. }
  4258. function toMs (s) {
  4259. return Number(s.slice(0, -1)) * 1000
  4260. }
  4261. /* */
  4262. function enter (vnode) {
  4263. var el = vnode.elm
  4264. // call leave callback now
  4265. if (el._leaveCb) {
  4266. el._leaveCb.cancelled = true
  4267. el._leaveCb()
  4268. }
  4269. var data = resolveTransition(vnode.data.transition)
  4270. if (!data) {
  4271. return
  4272. }
  4273. /* istanbul ignore if */
  4274. if (el._enterCb || el.nodeType !== 1) {
  4275. return
  4276. }
  4277. var css = data.css;
  4278. var type = data.type;
  4279. var enterClass = data.enterClass;
  4280. var enterActiveClass = data.enterActiveClass;
  4281. var appearClass = data.appearClass;
  4282. var appearActiveClass = data.appearActiveClass;
  4283. var beforeEnter = data.beforeEnter;
  4284. var enter = data.enter;
  4285. var afterEnter = data.afterEnter;
  4286. var enterCancelled = data.enterCancelled;
  4287. var beforeAppear = data.beforeAppear;
  4288. var appear = data.appear;
  4289. var afterAppear = data.afterAppear;
  4290. var appearCancelled = data.appearCancelled;
  4291. // activeInstance will always be the <transition> component managing this
  4292. // transition. One edge case to check is when the <transition> is placed
  4293. // as the root node of a child component. In that case we need to check
  4294. // <transition>'s parent for appear check.
  4295. var transitionNode = activeInstance.$vnode
  4296. var context = transitionNode && transitionNode.parent
  4297. ? transitionNode.parent.context
  4298. : activeInstance
  4299. var isAppear = !context._isMounted || !vnode.isRootInsert
  4300. if (isAppear && !appear && appear !== '') {
  4301. return
  4302. }
  4303. var startClass = isAppear ? appearClass : enterClass
  4304. var activeClass = isAppear ? appearActiveClass : enterActiveClass
  4305. var beforeEnterHook = isAppear ? (beforeAppear || beforeEnter) : beforeEnter
  4306. var enterHook = isAppear ? (typeof appear === 'function' ? appear : enter) : enter
  4307. var afterEnterHook = isAppear ? (afterAppear || afterEnter) : afterEnter
  4308. var enterCancelledHook = isAppear ? (appearCancelled || enterCancelled) : enterCancelled
  4309. var expectsCSS = css !== false && !isIE9
  4310. var userWantsControl =
  4311. enterHook &&
  4312. // enterHook may be a bound method which exposes
  4313. // the length of original fn as _length
  4314. (enterHook._length || enterHook.length) > 1
  4315. var cb = el._enterCb = once(function () {
  4316. if (expectsCSS) {
  4317. removeTransitionClass(el, activeClass)
  4318. }
  4319. if (cb.cancelled) {
  4320. if (expectsCSS) {
  4321. removeTransitionClass(el, startClass)
  4322. }
  4323. enterCancelledHook && enterCancelledHook(el)
  4324. } else {
  4325. afterEnterHook && afterEnterHook(el)
  4326. }
  4327. el._enterCb = null
  4328. })
  4329. if (!vnode.data.show) {
  4330. // remove pending leave element on enter by injecting an insert hook
  4331. mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', function () {
  4332. var parent = el.parentNode
  4333. var pendingNode = parent && parent._pending && parent._pending[vnode.key]
  4334. if (pendingNode && pendingNode.tag === vnode.tag && pendingNode.elm._leaveCb) {
  4335. pendingNode.elm._leaveCb()
  4336. }
  4337. enterHook && enterHook(el, cb)
  4338. })
  4339. }
  4340. // start enter transition
  4341. beforeEnterHook && beforeEnterHook(el)
  4342. if (expectsCSS) {
  4343. addTransitionClass(el, startClass)
  4344. addTransitionClass(el, activeClass)
  4345. nextFrame(function () {
  4346. removeTransitionClass(el, startClass)
  4347. if (!cb.cancelled && !userWantsControl) {
  4348. whenTransitionEnds(el, type, cb)
  4349. }
  4350. })
  4351. }
  4352. if (vnode.data.show) {
  4353. enterHook && enterHook(el, cb)
  4354. }
  4355. if (!expectsCSS && !userWantsControl) {
  4356. cb()
  4357. }
  4358. }
  4359. function leave (vnode, rm) {
  4360. var el = vnode.elm
  4361. // call enter callback now
  4362. if (el._enterCb) {
  4363. el._enterCb.cancelled = true
  4364. el._enterCb()
  4365. }
  4366. var data = resolveTransition(vnode.data.transition)
  4367. if (!data) {
  4368. return rm()
  4369. }
  4370. /* istanbul ignore if */
  4371. if (el._leaveCb || el.nodeType !== 1) {
  4372. return
  4373. }
  4374. var css = data.css;
  4375. var type = data.type;
  4376. var leaveClass = data.leaveClass;
  4377. var leaveActiveClass = data.leaveActiveClass;
  4378. var beforeLeave = data.beforeLeave;
  4379. var leave = data.leave;
  4380. var afterLeave = data.afterLeave;
  4381. var leaveCancelled = data.leaveCancelled;
  4382. var delayLeave = data.delayLeave;
  4383. var expectsCSS = css !== false && !isIE9
  4384. var userWantsControl =
  4385. leave &&
  4386. // leave hook may be a bound method which exposes
  4387. // the length of original fn as _length
  4388. (leave._length || leave.length) > 1
  4389. var cb = el._leaveCb = once(function () {
  4390. if (el.parentNode && el.parentNode._pending) {
  4391. el.parentNode._pending[vnode.key] = null
  4392. }
  4393. if (expectsCSS) {
  4394. removeTransitionClass(el, leaveActiveClass)
  4395. }
  4396. if (cb.cancelled) {
  4397. if (expectsCSS) {
  4398. removeTransitionClass(el, leaveClass)
  4399. }
  4400. leaveCancelled && leaveCancelled(el)
  4401. } else {
  4402. rm()
  4403. afterLeave && afterLeave(el)
  4404. }
  4405. el._leaveCb = null
  4406. })
  4407. if (delayLeave) {
  4408. delayLeave(performLeave)
  4409. } else {
  4410. performLeave()
  4411. }
  4412. function performLeave () {
  4413. // the delayed leave may have already been cancelled
  4414. if (cb.cancelled) {
  4415. return
  4416. }
  4417. // record leaving element
  4418. if (!vnode.data.show) {
  4419. (el.parentNode._pending || (el.parentNode._pending = {}))[vnode.key] = vnode
  4420. }
  4421. beforeLeave && beforeLeave(el)
  4422. if (expectsCSS) {
  4423. addTransitionClass(el, leaveClass)
  4424. addTransitionClass(el, leaveActiveClass)
  4425. nextFrame(function () {
  4426. removeTransitionClass(el, leaveClass)
  4427. if (!cb.cancelled && !userWantsControl) {
  4428. whenTransitionEnds(el, type, cb)
  4429. }
  4430. })
  4431. }
  4432. leave && leave(el, cb)
  4433. if (!expectsCSS && !userWantsControl) {
  4434. cb()
  4435. }
  4436. }
  4437. }
  4438. function resolveTransition (def) {
  4439. if (!def) {
  4440. return
  4441. }
  4442. /* istanbul ignore else */
  4443. if (typeof def === 'object') {
  4444. var res = {}
  4445. if (def.css !== false) {
  4446. extend(res, autoCssTransition(def.name || 'v'))
  4447. }
  4448. extend(res, def)
  4449. return res
  4450. } else if (typeof def === 'string') {
  4451. return autoCssTransition(def)
  4452. }
  4453. }
  4454. var autoCssTransition = cached(function (name) {
  4455. return {
  4456. enterClass: (name + "-enter"),
  4457. leaveClass: (name + "-leave"),
  4458. appearClass: (name + "-enter"),
  4459. enterActiveClass: (name + "-enter-active"),
  4460. leaveActiveClass: (name + "-leave-active"),
  4461. appearActiveClass: (name + "-enter-active")
  4462. }
  4463. })
  4464. function once (fn) {
  4465. var called = false
  4466. return function () {
  4467. if (!called) {
  4468. called = true
  4469. fn()
  4470. }
  4471. }
  4472. }
  4473. var transition = inBrowser ? {
  4474. create: function create (_, vnode) {
  4475. if (!vnode.data.show) {
  4476. enter(vnode)
  4477. }
  4478. },
  4479. remove: function remove (vnode, rm) {
  4480. /* istanbul ignore else */
  4481. if (!vnode.data.show) {
  4482. leave(vnode, rm)
  4483. } else {
  4484. rm()
  4485. }
  4486. }
  4487. } : {}
  4488. var platformModules = [
  4489. attrs,
  4490. klass,
  4491. events,
  4492. domProps,
  4493. style,
  4494. transition
  4495. ]
  4496. /* */
  4497. // the directive module should be applied last, after all
  4498. // built-in modules have been applied.
  4499. var modules = platformModules.concat(baseModules)
  4500. var patch = createPatchFunction({ nodeOps: nodeOps, modules: modules })
  4501. /**
  4502. * Not type checking this file because flow doesn't like attaching
  4503. * properties to Elements.
  4504. */
  4505. var modelableTagRE = /^input|select|textarea|vue-component-[0-9]+(-[0-9a-zA-Z_\-]*)?$/
  4506. /* istanbul ignore if */
  4507. if (isIE9) {
  4508. // http://www.matts411.com/post/internet-explorer-9-oninput/
  4509. document.addEventListener('selectionchange', function () {
  4510. var el = document.activeElement
  4511. if (el && el.vmodel) {
  4512. trigger(el, 'input')
  4513. }
  4514. })
  4515. }
  4516. var model = {
  4517. bind: function bind (el, binding, vnode) {
  4518. if (process.env.NODE_ENV !== 'production') {
  4519. if (!modelableTagRE.test(vnode.tag)) {
  4520. warn(
  4521. "v-model is not supported on element type: <" + (vnode.tag) + ">. " +
  4522. 'If you are working with contenteditable, it\'s recommended to ' +
  4523. 'wrap a library dedicated for that purpose inside a custom component.',
  4524. vnode.context
  4525. )
  4526. }
  4527. }
  4528. if (vnode.tag === 'select') {
  4529. setSelected(el, binding, vnode.context)
  4530. } else {
  4531. if (!isAndroid) {
  4532. el.addEventListener('compositionstart', onCompositionStart)
  4533. el.addEventListener('compositionend', onCompositionEnd)
  4534. }
  4535. /* istanbul ignore if */
  4536. if (isIE9) {
  4537. el.vmodel = true
  4538. }
  4539. }
  4540. },
  4541. componentUpdated: function componentUpdated (el, binding, vnode) {
  4542. if (vnode.tag === 'select') {
  4543. setSelected(el, binding, vnode.context)
  4544. // in case the options rendered by v-for have changed,
  4545. // it's possible that the value is out-of-sync with the rendered options.
  4546. // detect such cases and filter out values that no longer has a matchig
  4547. // option in the DOM.
  4548. var needReset = el.multiple
  4549. ? binding.value.some(function (v) { return hasNoMatchingOption(v, el.options); })
  4550. : hasNoMatchingOption(binding.value, el.options)
  4551. if (needReset) {
  4552. trigger(el, 'change')
  4553. }
  4554. }
  4555. }
  4556. }
  4557. function setSelected (el, binding, vm) {
  4558. var value = binding.value
  4559. var isMultiple = el.multiple
  4560. if (isMultiple && !Array.isArray(value)) {
  4561. process.env.NODE_ENV !== 'production' && warn(
  4562. "<select multiple v-model=\"" + (binding.expression) + "\"> " +
  4563. "expects an Array value for its binding, but got " + (Object.prototype.toString.call(value).slice(8, -1)),
  4564. vm
  4565. )
  4566. return
  4567. }
  4568. var selected, option
  4569. for (var i = 0, l = el.options.length; i < l; i++) {
  4570. option = el.options[i]
  4571. if (isMultiple) {
  4572. selected = value.indexOf(getValue(option)) > -1
  4573. if (option.selected !== selected) {
  4574. option.selected = selected
  4575. }
  4576. } else {
  4577. if (getValue(option) === value) {
  4578. if (el.selectedIndex !== i) {
  4579. el.selectedIndex = i
  4580. }
  4581. return
  4582. }
  4583. }
  4584. }
  4585. if (!isMultiple) {
  4586. el.selectedIndex = -1
  4587. }
  4588. }
  4589. function hasNoMatchingOption (value, options) {
  4590. for (var i = 0, l = options.length; i < l; i++) {
  4591. if (getValue(options[i]) === value) {
  4592. return false
  4593. }
  4594. }
  4595. return true
  4596. }
  4597. function getValue (option) {
  4598. return '_value' in option
  4599. ? option._value
  4600. : option.value || option.text
  4601. }
  4602. function onCompositionStart (e) {
  4603. e.target.composing = true
  4604. }
  4605. function onCompositionEnd (e) {
  4606. e.target.composing = false
  4607. trigger(e.target, 'input')
  4608. }
  4609. function trigger (el, type) {
  4610. var e = document.createEvent('HTMLEvents')
  4611. e.initEvent(type, true, true)
  4612. el.dispatchEvent(e)
  4613. }
  4614. /* */
  4615. // recursively search for possible transition defined inside the component root
  4616. function locateNode (vnode) {
  4617. return vnode.child && (!vnode.data || !vnode.data.transition)
  4618. ? locateNode(vnode.child._vnode)
  4619. : vnode
  4620. }
  4621. var show = {
  4622. bind: function bind (el, ref, vnode) {
  4623. var value = ref.value;
  4624. vnode = locateNode(vnode)
  4625. var transition = vnode.data && vnode.data.transition
  4626. if (value && transition && !isIE9) {
  4627. enter(vnode)
  4628. }
  4629. var originalDisplay = el.style.display === 'none' ? '' : el.style.display
  4630. el.style.display = value ? originalDisplay : 'none'
  4631. el.__vOriginalDisplay = originalDisplay
  4632. },
  4633. update: function update (el, ref, vnode) {
  4634. var value = ref.value;
  4635. var oldValue = ref.oldValue;
  4636. /* istanbul ignore if */
  4637. if (value === oldValue) return
  4638. vnode = locateNode(vnode)
  4639. var transition = vnode.data && vnode.data.transition
  4640. if (transition && !isIE9) {
  4641. if (value) {
  4642. enter(vnode)
  4643. el.style.display = el.__vOriginalDisplay
  4644. } else {
  4645. leave(vnode, function () {
  4646. el.style.display = 'none'
  4647. })
  4648. }
  4649. } else {
  4650. el.style.display = value ? el.__vOriginalDisplay : 'none'
  4651. }
  4652. }
  4653. }
  4654. var platformDirectives = {
  4655. model: model,
  4656. show: show
  4657. }
  4658. /* */
  4659. // Provides transition support for a single element/component.
  4660. // supports transition mode (out-in / in-out)
  4661. var transitionProps = {
  4662. name: String,
  4663. appear: Boolean,
  4664. css: Boolean,
  4665. mode: String,
  4666. type: String,
  4667. enterClass: String,
  4668. leaveClass: String,
  4669. enterActiveClass: String,
  4670. leaveActiveClass: String,
  4671. appearClass: String,
  4672. appearActiveClass: String
  4673. }
  4674. // in case the child is also an abstract component, e.g. <keep-alive>
  4675. // we want to recrusively retrieve the real component to be rendered
  4676. function getRealChild (vnode) {
  4677. var compOptions = vnode && vnode.componentOptions
  4678. if (compOptions && compOptions.Ctor.options.abstract) {
  4679. return getRealChild(getFirstComponentChild(compOptions.children))
  4680. } else {
  4681. return vnode
  4682. }
  4683. }
  4684. function extractTransitionData (comp) {
  4685. var data = {}
  4686. var options = comp.$options
  4687. // props
  4688. for (var key in options.propsData) {
  4689. data[key] = comp[key]
  4690. }
  4691. // events.
  4692. // extract listeners and pass them directly to the transition methods
  4693. var listeners = options._parentListeners
  4694. for (var key$1 in listeners) {
  4695. data[camelize(key$1)] = listeners[key$1].fn
  4696. }
  4697. return data
  4698. }
  4699. function placeholder (h, rawChild) {
  4700. return /\d-keep-alive$/.test(rawChild.tag)
  4701. ? h('keep-alive')
  4702. : null
  4703. }
  4704. function hasParentTransition (vnode) {
  4705. while ((vnode = vnode.parent)) {
  4706. if (vnode.data.transition) {
  4707. return true
  4708. }
  4709. }
  4710. }
  4711. var Transition = {
  4712. name: 'transition',
  4713. props: transitionProps,
  4714. abstract: true,
  4715. render: function render (h) {
  4716. var this$1 = this;
  4717. var children = this.$slots.default
  4718. if (!children) {
  4719. return
  4720. }
  4721. // filter out text nodes (possible whitespaces)
  4722. children = children.filter(function (c) { return c.tag; })
  4723. /* istanbul ignore if */
  4724. if (!children.length) {
  4725. return
  4726. }
  4727. // warn multiple elements
  4728. if (process.env.NODE_ENV !== 'production' && children.length > 1) {
  4729. warn(
  4730. '<transition> can only be used on a single element. Use ' +
  4731. '<transition-group> for lists.',
  4732. this.$parent
  4733. )
  4734. }
  4735. var mode = this.mode
  4736. // warn invalid mode
  4737. if (process.env.NODE_ENV !== 'production' &&
  4738. mode && mode !== 'in-out' && mode !== 'out-in') {
  4739. warn(
  4740. 'invalid <transition> mode: ' + mode,
  4741. this.$parent
  4742. )
  4743. }
  4744. var rawChild = children[0]
  4745. // if this is a component root node and the component's
  4746. // parent container node also has transition, skip.
  4747. if (hasParentTransition(this.$vnode)) {
  4748. return rawChild
  4749. }
  4750. // apply transition data to child
  4751. // use getRealChild() to ignore abstract components e.g. keep-alive
  4752. var child = getRealChild(rawChild)
  4753. /* istanbul ignore if */
  4754. if (!child) {
  4755. return rawChild
  4756. }
  4757. if (this._leaving) {
  4758. return placeholder(h, rawChild)
  4759. }
  4760. child.key = child.key == null
  4761. ? ("__v" + (child.tag + this._uid) + "__")
  4762. : child.key
  4763. var data = (child.data || (child.data = {})).transition = extractTransitionData(this)
  4764. var oldRawChild = this._vnode
  4765. var oldChild = getRealChild(oldRawChild)
  4766. // mark v-show
  4767. // so that the transition module can hand over the control to the directive
  4768. if (child.data.directives && child.data.directives.some(function (d) { return d.name === 'show'; })) {
  4769. child.data.show = true
  4770. }
  4771. if (oldChild && oldChild.data && oldChild.key !== child.key) {
  4772. // replace old child transition data with fresh one
  4773. // important for dynamic transitions!
  4774. var oldData = oldChild.data.transition = extend({}, data)
  4775. // handle transition mode
  4776. if (mode === 'out-in') {
  4777. // return placeholder node and queue update when leave finishes
  4778. this._leaving = true
  4779. mergeVNodeHook(oldData, 'afterLeave', function () {
  4780. this$1._leaving = false
  4781. this$1.$forceUpdate()
  4782. })
  4783. return placeholder(h, rawChild)
  4784. } else if (mode === 'in-out') {
  4785. var delayedLeave
  4786. var performLeave = function () { delayedLeave() }
  4787. mergeVNodeHook(data, 'afterEnter', performLeave)
  4788. mergeVNodeHook(data, 'enterCancelled', performLeave)
  4789. mergeVNodeHook(oldData, 'delayLeave', function (leave) {
  4790. delayedLeave = leave
  4791. })
  4792. }
  4793. }
  4794. return rawChild
  4795. }
  4796. }
  4797. /* */
  4798. // Provides transition support for list items.
  4799. // supports move transitions using the FLIP technique.
  4800. // Because the vdom's children update algorithm is "unstable" - i.e.
  4801. // it doesn't guarantee the relative positioning of removed elements,
  4802. // we force transition-group to update its children into two passes:
  4803. // in the first pass, we remove all nodes that need to be removed,
  4804. // triggering their leaving transition; in the second pass, we insert/move
  4805. // into the final disired state. This way in the second pass removed
  4806. // nodes will remain where they should be.
  4807. var props = extend({
  4808. tag: String,
  4809. moveClass: String
  4810. }, transitionProps)
  4811. delete props.mode
  4812. var TransitionGroup = {
  4813. props: props,
  4814. render: function render (h) {
  4815. var tag = this.tag || this.$vnode.data.tag || 'span'
  4816. var map = Object.create(null)
  4817. var prevChildren = this.prevChildren = this.children
  4818. var rawChildren = this.$slots.default || []
  4819. var children = this.children = []
  4820. var transitionData = extractTransitionData(this)
  4821. for (var i = 0; i < rawChildren.length; i++) {
  4822. var c = rawChildren[i]
  4823. if (c.tag) {
  4824. if (c.key != null && String(c.key).indexOf('__vlist') !== 0) {
  4825. children.push(c)
  4826. map[c.key] = c
  4827. ;(c.data || (c.data = {})).transition = transitionData
  4828. } else if (process.env.NODE_ENV !== 'production') {
  4829. var opts = c.componentOptions
  4830. var name = opts
  4831. ? (opts.Ctor.options.name || opts.tag)
  4832. : c.tag
  4833. warn(("<transition-group> children must be keyed: <" + name + ">"))
  4834. }
  4835. }
  4836. }
  4837. if (prevChildren) {
  4838. var kept = []
  4839. var removed = []
  4840. for (var i$1 = 0; i$1 < prevChildren.length; i$1++) {
  4841. var c$1 = prevChildren[i$1]
  4842. c$1.data.transition = transitionData
  4843. c$1.data.pos = c$1.elm.getBoundingClientRect()
  4844. if (map[c$1.key]) {
  4845. kept.push(c$1)
  4846. } else {
  4847. removed.push(c$1)
  4848. }
  4849. }
  4850. this.kept = h(tag, null, kept)
  4851. this.removed = removed
  4852. }
  4853. return h(tag, null, children)
  4854. },
  4855. beforeUpdate: function beforeUpdate () {
  4856. // force removing pass
  4857. this.__patch__(
  4858. this._vnode,
  4859. this.kept,
  4860. false, // hydrating
  4861. true // removeOnly (!important, avoids unnecessary moves)
  4862. )
  4863. this._vnode = this.kept
  4864. },
  4865. updated: function updated () {
  4866. var children = this.prevChildren
  4867. var moveClass = this.moveClass || (this.name + '-move')
  4868. if (!children.length || !this.hasMove(children[0].elm, moveClass)) {
  4869. return
  4870. }
  4871. children.forEach(function (c) {
  4872. /* istanbul ignore if */
  4873. if (c.elm._moveCb) {
  4874. c.elm._moveCb()
  4875. }
  4876. /* istanbul ignore if */
  4877. if (c.elm._enterCb) {
  4878. c.elm._enterCb()
  4879. }
  4880. var oldPos = c.data.pos
  4881. var newPos = c.data.pos = c.elm.getBoundingClientRect()
  4882. var dx = oldPos.left - newPos.left
  4883. var dy = oldPos.top - newPos.top
  4884. if (dx || dy) {
  4885. c.data.moved = true
  4886. var s = c.elm.style
  4887. s.transform = s.WebkitTransform = "translate(" + dx + "px," + dy + "px)"
  4888. s.transitionDuration = '0s'
  4889. }
  4890. })
  4891. // force reflow to put everything in position
  4892. var f = document.body.offsetHeight // eslint-disable-line
  4893. children.forEach(function (c) {
  4894. if (c.data.moved) {
  4895. var el = c.elm
  4896. var s = el.style
  4897. addTransitionClass(el, moveClass)
  4898. s.transform = s.WebkitTransform = s.transitionDuration = ''
  4899. el._moveDest = c.data.pos
  4900. el.addEventListener(transitionEndEvent, el._moveCb = function cb (e) {
  4901. if (!e || /transform$/.test(e.propertyName)) {
  4902. el.removeEventListener(transitionEndEvent, cb)
  4903. el._moveCb = null
  4904. removeTransitionClass(el, moveClass)
  4905. }
  4906. })
  4907. }
  4908. })
  4909. },
  4910. methods: {
  4911. hasMove: function hasMove (el, moveClass) {
  4912. /* istanbul ignore if */
  4913. if (!hasTransition) {
  4914. return false
  4915. }
  4916. if (this._hasMove != null) {
  4917. return this._hasMove
  4918. }
  4919. addTransitionClass(el, moveClass)
  4920. var info = getTransitionInfo(el)
  4921. removeTransitionClass(el, moveClass)
  4922. return (this._hasMove = info.hasTransform)
  4923. }
  4924. }
  4925. }
  4926. var platformComponents = {
  4927. Transition: Transition,
  4928. TransitionGroup: TransitionGroup
  4929. }
  4930. /* */
  4931. // install platform specific utils
  4932. Vue.config.isUnknownElement = isUnknownElement
  4933. Vue.config.isReservedTag = isReservedTag
  4934. Vue.config.getTagNamespace = getTagNamespace
  4935. Vue.config.mustUseProp = mustUseProp
  4936. // install platform runtime directives & components
  4937. extend(Vue.options.directives, platformDirectives)
  4938. extend(Vue.options.components, platformComponents)
  4939. // install platform patch function
  4940. Vue.prototype.__patch__ = config._isServer ? noop : patch
  4941. // wrap mount
  4942. Vue.prototype.$mount = function (
  4943. el,
  4944. hydrating
  4945. ) {
  4946. el = el && !config._isServer ? query(el) : undefined
  4947. return this._mount(el, hydrating)
  4948. }
  4949. // devtools global hook
  4950. /* istanbul ignore next */
  4951. setTimeout(function () {
  4952. if (config.devtools) {
  4953. if (devtools) {
  4954. devtools.emit('init', Vue)
  4955. } else if (
  4956. process.env.NODE_ENV !== 'production' &&
  4957. inBrowser && /Chrome\/\d+/.test(window.navigator.userAgent)
  4958. ) {
  4959. console.log(
  4960. 'Download the Vue Devtools for a better development experience:\n' +
  4961. 'https://github.com/vuejs/vue-devtools'
  4962. )
  4963. }
  4964. }
  4965. }, 0)
  4966. module.exports = Vue;