efront 3.22.6 → 3.22.7

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.
@@ -282,12 +282,12 @@ function single(c, u) {
282
282
  return [r * u, g * u, b * u];
283
283
  }
284
284
  function angle(c1, c2) {
285
+ c1 = parse(c1);
286
+ c2 = parse(c2);
287
+ c1 = normal(c1);
288
+ c2 = normal(c2);
285
289
  var theta = rgb2h(c2[0], c2[1], c2[2]) - rgb2h(c1[0], c1[1], c1[2]);
286
290
  if (theta < 0) theta += 360;
287
- // c1 = parse(c1);
288
- // c2 = parse(c2);
289
- // c1 = normal(c1);
290
- // c2 = normal(c2);
291
291
  // var [r1, g1, b1] = single(c1);
292
292
  // var [r2, g2, b2] = single(c2);
293
293
  // var c = [g1 * b2 - g2 * b1, b1 * r2 - b2 * r1, r1 * g2 - r2 * g1];
@@ -52,15 +52,17 @@ var power = function (source, search) {
52
52
  var match_text_pre = source.slice(0, match_start2);
53
53
  var match_text_aft = source.slice(match_start2 + match_text.length);
54
54
  var pp = 0, ap = 0;
55
+ var p = match_text.length;
56
+ if (match_text_pre.length) p += .1 / match_text_pre.length - .2;
57
+ if (match_text_aft.length) p += .1 / match_text_aft.length - .1;
55
58
  if (match_text_pre.length > 1) {
56
59
  [pp, match_text_pre] = power(match_text_pre, search);
57
60
  }
58
61
  if (match_text_aft.length > 1) {
59
62
  [ap, match_text_aft] = power(match_text_aft, search);
60
63
  }
61
- var p = match_text.length;
62
- p *= p;
63
- return [p + pp + ap, match_text_pre + MARK_PRE + match_text + MARK_AFT + match_text_aft];
64
+ p += (pp + ap) * .01;
65
+ return [p, match_text_pre + MARK_PRE + match_text + MARK_AFT + match_text_aft];
64
66
  }
65
67
  return [0, source];
66
68
  };
