shared.js 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. function noop() {}
  2. function assign(tar, src) {
  3. for (var k in src) tar[k] = src[k];
  4. return tar;
  5. }
  6. function assignTrue(tar, src) {
  7. for (var k in src) tar[k] = 1;
  8. return tar;
  9. }
  10. function isPromise(value) {
  11. return value && typeof value.then === 'function';
  12. }
  13. function callAfter(fn, i) {
  14. if (i === 0) fn();
  15. return () => {
  16. if (!--i) fn();
  17. };
  18. }
  19. function addLoc(element, file, line, column, char) {
  20. element.__svelte_meta = {
  21. loc: { file, line, column, char }
  22. };
  23. }
  24. function exclude(src, prop) {
  25. const tar = {};
  26. for (const k in src) k === prop || (tar[k] = src[k]);
  27. return tar;
  28. }
  29. function run(fn) {
  30. fn();
  31. }
  32. function append(target, node) {
  33. target.appendChild(node);
  34. }
  35. function insert(target, node, anchor) {
  36. target.insertBefore(node, anchor);
  37. }
  38. function detachNode(node) {
  39. node.parentNode.removeChild(node);
  40. }
  41. function detachBetween(before, after) {
  42. while (before.nextSibling && before.nextSibling !== after) {
  43. before.parentNode.removeChild(before.nextSibling);
  44. }
  45. }
  46. function detachBefore(after) {
  47. while (after.previousSibling) {
  48. after.parentNode.removeChild(after.previousSibling);
  49. }
  50. }
  51. function detachAfter(before) {
  52. while (before.nextSibling) {
  53. before.parentNode.removeChild(before.nextSibling);
  54. }
  55. }
  56. function reinsertBetween(before, after, target) {
  57. while (before.nextSibling && before.nextSibling !== after) {
  58. target.appendChild(before.parentNode.removeChild(before.nextSibling));
  59. }
  60. }
  61. function reinsertChildren(parent, target) {
  62. while (parent.firstChild) target.appendChild(parent.firstChild);
  63. }
  64. function reinsertAfter(before, target) {
  65. while (before.nextSibling) target.appendChild(before.nextSibling);
  66. }
  67. function reinsertBefore(after, target) {
  68. var parent = after.parentNode;
  69. while (parent.firstChild !== after) target.appendChild(parent.firstChild);
  70. }
  71. function destroyEach(iterations, detach) {
  72. for (var i = 0; i < iterations.length; i += 1) {
  73. if (iterations[i]) iterations[i].d(detach);
  74. }
  75. }
  76. function createFragment() {
  77. return document.createDocumentFragment();
  78. }
  79. function createElement(name) {
  80. return document.createElement(name);
  81. }
  82. function createSvgElement(name) {
  83. return document.createElementNS('http://www.w3.org/2000/svg', name);
  84. }
  85. function createText(data) {
  86. return document.createTextNode(data);
  87. }
  88. function createComment() {
  89. return document.createComment('');
  90. }
  91. function addListener(node, event, handler, options) {
  92. node.addEventListener(event, handler, options);
  93. }
  94. function removeListener(node, event, handler, options) {
  95. node.removeEventListener(event, handler, options);
  96. }
  97. function setAttribute(node, attribute, value) {
  98. if (value == null) node.removeAttribute(attribute);
  99. else node.setAttribute(attribute, value);
  100. }
  101. function setAttributes(node, attributes) {
  102. for (var key in attributes) {
  103. if (key === 'style') {
  104. node.style.cssText = attributes[key];
  105. } else if (key in node) {
  106. node[key] = attributes[key];
  107. } else {
  108. setAttribute(node, key, attributes[key]);
  109. }
  110. }
  111. }
  112. function setCustomElementData(node, prop, value) {
  113. if (prop in node) {
  114. node[prop] = value;
  115. } else if (value) {
  116. setAttribute(node, prop, value);
  117. } else {
  118. node.removeAttribute(prop);
  119. }
  120. }
  121. function setXlinkAttribute(node, attribute, value) {
  122. node.setAttributeNS('http://www.w3.org/1999/xlink', attribute, value);
  123. }
  124. function getBindingGroupValue(group) {
  125. var value = [];
  126. for (var i = 0; i < group.length; i += 1) {
  127. if (group[i].checked) value.push(group[i].__value);
  128. }
  129. return value;
  130. }
  131. function toNumber(value) {
  132. return value === '' ? undefined : +value;
  133. }
  134. function timeRangesToArray(ranges) {
  135. var array = [];
  136. for (var i = 0; i < ranges.length; i += 1) {
  137. array.push({ start: ranges.start(i), end: ranges.end(i) });
  138. }
  139. return array;
  140. }
  141. function children (element) {
  142. return Array.from(element.childNodes);
  143. }
  144. function claimElement (nodes, name, attributes, svg) {
  145. for (var i = 0; i < nodes.length; i += 1) {
  146. var node = nodes[i];
  147. if (node.nodeName === name) {
  148. for (var j = 0; j < node.attributes.length; j += 1) {
  149. var attribute = node.attributes[j];
  150. if (!attributes[attribute.name]) node.removeAttribute(attribute.name);
  151. }
  152. return nodes.splice(i, 1)[0]; // TODO strip unwanted attributes
  153. }
  154. }
  155. return svg ? createSvgElement(name) : createElement(name);
  156. }
  157. function claimText (nodes, data) {
  158. for (var i = 0; i < nodes.length; i += 1) {
  159. var node = nodes[i];
  160. if (node.nodeType === 3) {
  161. node.data = data;
  162. return nodes.splice(i, 1)[0];
  163. }
  164. }
  165. return createText(data);
  166. }
  167. function setData(text, data) {
  168. text.data = '' + data;
  169. }
  170. function setInputType(input, type) {
  171. try {
  172. input.type = type;
  173. } catch (e) {}
  174. }
  175. function setStyle(node, key, value) {
  176. node.style.setProperty(key, value);
  177. }
  178. function selectOption(select, value) {
  179. for (var i = 0; i < select.options.length; i += 1) {
  180. var option = select.options[i];
  181. if (option.__value === value) {
  182. option.selected = true;
  183. return;
  184. }
  185. }
  186. }
  187. function selectOptions(select, value) {
  188. for (var i = 0; i < select.options.length; i += 1) {
  189. var option = select.options[i];
  190. option.selected = ~value.indexOf(option.__value);
  191. }
  192. }
  193. function selectValue(select) {
  194. var selectedOption = select.querySelector(':checked') || select.options[0];
  195. return selectedOption && selectedOption.__value;
  196. }
  197. function selectMultipleValue(select) {
  198. return [].map.call(select.querySelectorAll(':checked'), function(option) {
  199. return option.__value;
  200. });
  201. }
  202. function addResizeListener(element, fn) {
  203. if (getComputedStyle(element).position === 'static') {
  204. element.style.position = 'relative';
  205. }
  206. const object = document.createElement('object');
  207. object.setAttribute('style', 'display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;');
  208. object.type = 'text/html';
  209. let win;
  210. object.onload = () => {
  211. win = object.contentDocument.defaultView;
  212. win.addEventListener('resize', fn);
  213. };
  214. if (/Trident/.test(navigator.userAgent)) {
  215. element.appendChild(object);
  216. object.data = 'about:blank';
  217. } else {
  218. object.data = 'about:blank';
  219. element.appendChild(object);
  220. }
  221. return {
  222. cancel: () => {
  223. win && win.removeEventListener && win.removeEventListener('resize', fn);
  224. element.removeChild(object);
  225. }
  226. };
  227. }
  228. function toggleClass(element, name, toggle) {
  229. element.classList.toggle(name, !!toggle);
  230. }
  231. function linear(t) {
  232. return t;
  233. }
  234. function generateRule({ a, b, delta, duration }, ease, fn) {
  235. const step = 16.666 / duration;
  236. let keyframes = '{\n';
  237. for (let p = 0; p <= 1; p += step) {
  238. const t = a + delta * ease(p);
  239. keyframes += p * 100 + `%{${fn(t, 1 - t)}}\n`;
  240. }
  241. return keyframes + `100% {${fn(b, 1 - b)}}\n}`;
  242. }
  243. // https://github.com/darkskyapp/string-hash/blob/master/index.js
  244. function hash(str) {
  245. let hash = 5381;
  246. let i = str.length;
  247. while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
  248. return hash >>> 0;
  249. }
  250. function wrapTransition(component, node, fn, params, intro) {
  251. let obj = fn.call(component, node, params);
  252. let duration;
  253. let ease;
  254. let cssText;
  255. let initialised = false;
  256. return {
  257. t: intro ? 0 : 1,
  258. running: false,
  259. program: null,
  260. pending: null,
  261. run(b, callback) {
  262. if (typeof obj === 'function') {
  263. transitionManager.wait().then(() => {
  264. obj = obj();
  265. this._run(b, callback);
  266. });
  267. } else {
  268. this._run(b, callback);
  269. }
  270. },
  271. _run(b, callback) {
  272. duration = obj.duration || 300;
  273. ease = obj.easing || linear;
  274. const program = {
  275. start: window.performance.now() + (obj.delay || 0),
  276. b,
  277. callback: callback || noop
  278. };
  279. if (intro && !initialised) {
  280. if (obj.css && obj.delay) {
  281. cssText = node.style.cssText;
  282. node.style.cssText += obj.css(0, 1);
  283. }
  284. if (obj.tick) obj.tick(0, 1);
  285. initialised = true;
  286. }
  287. if (!b) {
  288. program.group = outros.current;
  289. outros.current.remaining += 1;
  290. }
  291. if (obj.delay) {
  292. this.pending = program;
  293. } else {
  294. this.start(program);
  295. }
  296. if (!this.running) {
  297. this.running = true;
  298. transitionManager.add(this);
  299. }
  300. },
  301. start(program) {
  302. component.fire(`${program.b ? 'intro' : 'outro'}.start`, { node });
  303. program.a = this.t;
  304. program.delta = program.b - program.a;
  305. program.duration = duration * Math.abs(program.b - program.a);
  306. program.end = program.start + program.duration;
  307. if (obj.css) {
  308. if (obj.delay) node.style.cssText = cssText;
  309. const rule = generateRule(program, ease, obj.css);
  310. transitionManager.addRule(rule, program.name = '__svelte_' + hash(rule));
  311. node.style.animation = (node.style.animation || '')
  312. .split(', ')
  313. .filter(anim => anim && (program.delta < 0 || !/__svelte/.test(anim)))
  314. .concat(`${program.name} ${program.duration}ms linear 1 forwards`)
  315. .join(', ');
  316. }
  317. this.program = program;
  318. this.pending = null;
  319. },
  320. update(now) {
  321. const program = this.program;
  322. if (!program) return;
  323. const p = now - program.start;
  324. this.t = program.a + program.delta * ease(p / program.duration);
  325. if (obj.tick) obj.tick(this.t, 1 - this.t);
  326. },
  327. done() {
  328. const program = this.program;
  329. this.t = program.b;
  330. if (obj.tick) obj.tick(this.t, 1 - this.t);
  331. component.fire(`${program.b ? 'intro' : 'outro'}.end`, { node });
  332. if (!program.b && !program.invalidated) {
  333. program.group.callbacks.push(() => {
  334. program.callback();
  335. if (obj.css) transitionManager.deleteRule(node, program.name);
  336. });
  337. if (--program.group.remaining === 0) {
  338. program.group.callbacks.forEach(run);
  339. }
  340. } else {
  341. if (obj.css) transitionManager.deleteRule(node, program.name);
  342. }
  343. this.running = !!this.pending;
  344. },
  345. abort(reset) {
  346. if (this.program) {
  347. if (reset && obj.tick) obj.tick(1, 0);
  348. if (obj.css) transitionManager.deleteRule(node, this.program.name);
  349. this.program = this.pending = null;
  350. this.running = false;
  351. }
  352. },
  353. invalidate() {
  354. if (this.program) {
  355. this.program.invalidated = true;
  356. }
  357. }
  358. };
  359. }
  360. let outros = {};
  361. function groupOutros() {
  362. outros.current = {
  363. remaining: 0,
  364. callbacks: []
  365. };
  366. }
  367. var transitionManager = {
  368. running: false,
  369. transitions: [],
  370. bound: null,
  371. stylesheet: null,
  372. activeRules: {},
  373. promise: null,
  374. add(transition) {
  375. this.transitions.push(transition);
  376. if (!this.running) {
  377. this.running = true;
  378. requestAnimationFrame(this.bound || (this.bound = this.next.bind(this)));
  379. }
  380. },
  381. addRule(rule, name) {
  382. if (!this.stylesheet) {
  383. const style = createElement('style');
  384. document.head.appendChild(style);
  385. transitionManager.stylesheet = style.sheet;
  386. }
  387. if (!this.activeRules[name]) {
  388. this.activeRules[name] = true;
  389. this.stylesheet.insertRule(`@keyframes ${name} ${rule}`, this.stylesheet.cssRules.length);
  390. }
  391. },
  392. next() {
  393. this.running = false;
  394. const now = window.performance.now();
  395. let i = this.transitions.length;
  396. while (i--) {
  397. const transition = this.transitions[i];
  398. if (transition.program && now >= transition.program.end) {
  399. transition.done();
  400. }
  401. if (transition.pending && now >= transition.pending.start) {
  402. transition.start(transition.pending);
  403. }
  404. if (transition.running) {
  405. transition.update(now);
  406. this.running = true;
  407. } else if (!transition.pending) {
  408. this.transitions.splice(i, 1);
  409. }
  410. }
  411. if (this.running) {
  412. requestAnimationFrame(this.bound);
  413. } else if (this.stylesheet) {
  414. let i = this.stylesheet.cssRules.length;
  415. while (i--) this.stylesheet.deleteRule(i);
  416. this.activeRules = {};
  417. }
  418. },
  419. deleteRule(node, name) {
  420. node.style.animation = node.style.animation
  421. .split(', ')
  422. .filter(anim => anim && anim.indexOf(name) === -1)
  423. .join(', ');
  424. },
  425. wait() {
  426. if (!transitionManager.promise) {
  427. transitionManager.promise = Promise.resolve();
  428. transitionManager.promise.then(() => {
  429. transitionManager.promise = null;
  430. });
  431. }
  432. return transitionManager.promise;
  433. }
  434. };
  435. function wrapAnimation(node, from, fn, params) {
  436. if (!from) return;
  437. const to = node.getBoundingClientRect();
  438. if (from.left === to.left && from.right === to.right && from.top === to.top && from.bottom === to.bottom) return;
  439. const info = fn(node, { from, to }, params);
  440. const duration = 'duration' in info ? info.duration : 300;
  441. const delay = 'delay' in info ? info.delay : 0;
  442. const ease = info.easing || linear;
  443. const start = window.performance.now() + delay;
  444. const end = start + duration;
  445. const program = {
  446. a: 0,
  447. t: 0,
  448. b: 1,
  449. delta: 1,
  450. duration,
  451. start,
  452. end
  453. };
  454. const cssText = node.style.cssText;
  455. const animation = {
  456. pending: delay ? program : null,
  457. program: delay ? null : program,
  458. running: true,
  459. start() {
  460. if (info.css) {
  461. if (delay) node.style.cssText = cssText;
  462. const rule = generateRule(program, ease, info.css);
  463. program.name = `__svelte_${hash(rule)}`;
  464. transitionManager.addRule(rule, program.name);
  465. node.style.animation = (node.style.animation || '')
  466. .split(', ')
  467. .filter(anim => anim && (program.delta < 0 || !/__svelte/.test(anim)))
  468. .concat(`${program.name} ${program.duration}ms linear 1 forwards`)
  469. .join(', ');
  470. }
  471. animation.program = program;
  472. animation.pending = null;
  473. },
  474. update: now => {
  475. const p = now - program.start;
  476. const t = program.a + program.delta * ease(p / program.duration);
  477. if (info.tick) info.tick(t, 1 - t);
  478. },
  479. done() {
  480. if (info.tick) info.tick(1, 0);
  481. animation.stop();
  482. },
  483. stop() {
  484. if (info.css) transitionManager.deleteRule(node, program.name);
  485. animation.running = false;
  486. }
  487. };
  488. transitionManager.add(animation);
  489. if (info.tick) info.tick(0, 1);
  490. if (delay) {
  491. if (info.css) node.style.cssText += info.css(0, 1);
  492. } else {
  493. animation.start();
  494. }
  495. return animation;
  496. }
  497. function fixPosition(node) {
  498. const style = getComputedStyle(node);
  499. if (style.position !== 'absolute' && style.position !== 'fixed') {
  500. const { width, height } = style;
  501. const a = node.getBoundingClientRect();
  502. node.style.position = 'absolute';
  503. node.style.width = width;
  504. node.style.height = height;
  505. const b = node.getBoundingClientRect();
  506. if (a.left !== b.left || a.top !== b.top) {
  507. const style = getComputedStyle(node);
  508. const transform = style.transform === 'none' ? '' : style.transform;
  509. node.style.transform = `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`;
  510. }
  511. }
  512. }
  513. function handlePromise(promise, info) {
  514. var token = info.token = {};
  515. function update(type, index, key, value) {
  516. if (info.token !== token) return;
  517. info.resolved = key && { [key]: value };
  518. const child_ctx = assign(assign({}, info.ctx), info.resolved);
  519. const block = type && (info.current = type)(info.component, child_ctx);
  520. if (info.block) {
  521. if (info.blocks) {
  522. info.blocks.forEach((block, i) => {
  523. if (i !== index && block) {
  524. groupOutros();
  525. block.o(() => {
  526. block.d(1);
  527. info.blocks[i] = null;
  528. });
  529. }
  530. });
  531. } else {
  532. info.block.d(1);
  533. }
  534. block.c();
  535. block[block.i ? 'i' : 'm'](info.mount(), info.anchor);
  536. info.component.root.set({}); // flush any handlers that were created
  537. }
  538. info.block = block;
  539. if (info.blocks) info.blocks[index] = block;
  540. }
  541. if (isPromise(promise)) {
  542. promise.then(value => {
  543. update(info.then, 1, info.value, value);
  544. }, error => {
  545. update(info.catch, 2, info.error, error);
  546. });
  547. // if we previously had a then/catch block, destroy it
  548. if (info.current !== info.pending) {
  549. update(info.pending, 0);
  550. return true;
  551. }
  552. } else {
  553. if (info.current !== info.then) {
  554. update(info.then, 1, info.value, promise);
  555. return true;
  556. }
  557. info.resolved = { [info.value]: promise };
  558. }
  559. }
  560. function destroyBlock(block, lookup) {
  561. block.d(1);
  562. lookup[block.key] = null;
  563. }
  564. function outroAndDestroyBlock(block, lookup) {
  565. block.o(function() {
  566. destroyBlock(block, lookup);
  567. });
  568. }
  569. function fixAndOutroAndDestroyBlock(block, lookup) {
  570. block.f();
  571. outroAndDestroyBlock(block, lookup);
  572. }
  573. function updateKeyedEach(old_blocks, component, changed, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block, intro_method, next, get_context) {
  574. var o = old_blocks.length;
  575. var n = list.length;
  576. var i = o;
  577. var old_indexes = {};
  578. while (i--) old_indexes[old_blocks[i].key] = i;
  579. var new_blocks = [];
  580. var new_lookup = {};
  581. var deltas = {};
  582. var i = n;
  583. while (i--) {
  584. var child_ctx = get_context(ctx, list, i);
  585. var key = get_key(child_ctx);
  586. var block = lookup[key];
  587. if (!block) {
  588. block = create_each_block(component, key, child_ctx);
  589. block.c();
  590. } else if (dynamic) {
  591. block.p(changed, child_ctx);
  592. }
  593. new_blocks[i] = new_lookup[key] = block;
  594. if (key in old_indexes) deltas[key] = Math.abs(i - old_indexes[key]);
  595. }
  596. var will_move = {};
  597. var did_move = {};
  598. function insert(block) {
  599. block[intro_method](node, next);
  600. lookup[block.key] = block;
  601. next = block.first;
  602. n--;
  603. }
  604. while (o && n) {
  605. var new_block = new_blocks[n - 1];
  606. var old_block = old_blocks[o - 1];
  607. var new_key = new_block.key;
  608. var old_key = old_block.key;
  609. if (new_block === old_block) {
  610. // do nothing
  611. next = new_block.first;
  612. o--;
  613. n--;
  614. }
  615. else if (!new_lookup[old_key]) {
  616. // remove old block
  617. destroy(old_block, lookup);
  618. o--;
  619. }
  620. else if (!lookup[new_key] || will_move[new_key]) {
  621. insert(new_block);
  622. }
  623. else if (did_move[old_key]) {
  624. o--;
  625. } else if (deltas[new_key] > deltas[old_key]) {
  626. did_move[new_key] = true;
  627. insert(new_block);
  628. } else {
  629. will_move[old_key] = true;
  630. o--;
  631. }
  632. }
  633. while (o--) {
  634. var old_block = old_blocks[o];
  635. if (!new_lookup[old_block.key]) destroy(old_block, lookup);
  636. }
  637. while (n) insert(new_blocks[n - 1]);
  638. return new_blocks;
  639. }
  640. function measure(blocks) {
  641. const rects = {};
  642. let i = blocks.length;
  643. while (i--) rects[blocks[i].key] = blocks[i].node.getBoundingClientRect();
  644. return rects;
  645. }
  646. function animate(blocks, rects, fn, params) {
  647. let i = blocks.length;
  648. while (i--) {
  649. const block = blocks[i];
  650. const from = rects[block.key];
  651. if (!from) continue;
  652. const to = block.node.getBoundingClientRect();
  653. if (from.left === to.left && from.right === to.right && from.top === to.top && from.bottom === to.bottom) continue;
  654. }
  655. }
  656. function getSpreadUpdate(levels, updates) {
  657. var update = {};
  658. var to_null_out = {};
  659. var accounted_for = {};
  660. var i = levels.length;
  661. while (i--) {
  662. var o = levels[i];
  663. var n = updates[i];
  664. if (n) {
  665. for (var key in o) {
  666. if (!(key in n)) to_null_out[key] = 1;
  667. }
  668. for (var key in n) {
  669. if (!accounted_for[key]) {
  670. update[key] = n[key];
  671. accounted_for[key] = 1;
  672. }
  673. }
  674. levels[i] = n;
  675. } else {
  676. for (var key in o) {
  677. accounted_for[key] = 1;
  678. }
  679. }
  680. }
  681. for (var key in to_null_out) {
  682. if (!(key in update)) update[key] = undefined;
  683. }
  684. return update;
  685. }
  686. // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
  687. // https://infra.spec.whatwg.org/#noncharacter
  688. const invalidAttributeNameCharacter = /[\s'">\/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u;
  689. function spread(args) {
  690. const attributes = Object.assign({}, ...args);
  691. let str = '';
  692. Object.keys(attributes).forEach(name => {
  693. if (invalidAttributeNameCharacter.test(name)) return;
  694. const value = attributes[name];
  695. if (value === undefined) return;
  696. if (value === true) str += " " + name;
  697. const escaped = String(value)
  698. .replace(/"/g, '&#34;')
  699. .replace(/'/g, '&#39;');
  700. str += " " + name + "=" + JSON.stringify(escaped);
  701. });
  702. return str;
  703. }
  704. const escaped = {
  705. '"': '&quot;',
  706. "'": '&#39;',
  707. '&': '&amp;',
  708. '<': '&lt;',
  709. '>': '&gt;'
  710. };
  711. function escape(html) {
  712. return String(html).replace(/["'&<>]/g, match => escaped[match]);
  713. }
  714. function each(items, assign, fn) {
  715. let str = '';
  716. for (let i = 0; i < items.length; i += 1) {
  717. str += fn(assign(items[i], i));
  718. }
  719. return str;
  720. }
  721. const missingComponent = {
  722. _render: () => ''
  723. };
  724. function validateSsrComponent(component, name) {
  725. if (!component || !component._render) {
  726. if (name === 'svelte:component') name += ' this={...}';
  727. throw new Error(`<${name}> is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules`);
  728. }
  729. return component;
  730. }
  731. function debug(file, line, column, values) {
  732. console.log(`{@debug} ${file ? file + ' ' : ''}(${line}:${column})`);
  733. console.log(values);
  734. return '';
  735. }
  736. function blankObject() {
  737. return Object.create(null);
  738. }
  739. function destroy(detach) {
  740. this.destroy = noop;
  741. this.fire('destroy');
  742. this.set = noop;
  743. this._fragment.d(detach !== false);
  744. this._fragment = null;
  745. this._state = {};
  746. }
  747. function destroyDev(detach) {
  748. destroy.call(this, detach);
  749. this.destroy = function() {
  750. console.warn('Component was already destroyed');
  751. };
  752. }
  753. function _differs(a, b) {
  754. return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
  755. }
  756. function _differsImmutable(a, b) {
  757. return a != a ? b == b : a !== b;
  758. }
  759. function fire(eventName, data) {
  760. var handlers =
  761. eventName in this._handlers && this._handlers[eventName].slice();
  762. if (!handlers) return;
  763. for (var i = 0; i < handlers.length; i += 1) {
  764. var handler = handlers[i];
  765. if (!handler.__calling) {
  766. try {
  767. handler.__calling = true;
  768. handler.call(this, data);
  769. } finally {
  770. handler.__calling = false;
  771. }
  772. }
  773. }
  774. }
  775. function flush(component) {
  776. component._lock = true;
  777. callAll(component._beforecreate);
  778. callAll(component._oncreate);
  779. callAll(component._aftercreate);
  780. component._lock = false;
  781. }
  782. function get() {
  783. return this._state;
  784. }
  785. function init(component, options) {
  786. component._handlers = blankObject();
  787. component._slots = blankObject();
  788. component._bind = options._bind;
  789. component._staged = {};
  790. component.options = options;
  791. component.root = options.root || component;
  792. component.store = options.store || component.root.store;
  793. if (!options.root) {
  794. component._beforecreate = [];
  795. component._oncreate = [];
  796. component._aftercreate = [];
  797. }
  798. }
  799. function on(eventName, handler) {
  800. var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
  801. handlers.push(handler);
  802. return {
  803. cancel: function() {
  804. var index = handlers.indexOf(handler);
  805. if (~index) handlers.splice(index, 1);
  806. }
  807. };
  808. }
  809. function set(newState) {
  810. this._set(assign({}, newState));
  811. if (this.root._lock) return;
  812. flush(this.root);
  813. }
  814. function _set(newState) {
  815. var oldState = this._state,
  816. changed = {},
  817. dirty = false;
  818. newState = assign(this._staged, newState);
  819. this._staged = {};
  820. for (var key in newState) {
  821. if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
  822. }
  823. if (!dirty) return;
  824. this._state = assign(assign({}, oldState), newState);
  825. this._recompute(changed, this._state);
  826. if (this._bind) this._bind(changed, this._state);
  827. if (this._fragment) {
  828. this.fire("state", { changed: changed, current: this._state, previous: oldState });
  829. this._fragment.p(changed, this._state);
  830. this.fire("update", { changed: changed, current: this._state, previous: oldState });
  831. }
  832. }
  833. function _stage(newState) {
  834. assign(this._staged, newState);
  835. }
  836. function setDev(newState) {
  837. if (typeof newState !== 'object') {
  838. throw new Error(
  839. this._debugName + '.set was called without an object of data key-values to update.'
  840. );
  841. }
  842. this._checkReadOnly(newState);
  843. set.call(this, newState);
  844. }
  845. function callAll(fns) {
  846. while (fns && fns.length) fns.shift()();
  847. }
  848. function _mount(target, anchor) {
  849. this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
  850. }
  851. var PENDING = {};
  852. var SUCCESS = {};
  853. var FAILURE = {};
  854. function removeFromStore() {
  855. this.store._remove(this);
  856. }
  857. var proto = {
  858. destroy,
  859. get,
  860. fire,
  861. on,
  862. set,
  863. _recompute: noop,
  864. _set,
  865. _stage,
  866. _mount,
  867. _differs
  868. };
  869. var protoDev = {
  870. destroy: destroyDev,
  871. get,
  872. fire,
  873. on,
  874. set: setDev,
  875. _recompute: noop,
  876. _set,
  877. _stage,
  878. _mount,
  879. _differs
  880. };
  881. export { blankObject, destroy, destroyDev, _differs, _differsImmutable, fire, flush, get, init, on, set, _set, _stage, setDev, callAll, _mount, PENDING, SUCCESS, FAILURE, removeFromStore, proto, protoDev, wrapAnimation, fixPosition, handlePromise, append, insert, detachNode, detachBetween, detachBefore, detachAfter, reinsertBetween, reinsertChildren, reinsertAfter, reinsertBefore, destroyEach, createFragment, createElement, createSvgElement, createText, createComment, addListener, removeListener, setAttribute, setAttributes, setCustomElementData, setXlinkAttribute, getBindingGroupValue, toNumber, timeRangesToArray, children, claimElement, claimText, setData, setInputType, setStyle, selectOption, selectOptions, selectValue, selectMultipleValue, addResizeListener, toggleClass, destroyBlock, outroAndDestroyBlock, fixAndOutroAndDestroyBlock, updateKeyedEach, measure, animate, getSpreadUpdate, invalidAttributeNameCharacter, spread, escaped, escape, each, missingComponent, validateSsrComponent, debug, linear, generateRule, hash, wrapTransition, outros, groupOutros, transitionManager, noop, assign, assignTrue, isPromise, callAfter, addLoc, exclude, run };