@wiajs/core 0.1.19 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js CHANGED
@@ -1,104 +1,87 @@
1
1
  /*!
2
- * wia core v0.1.16
3
- * (c) 2021 Sibyl Yu
4
- * @license MIT
2
+ * wia core v1.0.1
3
+ * (c) 2015-2023 Sibyl Yu and contributors
4
+ * Released under the MIT License.
5
5
  */
6
6
  (function (global, factory) {
7
7
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
8
8
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
9
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@wiajs/Core"] = {}));
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@wiajs/core"] = {}));
10
10
  })(this, (function (exports) { 'use strict';
11
11
 
12
- /**
13
- * promise version ajax get、post
14
- * return Promise objext.
15
- * get move to base.js
16
- */
17
- var Ajax = /*#__PURE__*/function () {
12
+ var Ajax = function () {
18
13
  function Ajax() {}
19
-
20
14
  var _proto = Ajax.prototype;
21
-
22
15
  _proto.post = function post(url, data) {
23
16
  var pm = new Promise(function (res, rej) {
24
17
  var xhr = $.getXhr();
25
-
26
18
  xhr.onreadystatechange = function () {
27
19
  if (xhr.readyState === 4) {
28
20
  if (xhr.status === 200) res(xhr.responseText);else rej(new Error(xhr.statusText), xhr.responseText);
29
21
  }
30
- /*
31
- if ((xhr.readyState === 4) && (xhr.status === 200)) {
32
- cb(xhr.responseText);
33
- }
34
- */
35
-
36
- }; // 异步 post,回调通知
37
-
38
-
22
+ };
39
23
  xhr.open('POST', url, true);
40
24
  var param = data;
41
- if (typeof data === 'object') param = objToParam(data); // 发送 FormData 数据, 会自动设置为 multipart/form-data
42
-
43
- xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=AaB03x');
44
- // alert(param);
45
-
25
+ if (typeof data === 'object') param = objToParam(data);
26
+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
46
27
  xhr.send(param);
47
28
  });
48
29
  return pm;
49
- }
50
- /**
51
- * xmlHttpRequest POST 方法
52
- * 发送 FormData 数据, 会自动设置为 multipart/form-data
53
- * 其他数据,应该是 application/x-www-form-urlencoded
54
- * @param url post的url地址
55
- * @param data 要post的数据
56
- * @param cb 回调
57
- */
58
- ;
59
-
30
+ };
60
31
  _proto.postForm = function postForm(url, data) {
61
32
  var pm = new Promise(function (res, rej) {
62
33
  var xhr = $.getXhr();
63
-
64
34
  xhr.onreadystatechange = function () {
65
35
  if (xhr.readyState === 4) {
66
36
  if (xhr.status === 200) res(null, xhr.responseText);else rej(new Error(xhr.status), xhr.responseText);
67
37
  }
68
- }; // 异步 post,回调通知
69
-
70
-
71
- xhr.open('POST', url, true); // 发送 FormData 数据, 会自动设置为 multipart/form-data
72
- // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
73
- // xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=AaB03x');
74
-
38
+ };
39
+ xhr.open('POST', url, true);
75
40
  xhr.send(data);
76
41
  });
77
42
  return pm;
78
43
  };
79
-
80
44
  _proto.get = function get(url, param) {
81
45
  return $.get(url, param);
82
46
  };
83
-
84
47
  return Ajax;
85
48
  }();
86
-
87
49
  function objToParam(obj) {
88
50
  var rs = '';
89
51
  var arr = [];
90
-
91
52
  for (var k in obj) {
92
53
  if (obj.hasOwnProperty(k)) {
93
54
  arr.push(k + "=" + obj[k]);
94
- } // rs += `${k}=${obj[k]}&`;
55
+ }
56
+ }
57
+ rs = arr.sort().join('&');
58
+ return rs;
59
+ }
95
60
 
96
- } // 排序
61
+ function _typeof(obj) {
62
+ "@babel/helpers - typeof";
97
63
 
64
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
65
+ return typeof obj;
66
+ } : function (obj) {
67
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
68
+ }, _typeof(obj);
69
+ }
98
70
 
99
- rs = arr.sort().join('&'); // alert(rs);
71
+ function _toPrimitive(input, hint) {
72
+ if (_typeof(input) !== "object" || input === null) return input;
73
+ var prim = input[Symbol.toPrimitive];
74
+ if (prim !== undefined) {
75
+ var res = prim.call(input, hint || "default");
76
+ if (_typeof(res) !== "object") return res;
77
+ throw new TypeError("@@toPrimitive must return a primitive value.");
78
+ }
79
+ return (hint === "string" ? String : Number)(input);
80
+ }
100
81
 
101
- return rs;
82
+ function _toPropertyKey(arg) {
83
+ var key = _toPrimitive(arg, "string");
84
+ return _typeof(key) === "symbol" ? key : String(key);
102
85
  }
103
86
 
104
87
  function _defineProperties(target, props) {
@@ -107,71 +90,39 @@
107
90
  descriptor.enumerable = descriptor.enumerable || false;
108
91
  descriptor.configurable = true;
109
92
  if ("value" in descriptor) descriptor.writable = true;
110
- Object.defineProperty(target, descriptor.key, descriptor);
93
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
111
94
  }
112
95
  }
113
-
114
96
  function _createClass(Constructor, protoProps, staticProps) {
115
97
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
116
98
  if (staticProps) _defineProperties(Constructor, staticProps);
99
+ Object.defineProperty(Constructor, "prototype", {
100
+ writable: false
101
+ });
117
102
  return Constructor;
118
103
  }
119
104
 
120
- function _inheritsLoose(subClass, superClass) {
121
- subClass.prototype = Object.create(superClass.prototype);
122
- subClass.prototype.constructor = subClass;
123
-
124
- _setPrototypeOf(subClass, superClass);
105
+ function _assertThisInitialized(self) {
106
+ if (self === void 0) {
107
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
108
+ }
109
+ return self;
125
110
  }
126
111
 
127
112
  function _setPrototypeOf(o, p) {
128
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
113
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
129
114
  o.__proto__ = p;
130
115
  return o;
131
116
  };
132
-
133
117
  return _setPrototypeOf(o, p);
134
118
  }
135
119
 
