nerv.js 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151
  1. 'use strict';
  2. // tslint:disable-next-line
  3. var global = function () {
  4. var local;
  5. if (typeof global !== 'undefined') {
  6. local = global;
  7. } else if (typeof self !== 'undefined') {
  8. local = self;
  9. } else {
  10. try {
  11. local = Function('return this')();
  12. } catch (e) {
  13. throw new Error('global object is unavailable in this environment');
  14. }
  15. }
  16. return local;
  17. }();
  18. var isBrowser = typeof window !== 'undefined';
  19. // tslint:disable-next-line:no-empty
  20. function noop() {}
  21. var fakeDoc = {
  22. createElement: noop,
  23. createElementNS: noop,
  24. createTextNode: noop
  25. };
  26. var doc = isBrowser ? document : fakeDoc;
  27. function isNumber(arg) {
  28. return typeof arg === 'number';
  29. }
  30. var isSupportSVG = isFunction(doc.createAttributeNS);
  31. function isString(arg) {
  32. return typeof arg === 'string';
  33. }
  34. function isFunction(arg) {
  35. return typeof arg === 'function';
  36. }
  37. function isBoolean(arg) {
  38. return arg === true || arg === false;
  39. }
  40. var isArray = Array.isArray;
  41. function isUndefined(o) {
  42. return o === undefined;
  43. }
  44. var canUsePromise = 'Promise' in global;
  45. var resolved;
  46. if (canUsePromise) {
  47. resolved = Promise.resolve();
  48. }
  49. var nextTick = function (fn) {
  50. var args = [],
  51. len = arguments.length - 1;
  52. while (len-- > 0) args[len] = arguments[len + 1];
  53. fn = isFunction(fn) ? fn.bind.apply(fn, [null].concat(args)) : fn;
  54. if (canUsePromise) {
  55. return resolved.then(fn);
  56. }
  57. var timerFunc = 'requestAnimationFrame' in global ? requestAnimationFrame : setTimeout;
  58. timerFunc(fn);
  59. };
  60. /* istanbul ignore next */
  61. // tslint:disable-next-line
  62. Object.is = Object.is || function (x, y) {
  63. if (x === y) {
  64. return x !== 0 || 1 / x === 1 / y;
  65. }
  66. return x !== x && y !== y;
  67. };
  68. function shallowEqual(obj1, obj2) {
  69. if (obj1 === null || obj2 === null) {
  70. return false;
  71. }
  72. if (Object.is(obj1, obj2)) {
  73. return true;
  74. }
  75. var obj1Keys = obj1 ? Object.keys(obj1) : [];
  76. var obj2Keys = obj2 ? Object.keys(obj2) : [];
  77. if (obj1Keys.length !== obj2Keys.length) {
  78. return false;
  79. }
  80. for (var i = 0; i < obj1Keys.length; i++) {
  81. var obj1KeyItem = obj1Keys[i];
  82. if (!obj2.hasOwnProperty(obj1KeyItem) || !Object.is(obj1[obj1KeyItem], obj2[obj1KeyItem])) {
  83. return false;
  84. }
  85. }
  86. return true;
  87. }
  88. var SimpleMap = function SimpleMap() {
  89. this.cache = [];
  90. this.size = 0;
  91. };
  92. SimpleMap.prototype.set = function set(k, v) {
  93. var this$1 = this;
  94. var len = this.cache.length;
  95. if (!len) {
  96. this.cache.push({ k: k, v: v });
  97. this.size += 1;
  98. return;
  99. }
  100. for (var i = 0; i < len; i++) {
  101. var item = this$1.cache[i];
  102. if (item.k === k) {
  103. item.v = v;
  104. return;
  105. }
  106. }
  107. this.cache.push({ k: k, v: v });
  108. this.size += 1;
  109. };
  110. SimpleMap.prototype.get = function get(k) {
  111. var this$1 = this;
  112. var len = this.cache.length;
  113. if (!len) {
  114. return;
  115. }
  116. for (var i = 0; i < len; i++) {
  117. var item = this$1.cache[i];
  118. if (item.k === k) {
  119. return item.v;
  120. }
  121. }
  122. };
  123. SimpleMap.prototype.has = function has(k) {
  124. var this$1 = this;
  125. var len = this.cache.length;
  126. if (!len) {
  127. return false;
  128. }
  129. for (var i = 0; i < len; i++) {
  130. var item = this$1.cache[i];
  131. if (item.k === k) {
  132. return true;
  133. }
  134. }
  135. return false;
  136. };
  137. SimpleMap.prototype['delete'] = function delete$1(k) {
  138. var this$1 = this;
  139. var len = this.cache.length;
  140. for (var i = 0; i < len; i++) {
  141. var item = this$1.cache[i];
  142. if (item.k === k) {
  143. this$1.cache.splice(i, 1);
  144. this$1.size -= 1;
  145. return true;
  146. }
  147. }
  148. return false;
  149. };
  150. SimpleMap.prototype.clear = function clear() {
  151. var this$1 = this;
  152. var len = this.cache.length;
  153. this.size = 0;
  154. if (!len) {
  155. return;
  156. }
  157. while (len) {
  158. this$1.cache.pop();
  159. len--;
  160. }
  161. };
  162. var MapClass = 'Map' in global ? Map : SimpleMap;
  163. function isAttrAnEvent(attr) {
  164. return attr[0] === 'o' && attr[1] === 'n';
  165. }
  166. function extend(source, from) {
  167. if (!from) {
  168. return source;
  169. }
  170. for (var key in from) {
  171. if (from.hasOwnProperty(key)) {
  172. source[key] = from[key];
  173. }
  174. }
  175. return source;
  176. }
  177. function clone(obj) {
  178. return extend({}, obj);
  179. }
  180. var Current = {
  181. current: null
  182. };
  183. var EMPTY_CHILDREN = [];
  184. var EMPTY_OBJ = {};
  185. function isNullOrUndef(o) {
  186. return o === undefined || o === null;
  187. }
  188. function isInvalid(o) {
  189. return isNullOrUndef(o) || o === true || o === false;
  190. }
  191. function isVNode(node) {
  192. return !isNullOrUndef(node) && node.vtype === 2 /* Node */;
  193. }
  194. function isVText(node) {
  195. return !isNullOrUndef(node) && node.vtype === 1 /* Text */;
  196. }
  197. function isComponent(instance) {
  198. return !isInvalid(instance) && instance.isReactComponent === EMPTY_OBJ;
  199. }
  200. function isWidget(node) {
  201. return !isNullOrUndef(node) && (node.vtype & (4 /* Composite */ | 8 /* Stateless */)) > 0;
  202. }
  203. function isPortal(vtype, node) {
  204. return (vtype & 32 /* Portal */) > 0;
  205. }
  206. function isComposite(node) {
  207. return !isNullOrUndef(node) && node.vtype === 4 /* Composite */;
  208. }
  209. function isValidElement(node) {
  210. return !isNullOrUndef(node) && node.vtype;
  211. }
  212. // tslint:disable-next-line:no-empty
  213. function noop$1() {}
  214. // typescript will compile the enum's value for us.
  215. // eg.
  216. // Composite = 1 << 2 => Composite = 4
  217. var VType;
  218. (function (VType) {
  219. VType[VType["Text"] = 1] = "Text";
  220. VType[VType["Node"] = 2] = "Node";
  221. VType[VType["Composite"] = 4] = "Composite";
  222. VType[VType["Stateless"] = 8] = "Stateless";
  223. VType[VType["Void"] = 16] = "Void";
  224. VType[VType["Portal"] = 32] = "Portal";
  225. })(VType || (VType = {}));
  226. var Ref = {
  227. update: function update(lastVnode, nextVnode, domNode) {
  228. var prevRef = lastVnode != null && lastVnode.ref;
  229. var nextRef = nextVnode != null && nextVnode.ref;
  230. if (prevRef !== nextRef) {
  231. if (!isFunction(prevRef) || !isFunction(nextRef)) {
  232. this.detach(lastVnode, prevRef, lastVnode.dom);
  233. }
  234. this.attach(nextVnode, nextRef, domNode);
  235. }
  236. },
  237. attach: function attach(vnode, ref, domNode) {
  238. var node = isComposite(vnode) ? vnode.component : domNode;
  239. if (isFunction(ref)) {
  240. ref(node);
  241. } else if (isString(ref)) {
  242. var inst = vnode._owner;
  243. if (inst && isFunction(inst.render)) {
  244. inst.refs[ref] = node;
  245. }
  246. }
  247. },
  248. detach: function detach(vnode, ref, domNode) {
  249. var node = isComposite(vnode) ? vnode.component : domNode;
  250. if (isFunction(ref)) {
  251. ref(null);
  252. } else if (isString(ref)) {
  253. var inst = vnode._owner;
  254. if (inst.refs[ref] === node && isFunction(inst.render)) {
  255. delete inst.refs[ref];
  256. }
  257. }
  258. }
  259. };
  260. var ONINPUT = 'oninput';
  261. var ONPROPERTYCHANGE = 'onpropertychange';
  262. var isiOS = isBrowser && !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
  263. var delegatedEvents = new MapClass();
  264. var unbubbleEvents = {
  265. onmousemove: 1,
  266. ontouchmove: 1,
  267. onmouseleave: 1,
  268. onmouseenter: 1,
  269. onload: 1,
  270. onunload: 1,
  271. onscroll: 1,
  272. onfocus: 1,
  273. onblur: 1,
  274. onrowexit: 1,
  275. onbeforeunload: 1,
  276. onstop: 1,
  277. ondragdrop: 1,
  278. ondragenter: 1,
  279. ondragexit: 1,
  280. ondraggesture: 1,
  281. ondragover: 1,
  282. oncontextmenu: 1,
  283. onerror: 1,
  284. onabort: 1,
  285. oncanplay: 1,
  286. oncanplaythrough: 1,
  287. ondurationchange: 1,
  288. onemptied: 1,
  289. onended: 1,
  290. onloadeddata: 1,
  291. onloadedmetadata: 1,
  292. onloadstart: 1,
  293. onencrypted: 1,
  294. onpause: 1,
  295. onplay: 1,
  296. onplaying: 1,
  297. onprogress: 1,
  298. onratechange: 1,
  299. onseeking: 1,
  300. onseeked: 1,
  301. onstalled: 1,
  302. onsuspend: 1,
  303. ontimeupdate: 1,
  304. onvolumechange: 1,
  305. onwaiting: 1
  306. };
  307. unbubbleEvents[ONPROPERTYCHANGE] = 1;
  308. var bindFocus = false;
  309. /* istanbul ignore next */
  310. if (isBrowser && navigator.userAgent.indexOf('MSIE 9') >= 0) {
  311. var elements = [];
  312. var values = [];
  313. doc.addEventListener('selectionchange', function () {
  314. var el = doc.activeElement;
  315. if (detectCanUseOnInputNode(el)) {
  316. var index = elements.indexOf(el);
  317. var element = elements[index] || elements.push(el);
  318. if (element.value !== values[index]) {
  319. var ev = doc.createEvent('CustomEvent');
  320. ev.initCustomEvent('input', true, true, undefined);
  321. values[index] = element.value;
  322. el.dispatchEvent(ev);
  323. }
  324. }
  325. });
  326. }
  327. if (typeof Event !== 'undefined' && !Event.prototype.persist) {
  328. // tslint:disable-next-line:no-empty
  329. Event.prototype.persist = noop$1;
  330. }
  331. function attachEvent(domNode, eventName, handler) {
  332. eventName = fixEvent(domNode, eventName);
  333. /* istanbul ignore next */
  334. if (eventName === ONPROPERTYCHANGE) {
  335. processOnPropertyChangeEvent(domNode, handler);
  336. return;
  337. }
  338. var delegatedRoots = delegatedEvents.get(eventName);
  339. if (unbubbleEvents[eventName] === 1) {
  340. if (!delegatedRoots) {
  341. delegatedRoots = new MapClass();
  342. }
  343. var event = attachEventToNode(domNode, eventName, delegatedRoots);
  344. delegatedEvents.set(eventName, delegatedRoots);
  345. if (isFunction(handler)) {
  346. delegatedRoots.set(domNode, {
  347. eventHandler: handler,
  348. event: event
  349. });
  350. }
  351. } else {
  352. if (!delegatedRoots) {
  353. delegatedRoots = {
  354. items: new MapClass()
  355. };
  356. delegatedRoots.event = attachEventToDocument(doc, eventName, delegatedRoots);
  357. delegatedEvents.set(eventName, delegatedRoots);
  358. }
  359. if (isFunction(handler)) {
  360. if (isiOS) {
  361. domNode.onclick = noop$1;
  362. }
  363. delegatedRoots.items.set(domNode, handler);
  364. }
  365. }
  366. }
  367. function detachEvent(domNode, eventName, handler) {
  368. eventName = fixEvent(domNode, eventName);
  369. if (eventName === ONPROPERTYCHANGE) {
  370. return;
  371. }
  372. var delegatedRoots = delegatedEvents.get(eventName);
  373. if (unbubbleEvents[eventName] === 1 && delegatedRoots) {
  374. var event = delegatedRoots.get(domNode);
  375. if (event) {
  376. domNode.removeEventListener(parseEventName(eventName), event.event, false);
  377. /* istanbul ignore next */
  378. var delegatedRootsSize = delegatedRoots.size;
  379. if (delegatedRoots['delete'](domNode) && delegatedRootsSize === 0) {
  380. delegatedEvents['delete'](eventName);
  381. }
  382. }
  383. } else if (delegatedRoots && delegatedRoots.items) {
  384. var items = delegatedRoots.items;
  385. if (items['delete'](domNode) && items.size === 0) {
  386. doc.removeEventListener(parseEventName(eventName), delegatedRoots.event, false);
  387. delegatedEvents['delete'](eventName);
  388. }
  389. }
  390. }
  391. var propertyChangeActiveElement;
  392. var propertyChangeActiveElementValue;
  393. var propertyChangeActiveElementValueProp;
  394. var propertyChangeActiveHandler;
  395. /* istanbul ignore next */
  396. function propertyChangeHandler(event) {
  397. if (event.propertyName !== 'value') {
  398. return;
  399. }
  400. var target = event.target || event.srcElement;
  401. var val = target.value;
  402. if (val === propertyChangeActiveElementValue) {
  403. return;
  404. }
  405. propertyChangeActiveElementValue = val;
  406. if (isFunction(propertyChangeActiveHandler)) {
  407. propertyChangeActiveHandler.call(target, event);
  408. }
  409. }
  410. /* istanbul ignore next */
  411. function processOnPropertyChangeEvent(node, handler) {
  412. propertyChangeActiveHandler = handler;
  413. if (!bindFocus) {
  414. bindFocus = true;
  415. doc.addEventListener('focusin', function () {
  416. unbindOnPropertyChange();
  417. bindOnPropertyChange(node);
  418. }, false);
  419. doc.addEventListener('focusout', unbindOnPropertyChange, false);
  420. }
  421. }
  422. /* istanbul ignore next */
  423. function bindOnPropertyChange(node) {
  424. propertyChangeActiveElement = node;
  425. propertyChangeActiveElementValue = node.value;
  426. propertyChangeActiveElementValueProp = Object.getOwnPropertyDescriptor(node.constructor.prototype, 'value');
  427. Object.defineProperty(propertyChangeActiveElement, 'value', {
  428. get: function get() {
  429. return propertyChangeActiveElementValueProp.get.call(this);
  430. },
  431. set: function set(val) {
  432. propertyChangeActiveElementValue = val;
  433. propertyChangeActiveElementValueProp.set.call(this, val);
  434. }
  435. });
  436. propertyChangeActiveElement.addEventListener('propertychange', propertyChangeHandler, false);
  437. }
  438. /* istanbul ignore next */
  439. function unbindOnPropertyChange() {
  440. if (!propertyChangeActiveElement) {
  441. return;
  442. }
  443. delete propertyChangeActiveElement.value;
  444. propertyChangeActiveElement.removeEventListener('propertychange', propertyChangeHandler, false);
  445. propertyChangeActiveElement = null;
  446. propertyChangeActiveElementValue = null;
  447. propertyChangeActiveElementValueProp = null;
  448. }
  449. function detectCanUseOnInputNode(node) {
  450. var nodeName = node.nodeName && node.nodeName.toLowerCase();
  451. var type = node.type;
  452. return nodeName === 'input' && /text|password/.test(type) || nodeName === 'textarea';
  453. }
  454. function fixEvent(node, eventName) {
  455. if (eventName === 'onDoubleClick') {
  456. eventName = 'ondblclick';
  457. } else if (eventName === 'onTouchTap') {
  458. eventName = 'onclick';
  459. // tslint:disable-next-line:prefer-conditional-expression
  460. } else if (eventName === 'onChange' && detectCanUseOnInputNode(node)) {
  461. eventName = ONINPUT in window ? ONINPUT : ONPROPERTYCHANGE;
  462. } else {
  463. eventName = eventName.toLowerCase();
  464. }
  465. return eventName;
  466. }
  467. function parseEventName(name) {
  468. return name.substr(2);
  469. }
  470. /* istanbul ignore next */
  471. function stopPropagation() {
  472. this.cancelBubble = true;
  473. this.stopImmediatePropagation();
  474. }
  475. function dispatchEvent(event, target, items, count, eventData) {
  476. var eventsToTrigger = items.get(target);
  477. if (eventsToTrigger) {
  478. count--;
  479. eventData.currentTarget = target;
  480. // for React synthetic event compatibility
  481. Object.defineProperties(event, {
  482. nativeEvent: {
  483. value: event
  484. }
  485. });
  486. eventsToTrigger(event);
  487. if (event.cancelBubble) {
  488. return;
  489. }
  490. }
  491. if (count > 0) {
  492. var parentDom = target.parentNode;
  493. if (parentDom === null || event.type === 'click' && parentDom.nodeType === 1 && parentDom.disabled) {
  494. return;
  495. }
  496. dispatchEvent(event, parentDom, items, count, eventData);
  497. }
  498. }
  499. function attachEventToDocument(d, eventName, delegatedRoots) {
  500. var eventHandler = function (event) {
  501. var items = delegatedRoots.items;
  502. var count = items.size;
  503. if (count > 0) {
  504. var eventData = {
  505. currentTarget: event.target
  506. };
  507. /* istanbul ignore next */
  508. try {
  509. Object.defineProperties(event, {
  510. currentTarget: {
  511. configurable: true,
  512. get: function get() {
  513. return eventData.currentTarget;
  514. }
  515. },
  516. stopPropagation: {
  517. value: stopPropagation
  518. }
  519. });
  520. } catch (error) {
  521. // some browsers crashed
  522. // see: https://stackoverflow.com/questions/44052813/why-cannot-redefine-property
  523. }
  524. dispatchEvent(event, event.target, delegatedRoots.items, count, eventData);
  525. }
  526. };
  527. d.addEventListener(parseEventName(eventName), eventHandler, false);
  528. return eventHandler;
  529. }
  530. function attachEventToNode(node, eventName, delegatedRoots) {
  531. var eventHandler = function (event) {
  532. var eventToTrigger = delegatedRoots.get(node);
  533. if (eventToTrigger && eventToTrigger.eventHandler) {
  534. var eventData = {
  535. currentTarget: node
  536. };
  537. /* istanbul ignore next */
  538. Object.defineProperties(event, {
  539. currentTarget: {
  540. configurable: true,
  541. get: function get() {
  542. return eventData.currentTarget;
  543. }
  544. }
  545. });
  546. eventToTrigger.eventHandler(event);
  547. }
  548. };
  549. node.addEventListener(parseEventName(eventName), eventHandler, false);
  550. return eventHandler;
  551. }
  552. var options = {
  553. afterMount: noop$1,
  554. afterUpdate: noop$1,
  555. beforeUnmount: noop$1,
  556. roots: [],
  557. debug: false
  558. };
  559. function unmountChildren(children, parentDom) {
  560. if (isArray(children)) {
  561. for (var i = 0, len = children.length; i < len; i++) {
  562. unmount(children[i], parentDom);
  563. }
  564. } else {
  565. unmount(children, parentDom);
  566. }
  567. }
  568. function unmount(vnode, parentDom) {
  569. if (isInvalid(vnode)) {
  570. return;
  571. }
  572. var vtype = vnode.vtype;
  573. // Bitwise operators for better performance
  574. // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
  575. var dom = vtype & 4 /* Composite */ ? vnode.component.dom : vnode.dom;
  576. if ((vtype & (4 /* Composite */ | 8 /* Stateless */)) > 0) {
  577. options.beforeUnmount(vnode);
  578. vnode.destroy();
  579. } else if ((vtype & 2 /* Node */) > 0) {
  580. var props = vnode.props;
  581. var children = vnode.children;
  582. var ref = vnode.ref;
  583. unmountChildren(children);
  584. for (var propName in props) {
  585. if (isAttrAnEvent(propName)) {
  586. detachEvent(dom, propName, props[propName]);
  587. }
  588. }
  589. if (ref !== null) {
  590. Ref.detach(vnode, ref, dom);
  591. }
  592. } else if (vtype & 32 /* Portal */) {
  593. unmountChildren(vnode.children, vnode.type);
  594. }
  595. if (!isNullOrUndef(parentDom) && !isNullOrUndef(dom)) {
  596. parentDom.removeChild(dom);
  597. }
  598. // vnode.dom = null
  599. }
  600. var NS = {
  601. ev: 'http://www.w3.org/2001/xml-events',
  602. xlink: 'http://www.w3.org/1999/xlink',
  603. xml: 'http://www.w3.org/XML/1998/namespace'
  604. };
  605. var ATTRS = {
  606. accentHeight: 'accent-height',
  607. accumulate: 0,
  608. additive: 0,
  609. alignmentBaseline: 'alignment-baseline',
  610. allowReorder: 'allowReorder',
  611. alphabetic: 0,
  612. amplitude: 0,
  613. arabicForm: 'arabic-form',
  614. ascent: 0,
  615. attributeName: 'attributeName',
  616. attributeType: 'attributeType',
  617. autoReverse: 'autoReverse',
  618. azimuth: 0,
  619. baseFrequency: 'baseFrequency',
  620. baseProfile: 'baseProfile',
  621. baselineShift: 'baseline-shift',
  622. bbox: 0,
  623. begin: 0,
  624. bias: 0,
  625. by: 0,
  626. calcMode: 'calcMode',
  627. capHeight: 'cap-height',
  628. clip: 0,
  629. clipPath: 'clip-path',
  630. clipRule: 'clip-rule',
  631. clipPathUnits: 'clipPathUnits',
  632. colorInterpolation: 'color-interpolation',
  633. colorInterpolationFilters: 'color-interpolation-filters',
  634. colorProfile: 'color-profile',
  635. colorRendering: 'color-rendering',
  636. contentScriptType: 'contentScriptType',
  637. contentStyleType: 'contentStyleType',
  638. cursor: 0,
  639. cx: 0,
  640. cy: 0,
  641. d: 0,
  642. decelerate: 0,
  643. descent: 0,
  644. diffuseConstant: 'diffuseConstant',
  645. direction: 0,
  646. display: 0,
  647. divisor: 0,
  648. dominantBaseline: 'dominant-baseline',
  649. dur: 0,
  650. dx: 0,
  651. dy: 0,
  652. edgeMode: 'edgeMode',
  653. elevation: 0,
  654. enableBackground: 'enable-background',
  655. end: 0,
  656. evEvent: 'ev:event',
  657. exponent: 0,
  658. externalResourcesRequired: 'externalResourcesRequired',
  659. fill: 0,
  660. fillOpacity: 'fill-opacity',
  661. fillRule: 'fill-rule',
  662. filter: 0,
  663. filterRes: 'filterRes',
  664. filterUnits: 'filterUnits',
  665. floodColor: 'flood-color',
  666. floodOpacity: 'flood-opacity',
  667. focusable: 0,
  668. fontFamily: 'font-family',
  669. fontSize: 'font-size',
  670. fontSizeAdjust: 'font-size-adjust',
  671. fontStretch: 'font-stretch',
  672. fontStyle: 'font-style',
  673. fontVariant: 'font-variant',
  674. fontWeight: 'font-weight',
  675. format: 0,
  676. from: 0,
  677. fx: 0,
  678. fy: 0,
  679. g1: 0,
  680. g2: 0,
  681. glyphName: 'glyph-name',
  682. glyphOrientationHorizontal: 'glyph-orientation-horizontal',
  683. glyphOrientationVertical: 'glyph-orientation-vertical',
  684. glyphRef: 'glyphRef',
  685. gradientTransform: 'gradientTransform',
  686. gradientUnits: 'gradientUnits',
  687. hanging: 0,
  688. horizAdvX: 'horiz-adv-x',
  689. horizOriginX: 'horiz-origin-x',
  690. ideographic: 0,
  691. imageRendering: 'image-rendering',
  692. 'in': 0,
  693. in2: 0,
  694. intercept: 0,
  695. k: 0,
  696. k1: 0,
  697. k2: 0,
  698. k3: 0,
  699. k4: 0,
  700. kernelMatrix: 'kernelMatrix',
  701. kernelUnitLength: 'kernelUnitLength',
  702. kerning: 0,
  703. keyPoints: 'keyPoints',
  704. keySplines: 'keySplines',
  705. keyTimes: 'keyTimes',
  706. lengthAdjust: 'lengthAdjust',
  707. letterSpacing: 'letter-spacing',
  708. lightingColor: 'lighting-color',
  709. limitingConeAngle: 'limitingConeAngle',
  710. local: 0,
  711. markerEnd: 'marker-end',
  712. markerMid: 'marker-mid',
  713. markerStart: 'marker-start',
  714. markerHeight: 'markerHeight',
  715. markerUnits: 'markerUnits',
  716. markerWidth: 'markerWidth',
  717. mask: 0,
  718. maskContentUnits: 'maskContentUnits',
  719. maskUnits: 'maskUnits',
  720. mathematical: 0,
  721. mode: 0,
  722. numOctaves: 'numOctaves',
  723. offset: 0,
  724. opacity: 0,
  725. operator: 0,
  726. order: 0,
  727. orient: 0,
  728. orientation: 0,
  729. origin: 0,
  730. overflow: 0,
  731. overlinePosition: 'overline-position',
  732. overlineThickness: 'overline-thickness',
  733. paintOrder: 'paint-order',
  734. panose1: 'panose-1',
  735. pathLength: 'pathLength',
  736. patternContentUnits: 'patternContentUnits',
  737. patternTransform: 'patternTransform',
  738. patternUnits: 'patternUnits',
  739. pointerEvents: 'pointer-events',
  740. points: 0,
  741. pointsAtX: 'pointsAtX',
  742. pointsAtY: 'pointsAtY',
  743. pointsAtZ: 'pointsAtZ',
  744. preserveAlpha: 'preserveAlpha',
  745. preserveAspectRatio: 'preserveAspectRatio',
  746. primitiveUnits: 'primitiveUnits',
  747. r: 0,
  748. radius: 0,
  749. refX: 'refX',
  750. refY: 'refY',
  751. renderingIntent: 'rendering-intent',
  752. repeatCount: 'repeatCount',
  753. repeatDur: 'repeatDur',
  754. requiredExtensions: 'requiredExtensions',
  755. requiredFeatures: 'requiredFeatures',
  756. restart: 0,
  757. result: 0,
  758. rotate: 0,
  759. rx: 0,
  760. ry: 0,
  761. scale: 0,
  762. seed: 0,
  763. shapeRendering: 'shape-rendering',
  764. slope: 0,
  765. spacing: 0,
  766. specularConstant: 'specularConstant',
  767. specularExponent: 'specularExponent',
  768. speed: 0,
  769. spreadMethod: 'spreadMethod',
  770. startOffset: 'startOffset',
  771. stdDeviation: 'stdDeviation',
  772. stemh: 0,
  773. stemv: 0,
  774. stitchTiles: 'stitchTiles',
  775. stopColor: 'stop-color',
  776. stopOpacity: 'stop-opacity',
  777. strikethroughPosition: 'strikethrough-position',
  778. strikethroughThickness: 'strikethrough-thickness',
  779. string: 0,
  780. stroke: 0,
  781. strokeDasharray: 'stroke-dasharray',
  782. strokeDashoffset: 'stroke-dashoffset',
  783. strokeLinecap: 'stroke-linecap',
  784. strokeLinejoin: 'stroke-linejoin',
  785. strokeMiterlimit: 'stroke-miterlimit',
  786. strokeOpacity: 'stroke-opacity',
  787. strokeWidth: 'stroke-width',
  788. surfaceScale: 'surfaceScale',
  789. systemLanguage: 'systemLanguage',
  790. tableValues: 'tableValues',
  791. targetX: 'targetX',
  792. targetY: 'targetY',
  793. textAnchor: 'text-anchor',
  794. textDecoration: 'text-decoration',
  795. textRendering: 'text-rendering',
  796. textLength: 'textLength',
  797. to: 0,
  798. transform: 0,
  799. u1: 0,
  800. u2: 0,
  801. underlinePosition: 'underline-position',
  802. underlineThickness: 'underline-thickness',
  803. unicode: 0,
  804. unicodeBidi: 'unicode-bidi',
  805. unicodeRange: 'unicode-range',
  806. unitsPerEm: 'units-per-em',
  807. vAlphabetic: 'v-alphabetic',
  808. vHanging: 'v-hanging',
  809. vIdeographic: 'v-ideographic',
  810. vMathematical: 'v-mathematical',
  811. values: 0,
  812. vectorEffect: 'vector-effect',
  813. version: 0,
  814. vertAdvY: 'vert-adv-y',
  815. vertOriginX: 'vert-origin-x',
  816. vertOriginY: 'vert-origin-y',
  817. viewBox: 'viewBox',
  818. viewTarget: 'viewTarget',
  819. visibility: 0,
  820. widths: 0,
  821. wordSpacing: 'word-spacing',
  822. writingMode: 'writing-mode',
  823. x: 0,
  824. xHeight: 'x-height',
  825. x1: 0,
  826. x2: 0,
  827. xChannelSelector: 'xChannelSelector',
  828. xlinkActuate: 'xlink:actuate',
  829. xlinkArcrole: 'xlink:arcrole',
  830. xlinkHref: 'xlink:href',
  831. xlinkRole: 'xlink:role',
  832. xlinkShow: 'xlink:show',
  833. xlinkTitle: 'xlink:title',
  834. xlinkType: 'xlink:type',
  835. xmlBase: 'xml:base',
  836. xmlId: 'xml:id',
  837. xmlns: 0,
  838. xmlnsXlink: 'xmlns:xlink',
  839. xmlLang: 'xml:lang',
  840. xmlSpace: 'xml:space',
  841. y: 0,
  842. y1: 0,
  843. y2: 0,
  844. yChannelSelector: 'yChannelSelector',
  845. z: 0,
  846. zoomAndPan: 'zoomAndPan'
  847. };
  848. var SVGPropertyConfig = {
  849. Properties: {},
  850. DOMAttributeNamespaces: {
  851. 'ev:event': NS.ev,
  852. 'xlink:actuate': NS.xlink,
  853. 'xlink:arcrole': NS.xlink,
  854. 'xlink:href': NS.xlink,
  855. 'xlink:role': NS.xlink,
  856. 'xlink:show': NS.xlink,
  857. 'xlink:title': NS.xlink,
  858. 'xlink:type': NS.xlink,
  859. 'xml:base': NS.xml,
  860. 'xml:id': NS.xml,
  861. 'xml:lang': NS.xml,
  862. 'xml:space': NS.xml
  863. },
  864. DOMAttributeNames: {}
  865. };
  866. Object.keys(ATTRS).forEach(function (key) {
  867. SVGPropertyConfig.Properties[key] = 0;
  868. if (ATTRS[key]) {
  869. SVGPropertyConfig.DOMAttributeNames[key] = ATTRS[key];
  870. }
  871. });
  872. /* tslint:disable: no-empty*/
  873. function patch(lastVnode, nextVnode, lastDom, context, isSvg) {
  874. lastDom = lastVnode && lastVnode.dom || lastDom;
  875. if (isVText(nextVnode) && isVText(lastVnode)) {
  876. return patchVText(lastVnode, nextVnode);
  877. }
  878. var newDom;
  879. if (isSameVNode(lastVnode, nextVnode)) {
  880. if (isVNode(nextVnode)) {
  881. isSvg = isNullOrUndef(isSvg) ? lastVnode.isSvg : isSvg;
  882. if (isSvg) {
  883. nextVnode.isSvg = isSvg;
  884. }
  885. patchProps(lastDom, nextVnode.props, lastVnode.props, lastVnode, isSvg);
  886. patchChildren(lastDom, lastVnode.children, nextVnode.children, context, isSvg);
  887. if (nextVnode.ref !== null) {
  888. Ref.update(lastVnode, nextVnode, lastDom);
  889. }
  890. newDom = lastDom;
  891. } else if (isWidget(nextVnode)) {
  892. newDom = nextVnode.update(lastVnode, nextVnode, context, lastDom);
  893. options.afterUpdate(nextVnode);
  894. }
  895. nextVnode.dom = newDom;
  896. } else {
  897. var parentNode = lastDom.parentNode;
  898. var nextSibling = lastDom.nextSibling;
  899. unmount(lastVnode, parentNode);
  900. newDom = createElement(nextVnode, isSvg, context);
  901. if (nextVnode !== null) {
  902. nextVnode.dom = newDom;
  903. }
  904. if (parentNode !== null) {
  905. parentNode.insertBefore(newDom, nextVnode !== null && nextVnode.vtype & 32 /* Portal */ ? null : nextSibling);
  906. }
  907. }
  908. return newDom;
  909. }
  910. function patchArrayChildren(parentDom, lastChildren, nextChildren, context, isSvg) {
  911. var lastLength = lastChildren.length;
  912. var nextLength = nextChildren.length;
  913. if (lastLength === 0) {
  914. if (nextLength > 0) {
  915. for (var i = 0; i < nextLength; i++) {
  916. mountChild(nextChildren[i], parentDom, context, isSvg);
  917. }
  918. }
  919. } else if (nextLength === 0) {
  920. unmountChildren(lastChildren);
  921. parentDom.textContent = '';
  922. } else {
  923. if (isKeyed(lastChildren, nextChildren)) {
  924. patchKeyedChildren(lastChildren, nextChildren, parentDom, context, isSvg, lastLength, nextLength);
  925. } else {
  926. patchNonKeyedChildren(parentDom, lastChildren, nextChildren, context, isSvg, lastLength, nextLength);
  927. }
  928. }
  929. }
  930. function patchChildren(parentDom, lastChildren, nextChildren, context, isSvg) {
  931. if (lastChildren === nextChildren) {
  932. return;
  933. }
  934. var lastChildrenIsArray = isArray(lastChildren);
  935. var nextChildrenIsArray = isArray(nextChildren);
  936. if (lastChildrenIsArray && nextChildrenIsArray) {
  937. patchArrayChildren(parentDom, lastChildren, nextChildren, context, isSvg);
  938. } else if (!lastChildrenIsArray && !nextChildrenIsArray) {
  939. patch(lastChildren, nextChildren, parentDom, context, isSvg);
  940. } else if (lastChildrenIsArray && !nextChildrenIsArray) {
  941. patchArrayChildren(parentDom, lastChildren, [nextChildren], context, isSvg);
  942. } else if (!lastChildrenIsArray && nextChildrenIsArray) {
  943. patchArrayChildren(parentDom, [lastChildren], nextChildren, context, isSvg);
  944. }
  945. }
  946. function patchNonKeyedChildren(parentDom, lastChildren, nextChildren, context, isSvg, lastLength, nextLength) {
  947. var minLength = Math.min(lastLength, nextLength);
  948. var i = 0;
  949. while (i < minLength) {
  950. patch(lastChildren[i], nextChildren[i], parentDom, context, isSvg);
  951. i++;
  952. }
  953. if (lastLength < nextLength) {
  954. for (i = minLength; i < nextLength; i++) {
  955. if (parentDom !== null) {
  956. parentDom.appendChild(createElement(nextChildren[i], isSvg, context));
  957. }
  958. }
  959. } else if (lastLength > nextLength) {
  960. for (i = minLength; i < lastLength; i++) {
  961. unmount(lastChildren[i], parentDom);
  962. }
  963. }
  964. }
  965. /**
  966. *
  967. * Virtual DOM patching algorithm based on ivi by
  968. * Boris Kaul (@localvoid)
  969. * Licensed under the MIT License
  970. * https://github.com/ivijs/ivi/blob/master/LICENSE
  971. *
  972. */
  973. function patchKeyedChildren(a, b, dom, context, isSvg, aLength, bLength) {
  974. var aEnd = aLength - 1;
  975. var bEnd = bLength - 1;
  976. var aStart = 0;
  977. var bStart = 0;
  978. var i;
  979. var j;
  980. var aNode;
  981. var bNode;
  982. var nextNode;
  983. var nextPos;
  984. var node;
  985. var aStartNode = a[aStart];
  986. var bStartNode = b[bStart];
  987. var aEndNode = a[aEnd];
  988. var bEndNode = b[bEnd];
  989. // Step 1
  990. // tslint:disable-next-line
  991. outer: {
  992. // Sync nodes with the same key at the beginning.
  993. while (aStartNode.key === bStartNode.key) {
  994. patch(aStartNode, bStartNode, dom, context, isSvg);
  995. aStart++;
  996. bStart++;
  997. if (aStart > aEnd || bStart > bEnd) {
  998. break outer;
  999. }
  1000. aStartNode = a[aStart];
  1001. bStartNode = b[bStart];
  1002. }
  1003. // Sync nodes with the same key at the end.
  1004. while (aEndNode.key === bEndNode.key) {
  1005. patch(aEndNode, bEndNode, dom, context, isSvg);
  1006. aEnd--;
  1007. bEnd--;
  1008. if (aStart > aEnd || bStart > bEnd) {
  1009. break outer;
  1010. }
  1011. aEndNode = a[aEnd];
  1012. bEndNode = b[bEnd];
  1013. }
  1014. }
  1015. if (aStart > aEnd) {
  1016. if (bStart <= bEnd) {
  1017. nextPos = bEnd + 1;
  1018. nextNode = nextPos < bLength ? b[nextPos].dom : null;
  1019. while (bStart <= bEnd) {
  1020. node = b[bStart];
  1021. bStart++;
  1022. attachNewNode(dom, createElement(node, isSvg, context), nextNode);
  1023. }
  1024. }
  1025. } else if (bStart > bEnd) {
  1026. while (aStart <= aEnd) {
  1027. unmount(a[aStart++], dom);
  1028. }
  1029. } else {
  1030. var aLeft = aEnd - aStart + 1;
  1031. var bLeft = bEnd - bStart + 1;
  1032. var sources = new Array(bLeft);
  1033. // Mark all nodes as inserted.
  1034. for (i = 0; i < bLeft; i++) {
  1035. sources[i] = -1;
  1036. }
  1037. var moved = false;
  1038. var pos = 0;
  1039. var patched = 0;
  1040. // When sizes are small, just loop them through
  1041. if (bLeft <= 4 || aLeft * bLeft <= 16) {
  1042. for (i = aStart; i <= aEnd; i++) {
  1043. aNode = a[i];
  1044. if (patched < bLeft) {
  1045. for (j = bStart; j <= bEnd; j++) {
  1046. bNode = b[j];
  1047. if (aNode.key === bNode.key) {
  1048. sources[j - bStart] = i;
  1049. if (pos > j) {
  1050. moved = true;
  1051. } else {
  1052. pos = j;
  1053. }
  1054. patch(aNode, bNode, dom, context, isSvg);
  1055. patched++;
  1056. a[i] = null;
  1057. break;
  1058. }
  1059. }
  1060. }
  1061. }
  1062. } else {
  1063. var keyIndex = new MapClass();
  1064. for (i = bStart; i <= bEnd; i++) {
  1065. keyIndex.set(b[i].key, i);
  1066. }
  1067. for (i = aStart; i <= aEnd; i++) {
  1068. aNode = a[i];
  1069. if (patched < bLeft) {
  1070. j = keyIndex.get(aNode.key);
  1071. if (j !== undefined) {
  1072. bNode = b[j];
  1073. sources[j - bStart] = i;
  1074. if (pos > j) {
  1075. moved = true;
  1076. } else {
  1077. pos = j;
  1078. }
  1079. patch(aNode, bNode, dom, context, isSvg);
  1080. patched++;
  1081. a[i] = null;
  1082. }
  1083. }
  1084. }
  1085. }
  1086. if (aLeft === aLength && patched === 0) {
  1087. unmountChildren(a);
  1088. dom.textContent = '';
  1089. while (bStart < bLeft) {
  1090. node = b[bStart];
  1091. bStart++;
  1092. attachNewNode(dom, createElement(node, isSvg, context), null);
  1093. }
  1094. } else {
  1095. i = aLeft - patched;
  1096. while (i > 0) {
  1097. aNode = a[aStart++];
  1098. if (aNode !== null) {
  1099. unmount(aNode, dom);
  1100. i--;
  1101. }
  1102. }
  1103. if (moved) {
  1104. var seq = lis(sources);
  1105. j = seq.length - 1;
  1106. for (i = bLeft - 1; i >= 0; i--) {
  1107. if (sources[i] === -1) {
  1108. pos = i + bStart;
  1109. node = b[pos];
  1110. nextPos = pos + 1;
  1111. attachNewNode(dom, createElement(node, isSvg, context), nextPos < bLength ? b[nextPos].dom : null);
  1112. } else {
  1113. if (j < 0 || i !== seq[j]) {
  1114. pos = i + bStart;
  1115. node = b[pos];
  1116. nextPos = pos + 1;
  1117. attachNewNode(dom, node.dom, nextPos < bLength ? b[nextPos].dom : null);
  1118. } else {
  1119. j--;
  1120. }
  1121. }
  1122. }
  1123. } else if (patched !== bLeft) {
  1124. for (i = bLeft - 1; i >= 0; i--) {
  1125. if (sources[i] === -1) {
  1126. pos = i + bStart;
  1127. node = b[pos];
  1128. nextPos = pos + 1;
  1129. attachNewNode(dom, createElement(node, isSvg, context), nextPos < bLength ? b[nextPos].dom : null);
  1130. }
  1131. }
  1132. }
  1133. }
  1134. }
  1135. }
  1136. function attachNewNode(parentDom, newNode, nextNode) {
  1137. if (isNullOrUndef(nextNode)) {
  1138. parentDom.appendChild(newNode);
  1139. } else {
  1140. parentDom.insertBefore(newNode, nextNode);
  1141. }
  1142. }
  1143. /**
  1144. * Slightly modified Longest Increased Subsequence algorithm, it ignores items that have -1 value, they're representing
  1145. * new items.
  1146. *
  1147. * http://en.wikipedia.org/wiki/Longest_increasing_subsequence
  1148. *
  1149. * @param a Array of numbers.
  1150. * @returns Longest increasing subsequence.
  1151. */
  1152. function lis(a) {
  1153. var p = a.slice();
  1154. var result = [];
  1155. result.push(0);
  1156. var u;
  1157. var v;
  1158. for (var i = 0, il = a.length; i < il; ++i) {
  1159. if (a[i] === -1) {
  1160. continue;
  1161. }
  1162. var j = result[result.length - 1];
  1163. if (a[j] < a[i]) {
  1164. p[i] = j;
  1165. result.push(i);
  1166. continue;
  1167. }
  1168. u = 0;
  1169. v = result.length - 1;
  1170. while (u < v) {
  1171. var c = (u + v) / 2 | 0;
  1172. if (a[result[c]] < a[i]) {
  1173. u = c + 1;
  1174. } else {
  1175. v = c;
  1176. }
  1177. }
  1178. if (a[i] < a[result[u]]) {
  1179. if (u > 0) {
  1180. p[i] = result[u - 1];
  1181. }
  1182. result[u] = i;
  1183. }
  1184. }
  1185. u = result.length;
  1186. v = result[u - 1];
  1187. while (u-- > 0) {
  1188. result[u] = v;
  1189. v = p[v];
  1190. }
  1191. return result;
  1192. }
  1193. function isKeyed(lastChildren, nextChildren) {
  1194. return nextChildren.length > 0 && !isNullOrUndef(nextChildren[0]) && !isNullOrUndef(nextChildren[0].key) && lastChildren.length > 0 && !isNullOrUndef(lastChildren[0]) && !isNullOrUndef(lastChildren[0].key);
  1195. }
  1196. function isSameVNode(a, b) {
  1197. if (isInvalid(a) || isInvalid(b) || isArray(a) || isArray(b)) {
  1198. return false;
  1199. }
  1200. return a.type === b.type && a.key === b.key;
  1201. }
  1202. function patchVText(lastVNode, nextVNode) {
  1203. var dom = lastVNode.dom;
  1204. if (dom === null) {
  1205. return;
  1206. }
  1207. var nextText = nextVNode.text;
  1208. nextVNode.dom = dom;
  1209. if (lastVNode.text !== nextText) {
  1210. dom.nodeValue = nextText;
  1211. }
  1212. return dom;
  1213. }
  1214. var skipProps = {
  1215. children: 1,
  1216. key: 1,
  1217. ref: 1,
  1218. owner: 1
  1219. };
  1220. var IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i;
  1221. function setStyle(domStyle, style, value) {
  1222. if (isNullOrUndef(value) || isNumber(value) && isNaN(value)) {
  1223. domStyle[style] = '';
  1224. return;
  1225. }
  1226. if (style === 'float') {
  1227. domStyle['cssFloat'] = value;
  1228. domStyle['styleFloat'] = value;
  1229. return;
  1230. }
  1231. domStyle[style] = !isNumber(value) || IS_NON_DIMENSIONAL.test(style) ? value : value + 'px';
  1232. }
  1233. function patchEvent(eventName, lastEvent, nextEvent, domNode) {
  1234. if (lastEvent !== nextEvent) {
  1235. if (isFunction(lastEvent)) {
  1236. detachEvent(domNode, eventName, lastEvent);
  1237. }
  1238. attachEvent(domNode, eventName, nextEvent);
  1239. }
  1240. }
  1241. function patchStyle(lastAttrValue, nextAttrValue, dom) {
  1242. var domStyle = dom.style;
  1243. var style;
  1244. var value;
  1245. if (isString(nextAttrValue)) {
  1246. domStyle.cssText = nextAttrValue;
  1247. return;
  1248. }
  1249. if (!isNullOrUndef(lastAttrValue) && !isString(lastAttrValue)) {
  1250. for (style in nextAttrValue) {
  1251. value = nextAttrValue[style];
  1252. if (value !== lastAttrValue[style]) {
  1253. setStyle(domStyle, style, value);
  1254. }
  1255. }
  1256. } else {
  1257. for (style in nextAttrValue) {
  1258. value = nextAttrValue[style];
  1259. setStyle(domStyle, style, value);
  1260. }
  1261. }
  1262. }
  1263. function patchProp(domNode, prop, lastValue, nextValue, lastVnode, isSvg) {
  1264. // fix the value update for textarea/input
  1265. if (lastValue !== nextValue || prop === 'value') {
  1266. if (prop === 'className') {
  1267. prop = 'class';
  1268. }
  1269. if (skipProps[prop] === 1) {
  1270. return;
  1271. } else if (prop === 'class' && !isSvg) {
  1272. domNode.className = nextValue;
  1273. } else if (prop === 'dangerouslySetInnerHTML') {
  1274. var lastHtml = lastValue && lastValue.__html;
  1275. var nextHtml = nextValue && nextValue.__html;
  1276. if (lastHtml !== nextHtml) {
  1277. if (!isNullOrUndef(nextHtml)) {
  1278. if (isValidElement(lastVnode) && lastVnode.children !== EMPTY_CHILDREN) {
  1279. unmountChildren(lastVnode.children);
  1280. lastVnode.children = [];
  1281. }
  1282. domNode.innerHTML = nextHtml;
  1283. }
  1284. }
  1285. } else if (isAttrAnEvent(prop)) {
  1286. patchEvent(prop, lastValue, nextValue, domNode);
  1287. } else if (prop === 'style') {
  1288. patchStyle(lastValue, nextValue, domNode);
  1289. } else if (prop !== 'list' && prop !== 'type' && !isSvg && prop in domNode) {
  1290. setProperty(domNode, prop, nextValue == null ? '' : nextValue);
  1291. if (nextValue == null || nextValue === false) {
  1292. domNode.removeAttribute(prop);
  1293. }
  1294. } else if (isNullOrUndef(nextValue) || nextValue === false) {
  1295. domNode.removeAttribute(prop);
  1296. } else {
  1297. var namespace = SVGPropertyConfig.DOMAttributeNamespaces[prop];
  1298. if (isSvg && namespace) {
  1299. if (nextValue) {
  1300. domNode.setAttributeNS(namespace, prop, nextValue);
  1301. } else {
  1302. var colonPosition = prop.indexOf(':');
  1303. var localName = colonPosition > -1 ? prop.substr(colonPosition + 1) : prop;
  1304. domNode.removeAttributeNS(namespace, localName);
  1305. }
  1306. } else {
  1307. if (!isFunction(nextValue)) {
  1308. domNode.setAttribute(prop, nextValue);
  1309. }
  1310. // WARNING: Non-event attributes with function values:
  1311. // https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html#changes-in-detail
  1312. }
  1313. }
  1314. }
  1315. }
  1316. function setProperty(node, name, value) {
  1317. try {
  1318. node[name] = value;
  1319. } catch (e) {}
  1320. }
  1321. function patchProps(domNode, nextProps, previousProps, lastVnode, isSvg) {
  1322. for (var propName in previousProps) {
  1323. var value = previousProps[propName];
  1324. if (isNullOrUndef(nextProps[propName]) && !isNullOrUndef(value)) {
  1325. if (isAttrAnEvent(propName)) {
  1326. detachEvent(domNode, propName, value);
  1327. } else if (propName === 'dangerouslySetInnerHTML') {
  1328. domNode.textContent = '';
  1329. } else if (propName === 'className') {
  1330. domNode.removeAttribute('class');
  1331. } else {
  1332. domNode.removeAttribute(propName);
  1333. }
  1334. }
  1335. }
  1336. for (var propName$1 in nextProps) {
  1337. patchProp(domNode, propName$1, previousProps[propName$1], nextProps[propName$1], lastVnode, isSvg);
  1338. }
  1339. }
  1340. var SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
  1341. function createElement(vnode, isSvg, parentContext, parentComponent) {
  1342. var domNode;
  1343. if (isValidElement(vnode)) {
  1344. var vtype = vnode.vtype;
  1345. if (vtype & (4 /* Composite */ | 8 /* Stateless */)) {
  1346. domNode = vnode.init(parentContext, parentComponent);
  1347. options.afterMount(vnode);
  1348. } else if (vtype & 1 /* Text */) {
  1349. domNode = doc.createTextNode(vnode.text);
  1350. vnode.dom = domNode;
  1351. } else if (vtype & 2 /* Node */) {
  1352. domNode = mountVNode$1(vnode, isSvg, parentContext, parentComponent);
  1353. } else if (vtype & 16 /* Void */) {
  1354. domNode = vnode.dom;
  1355. } else if (isPortal(vtype, vnode)) {
  1356. vnode.type.appendChild(createElement(vnode.children, isSvg, parentContext, parentComponent));
  1357. domNode = doc.createTextNode('');
  1358. }
  1359. } else if (isString(vnode) || isNumber(vnode)) {
  1360. domNode = doc.createTextNode(vnode);
  1361. } else if (isNullOrUndef(vnode) || isBoolean(vnode)) {
  1362. domNode = doc.createTextNode('');
  1363. } else if (isArray(vnode)) {
  1364. domNode = doc.createDocumentFragment();
  1365. vnode.forEach(function (child) {
  1366. if (!isInvalid(child)) {
  1367. var childNode = createElement(child, isSvg, parentContext, parentComponent);
  1368. if (childNode) {
  1369. domNode.appendChild(childNode);
  1370. }
  1371. }
  1372. });
  1373. } else {
  1374. throw new Error('Unsupported VNode.');
  1375. }
  1376. return domNode;
  1377. }
  1378. function mountVNode$1(vnode, isSvg, parentContext, parentComponent) {
  1379. if (vnode.isSvg) {
  1380. isSvg = true;
  1381. } else if (vnode.type === 'svg') {
  1382. isSvg = true;
  1383. /* istanbul ignore next */
  1384. } else if (!isSupportSVG) {
  1385. isSvg = false;
  1386. }
  1387. if (isSvg) {
  1388. vnode.namespace = SVG_NAMESPACE;
  1389. vnode.isSvg = isSvg;
  1390. }
  1391. var domNode = !isSvg ? doc.createElement(vnode.type) : doc.createElementNS(vnode.namespace, vnode.type);
  1392. setProps(domNode, vnode, isSvg);
  1393. if (vnode.type === 'foreignObject') {
  1394. isSvg = false;
  1395. }
  1396. var children = vnode.children;
  1397. if (isArray(children)) {
  1398. for (var i = 0, len = children.length; i < len; i++) {
  1399. mountChild(children[i], domNode, parentContext, isSvg, parentComponent);
  1400. }
  1401. } else {
  1402. mountChild(children, domNode, parentContext, isSvg, parentComponent);
  1403. }
  1404. vnode.dom = domNode;
  1405. if (vnode.ref !== null) {
  1406. Ref.attach(vnode, vnode.ref, domNode);
  1407. }
  1408. return domNode;
  1409. }
  1410. function mountChild(child, domNode, parentContext, isSvg, parentComponent) {
  1411. child.parentContext = parentContext || EMPTY_OBJ;
  1412. var childNode = createElement(child, isSvg, parentContext, parentComponent);
  1413. if (childNode !== null) {
  1414. domNode.appendChild(childNode);
  1415. }
  1416. }
  1417. function setProps(domNode, vnode, isSvg) {
  1418. var props = vnode.props;
  1419. for (var p in props) {
  1420. patchProp(domNode, p, null, props[p], null, isSvg);
  1421. }
  1422. }
  1423. function createVText(text) {
  1424. return {
  1425. text: text,
  1426. vtype: 1 /* Text */
  1427. , dom: null
  1428. };
  1429. }
  1430. function createVoid() {
  1431. var dom = doc.createTextNode('');
  1432. return {
  1433. dom: dom,
  1434. vtype: 16 /* Void */
  1435. };
  1436. }
  1437. var readyComponents = [];
  1438. function errorCatcher(fn, component) {
  1439. try {
  1440. return fn();
  1441. } catch (error) {
  1442. errorHandler(component, error);
  1443. }
  1444. }
  1445. function errorHandler(component, error) {
  1446. var boundary;
  1447. while (true) {
  1448. if (isFunction(component.componentDidCatch)) {
  1449. boundary = component;
  1450. break;
  1451. } else if (component._parentComponent) {
  1452. component = component._parentComponent;
  1453. } else {
  1454. break;
  1455. }
  1456. }
  1457. if (boundary) {
  1458. var _disable = boundary._disable;
  1459. boundary._disable = false;
  1460. boundary.componentDidCatch(error);
  1461. boundary._disable = _disable;
  1462. } else {
  1463. throw error;
  1464. }
  1465. }
  1466. function mountVNode(vnode, parentContext, parentComponent) {
  1467. return createElement(vnode, false, parentContext, parentComponent);
  1468. }
  1469. function mountComponent(vnode, parentContext, parentComponent) {
  1470. var ref = vnode.ref;
  1471. vnode.component = new vnode.type(vnode.props, parentContext);
  1472. var component = vnode.component;
  1473. if (isComponent(parentComponent)) {
  1474. component._parentComponent = parentComponent;
  1475. }
  1476. if (isFunction(component.componentWillMount)) {
  1477. errorCatcher(function () {
  1478. component.componentWillMount();
  1479. }, component);
  1480. component.state = component.getState();
  1481. }
  1482. component._dirty = false;
  1483. var rendered = renderComponent(component);
  1484. component._rendered = rendered;
  1485. if (isFunction(component.componentDidMount)) {
  1486. readyComponents.push(component);
  1487. }
  1488. if (!isNullOrUndef(ref)) {
  1489. Ref.attach(vnode, ref, component.dom);
  1490. }
  1491. var dom = vnode.dom = component.dom = mountVNode(rendered, getChildContext(component, parentContext), component);
  1492. component._disable = false;
  1493. return dom;
  1494. }
  1495. function mountStatelessComponent(vnode, parentContext) {
  1496. vnode._rendered = vnode.type(vnode.props, parentContext);
  1497. return vnode.dom = mountVNode(vnode._rendered, parentContext);
  1498. }
  1499. function getChildContext(component, context) {
  1500. if (component.getChildContext) {
  1501. return extend(context, component.getChildContext());
  1502. }
  1503. return context;
  1504. }
  1505. function renderComponent(component) {
  1506. Current.current = component;
  1507. var rendered;
  1508. errorCatcher(function () {
  1509. rendered = component.render();
  1510. }, component);
  1511. if (isNumber(rendered) || isString(rendered)) {
  1512. rendered = createVText(rendered);
  1513. } else if (isUndefined(rendered)) {
  1514. rendered = createVoid();
  1515. }
  1516. Current.current = null;
  1517. return rendered;
  1518. }
  1519. function flushMount() {
  1520. if (!readyComponents.length) {
  1521. return;
  1522. }
  1523. // @TODO: perf
  1524. var queue = readyComponents.slice(0);
  1525. readyComponents.length = 0;
  1526. queue.forEach(function (item) {
  1527. if (isFunction(item)) {
  1528. item();
  1529. } else if (item.componentDidMount) {
  1530. errorCatcher(function () {
  1531. item.componentDidMount();
  1532. }, item);
  1533. }
  1534. });
  1535. }
  1536. function reRenderComponent(prev, current) {
  1537. var component = current.component = prev.component;
  1538. var nextProps = current.props;
  1539. var nextContext = component.context;
  1540. component._disable = true;
  1541. if (isFunction(component.componentWillReceiveProps)) {
  1542. errorCatcher(function () {
  1543. component.componentWillReceiveProps(nextProps, nextContext);
  1544. }, component);
  1545. }
  1546. component._disable = false;
  1547. component.prevProps = component.props;
  1548. component.prevState = component.state;
  1549. component.prevContext = component.context;
  1550. component.props = nextProps;
  1551. component.context = nextContext;
  1552. if (!isNullOrUndef(current.ref)) {
  1553. Ref.update(prev, current);
  1554. }
  1555. updateComponent(component);
  1556. return component.dom;
  1557. }
  1558. function reRenderStatelessComponent(prev, current, parentContext, domNode) {
  1559. var lastRendered = prev._rendered;
  1560. var rendered = current.type(current.props, parentContext);
  1561. current._rendered = rendered;
  1562. return current.dom = patch(lastRendered, rendered, domNode, parentContext);
  1563. }
  1564. function updateComponent(component, isForce) {
  1565. if (isForce === void 0) isForce = false;
  1566. var lastDom = component.dom;
  1567. var props = component.props;
  1568. var state = component.getState();
  1569. var context = component.context;
  1570. var prevProps = component.prevProps || props;
  1571. var prevState = component.prevState || state;
  1572. var prevContext = component.prevContext || context;
  1573. component.props = prevProps;
  1574. component.context = prevContext;
  1575. var skip = false;
  1576. if (!isForce && isFunction(component.shouldComponentUpdate) && component.shouldComponentUpdate(props, state, context) === false) {
  1577. skip = true;
  1578. } else if (isFunction(component.componentWillUpdate)) {
  1579. errorCatcher(function () {
  1580. component.componentWillUpdate(props, state, context);
  1581. }, component);
  1582. }
  1583. component.props = props;
  1584. component.state = state;
  1585. component.context = context;
  1586. component._dirty = false;
  1587. if (!skip) {
  1588. var lastRendered = component._rendered;
  1589. var rendered = renderComponent(component);
  1590. var childContext = getChildContext(component, context);
  1591. component.dom = patch(lastRendered, rendered, lastDom, childContext);
  1592. component._rendered = rendered;
  1593. if (isFunction(component.componentDidUpdate)) {
  1594. errorCatcher(function () {
  1595. component.componentDidUpdate(prevProps, prevState, context);
  1596. }, component);
  1597. }
  1598. }
  1599. component.prevProps = component.props;
  1600. component.prevState = component.state;
  1601. component.prevContext = component.context;
  1602. if (component._pendingCallbacks) {
  1603. while (component._pendingCallbacks.length) {
  1604. component._pendingCallbacks.pop().call(component);
  1605. }
  1606. }
  1607. flushMount();
  1608. }
  1609. function unmountComponent(vnode) {
  1610. var component = vnode.component;
  1611. if (isFunction(component.componentWillUnmount)) {
  1612. errorCatcher(function () {
  1613. component.componentWillUnmount();
  1614. }, component);
  1615. }
  1616. component._disable = true;
  1617. unmount(component._rendered);
  1618. if (!isNullOrUndef(vnode.ref)) {
  1619. Ref.detach(vnode, vnode.ref, vnode.dom);
  1620. }
  1621. }
  1622. function unmountStatelessComponent(vnode) {
  1623. unmount(vnode._rendered);
  1624. }
  1625. var items = [];
  1626. function enqueueRender(component) {
  1627. // tslint:disable-next-line:no-conditional-assignment
  1628. if (!component._dirty && (component._dirty = true) && items.push(component) === 1) {
  1629. nextTick(rerender);
  1630. }
  1631. }
  1632. function rerender() {
  1633. var p;
  1634. var list = items;
  1635. items = [];
  1636. // tslint:disable-next-line:no-conditional-assignment
  1637. while (p = list.pop()) {
  1638. if (p._dirty) {
  1639. updateComponent(p);
  1640. }
  1641. }
  1642. }
  1643. var Component = function Component(props, context) {
  1644. this._dirty = true;
  1645. this._disable = true;
  1646. this._pendingStates = [];
  1647. // Is a React Component.
  1648. // tslint:disable-next-line:max-line-length
  1649. // see: https://github.com/facebook/react/blob/3c977dea6b96f6a9bb39f09886848da870748441/packages/react/src/ReactBaseClasses.js#L26
  1650. this.isReactComponent = EMPTY_OBJ;
  1651. if (!this.state) {
  1652. this.state = {};
  1653. }
  1654. this.props = props || {};
  1655. this.context = context || EMPTY_OBJ;
  1656. this.refs = {};
  1657. };
  1658. Component.prototype.setState = function setState(state, callback) {
  1659. if (state) {
  1660. (this._pendingStates = this._pendingStates || []).push(state);
  1661. }
  1662. if (isFunction(callback)) {
  1663. (this._pendingCallbacks = this._pendingCallbacks || []).push(callback);
  1664. }
  1665. if (!this._disable) {
  1666. enqueueRender(this);
  1667. }
  1668. };
  1669. Component.prototype.getState = function getState() {
  1670. var this$1 = this;
  1671. // tslint:disable-next-line:no-this-assignment
  1672. var ref = this;
  1673. var _pendingStates = ref._pendingStates;
  1674. var state = ref.state;
  1675. var props = ref.props;
  1676. if (!_pendingStates.length) {
  1677. return state;
  1678. }
  1679. var stateClone = clone(state);
  1680. var queue = _pendingStates.concat();
  1681. this._pendingStates.length = 0;
  1682. queue.forEach(function (nextState) {
  1683. if (isFunction(nextState)) {
  1684. nextState = nextState.call(this$1, state, props);
  1685. }
  1686. extend(stateClone, nextState);
  1687. });
  1688. return stateClone;
  1689. };
  1690. Component.prototype.forceUpdate = function forceUpdate(callback) {
  1691. if (isFunction(callback)) {
  1692. (this._pendingCallbacks = this._pendingCallbacks || []).push(callback);
  1693. }
  1694. updateComponent(this, true);
  1695. };
  1696. // tslint:disable-next-line
  1697. Component.prototype.render = function render(nextProps, nextState, nextContext) {};
  1698. var PureComponent = function (Component$$1) {
  1699. function PureComponent() {
  1700. Component$$1.apply(this, arguments);
  1701. this.isPureComponent = true;
  1702. }
  1703. if (Component$$1) PureComponent.__proto__ = Component$$1;
  1704. PureComponent.prototype = Object.create(Component$$1 && Component$$1.prototype);
  1705. PureComponent.prototype.constructor = PureComponent;
  1706. PureComponent.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
  1707. return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState);
  1708. };
  1709. return PureComponent;
  1710. }(Component);
  1711. function render(vnode, container, callback) {
  1712. if (!container) {
  1713. throw new Error(container + " should be a DOM Element");
  1714. }
  1715. var lastVnode = container._component;
  1716. var dom;
  1717. options.roots.push(vnode);
  1718. if (lastVnode !== undefined) {
  1719. options.roots = options.roots.filter(function (item) {
  1720. return item !== lastVnode;
  1721. });
  1722. dom = patch(lastVnode, vnode, container, {});
  1723. } else {
  1724. dom = mountVNode(vnode, {});
  1725. container.appendChild(dom);
  1726. }
  1727. if (container) {
  1728. container._component = vnode;
  1729. }
  1730. flushMount();
  1731. if (callback) {
  1732. callback();
  1733. }
  1734. return isComposite(vnode) ? vnode.component : dom;
  1735. }
  1736. function createVNode(type, props, children, key, namespace, owner, ref) {
  1737. return {
  1738. type: type,
  1739. key: key || null,
  1740. vtype: 2 /* Node */
  1741. , props: props || EMPTY_OBJ,
  1742. children: children,
  1743. namespace: namespace || null,
  1744. _owner: owner,
  1745. dom: null,
  1746. ref: ref || null
  1747. };
  1748. }
  1749. function h(type, props, children) {
  1750. var childNodes;
  1751. if (props.children) {
  1752. if (!children) {
  1753. children = props.children;
  1754. }
  1755. }
  1756. if (isArray(children)) {
  1757. childNodes = [];
  1758. addChildren(childNodes, children, type);
  1759. } else if (isString(children) || isNumber(children)) {
  1760. children = createVText(String(children));
  1761. } else if (!isValidElement(children)) {
  1762. children = EMPTY_CHILDREN;
  1763. }
  1764. props.children = childNodes !== undefined ? childNodes : children;
  1765. return createVNode(type, props, props.children, props.key, props.namespace, props.owner, props.ref);
  1766. }
  1767. function addChildren(childNodes, children, type) {
  1768. if (isString(children) || isNumber(children)) {
  1769. childNodes.push(createVText(String(children)));
  1770. } else if (isValidElement(children)) {
  1771. childNodes.push(children);
  1772. } else if (isArray(children)) {
  1773. for (var i = 0; i < children.length; i++) {
  1774. addChildren(childNodes, children[i], type);
  1775. }
  1776. }
  1777. }
  1778. var ComponentWrapper = function ComponentWrapper(type, props) {
  1779. this.vtype = 4 /* Composite */;
  1780. this.type = type;
  1781. this.name = type.name || type.toString().match(/^function\s*([^\s(]+)/)[1];
  1782. type.displayName = this.name;
  1783. this._owner = props.owner;
  1784. delete props.owner;
  1785. if (this.ref = props.ref) {
  1786. delete props.ref;
  1787. }
  1788. this.props = props;
  1789. this.key = props.key;
  1790. this.dom = null;
  1791. };
  1792. ComponentWrapper.prototype.init = function init(parentContext, parentComponent) {
  1793. return mountComponent(this, parentContext, parentComponent);
  1794. };
  1795. ComponentWrapper.prototype.update = function update(previous, current, parentContext, domNode) {
  1796. return reRenderComponent(previous, this);
  1797. };
  1798. ComponentWrapper.prototype.destroy = function destroy() {
  1799. unmountComponent(this);
  1800. };
  1801. var StateLessComponent = function StateLessComponent(type, props) {
  1802. this.vtype = 8 /* Stateless */;
  1803. this.type = type;
  1804. this._owner = props.owner;
  1805. delete props.owner;
  1806. this.props = props;
  1807. this.key = props.key;
  1808. };
  1809. StateLessComponent.prototype.init = function init(parentContext) {
  1810. return mountStatelessComponent(this, parentContext);
  1811. };
  1812. StateLessComponent.prototype.update = function update(previous, current, parentContext, domNode) {
  1813. var props = current.props;
  1814. var context = current.context;
  1815. var shouldComponentUpdate = props.onShouldComponentUpdate;
  1816. if (isFunction(shouldComponentUpdate) && !shouldComponentUpdate(previous.props, props, context)) {
  1817. current._rendered = previous._rendered;
  1818. return domNode;
  1819. }
  1820. return reRenderStatelessComponent(previous, this, parentContext, domNode);
  1821. };
  1822. StateLessComponent.prototype.destroy = function destroy() {
  1823. unmountStatelessComponent(this);
  1824. };
  1825. function transformPropsForRealTag(type, props) {
  1826. var newProps = {};
  1827. for (var propName in props) {
  1828. var propValue = props[propName];
  1829. if (propName === 'defaultValue') {
  1830. newProps.value = props.value || props.defaultValue;
  1831. continue;
  1832. }
  1833. var svgPropName = SVGPropertyConfig.DOMAttributeNames[propName];
  1834. if (svgPropName && svgPropName !== propName) {
  1835. newProps[svgPropName] = propValue;
  1836. continue;
  1837. }
  1838. newProps[propName] = propValue;
  1839. }
  1840. return newProps;
  1841. }
  1842. /**
  1843. *
  1844. * @param props
  1845. * @param defaultProps
  1846. * defaultProps should respect null but ignore undefined
  1847. * @see: https://facebook.github.io/react/docs/react-component.html#defaultprops
  1848. */
  1849. function transformPropsForComponent(props, defaultProps) {
  1850. var newProps = {};
  1851. for (var propName in props) {
  1852. var propValue = props[propName];
  1853. newProps[propName] = propValue;
  1854. }
  1855. if (defaultProps) {
  1856. for (var propName$1 in defaultProps) {
  1857. if (isUndefined(newProps[propName$1])) {
  1858. newProps[propName$1] = defaultProps[propName$1];
  1859. }
  1860. }
  1861. }
  1862. return newProps;
  1863. }
  1864. function createElement$2(type, properties) {
  1865. var _children = [],
  1866. len = arguments.length - 2;
  1867. while (len-- > 0) _children[len] = arguments[len + 2];
  1868. var children = _children;
  1869. if (_children) {
  1870. if (_children.length === 1) {
  1871. children = _children[0];
  1872. } else if (_children.length === 0) {
  1873. children = undefined;
  1874. }
  1875. }
  1876. var props;
  1877. if (isString(type)) {
  1878. props = transformPropsForRealTag(type, properties);
  1879. props.owner = Current.current;
  1880. return h(type, props, children);
  1881. } else if (isFunction(type)) {
  1882. props = transformPropsForComponent(properties, type.defaultProps);
  1883. if (!props.children || props.children === EMPTY_CHILDREN) {
  1884. props.children = children || EMPTY_CHILDREN;
  1885. }
  1886. props.owner = Current.current;
  1887. return type.prototype && type.prototype.render ? new ComponentWrapper(type, props) : new StateLessComponent(type, props);
  1888. }
  1889. return type;
  1890. }
  1891. function cloneElement(vnode, props) {
  1892. var children = [],
  1893. len = arguments.length - 2;
  1894. while (len-- > 0) children[len] = arguments[len + 2];
  1895. if (isVText(vnode)) {
  1896. vnode.dom = null;
  1897. return vnode;
  1898. }
  1899. if (isString(vnode)) {
  1900. return createVText(vnode);
  1901. }
  1902. var properties = clone(extend(clone(vnode.props), props));
  1903. if (vnode.namespace) {
  1904. properties.namespace = vnode.namespace;
  1905. }
  1906. if (vnode.vtype & 4 /* Composite */ && !isNullOrUndef(vnode.ref)) {
  1907. properties.ref = vnode.ref;
  1908. }
  1909. var childrenTmp = (arguments.length > 2 ? [].slice.call(arguments, 2) : vnode.children || properties.children) || [];
  1910. if (childrenTmp.length) {
  1911. if (childrenTmp.length === 1) {
  1912. childrenTmp = children[0];
  1913. }
  1914. }
  1915. if (isArray(vnode)) {
  1916. return vnode.map(function (item) {
  1917. return cloneElement(item);
  1918. });
  1919. }
  1920. var newVNode = createElement$2(vnode.type, properties);
  1921. if (isArray(childrenTmp)) {
  1922. var _children = childrenTmp.map(function (child) {
  1923. return cloneElement(child, child.props);
  1924. });
  1925. if (_children.length === 0) {
  1926. _children = EMPTY_CHILDREN;
  1927. }
  1928. if (isVNode(newVNode)) {
  1929. newVNode.children = _children;
  1930. }
  1931. newVNode.props.children = _children;
  1932. } else if (childrenTmp) {
  1933. if (isVNode(newVNode)) {
  1934. newVNode.children = childrenTmp;
  1935. }
  1936. newVNode.props.children = cloneElement(childrenTmp, childrenTmp.props);
  1937. }
  1938. return newVNode;
  1939. }
  1940. var Children = {
  1941. map: function map(children, fn, ctx) {
  1942. if (isNullOrUndef(children)) {
  1943. return children;
  1944. }
  1945. children = Children.toArray(children);
  1946. if (ctx && ctx !== children) {
  1947. fn = fn.bind(ctx);
  1948. }
  1949. return children.map(fn);
  1950. },
  1951. forEach: function forEach(children, fn, ctx) {
  1952. if (isNullOrUndef(children)) {
  1953. return;
  1954. }
  1955. children = Children.toArray(children);
  1956. if (ctx && ctx !== children) {
  1957. fn = fn.bind(ctx);
  1958. }
  1959. for (var i = 0, len = children.length; i < len; i++) {
  1960. var child = isInvalid(children[i]) ? null : children[i];
  1961. fn(child, i, children);
  1962. }
  1963. },
  1964. count: function count(children) {
  1965. children = Children.toArray(children);
  1966. return children.length;
  1967. },
  1968. only: function only(children) {
  1969. children = Children.toArray(children);
  1970. if (children.length !== 1) {
  1971. throw new Error('Children.only() expects only one child.');
  1972. }
  1973. return children[0];
  1974. },
  1975. toArray: function toArray(children) {
  1976. if (isNullOrUndef(children)) {
  1977. return [];
  1978. }
  1979. if (isArray(children)) {
  1980. var result = [];
  1981. flatten(children, result);
  1982. return result;
  1983. }
  1984. return EMPTY_CHILDREN.concat(children);
  1985. }
  1986. };
  1987. function flatten(arr, result) {
  1988. for (var i = 0, len = arr.length; i < len; i++) {
  1989. var value = arr[i];
  1990. if (isArray(value)) {
  1991. flatten(value, result);
  1992. } else {
  1993. result.push(value);
  1994. }
  1995. }
  1996. return result;
  1997. }
  1998. // tslint:disable:no-conditional-assignment
  1999. function hydrate(vnode, container, callback) {
  2000. if (container !== null) {
  2001. // lastChild causes less reflow than firstChild
  2002. var dom = container.lastChild;
  2003. // there should be only a single entry for the root
  2004. while (dom) {
  2005. var next = dom.previousSibling;
  2006. container.removeChild(dom);
  2007. dom = next;
  2008. }
  2009. return render(vnode, container, callback);
  2010. }
  2011. }
  2012. function createPortal(children, container) {
  2013. return {
  2014. type: container,
  2015. vtype: 32 /* Portal */
  2016. , children: children,
  2017. dom: null
  2018. };
  2019. }
  2020. function unmountComponentAtNode(dom) {
  2021. var component = dom._component;
  2022. if (isValidElement(component)) {
  2023. unmount(component, dom);
  2024. delete dom._component;
  2025. return true;
  2026. }
  2027. return false;
  2028. }
  2029. function findDOMNode(component) {
  2030. return component && component.dom || component;
  2031. }
  2032. function createFactory(type) {
  2033. return createElement$2.bind(null, type);
  2034. }
  2035. var WrapperComponent = function (Component$$1) {
  2036. function WrapperComponent() {
  2037. Component$$1.apply(this, arguments);
  2038. }
  2039. if (Component$$1) WrapperComponent.__proto__ = Component$$1;
  2040. WrapperComponent.prototype = Object.create(Component$$1 && Component$$1.prototype);
  2041. WrapperComponent.prototype.constructor = WrapperComponent;
  2042. WrapperComponent.prototype.getChildContext = function getChildContext() {
  2043. // tslint:disable-next-line
  2044. return this.props.context;
  2045. };
  2046. WrapperComponent.prototype.render = function render$$1() {
  2047. return this.props.children;
  2048. };
  2049. return WrapperComponent;
  2050. }(Component);
  2051. function unstable_renderSubtreeIntoContainer(parentComponent, vnode, container, callback) {
  2052. // @TODO: should handle props.context?
  2053. var wrapper = createElement$2(WrapperComponent, { context: parentComponent.context }, vnode);
  2054. var rendered = render(wrapper, container);
  2055. if (callback) {
  2056. callback.call(rendered);
  2057. }
  2058. return rendered;
  2059. }
  2060. function isValidElement$1(element) {
  2061. return isValidElement(element) && (element.vtype & (4 /* Composite */ | 2 /* Node */)) > 0;
  2062. }
  2063. var unstable_batchedUpdates = nextTick;
  2064. var nerv = {
  2065. Children: Children,
  2066. Component: Component,
  2067. PureComponent: PureComponent,
  2068. createElement: createElement$2,
  2069. cloneElement: cloneElement,
  2070. render: render,
  2071. nextTick: nextTick,
  2072. options: options,
  2073. findDOMNode: findDOMNode,
  2074. isValidElement: isValidElement$1,
  2075. unmountComponentAtNode: unmountComponentAtNode,
  2076. createPortal: createPortal,
  2077. unstable_renderSubtreeIntoContainer: unstable_renderSubtreeIntoContainer,
  2078. hydrate: hydrate,
  2079. createFactory: createFactory,
  2080. unstable_batchedUpdates: unstable_batchedUpdates
  2081. };
  2082. //exports.Children = Children;
  2083. //exports.Component = Component;
  2084. //exports.PureComponent = PureComponent;
  2085. //exports.createElement = createElement$2;
  2086. //exports.cloneElement = cloneElement;
  2087. //exports.render = render;
  2088. //exports.nextTick = nextTick;
  2089. //exports.options = options;
  2090. //exports.findDOMNode = findDOMNode;
  2091. //exports.isValidElement = isValidElement$1;
  2092. //exports.unmountComponentAtNode = unmountComponentAtNode;
  2093. //exports.createPortal = createPortal;
  2094. //exports.unstable_renderSubtreeIntoContainer = unstable_renderSubtreeIntoContainer;
  2095. //exports.hydrate = hydrate;
  2096. //exports.createFactory = createFactory;
  2097. //exports.unstable_batchedUpdates = unstable_batchedUpdates;
  2098. window.React = window.ReactDOM = nerv;
  2099. //module.exports = nerv;
  2100. //exports['default'] = index;
  2101. //# sourceMappingURL=index.js.map