efront 3.25.8 → 3.25.12

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,3 +1,15 @@
1
+ /**
2
+ * @param {Item} item
3
+ */
4
+ function pathTo(find, item, path) {
5
+ path.push(item);
6
+ if (item === find || find === item.value) {
7
+ return path;
8
+ }
9
+ for (var m of item) {
10
+ if (pathTo(find, m, path)) return path;
11
+ }
12
+ }
1
13
  var id = 0;
2
14
  class Item extends Array {
3
15
  extended = false;
@@ -60,7 +72,9 @@ class Item extends Array {
60
72
  if (isObject(this.value)) return getName(this.value);
61
73
  return String(this.value);
62
74
  }
63
-
75
+ pathTo(menu) {
76
+ return pathTo(menu, this, []);
77
+ }
64
78
  isClosed() {
65
79
  if (isObject(this.value)) return !!this.value.closed;
66
80
  return this.closed;
@@ -1,7 +1,7 @@
1
1
  var notMatchLength = new Error("矩阵长度不一致");
2
2
  class Matrix extends Array {
3
3
  static create2d(theta = 0) {
4
- return MatrixTransposed.matrix2d(theta);
4
+ return MathMatrix.matrix2d(theta);
5
5
  }
6
6
  static create3d(factor = [0, 0, 0]) {
7
7
  return MathMatrix.matrix3d(factor);
@@ -83,6 +83,10 @@ class Matrix extends Array {
83
83
  }
84
84
  }
85
85
  class MathMatrix extends Matrix {
86
+ toDOMString() {
87
+ if (this.size()[1] === 2) return `matrix(${[this[0], this[1], this[3], this[4], this[6], this[7]]})`;
88
+ return `matrix(${this})`;
89
+ }
86
90
 
87
91
  static transform(B, dots) {
88
92
  var dimention = Math.sqrt(B.length - 1) | 0;
@@ -217,6 +221,10 @@ class MathMatrix extends Matrix {
217
221
 
218
222
  }
219
223
  class MatrixTransposed extends Matrix {
224
+ toDOMString() {
225
+ if (this.size()[1] === 2) return `matrix(${[this[0], this[3], this[1], this[4], this[2], this[5]]})`;
226
+ return `matrix(${this.transpose()})`;
227
+ }
220
228
  static transform(B, dots) {
221
229
  var dimention = Math.sqrt(B.length - 1) | 0;
222
230
  if (dots.length % dimention !== 0) throw notMatchLength;
@@ -1,5 +1,14 @@
1
+ var [
2
+ /* 静止 */静止,
3
+ /* 停止 */停止,
4
+ /* 移动 */移动,
5
+ /* 减速 */减速,
6
+ /* 回弹 */回弹,
7
+ /* 停靠 */停靠,
8
+ ] = new Array(6).fill(0).map((_, i) => i);
9
+
1
10
  function inertia(gun) {
2
- var _decreased = 0, spd = new Speed;
11
+ var spd = new Speed;
3
12
  var lastTime = 0;
4
13
  var _decrease = function () {
5
14
  lastTime = Speed.now() - 1;
@@ -9,14 +18,15 @@ function inertia(gun) {
9
18
  if (
10
19
  decrease instanceof Function
11
20
  ) {
12
- if (!spd.length || _decreased > 0 && spd.filter(a => a !== 0).length === 0) return;
21
+ if (!spd.length) return;
13
22
  var id = smooth_timer;
14
23
  var now = Speed.now();
15
- var res = decrease(now - lastTime, spd);
24
+ var res = decrease.call(that, now - lastTime, spd);
16
25
  lastTime = now;
17
26
  if (smooth_timer !== id) return;
18
27
  if (res === false || isEmpty(res)) {
19
28
  spd.unset();
29
+ train.state = 停止;
20
30
  return;
21
31
  }
22
32
  smooth_timer = requestAnimationFrame(_decrease0);
@@ -24,24 +34,21 @@ function inertia(gun) {
24
34
  };
25
35
  var _cancel = function () {
26
36
  cancelAnimationFrame(smooth_timer);
27
- _decreased = 0;
28
37
  decrease = null;
29
38
  }
30
39
  var smooth = function () {
31
40
  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
41
  var id = smooth_timer;
41
42
  var res = gun.apply(that, args);
42
43
  if (id !== smooth_timer) return;
43
44
  if (false === res) {
44
45
  spd.reset();
46
+ train.state = 回弹;
47
+ smooth_timer = requestAnimationFrame(_decrease);
48
+ return;
49
+ }
50
+ if (decrease && args.filter(a => Math.abs(a) > 1).length === 0) {
51
+ train.state = 回弹;
45
52
  smooth_timer = requestAnimationFrame(_decrease);
46
53
  return;
47
54
  }
@@ -52,21 +59,45 @@ function inertia(gun) {
52
59
  _cancel();
53
60
  var args = [].slice.call(arguments, 0, arguments.length);
54
61
  spd.write(args);
62
+ if (train.state !== 移动) train.state = 移动;
55
63
  gun.apply(this, args);
56
64
  that = this;
57
65
  };
58
66
  train.smooth = function (d) {
59
67
  _cancel();
60
68
  decrease = d;
61
- smooth_timer = requestAnimationFrame(smooth);
69
+ if (train.state === 移动) {
70
+ train.state = 减速;
71
+ smooth_timer = requestAnimationFrame(smooth);
72
+ }
73
+ else if (train.state === 回弹 || train.state === 停靠) {
74
+ train.state = 停靠;
75
+ smooth_timer = requestAnimationFrame(_decrease);
76
+ }
62
77
  };
63
- train.reset = function () {
78
+ train.state = 静止;
79
+ train.reset = train.start = function () {
64
80
  _cancel();
65
- spd.reset();
81
+ spd.unset();
82
+ train.state = 静止;
66
83
  };
67
84
  return train;
68
85
 
69
86
  }
87
+
88
+ inertia.静止 = 静止;
89
+ inertia.停止 = 停止;
90
+ inertia.移动 = 移动;
91
+ inertia.减速 = 减速;
92
+ inertia.回弹 = 回弹;
93
+ inertia.停靠 = 停靠;
94
+ inertia.STAND = 静止;
95
+ inertia.STOPPING = 停止;
96
+ inertia.MOVING = 移动;
97
+ inertia.SLOWING_DWON = 减速;
98
+ inertia.REBOUNDING = 回弹;
99
+ inertia.DOCKING = 停靠;
100
+
70
101
  class Speed extends Array {
71
102
  cache = [];
72
103
  stamp = 0;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 为可能正在加载的元素添加then方法
3
+ * 占用onload onerror complete then 共4个属性
4
+ * @param {Element|Object|any} image;
5
+ */
6
+ function awaitable(image) {
7
+ if (image.complete) return image;
8
+ var oks = [];
9
+ var ohs = [];
10
+ var resolved = false,
11
+ errored = false,
12
+ error = null;
13
+ var fire = function () {
14
+ if (resolved || errored) {
15
+ var _oks = oks.splice(0, oks.length);
16
+ var _ohs = ohs.splice(0, ohs.length);
17
+ if (errored) for (var o of _ohs) o(error);
18
+ delete image.then;
19
+ if (resolved) for (var o of _oks) o(image);
20
+ image.then = then;
21
+ }
22
+ };
23
+ var then = image.then = function (ok, oh) {
24
+ if (ok) oks.push(ok);
25
+ if (oh) ohs.push(oh);
26
+ fire();
27
+ };
28
+ image.onload = function () {
29
+ if (resolved || errored) return;
30
+ resolved = true;
31
+ if (!image.complete) image.complete = true;
32
+ fire();
33
+ };
34
+ image.onerror = function (e) {
35
+ if (resolved || errored) return;
36
+ errored = true;
37
+ error = e;
38
+ fire();
39
+ };
40
+ return image;
41
+ }
@@ -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,10 +1,16 @@
1
+ function set(target, k, v) {
2
+ if (target.getAttribute(k) !== v) target.setAttribute(k, v);
3
+ }
4
+ function unset(target, k) {
5
+ if (target.hasAttribute(k)) target.removeAttribute(k);
6
+ }
1
7
  function attr(target, key, value) {
2
8
  if (arguments.length === 3) {
3
- if (value === null) target.removeAttribute(key, value);
4
- else target.setAttribute(key, value);
9
+ if (value === null) unset(target, key);
10
+ else set(target, key, value);
5
11
  } else if (isObject(key)) {
6
12
  for (var k in key) {
7
- target.setAttribute(k, key[k]);
13
+ set(target, k, key[k]);
8
14
  }
9
15
  } else if (isString(key)) {
10
16
  return target.getAttribute(key);
@@ -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,19 +20,24 @@ 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
- removeFromList(keyMap[k], btn);
28
- keyMap[k].push(btn);
29
- once("remove")(btn, function () {
34
+ on("remove")(btn, function () {
30
35
  removeFromList(keyMap[k], btn);
31
36
  });
37
+ onmounted(btn, function () {
38
+ removeFromList(keyMap[k], btn);
39
+ keyMap[k].push(btn);
40
+ })
32
41
  };
33
42
  var getKeyFromText = function (btn) {
34
43
  var { innerText } = btn;
@@ -42,6 +51,7 @@ var getKeyFromText = function (btn) {
42
51
  return accesskey.toUpperCase();
43
52
  }
44
53
  function main(elem, key = getKeyFromText(elem)) {
54
+ if (!key) return;
45
55
  bindAccesskey(elem, key);
46
56
  return elem;
47
57
  }
@@ -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
 
@@ -51,7 +52,7 @@ var mousedown = function () {
51
52
  });
52
53
  active.call(this);
53
54
  };
54
- var mouseleave = function () {
55
+ var mouseleave = function (event) {
55
56
  removeClass(this, "hover");
56
57
  };
57
58
  var mousemove = function (event) {
@@ -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();