136
- function _isNativeReflectConstruct() {
137
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
138
- if (Reflect.construct.sham) return false;
139
- if (typeof Proxy === "function") return true;
140
-
141
- try {
142
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
143
- return true;
144
- } catch (e) {
145
- return false;
146
- }
147
- }
148
-
149
- function _construct(Parent, args, Class) {
150
- if (_isNativeReflectConstruct()) {
151
- _construct = Reflect.construct;
152
- } else {
153
- _construct = function _construct(Parent, args, Class) {
154
- var a = [null];
155
- a.push.apply(a, args);
156
- var Constructor = Function.bind.apply(Parent, a);
157
- var instance = new Constructor();
158
- if (Class) _setPrototypeOf(instance, Class.prototype);
159
- return instance;
160
- };
161
- }
162
-
163
- return _construct.apply(null, arguments);
164
- }
165
-
166
- function _assertThisInitialized(self) {
167
- if (self === void 0) {
168
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
169
- }
170
-
171
- return self;
120
+ function _inheritsLoose(subClass, superClass) {
121
+ subClass.prototype = Object.create(superClass.prototype);
122
+ subClass.prototype.constructor = subClass;
123
+ _setPrototypeOf(subClass, superClass);
172
124
  }
173
125
 
174
- /* eslint no-control-regex: "off" */
175
126
  var _uniqueNumber = 1;
176
127
  var Utils = {
177
128
  uniqueNumber: function uniqueNumber() {
@@ -182,27 +133,24 @@
182
133
  if (mask === void 0) {
183
134
  mask = 'xxxxxxxxxx';
184
135
  }
185
-
186
136
  if (map === void 0) {
187
137
  map = '0123456789abcdef';
188
138
  }
189
-
190
139
  return $.uid(mask, map);
191
140
  },
192
- mdPreloaderContent: "\n <span class=\"preloader-inner\">\n\t\t\t<svg viewBox=\"0 0 36 36\">\n\t\t\t\t<circle cx=\"18\" cy=\"18\" r=\"16\"></circle>\n\t\t\t</svg>\n </span>\n ".trim(),
193
- iosPreloaderContent: ("\n <span class=\"preloader-inner\">\n\t\t\t" + [0, 1, 2, 3, 4, 5, 6, 7].map(function () {
141
+ mdPreloaderContent: "\n\t\t<span class=\"preloader-inner\">\n\t\t\t<svg viewBox=\"0 0 36 36\">\n\t\t\t\t<circle cx=\"18\" cy=\"18\" r=\"16\"></circle>\n\t\t\t</svg>\n </span>\n ".trim(),
142
+ iosPreloaderContent: ("\n\t\t<span class=\"preloader-inner\">\n\t\t\t" + [0, 1, 2, 3, 4, 5, 6, 7].map(function () {
194
143
  return '<span class="preloader-inner-line"></span>';
195
- }).join('') + "\n </span>\n ").trim(),
196
- auroraPreloaderContent: "\n <span class=\"preloader-inner\">\n <span class=\"preloader-inner-circle\"></span>\n </span>\n ",
144
+ }).join('') + "\n\t\t</span>\n ").trim(),
145
+ auroraPreloaderContent: "\n <span class=\"preloader-inner\">\n <span class=\"preloader-inner-circle\"></span>\n </span>\n",
197
146
  eventNameToColonCase: function eventNameToColonCase(eventName) {
198
147
  var hasColon;
199
- return eventName.split('').map(function (char, index) {
200
- if (char.match(/[A-Z]/) && index !== 0 && !hasColon) {
148
+ return eventName.split('').map(function (_char, index) {
149
+ if (_char.match(/[A-Z]/) && index !== 0 && !hasColon) {
201
150
  hasColon = true;
202
- return ":" + char.toLowerCase();
151
+ return ":" + _char.toLowerCase();
203
152
  }
204
-
205
- return char.toLowerCase();
153
+ return _char.toLowerCase();
206
154
  }).join('');
207
155
  },
208
156
  deleteProps: function deleteProps(obj) {
@@ -212,7 +160,6 @@
212
160
  if (delay === void 0) {
213
161
  delay = 0;
214
162
  }
215
-
216
163
  return setTimeout(callback, delay);
217
164
  },
218
165
  nextFrame: function nextFrame(cb) {
@@ -234,43 +181,33 @@
234
181
  if (axis === void 0) {
235
182
  axis = 'x';
236
183
  }
237
-
238
184
  return $.getTranslate(el, axis);
239
185
  },
240
186
  serializeObject: function serializeObject(obj, parents) {
241
187
  if (parents === void 0) {
242
188
  parents = [];
243
189
  }
244
-
245
190
  if (typeof obj === 'string') return obj;
246
191
  var resultArray = [];
247
192
  var separator = '&';
248
193
  var newParents;
249
-
250
194
  function varName(name) {
251
195
  if (parents.length > 0) {
252
196
  var parentParts = '';
253
-
254
197
  for (var j = 0; j < parents.length; j += 1) {
255
198
  if (j === 0) parentParts += parents[j];else parentParts += "[" + encodeURIComponent(parents[j]) + "]";
256
199
  }
257
-
258
200
  return parentParts + "[" + encodeURIComponent(name) + "]";
259
201
  }
260
-
261
202
  return encodeURIComponent(name);
262
203
  }
263
-
264
204
  function varValue(value) {
265
205
  return encodeURIComponent(value);
266
206
  }
267
-
268
207
  Object.keys(obj).forEach(function (prop) {
269
208
  var toPush;
270
-
271
209
  if (Array.isArray(obj[prop])) {
272
210
  toPush = [];
273
-
274
211
  for (var i = 0; i < obj[prop].length; i += 1) {
275
212
  if (!Array.isArray(obj[prop][i]) && typeof obj[prop][i] === 'object') {
276
213
  newParents = parents.slice();
@@ -281,18 +218,15 @@
281
218
  toPush.push(varName(prop) + "[]=" + varValue(obj[prop][i]));
282
219
  }
283
220
  }
284
-
285
221
  if (toPush.length > 0) resultArray.push(toPush.join(separator));
286
222
  } else if (obj[prop] === null || obj[prop] === '') {
287
223
  resultArray.push(varName(prop) + "=");
288
224
  } else if (typeof obj[prop] === 'object') {
289
- // Object, convert to named array
290
225
  newParents = parents.slice();
291
226
  newParents.push(prop);
292
227
  toPush = Utils.serializeObject(obj[prop], newParents);
293
228
  if (toPush !== '') resultArray.push(toPush);
294
229
  } else if (typeof obj[prop] !== 'undefined' && obj[prop] !== '') {
295
- // Should be string or plain value
296
230
  resultArray.push(varName(prop) + "=" + varValue(obj[prop]));
297
231
  } else if (obj[prop] === '') resultArray.push(varName(prop));
298
232
  });
@@ -303,24 +237,19 @@
303
237
  },
304
238
  merge: function merge() {
305
239
  var _$;
306
-
307
240
  return (_$ = $).merge.apply(_$, arguments);
308
241
  },
309
242
  extend: function extend() {
310
243
  var _$2;
311
-
312
244
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
313
245
  args[_key] = arguments[_key];
314
246
  }
315
-
316
247
  var to = args[0];
317
248
  args.splice(0, 1);
318
249
  return (_$2 = $).assign.apply(_$2, [to].concat(args));
319
250
  },
320
- // ���෽������ʵ�������������ԡ���������
321
251
  bindMethods: function bindMethods(instance, obj) {
322
252
  var _this = this;
323
-
324
253
  Object.keys(obj).forEach(function (key) {
325
254
  if (_this.isObject(obj[key])) {
326
255
  Object.keys(obj[key]).forEach(function (subKey) {
@@ -329,7 +258,6 @@
329
258
  }
330
259
  });
331
260
  }
332
-
333
261
  instance[key] = obj[key];
334
262
  });
335
263
  },
@@ -350,12 +278,9 @@
350
278
  return "#" + result;
351
279
  },
352
280
  colorRgbToHsl: function colorRgbToHsl(r, g, b) {
353
- r /= 255; // eslint-disable-line
354
-
355
- g /= 255; // eslint-disable-line
356
-
357
- b /= 255; // eslint-disable-line
358
-
281
+ r /= 255;
282
+ g /= 255;
283
+ b /= 255;
359
284
  var max = Math.max(r, g, b);
360
285
  var min = Math.min(r, g, b);
361
286
  var d = max - min;
@@ -371,11 +296,9 @@
371
296
  var hp = h / 60;
372
297
  var x = c * (1 - Math.abs(hp % 2 - 1));
373
298
  var rgb1;
374
-
375
299
  if (Number.isNaN(h) || typeof h === 'undefined') {
376
300
  rgb1 = [0, 0, 0];
377
301
  } else if (hp <= 1) rgb1 = [c, x, 0];else if (hp <= 2) rgb1 = [x, c, 0];else if (hp <= 3) rgb1 = [0, c, x];else if (hp <= 4) rgb1 = [0, x, c];else if (hp <= 5) rgb1 = [x, 0, c];else if (hp <= 6) rgb1 = [c, 0, x];
378
-
379
302
  var m = l - c / 2;
380
303
  return rgb1.map(function (n) {
381
304
  return Math.max(0, Math.min(255, Math.round(255 * (n + m))));
@@ -415,11 +338,9 @@
415
338
  colorThemeCSSProperties: function colorThemeCSSProperties() {
416
339
  var hex;
417
340
  var rgb;
418
-
419
341
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
420
342
  args[_key2] = arguments[_key2];
421
343
  }
422
-
423
344
  if (args.length === 1) {
424
345
  hex = args[0];
425
346
  rgb = Utils.colorHexToRgb(hex);
@@ -427,7 +348,6 @@
427
348
  rgb = args;
428
349
  hex = Utils.colorRgbToHex.apply(Utils, rgb);
429
350
  }
430
-
431
351
  if (!rgb) return {};
432
352
  var hsl = Utils.colorRgbToHsl.apply(Utils, rgb);
433
353
  var hslShade = [hsl[0], hsl[1], Math.max(0, hsl[2] - 0.08)];
@@ -443,158 +363,255 @@
443
363
  }
444
364
  };
445
365
 
446
- /**
447
- * 事件类,提供对象的事件侦听、触发,只在类实例中有效。
448
- * 需要支持事件的对象,可以从这个类继承,则类实例具备事件功能。
449
- * Fork from Framework7,
450
- */
451
- var Event = /*#__PURE__*/function () {
452
- function Event(params, parents) {
366
+ var Event = function () {
367
+ function Event(params, parents, pre) {
453
368
  if (params === void 0) {
454
369
  params = {};
455
370
  }
456
-
457
371
  if (parents === void 0) {
458
372
  parents = [];
459
373
  }
460
-
461
- var self = this;
462
- self.params = params;
463
- self.eventsParents = parents;
464
- self.eventsListeners = {}; // 通过 params 中的 on 加载事件响应
465
-
466
- if (self.params && self.params.on) {
467
- Object.keys(self.params.on).forEach(function (eventName) {
468
- self.on(eventName, self.params.on[eventName]);
374
+ if (pre === void 0) {
375
+ pre = '';
376
+ }
377
+ var m = this;
378
+ m.params = params;
379
+ if (parents) {
380
+ if (!Array.isArray(parents)) m.eventsParents = [parents];else m.eventsParents = parents.filter(function (p) {
381
+ return p;
382
+ });
383
+ } else m.eventsParents = [];
384
+ m.eventsListeners = {};
385
+ m.pre = pre;
386
+ if (m.params && m.params.on) {
387
+ Object.keys(m.params.on).forEach(function (eventName) {
388
+ m.on(eventName, m.params.on[eventName]);
469
389
  });
470
390
  }
471
391
  }
472
-
473
392
  var _proto = Event.prototype;
474
-
475
393
  _proto.on = function on(events, handler, priority) {
476
- var self = this;
477
- if (typeof handler !== 'function') return self;
394
+ if (priority === void 0) {
395
+ priority = false;
396
+ }
397
+ var m = this;
398
+ if (typeof handler !== 'function') return m;
478
399
  var method = priority ? 'unshift' : 'push';
479
400
  events.split(' ').forEach(function (event) {
480
- if (!self.eventsListeners[event]) self.eventsListeners[event] = [];
481
- self.eventsListeners[event][method](handler);
401
+ var lis = {
402
+ owner: '',
403
+ appName: '',
404
+ handler: handler
405
+ };
406
+ if (event.includes('app::')) {
407
+ var page = null;
408
+ if ($.isPage(m)) page = m;else if ($.isPage(m == null ? void 0 : m.page)) page = m.page;else if ($.isPage(m == null ? void 0 : m.parent)) page = m.parent;
409
+ if (page && page.app && $.isApp(page.app)) {
410
+ lis.owner = page.owner;
411
+ lis.appName = page.appName;
412
+ var _page = page,
413
+ app = _page.app;
414
+ var ev = event.replace('app::', '');
415
+ if (!app.eventsListeners[ev]) app.eventsListeners[ev] = [];
416
+ app.eventsListeners[ev][method](lis);
417
+ }
418
+ } else {
419
+ if (!m.eventsListeners[event]) m.eventsListeners[event] = [];
420
+ m.eventsListeners[event][method](lis);
421
+ }
482
422
  });
483
- return self;
423
+ return m;
484
424
  };
485
-
486
425
  _proto.once = function once(events, handler, priority) {
487
- var self = this;
488
- if (typeof handler !== 'function') return self;
489
-
426
+ if (priority === void 0) {
427
+ priority = false;
428
+ }
429
+ var m = this;
430
+ if (typeof handler !== 'function') return m;
490
431
  function onceHandler() {
491
- self.off(events, onceHandler);
492
-
432
+ m.off(events, onceHandler);
493
433
  if (onceHandler.proxy) {
434
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
435
+ args[_key] = arguments[_key];
436
+ }
437
+ onceHandler.proxy.apply(m, args);
494
438
  delete onceHandler.proxy;
495
439
  }
496
-
497
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
498
- args[_key] = arguments[_key];
499
- }
500
-
501
- handler.apply(self, args);
502
440
  }
503
-
504
441
  onceHandler.proxy = handler;
505
- return self.on(events, onceHandler, priority);
442
+ return m.on(events, onceHandler, priority);
506
443
  };
507
-
508
444
  _proto.off = function off(events, handler) {
509
- var self = this;
510
- if (!self.eventsListeners) return self;
511
- events.split(' ').forEach(function (event) {
512
- if (typeof handler === 'undefined') {
513
- self.eventsListeners[event] = [];
514
- } else if (self.eventsListeners[event]) {
515
- self.eventsListeners[event].forEach(function (eventHandler, index) {
516
- if (eventHandler === handler || eventHandler.proxy && eventHandler.proxy === handler) {
517
- self.eventsListeners[event].splice(index, 1);
445
+ var m = this;
446
+ if (!m.eventsListeners) return m;
447
+ if (events) {
448
+ events.split(' ').forEach(function (event) {
449
+ if (typeof handler === 'undefined') m.eventsListeners[event] = [];else if (m.eventsListeners[event]) {
450
+ var arr = m.eventsListeners[event];
451
+ for (var i = arr.length - 1; i >= 0; i--) {
452
+ var _lis$handler;
453
+ var lis = arr[i];
454
+ if (lis.handler === handler || ((_lis$handler = lis.handler) == null ? void 0 : _lis$handler.proxy) === handler) arr.splice(i, 1);
518
455
  }
519
- });
520
- }
521
- });
522
- return self;
456
+ }
457
+ });
458
+ } else m.eventsListeners = {};
459
+ return m;
523
460
  };
524
-
525
461
  _proto.emit = function emit() {
526
- var self = this;
527
- if (!self.eventsListeners) return self;
462
+ var _eventsParents;
463
+ var m = this;
464
+ if (!m.eventsListeners) return m;
528
465
  var events;
529
466
  var data;
530
467
  var context;
531
468
  var eventsParents;
532
-
469
+ var pop = false;
533
470
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
534
471
  args[_key2] = arguments[_key2];
535
472
  }
536
-
537
- if (typeof args[0] === 'string' || Array.isArray(args[0])) {
538
- events = args[0];
473
+ var event = args[0];
474
+ if (!event) return m;
475
+ if (typeof event === 'string' || Array.isArray(event)) {
476
+ event = event.split(' ');
477
+ if (m.pre) {
478
+ events = [];
479
+ event.forEach(function (ev) {
480
+ events.push("." + ev);
481
+ events.push("" + m.pre + ev[0].toUpperCase() + ev.substr(1));
482
+ });
483
+ } else events = event;
539
484
  data = args.slice(1, args.length);
540
- context = self;
541
- eventsParents = self.eventsParents;
485
+ context = m;
486
+ eventsParents = m.eventsParents;
542
487
  } else {
543
- events = args[0].events;
544
- data = args[0].data;
545
- context = args[0].context || self;
546
- eventsParents = args[0].local ? [] : args[0].parents || self.eventsParents;
488
+ pop = event.pop;
489
+ events = event.events;
490
+ data = event.data;
491
+ context = event.context || m;
492
+ eventsParents = event.local ? [] : event.parents || m.eventsParents;
547
493
  }
548
-
549
494
  var eventsArray = Array.isArray(events) ? events : events.split(' ');
550
- var localEvents = eventsArray.map(function (eventName) {
551
- return eventName.replace('local::', '');
552
- });
553
- var parentEvents = eventsArray.filter(function (eventName) {
554
- return eventName.indexOf('local::') < 0;
495
+ var selfEvents = eventsArray.map(function (ev) {
496
+ return ev.replace(/local::|^[.]/, '');
555
497
  });
556
- localEvents.forEach(function (event) {
557
- if (self.eventsListeners && self.eventsListeners[event]) {
498
+ var parentEvents = null;
499
+ if (pop) parentEvents = event;else {
500
+ var popEvents = eventsArray.filter(function (ev) {
501
+ return !ev.match(/^local::|^[.]/);
502
+ });
503
+ if (popEvents != null && popEvents.length) {
504
+ parentEvents = {
505
+ pop: true,
506
+ events: popEvents,
507
+ context: m,
508
+ data: data,
509
+ owner: '',
510
+ appName: ''
511
+ };
512
+ }
513
+ }
514
+ if (parentEvents && $.isPage(m)) {
515
+ parentEvents.owner = m == null ? void 0 : m.owner;
516
+ parentEvents.appName = m == null ? void 0 : m.appName;
517
+ }
518
+ selfEvents.forEach(function (ev) {
519
+ if (m.eventsListeners && m.eventsListeners[ev]) {
558
520
  var handlers = [];
559
- self.eventsListeners[event].forEach(function (eventHandler) {
560
- handlers.push(eventHandler);
521
+ m.eventsListeners[ev].forEach(function (lis) {
522
+ if (lis.owner && lis.appName) {
523
+ if (pop && lis.owner === ev.owner && lis.appName === ev.appName) handlers.push(lis.handler);
524
+ } else handlers.push(lis.handler);
561
525
  });
562
- handlers.forEach(function (eventHandler) {
563
- eventHandler.apply(context, data);
526
+ handlers.forEach(function (fn) {
527
+ fn.apply(context, data);
564
528
  });
565
529
  }
566
530
  });
567
-
568
- if (eventsParents && eventsParents.length > 0) {
531
+ if (parentEvents && ((_eventsParents = eventsParents) == null ? void 0 : _eventsParents.length) > 0) {
569
532
  eventsParents.forEach(function (eventsParent) {
570
- eventsParent.emit.apply(eventsParent, [parentEvents].concat(data));
533
+ return eventsParent.emit(parentEvents);
571
534
  });
572
535
  }
573
-
574
- return self;
536
+ return m;
575
537
  };
576
-
577
538
  return Event;
578
539
  }();
579
540
 
580
- var Module = /*#__PURE__*/function (_Event) {
581
- _inheritsLoose(Module, _Event);
541
+ var Page = function (_Event) {
542
+ _inheritsLoose(Page, _Event);
543
+ function Page(app, name, title, style) {
544
+ var _this;
545
+ _this = _Event.call(this, null, [app]) || this;
546
+ _this.app = app;
547
+ _this.cfg = app.cfg;
548
+ _this.name = name;
549
+ _this.title = title;
550
+ _this.style = style || "./page/" + name + ".css";
551
+ _this.owner = '';
552
+ _this.appName = '';
553
+ _this.path = '';
554
+ _this.view = null;
555
+ _this.dom = null;
556
+ _this.$el = null;
557
+ _this.el = null;
558
+ _this.html = '';
559
+ _this.css = '';
560
+ _this.js = '';
561
+ _this.data = {};
562
+ _this.param = {};
563
+ return _this;
564
+ }
565
+ var _proto = Page.prototype;
566
+ _proto.load = function load(param) {
567
+ this.emit('local::load pageLoad', param);
568
+ this.emit('pageLoad', this);
569
+ };
570
+ _proto.ready = function ready(view, param, back) {
571
+ this.init();
572
+ this.emit('local::ready', view, param, back);
573
+ this.emit('pageReady', this);
574
+ };
575
+ _proto.init = function init(v) {
576
+ var view = this.view;
577
+ v = v ? $(v) : view;
578
+ };
579
+ _proto.show = function show(view, param) {
580
+ view.qus('[name$=-tp]').hide();
581
+ view.qus('a[href=""]').attr('href', 'javascript:;');
582
+ if (this.reset) this.reset();
583
+ this.emit('local::show', view, param);
584
+ this.emit('pageShow', this);
585
+ };
586
+ _proto.back = function back(view, param) {
587
+ view.qus('[name$=-tp]').hide();
588
+ view.qus('a[href=""]').attr('href', 'javascript:;');
589
+ this.emit('local::back', view, param);
590
+ this.emit('pageBack', this);
591
+ };
592
+ _proto.hide = function hide(view) {
593
+ this.emit('local::hide', view);
594
+ this.emit('pageHide', this);
595
+ };
596
+ _proto.unload = function unload(view) {
597
+ this.emit('local::unload', view);
598
+ this.emit('pageUnload', this);
599
+ };
600
+ return Page;
601
+ }(Event);
582
602
 
603
+ var Module = function (_Event) {
604
+ _inheritsLoose(Module, _Event);
583
605
  function Module(params, parents) {
584
606
  if (params === void 0) {
585
607
  params = {};
586
608
  }
587
-
588
609
  if (parents === void 0) {
589
610
  parents = [];
590
611
  }
591
-
592
612
  return _Event.call(this, params, parents) || this;
593
- } // eslint-disable-next-line
594
-
595
-
613
+ }
596
614
  var _proto = Module.prototype;
597
-
598
615
  _proto.useModuleParams = function useModuleParams(module, instanceParams) {
599
616
  if (module.params) {
600
617
  var originalParams = {};
@@ -608,60 +625,42 @@
608
625
  });
609
626
  }
610
627
  };
611
-
612
628
  _proto.useModulesParams = function useModulesParams(instanceParams) {
613
629
  var instance = this;
614
630
  if (!instance.modules) return;
615
631
  Object.keys(instance.modules).forEach(function (moduleName) {
616
- var module = instance.modules[moduleName]; // Extend params
617
-
632
+ var module = instance.modules[moduleName];
618
633
  if (module.params) {
619
634
  $.extend(instanceParams, module.params);
620
635
  }
621
636
  });
622
- }
623
- /**
624
- * 将扩展模块的相关方法、事件加载到类实例
625
- * @param {*} moduleName 扩展模块名称
626
- * @param {*} moduleParams
627
- */
628
- ;
629
-
637
+ };
630
638
  _proto.useModule = function useModule(moduleName, moduleParams) {
631
639
  if (moduleName === void 0) {
632
640
  moduleName = '';
633
641
  }
634
-
635
642
  if (moduleParams === void 0) {
636
643
  moduleParams = {};
637
644
  }
638
-
639
645
  var instance = this;
640
- if (!instance.modules) return; // 从原型中获得的模块类引用
641
-
646
+ if (!instance.modules) return;
642
647
  var module = typeof moduleName === 'string' ? instance.modules[moduleName] : moduleName;
643
- if (!module) return; // 扩展实例的方法和属性,Extend instance methods and props
644
-
648
+ if (!module) return;
645
649
  if (module.instance) {
646
650
  Object.keys(module.instance).forEach(function (modulePropName) {
647
651
  var moduleProp = module.instance[modulePropName];
648
-
649
652
  if (typeof moduleProp === 'function') {
650
653
  instance[modulePropName] = moduleProp.bind(instance);
651
654
  } else {
652
655
  instance[modulePropName] = moduleProp;
653
656
  }
654
657
  });
655
- } // 将扩展模块中的on加载到实例的事件侦听中,比如 init 在实例初始化时被调用
656
-
657
-
658
+ }
658
659
  if (module.on && instance.on) {
659
660
  Object.keys(module.on).forEach(function (moduleEventName) {
660
661
  instance.on(moduleEventName, module.on[moduleEventName]);
661
662
  });
662
- } // 加载扩展模块的vnodeHooks,Add vnode hooks
663
-
664
-
663
+ }
665
664
  if (module.vnode) {
666
665
  if (!instance.vnodeHooks) instance.vnodeHooks = {};
667
666
  Object.keys(module.vnode).forEach(function (vnodeId) {
@@ -672,24 +671,15 @@
672
671
  instance.vnodeHooks[hookName][vnodeId].push(handler.bind(instance));
673
672
  });
674
673
  });
675
- } // 执行模块的create方法,模块实例化回调,Module create callback
676
-
677
-
674
+ }
678
675
  if (module.create) {
679
676
  module.create.bind(instance)(moduleParams);
680
677
  }
681
- }
682
- /**
683
- * 实例创建初始化时,执行扩展模块中定义的相关回调
684
- * @param {*} modulesParams
685
- */
686
- ;
687
-
678
+ };
688
679
  _proto.useModules = function useModules(modulesParams) {
689
680
  if (modulesParams === void 0) {
690
681
  modulesParams = {};
691
682
  }
692
-
693
683
  var instance = this;
694
684
  if (!instance.modules) return;
695
685
  Object.keys(instance.modules).forEach(function (moduleName) {
@@ -697,67 +687,42 @@
697
687
  instance.useModule(moduleName, moduleParams);
698
688
  });
699
689
  };
700
-
701
- /**
702
- * 将模块类装配到指定类的modules属性,用于扩展类
703
- * @param {*} module 模块类
704
- * @param {...any} params 参数
705
- */
706
690
  Module.installModule = function installModule(module) {
707
691
  var Class = this;
708
692
  if (!Class.prototype.modules) Class.prototype.modules = {};
709
- var name = module.name || Object.keys(Class.prototype.modules).length + "_" + $.now(); // 原型属性中引用该模块类,类实例
710
-
711
- Class.prototype.modules[name] = module; // 模块如果定义了原型,则将模块原型加载到类原型
712
-
693
+ var name = module.name || Object.keys(Class.prototype.modules).length + "_" + $.now();
694
+ Class.prototype.modules[name] = module;
713
695
  if (module.proto) {
714
696
  Object.keys(module.proto).forEach(function (key) {
715
697
  Class.prototype[key] = module.proto[key];
716
698
  });
717
- } // 加载静态属性
718
-
719
-
720
- if (module.static) {
721
- Object.keys(module.static).forEach(function (key) {
722
- Class[key] = module.static[key];
699
+ }
700
+ if (module["static"]) {
701
+ Object.keys(module["static"]).forEach(function (key) {
702
+ Class[key] = module["static"][key];
723
703
  });
724
- } // 执行加载回调函数
725
-
726
-
704
+ }
727
705
  if (module.install) {
728
706
  for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
729
707
  params[_key - 1] = arguments[_key];
730
708
  }
731
-
732
709
  module.install.apply(Class, params);
733
710
  }
734
-
735
711
  return Class;
736
- }
737
- /**
738
- * 加载类扩展模块到类
739
- * @param {*} module
740
- * @param {...any} params
741
- */
742
- ;
743
-
712
+ };
744
713
  Module.use = function use(module) {
745
714
  var Class = this;
746
-
747
715
  if (Array.isArray(module)) {
748
716
  module.forEach(function (m) {
749
717
  return Class.installModule(m);
750
718
  });
751
719
  return Class;
752
720
  }
753
-
754
721
  for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
755
722
  params[_key2 - 1] = arguments[_key2];
756
723
  }
757
-
758
724
  return Class.installModule.apply(Class, [module].concat(params));
759
725
  };
760
-
761
726
  _createClass(Module, null, [{
762
727
  key: "components",
763
728
  set: function set(components) {
@@ -766,31 +731,52 @@
766
731
  Class.use(components);
767
732
  }
768
733
  }]);
769
-
770
734
  return Module;
771
735
  }(Event);
772
736
 
773
- /**
774
- * 扩展构造函数
775
- * @param {*} parameters
776
- */
737
+ function _isNativeReflectConstruct() {
738
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
739
+ if (Reflect.construct.sham) return false;
740
+ if (typeof Proxy === "function") return true;
741
+ try {
742
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
743
+ return true;
744
+ } catch (e) {
745
+ return false;
746
+ }
747
+ }
748
+
749
+ function _construct(Parent, args, Class) {
750
+ if (_isNativeReflectConstruct()) {
751
+ _construct = Reflect.construct.bind();
752
+ } else {
753
+ _construct = function _construct(Parent, args, Class) {
754
+ var a = [null];
755
+ a.push.apply(a, args);
756
+ var Constructor = Function.bind.apply(Parent, a);
757
+ var instance = new Constructor();
758
+ if (Class) _setPrototypeOf(instance, Class.prototype);
759
+ return instance;
760
+ };
761
+ }
762
+ return _construct.apply(null, arguments);
763
+ }
764
+
777
765
  function Constructors (parameters) {
778
766
  if (parameters === void 0) {
779
767
  parameters = {};
780
768
  }
781
-
782
769
  var _parameters = parameters,
783
- defaultSelector = _parameters.defaultSelector,
784
- Constructor = _parameters.constructor,
785
- domProp = _parameters.domProp,
786
- app = _parameters.app,
787
- addMethods = _parameters.addMethods;
770
+ defaultSelector = _parameters.defaultSelector,
771
+ Constructor = _parameters.constructor,
772
+ domProp = _parameters.domProp,
773
+ app = _parameters.app,
774
+ addMethods = _parameters.addMethods;
788
775
  var methods = {
789
776
  create: function create() {
790
777
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
791
778
  args[_key] = arguments[_key];
792
779
  }
793
-
794
780
  if (app) return _construct(Constructor, [app].concat(args));
795
781
  return _construct(Constructor, args);
796
782
  },
@@ -798,7 +784,6 @@
798
784
  if (el === void 0) {
799
785
  el = defaultSelector;
800
786
  }
801
-
802
787
  if (el instanceof Constructor) return el;
803
788
  var $el = $(el);
804
789
  if ($el.length === 0) return undefined;
@@ -810,26 +795,21 @@
810
795
  return undefined;
811
796
  }
812
797
  };
813
-
814
798
  if (addMethods && Array.isArray(addMethods)) {
815
799
  addMethods.forEach(function (methodName) {
816
800
  methods[methodName] = function (el) {
817
801
  if (el === void 0) {
818
802
  el = defaultSelector;
819
803
  }
820
-
821
804
  var instance = methods.get(el);
822
-
823
805
  for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
824
806
  args[_key2 - 1] = arguments[_key2];
825
807
  }
826
-
827
808
  if (instance && instance[methodName]) return instance[methodName].apply(instance, args);
828
809
  return undefined;
829
810
  };
830
811
  });
831
812
  }
832
-
833
813
  return methods;
834
814
  }
835
815
 
@@ -837,11 +817,10 @@
837
817
  if (parameters === void 0) {
838
818
  parameters = {};
839
819
  }
840
-
841
820
  var _parameters = parameters,
842
- defaultSelector = _parameters.defaultSelector,
843
- constructor = _parameters.constructor,
844
- app = _parameters.app;
821
+ defaultSelector = _parameters.defaultSelector,
822
+ constructor = _parameters.constructor,
823
+ app = _parameters.app;
845
824
  var methods = $.extend(Constructors({
846
825
  defaultSelector: defaultSelector,
847
826
  constructor: constructor,
@@ -860,7 +839,6 @@
860
839
  if (el === void 0) {
861
840
  el = defaultSelector;
862
841
  }
863
-
864
842
  var $el = $(el);
865
843
  if ($el.length === 0) return undefined;
866
844
  var instance = $el[0].f7Modal;
@@ -873,13 +851,7 @@
873
851
  return methods;
874
852
  }
875
853
 
876
- /**
877
- * 动态加载扩展模块,被 App调用。
878
- * 通过写入页面标签实现动态加载js、css
879
- * wia base中已经实现了动态下载、加载模块功能,该模块应删除
880
- */
881
854
  var fetchedModules = [];
882
-
883
855
  function loadModule(moduleToLoad) {
884
856
  var App = this;
885
857
  return new Promise(function (resolve, reject) {
@@ -887,30 +859,24 @@
887
859
  var modulePath;
888
860
  var moduleObj;
889
861
  var moduleFunc;
890
-
891
862
  if (!moduleToLoad) {
892
863
  reject(new Error('Wia: Lazy module must be specified'));
893
864
  return;
894
865
  }
895
-
896
866
  function install(module) {
897
867
  App.use(module);
898
-
899
868
  if (app) {
900
869
  app.useModuleParams(module, app.params);
901
870
  app.useModule(module);
902
871
  }
903
872
  }
904
-
905
873
  if (typeof moduleToLoad === 'string') {
906
874
  var matchNamePattern = moduleToLoad.match(/([a-z0-9-]*)/i);
907
-
908
875
  if (moduleToLoad.indexOf('.') < 0 && matchNamePattern && matchNamePattern[0].length === moduleToLoad.length) {
909
876
  if (!app || app && !app.params.lazyModulesPath) {
910
877
  reject(new Error('Wia: "lazyModulesPath" app parameter must be specified to fetch module by name'));
911
878
  return;
912
879
  }
913
-
914
880
  modulePath = app.params.lazyModulesPath + "/" + moduleToLoad + ".js";
915
881
  } else {
916
882
  modulePath = moduleToLoad;
@@ -918,88 +884,65 @@
918
884
  } else if (typeof moduleToLoad === 'function') {
919
885
  moduleFunc = moduleToLoad;
920
886
  } else {
921
- // considering F7-Plugin object
922
887
  moduleObj = moduleToLoad;
923
888
  }
924
-
925
889
  if (moduleFunc) {
926
890
  var module = moduleFunc(App, false);
927
-
928
891
  if (!module) {
929
892
  reject(new Error("Wia: Can't find Wia component in specified component function"));
930
893
  return;
931
- } // Check if it was added
932
-
933
-
894
+ }
934
895
  if (App.prototype.modules && App.prototype.modules[module.name]) {
935
896
  resolve();
936
897
  return;
937
- } // Install It
938
-
939
-
898
+ }
940
899
  install(module);
941
900
  resolve();
942
901
  }
943
-
944
902
  if (moduleObj) {
945
903
  var _module = moduleObj;
946
-
947
904
  if (!_module) {
948
905
  reject(new Error("Wia: Can't find Wia component in specified component"));
949
906
  return;
950
- } // Check if it was added
951
-
952
-
907
+ }
953
908
  if (App.prototype.modules && App.prototype.modules[_module.name]) {
954
909
  resolve();
955
910
  return;
956
- } // Install It
957
-
958
-
911
+ }
959
912
  install(_module);
960
913
  resolve();
961
914
  }
962
-
963
915
  if (modulePath) {
964
916
  if (fetchedModules.indexOf(modulePath) >= 0) {
965
917
  resolve();
966
918
  return;
967
919
  }
968
-
969
- fetchedModules.push(modulePath); // 动态加载 js 脚本
970
-
920
+ fetchedModules.push(modulePath);
971
921
  var scriptLoad = new Promise(function (resolveScript, rejectScript) {
972
922
  App.request.get(modulePath, function (scriptContent) {
973
923
  var id = $.id();
974
924
  var callbackLoadName = "wia_component_loader_callback_" + id;
975
925
  var scriptEl = document.createElement('script');
976
- scriptEl.innerHTML = "window." + callbackLoadName + " = function (Wia, WiaAutoInstallComponent) {return " + scriptContent.trim() + "}"; // 动态加载 js
977
-
926
+ scriptEl.innerHTML = "window." + callbackLoadName + " = function (Wia, WiaAutoInstallComponent) {return " + scriptContent.trim() + "}";
978
927
  $('head').append(scriptEl);
979
928
  var componentLoader = window[callbackLoadName];
980
929
  delete window[callbackLoadName];
981
930
  $(scriptEl).remove();
982
931
  var module = componentLoader(App, false);
983
-
984
932
  if (!module) {
985
933
  rejectScript(new Error("Wia: Can't find Wia component in " + modulePath + " file"));
986
934
  return;
987
- } // Check if it was added
988
-
989
-
935
+ }
990
936
  if (App.prototype.modules && App.prototype.modules[module.name]) {
991
937
  resolveScript();
992
938
  return;
993
- } // Install It
994
-
995
-
939
+ }
996
940
  install(module);
997
941
  resolveScript();
998
942
  }, function (xhr, status) {
999
943
  rejectScript(xhr, status);
1000
944
  });
1001
- }); // 动态加载css样式
1002
-
945
+ });
1003
946
  var styleLoad = new Promise(function (resolveStyle) {
1004
947
  App.request.get(modulePath.replace('.js', app.rtl ? '.rtl.css' : '.css'), function (styleContent) {
1005
948
  var styleEl = document.createElement('style');
@@ -1012,7 +955,7 @@
1012
955
  });
1013
956
  Promise.all([scriptLoad, styleLoad]).then(function () {
1014
957
  resolve();
1015
- }).catch(function (err) {
958
+ })["catch"](function (err) {
1016
959
  reject(err);
1017
960
  });
1018
961
  }
@@ -1032,10 +975,10 @@
1032
975
  };
1033
976
  var offset = app.root.offset();
1034
977
  var _ref = [app.root[0].offsetWidth, app.root[0].offsetHeight, offset.left, offset.top],
1035
- width = _ref[0],
1036
- height = _ref[1],
1037
- left = _ref[2],
1038
- top = _ref[3];
978
+ width = _ref[0],
979
+ height = _ref[1],
980
+ left = _ref[2],
981
+ top = _ref[3];
1039
982
  app.width = width;
1040
983
  app.height = height;
1041
984
  app.left = left;
@@ -1050,21 +993,17 @@
1050
993
  },
1051
994
  on: {
1052
995
  init: function init() {
1053
- var app = this; // Get Size
1054
-
1055
- app.getSize(); // Emit resize
1056
-
996
+ var app = this;
997
+ app.getSize();
1057
998
  window.addEventListener('resize', function () {
1058
999
  app.emit('resize');
1059
- }, false); // Emit orientationchange
1060
-
1000
+ }, false);
1061
1001
  window.addEventListener('orientationchange', function () {
1062
1002
  app.emit('orientationchange');
1063
1003
  });
1064
1004
  },
