efront 3.25.8 → 3.25.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  function inertia(gun) {
2
- var _decreased = 0, spd = new Speed;
2
+ var spd = new Speed;
3
+ var animateIndex = 0;
3
4
  var lastTime = 0;
4
5
  var _decrease = function () {
5
6
  lastTime = Speed.now() - 1;
@@ -9,7 +10,7 @@ function inertia(gun) {
9
10
  if (
10
11
  decrease instanceof Function
11
12
  ) {
12
- if (!spd.length || _decreased > 0 && spd.filter(a => a !== 0).length === 0) return;
13
+ if (!spd.length) return;
13
14
  var id = smooth_timer;
14
15
  var now = Speed.now();
15
16
  var res = decrease(now - lastTime, spd);
@@ -17,6 +18,7 @@ function inertia(gun) {
17
18
  if (smooth_timer !== id) return;
18
19
  if (res === false || isEmpty(res)) {
19
20
  spd.unset();
21
+ animateIndex = 0;
20
22
  return;
21
23
  }
22
24
  smooth_timer = requestAnimationFrame(_decrease0);
@@ -24,24 +26,21 @@ function inertia(gun) {
24
26
  };
25
27
  var _cancel = function () {
26
28
  cancelAnimationFrame(smooth_timer);
27
- _decreased = 0;
28
29
  decrease = null;
29
30
  }
30
31
  var smooth = function () {
31
32
  var args = spd.read();
32
- if (decrease && args.filter(a => Math.abs(a) > 2).length === 0) {
33
- _decrease();
34
- return;
35
- }
36
- if (!decrease && args.filter(a => Math.abs(a) > .5).length === 0) {
37
- spd.reset();
38
- return;
39
- }
40
33
  var id = smooth_timer;
41
34
  var res = gun.apply(that, args);
42
35
  if (id !== smooth_timer) return;
43
36
  if (false === res) {
44
37
  spd.reset();
38
+ animateIndex = 2;
39
+ smooth_timer = requestAnimationFrame(_decrease);
40
+ return;
41
+ }
42
+ if (decrease && args.filter(a => Math.abs(a) > 1).length === 0) {
43
+ animateIndex = 2;
45
44
  smooth_timer = requestAnimationFrame(_decrease);
46
45
  return;
47
46
  }
@@ -49,6 +48,7 @@ function inertia(gun) {
49
48
  };
50
49
  var spd, smooth_timer, that, decrease;
51
50
  var train = function () {
51
+ animateIndex = 1;
52
52
  _cancel();
53
53
  var args = [].slice.call(arguments, 0, arguments.length);
54
54
  spd.write(args);
@@ -58,7 +58,12 @@ function inertia(gun) {
58
58
  train.smooth = function (d) {
59
59
  _cancel();
60
60
  decrease = d;
61
- smooth_timer = requestAnimationFrame(smooth);
61
+ if (animateIndex === 1) {
62
+ smooth_timer = requestAnimationFrame(smooth);
63
+ }
64
+ else if (animateIndex === 2) {
65
+ smooth_timer = requestAnimationFrame(_decrease);
66
+ }
62
67
  };
63
68
  train.reset = function () {
64
69
  _cancel();
@@ -1,3 +1,4 @@
1
+ var window = this;
1
2
  var cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame || function (id) {
2
3
  return clearTimeout(id);
3
4
  };
@@ -2,25 +2,35 @@
2
2
  // 2.如果time小于0,传入的函数会立即执行,并忽略-time内的连续调用,time时间后触发最后一次调用
3
3
  // 如果time传false或0 使用requestAnimationFrame代替setTimeout按第1步执行
4
4
  // 如果time传null或undefined或NaN使用requestAnimationFrame代替setTimeout按第2步执行
5
- function lazy(run, time) {
5
+
6
+ /**
7
+ * @param {Function} run 主程序
8
+ * @param {number|undefined} time 间隔
9
+ * @param {any} ret 指定调用结束后返回的结果
10
+ */
11
+
12
+ function lazy(run, time, ret) {
6
13
  var wait = +time ? setTimeout : requestAnimationFrame;
7
- var ing, args, that;
14
+ var quit = wait === setTimeout ? clearTimeout : cancelAnimationFrame;
15
+ var ing, args, that, id;
8
16
  var hire = function () {
17
+ if (!ing) return;
9
18
  if (time >= 0) {
10
- if (ing === true) ing = wait(fire, +time / 2);
11
- else wait(fire, +time / 2), ing = -2;
19
+ if (ing === true) id = ing = wait(fire, +time / 2);
20
+ else id = wait(fire, +time / 2), ing = -2;
12
21
  }
13
22
  else {
14
- wait(fire, -time);
23
+ id = wait(fire, -time);
15
24
  }
16
25
  };
17
26
  var fire = function () {
27
+ if (!ing) return;
18
28
  if (time >= 0) {
19
29
  if (ing === true) {
20
- ing = wait(fire, +time / 2);
30
+ id = ing = wait(fire, +time / 2);
21
31
  }
22
32
  else if (ing > 0) {
23
- wait(fire, +time / 2);
33
+ id = wait(fire, +time / 2);
24
34
  ing = -1;
25
35
  }
26
36
  else if (ing === -1) {
@@ -36,27 +46,34 @@ function lazy(run, time) {
36
46
  if (ing === true) {
37
47
  ing = run.apply(that, args);
38
48
  if (ing instanceof Promise) ing.then(hire, hire);
39
- else ing = wait(fire, -time);
49
+ else id = ing = wait(fire, -time);
40
50
  } else {
41
51
  ing = false;
42
52
  }
43
53
  }
44
54
  };
45
- return function () {
55
+ var exec = function () {
46
56
  args = arguments;
47
57
  that = this;
48
58
  if (ing) return ing = true;
49
59
  if (time >= 0) {
50
- ing = wait(fire, +time);
60
+ id = ing = wait(fire, +time);
51
61
  }
52
62
  else if (time < 0) {
53
63
  ing = run.apply(that, args);
54
64
  if (ing instanceof Promise) ing.then(hire, hire);
55
- else ing = wait(fire, -time);
65
+ else id = ing = wait(fire, -time);
56
66
  }
57
67
  else {
58
- ing = true; wait(fire);
68
+ ing = true; id = wait(fire);
59
69
  }
70
+ return ret;
60
71
  };
72
+ exec.cancel = function () {
73
+ quit(id);
74
+ ing = false;
75
+ id = 0;
76
+ };
77
+ return exec;
61
78
  }
62
79
  module.exports = lazy;
@@ -169,7 +169,7 @@ var killCircle = function () {
169
169
  if (k.slice(0, keyprefix.length) === keyprefix && loadedModules[k] instanceof Array) {
170
170
  var key = k.slice(keyprefix.length);
171
171
  var args = loadedModules[k].args;
172
- if (loadedModules[k] instanceof Array) continue;
172
+ if (!(loadedModules[k] instanceof Array)) continue;
173
173
  args.forEach(arg => {
174
174
  if (!penddings[arg]) {
175
175
  penddings[arg] = [];
@@ -69,7 +69,7 @@ var power = function (source, search) {
69
69
  var pp = 0, ap = 0;
70
70
  var p = match_text.length;
71
71
  p = match_text.length;
72
- if (match_start2) p += .1 / match_start2;
72
+ if (match_start2) p += .1 / match_start2 - .2;
73
73
  if (match_text_pre.length > 1) {
74
74
  [pp, match_text_pre] = power(match_text_pre, search);
75
75
  }
@@ -0,0 +1,7 @@
1
+ var test = function (t1, t2) {
2
+ var a = mark.power(t1, t2)
3
+ console.log(t1, t2, a);
4
+ }
5
+ test("11234", '1234');
6
+ test("1234", '1234');
7
+
@@ -11,8 +11,8 @@ function createSeek(express) {
11
11
  return dist;
12
12
  }
13
13
  function main(express) {
14
- if (!/\?\s*\.(?=[^\d])|\?$/.test(express)) return express;
15
- var reg = /\\[\s\S]|\?\s*(\.(?!\d)|\s*$)|[\:\,\+\=\-\!%\^\|\/\&\*\!\;\?\>\<~\{\}\[\]\(\)'"`\s]/g;
14
+ if (!/\?\s*\.(?=[^\d])|\?\s*[\?\]\}\)\:\,=|%&;\>\<]|\?\s*$/.test(express)) return express;
15
+ var reg = /\\[\s\S]|\?\s*(\.(?!\d)|$|(?=[\?\]\}\)\:\,=|%&;\>\<\*\/]))|[\:\,\+\=\-\!%\^\|\/\&\*\!\;\?\>\<~\{\}\[\]\(\)'"`\s]/g;
16
16
  var cache = [], queue = [];
17
17
  var exp = [];
18
18
  var instr = false;
@@ -71,7 +71,7 @@ function main(express) {
71
71
  if (instr) {
72
72
  continue;
73
73
  }
74
- if (/['"`\/\s]/.test(m)) {
74
+ if (/['"`\/]/.test(m)) {
75
75
  isstr = true;
76
76
  index++;
77
77
  }
@@ -27,14 +27,17 @@
27
27
  if (/,/.test(k)) {
28
28
  var [k, ...roles] = k.split(',');
29
29
  }
30
- if (!icon && /\s+|\./.test(k)) {
30
+ if (!icon && /(?!\.)\.(?=[\w\-])/.test(k)) {
31
+ icon = k.slice(k.indexOf(/(?!\.)\.(?=[\w\-])/));
32
+ }
33
+ if (!icon && /\s+/.test(k)) {
31
34
  [icon] = k.split(/\s+/);
32
35
  k = k.slice(icon.length).trim();
33
36
  }
34
37
  if (!name) name = k;
35
38
  var item = {};
36
39
  if (icon) item.icon = icon.replace(/\./g, ' ');
37
- if (name) item.name = name;
40
+ item.name = name;
38
41
  if (hotkey) {
39
42
  hotkey = hotkey.split(',');
40
43
  for (var k of hotkey) {
@@ -1,8 +1,12 @@
1
1
  var keyMap = {};
2
- on("keydown")(window, function (event) {
2
+ /**
3
+ * @param {KeyboardEvent} event
4
+ */
5
+ var keydownhandler = function (event) {
6
+ if (event.defaultPrevented) return;
3
7
  var { which } = event;
4
8
  switch (event.which) {
5
- case 18:
9
+ case 18: // alt
6
10
  event.preventDefault();
7
11
  break;
8
12
  default:
@@ -16,12 +20,15 @@ on("keydown")(window, function (event) {
16
20
  if (elem) {
17
21
  var parent = elem.parentNode;
18
22
  if (event.altKey || parent === document.activeElement || parent.ispop) {
19
- event.preventDefault();
20
- elem.click();
23
+ if (!(event.metaKey || event.shiftKey || event.ctrlKey)) {
24
+ event.preventDefault();
25
+ elem.click();
26
+ }
21
27
  }
22
28
  }
23
29
  }
24
- });
30
+ }
31
+ on("keydown")(window, keydownhandler);
25
32
  var bindAccesskey = function (btn, k) {
26
33
  if (!keyMap[k]) keyMap[k] = [];
27
34
  removeFromList(keyMap[k], btn);
@@ -42,6 +49,7 @@ var getKeyFromText = function (btn) {
42
49
  return accesskey.toUpperCase();
43
50
  }
44
51
  function main(elem, key = getKeyFromText(elem)) {
52
+ if (!key) return;
45
53
  bindAccesskey(elem, key);
46
54
  return elem;
47
55
  }
@@ -1,5 +1,6 @@
1
1
  var _label = createElement("span");
2
2
  var track = createElement(div);
3
+ var onmouseenter = on("mouseenter");
3
4
  track.className = "track";
4
5
  _label.className = "label";
5
6
 
@@ -107,7 +108,7 @@ function button(texter, type) {
107
108
  button = button || createElement(btn, tracker, _texter);
108
109
  bindAccesskey(button);
109
110
  onremove(button, resetall);
110
- onmouseover(button, hover);
111
+ onmouseenter(button, hover);
111
112
  onmouseleave(button, mouseleave);
112
113
  onmousemove(button, mousemove);
113
114
  onmousedown(button, mousedown);
@@ -1,12 +1,16 @@
1
1
 
2
2
  var _slider = createElement(div);
3
+ /**
4
+ * @param {Element} container
5
+ * @param {Element|string} tagName;
6
+ */
3
7
  var getGenerator = function (container, tagName = 'item') {
4
8
  if (!container) return;
5
9
  var scopes = container.$parentScopes || [];
6
10
  if (container.$scope) scopes = scopes.concat(container.$scope);
7
11
  container.$generatorScopes = scopes;
8
12
  if (container.$generator) return container.$generator;
9
- var template = document.createElement(tagName);
13
+ var template = document.createElement(container.tagName);
10
14
  var templates = [].concat.apply([], container.childNodes).filter(a => {
11
15
  if (a.hasAttribute('insert')) {
12
16
  return false;
@@ -22,22 +26,34 @@ var getGenerator = function (container, tagName = 'item') {
22
26
  container.paddingCount = paddingCount;
23
27
  }
24
28
  appendChild(template, templates);
29
+ if (templates.length) container.$template = template;
25
30
  container.insertBefore = _slider.insertBefore;
26
31
  container.appendChild = _slider.appendChild;
32
+ /**
33
+ * @param {number} index;
34
+ * @param {Object} com;
35
+ * @param {Element} element;
36
+ */
27
37
  return container.$generator = function (index, com, element) {
28
38
  if (com === undefined) {
29
39
  if (!container.src || index >= container.src.length) return;
30
40
  com = container.src[index];
31
41
  }
32
42
  if (com === undefined) return;
33
- if (!isNode(element)) {
43
+ var needSetAttr = isElement(tagName);
44
+ if (isNode(element));
45
+ else if (!template.childNodes.length) {
46
+ element = needSetAttr ? tagName.cloneNode(true) : document.createElement(tagName);
47
+ needSetAttr = false;
48
+ }
49
+ else {
34
50
  var template1 = template.cloneNode(true);
35
- if (!template1.childNodes.length) {
36
- element = template1;
37
- }
38
- else {
39
- element = template1.childNodes[0];
40
- if (template1.childNodes.length > 1) element.with = [].concat.apply([], template1.childNodes).slice(1);
51
+ element = template1.childNodes[0];
52
+ if (template1.childNodes.length > 1) element.with = [].concat.apply([], template1.childNodes).slice(1);
53
+ }
54
+ if (needSetAttr) {
55
+ for (var a of tagName.attributes) {
56
+ element.setAttribute(a.name, a.value);
41
57
  }
42
58
  }
43
59
  var scopes = container.$generatorScopes;
@@ -1,4 +1,5 @@
1
1
  var hasOwnProperty = {}.hasOwnProperty;
2
+ var keys = ["name", 'title', 'label', 'value'];
2
3
  function getName(o) {
3
4
  var name;
4
5
  if (isEmpty(o)) return '';
@@ -7,11 +8,12 @@ function getName(o) {
7
8
  name = o.toString();
8
9
  if (!isEmpty(name)) return String(name);
9
10
  }
10
- if (!isEmpty(o.name)) return String(o.name);
11
- if (!isEmpty(o.title)) return String(o.title);
12
- if (!isEmpty(o.label)) return String(o.label);
13
- if (!isEmpty(o.value)) return String(o.value);
11
+ for (var k of keys) {
12
+ if (!hasOwnProperty.call(o, k)) continue;
13
+ if (!isEmpty(o[k])) return String(o[k]);
14
+ if (isString(o[k])) name = o[k];
15
+ }
14
16
  if (hasOwnProperty.call(o, 'valueOf')) name = o.valueOf();
15
- if (!isEmpty(name)) return String(name);
17
+ if (isString(name)) return name;
16
18
  return String(o);
17
19
  }
@@ -1,7 +1,8 @@
1
1
  var document = this.document;
2
2
 
3
3
  function innerHeight() {
4
- return document.documentElement.clientHeight || document.body && document.body.clientHeight;
4
+ if (isFinite(window.innerHeight)) return window.innerHeight;
5
+ return document.documentElement.offsetHeight || document.body && document.body.offsetHeight;
5
6
  }
6
7
  innerHeight.toString = function () {
7
8
  return this().toString();
@@ -1,6 +1,7 @@
1
1
  var document = this.document;
2
2
  function innerWidth() {
3
- return document.documentElement.clientWidth || document.body && document.body.clientWidth;
3
+ if (isFinite(window.innerWidth)) return window.innerWidth;
4
+ return document.documentElement.offsetWidth || document.body && document.body.offsetWidth;
4
5
  }
5
6
  innerWidth.toString = function () {
6
7
  return this().toString();
@@ -2,9 +2,12 @@
2
2
  function ylist(container, generator, $Y) {
3
3
  const cache_height = 2000;
4
4
  var restHeight = cache_height;
5
+ /**
6
+ * @type {HTMLElement}
7
+ */
5
8
  var list = container || div();
6
9
  list.autoFix = true;
7
- var saved_itemIndex;
10
+ var saved_itemIndex = 0;
8
11
  addClass(list, 'list-' + $Y.toLowerCase());
9
12
  if (!list.renders) {
10
13
  list.renders = [];
@@ -15,7 +18,11 @@ function ylist(container, generator, $Y) {
15
18
  if (a !== void 0) scrollTo(a);
16
19
  });
17
20
  var getNodeTarget = function (node) {
18
- if (node.nodeType === 8 && node.template) return node.template;
21
+ if (node.nodeType === 8 && node.$template) {
22
+ var t = node.$template;
23
+ if (!isFinite(t.index)) t.index = node.index;
24
+ return node.$template;
25
+ }
19
26
  return node;
20
27
  };
21
28
  //取底部元素
@@ -109,7 +116,9 @@ function ylist(container, generator, $Y) {
109
116
  for (var cx = 0, dx = children.length; cx < dx; cx++) {
110
117
  var child = children[cx];
111
118
  if (isFinite(child.index) && child.index !== null) {
112
- map[child.index] = child;
119
+ if (!map[child.index] || child.$template === map[child.index]) {
120
+ map[child.index] = child;
121
+ }
113
122
  }
114
123
  }
115
124
  return map;
@@ -203,10 +212,12 @@ function ylist(container, generator, $Y) {
203
212
  return y;
204
213
  }, false);
205
214
  var rebuild = function () {
206
- if (!/^(?:auto|scroll)$/i.test(getComputedStyle(list).overflowY)) return;
207
215
  runbuild();
208
216
  };
209
- on("scroll")(list, rebuild);
217
+ oncemount(list, function () {
218
+ if (!/^(?:auto|scroll)$/i.test(getComputedStyle(list).overflowY)) return;
219
+ on("scroll")(list, rebuild);
220
+ });
210
221
  var topinsert = document.createElement('ylist-insert');
211
222
  list.insertBefore(topinsert, list.firstChild);
212
223
  //计算当前高度
@@ -228,17 +239,17 @@ function ylist(container, generator, $Y) {
228
239
  return bottom_element ? bottom_element.nextSibling : null;
229
240
  };
230
241
  var getOffsetHeight = function (element) {
242
+ element = getNodeTarget(element);
231
243
  var temp = element;
232
244
  do {
233
245
  var next = getNextSibling(temp);
234
246
  if (!next) return element.offsetHeight;
235
- temp = next;
247
+ temp = getNodeTarget(next);
236
248
  } while (next.offsetTop === element.offsetTop);
237
249
  return next.offsetTop - element.offsetTop;
238
250
  };
239
251
  var patchBottom = function (deltaY = 0) {
240
252
  var cache_height = list.offsetHeight;
241
-
242
253
  var childrenMap = getChildrenMap();
243
254
  var last_element = getLastElement(1);
244
255
  if (!last_element || !last_element.offsetHeight) return;
@@ -271,7 +282,7 @@ function ylist(container, generator, $Y) {
271
282
  var collection = [];
272
283
  for (var k in childrenMap) {
273
284
  let item = childrenMap[k];
274
- if (item.offsetTop + getOffsetHeight(item) + cache_height < scrollTop) {
285
+ if (getNodeTarget(item).offsetTop + getOffsetHeight(item) + cache_height < scrollTop) {
275
286
  collection.push(item);
276
287
  }
277
288
  }
@@ -283,7 +294,7 @@ function ylist(container, generator, $Y) {
283
294
  item = collection.pop();
284
295
  }
285
296
  var item = collection[collection.length - 1];
286
- if (item) scrollTop -= item.offsetTop + getOffsetHeight(item) - collection[0].offsetTop;
297
+ if (item) scrollTop -= getNodeTarget(item).offsetTop + getOffsetHeight(item) - getNodeTarget(collection[0]).offsetTop;
287
298
  if (paddingCount > 0 && paddingMax > 0 && paddingCount < paddingMax) {
288
299
  let item = collection[collection.length - 1];
289
300
  while (paddingCount > 0) {
@@ -337,6 +348,7 @@ function ylist(container, generator, $Y) {
337
348
  var { clientHeight } = list;
338
349
  while (last_element && last_element.offsetTop > clientHeight + scrollTop + cache_height) {
339
350
  remove(last_element);
351
+ remove(last_element.$comment);
340
352
  last_element = getLastElement(1);
341
353
  }
342
354
  return scrollTop - list.scrollTop;
@@ -364,6 +376,9 @@ function ylist(container, generator, $Y) {
364
376
  }
365
377
  }
366
378
  };
379
+ bind('resize')(list, function () {
380
+ patchBottom(0);
381
+ });
367
382
  list.getLastVisibleElement = getLastVisibleElement;
368
383
  list.$stopY = function (t, spd) {
369
384
  var firstElement = getFirstVisibleElement();
@@ -387,7 +402,7 @@ function ylist(container, generator, $Y) {
387
402
  var target_by = last_y - scrolled_b * lastElement.offsetHeight;
388
403
  }
389
404
  var target_y = Math.abs(target_ty - last_y) > Math.abs(target_by - last_y) ? target_by : target_ty;
390
- var delta = Math.min(calcPixel(60), list.clientHeight >> 2);
405
+ var delta = Math.min(calcPixel(30), list.clientHeight >> 2);
391
406
  var absy = Math.abs(target_y - last_y), y;
392
407
  if (absy >= delta) {
393
408
  return false;
@@ -410,7 +425,8 @@ function ylist(container, generator, $Y) {
410
425
  list.$Height = function () {
411
426
  var elem = getLastElement(2);
412
427
  var listRestHeight = elem ? elem.offsetHeight + elem.offsetTop - list.scrollTop : list.clientHeight;
413
- return currentY() + listRestHeight + restHeight;
428
+ var paddingHeight = elem ? 0 : restHeight;
429
+ return currentY() + listRestHeight + paddingHeight;
414
430
  };
415
431
  list.$Top = function (y) {
416
432
  if (isFinite(y)) {
@@ -442,13 +458,126 @@ function ylist(container, generator, $Y) {
442
458
  list.patchBottom = patchBottom;
443
459
  list.patchTop = patchTop;
444
460
  list.scrollIfNotCover = scrollIfNotCover;
461
+ list.getLastElement = getLastElement;
445
462
  vbox(list, $Y);
446
463
  on("remove")(list, function () {
447
464
  saved_itemIndex = list.index();
448
465
  });
449
466
  onmounted(list, function () {
450
467
  if (isFinite(saved_itemIndex)) list.go(saved_itemIndex);
451
- })
468
+ });
469
+ /**
470
+ * @param {Element|null} focused
471
+ * @param {boolean} animate
472
+ */
473
+ list.setFocus = function (focused, animate) {
474
+ if (focused && (focused.hasAttribute("disabled") || focused.hasAttribute("line"))) return;
475
+ if (!focused) {
476
+ if (list.focused) {
477
+ removeClass(list.focused, 'focus');
478
+ list.focused = null;
479
+ }
480
+ return;
481
+ }
482
+ if (list.focused === focused) return;
483
+ if (list.focused) removeClass(list.focused, 'focus');
484
+ addClass(focused, "focus");
485
+ var scrollTop = list.scrollTop;
486
+ var firstElement = getFirstElement(1);
487
+ var sideheight = 0;
488
+ if (firstElement) {
489
+ sideheight += parseFloat(getComputedStyle(firstElement).paddingTop + firstElement.clientTop);
490
+ sideheight += (firstElement.offsetHeight - sideheight - sideheight) * .3;
491
+ sideheight += parseFloat(getComputedStyle(list).paddingTop);
492
+ }
493
+ if (focused.offsetTop + focused.offsetHeight + sideheight > list.scrollTop + list.clientHeight) {
494
+ scrollTop = focused.offsetTop + focused.offsetHeight + sideheight - list.clientHeight;
495
+ }
496
+ if (focused.offsetTop < list.scrollTop + sideheight) {
497
+ scrollTop = focused.offsetTop - sideheight;
498
+ }
499
+ if (scrollTop !== list.scrollTop) scrollBy(scrollTop - list.scrollTop, animate);
500
+ list.focused = focused;
501
+ };
502
+
503
+ /**
504
+ * @param {number|"up"|"down"|"home"|"end"|"pageup"|"pagedown"}delta
505
+ * @param {boolean} emit
506
+ */
507
+ list.moveFocus = function (delta, emit = true) {
508
+ var focused = list.focused;
509
+ var newIndex = 0, total = 0;
510
+ if (delta === 'up') delta = -1;
511
+ if (delta === 'down') delta = 1;
512
+ if (typeof delta === 'string') {
513
+ switch (delta.toLowerCase()) {
514
+ case "home":
515
+ newIndex = 0;
516
+ delta = 1;
517
+ break;
518
+ case "end":
519
+ var lastElement = getLastElement(1);
520
+ if (!lastElement) return;
521
+ newIndex = lastElement.index;
522
+ delta = -1;
523
+ break;
524
+ case "pageup":
525
+ var firstElement = getFirstVisibleElement();
526
+ if (!firstElement) return;
527
+ newIndex = firstElement.index;
528
+ list.scrollBy(-list.clientHeight + firstElement.offsetHeight);
529
+ var lastElement = getLastVisibleElement();
530
+ if (lastElement.index < newIndex) newIndex = lastElement.index;
531
+ delta = -1;
532
+ break;
533
+ case "pagedown":
534
+ var lastElement = getLastVisibleElement();
535
+ if (!lastElement) return;
536
+ newIndex = lastElement.index;
537
+ list.scrollBy(list.clientHeight - lastElement.offsetHeight);
538
+ var firstElement = getFirstVisibleElement();
539
+ if (firstElement.index > newIndex) newIndex = firstElement.index;
540
+ delta = 1;
541
+ break;
542
+ }
543
+ }
544
+ else if (!focused) {
545
+ var lastElement = getLastElement(1);
546
+ if (!lastElement) return;
547
+ total = lastElement.index + 1;
548
+ if (delta > 0) newIndex = 0;
549
+ else newIndex = total - 1;
550
+ }
551
+ else {
552
+ var newIndex = focused.index + delta;
553
+ var lastElement = getLastElement(1);
554
+ var total = lastElement.index + 1;
555
+ if (newIndex < 0) newIndex = total + newIndex;
556
+ if (newIndex > total - 1) newIndex = newIndex - total;
557
+ }
558
+ var savedIndex = newIndex;
559
+ var e = list.getIndexedElement(newIndex);
560
+ while (e && (e.hasAttribute("disabled") || e.hasAttribute("line"))) {
561
+ if (delta > 0) {
562
+ newIndex++;
563
+ if (newIndex >= total) {
564
+ if (!total) return;
565
+ newIndex = 0;
566
+ }
567
+ } else {
568
+ newIndex--;
569
+ if (newIndex < 0) {
570
+ if (!total) return;
571
+ newIndex = total - 1;
572
+ }
573
+ }
574
+ if (savedIndex === newIndex) return;
575
+ e = list.getIndexedElement(newIndex);
576
+ }
577
+ if (!e) list.setFocus(null);
578
+ else if (emit) list.setFocus(e, true), dispatch(list, 'focused');
579
+ else list.setFocus(e);
580
+ };
452
581
  return list;
453
582
  }
454
583
  var allArgumentsNames = arguments[arguments.length - 1];