efront 3.26.4 → 3.26.6

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.
@@ -102,6 +102,7 @@ class Speed extends Array {
102
102
  cache = [];
103
103
  stamp = 0;
104
104
  deltat = 0;
105
+ accelerate = .1;
105
106
  static now() {
106
107
  return performance.now ? performance.now() : Date.now();
107
108
  }
@@ -143,22 +144,23 @@ class Speed extends Array {
143
144
  var ratio;
144
145
  if (this.stamp) ratio = now - this.stamp;
145
146
  else ratio = deltat;
146
- if (ratio > 160) ratio = 1e-3;
147
+ if (ratio > 160) ratio = 1e-7;
147
148
  if (this.deltat) {
148
149
  if (deltat > this.deltat * 10) {
149
- ratio = 1e-3;
150
+ ratio = 1e-7;
150
151
  }
151
152
  }
152
153
  this.deltat = deltat;
153
154
  this.stamp = now;
154
155
  var sum = 0;
155
156
  for (var v of values) sum += v * v;
156
- v = Math.sqrt(sum) * ratio;
157
- if (v > 1) {
158
- v = Math.sqrt(v * (v - .996)) / v;
157
+ v = Math.sqrt(sum);
158
+ var a = this.accelerate * Math.atan(v + 1);
159
+ if (v > a + 1e-14) {
160
+ v = Math.sqrt(v * (v - a)) / v;
159
161
  }
160
162
  else {
161
- v = .9;
163
+ v = 1e-9;
162
164
  }
163
165
  var r = ratio * v;
164
166
  for (var cx = 0, dx = values.length; cx < dx; cx++) {
@@ -0,0 +1,10 @@
1
+ function isArrayLike(a) {
2
+ if (a === null || typeof a !== 'object' || isNode(a)) return false;
3
+ if (isFinite(a.length)) {
4
+ if (a.length > 0) {
5
+ return a.length - 1 in a;
6
+ }
7
+ return true;
8
+ }
9
+ return false;
10
+ }
@@ -323,16 +323,18 @@ var loadModule = function (name, then, prebuilds = {}) {
323
323
  }
324
324
  };
325
325
  var toRem = text => pixelDecoder && typeof text === 'string' ? text.replace(/(\:\s*)?\b((?:\d*\.)?\d+)px(\s*\))?/ig, (m, h, d, quote) => (h || "") + (d !== '1' ? h && quote ? renderPixelRatio * d + "pt" : pixelDecoder(d) : renderPixelRatio > 1 ? ".78pt" : 0.78 / devicePixelRatio + "pt") + (quote || "")) : text;
326
- if (document.head) {
327
- var efrontsign = document.head.lastElementChild.attributes[0];
328
- if (efrontsign && /^compiledinfo\-/.test(efrontsign.name)) efrontsign = efrontsign.name.slice(efrontsign.name.indexOf('-') + 1);
329
- else efrontsign = '';
330
- }
331
- else if (document.getElementsByTagName) {
332
- document.head = document.getElementsByTagName("head")[0];
333
- efrontsign = /\<script\s+compiledinfo\-(\S*?)\s*\=/i.exec(document.head.lastChild.outerHTML);
334
- if (efrontsign) efrontsign = efrontsign[1];
335
- else efrontsign = '';
326
+ if (document) {
327
+ if (document.head) {
328
+ var efrontsign = document.head.lastElementChild.attributes[0];
329
+ if (efrontsign && /^compiledinfo\-/.test(efrontsign.name)) efrontsign = efrontsign.name.slice(efrontsign.name.indexOf('-') + 1);
330
+ else efrontsign = '';
331
+ }
332
+ else if (document.getElementsByTagName) {
333
+ document.head = document.getElementsByTagName("head")[0];
334
+ efrontsign = /\<script\s+compiledinfo\-(\S*?)\s*\=/i.exec(document.head.lastChild.outerHTML);
335
+ if (efrontsign) efrontsign = efrontsign[1];
336
+ else efrontsign = '';
337
+ }
336
338
  }
337
339
  var uncode = function (text) {
338
340
  var ratio = 1;
@@ -597,10 +599,11 @@ var init = function (name, then, prebuilds) {
597
599
  var crack = function (error) {
598
600
  if (res.resolved || res.errored) return;
599
601
  var ed = errored[name];
600
- console.error(`加载${name}失败,${ed && ed.length ? `${ed.join(', ')} 等${ed.length}个模块` : "没有其他模块"}受到影响`);
601
602
  res.errored = true;
602
603
  res.error = error;
603
604
  res.fire();
605
+ console.error(`加载${name}失败,${ed && ed.length ? `${ed.join(', ')} 等${ed.length}个模块` : "没有其他模块"}受到影响`);
606
+ if (window.document) throw error;
604
607
  };
605
608
  loadModule(name, function (error) {
606
609
  if (hasOwnProperty.call(modules, name)) {
@@ -860,18 +863,19 @@ var requires_count = 3;
860
863
  var hook = function (requires_count) {
861
864
  if (requires_count !== 0) return;
862
865
  "alert confirm innerWidth innerHeight close prompt".split(/\s+/).map(removeGlobalProperty);
863
- initPixelDecoder();
864
866
  modules.Promise = Promise;
865
867
  modules.hook_time = +new Date;
866
- if (!efrontPath) efrontPath = document.body.getAttribute("main-path") || document.body.getAttribute("path") || document.body.getAttribute("main") || "zimoli";
867
- if (modules.hook_time - efront_time < (isProduction ? 30 : 5) && document.querySelector && devicePixelRatio > 1 && /Linux/.test(navigator.platform) && navigator.maxTouchPoints > 0) {
868
- let ratio = +(1000000 / devicePixelRatio + .5 | 0) / 1000000;
869
- document.querySelector("meta[name=viewport]").setAttribute("content", `width=device-width,target-densitydpi=device-dpi,user-scalable=no,initial-scale=1,maximum-scale=${ratio}`);
870
- renderPixelRatio *= devicePixelRatio;
871
- modules.renderPixelRatio = renderPixelRatio;
872
- devicePixelRatio = modules.devicePixelRatio = 1;
868
+ if (document) {
869
+ initPixelDecoder();
870
+ if (modules.hook_time - efront_time < (isProduction ? 30 : 5) && document.querySelector && devicePixelRatio > 1 && /Linux/.test(navigator.platform) && navigator.maxTouchPoints > 0) {
871
+ let ratio = +(1000000 / devicePixelRatio + .5 | 0) / 1000000;
872
+ document.querySelector("meta[name=viewport]").setAttribute("content", `width=device-width,target-densitydpi=device-dpi,user-scalable=no,initial-scale=1,maximum-scale=${ratio}`);
873
+ renderPixelRatio *= devicePixelRatio;
874
+ modules.renderPixelRatio = renderPixelRatio;
875
+ devicePixelRatio = modules.devicePixelRatio = 1;
876
+ }
877
+ if (!efrontPath) efrontPath = document.body.getAttribute("main-path") || document.body.getAttribute("path") || document.body.getAttribute("main") || "zimoli";
873
878
  }
874
-
875
879
  init(efrontPath, function (zimoli) {
876
880
  if (zimoli instanceof Function) zimoli();
877
881
  });
@@ -881,7 +885,7 @@ var initIfNotDefined = function (defined, path, onload) {
881
885
  else hook(--requires_count);
882
886
  };
883
887
 
884
- loadResponseTreeFromStorage();
888
+ if(document) loadResponseTreeFromStorage();
885
889
  initIfNotDefined([].map, "[]map", map => map);
886
890
  initIfNotDefined(Promise, "Promise", promise => Promise = promise);
887
891
  if (!isProduction) window.modules = modules;
@@ -889,5 +893,5 @@ var onload = function () {
889
893
  window.onload = null;
890
894
  hook(--requires_count);
891
895
  };
892
- if (document.body) onload();
896
+ if (!document || document.body) onload();
893
897
  else window.onload = onload;
@@ -17,11 +17,30 @@
17
17
  // │ href │
18
18
  // └────────────────────────────────────────────────────────────────────────────────────────────────┘
19
19
 
20
- // -------/// ---------------1---------------------------------///////////////////2-----3--------//////// ------4----2/////5---------------------------------------------------6-----------------------------------------------------------------------------//////////////-7--5///8-------9----------//10--11---10/8/--12----////
21
- var reg = /^([^\:\/\\\?#\[]+\:(?![^\:\/\\\?\#]*@|[\/\\][^\/\\]))?(?:\/\/|\\\\)?(?:(([^\:\/\\\?#]+)?(?:\:([^\/\\\?#]+))?)@)?(([^\/\\@\?\#\.]*?[^\/\\@\:\?\#\.\d][^\/\\@\:\?\#\.]*?|[^\/\\@\:\?\#\.]+(?:\:[\@\/\\\?#\.]*[^\d\@\:\/\\\?#\.]+|\.[^\/\\@\:\?\#]+?))?(?:(?:\:|^)(\d+))?)(((?:\/|\\|^)[^\?#]*)?(\?([^#]*))?)(#[\s\S]*)?$/;
22
- function parseURL(url) {
20
+ // -------/// ---------------1---------------------------------///////////////////2-----3--------//////// ------4----2/////5---------------------------------------------------6-----------------------------------------------------------------------------------//////////////-7--5///8-------9----------//10--11---10/8/--12----////
21
+ var reg = /^([^\:\/\\\?#\[]+\:(?![^\:\/\\\?\#]*@|[\/\\][^\/\\]))?(?:\/\/|\\\\)?(?:(([^\:\/\\\?#]+)?(?:\:([^\/\\\?#]+))?)@)?(([^\/\\@\?\#\.]*?[^\/\\@\:\?\#\.\d][^\/\\@\:\?\#\.]*?|[^\/\\@\:\?\#\.]+(?:\:[\@\/\\\?#\.]*[^\d\@\:\/\\\?#\.]+|(?:\.[^\/\\@\:\?\#\.]+)+))?(?:(?:\:|^)(\d+))?)(((?:\/|\\|^)[^\?#]*)?(\?([^#]*))?)(#[\s\S]*)?$/;
22
+ var hrefDescriptor = {
23
+ get() {
24
+ var href = '';
25
+ if (this.protocol) href += this.protocol;
26
+ if (this.auth) href += "//" + this.auth + "@" + this.host;
27
+ else if (this.host) href += "//" + this.host;
28
+ if (this.path) href += this.path;
29
+ if (this.hash) href += this.hash;
30
+ return href;
31
+ },
32
+ set(href) {
33
+ Object.assign(this, parseURL(href));
34
+ }
35
+ };
36
+ function parse(url) {
23
37
  if (url === undefined || url === null) url = '';
24
38
  var [__, protocol, auth, username, password, host, hostname, port, path, pathname, search, query, hash] = reg.exec(url);
25
- return { protocol, auth, username, password, host, hostname, port, path, pathname, search, query, hash, href: __ };
39
+ return { protocol, auth, username, password, host, hostname, port, path, pathname, search, query, hash };
40
+ }
41
+ function parseURL(url) {
42
+ var obj = parse(url);
43
+ Object.defineProperty(obj, "href", hrefDescriptor);
44
+ return obj;
26
45
  }
27
46
  module.exports = parseURL;
@@ -12,6 +12,10 @@ test('http://yunxu1019@live.cn@github.com/?a', 'username', 'yunxu1019@live.cn')
12
12
  test('localhost', 'host', 'localhost')
13
13
  test('localhost:80', 'port', '80')
14
14
  test('localhost:80/', 'port', '80')
15
+ test('magnet:?xt=::', 'search', '?xt=::')
16
+ test('magnet:?xt=::', 'protocol', 'magnet:')
17
+ test('magnet:?xt=::', 'host', '')
18
+ test('magnet:?xt=::', 'pathname', undefined)
15
19
  test('efront.cc', 'host', 'efront.cc')
16
20
  test('127.0.0.1', 'host', '127.0.0.1')
17
21
  test(':80', 'port', '80')
@@ -25,6 +29,9 @@ test('c:a:b@a80', 'auth', 'a:b')
25
29
  test('c:d:a:b@a80', 'password', 'a:b')
26
30
  test('localhost:', 'protocol', 'localhost:')
27
31
  test('localhost:80', 'hostname', 'localhost')
32
+ test('efront.cc', 'hostname', 'efront.cc')
33
+ test('efront.', 'hostname', undefined)
34
+ test('efront.', 'pathname', "efront.")
28
35
  test('http//:80', 'hostname', 'http')
29
36
  test('http//:80', 'pathname', '//:80')
30
37
  test('//h:80', 'host', 'h:80')
@@ -25,7 +25,7 @@ function appendChild(parent, obj, transition) {
25
25
  if (transition === false) {
26
26
  var children = [].concat(obj);
27
27
  } else {
28
- var children = isArray(obj) ? slice.call(obj, 0) : slice.call(arguments, 1);
28
+ var children = isArrayLike(obj) ? slice.call(obj, 0) : slice.call(arguments, 1);
29
29
  }
30
30
  if (parent.appendChild) {
31
31
  for (var cx = 0, dx = children.length; cx < dx; cx++) {
@@ -1,5 +1,8 @@
1
1
  var change = function (data) {
2
- zimoli.go(data, this.params, this);
2
+ if (isNode(data)) {
3
+ zimoli.global(data, this);
4
+ }
5
+ else zimoli.go(data, this.params, this);
3
6
  };
4
7
  var gosrc = function () {
5
8
  var { src } = this;
@@ -660,11 +660,45 @@ function responseCrash(e, data) {
660
660
  }
661
661
  error_report(e, e.status < 500 ? 'warn' : 'error');
662
662
  }
663
- var getData = function () { return this.data };
663
+ var toDataString = function () { return isEmpty(this.data) ? '' : this.data };
664
664
  var updateLoadingCount = function () {
665
665
  data.loading_count = cross.requests.length;
666
666
  };
667
667
  on('render')(window, updateLoadingCount, true);
668
+ var bubApply = function (f, args) {
669
+ if (args.length === 1) {
670
+ var [instanceMap] = args;
671
+ for (var k in instanceMap) {
672
+ f(k, instanceMap[k]);
673
+ }
674
+ }
675
+ else if (args.length === 2) {
676
+ var [instanceId, callback] = args;
677
+ f(instanceId, callback);
678
+ }
679
+ };
680
+
681
+ var bindInstance = function (instanceId, callback) {
682
+ if (!instanceListenerMap[instanceId]) {
683
+ instanceListenerMap[instanceId] = [];
684
+ }
685
+ var listeners = instanceListenerMap[instanceId];
686
+ if (!~listeners.indexOf(callback)) {
687
+ listeners.push(callback);
688
+ }
689
+ if (hasItem(instanceId)) callback(getItem(instanceId));
690
+ };
691
+ var unbindInstance = function (instanceId, callback) {
692
+ if (!instanceListenerMap[instanceId]) return;
693
+ if (!callback) {
694
+ delete instanceListenerMap[instanceId];
695
+ return;
696
+ }
697
+ removeFromList(instanceListenerMap[instanceId], callback);
698
+ if (!instanceListenerMap[instanceId].length) {
699
+ delete instanceListenerMap[instanceId];
700
+ }
701
+ };
668
702
  var data = {
669
703
  decodeStructure,
670
704
  encodeStructure,
@@ -1052,31 +1086,37 @@ var data = {
1052
1086
  }
1053
1087
  return this.setInstance(instanceId, instance, rememberWithStorage);
1054
1088
  },
1055
- bindInstance(instanceId, callback) {
1056
- if (!instanceListenerMap[instanceId]) {
1057
- instanceListenerMap[instanceId] = [];
1089
+ /**
1090
+ * bindInstance(instanceId, callback);
1091
+ * bindInstance(instanceMap);
1092
+ * bindInstance(page, instanceId, callback);
1093
+ * bindInstance(page, instanceMap);
1094
+ */
1095
+ bindInstance() {
1096
+ var [page] = arguments;
1097
+ if (isNode(page)) {
1098
+ var restargs = Array.prototype.slice.call(arguments, 1);
1099
+ onmounted(page, function () {
1100
+ bubApply(bindInstance, restargs);
1101
+ });
1102
+ on("remove")(page, function () {
1103
+ bubApply(unbindInstance, restargs);
1104
+ });
1058
1105
  }
1059
- var listeners = instanceListenerMap[instanceId];
1060
- if (!~listeners.indexOf(callback)) {
1061
- listeners.push(callback);
1106
+ else {
1107
+ bubApply(bindInstance, arguments);
1062
1108
  }
1063
- if (hasItem(instanceId)) callback(getItem(instanceId));
1064
1109
  },
1065
- unbindInstance(instanceId, callback) {
1066
- if (!instanceListenerMap[instanceId]) return;
1067
- if (!callback) {
1068
- delete instanceListenerMap[instanceId];
1069
- return;
1070
- }
1071
- removeFromList(instanceListenerMap[instanceId], callback);
1072
- if (!instanceListenerMap[instanceId].length) {
1073
- delete instanceListenerMap[instanceId];
1074
- }
1110
+ /**
1111
+ * 仅用于解除没有与DOM节点绑定的事件
1112
+ */
1113
+ unbindInstance() {
1114
+ bubApply(unbindInstance, arguments);
1075
1115
  },
1076
1116
  rebuildInstance(instance, data, old = instance) {
1077
1117
  if (instance === data) return;
1078
1118
  if (!isObject(instance)) throw new Error("只支持object类型的数据!");
1079
- if (!isObject(data)) data = { data }, data.toString = data.valueOf = getData;
1119
+ if (!isObject(data)) data = { data }, data.toString = data.valueOf = toDataString;
1080
1120
  if (instance instanceof Array) instance.splice(0, instance.length);
1081
1121
  var sample = new LoadingArray;
1082
1122
  Object.keys(old).forEach(function (k) {
@@ -1,5 +1,19 @@
1
1
 
2
2
  var _slider = createElement(div);
3
+ /**
4
+ * @param {Element} template
5
+ */
6
+ var cloneChildNodes = function (template) {
7
+ var cloned = template.cloneNode(true);
8
+ var cNodes = cloned.childNodes;
9
+ var tNodes = template.childNodes;
10
+ for (var cx = 0, dx = cNodes.length; cx < dx; cx++) {
11
+ cNodes[cx].$struct = tNodes[cx].$struct;
12
+ cNodes[cx].renderid = tNodes[cx].renderid;
13
+ }
14
+ return cNodes;
15
+ }
16
+
3
17
  /**
4
18
  * @param {Element} container
5
19
  * @param {Element|string} tagName;
@@ -26,6 +40,7 @@ var getGenerator = function (container, tagName = 'item') {
26
40
  container.paddingCount = paddingCount;
27
41
  }
28
42
  appendChild(template, templates);
43
+ render.struct(templates);
29
44
  if (templates.length) container.$template = template;
30
45
  container.insertBefore = _slider.insertBefore;
31
46
  container.appendChild = _slider.appendChild;
@@ -47,9 +62,9 @@ var getGenerator = function (container, tagName = 'item') {
47
62
  needSetAttr = false;
48
63
  }
49
64
  else {
50
- var template1 = template.cloneNode(true);
51
- element = template1.childNodes[0];
52
- if (template1.childNodes.length > 1) element.with = [].concat.apply([], template1.childNodes).slice(1);
65
+ var childNodes = cloneChildNodes(template);
66
+ element = childNodes[0];
67
+ if (childNodes.length > 1) element.with = Array.prototype.slice.call(childNodes, 1);
53
68
  }
54
69
  if (needSetAttr) {
55
70
  for (var a of tagName.attributes) {
@@ -59,12 +74,7 @@ var getGenerator = function (container, tagName = 'item') {
59
74
  var scopes = container.$generatorScopes;
60
75
  var parsedSrc = container.$src;
61
76
  if (parsedSrc) {
62
- var { keyName, itemName, indexName } = parsedSrc;
63
- var newScope = {
64
- [keyName || '$key']: index,
65
- [itemName || '$item']: com,
66
- [indexName || '$index']: index
67
- };
77
+ var newScope = parsedSrc.createScope(com, index, index);
68
78
  var newItem = render(element, newScope, scopes, false);
69
79
  if (element.with) newItem.with = render(element.with, newScope, scopes, false);
70
80
  } else {
@@ -612,24 +612,24 @@ function list() {
612
612
  }
613
613
  }
614
614
  }
615
- var bindSrc = null;
615
+ var bindSrc = isNode(container) && "$src" in container;
616
616
  if (container instanceof Array) {
617
617
  generator = getGeneratorFromArray(container);
618
618
  bindSrc = container;
619
619
  container = div();
620
620
  } else if (container && !generator) {
621
- if ("$src" in container) {
621
+ if (bindSrc) {
622
622
  generator = getGenerator(container);
623
- care(container, function () {
624
- var index = container.index();
625
- container.clean();
626
- container.go(index || 0);
627
- });
628
623
  bindSrc = true;
629
624
  } else {
630
625
  generator = function () { }
631
626
  }
632
627
  }
628
+ if (bindSrc === true) care(container, function () {
629
+ var index = container.index();
630
+ container.clean();
631
+ container.go(index || 0);
632
+ });
633
633
 
634
634
  if (!$Y) {
635
635
  if (container) {
@@ -648,8 +648,12 @@ function list() {
648
648
  container.go(container.index() || 0);
649
649
  }
650
650
  list.clean = function () {
651
- var children = (container || list).children;
652
- children = [].concat.apply([], children).filter(c => c.nodeType === 1 && isFinite(c.index));
651
+ var children = (container || list).childNodes;
652
+ children = Array.prototype.filter.call(children, c => {
653
+ if (isFinite(c.index)) return true;
654
+ if (c.nodeType === 1 && c.$comment && isFinite(c.$comment.index)) return true;
655
+ return false;
656
+ });
653
657
  remove(children);
654
658
  };
655
659
 
@@ -196,7 +196,6 @@ function main(elem, mode) {
196
196
  };
197
197
  if ("$src" in elem) {
198
198
  var src0 = [];
199
- menuList(elem, src0, emit, direction);
200
199
  care(elem, function (src) {
201
200
  bindGlobalkey(elem, src.keymap, emit);
202
201
  src0.splice(0, src0.length);
@@ -212,8 +211,8 @@ function main(elem, mode) {
212
211
  while (i < s.length) {
213
212
  src0.push.apply(src0, s.slice(i, i += 1000));
214
213
  }
215
- elem.go(0);
216
214
  });
215
+ menuList(elem, src0, emit, direction);
217
216
  }
218
217
  else {
219
218
  var nodes = getArrayNodes(elem);
@@ -9,7 +9,7 @@ function getMarginLeft(offsetLeft, offsetWidth, innerWidth) {
9
9
  // marginLeft*offsetWidth-marginLeft*innerWidth=offsetLeft*offsetWidth
10
10
  // marginLeft(offsetWidth-innerWidth)=offsetLeft*offsetWidth
11
11
  // marginLeft=offsetLeft*offsetWidth/(offsetWidth-innerWidth)
12
- if (offsetWidth === +innerWidth) return -offsetWidth / 2;
12
+ if (offsetWidth === +innerWidth || Math.abs(offsetLeft) > Math.abs(offsetWidth - innerWidth)) return -offsetWidth / 2;
13
13
  return offsetLeft * offsetWidth / (offsetWidth - innerWidth);
14
14
  }
15
15
 
@@ -175,12 +175,12 @@ var isypop = function (target) {
175
175
  if (!target) return false;
176
176
  var { offsetParent, nextSibling, previousSibling } = target;
177
177
  if (
178
- nextSibling && nextSibling.tagName === target.tagName
178
+ nextSibling
179
179
  && (
180
180
  nextSibling.offsetLeft - target.offsetLeft >= target.offsetWidth / 2
181
181
  || target.offsetLeft - nextSibling.offsetLeft >= nextSibling.offsetWidth / 2
182
182
  )
183
- || previousSibling && previousSibling.tagName === target.tagName
183
+ || previousSibling
184
184
  && (
185
185
  previousSibling.offsetLeft - target.offsetLeft >= target.offsetWidth / 2
186
186
  || target.offsetLeft - previousSibling.offsetLeft >= previousSibling.offsetWidth / 2