1065
1005
  orientationchange: function orientationchange() {
1066
- var app = this; // Fix iPad weird body scroll
1067
-
1006
+ var app = this;
1068
1007
  if (app.device.ipad) {
1069
1008
  document.body.scrollLeft = 0;
1070
1009
  setTimeout(function () {
@@ -1079,43 +1018,27 @@
1079
1018
  }
1080
1019
  };
1081
1020
 
1082
- /**
1083
- * document 绑定click事件
1084
- * 支持touch则绑定touch,否则绑定click
1085
- * 无论touch 还是 click事件,都会触发事件响应函数
1086
- * @param {*} cb
1087
- */
1088
1021
  function bindClick(cb) {
1089
1022
  var touchStartX;
1090
1023
  var touchStartY;
1091
-
1092
1024
  function touchStart(ev) {
1093
- // ev.preventDefault();
1094
1025
  touchStartX = ev.changedTouches[0].clientX;
1095
1026
  touchStartY = ev.changedTouches[0].clientY;
1096
1027
  }
1097
-
1098
1028
  function touchEnd(ev) {
1099
- // ev.preventDefault();
1100
1029
  var x = Math.abs(ev.changedTouches[0].clientX - touchStartX);
1101
- var y = Math.abs(ev.changedTouches[0].clientY - touchStartY); // console.log('touchEnd', {x, y});
1102
-
1030
+ var y = Math.abs(ev.changedTouches[0].clientY - touchStartY);
1103
1031
  if (x <= 5 && y <= 5) {
1104
1032
  cb.call(this, ev);
1105
1033
  }
1106
- } // 在捕捉时触发,不影响后续冒泡阶段再次触发
1107
-
1108
-
1034
+ }
1109
1035
  if ($.support.touch) {
1110
- // console.log('bind touch');
1111
1036
  document.addEventListener('touchstart', touchStart, true);
1112
1037
  document.addEventListener('touchend', touchEnd, true);
1113
1038
  } else {
1114
- // console.log('bind click');
1115
1039
  document.addEventListener('click', cb, true);
1116
1040
  }
1117
1041
  }
1118
-
1119
1042
  function initClicks(app) {
1120
1043
  function appClick(ev) {
1121
1044
  app.emit({
@@ -1123,43 +1046,34 @@
1123
1046
  data: [ev]
1124
1047
  });
1125
1048
  }
1126
-
1127
1049
  function handleClicks(e) {
1128
1050
  var $clickedEl = $(e.target);
1129
1051
  var $clickedLinkEl = $clickedEl.closest('a');
1130
1052
  var isLink = $clickedLinkEl.length > 0;
1131
- isLink && $clickedLinkEl.attr('href'); // call Modules Clicks
1132
-
1053
+ isLink && $clickedLinkEl.attr('href');
1133
1054
  Object.keys(app.modules).forEach(function (moduleName) {
1134
1055
  var moduleClicks = app.modules[moduleName].clicks;
1135
1056
  if (!moduleClicks) return;
1136
1057
  if (e.preventF7Router) return;
1137
1058
  Object.keys(moduleClicks).forEach(function (clickSelector) {
1138
1059
  var matchingClickedElement = $clickedEl.closest(clickSelector).eq(0);
1139
-
1140
1060
  if (matchingClickedElement.length > 0) {
1141
1061
  moduleClicks[clickSelector].call(app, matchingClickedElement, matchingClickedElement.dataset(), e);
1142
1062
  }
1143
1063
  });
1144
1064
  });
1145
- } // 绑定click 或 touch 事件,触发时,发射click事件
1146
-
1147
-
1148
- bindClick(appClick); // click event 响应
1149
-
1065
+ }
1066
+ bindClick(appClick);
1150
1067
  app.on('click', handleClicks);
1151
1068
  }
