efront 4.0.55 → 4.0.57

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.
@@ -259,14 +259,14 @@ function stringify(color) {
259
259
  }
260
260
  return "#" + [R, G, B].map(hex256).join("");
261
261
  }
262
- function doWith(manager, color, args) {
262
+ function doWith(manager, color, ...args) {
263
263
  var isparsed = color instanceof Array,
264
264
  c = isparsed ? color : parse(color);
265
265
  if (!c) {
266
266
  console.warn(`颜色数据不正确:${color}`);
267
267
  return color;
268
268
  }
269
- c = manager(c, args);
269
+ c = manager(c, ...args);
270
270
  if (!isparsed) c = stringify(c);
271
271
  return c;
272
272
  }
@@ -382,7 +382,89 @@ var gray4 = function (RGBA, A) {
382
382
  return [r, g, b, A || a];
383
383
  };
384
384
 
385
+ var saturate_rgb = function (RGBA, delta) {
386
+ var [r, g, b, a] = RGBA;
387
+ var h = rgb2h(r, g, b);
388
+ delta = percent(delta);
389
+ h += delta * 100;
390
+ [r, g, b] = rgb4h(r, g, b, h);
391
+ return [r, g, b, a];
392
+ };
393
+
394
+ var desaturate_rgb = function (RGBA, delta) {
395
+ delta = percent(delta);
396
+ return saturate_rgb(RGBA, -delta);
397
+ };
398
+
399
+ var lighten_rgb = function (RGBA, delta) {
400
+ var [r, g, b, a] = RGBA;
401
+ delta = percent(delta)
402
+ var l = rgb2v(r, g, b);
403
+ l += delta * 100;
404
+ [r, g, b] = rgb4v(r, g, b, l);
405
+ return [r, g, b, a];
406
+ };
385
407
 
408
+ var darken_rgb = function (RGBA, delta) {
409
+ delta = percent(delta);
410
+ return lighten_rgb(RGBA, -delta);
411
+ };
412
+
413
+ var fadein_rgb = function (RGBA, delta) {
414
+ delta = percent(delta);
415
+ var [r, g, b, a] = RGBA;
416
+ a += delta;
417
+ return [r, g, b, a];
418
+ };
419
+
420
+ var fadeout_rgb = function (RGBA, delta) {
421
+ delta = percent(delta);
422
+ return fadein_rgb(RGBA, -delta);
423
+ };
424
+
425
+ var fade_rgb = function (RGBA, alpha) {
426
+ var [r, g, b] = RGBA;
427
+ return [r, g, b, alpha];
428
+ };
429
+
430
+ var spin_rgb = function (RGBA, delta) {
431
+ var [r, g, b, a] = RGBA;
432
+ var s = rgb2s(r, g, b);
433
+ s += delta;
434
+ var [r, g, b] = rgb4s(r, g, b, s);
435
+ return [r, g, b, s];
436
+ };
437
+
438
+ var grayscale_rgb = function (RGBA) {
439
+ var [r, g, b, a] = RGBA;
440
+ [r, g, b] = rgb4s(r, g, b, 0);
441
+ return [r, g, b, a];
442
+ };
443
+ var grayluma_rgb = function (RGBA) {
444
+ var [r, g, b, a] = RGBA;
445
+ var v = rgb2v(r, g, b);
446
+ return [v, v, v, a];
447
+ };
448
+ var mix_rgb = function (RGBA, c2, power) {
449
+ var c1 = rgb2hsl(RGBA);
450
+ c1.push(RGBA[3]);
451
+ var rgba2 = parse(c2);
452
+ var c2 = rgb2hsl(rgba2);
453
+ c2.push(rgba2[3]);
454
+ return [0, 1, 2, 3].map(a => c1[a] * (1 - power) + c2[a] * power);
455
+ };
456
+ var tint_rgb = function (RGBA, power) {
457
+ return mix_rgb([255, 255, 255, RGBA[3]], RGBA, power);
458
+ };
459
+ var shade_rgb = function (RGBA, power) {
460
+ return mix_rgb([0, 0, 0, RGBA[3]], RGBA, power);
461
+ };
462
+
463
+ var wrap = function (f) {
464
+ return function () {
465
+ return doWith(f, ...arguments);
466
+ }
467
+ };
386
468
  var random_base = Math.PI * Math.random() * 2;
387
469
  extend(color, {
388
470
  setTransformer(transformer) {
@@ -394,6 +476,19 @@ extend(color, {
394
476
  contrast(color, ratio) {
395
477
  return doWith(contrast_rgb, color, ratio);
396
478
  },
479
+ saturate: wrap(saturate_rgb),
480
+ desaturate: wrap(desaturate_rgb),
481
+ lighten: wrap(lighten_rgb),
482
+ darken: wrap(darken_rgb),
483
+ fadein: wrap(mix_rgb),
484
+ fadeout: wrap(fadeout_rgb),
485
+ fade: wrap(fade_rgb),
486
+ spin: wrap(spin_rgb),
487
+ mix: wrap(mix_rgb),
488
+ tint: wrap(tint_rgb),
489
+ shade: wrap(shade_rgb),
490
+ grayscale: wrap(grayscale_rgb),
491
+ grayluma: wrap(grayluma_rgb),
397
492
  rgb2h,
398
493
  rgb4h,
399
494
  rgb2v,
@@ -40,6 +40,8 @@ class Javascript extends Program {
40
40
  strapexp_reg = /^(new|void|typeof|delete|class|function|await)/;
41
41
  forceend_reg = /^(return|yield|break|continue|debugger)$/;
42
42
  classstrap_reg = /^(class|function|async)$/;
43
+ colonstrap_reg = /^(case|default)$/;
44
+
43
45
  defaultType = EXPRESS;
44
46
  }
45
47
  var propresolve_reg = /^(static|get|set|async)$/;
@@ -210,7 +212,126 @@ var isShortMethodEnd = function (o) {
210
212
  return o.isprop;
211
213
  };
212
214
 
215
+ var setObject = function (o) {
216
+ o.isObject = true;
217
+ var needproperty = true;
218
+ for (var cx = 0; cx < o.length; cx++) {
219
+ var m = o[cx];
220
+ if (!needproperty) {
221
+ if (m.type === SCOPED && m.entry === '{') {
222
+ if (!m.isObject) setObject(m);
223
+ continue;
224
+ }
225
+ if (m.type !== STAMP || m.text !== ',') continue;
226
+ }
227
+ if (m.type === STAMP && m.text === ':') {
228
+ needproperty = false;
229
+ continue;
230
+ }
231
+ if (m.type === LABEL) {
232
+ o.splice(cx, 0, o[++cx].prev = m.next = m.next.prev = {
233
+ prev: m,
234
+ text: ':',
235
+ type: STAMP,
236
+ next: m.next,
237
+ });
238
+ m.type = PROPERTY;
239
+ m.text = m.text.replace(/\:$/, '');
240
+ m.isprop = true;
241
+ m.end--;
242
+ needproperty = false;
243
+ continue;
244
+ }
245
+ m.isprop = true;
246
+ if (m.type === EXPRESS || m.type === QUOTED) {
247
+ if (!/\./.test(m.text)) m.type = PROPERTY;
248
+ }
249
+ if (m.prev && m.prev.type === PROPERTY) {
250
+
251
+ m.prev.type = STRAP;
252
+ }
253
+ }
254
+ };
255
+ Javascript.prototype.detectLabel = function (o) {
256
+ var queue = o.queue;
257
+ var last = queue.last;
258
+ var m = o.text;
259
+ var type = o.type;
260
+ var colonstrap_reg = this.colonstrap_reg;
261
+ var end = o.end;
262
+
263
+ if (type === SPACE);
264
+ else if (type !== STAMP);
265
+ else if (m === ";") {
266
+ if (last && last.isend === false) last.isend = true;
267
+ queue.inExpress = false;
268
+ }
269
+ else if (last) check: switch (m) {
270
+ case "?":
271
+ queue.inExpress = true;
272
+ if (!queue.question) queue.question = 1;
273
+ else queue.question++;
274
+ break;
275
+ case "=":
276
+ queue.inExpress = true;
277
+ if (last.type === SCOPED && last.entry === "{") {
278
+ if (!last.isObject) {
279
+ setObject(last);
280
+ }
281
+ }
282
+ case ",":
283
+ if (queue.isObject) {
284
+ if (last.type === PROPERTY) {
285
+ last.short = true;
286
+ }
287
+ }
288
+ queue.inExpress = true;
289
+ break;
290
+ case ":":
291
+ if (queue.question) {
292
+ queue.question--;
293
+ queue.inExpress = true;
294
+ break;
295
+ }
296
+ if (queue.isObject) {
297
+ if (last.type === PROPERTY || last.isprop) {
298
+ queue.inExpress = true;
299
+ break;
300
+ }
301
+ if (last.type === SCOPED && (!last.prev || !last.prev.type === STAMP && last.prev.text === ",")) {
302
+ queue.inExpress = true;
303
+ }
304
+ break;
305
+ }
306
+ var temp = last;
307
+ while (temp) {
308
+ if (temp.type === STRAP && colonstrap_reg.test(temp.text)) {
309
+ queue.inExpress = false;
310
+ break check;
311
+ }
312
+ if (!temp.isExpress) break;
313
+ temp = temp.prev;
314
+ }
315
+ queue.inExpress = false;
316
+ if (last.type & (EXPRESS | STRAP | VALUE | QUOTED)) {
317
+ // label
318
+ last.type = LABEL;
319
+ last.text += ":";
320
+ last.end = end;
321
+ return o;
322
+ }
323
+ break;
324
+ default:
325
+ queue.inExpress = true;
326
+ }
327
+ else {
328
+ queue.inExpress = true;
329
+ }
330
+ o.isExpress = queue.inExpress;
331
+ }
332
+
213
333
  Javascript.prototype.setType = function (o) {
334
+ if (this.detectLabel(o)) return false;
214
335
  var last = o.prev;
215
336
  if (o.type === EXPRESS && /^\.[^\.]/.test(o.text) && last && last.type === STAMP && last.text === "?") {
216
337
  last = o.prev = snapExpressHead(last.prev);
@@ -14,46 +14,7 @@ const {
14
14
  number_reg,
15
15
  } = require("./common");
16
16
  var combine = require("../basic/combine");
17
- var setObject = function (o) {
18
- o.isObject = true;
19
- var needproperty = true;
20
- for (var cx = 0; cx < o.length; cx++) {
21
- var m = o[cx];
22
- if (!needproperty) {
23
- if (m.type === SCOPED && m.entry === '{') {
24
- if (!m.isObject) setObject(m);
25
- continue;
26
- }
27
- if (m.type !== STAMP || m.text !== ',') continue;
28
- }
29
- if (m.type === STAMP && m.text === ':') {
30
- needproperty = false;
31
- continue;
32
- }
33
- if (m.type === LABEL) {
34
- o.splice(cx, 0, o[++cx].prev = m.next = m.next.prev = {
35
- prev: m,
36
- text: ':',
37
- type: STAMP,
38
- next: m.next,
39
- });
40
- m.type = PROPERTY;
41
- m.text = m.text.replace(/\:$/, '');
42
- m.isprop = true;
43
- m.end--;
44
- needproperty = false;
45
- continue;
46
- }
47
- m.isprop = true;
48
- if (m.type === EXPRESS || m.type === QUOTED) {
49
- if (!/\./.test(m.text)) m.type = PROPERTY;
50
- }
51
- if (m.prev && m.prev.type === PROPERTY) {
52
17
 
53
- m.prev.type = STRAP;
54
- }
55
- }
56
- };
57
18
  var sortRegExpSource = function (a, b) {
58
19
  if (a.indexOf(b) >= 0) return -1;
59
20
  if (b.indexOf(a) >= 0) return 1;
@@ -147,7 +108,6 @@ class Program {
147
108
  Code = Array;
148
109
  transive_reg = /^(new|void|case|break|continue|return|throw|extends|import)$/
149
110
  straps = "if,for".split(',');
150
- colonstrap_reg = /^(case|default)$/;
151
111
  forceend_reg = /^(return|break|continue)$/;
152
112
  classstrap_reg = /^(class)$/;
153
113
  extends_reg = /^(extends)$/;
@@ -186,7 +146,6 @@ class Program {
186
146
  var Code = this.Code;
187
147
  var queue = new Code();
188
148
  var origin = queue;
189
- var colonstrap_reg = this.colonstrap_reg;
190
149
  var forceend_reg = this.forceend_reg;
191
150
  var program = this;
192
151
  var queue_push = function (scope) {
@@ -237,74 +196,7 @@ class Program {
237
196
  return;
238
197
  }
239
198
  }
240
- var last = queue.last;
241
- if (type === SPACE);
242
- else if (type !== STAMP);
243
- else if (m === ";") {
244
- if (last && last.isend === false) last.isend = true;
245
- queue.inExpress = false;
246
- }
247
- else if (last) check: switch (m) {
248
- case "?":
249
- queue.inExpress = true;
250
- if (!queue.question) queue.question = 1;
251
- else queue.question++;
252
- break;
253
- case "=":
254
- queue.inExpress = true;
255
- if (last.type === SCOPED && last.entry === "{") {
256
- if (!last.isObject) {
257
- setObject(last);
258
- }
259
- }
260
- case ",":
261
- if (queue.isObject) {
262
- if (last.type === PROPERTY) {
263
- last.short = true;
264
- }
265
- }
266
- queue.inExpress = true;
267
- break;
268
- case ":":
269
- if (queue.question) {
270
- queue.question--;
271
- queue.inExpress = true;
272
- break;
273
- }
274
- if (queue.isObject) {
275
- if (last.type === PROPERTY || last.isprop) {
276
- queue.inExpress = true;
277
- break;
278
- }
279
- if (last.type === SCOPED && (!last.prev || !last.prev.type === STAMP && last.prev.text === ",")) {
280
- queue.inExpress = true;
281
- }
282
- break;
283
- }
284
- var temp = last;
285
- while (temp) {
286
- if (temp.type === STRAP && colonstrap_reg.test(temp.text)) {
287
- queue.inExpress = false;
288
- break check;
289
- }
290
- if (!temp.isExpress) break;
291
- temp = temp.prev;
292
- }
293
- queue.inExpress = false;
294
- if (last.type & (EXPRESS | STRAP | VALUE | QUOTED)) {
295
- // label
296
- last.type = LABEL;
297
- last.text += ":";
298
- last.end = end;
299
- return;
300
- }
301
- break;
302
- default:
303
- queue.inExpress = true;
304
- }
305
- else {
306
- queue.inExpress = true;
307
- }
199
+
308
200
  var scope = {
309
201
  type,
310
202
  start,
@@ -27,4 +27,8 @@ t("for(;;a=1){ console.log(a)} console.log(a)", "for (;; a = 1) { console.log(a)
27
27
  t("for(var a = 1;;){ console.log(a)} console.log(a)", "for (var a = 1;;) { console.log(1) } console.log(1)");
28
28
  t("for(let a = 1;;){ console.log(a)} console.log(a)", "for (let a = 1;;) { console.log(a) } console.log(a)");
29
29
  t("var a=-1; console.log(-a)", "var a = -1; console.log(- -1)");
30
+ t("var a=-1; console.log(--a)", "var a = -1; console.log(--a)");
31
+ t("var a=-1; return ++a", "var a = -1; return ++a");
32
+ t("var a=-1; typeof ++a", "var a = -1; typeof ++a");
33
+ t("var a=-1; ++a", "var a = -1; ++a");
30
34
  // t(fs.readFileSync(path.join(__dirname,"../zimoli/spacechar_test.js")).toString())
@@ -404,7 +404,7 @@ var createScoped = function (parsed, wash) {
404
404
  var function_obj = null;
405
405
  if (o.type === STAMP && equal_reg.test(o.text)) {
406
406
  var p = snapExpressHead(o.prev);
407
- if (!p) {
407
+ if (!p || p.type & (STRAP | STAMP)) {
408
408
  let n = o.next;
409
409
  if (n && n.type & (EXPRESS | VALUE)) {
410
410
  n.equal = o;
@@ -999,7 +999,9 @@ var setqueue = function (list, queue = list) {
999
999
  };
1000
1000
 
1001
1001
  var createString = function (parsed) {
1002
+ var autospace = parsed.autospace !== false;
1002
1003
  var keepspace = parsed.keepspace !== false;
1004
+ var patchspace = autospace && keepspace;
1003
1005
  var helpcode = parsed.helpcode;
1004
1006
  var lasttype = SPACE;
1005
1007
  var uncomment = parsed.comment === false;
@@ -1007,7 +1009,7 @@ var createString = function (parsed) {
1007
1009
  var helpcolor = parsed.keepcolor === false;
1008
1010
  var run = (o, i, a) => {
1009
1011
  var prev = o.prev;
1010
- if (!((SPACE | COMMENT | STAMP | PIECE | SCOPED) & o.type) && prev && lasttype !== SPACE && keepspace) {
1012
+ if (!((SPACE | COMMENT | STAMP | PIECE | SCOPED) & o.type) && prev && lasttype !== SPACE && patchspace) {
1011
1013
  if ((QUOTED | SCOPED | STRAP | LABEL | COMMENT) & lasttype
1012
1014
  || prev.type === STAMP && !prev.unary
1013
1015
  ) {
@@ -1048,12 +1050,12 @@ var createString = function (parsed) {
1048
1050
  }
1049
1051
  }
1050
1052
  if (keepspace && !opentmp) {
1051
- if (lasttype !== SPACE && lasttype !== EXPRESS) result.push(" ");
1053
+ if (patchspace && lasttype !== SPACE && lasttype !== EXPRESS) result.push(" ");
1052
1054
  result.push(tmp);
1053
1055
  }
1054
1056
  break;
1055
1057
  case SPACE:
1056
- if (keepspace) {
1058
+ if (!autospace || keepspace) {
1057
1059
  result.push(o.text);
1058
1060
  lasttype = SPACE;
1059
1061
  break;
@@ -1068,21 +1070,21 @@ var createString = function (parsed) {
1068
1070
  break;
1069
1071
  }
1070
1072
  case SCOPED:
1071
- if (keepspace && o.type !== QUOTED && (lasttype & (STRAP | COMMENT | STAMP)
1073
+ if (patchspace && o.type !== QUOTED && (lasttype & (STRAP | COMMENT | STAMP)
1072
1074
  && (!o.prev || !/[\+\-\~\!]$/.test(o.prev.text) || /[\+\-]$/.test(o.prev.text) && (!o.prev.prev || !((STAMP | STRAP) & o.prev.prev.type)))
1073
1075
  || lasttype === SCOPED && o.entry === "{"
1074
1076
  )) result.push(" ");
1075
1077
  result.push(o.entry);
1076
1078
  if (o.length > 0) {
1077
1079
  if (o.entry === "{" && o[0].type !== SPACE) {
1078
- if (keepspace && lasttype !== PIECE) {
1080
+ if (patchspace && lasttype !== PIECE) {
1079
1081
  result.push(" ");
1080
1082
  }
1081
1083
  }
1082
1084
  lasttype = SPACE;
1083
1085
  o.forEach(run);
1084
1086
  if (o.prev && o.prev.type === STRAP && /^for$/.test(o.prev.text));
1085
- else if (/^[,;]$/.test(result[result.length - 1]) && !keepspace) {
1087
+ else if (/^[,;]$/.test(result[result.length - 1]) && autospace && !keepspace) {
1086
1088
  var last = o.last;
1087
1089
  var lp = last && last.prev;
1088
1090
  if (!lp) result.pop();
@@ -1093,7 +1095,7 @@ var createString = function (parsed) {
1093
1095
  }
1094
1096
  }
1095
1097
  if (o.leave === "}" && o.entry === "{" && o[o.length - 1].type !== SPACE) {
1096
- if (keepspace) result.push(" ");
1098
+ if (patchspace) result.push(" ");
1097
1099
  }
1098
1100
  }
1099
1101
  result.push(o.leave);
@@ -1102,13 +1104,13 @@ var createString = function (parsed) {
1102
1104
  if (o && typeof o === "object") {
1103
1105
  if (o.prev && o.prev.type === EXPRESS && o.type === EXPRESS && (/^[\.\[]/.test(o.text) || /\.$/.test(o.prev.text)));
1104
1106
  else if ((STRAP | EXPRESS | PROPERTY | COMMENT | VALUE) & lasttype && (STRAP | EXPRESS | PROPERTY | VALUE | LABEL) & o.type) {
1105
- result.push(" ");
1107
+ if (autospace) result.push(" ");
1106
1108
  }
1107
1109
  else if (o.prev && o.type === STAMP && !/^([,;])$/.test(o.text)) {
1108
1110
  if (result[result.length - 1] === " " || (lasttype === PROPERTY || !o.isExpress && o.prev && o.prev.type !== LABEL) && o.text === ':') { }
1109
1111
  else if (lasttype === STAMP) {
1110
1112
  var prev = o.prev;
1111
- if (!prev.unary || /[\+\-]$/.test(prev.text) && prev.text === o.text) result.push(" ");
1113
+ if (autospace) if (!prev.unary || /[\+\-]$/.test(prev.text) && prev.text === o.text) result.push(" ");
1112
1114
  }
1113
1115
  else if (/^(\+\+|\-\-)$/.test(o.prev.text) && o.prev.prev) {
1114
1116
  var prev_prev = o.prev.prev;
@@ -1119,10 +1121,10 @@ var createString = function (parsed) {
1119
1121
  }
1120
1122
 
1121
1123
  else if (o.text === '*') {
1122
- if (keepspace && lasttype !== SPACE && (lasttype !== STRAP || o.prev && o.prev.text !== 'function')) result.push(" ");
1124
+ if (patchspace && lasttype !== SPACE && (lasttype !== STRAP || o.prev && o.prev.text !== 'function')) result.push(" ");
1123
1125
  }
1124
- else if (!/^(\+\+|\-\-)$/.test(o.text)) {
1125
- if (keepspace && lasttype !== SPACE) result.push(" ");
1126
+ else if (!/^(\+\+|\-\-)$/.test(o.text) || o.prev && o.prev.type & (STAMP | STRAP)) {
1127
+ if (patchspace && lasttype !== SPACE) result.push(" ");
1126
1128
  }
1127
1129
  }
1128
1130
  if (o.type === VALUE) {