efront 3.11.3 → 3.12.2

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.
package/apps/kugou/api.js CHANGED
@@ -2,15 +2,18 @@
2
2
  "https://m.kugou.com/": {
3
3
  "song-info": "get app/i/getSongInfo.php?cmd=playInfo&from=mkugou&hash",
4
4
  "slider-src": "get:[].mod-slider>.swipe-wrap>div .#src=img!src&href=a!href",
5
- "songs-list": "get:[].panel-songslist>li .#hash=!id&.panel-songs-item-name>span!innerText",
6
- "rank-list": "get:[].panel-img-list>li rank/list#href=a!href&=a!href\\rank-info&imgurl=img!_src&name=p|innerText",
7
- "rank-info": "get:[].panel-songslist>li rank/info/:id#src=!id&name=.panel-songs-item-name|innerText&data=.panel-songs-item-download/innerText",
8
- "plist-index": "get:[].panel-img-list>li plist/index#href=a!href&=a!href\\plist-info&imgurl=img!_src&name=.panel-img-content-first|innerText&count=.panel-img-content-sub|innerText",
9
- "plist-info": "get:[].panel-songslist>li plist/list/:id#name=.panel-songs-item-name|innerText&data=.panel-songs-item-download/innerText",
5
+ "songs-list": "get:[].panel-songslist%20li .#hash=!id&.panel-songs-item-name>span!innerText",
6
+ "rank-list": "get:[].panel-img-list%20li rank/list#href=a!href&=a!href\\rank-info&imgurl=img!_src&name=p|innerText",
7
+ "rank-info": "get:[].panel-songslist%20li rank/info/:id#src=!id&name=.panel-songs-item-name|innerText&data=.panel-songs-item-download/innerText",
8
+ "plist-index": "get:[].panel-img-list%20li plist/index#href=a!href&=a!href\\plist-info&imgurl=img!_src&name=.panel-img-content-first|innerText&count=.panel-img-content-sub|innerText",
9
+ "plist-info": "get:[].panel-songslist%20li plist/list/:id#name=.panel-songs-item-name|innerText&data=.panel-songs-item-download/innerText",
10
10
  "search-hot": "get api/v3/search/hot?format=json&plat=0&count=30",
11
11
  "singer-class": "get:[].bd%20li singer/class#href=a!href&=a!href\\singer-list&name=a|innerText&group=?parentNode",
12
- "singer-list": "get:[].singer-img-list>li singer/list/:id#href=a!href&=a!href\\singer-info&imgurl=img!_src&name=p|innerText",
13
- "singer-info": "mget:[].singer-songs-list>li singer/info/:id#hash=!id&singer=.singer-name|innerText&name=.song-name|innerText&data=em/innerText"
12
+ "singer-list": "get:[].singer-img-list>li singer/list/:id#href=a!href&=a!href\\singer-info0&imgurl=img!_src&name=p|innerText",
13
+ "singer-info0": "mget:[].singer-songs-list>li singer/info/:id#hash=!id&singer=.singer-name|innerText&name=.song-name|innerText&data=em/innerText"
14
+ },
15
+ "https://www.kugou.com/": {
16
+ "singer-info": "cget:link[rel]+script yy/singer/home/:id.html",
14
17
  },
15
18
  "http://mobilecdn.kugou.com/": {
16
19
  "search?keyword": "get:data.info api/v3/search/song?format=json&page=1&pagesize=30&showtype=1"
@@ -1,5 +1,5 @@
1
1
  <div class="clusters">
2
- <a -repeat="(c,i) in clusters" ng-class="{current:i===index}" @click="active(i,c)">
2
+ <a -repeat="(c,i) in clusters" ng-class="{current:i===index.index}" @click="active(i,c)">
3
3
  <span -text="c"></span>
4
4
  </a>
5
5
  </div>
@@ -7,13 +7,13 @@ function main() {
7
7
  await this.clusters;
8
8
  this.active();
9
9
  },
10
- index: data.getInstance("index").index || 0,
10
+ index: data.getInstance("index"),
11
11
  clusters: [],
12
12
  filterTime(d) {
13
13
  return ((new Date - d) / 1000 | 0) + "秒";
14
14
  },
15
15
  clients: [],
16
- active(index = this.index) {
16
+ active(index = this.index.index | 0) {
17
17
  data.setInstance('index', { index });
18
18
  var clusters = this.clusters;
19
19
  if (index >= clusters.length) index = clusters.length - 1;
@@ -48,11 +48,13 @@ var parse一二三 = function (a) {
48
48
  };
49
49
  var map甲乙丙 = createMap("甲乙丙丁戊己庚辛壬癸");
50
50
  var map子丑寅 = createMap("子丑寅卯辰巳午未申酉戌亥");
51
+ var map上中下 = createMap("前上中下后");
51
52
 
52
53
  var reg123 = /^(\d+|\d+[\.\d]+\d+)[\s\S]*$/;
53
54
  var reg一二三 = /^([一二三四五六七八九十百千万亿壹贰叁肆伍陆柒捌玖拾佰仟萬零〇]+)[\s\S]*$/;
54
55
  var reg甲乙丙 = /^([甲乙丙丁戊己庚辛壬癸])[\s\S]*$/;
55
56
  var reg子丑寅 = /^([子丑寅卯辰巳午未申酉戌亥])[\s\S]*$/;
57
+ var reg上中下 = /^([前上中下后])[\s\S]*$/;
56
58
  var reg天干地支 = /^([甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥])[\s\S]*$/;
57
59
 
58
60
  var getDelta = function (a, b, reg, parse) {
@@ -85,14 +87,14 @@ var compare = function (a, b) {
85
87
  for (var cx1 = a.length - 1, cx2 = b.length - 1; cx1 >= 0 && cx2 >= 0; cx1--, cx2--) {
86
88
  while (/\s\u00a0/.test(a[cx1])) cx1--;
87
89
  while (/\s\u00a0/.test(b[cx2])) cx2--;
88
- if (a[cx1] !== b[cx2] || a[cx1] in map子丑寅 || a[cx1] in map一二三 || a in power || /^\d$/.test(a[cx1])) break;
90
+ if (a[cx1] !== b[cx2] || a[cx1] in map子丑寅 || a[cx1] in map上中下 || a[cx1] in map一二三 || a in power || /^\d$/.test(a[cx1])) break;
89
91
  }
90
92
  a = a.slice(0, cx1 + 1);
91
93
  b = b.slice(0, cx2 + 1);
92
94
  for (var cx1 = 0, cx2 = 0, dx1 = b.length, dx2 = b.length; cx1 < dx1 && cx2 < dx2; cx1++, cx2++) {
93
95
  while (/[\s\u00a0]/.test(a[cx1])) cx1++;
94
96
  while (/[\s\u00a0]/.test(b[cx2])) cx2++;
95
- if (a[cx1] !== b[cx2] || a[cx1] in map甲乙丙 || a[cx1] in map一二三 || a in power || /^\d/.test(a[cx1])) break;
97
+ if (a[cx1] !== b[cx2] || a[cx1] in map甲乙丙 || a[cx1] in map上中下 || a[cx1] in map一二三 || a in power || /^\d/.test(a[cx1])) break;
96
98
  }
97
99
  if (cx1) a = a.slice(cx1);
98
100
  if (cx2) b = b.slice(cx2);
@@ -108,6 +110,8 @@ var compare = function (a, b) {
108
110
  if (delta) return delta;
109
111
  delta = getDelta(a, b, reg子丑寅, d => map子丑寅[d]);
110
112
  if (delta) return delta;
113
+ delta = getDelta(a, b, reg上中下, d => map上中下[d]);
114
+ if (delta) return delta;
111
115
  return 0;
112
116
  }
113
117
  function sortname(list = this) {
@@ -1,10 +1,24 @@
1
- a => a.map(b => {
2
- var data = {};
3
- if (b.data) extend(data, {
4
- name: b.data.filename.replace(/^[\s\S]*?\s*\-\s*/, ''),
5
- singer: b.data.filename.replace(/\s*\-\s*[\s\S]*?$/, '')
6
- }, b.data);
7
- else extend(data, b);
8
- if (data.hash) data.hash = data.hash.replace(/^songs\_/i, '');
9
- return data;
10
- });
1
+ a => {
2
+ if (isElement(a)) {
3
+ var m = /songsdata\s*=\s*(\[[\s\S]*\])/.exec(a.innerText);
4
+ if (!m) throw new Error("无法加载数据!");
5
+ if (m) a = m[1];
6
+ a = JSON.parse(a);
7
+ console.log(a)
8
+ }
9
+ return a.map(b => {
10
+ var data = {};
11
+ if (b.data) extend(data, {
12
+ name: b.data.filename.replace(/^[\s\S]*?\s*\-\s*/, ''),
13
+ singer: b.data.filename.replace(/\s*\-\s*[\s\S]*?$/, '')
14
+ }, b.data);
15
+ else extend(data, b);
16
+ if (!data.singer) {
17
+ data.singer = data.author_name;
18
+ }
19
+ if (!data.name) data.name = data.audio_name;
20
+ if (data.hash) data.hash = data.hash.replace(/^songs\_/i, '');
21
+ return data;
22
+ });
23
+
24
+ }
@@ -927,6 +927,7 @@ var data = {
927
927
  setSource(sourceid, value) {
928
928
  var rememberWithStorage;
929
929
  if (isObject(sourceid)) {
930
+
930
931
  this.rebuildInstance(dataSourceMap, sourceid);
931
932
  rememberWithStorage = value;
932
933
  } else {
@@ -975,7 +976,7 @@ var data = {
975
976
  if (key === true || key === false || isEmpty(key)) {
976
977
  rememberWithStorage = key;
977
978
  key = null;
978
- var value = instance;
979
+ var value = instance.valueOf();
979
980
  } else {
980
981
  var value = instance[key];
981
982
  }
@@ -24,11 +24,11 @@ var getGenerator = function (container, tagName = 'item') {
24
24
  var scopes = container.$parentScopes || [];
25
25
  if (container.$scope) scopes = scopes.concat(container.$scope);
26
26
  return container.$generator = function (index, com, element) {
27
- if (!com) {
27
+ if (com === undefined) {
28
28
  if (!container.src || index >= container.src.length) return;
29
29
  com = container.src[index];
30
30
  }
31
- if (!com) return;
31
+ if (com === undefined) return;
32
32
  if (!element) {
33
33
  var template1 = template.cloneNode(true);
34
34
  if (!template1.childNodes.length) {
@@ -60,6 +60,28 @@ function ylist(container, generator, $Y) {
60
60
  }
61
61
  return null;
62
62
  };
63
+ var hasCover = function (child) {
64
+ var scrollTop = list.scrollTop;
65
+ if (child.offsetTop + child.offsetHeight < scrollTop || child.offsetTop >= scrollTop + list.clientHeight) return false;
66
+ if (child.offsetTop <= scrollTop && child.offsetTop + child.offsetHeight >= scrollTop + list.clientHeight) return true;
67
+ if (child.offsetTop < scrollTop) return false;
68
+ if (child.offsetTop + child.offsetHeight > scrollTop + list.clientHeight) return false;
69
+ return true;
70
+ };
71
+ var scrollIfNotCover = function (index) {
72
+ var c = getIndexedElement(index);
73
+ if (!c) return scrollTo(index);
74
+ if (hasCover(c)) return;
75
+ var scrollTop = list.scrollTop;
76
+ var deltat = scrollTop - c.offsetTop;
77
+ var deltab = c.offsetTop + c.offsetHeight - scrollTop - list.clientHeight;
78
+ if (deltat > 0) {
79
+ return scrollBy(-deltab > deltat ? -deltat : -deltab);
80
+ }
81
+ if (deltab > 0) {
82
+ return scrollBy(deltab < deltat ? deltat : deltab);
83
+ }
84
+ };
63
85
  var getLastVisibleElement = function (deltaY = 0) {
64
86
  var { scrollTop } = list;
65
87
  scrollTop += deltaY;
@@ -102,10 +124,10 @@ function ylist(container, generator, $Y) {
102
124
  }
103
125
  var cache_height = list.offsetHeight;
104
126
  var index = itemIndex | 0;
127
+ if (itemIndex < 0) index--;
105
128
  var ratio = itemIndex - index || 0;
106
- if (index < 0) index = 0;
107
129
  var childrenMap = getChildrenMap();
108
- var offsetBottom = 0, ratioTop = 0, offset = +index || 0, last_item = getFirstElement() || null, last_index = last_item && last_item.index || offset;
130
+ var offsetBottom = 0, ratioTop = 0, offset = index, last_item = getFirstElement() || null, last_index = last_item && last_item.index || offset;
109
131
  var count = 0, delta = 1, bottom_item, offsett = offset, offsetb = offset, top_item;
110
132
  var indexed_item;
111
133
  while (offsetBottom - ratioTop <= list.clientHeight + cache_height || indexed_item && top_item && indexed_item.offsetTop - top_item.offsetTop < cache_height) {
@@ -181,7 +203,9 @@ function ylist(container, generator, $Y) {
181
203
  var currentY = function () {
182
204
  var firstElement = getFirstElement(1);
183
205
  if (!firstElement) return;
184
- return firstElement.index * firstElement.offsetHeight + list.scrollTop;
206
+ var index = firstElement.index;
207
+ if (index < 0) index = index - index | 0;
208
+ return index * firstElement.offsetHeight + list.scrollTop;
185
209
  };
186
210
  var getBottomElement = function (last_element) {
187
211
  if (!last_element) return null;
@@ -237,8 +261,6 @@ function ylist(container, generator, $Y) {
237
261
  let item = childrenMap[k];
238
262
  if (item.offsetTop + getOffsetHeight(item) + cache_height < scrollTop) {
239
263
  collection.push(item);
240
- } else {
241
- break;
242
264
  }
243
265
  }
244
266
  if (collection.length) {
@@ -280,9 +302,6 @@ function ylist(container, generator, $Y) {
280
302
  if (!(scrollTop < targetHeight)) {
281
303
  paddingCount--;
282
304
  }
283
- if (!(offset >= 0)) {
284
- break;
285
- }
286
305
  var item = childrenMap[offset];
287
306
  if (!item) {
288
307
  item = createItem(offset);
@@ -313,7 +332,6 @@ function ylist(container, generator, $Y) {
313
332
  } else {
314
333
  deltaScroll = patchTop(deltaY, animate);
315
334
  }
316
-
317
335
  if (deltaScroll) {
318
336
  if (animate && __scrollBy) {
319
337
  list.scrollTop += deltaScroll - deltaY;
@@ -378,13 +396,20 @@ function ylist(container, generator, $Y) {
378
396
  };
379
397
  if (!/^i(Phone|Pod|Watch|Pad)|^Mac/i.test(navigator.platform)) var __scrollBy = list.scrollBy;
380
398
  list.scrollBy = scrollBy;
381
- list.index = function () {
399
+ list.index = function (update) {
400
+ if (update === false) return saved_itemIndex;
382
401
  var firstElement = getFirstVisibleElement();
383
402
  if (!firstElement) return saved_itemIndex;
384
403
  var index = firstElement.index;
385
- var scrolled = (list.scrollTop - firstElement.offsetTop + parseFloat(getComputedStyle(list).paddingTop)) / firstElement.offsetHeight;
404
+ var scrolled = (list.scrollTop - firstElement.offsetTop + parseFloat(getComputedStyle(list).paddingTop) + .5 | 0) / firstElement.offsetHeight;
386
405
  return index + scrolled;
387
406
  };
407
+ on("remove")(list, function () {
408
+ saved_itemIndex = list.index();
409
+ });
410
+ on("append")(list, function () {
411
+ if (isFinite(saved_itemIndex)) list.go(saved_itemIndex);
412
+ })
388
413
  list.topIndex = function () {
389
414
  var element = getFirstElement(1);
390
415
  return element ? element.index : 0;
@@ -392,6 +417,7 @@ function ylist(container, generator, $Y) {
392
417
  list.getIndexedElement = getIndexedElement;
393
418
  list.patchBottom = patchBottom;
394
419
  list.patchTop = patchTop;
420
+ list.scrollIfNotCover = scrollIfNotCover;
395
421
  vbox(list, $Y);
396
422
  return list;
397
423
  }
@@ -400,7 +426,7 @@ var xlist = arriswise(ylist, allArgumentsNames.concat([].slice.call(arguments, 0
400
426
 
401
427
  var getGeneratorFromArray = function (source) {
402
428
  return function (index) {
403
- if (index >= source.length) return null;
429
+ if (index >= source.length || index < 0) return null;
404
430
  return block(source[index]);
405
431
  };
406
432
  };
@@ -1,5 +1,5 @@
1
1
  var listX = list(function (index) {
2
- if(index>100)return;
2
+ if (index > 100 || index < 0) return;
3
3
  var item = div();
4
4
  css(item, `height:100%;width:${Math.random() * 110 + 30}px;border:1px solid;`);
5
5
  text(item, index);
@@ -10,7 +10,7 @@ onappend(listX, function () {
10
10
  });
11
11
  css(listX, "width:360px;height:160px;");
12
12
  var listY = list(function (index) {
13
- if(index>100)return;
13
+ if (index > 100 || index < 0) return;
14
14
  var item = div();
15
15
  css(item, `width:100%;height:${Math.random() * 110 + 30}px;border:1px solid;`);
16
16
  text(item, index);
@@ -165,6 +165,7 @@ function main(elem, mode) {
165
165
  }
166
166
  else {
167
167
  var nodes = getArrayNodes(elem);
168
+ remove(elem.children);
168
169
  elem = menuList(elem, nodes, emit, direction);
169
170
  elem.registerAsRoot();
170
171
  }
@@ -113,7 +113,7 @@ function keytab(event) {
113
113
  if (root_menu !== document.activeElement) return;
114
114
  var menu = mounted_menus[mounted_menus.length - 1] || root_menu;
115
115
  event.preventDefault();
116
- menu.moveFocus(1);
116
+ menu.moveFocus(event.shiftKey ? -1 : 1);
117
117
  }
118
118
  function keyesc() {
119
119
  if (root_menu === document.activeElement && !mounted_menus.length) {
@@ -142,17 +142,16 @@ function keyspace() {
142
142
  }
143
143
  }
144
144
  function register() {
145
- // on('keydown.alt')(window, e => e.preventDefault());
146
- on('keydown.tab')(window, keytab);
147
- on('keydown.alt.')(window, keyalt);
148
- on('keydown.esc')(window, keyesc);
149
- on('keydown.left')(window, keyleft);
150
- on('keydown.right')(window, keyright);
151
- on('keydown.up')(window, keyup);
152
- on('keydown.down')(window, keydown);
153
- on('keydown.enter')(window, keyspace);
154
- on('keydown.space')(window, keyspace);
155
145
  root_menu = this;
146
+ bind('keydown.tab')(root_menu, keytab);
147
+ bind('keydown.alt.')(root_menu, keyalt);
148
+ bind('keydown.esc')(root_menu, keyesc);
149
+ bind('keydown.left')(root_menu, keyleft);
150
+ bind('keydown.right')(root_menu, keyright);
151
+ bind('keydown.up')(root_menu, keyup);
152
+ bind('keydown.down')(root_menu, keydown);
153
+ bind('keydown.enter')(root_menu, keyspace);
154
+ bind('keydown.space')(root_menu, keyspace);
156
155
  }
157
156
  function main(page, items, active, direction = 'y') {
158
157
  if (!isNode(page)) {
@@ -208,8 +207,8 @@ function main(page, items, active, direction = 'y') {
208
207
  var open = function () {
209
208
  cancel();
210
209
  var elem = this;
211
- page.setFocus(elem);
212
210
  if (page.ispop) popTimer = setTimeout(function () {
211
+ page.setFocus(elem);
213
212
  popMenu(elem.menu, elem);
214
213
  }, 60);
215
214
  };
@@ -261,6 +260,7 @@ function main(page, items, active, direction = 'y') {
261
260
  if (!page.firstMenu) {
262
261
  page.firstMenu = a;
263
262
  }
263
+ a.menu = s.menu;
264
264
  return a;
265
265
  },
266
266
  menus: items,
@@ -91,15 +91,17 @@ var constructors = {
91
91
  }
92
92
  else if (t === 'a') {
93
93
  var { field, data } = _;
94
- var pad = selectList(field.options, field.multi, true);
95
- var e = document.createElement('select');
96
94
  var opt = null;
97
- for (var o of field.options) {
95
+ for (var cx = 0, options = field.options, dx = options.length; cx < dx; cx++) {
96
+ var o = options[cx];
98
97
  if (o.key === data[field.key]) {
99
98
  opt = o;
99
+ o.selected = true;
100
100
  break;
101
101
  }
102
102
  }
103
+ var pad = selectList(field.options, field.multi, true);
104
+ var e = document.createElement('select');
103
105
  e.innerHTML = `<option selected value="${opt ? opt.key : ''}">${opt ? opt.name : '请选择'}</option>`;
104
106
  e.value = opt ? opt.key : '';
105
107
  elem = select(e, pad);
package/coms/zimoli/on.js CHANGED
@@ -20,8 +20,8 @@ var keyCodeMap = {
20
20
  space: 32,
21
21
  pageup: 33,
22
22
  pagedown: 34,
23
- home: 35,
24
- end: 36,
23
+ end: 35,
24
+ home: 36,
25
25
  left: 37,
26
26
  up: 38,
27
27
  right: 39,
@@ -94,6 +94,15 @@ function select(target, list, removeOnSelect, direction) {
94
94
  if (removeOnSelect === null) {
95
95
  onmousedown(list, preventDefault);
96
96
  }
97
+ on("keydown.up")(target, preventDefault);
98
+ on("keydown.down")(target, preventDefault);
99
+ on("keydown.enter")(target, preventDefault);
100
+ on("keydown.space")(target, preventDefault);
101
+ var pop = function () {
102
+ if (saved_list !== list) mousedown.call(this);
103
+ };
104
+ on("keydown.down")(target, pop);
105
+ on("keydown.enter")(target, pop);
97
106
  onremove(list, onlistremove);
98
107
  };
99
108
  if (isNode(list)) {
@@ -103,7 +112,23 @@ function select(target, list, removeOnSelect, direction) {
103
112
  };
104
113
  var setIcon = function () {
105
114
  };
106
- } else {
115
+ }
116
+ else if (target.$src) {
117
+ var generator = getGenerator(target);
118
+ var initList2 = function (src) {
119
+ list = selectList(generator, src, target.multiple, target.editable);
120
+ if (!target.multiple) {
121
+ onclick(list, onlistclick);
122
+ }
123
+ bindEvent();
124
+ };
125
+ care(target, initList2);
126
+ var initList = function () {
127
+ };
128
+ var setIcon = function () {
129
+ };
130
+ }
131
+ else {
107
132
  var savedOptions;
108
133
  removeOnSelect = null;
109
134
  var lastSelected = [];
@@ -1,12 +1,17 @@
1
1
  var singleClick = function () {
2
2
  var node = this.parentNode;
3
3
  if (node.activeNode === this) return;
4
- if (node.activeNode) node.activeNode.removeAttribute("selected");
4
+ if (node.activeNode) {
5
+ if (node.activeNode.origin) node.activeNode.origin.selected = false;
6
+ node.activeNode.removeAttribute("selected");
7
+ }
5
8
  this.setAttribute("selected", "");
9
+
6
10
  node.activeNode = this;
7
11
  if (node.value === this.value) return;
8
12
  node.value = this.value;
9
13
  node.name = this.name;
14
+ if (this.origin) this.origin.selected = true;
10
15
  dispatch(node, "change");
11
16
  };
12
17
  var multipleClick = function () {
@@ -20,13 +25,33 @@ var multipleClick = function () {
20
25
  values.splice(index, 1);
21
26
  this.removeAttribute("selected");
22
27
  }
28
+ if (this.origin) this.origin.selected = true;
23
29
  dispatch(node, "change");
24
30
  };
25
31
 
26
- function main(children, multiple, addable) {
27
- var page = div();
32
+
33
+ function main() {
34
+ var children, multiple, addable, generator, page;
35
+ for (let a of arguments) {
36
+ if (a instanceof Array) children = a;
37
+ switch (typeof a) {
38
+ case "function":
39
+ generator = a;
40
+ break;
41
+ case "boolean":
42
+ if (multiple === void 0) multiple = a;
43
+ else addable = a;
44
+ case "object":
45
+ if (isNode(a)) {
46
+ page = a;
47
+ if (!generator) generator = getGenerator(page);
48
+ }
49
+ else if (a.length) children = a;
50
+
51
+ }
52
+ }
53
+ if (!page) page = div();
28
54
  page.value = multiple ? [] : "";
29
- var firstValue = false;
30
55
  var clicker = multiple ? multipleClick : singleClick;
31
56
  var itemMap = Object.create(null);
32
57
  function createItem(option) {
@@ -36,6 +61,7 @@ function main(children, multiple, addable) {
36
61
  item.setAttribute("item", '');
37
62
  item.innerHTML = option.innerHTML || option.name;
38
63
  item.name = option.name || option.innerHTML;
64
+ item.origin = option;
39
65
  var icon = option.getAttribute ? option.getAttribute("icon") : option.icon;
40
66
  if (icon) {
41
67
  if (!hasIcon) {
@@ -50,10 +76,10 @@ function main(children, multiple, addable) {
50
76
  if (multiple) {
51
77
  item.setAttribute("selected", "");
52
78
  page.value.push(option.value);
53
- } else if (!firstValue) {
79
+ }
80
+ else {
54
81
  item.setAttribute("selected", "");
55
82
  page.activeNode = item;
56
- firstValue = true;
57
83
  page.value = option.value
58
84
  }
59
85
  }
@@ -61,18 +87,28 @@ function main(children, multiple, addable) {
61
87
  item.setAttribute('disabled', '');
62
88
  } else {
63
89
  onclick(item, clicker);
90
+ on("mouseenter")(item, mouseenter);
64
91
  }
65
92
  return item;
66
93
 
67
94
  }
95
+ var mouseenter = function () {
96
+ if (!mouse) return;
97
+ focus = this.index;
98
+ setFocus();
99
+ };
100
+
101
+
68
102
  var hasIcon = false, iconed = '';
69
103
  var page = list(page, function (i) {
70
104
  if (i < 0 || i >= children.length) return;
71
- return createItem(children[i]);
105
+ return createItem(generator ? generator(i) : children[i]);
72
106
  });
73
- on("append")(page, function () {
107
+ once("append")(page, function () {
108
+ var index = 0;
109
+ for (var cx = 0, dx = children.length; cx < dx; cx++)if (children[cx].selected) index = cx;
74
110
  page.clean();
75
- page.go(0);
111
+ page.go(index);
76
112
  if (adder) {
77
113
  remove(adder);
78
114
  appendChild(page, adder);
@@ -129,6 +165,60 @@ function main(children, multiple, addable) {
129
165
  adder.setAttribute("adder", '');
130
166
  }
131
167
  page.icon = iconed;
168
+ var focus = 0, focused, mouse = false;
169
+ var setFocus = function () {
170
+ var e = page.getIndexedElement(focus);
171
+ if (e === focused) return;
172
+ if (focused) removeClass(focused, 'focus');
173
+ focused = e;
174
+ if (e) addClass(e, 'focus');
175
+ mouse = false;
176
+ };
177
+ var setMouse = function () {
178
+ mouse = true;
179
+ }
180
+ onmousemove(page, setMouse);
181
+ onmousewheel(page, setMouse);
182
+ var moveFocus = function (delta) {
183
+ focus += delta;
184
+ if (focus < 0) focus = 0;
185
+ if (focus >= children.length) focus = children.length - 1;
186
+ page.scrollIfNotCover(focus);
187
+ setFocus();
188
+ };
189
+ bind('keydown.up')(page, function () {
190
+ moveFocus(-1);
191
+ });
192
+ bind('keydown.down')(page, function () {
193
+ moveFocus(1);
194
+ });
195
+ bind('keydown.tab')(page, function (event) {
196
+ if (document.activeElement === page.target) event.preventDefault();
197
+ moveFocus(event.shiftKey ? -1 : 1);
198
+ });
199
+ bind("keydown.home")(page, function (e) {
200
+ moveFocus(-focus);
201
+ });
202
+ bind("keydown.end")(page, function (e) {
203
+ moveFocus(children.length - 1 - focus);
204
+ });
205
+ bind("keydown.pagedown")(page, function (e) {
206
+ page.scrollBy(page.clientHeight);
207
+ focus = page.index() | 0;
208
+ moveFocus(0);
209
+ })
210
+ bind("keydown.pageup")(page, function (e) {
211
+ page.scrollBy(-page.clientHeight);
212
+ focus = page.index() | 0;
213
+ moveFocus(0);
214
+ })
215
+ var enter = function (e) {
216
+ e.preventDefault();
217
+ var e = page.getIndexedElement(focus);
218
+ if (e) e.click();
219
+ };
220
+ bind('keydown.enter')(page, enter);
221
+ bind('keydown.space')(page, enter);
132
222
  on('mousedown')(page, e => e.preventDefault());
133
223
  return page;
134
224
  }
@@ -15,10 +15,10 @@
15
15
  padding: 0 16px;
16
16
 
17
17
  &[selected] {
18
- color: #26f;
18
+ color: #29e;
19
19
  }
20
20
 
21
- &:hover {
21
+ &.focus {
22
22
  background-color: #2ca2f9;
23
23
  color: #fff;
24
24
  }
@@ -2,9 +2,13 @@
2
2
  <option>选项一</option>
3
3
  <option>选项二</option>
4
4
  <option>选项三</option>
5
+ <option selected>简单选项</option>
5
6
  </select>
6
7
  <select>
7
- <option>选项一</option>
8
- <option>选项二</option>
9
- <option>选项三</option>
8
+ <option -repeat="(o,i) in options600" -text="'选项'+o">选项</option>
9
+ <option selected>600个选项</option>
10
10
  </select>
11
+ <select -src="(o,i) in options6000">
12
+ <option -text="'选项'+o">选项</option>
13
+ <option insert selected>60000个选项</option>
14
+ </select>
@@ -1,8 +1,14 @@
1
1
  var page = div();
2
2
  page.innerHTML = selectList_test;
3
- render(page,{
4
- select
5
- })
3
+ render(page, {
4
+ select,
5
+ select2() {
6
+ var sel = document.createElement("select");
7
+ return sel;
8
+ },
9
+ options600: new Array(600).fill(0).map((_, a) => a),
10
+ options6000: new Array(60000).fill(0).map((_, a) => a)
11
+ });
6
12
  function main() {
7
13
  return page;
8
14
  }
@@ -1,7 +1,7 @@
1
- var listY = list(function (data, index) {
1
+ var listY = list(function (index) {
2
2
  var item = div();
3
3
  css(item, `width:100%;height:${Math.random() * 110 + 30}px;border:1px solid;`);
4
- text(item, data);
4
+ text(item, index);
5
5
  return item;
6
6
  }, "Y");
7
7
  onappend(listY, function () {