1152
-
1153
1069
  var Click = {
1154
1070
  name: 'clicks',
1155
1071
  params: {
1156
1072
  clicks: {
1157
- // External Links
1158
1073
  externalLinks: '.ext'
1159
1074
  }
1160
1075
  },
1161
1076
  on: {
1162
- // app 创建时被调用
1163
1077
  init: function init() {
1164
1078
  var app = this;
1165
1079
  initClicks(app);
@@ -1171,13 +1085,11 @@
1171
1085
  registrations: [],
1172
1086
  register: function register(path, scope) {
1173
1087
  var app = this;
1174
-
1175
1088
  if (!('serviceWorker' in window.navigator) || !app.serviceWorker.container) {
1176
1089
  return new Promise(function (resolve, reject) {
1177
1090
  reject(new Error('Service worker is not supported'));
1178
1091
  });
1179
1092
  }
1180
-
1181
1093
  return new Promise(function (resolve, reject) {
1182
1094
  app.serviceWorker.container.register(path, scope ? {
1183
1095
  scope: scope
@@ -1185,7 +1097,7 @@
1185
1097
  SW.registrations.push(reg);
1186
1098
  app.emit('serviceWorkerRegisterSuccess', reg);
1187
1099
  resolve(reg);
1188
- }).catch(function (error) {
1100
+ })["catch"](function (error) {
1189
1101
  app.emit('serviceWorkerRegisterError', error);
1190
1102
  reject(error);
1191
1103
  });
@@ -1193,13 +1105,11 @@
1193
1105
  },
1194
1106
  unregister: function unregister(registration) {
1195
1107
  var app = this;
1196
-
1197
1108
  if (!('serviceWorker' in window.navigator) || !app.serviceWorker.container) {
1198
1109
  return new Promise(function (resolve, reject) {
1199
1110
  reject(new Error('Service worker is not supported'));
1200
1111
  });
1201
1112
  }
1202
-
1203
1113
  var registrations;
1204
1114
  if (!registration) registrations = SW.registrations;else if (Array.isArray(registration)) registrations = registration;else registrations = [registration];
1205
1115
  return Promise.all(registrations.map(function (reg) {
@@ -1208,10 +1118,9 @@
1208
1118
  if (SW.registrations.indexOf(reg) >= 0) {
1209
1119
  SW.registrations.splice(SW.registrations.indexOf(reg), 1);
1210
1120
  }
1211
-
1212
1121
  app.emit('serviceWorkerUnregisterSuccess', reg);
1213
1122
  resolve();
1214
- }).catch(function (error) {
1123
+ })["catch"](function (error) {
1215
1124
  app.emit('serviceWorkerUnregisterError', reg, error);
1216
1125
  reject(error);
1217
1126
  });
@@ -1256,24 +1165,19 @@
1256
1165
 
1257
1166
  var Support$1 = $.support;
1258
1167
  var Device$1 = $.device;
1259
- /**
1260
- * 应用类,每个wia应用从该类继承,由 首页加载创建或者路由创建
1261
- */
1262
-
1263
- var App = /*#__PURE__*/function (_Module) {
1168
+ var App = function (_Module) {
1264
1169
  _inheritsLoose(App, _Module);
1265
-
1266
1170
  function App(opt) {
1267
1171
  var _this;
1268
-
1269
1172
  _this = _Module.call(this, opt) || this;
1270
1173
  var passedParams = $.extend({}, opt);
1271
-
1272
1174
  var app = _assertThisInitialized(_this);
1273
-
1274
1175
  app.device = Device$1;
1275
- app.support = Support$1; // Default
1276
-
1176
+ app.support = Support$1;
1177
+ console.log('App constructor', {
1178
+ Device: Device$1,
1179
+ Support: Support$1
1180
+ });
1277
1181
  var def = {
1278
1182
  version: '0.0.1',
1279
1183
  root: 'body',
@@ -1282,95 +1186,74 @@
1282
1186
  routes: [],
1283
1187
  lazyModulesPath: null,
1284
1188
  initOnDeviceReady: true,
1285
- // init: true, // 路由加载时,为 false,,为true
1286
1189
  autoDarkTheme: false,
1287
1190
  iosTranslucentBars: true,
1288
1191
  iosTranslucentModals: true,
1289
1192
  component: undefined,
1290
1193
  componentUrl: undefined
1291
- }; // Extend defaults with modules params
1292
-
1293
- app.useModulesParams(def); // Extend defaults with passed params
1294
-
1194
+ };
1195
+ app.useModulesParams(def);
1295
1196
  app.params = $.extend(def, opt);
1296
1197
  var $rootEl = $(app.params.root);
1198
+ $.isPage = function (p) {
1199
+ return p instanceof Page;
1200
+ };
1201
+ $.isApp = function (p) {
1202
+ return p instanceof App;
1203
+ };
1297
1204
  $.extend(app, {
1298
1205
  owner: app.params.owner,
1299
1206
  name: app.params.name,
1300
1207
  id: app.params.owner + "." + app.params.name,
1301
- // App version
1302
1208
  version: app.params.version,
1303
- // Routes
1304
1209
  routes: app.params.routes,
1305
- // Lang
1306
1210
  language: app.params.language,
1307
- // Root
1308
1211
  root: $rootEl,
1309
1212
  $el: $rootEl,
1310
1213
  cfg: app.params.cfg,
1311
- // app config
1312
1214
  api: app.params.api,
1313
- // api config
1314
- // RTL
1315
1215
  rtl: $rootEl.css('direction') === 'rtl',
1316
- // Theme
1317
1216
  theme: function getTheme() {
1318
1217
  if (app.params.theme === 'auto') {
1319
1218
  if (Device$1.ios) return 'ios';
1320
1219
  if (Device$1.desktop) return 'aurora';
1321
1220
  return 'md';
1322
1221
  }
1323
-
1324
1222
  return app.params.theme;
1325
1223
  }(),
1326
- // Initially passed parameters
1327
1224
  passedParams: passedParams,
1328
1225
  online: window.navigator.onLine
1329
- }); // Save Root
1330
-
1226
+ });
1331
1227
  if (app.root && app.root[0]) {
1332
1228
  app.root[0].wia = app;
1333
1229
  }
1334
-
1335
1230
  app.touchEvents = {
1336
1231
  start: Support$1.touch ? 'touchstart' : Support$1.pointerEvents ? 'pointerdown' : 'mousedown',
1337
1232
  move: Support$1.touch ? 'touchmove' : Support$1.pointerEvents ? 'pointermove' : 'mousemove',
1338
1233
  end: Support$1.touch ? 'touchend' : Support$1.pointerEvents ? 'pointerup' : 'mouseup'
1339
- }; // 加载use插入的模块类,每个模块作为app的一个属性,合并到实例。
1340
- // 模块包括相关属性及方法(如:create、get、destroy)
1341
- // 调用每个模块的 create 方法
1342
-
1343
- app.useModules(); // 初始化数据,Init Data & Methods
1344
-
1345
- app.initData(); // 自动暗黑主题,Auto Dark Theme
1346
-
1234
+ };
1235
+ app.useModules();
1236
+ app.initData();
1347
1237
  var DARK = '(prefers-color-scheme: dark)';
1348
1238
  var LIGHT = '(prefers-color-scheme: light)';
1349
1239
  app.mq = {};
1350
-
1351
1240
  if (window.matchMedia) {
1352
1241
  app.mq.dark = window.matchMedia(DARK);
1353
1242
  app.mq.light = window.matchMedia(LIGHT);
1354
1243
  }
1355
-
1356
1244
  app.colorSchemeListener = function (_ref) {
1357
1245
  var matches = _ref.matches,
1358
- media = _ref.media;
1359
-
1246
+ media = _ref.media;
1360
1247
  if (!matches) {
1361
1248
  return;
1362
1249
  }
1363
-
1364
1250
  var html = document.querySelector('html');
1365
-
1366
1251
  if (media === DARK) {
1367
1252
  html.classList.add('theme-dark');
1368
1253
  } else if (media === LIGHT) {
1369
1254
  html.classList.remove('theme-dark');
1370
1255
  }
1371
- }; // app 初始化,Init
1372
-
1373
-
1256
+ };
1374
1257
  function init() {
1375
1258
  if (Device$1.cordova && app.params.initOnDeviceReady) {
1376
1259
  $(document).on('deviceready', function () {
@@ -1379,54 +1262,32 @@
1379
1262
  } else {
1380
1263
  app.init();
1381
1264
  }
1382
- } // 应用初始化,路由跳转时不执行初始化
1383
-
1384
-
1385
- if (app.params.init) init(); // Return app instance
1386
-
1265
+ }
1266
+ if (app.params.init) init();
1387
1267
  return app || _assertThisInitialized(_this);
1388
- } // 首次加载事件,全局只触发一次
1389
-
1390
-
1268
+ }
1391
1269
  var _proto = App.prototype;
1392
-
1393
1270
  _proto.load = function load(param) {
1394
1271
  this.emit('local::load appLoad', param);
1395
- } // 从后台切换到前台显示事件
1396
- ;
1397
-
1272
+ };
1398
1273
  _proto.show = function show(url, data) {
1399
1274
  this.emit('local::show appShow', url, data);
1400
- } // 从前台显示切换到后台事件
1401
- ;
1402
-
1275
+ };
1403
1276
  _proto.hide = function hide() {
1404
1277
  this.emit('local::hide appHide');
1405
- } // 卸载应用事件
1406
- ;
1407
-
1278
+ };
1408
1279
  _proto.unload = function unload() {
1409
1280
  this.emit('local::unload appUnload');
1410
- }
1411
- /**
1412
- * 初始化数据
1413
- */
1414
- ;
1415
-
1281
+ };
1416
1282
  _proto.initData = function initData() {
1417
- var app = this; // Data
1418
-
1283
+ var app = this;
1419
1284
  app.data = {};
1420
-
1421
1285
  if (app.params.data && typeof app.params.data === 'function') {
1422
1286
  $.extend(app.data, app.params.data.bind(app)());
1423
1287
  } else if (app.params.data) {
1424
1288
  $.extend(app.data, app.params.data);
1425
- } // Methods
1426
-
1427
-
1289
+ }
1428
1290
  app.methods = {};