@@ -1,19 +1,77 @@
1
1
  function search(seartext, options, path = "name") {
2
- if (options instanceof Array) {
3
- var hasFullmatch = false;
4
- var a = options.map(o => {
5
- var name = seek(o, path);
6
- if (name === seartext) hasFullmatch = true;
7
- var [power, m] = mark.power(name, seartext);
8
- o = Object.create(o);
9
- o.power = power;
10
- if (path) o[path] = m;
11
- return o;
12
- }).filter(a => a.power > 0);
13
- a.sort(function (a, b) {
14
- return b.power - a.power;
15
- });
16
- a.hasFullmatch = hasFullmatch;
17
- return a;
2
+ var a = new SearchResult;
3
+ a.searchPath = path;
4
+ a.searchText = seartext;
5
+ a.source = options;
6
+ if (a.searchText) a.start();
7
+ return a;
8
+ }
9
+ function minusPower(a, b) {
10
+ return a.power - b.power >= 0;
11
+ }
12
+ function returnName() {
13
+ return this.name;
14
+ }
15
+ class SearchResult extends Array {
16
+ searchPath = 'name';
17
+ searchText = null;
18
+ source = null;
19
+ complete = true;
20
+ searched = 0;
21
+ searchid = 0;
22
+ hasFullmatch = false;
23
+ callback = null;
24
+ addItem(o) {
25
+ var path = this.searchPath;
26
+ var seartext = this.searchText;
27
+ if (isEmpty(o)) return;
28
+ var name = seek(o, path);
29
+ if (name === seartext) this.hasFullmatch = true;
30
+ var [power, m] = mark.power(name, seartext);
31
+ if (isNode(o)) {
32
+ o = extend({
33
+ name: o.name,
34
+ title: o.title,
35
+ value: o.value,
36
+ key: o.key,
37
+ nodeType: o.nodeType,
38
+ tagName: o.tagName,
39
+ nodeValue: o.nodeValue,
40
+ }, o);
41
+ }
42
+ else o = isObject(o) ? Object.create(o) : new o.constructor(o);
43
+ o.power = power;
44
+ if (isString(path)) o[path] = m;
45
+ else o.name = m, o.toString = returnName, o.valueOf = returnName;
46
+ if (o.power > 0) {
47
+ saveToOrderedArray(this, o, minusPower);
48
+ }
49
+ }
50
+ search(text, callback) {
51
+ if (isFunction(callback)) this.callback = callback;
52
+ if (text === this.searchText) return;
53
+ this.searchText = text;
54
+ this.start();
55
+ }
56
+ async start() {
57
+ this.searched = 0;
58
+ this.splice(0, this.length);
59
+ var searchid = ++this.searchid;
60
+ this.complete = false;
61
+ if (this.searchText) for (var o of this.source) {
62
+ this.addItem(o);
63
+ if (++this.searched % 6000 === 0) {
64
+ if (isFunction(this.callback)) this.callback();
65
+ await new Promise(function (ok) {
66
+ setTimeout(ok, 20)
67
+ });
68
+ if (this.searchid !== searchid) break;
69
+ }
70
+ }
71
+ this.complete = true;
72
+ if (isFunction(this.callback)) this.callback();
73
+ }
74
+ abort() {
75
+ this.searchid++;
18
76
  }
19
77
  }
@@ -124,7 +124,7 @@ function select(target, list, removeOnSelect, direction) {
124
124
  var initList2 = function (src) {
125
125
  src.forEach(s => {
126
126
  optionsMap[s.key] = s;
127
- s.selected = s.key === target.value;
127
+ if (isObject(s)) s.selected = s.key === target.value;
128
128
  });
129
129
  list = selectList(generator, src, !!target.multiple, !!target.editable);
130
130
  list.value = target.value;
@@ -183,6 +183,7 @@ function select(target, list, removeOnSelect, direction) {
183
183
  if (!target.multiple) {
184
184
  onclick(list, onlistclick);
185
185
  }
186
+ removeOnSelect = undefined;
186
187
  bindEvent();
187
188
  };
188
189
  }
@@ -2,7 +2,7 @@ var singleClick = function () {
2
2
  var node = this.parentNode;
3
3
  if (node.activeNode === this) return;
4
4
  if (node.activeNode) {
5
- if (node.activeNode.origin) node.activeNode.origin.selected = false;
5
+ if (isObject(node.activeNode.origin)) node.activeNode.origin.selected = false;
6
6
  node.activeNode.removeAttribute("selected");
7
7
  }
8
8
  this.setAttribute("selected", "");
@@ -11,8 +11,9 @@ var singleClick = function () {
11
11
  if (node.value === this.value) return;
12
12
  node.value = this.value;
13
13
  node.name = this.name;
14
- if (this.origin) this.origin.selected = true;
14
+ if (isObject(this.origin)) this.origin.selected = true;
15
15
  dispatch(node, "change");
16
+ if (getTargetIn(node, document.activeElement)) document.activeElement.blur();
16
17
  };
17
18
  var multipleClick = function () {
18
19
  var node = this.parentNode;
@@ -25,10 +26,15 @@ var multipleClick = function () {
25
26
  values.splice(index, 1);
26
27
  this.removeAttribute("selected");
27
28
  }
28
- if (this.origin) this.origin.selected = true;
29
+ if (isObject(this.origin)) this.origin.selected = true;
29
30
  dispatch(node, "change");
30
31
  };
31
32
 
33
+ var searchinput = function () {
34
+ var ipt = document.createElement("input");
35
+ ipt.placeholder = '搜索';
36
+ return ipt;
37
+ };
32
38
 
33
39
  function main() {
34
40
  var children, multiple, addable, generator, page;
@@ -101,9 +107,46 @@ function main() {
101
107
 
102
108
 
103
109
  var hasIcon = false, iconed = '';
110
+
111
+ if (children.length > 6) {
112
+ var ipt = searchinput()
113
+ page.insertBefore(ipt, page.firstChild);
114
+ var searchtext = function () {
115
+ if (this.value) children = searchResult;
116
+ else children = searchResult.source;
117
+ if (isMounted(this)) searchResult.search(this.value);
118
+ };
119
+ var searchResult = search(ipt.value, children, a => {
120
+ return isObject(a) ? getName(a) : String(a);
121
+ });
122
+ searchResult.callback = function () {
123
+ if (!searchResult.complete) {
124
+ page.setAttribute('searching', '');
125
+ }
126
+ else {
127
+ if (searchResult.searchText && !searchResult.length) {
128
+ page.setAttribute('empty', '');
129
+ }
130
+ else {
131
+ page.removeAttribute('empty');
132
+ }
133
+ page.removeAttribute('searching');
134
+ }
135
+ itemMap = Object.create(null);
136
+ page.clean();
137
+ page.go(0);
138
+ }
139
+ on('remove')(ipt, function () {
140
+ searchResult.abort();
141
+ });
142
+ on('input')(ipt, searchtext);
143
+ on('keyup')(ipt, searchtext);
144
+ on('change')(ipt, searchtext);
145
+
146
+ }
104
147
  var page = list(page, function (i) {
105
148
  if (i < 0 || i >= children.length) return;
106
- return createItem(generator ? generator(i) : children[i]);
149
+ return createItem(generator ? generator(i, children[i]) : children[i]);
107
150
  });
108
151
  once("mounted")(page, function () {
109
152
  var index = 0;
@@ -220,6 +263,6 @@ function main() {
220
263
  };
221
264
  bind('keydown.enter')(page, enter);
222
265
  bind('keydown.space')(page, enter);
223
- on('mousedown')(page, e => e.preventDefault());
266
+ on('mousedown')(page, e => !/^input$/i.test(e.target.tagName) && e.preventDefault());
224
267
  return page;
225
268
  }
@@ -78,4 +78,50 @@
78
78
  vertical-align: top;
79
79
  margin-left: 10px;
80
80
  }
81
+ }
82
+
83
+ &>input {
84
+ height: 28px;
85
+ line-height: 28px;
86
+ padding: 0 16px;
87
+ border: none;
88
+ appearance: none;
89
+ width: 100%;
90
+ min-width: 0;
91
+ box-sizing: border-box;
92
+ display: block;
93
+ position: sticky;
94
+ top: 0;
95
+ border-bottom: 1px solid #0006;
96
+
97
+ &:focus {
98
+ outline-offset: -1px;
99
+ outline: 1px solid #2ca2f9;
100
+ }
101
+ }
102
+
103
+ &[searching] {
104
+ &::before {
105
+ content: "正在搜索..";
106
+ position: absolute;
107
+ left: 0;
108
+ top: 0;
109
+ right: 0;
110
+ display: block;
111
+ font-size: 12px;
112
+ text-align: right;
113
+ pointer-events: none;
114
+ padding: 0 16px;
115
+ }
116
+ }
117
+
118
+ &[empty] {
119
+ background-color: #fff;
120
+ }
121
+
122
+ b {
123
+ border: 1px solid #29e;
124
+ background-color: #29e2;
125
+ font-weight: 400;
126
+ border-radius: 2px;
81
127
  }
@@ -10,5 +10,5 @@
10
10
  </select>
11
11
  <select -src="(o,i) in options6000">
12
12
  <option value="" insert selected>60000个选项</option>
13
- <option -text="'选项'+o">选项</option>
13
+ <option -html="'选项'+o">选项</option>
14
14
  </select>
@@ -7,50 +7,36 @@ function createTouchEvent(eventtype, extra = {}) {
7
7
  }
8
8
 
9
9
 
10
- function _test_scroll(banner) {
11
- var clientY = 10;
12
- var touchstartEvent = createTouchEvent("touchstart", { clientY });
10
+ function _test_scroll() {
11
+ var banner = this;
12
+ var clientY = 2;
13
+ var touchstartEvent = createTouchEvent("touchstart", { clientY, clientX: 0 });
13
14
  var deltaY = 100;
15
+ onclick.preventClick = true;
14
16
  dispatch(banner, touchstartEvent);
15
17
  var interval_handle = setInterval(function () {
16
- clientY -= deltaY;
17
- var touchmoveEvent = createTouchEvent("touchmove", { clientY });
18
- dispatch(banner, touchmoveEvent);
18
+ clientY += deltaY;
19
+ var touchmoveEvent = createTouchEvent("touchmove", { clientY, clientX: 0 });
20
+ dispatch(window, touchmoveEvent);
19
21
  }, 10);
20
22
 
21
23
  setTimeout(function () {
22
- deltaY = -10
23
- }, 300);
24
+ deltaY = -2
25
+ }, 200);
24
26
  setTimeout(function () {
25
- deltaY = 100
27
+ deltaY = 5
26
28
  }, 400);
27
- setTimeout(function () {
28
- deltaY = -10
29
- }, 420);
30
- setTimeout(function () {
31
- deltaY = -50
32
- }, 450);
33
- setTimeout(function () {
34
- deltaY = 50
35
- }, 470);
36
- setTimeout(function () {
37
- deltaY = -100050
38
- }, 480);
39
- setTimeout(function () {
40
- deltaY = +100050
41
- }, 490);
42
29
  setTimeout(function () {
43
30
  clearInterval(interval_handle);
31
+ }, 510);
32
+ setTimeout(function () {
44
33
  var touchendEvent = createTouchEvent("touchend");
34
+ touchendEvent.touches.pop();
45
35
  dispatch(banner, touchendEvent);
46
- }, 510);
36
+ }, 560);
47
37
  }
48
38
 
49
- function main(banner){
50
- if(banner.isMounted){
51
- _test_scroll(banner);
52
- }else{
53
- on("append")(banner,_test_scroll);
54
- }
39
+ function main(banner) {
40
+ oncemount(banner, _test_scroll);
55
41
 
56
42
  }
@@ -2,7 +2,7 @@ function vbox_test() {
2
2
  var vbox1 = vbox();
3
3
  var vbox2 = vbox();
4
4
  vbox2.innerHTML = '<span></span>';
5
- test_scroll(vbox2);
6
5
  appendChild(vbox1, vbox2);
6
+ test_scroll(vbox2);
7
7
  return vbox1;
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.22.6",
3
+ "version": "3.22.7",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {