efront 4.22.10 → 4.22.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@ var strings = require("../basic/strings");
8
8
  var lastLogLength = 0;
9
9
  var needNextLine = false;
10
10
  var getColor = function (c) {
11
+ if (c === 'wrap') return;
11
12
  if (!c) return colors.Reset;
12
13
  switch (c) {
13
14
  case "red":
@@ -118,7 +119,7 @@ var formatRows = function (arg, rows, deep, entry, leave) {
118
119
  if (rows.length === 0) return entry + leave;
119
120
  var ci = circleobjs.indexOf(arg);
120
121
  if (ci >= 0) {
121
- entry = `<cyan><引用点 *${ci + 1}></cyan> ` + entry;
122
+ entry = bindColor('cyan', `<引用点 *${ci + 1}> `) + entry;
122
123
  }
123
124
  if (deepobjs.length === 0) circleobjs.splice(0, circleobjs.length);
124
125
  var space = new Array(deep).join(" ");
@@ -180,17 +181,17 @@ var format = function (arg, deep = 0) {
180
181
  deep++;
181
182
  if (arg === null) return String(arg);
182
183
  if (typeof arg === 'string') {
183
- if (deep > 1) return "<green>" + strings.encode(arg) + "</green>";
184
+ if (deep > 1) return bindColor("green", arg);
184
185
  return arg;
185
186
  }
186
- if (typeof arg === 'function') return `<cyan>[${arg.constructor.name}${arg.name ? ": " + arg.name : " (匿名)"}]</cyan>`;
187
- if (/^(number|boolean)$/.test(typeof arg)) return '<yellow>' + arg + "</yellow>";
188
- if (arg === undefined) return "<gray>undefined</gray>";
187
+ if (typeof arg === 'function') return bindColor('cyan', `[${arg.constructor.name}${arg.name ? ": " + arg.name : " (匿名)"}]`);
188
+ if (/^(number|boolean)$/.test(typeof arg)) return bindColor('yellow', arg);
189
+ if (arg === undefined) return bindColor('gray', 'undefined');
189
190
  if (typeof arg === "object") {
190
191
  if (deepobjs.indexOf(arg) >= 0) {
191
192
  var ci = circleobjs.indexOf(arg);
192
193
  if (ci < 0) ci = circleobjs.length, circleobjs.push(arg);
193
- return `<cyan>[循环点 *${ci + 1}]</cyan>`;
194
+ return bindColor("cyan", `[循环点 *${ci + 1}]`);
194
195
  }
195
196
  if (arg instanceof Error) {
196
197
  if (deep > 1) return String(arg.message);
@@ -198,7 +199,7 @@ var format = function (arg, deep = 0) {
198
199
  }
199
200
  if (arg instanceof Buffer || arg instanceof ArrayBuffer || arg instanceof SharedArrayBuffer) {
200
201
  var data = new Uint8Array(arg.buffer || arg, arg.byteOffset || 0, arg.byteLength);
201
- return `<magenta><${arg.constructor.name} ${Array.prototype.slice.call(data, 0, 20).map(a => a < 16 ? "0" + a.toString(16) : a.toString(16)).join(' ')}${arg.byteLength > 20 ? ` ... 其他 ${arg.byteLength - 20} 字节` : ''}></magenta>`;
202
+ return bindColor('magenta', `<${arg.constructor.name} ${Array.prototype.slice.call(data, 0, 20).map(a => a < 16 ? "0" + a.toString(16) : a.toString(16)).join(' ')}${arg.byteLength > 20 ? ` ... 其他 ${arg.byteLength - 20} 字节` : ''}>`);
202
203
  }
203
204
  else if (isFinite(arg.length)) {
204
205
  var entry = "[";
@@ -209,26 +210,26 @@ var format = function (arg, deep = 0) {
209
210
  deepobjs.push(arg);
210
211
  var res = Array.prototype.slice.call(arg, 0, 100).map(a => format(a, deep));
211
212
  deepobjs.pop();
212
- if (arg.length > res.length) res.push(`<gray>.. 其他 ${arg.length - res.length} 项</gray>`);
213
+ if (arg.length > res.length) res.push(bindColor('gray', `.. 其他 ${arg.length - res.length} 项`));
213
214
  return formatRows(arg, res, deep, entry, leave);
214
215
  }
215
216
  if (arg.constructor === Date) {
216
- return '<purple>' + formatDate.call(arg) + "</purple>";
217
+ return bindColor('purple', formatDate.call(arg));
217
218
  }
218
219
  if (arg.constructor === RegExp) {
219
- return `<red2>/${arg.source}/</red2><cyan>${arg.flags}</cyan>`;
220
+ return bindColor('red2', `/${arg.source}/`) + bindColor('cyan', arg.flags);
220
221
  }
221
222
  var keys = Object.keys(arg);
222
223
  var ks = keys.slice(0, 100);
223
224
  if (deep > 3 && deep + keys.length > 5) {
224
225
  var kvs = [];
225
- if (keys.length > 0) kvs.push(`<gray>.. 共 ${keys.length} 个属性</gray>`);
226
+ if (keys.length > 0) kvs.push(bindColor('gray', `.. 共 ${keys.length} 个属性`));
226
227
  }
227
228
  else {
228
229
  deepobjs.push(arg);
229
230
  var kvs = ks.map(k => `${/[\:'"`\[\{\(\r\n\u2028\u2029]|^\s|\s$/.test(k) ? format(k, deep) : k}: ${format(arg[k], deep)}`);
230
231
  deepobjs.pop();
231
- if (keys.length > ks.length) kvs.push(`<gray>.. 其他 ${keys.length - ks.length} 个属性</gray>`);
232
+ if (keys.length > ks.length) kvs.push(bindColor('gray', `.. 其他 ${keys.length - ks.length} 个属性`));
232
233
  }
233
234
  var entry = '{';
234
235
  if (arg.constructor && arg.constructor !== Object) entry = arg.constructor.name + entry;
@@ -281,7 +282,7 @@ colored.log = function () {
281
282
  if (needNextLine) needNextLine = false;
282
283
  _log.apply(console, arguments);
283
284
  };
284
- colored.wrap = function (c, content) {
285
+ var bindColor = colored.wrap = function (c, content) {
285
286
  var c = getColor(c);
286
287
  if (!c) throw new Error(i18n`${c}不是有效的色彩信息`);
287
288
  return c + content + colors.Reset;
@@ -300,11 +301,7 @@ colored.clear = function (tag) {
300
301
  write1(false, '');
301
302
  if (tag) write1(true, tag);
302
303
  };
303
- colored.format = function (a) {
304
- a = format(a);
305
- a = renderColor(a);
306
- return a;
307
- };
304
+ colored.format = format;
308
305
  if (typeof i18n !== 'undefined') {
309
306
  colored.info.tip = i18n`提示`;
310
307
  colored.warn.tip = i18n`注意`;
@@ -54,4 +54,5 @@ var data = [
54
54
  data[data.length - 1].循环对象 = data[data.length - 1];
55
55
  console.log(data);
56
56
  console.line(data);
57
+ console.log(compile$common.createString(茨菰$标签化(compile$scanner2("arguments.length"), colors.wrap)));
57
58
  throw new Error(2);
@@ -80,4 +80,10 @@ class Color {
80
80
  }
81
81
  for (var k in colors) {
82
82
  colors[k] = new Color(k, colors[k]);
83
- }
83
+ }
84
+ var reset = colors.Reset;
85
+ colors.wrap = function (content, label) {
86
+ var c = colors[label];
87
+ if (!c) return content;
88
+ return c + content + reset;
89
+ };
@@ -36,6 +36,7 @@ onhashchange(window, function (event) {
36
36
  var currentHash = getCurrentHash();
37
37
  if (currentHash && currentHash === targetHash) return;
38
38
  var targetpath = pathFromHash(targetHash);
39
+ if (targetpath === popupHashlessPath) return fixurl();
39
40
  if (pathFromHash(currentHash) === popupHashlessPath) {
40
41
  backward();
41
42
  return;
@@ -419,6 +420,7 @@ function create(pagepath, args, from, needroles) {
419
420
  var createEmptyHistory = function (emptyState, allowForward = true) {
420
421
  var h = [emptyState];
421
422
  h.index = 0;
423
+ h.lastIndex = 0;
422
424
  h.wardable = allowForward;
423
425
  return h;
424
426
  }
@@ -484,10 +486,10 @@ var pushstate = function (path_name, history_name) {
484
486
  _history.index++;
485
487
  }
486
488
  if (_history[_history.index] !== path_name) {
487
- _history.lastIndex = index;
488
489
  _history.splice(_history.index, _history.length - _history.index);
489
490
  _history[_history.index] = path_name;
490
491
  }
492
+ _history.lastIndex = index;
491
493
  }
492
494
  savestate();
493
495
  return isBack;
@@ -515,34 +517,40 @@ var getCurrentHash = function () {
515
517
  var targeturl = `#${history_name}${_historylist.length ? _historylist[_historylist.index] : ""}`;
516
518
  return encodeURI(targeturl);
517
519
  };
520
+ var fixlock = false;
521
+ var fixUnlock = function () {
522
+ fixlock = false;
523
+ }
524
+ var fixNext = function (d) {
525
+ fixlock = true;
526
+ var h = history[current_history];
527
+ h.lastIndex = h.index;
528
+ preventNextHashChange = true;
529
+ window_history.go(d);
530
+ setTimeout(fixUnlock, 60);
531
+ setTimeout(fixurl, 60);
532
+ };
518
533
  var fixurl = function () {
534
+ if (fixlock) return;
519
535
  if (false === fullfill_is_dispatched) return;
520
536
  var zimoli_hash = getCurrentHash();
521
537
  var location_hash = getLocationHash();
522
538
  if (location_hash === zimoli_hash) return;
523
539
  var location_path = pathFromHash(location_hash);
524
540
  if (location_path === popupHashlessPath) {
525
- preventNextHashChange = true;
526
- window_history.go(-1);
527
- location_hash = getCurrentHash();
528
- location_path = pathFromHash(location_hash);
541
+ fixNext(-1);
542
+ return;
529
543
  };
530
- if (zimoli_hash === location_hash) return;
531
544
  var zimoli_path = pathFromHash(zimoli_hash);
532
545
  if (zimoli_path === popupHashlessPath) return setLocationHash(zimoli_hash);
533
546
  if (zimoli_hash) {
534
547
  if (!location_hash) setLocationHash(zimoli_hash);
535
548
  else {
536
549
  var _history = history[current_history];
537
- var b = _history.indexOf(location_path);
538
- if (b >= 0) {
539
- var c = _history.indexOf(zimoli_path);
540
- if (c >= 0) {
541
- var d = c - b;
542
- preventNextHashChange = true;
543
- window_history.go(d);
544
- location_hash = getLocationHash();
545
- }
550
+ var d = _history.index - _history.lastIndex;
551
+ if (d) {
552
+ fixNext(d);
553
+ return;
546
554
  }
547
555
  if (location_hash !== zimoli_hash) {
548
556
  setLocationHash(zimoli_hash);
@@ -552,11 +560,8 @@ var fixurl = function () {
552
560
  else if (location_path !== getInitPath()) {
553
561
  var _history = history[current_history];
554
562
  var i = _history.indexOf(location_path);
555
- if (i === -1) i = _history.lastIndex;
556
- if (i > 0) {
557
- preventNextHashChange = true;
558
- window_history.go(-i);
559
- }
563
+ if (i === -1) i = _history.lastIndex, _history.lastIndex = _history.index;
564
+ if (i > 0) fixNext(-i);
560
565
  }
561
566
  };
562
567
  var checkonback = function (elements) {
@@ -6,7 +6,20 @@ predefs.exports = true;
6
6
  predefs["module.exports"] = true;
7
7
  predefs.Promise = true;
8
8
  [Boolean, Number, String, Function, Object, Array, Date, RegExp, Error].forEach(p => predefs[p.name] = true);
9
+ var wrapLabel = function (content, typeName) {
10
+ return `<${typeName}>${content}</${typeName}>`;
11
+ };
12
+ var amp = a => `&#${a.charCodeAt()};`;
13
+ var encodeAmp = function (a) {
14
+ return a.replace(/[\<\>\|&]/g, amp);
15
+ };
9
16
  var codecolor = function (c, encode) {
17
+ var wrap = arguments[2];
18
+ if (encode?.length === 2) wrap = encode, encode = arguments[2];
19
+ if (!wrap) {
20
+ wrap = wrapLabel;
21
+ if (!encode) encode = encodeAmp;
22
+ }
10
23
  var envs = c.envs;
11
24
  var deep = 0;
12
25
  var used = c.used;
@@ -45,17 +58,25 @@ var codecolor = function (c, encode) {
45
58
  return false;
46
59
  };
47
60
  var setExpress = function (o, label) {
48
- if (!o.text || /^</.test(o.text)) return;
61
+ if (!o.text || o.wraped) return;
62
+ o.wraped = true;
49
63
  var keys = o.text.split(".");
64
+ var invoked = null;
65
+ var endi = keys.length - 1;
50
66
  if (isInvoke(o)) {
51
- if (!/^[\<\?]/.test(keys[keys.length - 1])) keys[keys.length - 1] = `<invoke>${keys[keys.length - 1]}</invoke>`;
67
+ if (!/^[\?]/.test(keys[endi])) invoked = wrap(keys[endi], "invoke");
52
68
  }
69
+ else endi++;
53
70
  var [name] = keys;
54
- if (/^[\<\?]/.test(name) || !name);
55
- else if (!o.isprop && o.text !== name && isConstValue(name)) name = `<strap>${name}</strap>`;
56
- else name = `<${label}>${name}</${label}>`;
71
+ if (!o.isprop && o.text !== name && isConstValue(name)) name = wrap(name, "strap");
72
+ else name = wrap(name, label);
57
73
  keys[0] = name;
58
- o.text = keys.map(k => /^[\<\?]/.test(k) || !k ? k : `<express>${k}</express>`).join(".");
74
+ for (var cx = 1, dx = endi; cx < dx; cx++) {
75
+ var k = keys[cx];
76
+ keys[cx] = /^[\?]/.test(k) || !k ? k : wrap(k, 'express');
77
+ }
78
+ if (endi === keys.length - 1) keys[endi] = invoked;
79
+ o.text = keys.join('.');
59
80
  };
60
81
  var setPredef = o => setExpress(o, 'predef');
61
82
  var setOutside = o => setExpress(o, 'outside');
@@ -66,11 +87,15 @@ var codecolor = function (c, encode) {
66
87
  if (spaceReg) var unspaceReg = new RegExp(`(?:[^${光标}])+`, 'g');
67
88
  var wraptext = function (t, l) {
68
89
  if (unspaceReg) t = t.replace(unspaceReg, a => {
69
- a = encode(a);
70
- return `<${l}>${a}</${l}>`
90
+ if (encode) a = encode(a);
91
+ return wrap(a, l);
71
92
  });
72
93
  return t;
73
94
  };
95
+ var wrapcode = encode ? function (t, l) {
96
+ t = encode(t);
97
+ return wrap(t, l);
98
+ } : wrap;
74
99
  c.colored = true;
75
100
  var setcolor = function (o) {
76
101
  if (o.colored) return;
@@ -78,13 +103,13 @@ var codecolor = function (c, encode) {
78
103
  var text = o.text;
79
104
  switch (o.type) {
80
105
  case LABEL:
81
- o.text = `<label>${o.text}</label>`;
106
+ o.text = wrap(o.text, 'label');
82
107
  break;
83
108
  case QUOTED:
84
109
  if (o.length || !o.text) {
85
110
  o.forEach(setcolor);
86
- o.entry = "<text>" + o.entry + "</text>";
87
- o.leave = "<text>" + o.leave + "</text>";
111
+ o.entry = wrap(o.entry, 'text');
112
+ o.leave = wrap(o.leave, 'text');
88
113
  break;
89
114
  }
90
115
  if (/^\//.test(o.text)) {
@@ -101,30 +126,30 @@ var codecolor = function (c, encode) {
101
126
  }
102
127
  case PIECE:
103
128
  if (o.queue && o.queue.tag) {
104
- o.text = encode(o.text);
129
+ if (encode) o.text = encode(o.text);
105
130
  }
106
131
  else o.text = wraptext(o.text, 'text');
107
132
  break;
108
133
  break;
109
134
  case ELEMENT:
110
135
  if (o.attributes) o.attributes.forEach(setcolor);
111
- if (o.tag_entry) o.tag_entry = `<stamp>${encode(o.tag_entry)}</stamp>`;
112
- if (o.tag_leave) o.tag_leave = `<stamp>${encode(o.tag_leave)}</stamp>`;
113
- if (o.entry) o.entry = `<stamp>${encode(o.entry)}</stamp>`;
114
- if (o.leave) o.leave = `<stamp>${encode(o.leave)}</stamp>`;
115
- o.tag = `<label>${o.tag}</label>`;
136
+ if (o.tag_entry) o.tag_entry = wrapcode(o.tag_entry, 'stamp');
137
+ if (o.tag_leave) o.tag_leave = wrapcode(o.tag_leave, 'stamp');
138
+ if (o.entry) o.entry = wrapcode(o.entry, 'stamp');
139
+ if (o.leave) o.leave = wrapcode(o.leave, 'stamp');
140
+ o.tag = wrapcode(o.tag, 'label');
116
141
  o.forEach(setcolor);
117
142
  break;
118
143
  case SCOPED:
119
144
  deep++;
120
145
  o.forEach(setcolor);
121
146
  deep--;
122
- o.entry = `<deep${deep}>${o.entry}</deep${deep}>`;
123
- o.leave = `<deep${deep}>${o.leave}</deep${deep}>`;
147
+ o.entry = wrapcode(o.entry, 'deep' + deep);
148
+ o.leave = wrapcode(o.leave, 'deep' + deep);
124
149
  break;
125
150
  case VALUE:
126
- if (o.isdigit) o.text = `<digit>${o.text}</digit>`;
127
- else o.text = `<value>${o.text}</value>`;
151
+ if (o.isdigit) o.text = wrap(o.text, 'digit');
152
+ else o.text = wrap(o.text, 'value');
128
153
  break;
129
154
  case PROPERTY:
130
155
  var next = o.next;
@@ -138,13 +163,11 @@ var codecolor = function (c, encode) {
138
163
  setExpress(o, o.istype || o.isdef || o.next?.needle ? 'predef' : 'express');
139
164
  break;
140
165
  case STRAP:
141
- if (control_reg?.test(text)) o.text = `<flow>${o.text}</flow>`;
142
- else o.text = `<strap>${o.text}</strap>`;
166
+ if (control_reg?.test(text)) o.text = wrap(o.text, 'flow');
167
+ else o.text = wrap(o.text, 'strap');
143
168
  break;
144
169
  case STAMP:
145
- if (/^(=>)$/.test(o.text) || o.text === "*" && o.prev && o.prev.type === STRAP) o.text = `<strap>${encode(o.text)}</strap>`;
146
- // else if (!/^[<\/>]+$/.test(o.text));
147
- // else o.text = `<stamp>${encode(o.text)}</stamp>`;
170
+ if (/^(=>)$/.test(o.text) || o.text === "*" && o.prev && o.prev.type === STRAP) o.text = wrapcode(o.text, 'strap');
148
171
  break;
149
172
  case COMMENT:
150
173
  o.text = wraptext(o.text, 'comment');
@@ -154,4 +177,5 @@ var codecolor = function (c, encode) {
154
177
  c.forEach(setcolor);
155
178
  return c;
156
179
  }
180
+ codecolor.encode = encodeAmp;
157
181
  return codecolor;
@@ -1,8 +1,5 @@
1
1
 
2
2
  var { SCOPED, QUOTED, SPACE, STAMP, STRAP, EXPRESS, PROPERTY } = compile$common;
3
- var encode = function (text) {
4
- return text.replace(/[\<\>\|]/g, a => `&#${a.charCodeAt()};`);
5
- };
6
3
 
7
4
  var rows = function (type, text) {
8
5
  if (typeof text !== 'string') {
@@ -12,11 +9,11 @@ var rows = function (type, text) {
12
9
  type = String(type).toLowerCase();
13
10
  if (type in 语言) {
14
11
  var c = 语言[type](text);
15
- 标签化(c, encode);
12
+ 标签化(c);
16
13
  text = c.toString();
17
14
 
18
15
  }
19
- else text = encode(text);
16
+ else text = 标签化.encode(text);
20
17
 
21
18
  var codes = text.split(/\r\n|\r|\n/);
22
19
  var minSpace = Infinity;
@@ -41,5 +38,5 @@ function 茨菰(type, text) {
41
38
  };
42
39
 
43
40
  茨菰.rows = rows;
44
- 茨菰.encode = encode;
41
+ 茨菰.encode = 标签化.encode;
45
42
  return 茨菰;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.22.10",
3
+ "version": "4.22.12",
4
4
  "description": "一个开发环境,提供一种自由的前端开发模式,也可作为辅助工具使用。",
5
5
  "main": "public/efront.js",
6
6
  "directories": {