1429
-
1430
1291
  if (app.params.methods) {
1431
1292
  Object.keys(app.params.methods).forEach(function (methodName) {
1432
1293
  if (typeof app.params.methods[methodName] === 'function') {
@@ -1437,54 +1298,40 @@
1437
1298
  });
1438
1299
  }
1439
1300
  };
1440
-
1441
1301
  _proto.enableAutoDarkTheme = function enableAutoDarkTheme() {
1442
1302
  if (!window.matchMedia) return;
1443
1303
  var app = this;
1444
1304
  var html = document.querySelector('html');
1445
-
1446
1305
  if (app.mq.dark && app.mq.light) {
1447
1306
  app.mq.dark.addListener(app.colorSchemeListener);
1448
1307
  app.mq.light.addListener(app.colorSchemeListener);
1449
1308
  }
1450
-
1451
1309
  if (app.mq.dark && app.mq.dark.matches) {
1452
1310
  html.classList.add('theme-dark');
1453
1311
  } else if (app.mq.light && app.mq.light.matches) {
1454
1312
  html.classList.remove('theme-dark');
1455
1313
  }
1456
1314
  };
1457
-
1458
1315
  _proto.disableAutoDarkTheme = function disableAutoDarkTheme() {
1459
1316
  if (!window.matchMedia) return;
1460
1317
  var app = this;
1461
1318
  if (app.mq.dark) app.mq.dark.removeListener(app.colorSchemeListener);
1462
1319
  if (app.mq.light) app.mq.light.removeListener(app.colorSchemeListener);
1463
- } // 初始化,包括控制 html 样式,wia app 启动时需要执行,切换app时,不需要
1464
- ;
1465
-
1320
+ };
1466
1321
  _proto.init = function init() {
1467
1322
  var app = this;
1468
1323
  if (app.initialized) return app;
1469
1324
  $.App = App;
1470
-
1471
1325
  if (Device$1.ios && Device$1.webView) {
1472
- // Strange hack required for iOS 8 webview to work on inputs
1473
1326
  window.addEventListener('touchstart', function () {});
1474
1327
  }
1475
-
1476
- app.root.addClass('framework7-initializing'); // RTL attr
1477
-
1328
+ app.root.addClass('framework7-initializing');
1478
1329
  if (app.rtl) {
1479
1330
  $('html').attr('dir', 'rtl');
1480
- } // Auto Dark Theme
1481
-
1482
-
1331
+ }
1483
1332
  if (app.params.autoDarkTheme) {
1484
1333
  app.enableAutoDarkTheme();
1485
- } // Watch for online/offline state
1486
-
1487
-
1334
+ }
1488
1335
  window.addEventListener('offline', function () {
1489
1336
  app.online = false;
1490
1337
  app.emit('offline');
@@ -1494,51 +1341,35 @@
1494
1341
  app.online = true;
1495
1342
  app.emit('online');
1496
1343
  app.emit('connection', true);
1497
- }); // Root class
1498
-
1499
- app.root.addClass('framework7-root'); // Theme class
1500
-
1501
- $('html').removeClass('ios md aurora').addClass(app.theme); // iOS Translucent
1502
-
1344
+ });
1345
+ app.root.addClass('framework7-root');
1346
+ $('html').removeClass('ios md aurora').addClass(app.theme);
1503
1347
  if (app.params.iosTranslucentBars && app.theme === 'ios' && Device$1.ios) {
1504
1348
  $('html').addClass('ios-translucent-bars');
1505
1349
  }
1506
-
1507
1350
  if (app.params.iosTranslucentModals && app.theme === 'ios' && Device$1.ios) {
1508
1351
  $('html').addClass('ios-translucent-modals');
1509
- } // Init class
1510
-
1511
-
1352
+ }
1512
1353
  $.nextFrame(function () {
1513
1354
  app.root.removeClass('framework7-initializing');
1514
1355
  });
1515
- initStyle(); // Emit, init other modules
1516
-
1517
- app.initialized = true; // 发起init 事件,模块 on 里面有 init方法的会被触发
1518
-
1356
+ initStyle();
1357
+ app.initialized = true;
1519
1358
  app.emit('init');
1520
1359
  return app;
1521
- } // eslint-disable-next-line
1522
- ;
1523
-
1360
+ };
1524
1361
  _proto.loadModule = function loadModule(m) {
1525
- App.loadModule(m); // 模块初始化
1526
-
1362
+ App.loadModule(m);
1527
1363
  if (this[m.name].init) this[m.name].init();
1528
- } // eslint-disable-next-line
1529
- ;
1530
-
1364
+ };
1531
1365
  _proto.loadModules = function loadModules() {
1532
1366
  return App.loadModules.apply(App, arguments);
1533
1367
  };
1534
-
1535
1368
  _proto.getVnodeHooks = function getVnodeHooks(hook, id) {
1536
1369
  var app = this;
1537
1370
  if (!app.vnodeHooks || !app.vnodeHooks[hook]) return [];
1538
1371
  return app.vnodeHooks[hook][id] || [];
1539
- } // eslint-disable-next-line
1540
- ;
1541
-
1372
+ };
1542
1373
  _createClass(App, [{
1543
1374
  key: "$",
1544
1375
  get: function get() {
@@ -1565,188 +1396,93 @@
1565
1396
  return Event;
1566
1397
  }
1567
1398
  }]);
1568
-
1569
1399
  return App;
1570
1400
  }(Module);
1571
- /**
1572
- * 初始化html样式
1573
- * from device module
1574
- */
1575
-
1576
-
1577
1401
  App.apps = {};
1578
-
1579
1402
  function initStyle() {
1580
1403
  var classNames = [];
1581
1404
  var html = document.querySelector('html');
1582
1405
  var metaStatusbar = document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]');
1583
1406
  if (!html) return;
1584
-
1585
1407
  if (Device$1.standalone && Device$1.ios && metaStatusbar && metaStatusbar.content === 'black-translucent') {
1586
1408
  classNames.push('device-full-viewport');
1587
- } // Pixel Ratio
1588
-
1589
-
1590
- classNames.push("device-pixel-ratio-" + Math.floor(Device$1.pixelRatio)); // OS classes
1591
-
1409
+ }
1410
+ classNames.push("device-pixel-ratio-" + Math.floor(Device$1.pixelRatio));
1592
1411
  if (Device$1.os && !Device$1.desktop) {
1593
1412
  classNames.push("device-" + Device$1.os);
1594
1413
  } else if (Device$1.desktop) {
1595
1414
  classNames.push('device-desktop');
1596
-
1597
1415
  if (Device$1.os) {
1598
1416
  classNames.push("device-" + Device$1.os);
1599
1417
  }
1600
1418
  }
1601
-
1602
1419
  if (Device$1.cordova || Device$1.phonegap) {
1603
1420
  classNames.push('device-cordova');
1604
- } // Add html classes
1605
-
1606
-
1421
+ }
1607
1422
  classNames.forEach(function (className) {
1608
- html.classList.add(className); // console.log({className});
1423
+ html.classList.add(className);
1609
1424
  });
1610
- } // App 类 静态方法、属性
1611
-
1612
-
1425
+ }
1613
1426
  App.ModalMethods = Modals;
1614
- App.ConstructorMethods = Constructors; // 动态加载模块(base里面已经内置动态加载,这个方法应该用不上)
1615
-
1427
+ App.ConstructorMethods = Constructors;
1616
1428
  App.loadModule = loadModule;
1617
-
1618
1429
  App.loadModules = function (modules) {
1619
1430
  return Promise.all(modules.map(function (module) {
1620
1431
  return App.loadModule(module);
1621
1432
  }));
1622
- }; // app 加载到 app实例的一些扩展模块
1623
-
1624
-
1433
+ };
1625
1434
  App.support = Support$1;
1626
1435
  App.device = Device$1;
1627
- App.utils = Utils; // 添加应用缺省模块
1436
+ App.utils = Utils;
1437
+ App.use([Resize, Click, SW$1]);
1628
1438
 
1629
- App.use([Resize, // 控制屏幕大小
1630
- Click, // 触发UI组件的点击(Click 或 Touch)事件
1631
- SW$1 // ServiceWorker
1632
- //INSTALL_COMPONENTS
1633
- ]);
1634
-
1635
- /**
1636
- * Released on: August 28, 2016
1637
- * 图片延迟加载
1638
- * 使用方法:
1639
- * import {Lazy from '@wiajs/core';
1640
- * const _lazy = new Lazy();
1641
- * _lazy.start(dv); // 注意,这个dv是滚动的层,错了无法触发加载,sui 就是内容层!
1642
- * setTimeout(() => {loadView()}, 1); // krouter 里面已经做了处理,bind 时直接 加载视图即可!
1643
- * loadView 加载视图中(每次页面更新内容后,需调用)
1644
- * _lazy.update(); // 没有显示的图片,加入 待加载数组,并检查是否可视,可视则加载!
1645
- */
1646
- // options
1647
1439
  var _opts = {
1648
1440
  normal: 'nor',
1649
- // 'data-normal' 普通图片
1650
1441
  retina: 'ret',
1651
- // 'data-retina',
1652
1442
  srcset: 'set',
1653
- // 'data-srcset', 浏览器根据宽、高和像素密度来加载相应的图片资源
1654
1443
  threshold: 0
1655
1444
  };
1656
-
1657
1445
  var _opt;
1658
-
1659
1446
  var _ticking;
1660
-
1661
1447
  var _nodes;
1662
-
1663
1448
  var _windowHeight = window.innerHeight;
1664
-
1665
- var _root; // private
1666
-
1667
-
1668
- var _prevLoc = getLoc(); // feature detection
1669
- // https://github.com/Modernizr/Modernizr/blob/master/feature-detects/img/srcset.js
1670
-
1671
-
1672
- var _srcset = document.body.classList.contains('srcset') || 'srcset' in document.createElement('img'); // 设备分辨率
1673
- // not supported in IE10 - https://msdn.microsoft.com/en-us/library/dn265030(v=vs.85).aspx
1674
-
1675
-
1449
+ var _root;
1450
+ var _prevLoc = getLoc();
1451
+ var _srcset = document.body.classList.contains('srcset') || 'srcset' in document.createElement('img');
1676
1452
  var _dpr = window.devicePixelRatio || window.screen.deviceXDPI / window.screen.logicalXDPI;
1677
- /**
1678
- * 输外部可调用的类
1679
- * 类外面的变量、函数作为模块内部私有属性、方法,外部无法调用
1680
- * 如果全部放入类中,属性、函数相互调用,都需要 this,非常麻烦!
1681
- * 也可以直接使用 export default (options = {}) => {} 输出一个函数!
1682
- * 函数内部反而不需要this,比较方便。
1683
- */
1684
-
1685
-
1686
- var Lazy = /*#__PURE__*/function () {
1687
- // 实例属性
1453
+ var Lazy = function () {
1688
1454
  function Lazy(opt) {
1689
1455
  _opt = $.assign({}, _opts, opt);
1690
- } // API
1691
- //----------------------------------------
1692
- // dom 就绪后 start,dom 更新后,需 update
1693
-
1694
- /**
1695
- * 启动延迟加载, 加载事件, dom ready时调用!
1696
- * @param root 根对象, scroll的目标对象,错了无法触发scroll 事件!
1697
- * @returns {init}
1698
- */
1699
-
1700
-
1456
+ }
1701
1457
  var _proto = Lazy.prototype;
1702
-
1703
1458
  _proto.start = function start(root) {
1704
- // sui window scroll event invalid!!!
1705
- // ['scroll', 'resize'].forEach(event => window[action](event, requestScroll));
1706
1459
  ['scroll', 'resize'].forEach(function (event) {
1707
1460
  return root['addEventListener'](event, requestScroll);
1708
1461
  });
1709
1462
  _root = root;
1710
1463
  return this;
1711
- }
1712
- /**
1713
- * 停止延迟加载,卸载事件!
1714
- * @param root 根对象, scroll的目标对象
1715
- * @returns {init}
1716
- */
1717
- ;
1718
-
1464
+ };
1719
1465
  _proto.stop = function stop() {
1720
- // sui window scroll event invalid!!!
1721
- // ['scroll', 'resize'].forEach(event => window[action](event, requestScroll));
1722
1466
  ['scroll', 'resize'].forEach(function (event) {
1723
1467
  return _root['removeEventListener'](event, requestScroll);
1724
1468
  });
1725
1469
  return this;
1726
1470
  };
1727
-
1728
1471
  _proto.update = function update() {
1729
1472
  setTimeout(function () {
1730
1473
  _update();
1731
-
1732
1474
  check();
1733
1475
  }, 1);
1734
1476
  };
1735
-
1736
1477
  return Lazy;
1737
1478
  }();
1738
-
1739
1479
  function getLoc() {
1740
- // console.log(`window.scrollY:${window.scrollY} window.pageYOffset:${window.pageYOffset}`);
1741
1480
  return window.scrollY || window.pageYOffset;
1742
- } // debounce helpers
1743
-
1744
-
1481
+ }
1745
1482
  function requestScroll() {
1746
1483
  _prevLoc = getLoc();
1747
1484
  requestFrame();
1748
1485
  }
1749
-
1750
1486
  function requestFrame() {
1751
1487
  if (!_ticking) {
1752
1488
  window.requestAnimationFrame(function () {
@@ -1754,49 +1490,21 @@
1754
1490
  });
1755
1491
  _ticking = true;
1756
1492
  }
1757
- } // offset helper
1758
-
1759
- /**
1760
- * 节点相对视口的坐标,对于动态加载的,好像得到都是0,使用定时器延迟加载就能正确获取!
1761
- */
1762
-
1763
-
1493
+ }
1764
1494
  function getOffset(node) {
1765
- // 元素四个位置的相对于视口的坐标
1766
- return node.getBoundingClientRect().top + _prevLoc; // return node.offsetTop + _prevLoc;
1495
+ return node.getBoundingClientRect().top + _prevLoc;
1767
1496
  }
1768
- /**
1769
- * 节点是否在可视窗口判断
1770
- * 通过可视窗口顶部、底部坐标来判断
1771
- * 顶部坐标就是页面的滚动条滚动的距离
1772
- * 底部坐标就是滚动条的距离加上当前可视窗口的高度
1773
- * dom元素中心:元素到最顶端的高度加上自身高度的一半
1774
- * @param {*} node
1775
- */
1776
-
1777
-
1778
1497
  function inViewport(node) {
1779
- var viewTop = _prevLoc; // 视口顶部坐标
1780
-
1781
- var viewBot = viewTop + _windowHeight; // 视口底部坐标
1782
- // console.log(`viewTop:${viewTop} viewBot:${viewBot}`);
1783
- // 节点坐标
1784
-
1498
+ var viewTop = _prevLoc;
1499
+ var viewBot = viewTop + _windowHeight;
1785
1500
  var nodeTop = getOffset(node);
1786
- var nodeBot = nodeTop + node.offsetHeight; // console.log(`nodeTop:${nodeTop} nodeBot:${nodeBot}`);
1787
-
1788
- var offset = _opt.threshold / 100 * _windowHeight; // 节点在可视范围内
1789
-
1790
- var rc = nodeBot >= viewTop - offset && nodeTop <= viewBot + offset; // if (rc)
1791
- // console.log(`nodeBot:${nodeBot} >= view:${viewTop - offset} nodeTop:${nodeTop} <= view:${viewBot + offset}`);
1792
-
1501
+ var nodeBot = nodeTop + node.offsetHeight;
1502
+ var offset = _opt.threshold / 100 * _windowHeight;
1503
+ var rc = nodeBot >= viewTop - offset && nodeTop <= viewBot + offset;
1793
1504
  return rc;
1794
- } // source helper
1795
-
1796
-
1505
+ }
1797
1506
  function setSource(node) {
1798
- $.emit('lazy:src:before', node); // prefer srcset, fallback to pixel density
1799
-
1507
+ $.emit('lazy:src:before', node);
1800
1508
  if (_srcset && node.hasAttribute(_opt.srcset)) {
1801
1509
  node.setAttribute('srcset', node.getAttribute(_opt.srcset));
1802
1510
  } else {
@@ -1805,188 +1513,45 @@
1805
1513
  node.setAttribute('src', src);
1806
1514
  console.log("set src:" + src);
1807
1515
  }
1808
-
1809
- $.emit('lazy:src:after', node); // 删除懒加载属性,避免重复加载
1810
-
1516
+ $.emit('lazy:src:after', node);
1811
1517
  [_opt.normal, _opt.retina, _opt.srcset].forEach(function (attr) {
1812
1518
  return node.removeAttribute(attr);
1813
1519
  });
1814
-
1815
1520
  _update();
1816
1521
  }
1817
- /**
1818
- * 检查是否可视,如果可视则更改图片src,加载图片
1819
- * @returns {check}
1820
- */
1821
-
1822
-
1823
1522
  function check() {
1824
1523
  if (!_nodes) return;
1825
1524
  _windowHeight = window.innerHeight;
1826
-
1827
1525
  _nodes.forEach(function (node) {
1828
1526
  return inViewport(node) && setSource(node);
1829
1527
  });
1830
-
1831
1528
  _ticking = false;
1832
1529
  return this;
1833
1530
  }
1834
- /**
1835
- * 新的图片加入dom,需重新获取属性为nor的图片节点,
1836
- * @returns {update}
1837
- */
1838
-
1839
-
1840
1531
  function _update(root) {
1841
1532
  if (root) _nodes = Array.prototype.slice.call(root.querySelectorAll("[" + _opt.normal + "]"));else _nodes = Array.prototype.slice.call(document.querySelectorAll("[" + _opt.normal + "]"));
1842
1533
  return this;
1843
1534
  }
1844
1535
 
1845
- var Page = /*#__PURE__*/function (_Event) {
1846
- _inheritsLoose(Page, _Event);
1847
-
1848
- function Page(app, name, title, style) {
1849
- var _this;
1850
-
1851
- _this = _Event.call(this, null, [app]) || this;
1852
- _this.app = app;
1853
- _this.cfg = app.cfg;
1854
- _this.name = name; // 名称,支持带路径:admin/login
1855
-
1856
- _this.title = title; // 浏览器标题
1857
-
1858
- _this.style = style || "./page/" + name + ".css";
1859
- _this.path = "" + name; // url 路径,不使用正则,直接查找
1860
-
1861
- _this.view = null; // 页面的div层$Dom对象,router创建实例时赋值
1862
-
1863
- _this.el = null; // $dom
1864
-
1865
- _this.$el = null; // $dom
1866
-
1867
- _this.html = ''; // 页面html文本,router创建实例时赋值
1868
-
1869
- _this.css = ''; // 页面css样式,router创建实例时赋值
1870
-
1871
- _this.js = ''; // 页面代码,router创建实例时赋值
1872
-
1873
- _this.data = {}; // 页面数据对象
1874
-
1875
- _this.param = {}; // 页面切换传递进来的参数对象,router创建实例时赋值
1876
-
1877
- return _this;
1878
- }
1879
- /**
1880
- * 异步加载页面视图内容
1881
- * 返回Promise对象
1882
- * @param {*} param
1883
- * @param {*} cfg
1884
- */
1885
-
1886
-
1887
- var _proto = Page.prototype;
1888
-
1889
- _proto.load = function load(param) {
1890
- // $.assign(this.data, param);
1891
- this.emit('local::load pageLoad', param);
1892
- }
1893
- /**
1894
- * 在已经加载就绪的视图上操作
1895
- * @param {*} view 页面层的 Dom 对象,已经使用`$(#page-name)`,做了处理
1896
- * @param {*} param go 函数的参数,或 网址中 url 中的参数
1897
- * @param {*} back 是否为回退,A->B, B->A,这种操作属于回退
1898
- */
1899
- ;
1900
-
1901
- _proto.ready = function ready(view, param, back) {
1902
- // $.assign(this, {page, param, back});
1903
- // $.assign(this.data, param);
1904
- // 隐藏所有模板
1905
- this.init();
1906
- this.emit('local::ready pageReady', view, param, back);
1907
- }
1908
- /**
1909
- * 对页面进行初始化处理,或页面内容动态变更时,对局部页面容器进行初始化
1910
- * 具备name属性的dom节点直接赋值给页面view
1911
- * 只挂载一个,多个同名name,最后一个起作用,因此一个页面内,name不要重复
1912
- * 同节点多次调用不覆盖,同名不同dom节点,覆盖
1913
- * 覆盖后,原直接节点属性的 bind 会失效,需真的新的$dom重新bind
1914
- * @param {*} v dom 容器,默认为页面实例的view
1915
- */
1916
- ;
1917
-
1918
- _proto.init = function init(v) {
1919
- var view = this.view;
1920
- v = v ? $(v) : view; // 页面上带name属性节点,直接作为page.view的属性,方便页面代码直接调用
1921
-
1922
- var ns = v.qus('[name]');
1923
- ns === null || ns === void 0 ? void 0 : ns.forEach(function (n) {
1924
- var $n = $(n);
1925
- var name = $n.attr('name');
1926
- if (!view[name] || view[name].dom !== n) view[name] = $n;
1927
- }); // 隐藏所有模板
1928
-
1929
- v.qus('[name$=-tp]').hide(); // 防止空链接,刷新页面
1930
-
1931
- v.qus('a[href=""]').attr('href', 'javascript:;');
1932
- } // 显示已加载的页面
1933
- // view:页面Dom层,param:参数
1934
- ;
1935
-
1936
- _proto.show = function show(view, param) {
1937
- // 隐藏所有模板
1938
- view.qus('[name$=-tp]').hide(); // 防止空链接,刷新页面
1939
-
1940
- view.qus('a[href=""]').attr('href', 'javascript:;'); // this.init();
1941
-
1942
- if (this.reset) this.reset();
1943
- this.emit('local::show pageShow', view, param);
1944
- } // 回退显示已加载的页面
1945
- // view:页面Dom层,param:参数
1946
- ;
1947
-
1948
- _proto.back = function back(view, param) {
1949
- // 隐藏所有模板
1950
- view.qus('[name$=-tp]').hide(); // 防止空链接,刷新页面
1951
-
1952
- view.qus('a[href=""]').attr('href', 'javascript:;');
1953
- this.emit('local::back pageBack', view, param);
1954
- };
1955
-
1956
- _proto.hide = function hide(view) {
1957
- this.emit('local::hide pageHide', view);
1958
- };
1959
-
1960
- return Page;
1961
- }(Event);
1962
-
1963
1536
  var openedModals = [];
1964
1537
  var dialogsQueue = [];
