efront 3.9.14 → 3.10.3

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.
@@ -0,0 +1,68 @@
1
+ return _cross.bind(function (callback, onerror) {
2
+ var response;
3
+ var xhr = {
4
+ status: 0,
5
+ method: null,
6
+ url: null,
7
+ http: null,
8
+ headers: {},
9
+ response: null,
10
+ getResponseHeader(key) {
11
+ return response.headers[key];
12
+ },
13
+ send(data) {
14
+ var { hostname, port, path, auth } = parseURL(this.url);
15
+ if (data) {
16
+ data = Buffer.from(data);
17
+ this.headers["Content-Length"] = data.length;
18
+ }
19
+ var req = http.request({
20
+ method: this.method,
21
+ hostname,
22
+ port,
23
+ path,
24
+ auth,
25
+ headers: this.headers,
26
+ }, function (res) {
27
+ var data = [];
28
+ var session_text = res.headers["set-cookie"];
29
+ if (session_text instanceof Array) session_text.forEach(t => cookie.addCookie(t));
30
+ else if (typeof session_text === "string") cookie.addCookie(session_text);
31
+ xhr.status = res.statusCode;
32
+ xhr.response = res;
33
+ res.on("data", function (chunk) {
34
+ data.push(chunk);
35
+ });
36
+ res.on("end", function () {
37
+ data = Buffer.concat(data);
38
+ xhr.response = data;
39
+ callback(res.statusCode, data);
40
+ console.log(String(data), res.statusCode);
41
+ });
42
+ res.on("error", function (e) {
43
+ onerror(e);
44
+ });
45
+ });
46
+ if (data) req.end(data);
47
+ else req.end();
48
+ },
49
+ open(method, url) {
50
+ this.method = method;
51
+ this.url = url;
52
+ this.status = 0;
53
+ var http;
54
+ if (/^https?\:/i.test(url)) {
55
+ http = require("http");
56
+ }
57
+ else {
58
+ http = require("https");
59
+ }
60
+ this.http = http;
61
+ },
62
+ setRequestHeader(key, value) {
63
+ this.headers[key] = value;
64
+ },
65
+
66
+ };
67
+ return xhr;
68
+ }, null, undefined);
File without changes
@@ -23,7 +23,7 @@ function main(m3u8, dst) {
23
23
  console.info(file);
24
24
  var fileurl = URL.resolve(m3u8, file);
25
25
  return fetch(fileurl).then(function (buff) {
26
- return fs(path.join(dst, index(cx, list.length) + '.' + file)).writeSync(buff);
26
+ return fs2(path.join(dst, index(cx, list.length) + '.' + file)).writeSync(buff);
27
27
  });
28
28
  });
29
29
  });
@@ -0,0 +1,14 @@
1
+ function bind(eventName, bindTo = window) {
2
+ return function (target, eventListener) {
3
+ var off;
4
+ var off1 = on("append")(target, function () {
5
+ if (off) off();
6
+ off = on(eventName).call(bindTo, target, eventListener);
7
+ });
8
+ var off2 = on("remove")(target, function () {
9
+ if (off) off();
10
+ off = null;
11
+ });
12
+ return function () { off1(); off2(); };
13
+ }
14
+ }
@@ -183,6 +183,7 @@ a&,
183
183
  color: @default-color;
184
184
  cursor: pointer;
185
185
  outline: none;
186
+ .clear();
186
187
 
187
188
  .clear() {
188
189
  text-shadow: none;
@@ -1,22 +1,14 @@
1
- var FormData = this.FormData;
2
- var cookiesMap = {};
3
- // ///// 1 ////////// 2 /////// 3 //// 4 //
4
- var domainReg = /^(?:(https?)\:)?\/\/(.*?)(?:\/(.*?))?([\?#].*)?$/i;
5
- var base = domainReg.test(location.href) ? '/' : "http://efront.cc/";
6
- var location_host = location.href.replace(domainReg, '$1://$2/');
7
- var setHost = function (host) {
8
- var parsed = parseURL(host);
9
- if (!host) return console.error("cross_host格式不正确", host);
10
- var host = parsed.host + (parsed.pathname || '/');
11
- host = (/^https/.test(location_host) ? "https://" : "http://") + host;
12
- base = host;
13
- };
1
+ var { cookiesMap, saveCookie } = cookie;
2
+ var saveCookie = lazy(function () {
3
+ sessionStorage.setItem(cookieItemsInSessionStorageKey, JSON.stringify(cookiesMap));
4
+ }, 20);
14
5
  var { efrontURI, cross_host = efrontURI } = this;
15
- if (cross_host) setHost(cross_host);
16
- var HeadersKeys = ["Content-Type"];
6
+ var location_href = parseURL(location.href);
7
+ location_href = `${location_href.protocol}//${location_href.host}/`;
8
+ _cross.setLocation(location_href);
9
+
17
10
  var cookieItemsInSessionStorageKey = "--zimoli-coms-cross";
18
11
  var cookiesData = sessionStorage.getItem(cookieItemsInSessionStorageKey);
19
- var cors_hosts = [];
20
12
  if (cookiesData) {
21
13
  try {
22
14
  extend(cookiesMap, JSON.parse(cookiesData));
@@ -24,337 +16,45 @@ if (cookiesData) {
24
16
  console.warn("加载cookie出错!");
25
17
  }
26
18
  }
27
- function getDomainPath(url) {
28
- return url.replace(domainReg, "$2/$3");
29
- }
30
- function getRequestProtocol(url) {
31
- if (/^https:/i.test(url)) {
32
- return "https:";
33
- }
34
- return "http:";
35
- }
36
- function getCookies(domainPath) {
37
- var cookieObject = {};
38
- var splited = domainPath.split("/");
39
- var domain = splited[0];
40
- do {
41
- var copy = splited.slice(0);
42
- do {
43
- domainPath = copy.join("/");
44
- var cookie = cookiesMap[domainPath];
45
- if (cookie) {
46
- for (var k in cookie) {
47
- if (!cookieObject[k]) {
48
- cookieObject[k] = cookie[k];
49
- }
50
- }
51
- }
52
- copy.pop();
53
- } while (copy.length);
54
- domain = domain.replace(/^.*?(\.|$)/, "");
55
- splited[0] = domain;
56
- } while (domain.length);
57
- return serialize(cookieObject, ";");
58
- }
59
- function addCookie(cookie, originDomain = "") {
60
- if (cookie) {
61
- clearTimeout(addCookie.save_timer);
62
- addCookie.save_timer = setTimeout(function () {
63
- sessionStorage.setItem(cookieItemsInSessionStorageKey, JSON.stringify(cookiesMap));
64
- }, 20);
65
- cookie.replace(/(^|;|,)\s*(expires)=(\w*),([^=]*)(;|$)/ig, "$1$2=$3.$4$5")
66
- .split(/,\s*/).map(function (cookie) {
67
- var cookieObject = {};
68
- var result = cookie.split(/;\s*/);
69
- result.slice(1).map(function (kev) {
70
- var kvs = /^(.+?)\=(.+?)$/.exec(kev);
71
- if (kvs) {
72
- var [, k, v] = kvs;
73
- cookieObject[k.toLowerCase()] = v;
74
- }
75
- });
76
- var { path, domain } = cookieObject;
77
- if (!domain) {
78
- domain = originDomain.replace(/[^\/]+$/, "");
79
- }
80
- if (/^\./.test(domain)) {
81
- domain = domain.replace(/^\.+/, "");
82
- }
83
- var destPath;
84
- if (/^\//.test(path)) {
85
- destPath = domain.replace(/\/.*$/, "") + path;
86
- } else {
87
- destPath = domain;
88
- }
89
- destPath = destPath.replace(/\/+$/, "");
90
- if (originDomain.indexOf(destPath) >= 0) {
91
- var cookieMap = parseKV(result[0], ";");
92
- if (!cookiesMap[destPath]) {
93
- cookiesMap[destPath] = cookieMap;
94
- } else {
95
- extend(cookiesMap[destPath], cookieMap);
96
- }
97
- }
98
- });
99
- }
100
- }
101
- function isChildPath(relative, path) {
102
- return relative.replace(/^(.*\/)[^\/]*$/, path);
103
- }
19
+
104
20
  var digest = function () {
105
21
  dispatch('render', window);
106
22
  };
107
23
 
108
- var getCrossUrl = function (domain, headers) {
109
- if (notCross(domain)) return domain;
110
- var originDomain = getDomainPath(domain);
111
- var _cookies = getCookies(originDomain);
112
- var _headers = {};
113
- if (_cookies) {
114
- _headers.Cookie = _cookies;
115
- }
116
- extend(_headers, headers);
117
- _headers = serialize(_headers);
118
- if (_headers) _headers = "," + _headers;
119
- return domain
120
- .replace(/^(s?)(\/\/)/i, "http$1:$2")
121
- .replace(domainReg, base + `*${/^(https\:|s\/\/)/i.test(domain) ? "*" : ""}$2${_headers}/$3$4`);
122
- };
123
- function cross(method, url, headers) {
124
- var originDomain = getDomainPath(url);
125
- if (!originDomain) throw new Error("Unsupposed url format!");
126
- var _cookies = getCookies(originDomain);
127
- var _headers = {};
128
- if (_cookies) {
129
- _headers.Cookie = _cookies;
130
- }
131
- extend(_headers, headers);
132
- if (/^[mc]/i.test(method)) {
133
- _headers["User-Agent"] = /^m/i.test(method)
134
- ? "Efront/1.9 (iPhone) Safari/602.1"
135
- : "Efront/1.9 (Windows) Chrome/77.0.3865.90";
136
- method = method.slice(1);
137
- }
138
- if (/^jsonp/i.test(method)) {
139
- var cb = method.split('\-')[1] || 'callback';
140
- setTimeout(function () {
141
- if (!isEmpty(jsondata) && isEmpty(datas)) {
142
- datas = serialize(jsondata);
143
- }
144
- if (datas) {
145
- xhr.src += "&" + datas;
146
- }
147
- });
148
- var xhr = jsonp(url, {
149
- [cb](a) {
150
- xhr.response = xhr.responseText = JSON.stringify(a);
151
- onload(xhr);
152
- }
153
- });
154
- xhr.onerror = function (e) {
155
- onerror(e);
156
- };
157
- xhr.abort = function () {
158
- removeFromList(requests, this);
159
- remove(this);
160
- };
161
- } else {
162
- var nocross = notCross(url);
163
- var xhr = new XMLHttpRequest;
164
- var abort = xhr.abort;
165
- xhr.abort = function () {
166
- xhr.onreadystatechange = null;
167
- removeFromList(requests, this);
168
- abort.call(this);
169
- clearTimeout(sendtimer);
170
- };
24
+ var cross = _cross.bind(function (callback, onerror) {
25
+ var xhr = new XMLHttpRequest;
26
+ var abort = xhr.abort;
27
+ xhr.abort = function () {
28
+ xhr.onreadystatechange = null;
29
+ abort.call(this);
30
+ };
31
+ xhr.onerror = onerror;
171
32
 
172
- xhr.onreadystatechange = function () {
173
- if (xhr.readyState === 4) {
174
- if (xhr.getResponseHeader && !nocross) {
175
- var cookie = xhr.getResponseHeader("efront-cookie");
176
- addCookie(cookie, originDomain);
177
- }
178
- switch (xhr.status) {
179
- case 0:
180
- if (!navigator.onLine) {
181
- onerror({ status: "网络断开" });
182
- break;
183
- }
184
- if (!xhr.response) {
185
- onerror({ status: "无法访问服务器" });
186
- break;
187
- }
188
- case 200:
189
- case 201:
190
- case 304:
191
- onload(xhr);
33
+ xhr.onreadystatechange = function () {
34
+ if (xhr.readyState === 4) {
35
+ dispatch(window, 'render');
36
+ switch (xhr.status) {
37
+ case 0:
38
+ if (!navigator.onLine) {
39
+ onerror({ status: "网络断开" });
192
40
  break;
193
- case 302:
194
- case 301:
195
- if (xhr.isRedirected > 2 || nocross) break;
196
- var location = xhr.getResponseHeader("efront-location");
197
- if (!domainReg.test(location)) {
198
- if (/^\//.test(location)) {
199
- location = originDomain.replace(/\/.*$/, location);
200
- } else {
201
- location = originDomain.replace(/[^\/+]$/, location);
202
- }
203
- location = getRequestProtocol(url) + "//" + location;
204
- }
205
- var crs = cross("get", location, headers);
206
- crs.isRedirected = (xhr.isRedirected || 0) + 1;
207
- crs.done(onload, false);
208
- crs.error(onerror, false);
209
- break;
210
- default:
211
- onerror(xhr);
212
- }
213
- dispatch(window, 'render');
214
- }
215
- };
216
- var setRequestHeader = xhr.setRequestHeader;
217
- var realHeaders = Object.create(null);
218
- xhr.setRequestHeader = function (key, value) {
219
- realHeaders[key] = value;
220
- };
221
- xhr.then = function (ok, oh) {
222
- onloads.push(ok);
223
- onerrors.push(oh);
224
- flush();
225
- };
226
- var sendtimer = setTimeout(function () {
227
- digest();
228
- var isform = /^f/i.test(method);
229
- if (isform) {
230
- if (method === 'form') method = 'post';
231
- else method = method.slice(1);
232
- }
233
- if (!isEmpty(jsondata) && isEmpty(datas)) {
234
- if (/^(get|head|trace)$/i.test(method)) {
235
- url = url.replace(/#[\s\S]*/, '');
236
- datas = serialize(jsondata);
237
- if (datas) url += (/\?/.test(url) ? "&" : "?") + datas;
238
- } else if (isform) {
239
- xhr.form(jsondata);
240
- } else {
241
- datas = JSON.stringify(jsondata);
242
- if (datas === "{}" || datas === "[]") {
243
- datas = '';
244
- } else {
245
- realHeaders["Content-Type"] = "application/json;charset=UTF-8";
246
41
  }
247
- }
248
- }
249
- if (nocross) {
250
- extend(realHeaders, _headers);
251
- xhr.open(method, url);
252
- } else {
253
- xhr.open(method, getCrossUrl(url, _headers));
254
- }
255
- Object.keys(realHeaders).forEach(key => setRequestHeader.call(xhr, key, realHeaders[key]));
256
- send.call(xhr, datas);
257
- }, 0);
258
- }
259
- var loaded, errored;
260
- var onload = function (xhr) {
261
- removeFromList(requests, xhr);
262
- if (xhr.decoder) {
263
- xhr = xhr.decoder(xhr);
264
- }
265
- loaded = xhr;
266
- flush();
267
- digest();
268
- };
269
- var onerror = function (xhr) {
270
- removeFromList(requests, xhr);
271
- errored = xhr;
272
- flush();
273
- digest();
274
- };
275
- var flush = function () {
276
- var then = xhr.then;
277
- delete xhr.then;
278
- if (loaded) onloads.splice(0, onloads.length).map(e => e instanceof Function && e(xhr));
279
- if (errored) onerrors.splice(0, onerrors.length).map(e => e instanceof Function && e(errored));
280
- xhr.then = then;
281
- };
282
- var onloads = [], onerrors = [];
283
- xhr.done = xhr.success = function (on, asqueue = true) {
284
- if (!asqueue) onloads.splice(0, onloads.length);
285
- onloads.push(on);
286
- flush();
287
- return xhr;
288
- };
289
- var send = xhr.send;
290
- var datas = "";
291
- var jsondata = null;
292
- xhr.json = xhr.data = xhr.send = function (data, value) {
293
- if (!jsondata && !(isEmpty(data) && isEmpty(value))) jsondata = data instanceof Array ? [] : {};
294
- if (FormData && data instanceof FormData) {
295
- datas = data;
296
- } else if (isObject(data) && !isFile(data)) {
297
- extend(jsondata, data);
298
- } else if (!isEmpty(value)) {
299
- extend(jsondata, { [data]: value });
300
- } else if (isString(data) && value !== false && /^\s*\{|\=/.test(data)) {
301
- var data = /^\s*\{/.test(data) ? JSON.parse(data) : parseKV(data, "&", "=");
302
- extend(jsondata, data);
303
- } else {
304
- datas = data;
305
- }
306
- return xhr;
307
- };
308
- xhr.form = function (data) {
309
- xhr.data(data);
310
- if (FormData) {
311
- datas = new FormData;
312
- for (var k in jsondata) {
313
- datas.append(k, jsondata[k]);
42
+ break;
43
+ default:
44
+ callback(xhr.status, xhr.response);
314
45
  }
315
- } else {
316
- realHeaders["Content-Type"] = "application/x-www-form-urlencoded";
317
- datas = serialize(jsondata, "&", "=");
46
+ saveCookie();
318
47
  }
319
48
  };
320
- xhr.fail = xhr.error = function (on, asqueue = true) {
321
- if (!asqueue) {
322
- onerrors.splice(0, onerrors.length);
323
- }
324
- onerrors.push(on);
325
- flush();
326
- return xhr;
327
- };
328
- requests.push(xhr);
49
+
329
50
  return xhr;
330
- }
331
- function addDirect(a) {
332
- if (typeof a === 'string' || a instanceof RegExp) cors_hosts.push(a);
333
- }
334
- function notCross(domain) {
335
- if (location_host === domain.slice(0, location_host.length) || !/^https?\:\/\/|^s?\/\//.test(domain)) return true;
336
- for (var cx = 0, dx = cors_hosts.length; cx < dx; cx++) {
337
- var host = cors_hosts[cx];
338
- if (host instanceof RegExp) {
339
- if (host.test(domain)) return true;
340
- } else {
341
- host = host.replace(domainReg, '$2/$3');
342
- if (domain.replace(domainReg, '$2/$3').slice(0, host.length) === host) return true;
343
- }
344
- }
345
- return false;
346
- }
51
+ }, jsonp, digest);
347
52
 
348
- var requests = [];
349
- extend(cross, {
350
- requests,
351
- abortAll() {
352
- var rs = requests.splice(0, requests.length);
353
- for (var r of rs) r.abort();
354
- },
355
- setHost,
356
- getCookies,
357
- addCookie,
358
- addDirect,
359
- getCrossUrl
360
- });
53
+ cross.setHost = function (host) {
54
+ var parsed = parseURL(host);
55
+ if (!host) return console.error("cross_host格式不正确", host);
56
+ var host = parsed.host + (parsed.pathname || '/');
57
+ host = (/^https/.test(location_href) ? "https://" : "http://") + host;
58
+ _cross.setHost(host);
59
+ };
60
+ if (cross_host) cross.setHost(cross_host);
@@ -539,9 +539,9 @@ var privates = {
539
539
  rest.forEach(k => delete params[k]);
540
540
  return { method: realmethod, coinmethod, selector: method.slice(spliterIndex + 1), search, baseuri, uri, params };
541
541
  },
542
- loadIgnoreConfig(method, url, params, api) {
542
+ loadIgnoreConfig(method, url, params1, api) {
543
543
  var headers = api && api.headers;
544
- var { method: realmethod, uri, baseuri, coinmethod, search, selector, params } = this.prepare(method, url, params);
544
+ var { method: realmethod, uri, baseuri, coinmethod, search, selector, params } = this.prepare(method, url, params1);
545
545
  var id = realmethod + " " + baseuri;
546
546
  var promise = cachedLoadingPromise[id];
547
547
  var temp = JSON.stringify(params);
@@ -556,7 +556,7 @@ var privates = {
556
556
  }).error(xhr => {
557
557
  try {
558
558
  var e = getErrorMessage(parseData(xhr.response || xhr.responseText || xhr.statusText || xhr.status));
559
- oh({ status: xhr.status, error: e, toString: getErrorMessage })
559
+ oh({ status: xhr.status, api, params: params1, error: e, toString: getErrorMessage })
560
560
  } catch (error) {
561
561
  oh(error);
562
562
  }
@@ -852,12 +852,12 @@ var data = {
852
852
  instance.loading.abort();
853
853
  }
854
854
  this.responseLoading(instance);
855
- var params = privates.pack(sid, params1);
856
- if (!privates.validApi(api, params)) throw aborted;
855
+ var params2 = privates.pack(sid, params1);
856
+ if (!privates.validApi(api, params2)) throw aborted;
857
857
  let url = api.url;
858
858
  var base = api.base;
859
859
  if (base) url = base + api.path;
860
- var { method, uri, params, selector } = privates.prepare(api.method, url, params);
860
+ var { method, uri, params, selector } = privates.prepare(api.method, url, params2);
861
861
  var promise = new Promise(function (ok, oh) {
862
862
  var headers = api.headers;
863
863
  if (headers) {
@@ -872,7 +872,7 @@ var data = {
872
872
  instance.loading = null;
873
873
  try {
874
874
  var e = getErrorMessage(parseData(xhr.response || xhr.responseText || xhr.statusText || xhr.status));
875
- oh({ status: xhr.status, error: e, toString: getErrorMessage })
875
+ oh({ status: xhr.status, error: e, api, params: params2, toString: getErrorMessage })
876
876
  } catch (error) {
877
877
  oh(error);
878
878
  }
@@ -23,5 +23,8 @@ function jsonp(url, params) {
23
23
  url += /\?/.test(url) ? "&" + search : "?" + search;
24
24
  }
25
25
  var s = script(url);
26
+ s.abort = function () {
27
+ remove(this);
28
+ };
26
29
  return s;
27
30
  }
package/coms/zimoli/on.js CHANGED
@@ -167,8 +167,13 @@ if (is_addEventListener_enabled) {
167
167
  var eventtypes = parseEventTypes(k);
168
168
  k = k.replace(eventtypereg, '');
169
169
  function addhandler(element, handler, firstmost) {
170
+ var target = this;
170
171
  handler = wrapHandler(handler);
171
172
  if (eventtypes.capture) firstmost = true;
173
+ if (target && element !== target) {
174
+ handler = handler.bind(element);
175
+ element = target;
176
+ }
172
177
  if (k === changes_key) {
173
178
  if (!element.needchanges) element.needchanges = 0;
174
179
  element.needchanges++;
@@ -207,11 +212,16 @@ if (is_addEventListener_enabled) {
207
212
 
208
213
  if (handlersMap[on_event_path]) return handlersMap[on_event_path];
209
214
  function addhandler(element, handler, firstmost = false) {
215
+ var target = this;
210
216
  handler = wrapHandler(handler);
211
217
  if (eventtypes.capture) {
212
218
  console.warn("当前运行环境不支持事件capture");
213
219
  firstmost = true;
214
220
  }
221
+ if (target && element !== target) {
222
+ handler = handler.bind(element);
223
+ element = target;
224
+ }
215
225
  if (k === changes_key) {
216
226
  if (!element.needchanges) element.needchanges = 0;
217
227
  element.needchanges++;
@@ -105,9 +105,16 @@ var popup_path = function (path = "", parameters, target) {
105
105
  element.style.opacity = 1;
106
106
  });
107
107
  }
108
+ callbacks.forEach(f => f(element));
108
109
  };
110
+ var callbacks = [];
109
111
  popup.prepare(path, fullfill);
110
- return element;
112
+ return element || {
113
+ then(ok) {
114
+ if (element) return ok(element);
115
+ else callbacks.push(ok);
116
+ }, fullfill
117
+ };
111
118
  };
112
119
 
113
120
  var popup_view = function (element, target, style) {
@@ -52,12 +52,19 @@ body>& {
52
52
  position: relative;
53
53
  position: sticky;
54
54
  line-height: 20px;
55
- white-space: nowrap;
56
55
  overflow: hidden;
57
56
  text-overflow: ellipsis;
58
57
  color: #333;
59
58
  padding: 12px 16px 10px 16px;
60
59
 
60
+ &:before {
61
+ display: block;
62
+ content: "";
63
+ width: 20px;
64
+ height: 20px;
65
+ float: right;
66
+ }
67
+
61
68
  &:not(:last-child) {
62
69
  margin: 0 0 -42px;
63
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.9.14",
3
+ "version": "3.10.3",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {