efront 3.36.3 → 3.36.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,10 +4,9 @@ var { createString } = require("./common");
4
4
  function test(codetext, expect, ret = false) {
5
5
  var code = scanner2(codetext);
6
6
  var i = -2;
7
- code = unstruct(code, () => ++i >= 0 ? "_" + i : '_', ret);
7
+ code = unstruct(code, () => ++i >= 0 ? "_" + i : '_', ret && "@");
8
8
  assert(code.map(createString).join("; "), expect);
9
9
  }
10
-
11
10
  test('a+b', "a + b");
12
11
  test('a + !c', "_ = !c, a + _");
13
12
  test('a + b * c', "_ = b * c, a + _");
@@ -17,38 +16,46 @@ test('a * a + b * c', "_ = a * a, _0 = b * c, _ + _0");
17
16
  test('a * a + b * c * c ** d', "_ = a * a, _0 = b * c, _1 = c ** d, _0 = _0 * _1, _ + _0");
18
17
  test('a * a || b * c * c ** d', "_ = a * a @re _ = b * c, _0 = c ** d, _ * _0");
19
18
  test('a * a || b * c || c * d', "_ = a * a @re _ = b * c @re c * d");
20
- test('a?b:c', "_ = a; return [_ ? 1 : 2, _]; _ = b; return [2, _]; _ = c; return [1, _]");
19
+ test('a?b:c', "_ = a; return [_ ? 1 : 2, 0]; _ = b; return [2, 0]; _ = c");
21
20
  test('a * a && b * c * c ** d', "_ = a * a @rz _ = b * c, _0 = c ** d, _ * _0");
22
- test('a = b', "a = b; return [1, a]", true);
23
- test('a = b = c', "_ = c; b = _; a = _; return [1, a]", true);
24
- test('a = b = c + d', "_ = c + d; b = _; a = _; return [1, a]", true);
25
- test('a = b = c + d * 1', "_ = d * 1; _ = c + _; b = _; a = _; return [1, a]", true);
26
- test('return a = b', "a = b; return [1, a]", true);
27
- test('a*a', "_ = a * a; return [1, _]", true);
28
- test('a * a && b * c * c ** d', "_ = a * a; if (!_) return [2, _]; _ = b * c; _0 = c ** d; _ = _ * _0; return [1, _]", true);
21
+ test('a = 1 + 2', "_ = 1 + 2, a = _", true);
22
+ test('a = b', "a = b", true);
23
+ test('a = b = c', "_ = c, b = _, a = _", true);
24
+ test('a = b = c + d', "_ = c + d, b = _, a = _", true);
25
+ test('a = b = c + d * 1', "_ = d * 1, _ = c + _, b = _, a = _", true);
26
+ test('return a = b', "a = b; return [a, 2]", true);
27
+ test('a*a', "_ = a * a", true);
28
+ test('a * a && b * c * c ** d', "_ = a * a; if (!_) return [1, 0]; _ = b * c, _0 = c ** d, _ = _ * _0", true);
29
+ test('a * a || b * c * c ** d', "_ = a * a; if (_) return [1, 0]; _ = b * c, _0 = c ** d, _ = _ * _0", true);
30
+ test('a * a ?? b * c * c ** d', "_ = a * a; if (_ !== null && _ !== undefined) return [1, 0]; _ = b * c, _0 = c ** d, _ = _ * _0", true);
31
+ test('a * a && await b*c', "_ = a * a; if (!_) return [2, 0]; _ = b; return [_, 1]; _ = @; _ = _ * c", true);
29
32
 
30
- test("await a", "_ = a; return [1, _]", true);
31
- test("await a()", "_ = a(); return [1, _]", true);
32
- test("(1+ +1)", "_ = +1; _ = 1 + _; _ = (_); return [1, _]", true);
33
- test("await a(await b)", "_ = b; return [1, _]; _ = a(_); return [1, _]", true);
34
- test("await a(await b).s(await c)", "_ = b; return [1, _]; _ = a(_); _0 = c; return [1, _0]; _ = _.s(_0); return [1, _]", true);
35
- test("a*a + await a(await b).s(await c)", "_ = a * a; _0 = b; return [1, _0]; _0 = a(_0); _1 = c; return [1, _1]; _0 = _0.s(_1); return [1, _0]; _ = _ + _0; return [1, _]", true);
36
- test("a*a + await a(await b(await c)).s(await c)", "_ = a * a; _0 = c; return [1, _0]; _0 = b(_0); return [1, _0]; _0 = a(_0); _1 = c; return [1, _1]; _0 = _0.s(_1); return [1, _0]; _ = _ + _0; return [1, _]", true);
37
- test("await a, await b", "_ = a; return [1, _]; _ = b; return [1, _]", true);
38
- test("await a * b, await b", "_ = a; return [1, _]; _ = _ * b; return [1, _]; _ = b; return [1, _]", true);
39
- test("if(a) await b", "if (!a) return [1]; _ = b; return [1, _]", true);
40
- test("if(a) await b; else await c", "if (!a) return [1]; _ = b; return [2, _]; _ = c; return [1, _]", true);
41
- test("if(a) await b; else if(e) await c", "if (!a) return [1]; _ = b; return [2, _]; if (!e) return [1]; _ = c; return [1, _]", true);
42
- test("if(a) await b; else if(e) await c else await d", "if (!a) return [1]; _ = b; return [3, _]; if (!e) return [1]; _ = c; return [2, _]; _ = d; return [1, _]", true);
43
- test("if(await a) await b", "_ = a; return [1, _]; if (!_) return [1]; _ = b; return [1, _]", true);
44
- test("for(a=0;a<10;a++) await a", "a = 0; return [1]; _ = a < 10; if (!_) return [3]; _ = a; return [1, _]; _ = a++; return [-2]", true);
45
- test("for(a=0;a<10;a++) await a, await b", "a = 0; return [1]; _ = a < 10; if (!_) return [4]; _ = a; return [1, _]; _ = b; return [1, _]; _ = a++; return [-3]", true);
46
- test("while(a) await b", "_ = a; if (!_) return [3]; _ = b; return [1, _]; return [-2]", true);
47
- test("do{await b}while(a)", "_ = b; return [1, _]; _ = a; return [_ ? -2 : 1]", true);
48
- test("switch(a){case 1:}", "_ = a; _0 = 1; if (_ === _0) return [1]", true);
49
- test("switch(a){case 1:break;}", "_ = a; _0 = 1; if (_ === _0) return [1]; return [1]", true);
50
- test("switch(a){case 1:break;case 2:break;}", "_ = a; _0 = 1; if (_ === _0) return [2]; _0 = 2; if (_ === _0) return [2]; return [2]; return [1]", true);
51
- test("switch(a){case 1:case 2:break;}", "_ = a; _0 = 1; if (_ === _0) return [2]; _0 = 2; if (_ === _0) return [1]; return [1]", true);
52
- test("switch(a){case 1:case 2:x=1;}", "_ = a; _0 = 1; if (_ === _0) return [2]; _0 = 2; if (_ === _0) return [1]; x = 1", true);
53
- test("switch(a){case 1:case 2:x=1;}", "_ = a; _0 = 1; if (_ === _0) return [2]; _0 = 2; if (_ === _0) return [1]; x = 1", true);
33
+ test("await a", "_ = a; return [_, 1]", true);
34
+ test("await a()", "_ = a(); return [_, 1]", true);
35
+ test("(1+ +1)", "_ = +1, _ = 1 + _; _ = (_)", true);
36
+ test("await a(await b)", "_ = b; return [_, 1]; _ = @; _ = a(_); return [_, 1]", true);
37
+ test("await a(await b).s(await c)", "_ = b; return [_, 1]; _ = @; _ = a(_); _0 = c; return [_0, 1]; _0 = @; _ = _.s(_0); return [_, 1]", true);
38
+ test("a*a + await a(await b).s(await c)", "_ = a * a; _0 = b; return [_0, 1]; _0 = @; _0 = a(_0); _1 = c; return [_1, 1]; _1 = @; _0 = _0.s(_1); return [_0, 1]; _0 = @; _ = _ + _0", true);
39
+ test("a*a + await a(await b(await c)).s(await c)", "_ = a * a; _0 = c; return [_0, 1]; _0 = @; _0 = b(_0); return [_0, 1]; _0 = @; _0 = a(_0); _1 = c; return [_1, 1]; _1 = @; _0 = _0.s(_1); return [_0, 1]; _0 = @; _ = _ + _0", true);
40
+ test("await a, await b", "_ = a; return [_, 1]; _ = b; return [_, 1]", true);
41
+ test("await a * b, await b", "_ = a; return [_, 1]; _ = @; _ = _ * b; _ = b; return [_, 1]", true);
42
+ test("if(a);", "", true);
43
+ test("if(a) await b", "if (!a) return [1, 0]; _ = b; return [_, 1]", true);
44
+ test("if(a) await b; else await c", "if (!a) return [2, 0]; _ = b; return [_, 1]; return [2, 0]; _ = c; return [_, 1]", true);
45
+ test("if(a) b; else await c", "if (!a) return [1, 0]; _ = b; return [2, 0]; _ = c; return [_, 1]", true);
46
+ test("if(a) await b; else if(e) await c", "if (!a) return [2, 0]; _ = b; return [_, 1]; return [2, 0]; if (!e) return [1, 0]; _ = c; return [_, 1]", true);
47
+ test("if(a) await b; else if(e) await c else await d", "if (!a) return [2, 0]; _ = b; return [_, 1]; return [4, 0]; if (!e) return [2, 0]; _ = c; return [_, 1]; return [2, 0]; _ = d; return [_, 1]", true);
48
+ test("if(await a) await b", "_ = a; return [_, 1]; if (!_) return [1, 0]; _ = b; return [_, 1]", true);
49
+ test("for(a=0;a<10;a++) await a", "a = 0; return [1, 0]; _ = a < 10; if (!_) return [3, 0]; _ = a; return [_, 1]; _ = a++; return [-2, 0]", true);
50
+ test("for(a=0;a<10;a++) await a, await b", "a = 0; return [1, 0]; _ = a < 10; if (!_) return [4, 0]; _ = a; return [_, 1]; _ = b; return [_, 1]; _ = a++; return [-3, 0]", true);
51
+ test("while(a) await b", "_ = a; if (!_) return [3, 0]; _ = b; return [_, 1]; return [-2, 0]", true);
52
+ test("do{await b}while(a)", "_ = b; return [_, 1]; _ = a; return [_ ? -2 : 1, 0]", true);
53
+ test("switch(a){case 1:}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]", true);
54
+ test("switch(a){case 1:break;}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]; return [1, 0]", true);
55
+ test("switch(a){case 1:break;case 2:break;}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]; _0 = 2; if (_ === _0) return [2, 0]; return [2, 0]; return [1, 0]", true);
56
+ test("switch(a){case 1:case 2:break;}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]; _0 = 2; if (_ === _0) return [1, 0]; return [1, 0]", true);
57
+ test("switch(a){case 1:case 2:x=1;}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]; _0 = 2; if (_ === _0) return [1, 0]; x = 1", true);
58
+ test("switch(a){case 1:case 2:x=1;}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]; _0 = 2; if (_ === _0) return [1, 0]; x = 1", true);
54
59
  test("with(a){ a = 1}", `_ = a; if (_0 = with_("a", [_])) _0.a = 1; else a = 1;`, true);