1965
-
1966
1538
  function clearDialogsQueue() {
1967
1539
  if (dialogsQueue.length === 0) return;
1968
1540
  var dialog = dialogsQueue.shift();
1969
1541
  dialog.open();
1970
1542
  }
1971
-
1972
- var Modal = /*#__PURE__*/function (_Event) {
1543
+ var Modal = function (_Event) {
1973
1544
  _inheritsLoose(Modal, _Event);
1974
-
1975
1545
  function Modal(app, params) {
1976
1546
  var _this;
1977
-
1978
1547
  _this = _Event.call(this, params, [app]) || this;
1979
-
1980
1548
  var modal = _assertThisInitialized(_this);
1981
-
1982
1549
  var defaults = {};
1983
1550
  modal.params = Utils.extend(defaults, params);
1984
1551
  modal.opened = false;
1985
1552
  return _assertThisInitialized(_this) || _assertThisInitialized(_this);
1986
1553
  }
1987
-
1988
1554
  var _proto = Modal.prototype;
1989
-
1990
1555
  _proto.onOpen = function onOpen() {
1991
1556
  var modal = this;
1992
1557
  modal.opened = true;
@@ -1995,13 +1560,11 @@
1995
1560
  modal.$el.trigger("modal:open " + modal.type.toLowerCase() + ":open");
1996
1561
  modal.emit("local::open modalOpen " + modal.type + "Open", modal);
1997
1562
  };
1998
-
1999
1563
  _proto.onOpened = function onOpened() {
2000
1564
  var modal = this;
2001
1565
  modal.$el.trigger("modal:opened " + modal.type.toLowerCase() + ":opened");
2002
1566
  modal.emit("local::opened modalOpened " + modal.type + "Opened", modal);
2003
1567
  };
2004
-
2005
1568
  _proto.onClose = function onClose() {
2006
1569
  var modal = this;
2007
1570
  modal.opened = false;
@@ -2011,7 +1574,6 @@
2011
1574
  modal.$el.trigger("modal:close " + modal.type.toLowerCase() + ":close");
2012
1575
  modal.emit("local::close modalClose " + modal.type + "Close", modal);
2013
1576
  };
2014
-
2015
1577
  _proto.onClosed = function onClosed() {
2016
1578
  var modal = this;
2017
1579
  if (!modal.type || !modal.$el) return;
@@ -2020,26 +1582,22 @@
2020
1582
  modal.$el.trigger("modal:closed " + modal.type.toLowerCase() + ":closed");
2021
1583
  modal.emit("local::closed modalClosed " + modal.type + "Closed", modal);
2022
1584
  };
2023
-
2024
1585
  _proto.open = function open(animateModal) {
2025
1586
  var modal = this;
2026
1587
  var app = modal.app,
2027
- $el = modal.$el,
2028
- type = modal.type,
2029
- $backdropEl = modal.$backdropEl;
1588
+ $el = modal.$el,
1589
+ type = modal.type,
1590
+ $backdropEl = modal.$backdropEl;
2030
1591
  var moveToRoot = modal.params.moveToRoot;
2031
1592
  var animate = true;
2032
1593
  if (typeof animateModal !== 'undefined') animate = animateModal;else if (typeof modal.params.animate !== 'undefined') {
2033
1594
  animate = modal.params.animate;
2034
1595
  }
2035
-
2036
1596
  if (!$el || $el.hasClass('modal-in')) {
2037
1597
  return modal;
2038
1598
  }
2039
-
2040
1599
  if (type === 'dialog' && app.params.modal.queueDialogs) {
2041
1600
  var pushToQueue;
2042
-
2043
1601
  if ($('.dialog.modal-in').length > 0) {
2044
1602
  pushToQueue = true;
2045
1603
  } else if (openedModals.length > 0) {
@@ -2047,16 +1605,13 @@
2047
1605
  if (openedModal.type === 'dialog') pushToQueue = true;
2048
1606
  });
2049
1607
  }
2050
-
2051
1608
  if (pushToQueue) {
2052
1609
  dialogsQueue.push(modal);
2053
1610
  return modal;
2054
1611
  }
2055
1612
  }
2056
-
2057
1613
  var $modalParentEl = $el.parent();
2058
1614
  var wasInDom = $el.parents(document).length > 0;
2059
-
2060
1615
  if (moveToRoot && app.params.modal.moveToRoot && !$modalParentEl.is(app.root)) {
2061
1616
  app.root.append($el);
2062
1617
  modal.once(type + "Closed", function () {
@@ -2066,14 +1621,9 @@
2066
1621
  $el.remove();
2067
1622
  }
2068
1623
  });
2069
- } // Show Modal
2070
-
2071
-
1624
+ }
2072
1625
  $el.show();
2073
- /* eslint no-underscore-dangle: ["error", { "allow": ["_clientLeft"] }] */
2074
-
2075
- modal._clientLeft = $el[0].clientLeft; // Modal
2076
-
1626
+ modal._clientLeft = $el[0].clientLeft;
2077
1627
  function transitionEnd() {
2078
1628
  if ($el.hasClass('modal-out')) {
2079
1629
  modal.onClosed();
@@ -2081,13 +1631,11 @@
2081
1631
  modal.onOpened();
2082
1632
  }
2083
1633
  }
2084
-
2085
1634
  if (animate) {
2086
1635
  if ($backdropEl) {
2087
1636
  $backdropEl.removeClass('not-animated');
2088
1637
  $backdropEl.addClass('backdrop-in');
2089
1638
  }
2090
-
2091
1639
  $el.animationEnd(function () {
2092
1640
  transitionEnd();
2093
1641
  });
@@ -2100,15 +1648,12 @@
2100
1648
  if ($backdropEl) {
2101
1649
  $backdropEl.addClass('backdrop-in not-animated');
2102
1650
  }
2103
-
2104
1651
  $el.removeClass('modal-out').addClass('modal-in not-animated');
2105
1652
  modal.onOpen();
2106
1653
  modal.onOpened();
2107
1654
  }
2108
-
2109
1655
  return modal;
2110
1656
  };
2111
-
2112
1657
  _proto.close = function close(animateModal) {
2113
1658
  var modal = this;
2114
1659
  var $el = modal.$el;
@@ -2117,39 +1662,29 @@
2117
1662
  if (typeof animateModal !== 'undefined') animate = animateModal;else if (typeof modal.params.animate !== 'undefined') {
2118
1663
  animate = modal.params.animate;
2119
1664
  }
2120
-
2121
1665
  if (!$el || !$el.hasClass('modal-in')) {
2122
1666
  if (dialogsQueue.indexOf(modal) >= 0) {
2123
1667
  dialogsQueue.splice(dialogsQueue.indexOf(modal), 1);
2124
1668
  }
2125
-
2126
1669
  return modal;
2127
- } // backdrop
2128
-
2129
-
1670
+ }
2130
1671
  if ($backdropEl) {
2131
1672
  var needToHideBackdrop = true;
2132
-
2133
1673
  if (modal.type === 'popup') {
2134
1674
  modal.$el.prevAll('.popup.modal-in').each(function (index, popupEl) {
2135
1675
  var popupInstance = popupEl.f7Modal;
2136
1676
  if (!popupInstance) return;
2137
-
2138
1677
  if (popupInstance.params.closeByBackdropClick && popupInstance.params.backdrop && popupInstance.backdropEl === modal.backdropEl) {
2139
1678
  needToHideBackdrop = false;
2140
1679
  }
2141
1680
  });
2142
1681
  }
2143
-
2144
1682
  if (needToHideBackdrop) {
2145
1683
  $backdropEl[animate ? 'removeClass' : 'addClass']('not-animated');
2146
1684
  $backdropEl.removeClass('backdrop-in');
2147
1685
  }
2148
- } // Modal
2149
-
2150
-
1686
+ }
2151
1687
  $el[animate ? 'removeClass' : 'addClass']('not-animated');
2152
-
2153
1688
  function transitionEnd() {
2154
1689
  if ($el.hasClass('modal-out')) {
2155
1690
  modal.onClosed();
@@ -2157,7 +1692,6 @@
2157
1692
  modal.onOpened();
2158
1693
  }
2159
1694
  }
2160
-
2161
1695
  if (animate) {
2162
1696
  $el.animationEnd(function () {
2163
1697
  transitionEnd();
@@ -2165,69 +1699,52 @@
2165
1699
  $el.transitionEnd(function () {
2166
1700
  transitionEnd();
2167
1701
  });
2168
- $el.removeClass('modal-in').addClass('modal-out'); // Emit close
2169
-
1702
+ $el.removeClass('modal-in').addClass('modal-out');
2170
1703
  modal.onClose();
2171
1704
  } else {
2172
- $el.addClass('not-animated').removeClass('modal-in').addClass('modal-out'); // Emit close
2173
-
1705
+ $el.addClass('not-animated').removeClass('modal-in').addClass('modal-out');
2174
1706
  modal.onClose();
2175
1707
  modal.onClosed();
2176
1708
  }
2177
-
2178
1709
  if (modal.type === 'dialog') {
2179
1710
  clearDialogsQueue();
2180
1711
  }
2181
-
2182
1712
  return modal;
2183
1713
  };
2184
-
2185
1714
  _proto.destroy = function destroy() {
2186
1715
  var modal = this;
2187
1716
  if (modal.destroyed) return;
2188
1717
  modal.emit("local::beforeDestroy modalBeforeDestroy " + modal.type + "BeforeDestroy", modal);
2189
-
2190
1718
  if (modal.$el) {
2191
1719
  modal.$el.trigger("modal:beforedestroy " + modal.type.toLowerCase() + ":beforedestroy");
2192
-
2193
1720
  if (modal.$el.length && modal.$el[0].f7Modal) {
2194
1721
  delete modal.$el[0].f7Modal;
2195
1722
  }
2196
1723
  }
2197
-
2198
1724
  Utils.deleteProps(modal);
2199
1725
  modal.destroyed = true;
2200
1726
  };
2201
-
2202
1727
  return Modal;
2203
1728
  }(Event);
2204
1729
 
2205
- // replace react, use by @babel/plugin-transform-react-jsx
2206
-
2207
- /* eslint-disable prefer-rest-params */
2208
1730
  function jsx(tag, props) {
2209
1731
  var attrs = props || {};
2210
-
2211
1732
  for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
2212
1733
  args[_key - 2] = arguments[_key];
2213
1734
  }
2214
-
2215
1735
  var children = args || [];
2216
1736
  var attrsString = Object.keys(attrs).map(function (attr) {
2217
1737
  if (attr[0] === '_') {
2218
1738
  if (attrs[attr]) return attr.replace('_', '');
2219
1739
  return '';
2220
1740
  }
2221
-
2222
1741
  return attr + "=\"" + attrs[attr] + "\"";
2223
1742
  }).filter(function (attr) {
2224
1743
  return !!attr;
2225
1744
  }).join(' ');
2226
-
2227
1745
  if (['path', 'img', 'circle', 'polygon', 'line', 'input'].indexOf(tag) >= 0) {
2228
1746
  return ("<" + tag + " " + attrsString + " />").trim();
2229
1747
  }
2230
-
2231
1748
  var childrenContent = children.filter(function (c) {
2232
1749
  return !!c;
2233
1750
  }).map(function (c) {
@@ -2236,8 +1753,6 @@
2236
1753
  return ("<" + tag + " " + attrsString + ">" + childrenContent + "</" + tag + ">").trim();
2237
1754
  }
2238
1755
 
2239
- // export {default as Device} from './device';
2240
-
2241
1756
  var Support = $.support;
2242
1757
  var Device = $.device;
2243
1758
 
@@ -2258,6 +1773,4 @@
2258
1773
  exports.jsx = jsx;
2259
1774
  exports.loadModule = loadModule;
2260
1775
 
2261
- Object.defineProperty(exports, '__esModule', { value: true });
2262
-
2263
1776
  }));