efront 4.4.3 → 4.4.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.
@@ -1 +1 @@
1
- fromBase64
1
+ b => decodeUTF8(fromBase64(b));
@@ -0,0 +1 @@
1
+ a => toBase64(encodeUTF8(String(a)));
@@ -62,7 +62,9 @@ Javascript.prototype.isProperty = function (o) {
62
62
  if (prev.isprop) return true;
63
63
  return /^(\+\+|\-\-|;)$/.test(prev.text);
64
64
  }
65
- if (prev.type === EXPRESS && !/\.$/.test(prev.text)) return true;
65
+ if (prev.type === EXPRESS && !/\.$/.test(prev.text)) {
66
+ return prev.text !== 'async' || o.text !== 'function';
67
+ }
66
68
  if (prev.type & (SCOPED | VALUE | QUOTED | PROPERTY)) return true;
67
69
  }
68
70
  if (!prev) return false;
@@ -341,6 +343,11 @@ Javascript.prototype.setType = function (o) {
341
343
  last.type = EXPRESS;
342
344
  return false;
343
345
  }
346
+ if (last) {
347
+ if (o.type === STRAP && o.text === "function") {
348
+ if (last.text === 'async') last.type = last.isend ? EXPRESS : STRAP;
349
+ }
350
+ }
344
351
  this.fixType(o);
345
352
  var queue = o.queue;
346
353
  if (queue.isObject || queue.isClass) {
@@ -371,14 +378,10 @@ Javascript.prototype.setType = function (o) {
371
378
  }
372
379
  }
373
380
  if (o.type === PROPERTY || o.isprop);
374
- else if (o.type === STRAP && /^(get|set|static)/.test(o.text)) {
381
+ else if (o.type === STRAP && /^(get|set|static|async)$/.test(o.text)) {
375
382
  o.type = EXPRESS;
376
383
  }
377
384
  if (last) {
378
- if (!o.isprop && last.type === STRAP) {
379
- if (last.text === 'async' && o.text !== "function")
380
- last.type = EXPRESS;
381
- }
382
385
  if (o.type === STAMP && o.text === "=>") {
383
386
  var pp = last.prev;
384
387
  if (pp && pp.type === EXPRESS && pp.text === 'async') {
@@ -111,7 +111,7 @@ class Program {
111
111
  Code = Array;
112
112
  transive_reg = /^(new|void|case|break|continue|return|throw|extends|import)$/
113
113
  straps = "if,for".split(',');
114
- forceend_reg = /^(return|break|continue)$/;
114
+ forceend_reg = /^(return|break|continue|async)$/;
115
115
  classstrap_reg = /^(class)$/;
116
116
  extends_reg = /^(extends)$/;
117
117
  spaces = spaceDefined;
@@ -444,6 +444,7 @@ class Program {
444
444
  if (last.type === QUOTED && !last.tag) break test;
445
445
  if (last.type === SCOPED && queue.inExpress) break test;
446
446
  if (lasttype === STAMP && m === last.text) break test;
447
+ if (last.type === STAMP && /^(\+\+|\-\-)$/.test(last.text)) break test;
447
448
  }
448
449
  var scope = [];
449
450
  scope.type = this.comment_entry.test(m) ? COMMENT : QUOTED;
@@ -608,7 +608,7 @@ var _invoke = function (t, getname) {
608
608
  }
609
609
  }
610
610
  if (queue.length) {
611
- queue.push(t);
611
+ if (t.length) queue.push(t);
612
612
  flushqueue(result, queue);
613
613
  }
614
614
  else if (t.length) {
@@ -617,6 +617,7 @@ var _invoke = function (t, getname) {
617
617
  t.unshift(...rescan(`${qname}=${qname}`));
618
618
  relink(t);
619
619
  }
620
+ t = uncurve(t);
620
621
  pushstep(result, t);
621
622
  }
622
623
  if (ret_) patchresult(result, 0);
@@ -704,7 +705,10 @@ var popexp = function (explist) {
704
705
  }
705
706
  return [asn, n];
706
707
  }
707
-
708
+ var uncurve = function (c) {
709
+ if (c.length === 1 && c[0].type === SCOPED && c[0].entry === '(' && canbeOnce(c[0])) c = c[0];
710
+ return c;
711
+ };
708
712
  var ternary = function (body, getname, ret) {
709
713
  var eqused = 0;
710
714
  var getnextname = function (i) {
@@ -787,7 +791,6 @@ var ternary = function (body, getname, ret) {
787
791
  explist = [r];
788
792
  }
789
793
  else {
790
- if (equals.length && bd.length === 1 && bd[0].type === SCOPED && bd[0].entry === '(' && skipAssignment(bd[0], 0) === bd[0].length) bd = bd[0];
791
794
  explist = _express(bd, getnextname, equalsend > skip || ret);
792
795
  }
793
796
  }
@@ -840,6 +843,7 @@ var ternary = function (body, getname, ret) {
840
843
  eq.text = "=";
841
844
  }
842
845
  else an = n;
846
+ asn = uncurve(asn);
843
847
  ass.push(equals[i], ...asn);
844
848
  relink(ass);
845
849
  if (evals.length) ass[0].set = getnextname(0);
@@ -39,13 +39,13 @@ test('a * a ?? b * c * c ** d', "_ = a * a; if (_ !== null && _ !== undefined) r
39
39
  test('a * a && await b*c', "_ = a * a; if (!_) return [2, 0]; _ = b; return [_, 1];\r\n _ = @; _ * c", true);
40
40
  test("await a", "_ = a; return [_, 1]", true);
41
41
  test("yield a", "return [a, 3]", true);
42
- test("!a.done&&(b=await a.value)", "_ = !a.done; if (!_) return [2, 0]; _ = a.value; return [_, 1];\r\n _ = @; b = _; (_)", true);
42
+ test("!a.done&&(b=await a.value)", "_ = !a.done; if (!_) return [2, 0]; _ = a.value; return [_, 1];\r\n _ = @; b = _; _", true);
43
43
  test("a=1?2:3", `if (false) return [1, 0]; a = 2; return [2, 0];\r\n a = 3; return [1, 0]`)
44
44
  test("await a()", "_ = a(); return [_, 1]", true);
45
45
  test("yield a()", "_ = a(); return [_, 3]", true);
46
46
  test("a = await a()", "_ = a(); return [_, 1];\r\n _ = @; a = _", true);
47
47
  test("a = yield a()", "_ = a(); return [_, 3];\r\n _ = @; a = _", true);
48
- test("(1+ +1)", "_ = 1 + +1; (_)", true);
48
+ test("(1+ +1)", "_ = 1 + +1; _", true);
49
49
  test("await a(await b)", "_ = b; return [_, 1];\r\n _ = @; _ = a(_); return [_, 1]", true);
50
50
  test("await a(await b).s(await c)", "_ = b; return [_, 1];\r\n _ = @; _ = a(_); _0 = c; return [_0, 1];\r\n _0 = @; _ = _.s(_0); return [_, 1]", true);
51
51
  test("a*a + await a(await b).s(await c)", "_ = a * a, _0 = b; return [_0, 1];\r\n _0 = @; _0 = a(_0); _1 = c; return [_1, 1];\r\n _1 = @; _0 = _0.s(_1); return [_0, 1];\r\n _0 = @; _ + _0", true);
@@ -89,8 +89,8 @@ test("with(a){ a = 1}", `if (_ = with_("a", [a])) _.a = 1; else a = 1;`, true);
89
89
  test("try{a=2+1}catch(e){return;}", 'return [65537, 7];\r\n a = 2 + 1; return [0, 9];\r\n e = @; return [undefined, 2];\r\n return [1, 9]', true);
90
90
  test("try{a=2+1}catch(e){}", 'return [1, 7];\r\n a = 2 + 1; return [0, 9];\r\n return [1, 9]', true);
91
91
  test("try{a=2+1}catch(e){a=3}", 'return [65537, 7];\r\n a = 2 + 1; return [0, 9];\r\n e = @; a = 3; return [0, 9];\r\n return [1, 9]', true);
92
- test("(function(){})", '_ = function () {}; (_)', true);
93
- test("(1+2*function(){}())", '_ = 2 * function () {}(), _ = 1 + _; (_)', true);
92
+ test("(function(){})", '_ = function () {}; _', true);
93
+ test("(1+2*function(){}())", '_ = 2 * function () {}(), _ = 1 + _; _', true);
94
94
  test("function a(){}", 'a = function a() {}', true);
95
95
  test("if(1) function a(){}", 'if (false) return [1, 0]; a = function a() {}; return [1, 0]', true);
96
96
  test("if(1) {function a(){}}", 'if (false) return [1, 0]; a = function a() {}; return [1, 0]', true);
@@ -153,3 +153,4 @@ test(`c=b+ !a`, "_ = !a, c = b + _");
153
153
  test(`do {var loadcount = 0;} while (loadcount !== 0);`, `loadcount = 0; _ = loadcount !== 0; if (_) return [0, 0]`);
154
154
  unstruct.debug = true; r++;
155
155
  test("if(a)try{a}catch{};a;", 'if (!a) return [4, 0]; return [1, 7];\r\n a; return [0, 9];\r\n return [1, 9];\r\n return [1, 0];\r\n a');
156
+ test("url = (o===void 0||o===null?void 0:o.url)", '_ = void 0, _ = o === _; if (_) return [1, 0]; _ = o === null;\r\n if (!_) return [1, 0]; _ = void 0; return [2, 0];\r\n _ = o.url; return [1, 0];\r\n url = _', true);
@@ -1,10 +1,16 @@
1
+ <style>
2
+ &[empty] {
3
+ opacity: .3;
4
+ }
5
+ </style>
1
6
  <canvas width="240" height="240" style="width:240px;height:240px;image-rendering: pixelated;" />
2
7
  <script>
3
8
  async function loadQRCode() {
4
- this.innerHTML = template;
5
9
  var o = this.target.data;
10
+ var url = o?.url;
11
+ if (!url) return;
12
+ this.innerHTML = template;
6
13
  var canvas = this.firstElementChild;
7
- var url = o.url;
8
14
  var host = data.getInstance("base");
9
15
  var href = host.base + url.replace(/^[\/\\]/, '');
10
16
  var qrcode = await init("thirdParty$qrcode");
@@ -20,7 +26,12 @@
20
26
  var v = document.createElement("qrcode");
21
27
  select(element, v);
22
28
  oncemount(v, loadQRCode);
29
+ oncemount(element, function () {
30
+ if (this.data?.url) return;
31
+ this.setAttribute('empty', '');
32
+ });
23
33
  v.tabIndex = 0;
24
34
  v.onclick = e => e.preventDefault();
35
+ return element;
25
36
  }
26
37
  </script>
@@ -21,19 +21,14 @@ var gosrc = function () {
21
21
  if (this.hasAttribute && this.hasAttribute('src')) {
22
22
  src = this.getAttribute('src');
23
23
  }
24
- if (src !== this._src) {
24
+ if (src !== this.$src) {
25
25
  change.call(this, src);
26
- this._src = src;
26
+ this.$src = src;
27
27
  }
28
28
  };
29
29
  function container(element) {
30
- var src;
31
- if (element && element.hasAttribute('src')) {
32
- src = element.getAttribute('src');
33
- }
34
30
  var comment = document.createComment('container');
35
- comment.src = src;
36
31
  comment.$struct = element.$struct;
37
- comment.renders = [gosrc];
32
+ care(comment, gosrc);
38
33
  return comment;
39
34
  }
@@ -8,20 +8,14 @@ var decodeMap = function () {
8
8
  return map;
9
9
  }();
10
10
  function fromBase64(input) {
11
- var str = String(input).replace(/[=]+$/, ''); // #31: ExtendScript bad parse of /=
12
- for (
13
- // initialize result and counters
14
- var bc = 0, bs, buffer, idx = 0, output = [];
15
- // get next character
16
- buffer = str.charAt(idx++);
17
- // character found in table? initialize bit storage and add its ascii value;
18
- ~buffer && (bs = bc % 4 ? (bs << 6) + buffer : buffer,
19
- // and if not first of each 4 characters,
20
- // convert the first 8 bits to one ascii character
21
- bc++ % 4) ? output.push(255 & bs >> (-2 * bc & 6)) : 0
22
- ) {
23
- // try to find character in table (0-63, not found => -1)
24
- buffer = decodeMap[buffer];
11
+ input = String(input).replace(/\=+$/, '');
12
+ var output = [];
13
+ for (var cx = 0, dx = input.length; cx < dx;) {
14
+ var block = decodeMap[input.charAt(cx++)] << 18 | decodeMap[input.charAt(cx++)] << 12 | decodeMap[input.charAt(cx++)] << 6 | decodeMap[input.charAt(cx++)];
15
+ output.push(block >> 16, block >> 8 & 0xff, block & 0xff);
25
16
  }
17
+ cx -= dx;
18
+ if (cx > 1) output.pop();
19
+ if (cx > 0) output.pop();
26
20
  return output;
27
21
  }
@@ -71,13 +71,16 @@ var removeRenderElement = function () {
71
71
  function refresh(root) {
72
72
  var rest = [];
73
73
  var body = document.documentElement;
74
- for (var k in renderElements) {
75
- var element = renderElements[k];
76
- if (root && root.renders) {
74
+ if (root && root.renders) {
75
+ for (var k in renderElements) {
76
+ var element = renderElements[k];
77
77
  if (
78
78
  getTargetIn(root, element)
79
79
  ) rebuild(element);
80
- } else {
80
+ }
81
+ } else {
82
+ for (var k in renderElements) {
83
+ var element = renderElements[k];
81
84
  rebuild(element);
82
85
  if (!getTargetIn(body, element)) {
83
86
  rest.push(element);
@@ -697,18 +700,22 @@ var emiters = {
697
700
  };
698
701
  emiters.v = emiters.ng = emiters.on;
699
702
 
703
+ var keyAdapters = [
704
+ key => key,
705
+ key => key.toLowerCase(),
706
+ key => key.replace(/\-+([a-z])/g, (_, w) => w.toUpperCase()),
707
+ key => key.replace(/^([a-z])/g, (_, w) => w.toUpperCase())
708
+ ];
700
709
  function getFromScopes(key, scope, parentScopes) {
701
- if (scope) if (key in scope) {
702
- return scope[key];
703
- }
704
- if (parentScopes) for (var cx = parentScopes.length - 1; cx >= 0; cx--) {
705
- var o = parentScopes[cx];
706
- if (o && key in o) {
707
- return o[key];
710
+ if (!isHandled(key)) return;
711
+ for (var ka of keyAdapters) {
712
+ key = ka(key);
713
+ if (scope && key in scope) return scope[key];
714
+ if (parentScopes) for (var cx = parentScopes.length - 1; cx >= 0; cx--) {
715
+ var o = parentScopes[cx];
716
+ if (o && key in o) return o[key];
708
717
  }
709
- }
710
- if (key in presets) {
711
- return presets[key];
718
+ if (key in presets) return presets[key];
712
719
  }
713
720
  }
714
721
 
@@ -788,14 +795,6 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
788
795
  var { tagName, parentNode, nextSibling } = element;
789
796
  // 替换元素
790
797
  var constructor = getFromScopes(tagName, scope, parentScopes);
791
- if (!constructor) {
792
- tagName = tagName.toLowerCase();
793
- constructor = getFromScopes(tagName, scope, parentScopes);
794
- }
795
- if (!constructor) {
796
- tagName = tagName.replace(/(?:^|\-+)([a-z])/ig, (_, w) => w.toUpperCase());
797
- constructor = getFromScopes(tagName, scope, parentScopes);
798
- }
799
798
  if (isFunction(constructor)) {
800
799
  var replacer = constructor.call(scope, element, scope, parentScopes);
801
800
  if (isNode(replacer) && element !== replacer) {
@@ -1,18 +1,14 @@
1
- //base64
2
- var encoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
1
+ var encoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
3
2
  function toBase64(input) {
4
- for (
5
- // initialize result and counter
6
- var block, charCode, idx = 0, map = encoding, length = input.length, output = [];
7
- // if the next str index does not exist:
8
- // change the mapping table to "="
9
- // check if d has no fractional digits
10
- idx < length || (map = '=', idx % 1);
11
- // "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
12
- output.push(encoding.charAt(63 & block >> 8 - idx % 1 * 8))
13
- ) {
14
- charCode = input[parseInt(idx += 3 / 4)];
15
- block = block << 8 | charCode;
3
+ for (var cx = 0, block, output = [], dx = input.length; cx < dx;) {
4
+ block = input[cx++] << 16 | input[cx++] << 8 | input[cx++];
5
+ output.push(
6
+ encoding[block >> 18],
7
+ encoding[block >> 12 & 0b111111],
8
+ encoding[block >> 6 & 0b111111],
9
+ encoding[block & 0b111111]
10
+ );
16
11
  }
12
+ for (cx = output.length + dx - cx, dx = output.length; cx < dx; cx++) output[cx] = '=';
17
13
  return output.join("");
18
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.4.3",
3
+ "version": "4.4.6",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {