efront 4.35.2 → 4.35.4

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.
Files changed (35) hide show
  1. package/#/345/233/275/351/231/205/345/214/226.yml +3 -0
  2. package/coms/basic/#loader.js +1 -1
  3. package/coms/basic/Table.js +26 -0
  4. package/coms/basic/escapeRegExp.js +24 -0
  5. package/coms/basic/escapeRegExp_test.js +35 -0
  6. package/coms/basic/math.js +106 -4
  7. package/coms/basic/math.md +128 -25
  8. package/coms/basic/spaces.js +1 -1
  9. package/coms/compile/Program.js +1 -1
  10. package/coms/compile/common.js +1 -1
  11. package/coms/compile//347/256/227/345/274/217.js +62 -20
  12. package/coms/compile//347/256/227/345/274/217_test.js +6 -2
  13. package/coms/compile//347/264/240/351/246/250.js +5 -4
  14. package/coms/compile//347/264/240/351/246/250_test.js +21 -1
  15. package/coms/explorer/main.less +1 -0
  16. package/coms/reptile/colors.js +2 -1
  17. package/coms/zimoli/arriswise.js +6 -1
  18. package/coms/zimoli/color-config.less +1 -1
  19. package/coms/zimoli/confirm.js +1 -1
  20. package/coms/zimoli/getGenerator.js +0 -1
  21. package/coms/zimoli/list.js +609 -576
  22. package/coms/zimoli/popup.js +1 -1
  23. package/coms/zimoli/prompt.js +4 -1
  24. package/coms/zimoli/scrollbar.less +1 -1
  25. package/coms/zimoli/table.js +1 -1
  26. package/coms/zimoli/vbox.js +1 -0
  27. package/coms//350/214/250/350/217/260//344/270/212/350/211/262.xht +5 -1
  28. package/coms//350/214/250/350/217/260//346/240/207/347/255/276/345/214/226.js +9 -1
  29. package/coms//350/214/250/350/217/260//346/270/262/346/237/223.js +1 -1
  30. package/coms//350/214/250/350/217/260//347/274/226/350/276/221/346/241/206.xht +16 -2
  31. package/coms//350/214/250/350/217/260//350/257/255/350/250/200.js +5 -0
  32. package/package.json +1 -1
  33. package/public/efront.js +1 -1
  34. package/public//346/226/207/344/273/266/347/263/273/347/273/237//344/270/273/351/241/265.jsp +2 -2
  35. package/debug.log +0 -3
@@ -1,402 +1,388 @@
1
1
  // 中文编码 utf8
2
- function ylist(container, generator, $Y) {
3
- const cache_height = 2000;
4
- var restHeight = cache_height;
5
- /**
6
- * @type {HTMLElement}
7
- */
8
- var list = container;
9
- list.autoFix = true;
10
- var saved_itemIndex = 0;
11
- addClass(list, 'list-' + $Y.toLowerCase());
12
- var getNodeTarget = function (node) {
13
- if (node.nodeType === 8 && node.$template) {
14
- var t = node.$template;
15
- if (!isFinite(t.index)) t.index = node.index;
16
- return node.$template;
17
- }
18
- return node;
19
- };
20
- //取底部元素
21
- var getLastElement = function (nodeType) {
22
- var children = list.childNodes;
23
- for (var cx = children.length - 1; cx >= 0; cx--) {
24
- var child = children[cx];
25
- if (!(isFinite(child.index) || nodeType === 2 && child.offsetHeight)) continue;
26
- child = getNodeTarget(child);
27
- return child;
28
- }
29
- return null;
30
- };
31
- //取底部元素
32
- var getIndexedElement = function (index) {
33
- var children = list.childNodes;
34
- for (var cx = children.length - 1; cx >= 0; cx--) {
35
- var child = children[cx];
36
- if (child.index !== index) continue;
37
- child = getNodeTarget(child);
38
- return child;
39
- }
40
- return null;
41
- };
2
+ var getNodeTarget = function (node) {
3
+ if (node.nodeType === 8 && node.$template) {
4
+ var t = node.$template;
5
+ if (!isFinite(t.index)) t.index = node.index;
6
+ return node.$template;
7
+ }
8
+ return node;
9
+ };
10
+ //取底部元素
11
+ var getLastElement_ = function (nodeType) {
12
+ var children = this.childNodes;
13
+ for (var cx = children.length - 1; cx >= 0; cx--) {
14
+ var child = children[cx];
15
+ if (!(isFinite(child.index) || nodeType === 2 && child.offsetHeight)) continue;
16
+ child = getNodeTarget(child);
17
+ return child;
18
+ }
19
+ return null;
20
+ };
21
+ //取底部元素
22
+ var getIndexedElement_ = function (index) {
23
+ var children = this.childNodes;
24
+ for (var cx = children.length - 1; cx >= 0; cx--) {
25
+ var child = children[cx];
26
+ if (child.index !== index) continue;
27
+ child = getNodeTarget(child);
28
+ return child;
29
+ }
30
+ return null;
31
+ };
42
32
 
43
- //取顶部元素
44
- var getFirstElement = function (nodeType) {
45
- var children = list.childNodes;
46
- for (var cx = 0, dx = children.length; cx < dx; cx++) {
47
- var child = children[cx];
48
- if (!(isFinite(child.index) && (nodeType === 0 || child.index !== null) || nodeType === 2 && child.offsetHeight)) continue;
49
- if (nodeType === 1) child = getNodeTarget(child);
50
- return child;
51
- }
52
- return null;
53
- };
54
- var isSticky = child => isElement(child) && /^(sticky|fixed|absolute)$/.test(getComputedStyle(child).position);
55
- var getFirstVisibleElement = function (deltaY) {
56
- var children = list.childNodes;
57
- var { scrollTop } = list;
58
- var paddingTop = parseFloat(getComputedStyle(list).paddingTop);
59
- deltaY = paddingTop + (deltaY || 0);
60
- if (deltaY) scrollTop += deltaY;
61
- for (var cx = 0, dx = children.length; cx < dx; cx++) {
62
- var child = children[cx];
63
- if (!isFinite(child.index) || child.index === null) continue;
64
- var c = getNodeTarget(child);
65
- if (isSticky(c)) continue;
66
- if (c.offsetTop + c.offsetHeight >= scrollTop + 1) return deltaY === 0 ? child : c;
67
- }
68
- return null;
69
- };
70
- var getRelativeElement = function (element, delta) {
71
- delta = +delta;
72
- if (!delta || !isFinite(element.index)) return;
73
- var target = element.index + delta;
74
- if (!target) return;
75
- if (delta < 0) var key = "previousElementSibling";
76
- else key = "nextElementSibling";
77
- while (element) {
78
- if (element.index === target) return element;
79
- element = element[key];
80
- }
33
+ //取顶部元素
34
+ var getFirstElement_ = function (nodeType) {
35
+ var children = this.childNodes;
36
+ for (var cx = 0, dx = children.length; cx < dx; cx++) {
37
+ var child = children[cx];
38
+ if (!(isFinite(child.index) && (nodeType === 0 || child.index !== null) || nodeType === 2 && child.offsetHeight)) continue;
39
+ if (nodeType === 1) child = getNodeTarget(child);
40
+ return child;
81
41
  }
82
- var hasCover = function (child) {
83
- var scrollTop = list.scrollTop;
84
- if (child.offsetTop + child.offsetHeight < scrollTop || child.offsetTop >= scrollTop + list.clientHeight) return false;
85
- if (child.offsetTop <= scrollTop && child.offsetTop + child.offsetHeight >= scrollTop + list.clientHeight) return true;
86
- if (child.offsetTop < scrollTop) return false;
87
- if (child.offsetTop + child.offsetHeight > scrollTop + list.clientHeight) return false;
88
- return true;
89
- };
90
- var scrollIfNotCover = function (index) {
91
- var c = getIndexedElement(index);
92
- if (!c) return scrollTo(index);
93
- if (hasCover(c)) return;
94
- var scrollTop = list.scrollTop;
95
- var deltat = scrollTop - c.offsetTop;
96
- var deltab = c.offsetTop + c.offsetHeight - scrollTop - list.clientHeight;
97
- if (deltat > 0) {
98
- return scrollBy(-deltab > deltat ? -deltat : -deltab);
99
- }
100
- if (deltab > 0) {
101
- return scrollBy(deltab < deltat ? deltat : deltab);
102
- }
103
- };
104
- var getLastVisibleElement = function (deltaY) {
105
- var { scrollTop } = list;
106
- deltaY = +deltaY;
107
- var paddingBottom = parseFloat(getComputedStyle(list).paddingBottom);
108
- if (deltaY) scrollTop += deltaY;
109
- var children = list.children;
110
- for (var cx = children.length - 1; cx >= 0; cx--) {
111
- var child = children[cx];
112
- if (!isFinite(child.index)) continue;
113
- var c = getNodeTarget(child);
114
- if (isSticky(c)) continue;
115
- if (c.offsetTop + 1 <= scrollTop + list.clientHeight - paddingBottom) {
116
- return deltaY === 0 ? child : c;
117
- }
118
- }
119
- return null;
120
- };
121
- //元素表
122
- var getChildrenMap = function () {
123
- var children = list.childNodes;
124
- var map = {};
125
- for (var cx = 0, dx = children.length; cx < dx; cx++) {
126
- var child = children[cx];
127
- if (isFinite(child.index) && child.index !== null) {
128
- if (!map[child.index] || child.$template === map[child.index]) {
129
- map[child.index] = child;
130
- }
131
- }
132
- }
133
- return map;
134
- };
135
- var createItem = function (index) {
136
- var item = generator(index);
137
- if (isNode(item)) {
138
- item.index = index;
139
- }
140
- return item;
141
- };
142
- //设置当前下标
143
- var scrollTo = function (itemIndex) {
144
- if (isNaN(itemIndex)) return;
145
- lastY = NaN;
146
- itemIndex = +itemIndex;
147
- __animated = false;
148
- if (!list.offsetHeight && !list.offsetWidth && !isMounted(list)) {
149
- saved_itemIndex = itemIndex;
150
- return;
151
- }
152
- var cache_height = Math.min(list.offsetHeight, screen.height >> 1);
153
- var index = itemIndex | 0;
154
- if (itemIndex < 0) index--;
155
- var ratio = itemIndex - index || 0;
156
- var childrenMap = getChildrenMap();
157
- var offsetBottom = 0, ratioTop = 0, offset = index, last_item = getFirstElement(0) || null, last_index = last_item && last_item.index || offset;
158
- if (!last_item) {
159
- last_item = list.lastChild;
160
- while (last_item && last_item.$isafter) last_item = last_item.previousSibling;
42
+ return null;
43
+ };
44
+ var getFirstVisibleElement_ = function (deltaY) {
45
+ var children = this.childNodes;
46
+ var { scrollTop } = this;
47
+ var paddingTop = parseFloat(getComputedStyle(this).paddingTop);
48
+ deltaY = paddingTop + (deltaY || 0);
49
+ if (deltaY) scrollTop += deltaY;
50
+ for (var cx = 0, dx = children.length; cx < dx; cx++) {
51
+ var child = children[cx];
52
+ if (!isFinite(child.index) || child.index === null) continue;
53
+ var c = getNodeTarget(child);
54
+ if (isSticky(c)) continue;
55
+ if (c.offsetTop + c.offsetHeight >= scrollTop + 1) return deltaY === 0 ? child : c;
56
+ }
57
+ return null;
58
+ };
59
+ var getRelativeElement_ = function (element, delta) {
60
+ delta = +delta;
61
+ if (!delta || !isFinite(element.index)) return;
62
+ var target = element.index + delta;
63
+ if (!target) return;
64
+ if (delta < 0) var key = "previousElementSibling";
65
+ else key = "nextElementSibling";
66
+ while (element) {
67
+ if (element.index === target) return element;
68
+ element = element[key];
69
+ }
70
+ }
71
+ var isSticky = child => isElement(child) && /^(sticky|fixed|absolute)$/.test(getComputedStyle(child).position);
72
+ var hasCover_ = function (child) {
73
+ var scrollTop = this.scrollTop;
74
+ if (child.offsetTop + child.offsetHeight < scrollTop || child.offsetTop >= scrollTop + this.clientHeight) return false;
75
+ if (child.offsetTop <= scrollTop && child.offsetTop + child.offsetHeight >= scrollTop + this.clientHeight) return true;
76
+ if (child.offsetTop < scrollTop) return false;
77
+ if (child.offsetTop + child.offsetHeight > scrollTop + this.clientHeight) return false;
78
+ return true;
79
+ };
80
+
81
+ var scrollIfNotCover_ = function (index) {
82
+ var c = this.getIndexedElement(index);
83
+ if (!c) return this.scrollTo(index);
84
+ if (this.hasCover(c)) return;
85
+ var scrollTop = this.scrollTop;
86
+ var deltat = scrollTop - c.offsetTop;
87
+ var deltab = c.offsetTop + c.offsetHeight - scrollTop - this.clientHeight;
88
+ if (deltat > 0) {
89
+ return this.scrollBy(-deltab > deltat ? -deltat : -deltab);
90
+ }
91
+ if (deltab > 0) {
92
+ return this.scrollBy(deltab < deltat ? deltat : deltab);
93
+ }
94
+ };
95
+ var getLastVisibleElement_ = function (deltaY) {
96
+ var { scrollTop } = this;
97
+ deltaY = +deltaY;
98
+ var paddingBottom = parseFloat(getComputedStyle(this).paddingBottom);
99
+ if (deltaY) scrollTop += deltaY;
100
+ var children = this.children;
101
+ for (var cx = children.length - 1; cx >= 0; cx--) {
102
+ var child = children[cx];
103
+ if (!isFinite(child.index)) continue;
104
+ var c = getNodeTarget(child);
105
+ if (isSticky(c)) continue;
106
+ if (c.offsetTop + 1 <= scrollTop + this.clientHeight - paddingBottom) {
107
+ return deltaY === 0 ? child : c;
161
108
  }
162
- if (last_item) last_item = getNodeTarget(last_item);
163
- var count = 0, delta = 1, bottom_item, offsett = offset, offsetb = offset, top_item;
164
- var indexed_item;
165
- var limitHeight = screen.height;
166
- while (
167
- offsetBottom - ratioTop <= limitHeight + cache_height
168
- || delta < 0 && indexed_item && top_item && indexed_item.offsetTop - top_item.offsetTop < cache_height) {
169
- var item = childrenMap[offset];
170
- if (!item) {
171
- item = createItem(offset);
172
- if (!item || delta > 0 && offsetBottom - ratioTop > list.clientHeight + cache_height) {
173
- if (delta < 0) break;
174
- delta = -1;
175
- offset = index - 1;
176
- bottom_item = getIndexedElement(offsetb);
177
- last_item = getIndexedElement(index);
178
- last_index = index;
179
- continue;
180
- }
181
- } else {
182
- delete childrenMap[offset];
183
- }
184
- if (last_index > offset) {
185
- if (item.nextElementSibling !== last_item) insertBeforeList(item, last_item);
186
- } else {
187
- if (item.previousElementSibling !== item) insertBeforeList(item, getNextSibling(last_item));
188
- }
189
- last_index = offset;
190
- item = getNodeTarget(item);
191
- last_item = item;
192
- if (offset === index || !indexed_item) indexed_item = item;
193
- if (delta > 0) {
194
- offsetb = offset;
195
- offset++;
196
- bottom_item = item;
197
- if (!top_item) top_item = item;
198
- } else {
199
- offsett = offset;
200
- offset--;
201
- if (!bottom_item) bottom_item = item;
202
- top_item = item;
109
+ }
110
+ return null;
111
+ };
112
+ //元素表
113
+ var getChildrenMap = function (list) {
114
+ var children = list.childNodes;
115
+ var map = {};
116
+ for (var cx = 0, dx = children.length; cx < dx; cx++) {
117
+ var child = children[cx];
118
+ if (isFinite(child.index) && child.index !== null) {
119
+ if (!map[child.index] || child.$template === map[child.index]) {
120
+ map[child.index] = child;
203
121
  }
204
- offsetBottom = bottom_item.offsetTop + bottom_item.offsetHeight;
205
- ratioTop = top_item.offsetTop + top_item.offsetHeight * ratio;
206
- if (count++ > 600) throw console.log(
207
- `头部下标`, index,
208
- `当前下标`, offset,
209
- `缓冲尺寸`, cache_height,
210
- '限制尺寸', limitHeight,
211
- '框架尺寸', list.offsetHeight,
212
- '当前绘制到', ratioTop,
213
- `当前元素到顶部元素占用`, offsetBottom - ratioTop
214
- ), new Error(i18n`多于600个元素需要绘制!`);
215
- }
216
- for (var k in childrenMap) {
217
- remove(childrenMap[k]);
218
- }
219
- var indexed_item = getIndexedElement(index) || bottom_item;
220
- if (indexed_item) {
221
- var firstElement = getFirstElement(1) || indexed_item;
222
- list.scrollTop = -firstElement.offsetTop + indexed_item.offsetTop + indexed_item.offsetHeight * ratio;
223
122
  }
224
- };
225
- //计算当前高度
226
- var currentY = function () {
227
- var firstElement = getFirstElement();
228
- if (!firstElement) return;
229
- var index = firstElement.index;
230
- firstElement = getNodeTarget(firstElement);
231
- if (index < 0) index = index - index | 0;
232
- return index * firstElement.offsetHeight + list.scrollTop;
233
- };
234
- var getBottomElement = function (last_element) {
235
- if (!last_element) return null;
236
- var with_elements = last_element.with;
237
- return with_elements && with_elements.length ? with_elements[with_elements.length - 1] : last_element;
238
- };
239
- var getNextSibling = function (last_element) {
240
- var bottom_element = getBottomElement(last_element);
241
- return bottom_element ? bottom_element.nextSibling : null;
242
- };
243
- var getOffsetHeight = function (element) {
244
- element = getNodeTarget(element);
245
- var temp = element;
246
- do {
247
- var next = getNextSibling(temp);
248
- if (!next) return element.offsetHeight;
249
- temp = getNodeTarget(next);
250
- } while (next.offsetTop === element.offsetTop);
251
- return next.offsetTop - element.offsetTop;
252
- };
253
- var insertBeforeList = function (elem, flag) {
254
- if (flag) {
255
- var w = elem.with;
256
- if (w) {
257
- if (w[w.length - 1].nextSibling === flag) return;
123
+ }
124
+ return map;
125
+ };
126
+ var createItem_ = function (index) {
127
+ var item = this.generator_(index);
128
+ if (isNode(item)) {
129
+ item.index = index;
130
+ }
131
+ return item;
132
+ };
133
+ //设置当前下标
134
+ var scrollTo_ = function (itemIndex) {
135
+ if (isNaN(itemIndex)) return;
136
+ this.$lastY_ = NaN;
137
+ itemIndex = +itemIndex;
138
+ this.__animated = false;
139
+ if (!this.offsetHeight && !this.offsetWidth && !isMounted(this)) {
140
+ this.itemIndex_saved_ = itemIndex;
141
+ return;
142
+ }
143
+ var cache_height = Math.min(this.offsetHeight, screen.height >> 1);
144
+ var index = itemIndex | 0;
145
+ if (itemIndex < 0) index--;
146
+ var ratio = itemIndex - index || 0;
147
+ var childrenMap = getChildrenMap(this);
148
+ var offsetBottom = 0, ratioTop = 0, offset = index, last_item = this.getFirstElement(0) || null, last_index = last_item && last_item.index || offset;
149
+ if (!last_item) {
150
+ last_item = this.lastChild;
151
+ while (last_item && last_item.$isafter) last_item = last_item.previousSibling;
152
+ }
153
+ if (last_item) last_item = getNodeTarget(last_item);
154
+ var count = 0, delta = 1, bottom_item, offsett = offset, offsetb = offset, top_item;
155
+ var indexed_item;
156
+ var limitHeight = screen.height;
157
+ while (
158
+ offsetBottom - ratioTop <= limitHeight + cache_height
159
+ || delta < 0 && indexed_item && top_item && indexed_item.offsetTop - top_item.offsetTop < cache_height) {
160
+ var item = childrenMap[offset];
161
+ if (!item) {
162
+ item = this.createItem(offset);
163
+ if (!item || delta > 0 && offsetBottom - ratioTop > this.clientHeight + cache_height) {
164
+ if (delta < 0) break;
165
+ delta = -1;
166
+ offset = index - 1;
167
+ bottom_item = this.getIndexedElement(offsetb);
168
+ last_item = this.getIndexedElement(index);
169
+ last_index = index;
170
+ continue;
258
171
  }
259
- else if (elem.nextSibling === flag) return;
172
+ } else {
173
+ delete childrenMap[offset];
260
174
  }
261
- list.insertBefore(elem, flag);
262
- if (elem.with) for (var w of elem.with) list.insertBefore(w, flag);
263
- };
264
- var patchBottom = function (deltaY = 0) {
265
- var cache_height = Math.min(list.offsetHeight, screen.height >> 1);
266
- var limitHeight = screen.height + cache_height;
267
- var childrenMap = getChildrenMap();
268
- var last_element = getLastElement(1);
269
- if (!last_element || !last_element.offsetHeight) return;
270
- let { scrollTop } = list;
271
- scrollTop += deltaY;
272
- var offsetBottom = getOffsetHeight(last_element) + last_element.offsetTop;
273
- var offset = last_element.index || 0;
274
- //追加元素到底部
275
- while (offsetBottom <= scrollTop + limitHeight) {
175
+ if (last_index > offset) {
176
+ if (item.nextElementSibling !== last_item) this.insertBeforeList(item, last_item);
177
+ } else {
178
+ if (item.previousElementSibling !== item) this.insertBeforeList(item, getNextSibling(last_item));
179
+ }
180
+ last_index = offset;
181
+ item = getNodeTarget(item);
182
+ last_item = item;
183
+ if (offset === index || !indexed_item) indexed_item = item;
184
+ if (delta > 0) {
185
+ offsetb = offset;
276
186
  offset++;
277
- var item = childrenMap[offset];
187
+ bottom_item = item;
188
+ if (!top_item) top_item = item;
189
+ } else {
190
+ offsett = offset;
191
+ offset--;
192
+ if (!bottom_item) bottom_item = item;
193
+ top_item = item;
194
+ }
195
+ offsetBottom = bottom_item.offsetTop + bottom_item.offsetHeight;
196
+ ratioTop = top_item.offsetTop + top_item.offsetHeight * ratio;
197
+ if (count++ > 600) throw console.log(
198
+ `头部下标`, index,
199
+ `当前下标`, offset,
200
+ `缓冲尺寸`, cache_height,
201
+ '限制尺寸', limitHeight,
202
+ '框架尺寸', this.offsetHeight,
203
+ '当前绘制到', ratioTop,
204
+ `当前元素到顶部元素占用`, offsetBottom - ratioTop
205
+ ), new Error(i18n`多于600个元素需要绘制!`);
206
+ }
207
+ for (var k in childrenMap) {
208
+ remove(childrenMap[k]);
209
+ }
210
+ var indexed_item = this.getIndexedElement(index) || bottom_item;
211
+ if (indexed_item) {
212
+ var firstElement = this.getFirstElement(1) || indexed_item;
213
+ this.scrollTop = -firstElement.offsetTop + indexed_item.offsetTop + indexed_item.offsetHeight * ratio;
214
+ }
215
+ };
216
+ //计算当前高度
217
+ var currentY_ = function () {
218
+ var firstElement = this.getFirstElement();
219
+ if (!firstElement) return;
220
+ var index = firstElement.index;
221
+ firstElement = getNodeTarget(firstElement);
222
+ if (index < 0) index = index - index | 0;
223
+ return index * firstElement.offsetHeight + this.scrollTop;
224
+ };
225
+ var getBottomElement = function (last_element) {
226
+ if (!last_element) return null;
227
+ var with_elements = last_element.with;
228
+ return with_elements && with_elements.length ? with_elements[with_elements.length - 1] : last_element;
229
+ };
230
+ var getNextSibling = function (last_element) {
231
+ var bottom_element = getBottomElement(last_element);
232
+ return bottom_element ? bottom_element.nextSibling : null;
233
+ };
234
+ var getOffsetHeight = function (element) {
235
+ element = getNodeTarget(element);
236
+ var temp = element;
237
+ do {
238
+ var next = getNextSibling(temp);
239
+ if (!next) return element.offsetHeight;
240
+ temp = getNodeTarget(next);
241
+ } while (next.offsetTop === element.offsetTop);
242
+ return next.offsetTop - element.offsetTop;
243
+ };
244
+ var insertBeforeList_ = function (elem, flag) {
245
+ if (flag) {
246
+ var w = elem.with;
247
+ if (w) {
248
+ if (w[w.length - 1].nextSibling === flag) return;
249
+ }
250
+ else if (elem.nextSibling === flag) return;
251
+ }
252
+ this.insertBefore(elem, flag);
253
+ if (elem.with) for (var w of elem.with) this.insertBefore(w, flag);
254
+ };
255
+
256
+ var patchBottom_ = function (deltaY = 0) {
257
+ var cache_height = Math.min(this.offsetHeight, screen.height >> 1);
258
+ var limitHeight = screen.height + cache_height;
259
+ var childrenMap = getChildrenMap(this);
260
+ var last_element = this.getLastElement(1);
261
+ if (!last_element || !last_element.offsetHeight) return;
262
+ let { scrollTop } = this;
263
+ scrollTop += deltaY;
264
+ var offsetBottom = getOffsetHeight(last_element) + last_element.offsetTop;
265
+ var offset = last_element.index || 0;
266
+ //追加元素到底部
267
+ while (offsetBottom <= scrollTop + limitHeight) {
268
+ offset++;
269
+ var item = childrenMap[offset];
270
+ if (!item) {
271
+ item = this.createItem(offset);
278
272
  if (!item) {
279
- item = createItem(offset);
280
- if (!item) {
281
- restHeight = 0;
282
- break;
283
- } else if (!restHeight) {
284
- restHeight = cache_height;
285
- }
286
- insertBeforeList(item, getNextSibling(last_element));
287
- }
288
- item = getNodeTarget(item);
289
- if (!item.offsetHeight) {
290
- console.warn(item, '!item.offsetHeight');
273
+ this.restHeight_ = 0;
291
274
  break;
275
+ } else if (!this.restHeight_) {
276
+ this.restHeight_ = cache_height;
292
277
  }
293
- offsetBottom = item.offsetTop + getOffsetHeight(item);
294
- last_element = item;
278
+ this.insertBeforeList(item, getNextSibling(last_element));
295
279
  }
296
- var collection = [];
297
- for (var k in childrenMap) {
298
- let item = childrenMap[k];
299
- if (getNodeTarget(item).offsetTop + getOffsetHeight(item) + limitHeight < scrollTop) {
300
- collection.push(item);
301
- }
280
+ item = getNodeTarget(item);
281
+ if (!item.offsetHeight) {
282
+ console.warn(item, '!item.offsetHeight');
283
+ break;
302
284
  }
303
- if (collection.length) {
304
- var item = collection[collection.length - 1];
305
- var { paddingCount = 0, paddingMax } = list;
306
- if (item) item = item.nextSibling;
307
- if (!paddingMax) while (item && item.index % list.group) {
308
- item = collection.pop();
309
- }
310
- var item = collection[collection.length - 1];
311
- if (item) scrollTop -= getNodeTarget(item).offsetTop + getOffsetHeight(item) - getNodeTarget(collection[0]).offsetTop;
312
- if (paddingCount > 0 && paddingMax > 0 && paddingCount < paddingMax) {
313
- let item = collection[collection.length - 1];
314
- while (paddingCount > 0) {
315
- if (!item) break;
316
- paddingCount--;
317
- collection.push(item.nextSibling);
318
- item = item.nextSibling;
319
- }
320
- }
321
- remove(collection);
322
- }
323
- //滚动到相应的位置
324
- return scrollTop - list.scrollTop;
325
- };
326
- var patchTop = function (deltaY = 0) {
327
- var cache_height = Math.min(list.offsetHeight, screen.height >> 1);
328
-
329
- var childrenMap = getChildrenMap();
330
- var first_element, flag_element = first_element = getFirstElement(1);
331
- if (!flag_element || !isFinite(flag_element.offsetTop)) return;
332
- var offset = flag_element.index || 0;
333
- var offsetTop = flag_element.offsetTop;
334
- var { scrollTop } = list;
335
- scrollTop += deltaY;
336
- //追加元素到顶部
337
- var targetHeight = screen.height + cache_height + first_element.offsetTop;
338
- var { paddingCount, paddingMax } = list;
339
- if (!(paddingCount > 0 && paddingMax > 0 && paddingCount < paddingMax) || !(scrollTop < targetHeight)) {
340
- paddingCount = 0;
285
+ offsetBottom = item.offsetTop + getOffsetHeight(item);
286
+ last_element = item;
287
+ }
288
+ var collection = [];
289
+ for (var k in childrenMap) {
290
+ let item = childrenMap[k];
291
+ if (getNodeTarget(item).offsetTop + getOffsetHeight(item) + limitHeight < scrollTop) {
292
+ collection.push(item);
341
293
  }
342
- while (scrollTop < targetHeight || paddingCount > 0 || offset % list.group) {
343
- offset--;
344
- if (!(scrollTop < targetHeight)) {
345
- paddingCount--;
346
- }
347
- var item = childrenMap[offset];
348
- if (!item) {
349
- item = createItem(offset);
294
+ }
295
+ if (collection.length) {
296
+ var item = collection[collection.length - 1];
297
+ var { paddingCount = 0, paddingMax } = this;
298
+ if (item) item = item.nextSibling;
299
+ if (!paddingMax) while (item && item.index % this.group) {
300
+ item = collection.pop();
301
+ }
302
+ var item = collection[collection.length - 1];
303
+ if (item) scrollTop -= getNodeTarget(item).offsetTop + getOffsetHeight(item) - getNodeTarget(collection[0]).offsetTop;
304
+ if (paddingCount > 0 && paddingMax > 0 && paddingCount < paddingMax) {
305
+ let item = collection[collection.length - 1];
306
+ while (paddingCount > 0) {
350
307
  if (!item) break;
351
- insertBeforeList(item, first_element);
352
- item = getNodeTarget(item);
353
- scrollTop += flag_element.offsetTop - offsetTop;
354
- offsetTop = flag_element.offsetTop;
308
+ paddingCount--;
309
+ collection.push(item.nextSibling);
310
+ item = item.nextSibling;
355
311
  }
356
- first_element = item;
357
312
  }
358
- //滚动到相应位置
359
- if (scrollTop < 0) scrollTop = 0;
360
- //-list_scrollTop + lElem_offsetTop = -list_newScrollTop + lElem_newoffsetTop + deltaY
361
- var last_element = getLastElement(1);
362
- var { clientHeight } = list;
363
- while (last_element && last_element.offsetTop > clientHeight + scrollTop + cache_height) {
364
- remove(last_element);
365
- remove(last_element.$comment);
366
- last_element = getLastElement(1);
313
+ remove(collection);
314
+ }
315
+ //滚动到相应的位置
316
+ return scrollTop - this.scrollTop;
317
+ };
318
+ var patchTop_ = function (deltaY = 0) {
319
+ var cache_height = Math.min(this.offsetHeight, screen.height >> 1);
320
+
321
+ var childrenMap = getChildrenMap(this);
322
+ var first_element, flag_element = first_element = this.getFirstElement(1);
323
+ if (!flag_element || !isFinite(flag_element.offsetTop)) return;
324
+ var offset = flag_element.index || 0;
325
+ var offsetTop = flag_element.offsetTop;
326
+ var { scrollTop } = this;
327
+ scrollTop += deltaY;
328
+ //追加元素到顶部
329
+ var targetHeight = screen.height + cache_height + first_element.offsetTop;
330
+ var { paddingCount, paddingMax } = this;
331
+ if (!(paddingCount > 0 && paddingMax > 0 && paddingCount < paddingMax) || !(scrollTop < targetHeight)) {
332
+ paddingCount = 0;
333
+ }
334
+ while (scrollTop < targetHeight || paddingCount > 0 || offset % this.group) {
335
+ offset--;
336
+ if (!(scrollTop < targetHeight)) {
337
+ paddingCount--;
338
+ }
339
+ var item = childrenMap[offset];
340
+ if (!item) {
341
+ item = this.createItem(offset);
342
+ if (!item) break;
343
+ this.insertBeforeList(item, first_element);
344
+ item = getNodeTarget(item);
345
+ scrollTop += flag_element.offsetTop - offsetTop;
346
+ offsetTop = flag_element.offsetTop;
367
347
  }
368
- return scrollTop - list.scrollTop;
369
- };
370
- var __animated = false;
371
- //滚动一定的距离
372
- var scrollBy = function (deltaY, animate = false) {
373
- var deltaScroll;
374
- if (deltaY > 0) {
375
- deltaScroll = patchBottom(deltaY, animate);
348
+ first_element = item;
349
+ }
350
+ //滚动到相应位置
351
+ if (scrollTop < 0) scrollTop = 0;
352
+ //-list_scrollTop + lElem_offsetTop = -list_newScrollTop + lElem_newoffsetTop + deltaY
353
+ var last_element = this.getLastElement(1);
354
+ var { clientHeight } = this;
355
+ while (last_element && last_element.offsetTop > clientHeight + scrollTop + cache_height) {
356
+ remove(last_element);
357
+ remove(last_element.$comment);
358
+ last_element = this.getLastElement(1);
359
+ }
360
+ return scrollTop - this.scrollTop;
361
+ };
362
+ //滚动一定的距离
363
+ var scrollBy_ = function (deltaY, animate = false) {
364
+ var deltaScroll;
365
+ if (deltaY > 0) {
366
+ deltaScroll = this.patchBottom(deltaY, animate);
367
+ } else {
368
+ deltaScroll = this.patchTop(deltaY, animate);
369
+ }
370
+ if (deltaScroll) {
371
+ if (animate && this.scrollBy_) {
372
+ this.scrollTop += deltaScroll - deltaY;
373
+ this.scrollBy_({
374
+ top: deltaY,
375
+ behavior: 'smooth'
376
+ });
377
+ this.__animated = true;
376
378
  } else {
377
- deltaScroll = patchTop(deltaY, animate);
378
- }
379
- if (deltaScroll) {
380
- if (animate && __scrollBy) {
381
- list.scrollTop += deltaScroll - deltaY;
382
- __scrollBy.call(list, {
383
- top: deltaY,
384
- behavior: 'smooth'
385
- });
386
- __animated = true;
387
- } else {
388
- list.scrollTop += deltaScroll;
389
- __animated = false;
390
- }
379
+ this.scrollTop += deltaScroll;
380
+ this.__animated = false;
391
381
  }
392
- };
393
- bind('resize')(list, function () {
394
- patchBottom(0);
395
- });
396
- list.getLastVisibleElement = getLastVisibleElement;
397
- list.getFirstVisibleElement = getFirstVisibleElement;
398
- var lastY = NaN;
399
- //
382
+ }
383
+ };
384
+
385
+ var $stopY_ = function (t, spd) {
400
386
  // 最大距离 S,最大初始速度 V = a * t = 1,求加速 a
401
387
  // S = 0.5 * a * t * t = 0.5 * V * t;
402
388
  // => t = S * 2 / V = S * 2, a = V / t = 1 / (S * 2);
@@ -404,221 +390,267 @@ function ylist(container, generator, $Y) {
404
390
  // 加速度a = 1 / (S * 2),对任意s,有t = sqrt(2 * s / a) = sqrt(2 * s * S * 2) = 2 * sqrt(s * S);
405
391
  // 对应速度 v = a * t = 1 / (S * 2) * 2 * sqrt(s * S) = sqrt(s * S) / S;
406
392
  // 临近零点的距离 s0 = a / 2 = 1 / (S * 4);
407
- list.$stopY = function (t, spd) {
408
- var firstElement = getFirstVisibleElement();
409
- var lastElement = getLastVisibleElement();
410
- if (!firstElement || !lastElement || !list.clientHeight) return false;
411
- if (isNaN(lastY)) return false;
412
- var paddingTop = parseFloat(getComputedStyle(list).paddingTop);
413
- var paddingBottom = parseFloat(getComputedStyle(list).paddingBottom);
414
- var scrolled_t = (list.scrollTop - firstElement.offsetTop + paddingTop) / firstElement.offsetHeight;
415
- if (scrolled_t > 1) scrolled_t -= scrolled_t | 0;
416
- var last_y = lastY;
417
- if (spd[0] > 0) {
418
- var target_ty = last_y + (1 - scrolled_t) * firstElement.offsetHeight;
419
- } else {
420
- var target_ty = last_y - scrolled_t * firstElement.offsetHeight;
421
- }
422
- var scrolled_b = (list.scrollTop + list.clientHeight - lastElement.offsetTop - paddingBottom) / lastElement.offsetHeight;
423
- if (scrolled_b < 0) scrolled_b -= scrolled_b - 1 | 0;
424
- if (spd[0] > 0) {
425
- var target_by = last_y + (1 - scrolled_b) * lastElement.offsetHeight;
426
- } else {
427
- var target_by = last_y - scrolled_b * lastElement.offsetHeight;
393
+ var firstElement = this.getFirstVisibleElement();
394
+ var lastElement = this.getLastVisibleElement();
395
+ if (!firstElement || !lastElement || !this.clientHeight) return false;
396
+ if (isNaN(this.$lastY_)) return false;
397
+ var paddingTop = parseFloat(getComputedStyle(this).paddingTop);
398
+ var paddingBottom = parseFloat(getComputedStyle(this).paddingBottom);
399
+ var scrolled_t = (this.scrollTop - firstElement.offsetTop + paddingTop) / firstElement.offsetHeight;
400
+ if (scrolled_t > 1) scrolled_t -= scrolled_t | 0;
401
+ var last_y = this.$lastY_;
402
+ if (spd[0] > 0) {
403
+ var target_ty = last_y + (1 - scrolled_t) * firstElement.offsetHeight;
404
+ } else {
405
+ var target_ty = last_y - scrolled_t * firstElement.offsetHeight;
406
+ }
407
+ var scrolled_b = (this.scrollTop + this.clientHeight - lastElement.offsetTop - paddingBottom) / lastElement.offsetHeight;
408
+ if (scrolled_b < 0) scrolled_b -= scrolled_b - 1 | 0;
409
+ if (spd[0] > 0) {
410
+ var target_by = last_y + (1 - scrolled_b) * lastElement.offsetHeight;
411
+ } else {
412
+ var target_by = last_y - scrolled_b * lastElement.offsetHeight;
413
+ }
414
+ var S = calcPixel(30);
415
+ var target_y = Math.abs(target_ty - last_y) > Math.abs(target_by - last_y) ? target_by : target_ty;
416
+ var delta = Math.min(S, this.clientHeight >> 2);
417
+ var absy = Math.abs(target_y - last_y), y;
418
+ if (absy >= delta) {
419
+ return false;
420
+ }
421
+ if (absy < 1) y = target_y;
422
+ else {
423
+ var speed = Math.sqrt(absy * S) / S;
424
+ y = last_y + (target_y > last_y ? speed : -speed);
425
+ }
426
+ this.$Top(y);
427
+ if (target_y === y) {
428
+ return false;
429
+ }
430
+ return true;
431
+ };
432
+ var $Height = function () {
433
+ var elem = this.getLastElement(2);
434
+ var listRestHeight = elem ? elem.offsetHeight + elem.offsetTop - this.scrollTop : this.clientHeight;
435
+ var paddingHeight = elem ? 0 : this.restHeight_;
436
+ if (listRestHeight < this.clientHeight) listRestHeight = this.clientHeight;
437
+ return this.currentY_() + listRestHeight + paddingHeight;
438
+ };
439
+ var $Top = function (y) {
440
+ if (isFinite(y)) {
441
+ this.$lastY_ = y;
442
+ var last_y = this.currentY_();
443
+ if (y !== last_y) {
444
+ this.scrollBy(y - last_y);
428
445
  }
429
- var S = calcPixel(30);
430
- var target_y = Math.abs(target_ty - last_y) > Math.abs(target_by - last_y) ? target_by : target_ty;
431
- var delta = Math.min(S, list.clientHeight >> 2);
432
- var absy = Math.abs(target_y - last_y), y;
433
- if (absy >= delta) {
434
- return false;
446
+ }
447
+ return this.currentY_();
448
+ };
449
+ var index_ = function (update) {
450
+ if (update === false) return this.itemIndex_saved_;
451
+ var firstVisible = this.getFirstVisibleElement(0);
452
+ if (!firstVisible) return this.itemIndex_saved_;
453
+ var index = firstVisible.index;
454
+ firstVisible = getNodeTarget(firstVisible);
455
+ if (!firstVisible) return this.itemIndex_saved_;
456
+ var firstElement = this.getFirstElement(1);
457
+ var scrolled = (this.scrollTop - firstVisible.offsetTop + firstElement.offsetTop + .5 | 0) / firstVisible.offsetHeight;
458
+ return index + scrolled;
459
+ };
460
+ var topIndex_ = function () {
461
+ var element = this.getFirstElement(1);
462
+ return element ? element.index : 0;
463
+ };
464
+ var setFocus_ = function (focused, animate = true) {
465
+ if (isElement(focused) && (focused.hasAttribute("disabled") || focused.hasAttribute("line"))) return;
466
+ if (focused === (focused | 0)) {
467
+ var index = focused;
468
+ focused = this.getIndexedElement(index);
469
+ if (!focused) {
470
+ this.go(index);
471
+ focused = this.getIndexedElement(index);
435
472
  }
436
- if (absy < 1) y = target_y;
437
- else {
438
- var speed = Math.sqrt(absy * S) / S;
439
- y = last_y + (target_y > last_y ? speed : -speed);
473
+ }
474
+ if (!focused) {
475
+ if (this.focused) {
476
+ removeClass(this.focused, 'focus');
477
+ this.focused = null;
440
478
  }
441
- list.$Top(y);
442
- if (target_y === y) {
479
+ return;
480
+ }
481
+ if (this.focused === focused) return;
482
+ if (this.focused) removeClass(this.focused, 'focus');
483
+ addClass(focused, "focus");
484
+ this.focused = focused;
485
+ while (focused && focused.parentNode !== this) focused = focused.parentNode;
486
+ if (!focused) return;
487
+ var scrollTop = this.scrollTop;
488
+ var firstElement = this.getFirstElement(1);
489
+ var sideheight = 0;
490
+ if (firstElement) {
491
+ sideheight += parseFloat(getComputedStyle(firstElement).paddingTop + firstElement.clientTop);
492
+ sideheight += (firstElement.offsetHeight - sideheight - sideheight) * .3;
493
+ sideheight += parseFloat(getComputedStyle(this).paddingTop);
494
+ }
495
+ if (focused.offsetTop + focused.offsetHeight + sideheight > this.scrollTop + this.clientHeight) {
496
+ scrollTop = focused.offsetTop + focused.offsetHeight + sideheight - this.clientHeight;
497
+ }
498
+ if (focused.offsetTop < this.scrollTop + sideheight) {
499
+ scrollTop = focused.offsetTop - sideheight;
500
+ }
501
+ if (scrollTop !== this.scrollTop) this.scrollBy(scrollTop - this.scrollTop, animate);
502
+ };
503
+
504
+ var moveFocus_ = function (delta, emit = true) {
505
+ var focused = this.focused;
506
+ var newIndex = 0, total = 0;
507
+ if (delta === 'up') delta = -1;
508
+ if (delta === 'down') delta = 1;
509
+ if (typeof delta === 'string') switch (delta.toLowerCase()) {
510
+ case "home":
511
+ newIndex = 0;
512
+ delta = 1;
513
+ break;
514
+ case "end":
515
+ var lastElement = this.getLastElement(1);
516
+ if (!lastElement) return;
517
+ newIndex = lastElement.index;
518
+ delta = -1;
519
+ break;
520
+ case "pageup":
521
+ var firstElement = this.getFirstVisibleElement();
522
+ if (!firstElement) return;
523
+ newIndex = firstElement.index;
524
+ this.scrollBy(-this.clientHeight + firstElement.offsetHeight);
525
+ var lastElement = this.getLastVisibleElement();
526
+ if (lastElement.index < newIndex) newIndex = lastElement.index;
527
+ delta = -1;
528
+ break;
529
+ case "pagedown":
530
+ var lastElement = this.getLastVisibleElement();
531
+ if (!lastElement) return;
532
+ newIndex = lastElement.index;
533
+ this.scrollBy(this.clientHeight - lastElement.offsetHeight);
534
+ var firstElement = this.getFirstVisibleElement();
535
+ if (firstElement.index > newIndex) newIndex = firstElement.index;
536
+ delta = 1;
537
+ break;
538
+ default:
443
539
  return false;
444
- }
445
- return true;
446
- };
447
- //导出方法
448
- list.go = scrollTo;
449
- list.$Height = function () {
450
- var elem = getLastElement(2);
451
- var listRestHeight = elem ? elem.offsetHeight + elem.offsetTop - list.scrollTop : list.clientHeight;
452
- var paddingHeight = elem ? 0 : restHeight;
453
- if (listRestHeight < list.clientHeight) listRestHeight = list.clientHeight;
454
- return currentY() + listRestHeight + paddingHeight;
455
- };
456
- list.$Top = function (y) {
457
- if (isFinite(y)) {
458
- lastY = y;
459
- var last_y = currentY();
460
- if (y !== last_y) {
461
- scrollBy(y - last_y);
540
+ }
541
+ else if (!focused) {
542
+ var lastElement = this.getLastElement(1);
543
+ if (!lastElement) return;
544
+ total = lastElement.index + 1;
545
+ if (delta > 0) newIndex = 0;
546
+ else newIndex = total - 1;
547
+ }
548
+ else {
549
+ var newIndex = focused.index + delta;
550
+ var lastElement = this.getLastElement(1);
551
+ var total = lastElement.index + 1;
552
+ if (newIndex < 0) newIndex = total + newIndex;
553
+ if (newIndex > total - 1) newIndex = newIndex - total;
554
+ }
555
+ var savedIndex = newIndex;
556
+ var e = this.getIndexedElement(newIndex);
557
+ while (e && (e.hasAttribute("disabled") || e.hasAttribute("line"))) {
558
+ if (delta > 0) {
559
+ newIndex++;
560
+ if (newIndex >= total) {
561
+ if (!total) return;
562
+ newIndex = 0;
563
+ }
564
+ } else {
565
+ newIndex--;
566
+ if (newIndex < 0) {
567
+ if (!total) return;
568
+ newIndex = total - 1;
462
569
  }
463
570
  }
464
- return currentY();
465
- };
466
- if (!/^i(Phone|Pod|Watch|Pad)|^Mac/i.test(navigator.platform)) var __scrollBy = list.scrollBy;
467
- list.scrollBy = scrollBy;
468
- list.index = function (update) {
469
- if (update === false) return saved_itemIndex;
470
- var firstVisible = getFirstVisibleElement(0);
471
- if (!firstVisible) return saved_itemIndex;
472
- var index = firstVisible.index;
473
- firstVisible = getNodeTarget(firstVisible);
474
- if (!firstVisible) return saved_itemIndex;
475
- var firstElement = getFirstElement(1);
476
- var scrolled = (list.scrollTop - firstVisible.offsetTop + firstElement.offsetTop + .5 | 0) / firstVisible.offsetHeight;
477
- return index + scrolled;
478
- };
479
- list.topIndex = function () {
480
- var element = getFirstElement(1);
481
- return element ? element.index : 0;
482
- };
483
- list.getIndexedElement = getIndexedElement;
484
- list.patchBottom = patchBottom;
485
- list.patchTop = patchTop;
486
- list.scrollIfNotCover = scrollIfNotCover;
487
- list.getLastElement = getLastElement;
488
- vbox(list, $Y);
489
- on("remove")(list, function () {
490
- saved_itemIndex = list.index();
491
- });
492
- onmounted(list, function () {
493
- if (isFinite(saved_itemIndex)) list.go(saved_itemIndex);
494
- });
571
+ if (savedIndex === newIndex) return;
572
+ e = this.getIndexedElement(newIndex);
573
+ }
574
+ if (!e) this.setFocus(null);
575
+ else if (emit) this.setFocus(e, true), dispatch(this, 'focused');
576
+ else this.setFocus(e);
577
+ };
578
+ var mounted = function () {
579
+ if (isFinite(this.itemIndex_saved_)) this.go(this.itemIndex_saved_);
580
+ };
581
+ var unmount = function () {
582
+ this.itemIndex_saved_ = this.index();
583
+ };
584
+ var resize = function () {
585
+ this.patchBottom(0);
586
+ };
587
+
588
+ const cache_height = 2000;
589
+ function ylist(container, generator, $Y) {
590
+ /**
591
+ * @type {HTMLElement}
592
+ */
593
+ var list = container;
594
+ list.$restHeight_ = cache_height;
595
+ list.autoFix = true;
596
+ list.itemIndex_saved_ = 0;
597
+ addClass(list, 'list-y');
598
+ list.__animated = false;
599
+ list.__generator = generator;
600
+ list.currentY_ = currentY_;
601
+
602
+ bind('resize')(list, resize);
603
+ list.getLastVisibleElement = getLastVisibleElement_;
604
+ list.getFirstVisibleElement = getFirstVisibleElement_;
605
+ list.$lastY_ = NaN;
606
+ list.$Height = $Height;
607
+ list.$Top = $Top;
608
+ list.index = index_;
609
+ list.topIndex = topIndex_;
610
+ list.setFocus = setFocus_;
611
+ list.moveFocus = moveFocus_;
612
+ //导出方法
613
+ list.go = scrollTo_;
614
+ this.scrollTo = scrollTo_;
615
+
616
+ if (list.scrollBy !== scrollBy_ && !/^i(Phone|Pod|Watch|Pad)|^Mac/i.test(navigator.platform)) list.scrollBy_ = list.scrollBy;
617
+ list.scrollBy = scrollBy_;
618
+
619
+
620
+ list.getIndexedElement = getIndexedElement_;
621
+ list.patchBottom = patchBottom_;
622
+ list.patchTop = patchTop_;
623
+ list.scrollIfNotCover = scrollIfNotCover_;
624
+ list.getFirstElement = getFirstElement_;
625
+ list.createItem = createItem_;
626
+ list.generator_ = generator;
627
+ list.insertBeforeList = insertBeforeList_;
628
+ list.getLastElement = getLastElement_;
629
+ list.hasCover = hasCover_;
630
+
631
+ vbox(list, 'Y');
632
+
633
+ on("remove")(list, unmount);
634
+ onmounted(list, mounted);
495
635
  /**
496
636
  * @param {Element|null} focused
497
637
  * @param {boolean} animate
498
638
  */
499
- list.setFocus = function (focused, animate = true) {
500
- if (isElement(focused) && (focused.hasAttribute("disabled") || focused.hasAttribute("line"))) return;
501
- if (focused === (focused | 0)) {
502
- var index = focused;
503
- focused = list.getIndexedElement(index);
504
- if (!focused) {
505
- list.go(index);
506
- focused = list.getIndexedElement(index);
507
- }
508
- }
509
- if (!focused) {
510
- if (list.focused) {
511
- removeClass(list.focused, 'focus');
512
- list.focused = null;
513
- }
514
- return;
515
- }
516
- if (list.focused === focused) return;
517
- if (list.focused) removeClass(list.focused, 'focus');
518
- addClass(focused, "focus");
519
- list.focused = focused;
520
- while (focused && focused.parentNode !== list) focused = focused.parentNode;
521
- if (!focused) return;
522
- var scrollTop = list.scrollTop;
523
- var firstElement = getFirstElement(1);
524
- var sideheight = 0;
525
- if (firstElement) {
526
- sideheight += parseFloat(getComputedStyle(firstElement).paddingTop + firstElement.clientTop);
527
- sideheight += (firstElement.offsetHeight - sideheight - sideheight) * .3;
528
- sideheight += parseFloat(getComputedStyle(list).paddingTop);
529
- }
530
- if (focused.offsetTop + focused.offsetHeight + sideheight > list.scrollTop + list.clientHeight) {
531
- scrollTop = focused.offsetTop + focused.offsetHeight + sideheight - list.clientHeight;
532
- }
533
- if (focused.offsetTop < list.scrollTop + sideheight) {
534
- scrollTop = focused.offsetTop - sideheight;
535
- }
536
- if (scrollTop !== list.scrollTop) scrollBy(scrollTop - list.scrollTop, animate);
537
- };
639
+
538
640
 
539
641
  /**
540
642
  * @param {number|"up"|"down"|"home"|"end"|"pageup"|"pagedown"}delta
541
643
  * @param {boolean} emit
542
644
  */
543
- list.moveFocus = function (delta, emit = true) {
544
- var focused = list.focused;
545
- var newIndex = 0, total = 0;
546
- if (delta === 'up') delta = -1;
547
- if (delta === 'down') delta = 1;
548
- if (typeof delta === 'string') switch (delta.toLowerCase()) {
549
- case "home":
550
- newIndex = 0;
551
- delta = 1;
552
- break;
553
- case "end":
554
- var lastElement = getLastElement(1);
555
- if (!lastElement) return;
556
- newIndex = lastElement.index;
557
- delta = -1;
558
- break;
559
- case "pageup":
560
- var firstElement = getFirstVisibleElement();
561
- if (!firstElement) return;
562
- newIndex = firstElement.index;
563
- list.scrollBy(-list.clientHeight + firstElement.offsetHeight);
564
- var lastElement = getLastVisibleElement();
565
- if (lastElement.index < newIndex) newIndex = lastElement.index;
566
- delta = -1;
567
- break;
568
- case "pagedown":
569
- var lastElement = getLastVisibleElement();
570
- if (!lastElement) return;
571
- newIndex = lastElement.index;
572
- list.scrollBy(list.clientHeight - lastElement.offsetHeight);
573
- var firstElement = getFirstVisibleElement();
574
- if (firstElement.index > newIndex) newIndex = firstElement.index;
575
- delta = 1;
576
- break;
577
- default:
578
- return false;
579
- }
580
- else if (!focused) {
581
- var lastElement = getLastElement(1);
582
- if (!lastElement) return;
583
- total = lastElement.index + 1;
584
- if (delta > 0) newIndex = 0;
585
- else newIndex = total - 1;
586
- }
587
- else {
588
- var newIndex = focused.index + delta;
589
- var lastElement = getLastElement(1);
590
- var total = lastElement.index + 1;
591
- if (newIndex < 0) newIndex = total + newIndex;
592
- if (newIndex > total - 1) newIndex = newIndex - total;
593
- }
594
- var savedIndex = newIndex;
595
- var e = list.getIndexedElement(newIndex);
596
- while (e && (e.hasAttribute("disabled") || e.hasAttribute("line"))) {
597
- if (delta > 0) {
598
- newIndex++;
599
- if (newIndex >= total) {
600
- if (!total) return;
601
- newIndex = 0;
602
- }
603
- } else {
604
- newIndex--;
605
- if (newIndex < 0) {
606
- if (!total) return;
607
- newIndex = total - 1;
608
- }
609
- }
610
- if (savedIndex === newIndex) return;
611
- e = list.getIndexedElement(newIndex);
612
- }
613
- if (!e) list.setFocus(null);
614
- else if (emit) list.setFocus(e, true), dispatch(list, 'focused');
615
- else list.setFocus(e);
616
- };
617
- list.getRelativeElement = getRelativeElement;
645
+
646
+ list.getRelativeElement = getRelativeElement_;
618
647
  return list;
619
648
  }
649
+
620
650
  var allArgumentsNames = arguments[arguments.length - 1];
621
- var xlist = arriswise(ylist, allArgumentsNames.concat([].slice.call(arguments, 0)));
651
+ if (allArgumentsNames.done) return ylist;
652
+ allArgumentsNames.done = true;
653
+ var xlist = arriswise.call(this, arguments[arguments.length - 3], arguments).apply(this, arguments);
622
654
 
623
655
  var getGeneratorFromArray = function (source) {
624
656
  return function (index) {
@@ -706,4 +738,5 @@ function list() {
706
738
  remove(children);
707
739
  };
708
740
  return list;
709
- }
741
+ }
742
+ return list;