60
+ test("try{a=2+1}catch(e){}", 'return [65536, 7]; _ = 2 + 1, a = _; return [0, 9]; e = @; return [1, 9]', true);
61
+ test("try{a=2+1}catch(e){a=3}", 'return [65536, 7]; _ = 2 + 1, a = _; return [0, 9]; e = @; a = 3; return [1, 9]', true);
@@ -84,7 +84,7 @@
84
84
  var encode = function (text) {
85
85
  return text.replace(/[\<\>\|]/g, a => `&#${a.charCodeAt()};`)
86
86
  };
87
- var codecolor = function (c) {
87
+ var codecolor = function (c, blink) {
88
88
  var envs = c.envs;
89
89
  var predefs = Object.create(null);
90
90
  predefs.module = true;
@@ -95,6 +95,8 @@
95
95
  var { STRAP, SCOPED, QUOTED, LABEL, COMMENT, STAMP, VALUE, EXPRESS, PROPERTY, PIECE } = c;
96
96
  var deep = 0;
97
97
  var setcolor = function (o) {
98
+ var text = o.text;
99
+ if (o.blink >= 0) o.text = o.text.slice(0, o.blink) + blink + o.text.slice(o.blink);
98
100
  switch (o.type) {
99
101
  case LABEL:
100
102
  o.text = `<label>${o.text}</label>`;
@@ -137,16 +139,16 @@
137
139
  if (next && next.type === c.SCOPED && next.entry === '(') {
138
140
  keys[keys.length - 1] = `<invoke>${keys[keys.length - 1]}</invoke>`;
139
141
  }
142
+ var [name0] = text.split(".");
140
143
  var [name] = keys;
141
- if (/^</.test(name));
142
- else if (/^(arguments|this|super|Infinity|NaN)$/.test(name)) name = `<strap>${name}</strap>`;
143
- else if (name in envs) name = name in predefs ? `<predef>${name}</predef>` : `<outside>${name}</outside>`;
144
-
144
+ if (/^</.test(name0));
145
+ else if (/^(arguments|this|super|Infinity|NaN)$/.test(name0)) name = `<strap>${name}</strap>`;
146
+ else if (name0 in envs) name = name0 in predefs ? `<predef>${name}</predef>` : `<outside>${name}</outside>`;
145
147
  keys[0] = name;
146
148
  o.text = keys.map(k => /^\</.test(k) || !k ? k : `<express>${k}</express>`).join(".");
147
149
  break;
148
150
  case STRAP:
149
- if (/^(if|else|switch|case|do|while|for|break|continue|default|import|from|as|export|try|catch|finally|await|yield|return)/.test(o.text))
151
+ if (/^(if|else|switch|case|do|while|for|break|continue|default|import|from|as|export|try|catch|finally|await|yield|return)/.test(text))
150
152
  o.text = `<flow>${o.text}</flow>`;
151
153
  else o.text = `<strap>${o.text}</strap>`;
152
154
  break;
@@ -166,10 +168,17 @@
166
168
  var typescript = new compile$Javascript;
167
169
  typescript.straps = typescript.straps.concat("interface", "implements", "declare", "module", "readonly", "enum");
168
170
  var codesupports = {
169
- javascript(a) {
171
+ javascript(a, blink) {
172
+ if (blink) var index = a.indexOf(blink);
173
+ if (index >= 0) a = a.slice(0, index) + a.slice(index + 1);
170
174
  var c = compile$scanner2(a);
171
- codecolor(c);
172
- return c.toString();
175
+ if (index >= 0) {
176
+ var patched = patchBlink(c, index, blink);
177
+ }
178
+ codecolor(c, blink);
179
+ a = c.toString();
180
+ if (index >= 0 && !patched) a = blink + a;
181
+ return a;
173
182
  },
174
183
  typescript(a) {
175
184
  var c = compile$scanner2(a, typescript);
@@ -199,15 +208,67 @@
199
208
  codesupports.jsx = codesupports.js = codesupports.javascript;
200
209
  codesupports.tsx = codesupports.ts = codesupports.typescript;
201
210
  codesupports.xml = codesupports.html;
202
- function codetext(type, text) {
203
- try {
204
- type = type.toLowerCase();
205
- if (type in codesupports) text = codesupports[type](text);
206
- else text = encode(text);
207
-
208
- } catch (e) {
209
- console.error(e);
211
+ var { SCOPED, QUOTED } = compile$common;
212
+ var patchBlink = function (code, index, blink) {
213
+ for (var cx = 0, dx = code.length; cx < dx; cx++) {
214
+ var c = code[cx];
215
+ var haschildren = c => c.type === SCOPED || c.type === QUOTED && c.length;
216
+ if (c.start === index) {
217
+ if (haschildren(c)) {
218
+ c.entry = blink + c.entry;
219
+ }
220
+ else {
221
+ c.blink = 0;
222
+ }
223
+ return true;
224
+ }
225
+ else if (c.start < index && c.end > index) {
226
+ if (haschildren(c)) {
227
+ return patchBlink(c, index, blink);
228
+ }
229
+ else {
230
+ c.blink = index - c.start;
231
+ return true;
232
+ }
233
+ }
234
+ else if (c.end === index) {
235
+ if (haschildren(c)) {
236
+ c.leave += blink;
237
+ }
238
+ else {
239
+ c.blink = c.text.length;
240
+ }
241
+ return true;
242
+ }
243
+ else if (c.start > index) {
244
+ if (cx === 0) {
245
+ if (code.entry) return code.entry += blink, true;
246
+ return false;
247
+ }
248
+ else {
249
+ var p = code[cx - 1];
250
+ if (haschildren(p)) {
251
+ p.leave += blink;
252
+ }
253
+ else {
254
+ p.blink = p.text.length;
255
+ }
256
+ return true;
257
+ }
258
+ }
259
+ }
260
+ if (code.leave) {
261
+ code.leave = blink + code.leave;
262
+ return true;
263
+ }
264
+ return false;
265
+ };
266
+ function codetext(type, text, blink) {
267
+ type = type.toLowerCase();
268
+ if (type in codesupports) {
269
+ text = codesupports[type](text, blink);
210
270
  }
271
+ else text = encode(text);
211
272
  var codes = text.split(/\r\n|\r|\n/);
212
273
  var minSpace = 0;
213
274
  for (var c of codes) {
@@ -99,7 +99,12 @@ function markdown(text) {
99
99
  if (q.length === 1) return `<m>${_}</m>`;
100
100
  var t = /^\S+/.exec(c);
101
101
  if (t) t = t[0]; c = c.slice(t.length).replace(/^(\r\n|\r|\n)|\s+$/g, '');
102
- return codetext(t, c);
102
+ try {
103
+ return codetext(t, c);
104
+ } catch (e) {
105
+ console.error(e);
106
+ return c;
107
+ }
103
108
  }).replace(/\s*((&nbsp;\s*)+)/g, "$1").split(/\r\n|\r|\n/).forEach(richtext);
104
109
  list_elem = null;
105
110
  list_tag = null;
@@ -60,7 +60,7 @@
60
60
  }
61
61
 
62
62
  span {
63
- writing-mode: horizontal-tb;
63
+ writing-mode: vertical-rl;
64
64
  }
65
65
 
66
66
 
@@ -12,10 +12,11 @@ styles.default = '#000a';
12
12
  var fontSize = 16;
13
13
  var singleHeight = fontSize * 3.125 | 0;
14
14
  var container = document.createElement('alert-container');
15
- css(container, 'height:0;left:0;right:0;transition:all 0.2s ease-out;position:absolute;')
15
+ css(container, 'top:0;height:0;left:0;right:0;transition:all 0.2s ease-out;position:absolute;')
16
16
  var _text = function (bgcolor, parameters) {
17
17
  var box = document.createElement('div');
18
- box.innerHTML = `<div style='padding:${fromPixel(10)} ${fromPixel(20)};background-color:${bgcolor};color:${color.pair(bgcolor, 1)};'>${[].slice.call(parameters, 0).join(", ")}</div>`;
18
+ css(box, `background-color:${bgcolor};color:${color.pair(bgcolor, 1)};`);
19
+ box.innerHTML = [].slice.call(parameters, 0).join(", ");
19
20
  box.initialStyle = `margin-top:-${fromPixel(singleHeight)};`;
20
21
  return box;
21
22
  };
@@ -55,13 +56,12 @@ function alert() {
55
56
  } else {
56
57
  elem = _text(styles.log, [text]);
57
58
  }
58
- var _onclose = function (event) {
59
+ var _onclose = lazy(function (event) {
59
60
  if (onclose) {
60
61
  onclose.call(this, event);
61
62
  }
62
63
  if (close_timer) clearTimeout(close_timer);
63
- if (!container.children.length) remove(container);
64
- }
64
+ });
65
65
  onremove(elem, _onclose);
66
66
  var close_timer;
67
67
  var waitclose = function (autoclose, deltaTime) {
@@ -78,7 +78,7 @@ function alert() {
78
78
  };
79
79
  waitclose(autoclose, 400)
80
80
  elem.setText = function (content, timeout = true) {
81
- var c = elem.children[0];
81
+ var c = elem;
82
82
  c.innerHTML = content;
83
83
  text = content;
84
84
  if (timeout) {
@@ -87,7 +87,7 @@ function alert() {
87
87
  }
88
88
  };
89
89
  if (!container.parentNode) popup(container);
90
- appendChild(container, elem);
90
+ if (!elem.parentNode) appendChild(container, elem);
91
91
  return elem;
92
92
  }
93
93
  for (var k in styles) {
@@ -6,5 +6,7 @@
6
6
  margin: 0 auto;
7
7
  height: auto;
8
8
  line-height: 1.2;
9
+ padding: 10px 20px;
9
10
  text-align: center;
11
+ position: relative;
10
12
  }
@@ -1,4 +1,4 @@
1
-
1
+ "use strict";
2
2
  var _create = function (commFactory, className, _invoke) {
3
3
  if (!className) return commFactory;
4
4
  if (commFactory instanceof Promise) {
@@ -24,7 +24,7 @@ var getGenerator = function (container, tagName = 'item') {
24
24
  var template = document.createElement(container.tagName);
25
25
  var templates = [];
26
26
  for (let a of container.childNodes) {
27
- if (a.hasAttribute('insert')) {
27
+ if (a.nodeType === 1 && a.hasAttribute('insert')) {
28
28
  if (!templates.length) a.$isbefore = true;
29
29
  else a.$isafter = true;
30
30
  }
@@ -1,5 +1,5 @@
1
1
  <template -if='hasIcon?'>
2
- <i -class="icon?" -style="{color:menu.color}"></i>
2
+ <i -class="menu.icon" -style="{color:menu.color}"></i>
3
3
  <template -if="menu.name">
4
4
  &nbsp;&nbsp;
5
5
  </template>
@@ -19,7 +19,7 @@ function main(elem, scope, hasIcon) {
19
19
  menu,
20
20
  checker,
21
21
  };
22
- if (hasIcon) scope.hasIcon = true;
22
+ if (hasIcon || menu.icon) scope.hasIcon = true;
23
23
  render(item.children, scope);
24
24
  if (menu.line) item.setAttribute("line", ''), on("click")(item, preventDefault);
25
25
  return item;
@@ -886,6 +886,7 @@ class Struct {
886
886
  function createStructure(element) {
887
887
  if (isArrayLike(element)) return Array.prototype.map.call(element, createStructure);
888
888
  if (element.$struct) return element.$struct;
889
+ if (element.nodeType !== 1) return;
889
890
  // 处理结构流
890
891
  var attributes = element.attributes;
891
892
  var attrs = Array.apply(null, attributes);
@@ -58,7 +58,8 @@ if (/MSIE\s*[2-7]/.test(navigator.userAgent)) {
58
58
  if (currentHash && currentHash === targetHash) return;
59
59
  var targetHashIndex = targetHash.indexOf("#" + current_history);
60
60
  if (targetHashIndex < 0) return;
61
- var targetpath = targetHash.slice(targetHashIndex + current_history.length);
61
+ var targetpath = targetHash.slice(targetHashIndex + current_history.length + 1);
62
+ targetpath = decodeURI(targetpath);
62
63
  go(targetpath);
63
64
  return;
64
65
  }
package/docs/main.xht CHANGED
@@ -150,7 +150,7 @@
150
150
  var map = Object.create(null);
151
151
  var children = [];
152
152
  for (var a of c.children) {
153
- if (/_test\.([tj]sx?|xht|html|less|md)$/i.test(a)) {
153
+ if (/_test\.([tj]sx?|xht|html|less|css|md)$/i.test(a)) {
154
154
  var testName = a.replace(/\.\w+$/g, '');
155
155
  if (!map[testName]) map[testName] = [];
156
156
  map[testName].push(a);
@@ -175,7 +175,7 @@
175
175
  c.children = children;
176
176
  c.closed = true;
177
177
  }
178
-
178
+ data.setInstance('components', m);
179
179
  menus[2].children = m;
180
180
  };
181
181
  var initMenus = async function () {
@@ -18,10 +18,6 @@
18
18
  border-bottom: 46px solid transparent;
19
19
  }
20
20
 
21
- textarea {
22
- outline: none;
23
- white-space: nowrap;
24
- }
25
21
 
26
22
  p4 {
27
23
  line-height: 1.8;
@@ -75,15 +71,16 @@
75
71
  overflow: auto;
76
72
  width: 100%;
77
73
  height: 100%;
78
- padding-bottom: 600px;
74
+ padding: 10px 20px 600px 20px;
79
75
  white-space: nowrap;
76
+ outline: none;
80
77
  }
81
78
 
82
79
  markdown {
83
80
  margin: -6px -20px 0 -10px;
84
81
  }
85
82
 
86
- button {
83
+ [foot]>button {
87
84
  padding: 0 20px;
88
85
  }
89
86
 
@@ -125,7 +122,7 @@
125
122
  </p4>
126
123
  </div>
127
124
  <div body -elseif="tags[1].actived">
128
- <div codearea #coder onkeyup="updatecode()"></div>
125
+ <div codearea #coder onkeyup="!event.isComposing&&updatecode()" onkeydown.tab="keytab(event)"></div>
129
126
  <resultpad .result #coderesult></resultpad>
130
127
  </div>
131
128
  <div foot -if="tags[1].actived">
@@ -134,6 +131,38 @@
134
131
  <btn @click="execute()">运行</btn>
135
132
  </div>
136
133
  <script>
134
+ var commaps = Object.create(null);
135
+ var initCommap = function (live) {
136
+ var commap = commaps[live];
137
+ if (!commap) {
138
+ commap = commaps[live] = Object.create(null);
139
+ var lives = data.getInstance("components");
140
+ if (live) {
141
+ lives = lives.slice().sort((a, b) => {
142
+ if (a.name === live) return -1;
143
+ return 0;
144
+ });
145
+ lives.forEach(a => {
146
+ for (var c of a.children) {
147
+ var name = c.name.replace(/\.[^\.]+$/, '');
148
+ var real = `${a.name}$${name}`;
149
+ if (!commap[name]) commap[name] = real;
150
+ commap[real] = real;
151
+ }
152
+ })
153
+ }
154
+ }
155
+ return commap;
156
+ };
157
+ var request = modules["get request"]();
158
+ modules["set request"](function (url, onload, onerror, version) {
159
+ if (!/[\*~]/.test(url)) return request(url, onload, onerror, version);
160
+ var name = url.replace(/[\*~][\s\S]*$/, '');
161
+ var live = url.slice(name.length + 1);
162
+ var commap = initCommap(live);
163
+ name = name.replace(/[^\/]+$/g, a => commap[a] || a);
164
+ return request(name, onload, onerror, version)
165
+ });
137
166
  var 分析 = lazy(async function (com, props) {
138
167
  if (props.mark) props.url = '/mark/coms/' + com.replace(/\.js$/i, '.md');
139
168
  scope.doc = props;
@@ -206,7 +235,43 @@
206
235
  scope.codetext = scope.coder.innerText;
207
236
  execute();
208
237
  };
209
-
238
+ var blink = "\u0080";
239
+ var markAnchorOffset = function () {
240
+ var { anchorNode, anchorOffset } = document.getSelection();
241
+ if (!anchorNode || !scope.coder) return;
242
+ var [c] = scope.coder.children;
243
+ if (anchorNode.nodeType === 1) {
244
+ var node = document.createTextNode(blink);
245
+ anchorNode.insertBefore(node, anchorNode.childNodes[anchorOffset])
246
+ }
247
+ else if (anchorNode.nodeType === 3) {
248
+ anchorNode.nodeValue = anchorNode.nodeValue.slice(0, anchorOffset) + blink + anchorNode.nodeValue.slice(anchorOffset);
249
+ }
250
+ };
251
+ var unmarkAnchorOffset = function () {
252
+ var [c] = scope.coder.children;
253
+ var node = c.firstChild;
254
+ while (node) {
255
+ if (node.nodeType === 1) {
256
+ if (node.innerText.indexOf(blink) >= 0) {
257
+ node = node.firstChild;
258
+ continue;
259
+ }
260
+ }
261
+ else if (node.nodeType === 3) {
262
+ if (node.nodeValue.indexOf(blink) >= 0) break;
263
+ }
264
+ node = node.nextSibling;
265
+ }
266
+ if (node) {
267
+ var offset = node.nodeValue.indexOf(blink);
268
+ node.nodeValue = node.nodeValue.slice(0, offset) + node.nodeValue.slice(offset + 1);
269
+ document.getSelection().setBaseAndExtent(node, offset, node, offset);
270
+ if (!node.nodeValue) {
271
+ remove(node);
272
+ }
273
+ }
274
+ }
210
275
  var getAnchorOffset = function () {
211
276
  var { anchorNode, anchorOffset } = document.getSelection();
212
277
  var [c] = scope.coder.children;
@@ -246,8 +311,12 @@
246
311
  }
247
312
  if (delta >= offset) {
248
313
  if (child.nodeType === 1) {
249
- child = child.firstChild;
250
- continue;
314
+ if (child.firstChild) {
315
+ child = child.firstChild;
316
+ continue;
317
+ }
318
+ offset -= 1;
319
+ break;
251
320
  }
252
321
  break;
253
322
  }
@@ -259,36 +328,44 @@
259
328
  return document.getSelection().setBaseAndExtent(child, offset, child, offset);
260
329
  }
261
330
  var initcode = function (innerText) {
262
- var colored = codetext("js", innerText);
263
- var offset = getAnchorOffset();
331
+ try {
332
+ var colored = codetext("js", innerText, blink);
333
+ } catch { return; }
264
334
  var innerHTML = scope.coder.innerHTML.replace(/\s*contenteditable\=[^\s\>]+/i, '');
265
335
  if (innerHTML === colored) return;
266
336
  var [c0] = scope.coder.children;
267
- var nodesCount = c0 ? c0.childNodes.length : 0;
337
+ var contentLength = c0 ? innerText.length : 0;
338
+ var scrollTop = c0 ? c0.scrollTop : 0;
339
+ var scrollLeft = c0 ? c0.scrollLeft : 0;
268
340
  scope.coder.innerHTML = colored;
269
341
  var [c] = scope.coder.children;
270
- if (nodesCount < c.childNodes.length) {
271
- if (offset < 0) offset--;
272
- else if (offset > 0) offset++;
273
- }
342
+ c.scrollTop = scrollTop;
343
+ c.scrollLeft = scrollLeft;
274
344
  c.contentEditable = true;
275
- setAnchorOffset(offset);
276
345
  };
277
- var updatecode = lazy(function (event) {
346
+ var updatecode = lazy(function () {
347
+ markAnchorOffset();
278
348
  var innerText = scope.coder.innerText;
279
- if (scope.codetext.replace(/[\s\u00a0]+/g, ' ').trim() === innerText.replace(/[\s\u00a0]+/g, ' ').trim()) return;
349
+ var trimspace = (_, a) => a ? "" : " ";
350
+ var trimreg = /[\s\u00a0\u2002\u0080]+([\}\{\;\[\]\(\)\,\>\<\+\-\*\&\^\/%!~:?])*/g;
351
+ unmarkAnchorOffset();
352
+ if (scope.codetext.replace(trimreg, trimspace).trim() === innerText.replace(trimreg, trimspace).trim()) return;
280
353
  initcode(innerText);
354
+ unmarkAnchorOffset();
281
355
  scope.codetext = scope.coder.innerText;
282
356
  });
283
357
  var execute = async function () {
284
358
  try {
359
+ var live = /^([\s\S]+)\//.exec(scope.name);
360
+ if (live) live = live[1];
361
+ var commap = initCommap(live);
285
362
  remove(scope.coderesult.childNodes);
286
363
  var codetext = scope.codetext.replace(/[\u2002\u00a0]/g, ' ');
287
364
  data.patchInstance("docscode", { codetext: codetext })
288
365
  var code = compile$scanner2(codetext);
289
366
  var envs = code.envs;
290
367
  var argNames = Object.keys(envs);
291
- var args = await Promise.all(argNames.map(a => init(a)));
368
+ var args = await Promise.all(argNames.map(a => init(a + "*" + live, null, { ["init*" + live]: init, ["put*" + live]: put, ["zimoli*" + live]: zimoli, ["appendChild*" + live]: appendChild, ["remove*" + live]: remove })));
292
369
  var func = createFunction("", codetext, argNames, code.async, code.yield);
293
370
  var res = func.apply(window, args);
294
371
  if (isFunction(res)) {
@@ -299,6 +376,7 @@
299
376
  }
300
377
  } catch (e) {
301
378
  alert(String(e), 'error');
379
+ throw e;
302
380
  }
303
381
  };
304
382
  var tags = [
@@ -309,6 +387,7 @@
309
387
  var actived = tags.map(t => t.actived);
310
388
  var xmenu = menu;
311
389
  var page = view();
390
+ on("submit")(page, e => e.preventDefault());
312
391
  page.innerHTML = template;
313
392
  var scope = {
314
393
  btn: button,
@@ -326,8 +405,11 @@
326
405
  updatecode,
327
406
  saveTagIndex(i) {
328
407
  data.setInstance("docscode", { tagIndex: i });
329
- if (i === 1 && !scope.codetext) loadcode();
408
+ if (i === 1 && !scope.codetext) requestAnimationFrame(loadcode);
330
409
  },
410
+ keytab(event) {
411
+ event.preventDefault();
412
+ }
331
413
  };
332
414
  render(page, scope);
333
415
  function main(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.36.3",
3
+ "version": "3.36.6",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {