efront 4.35.1 → 4.35.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.
@@ -524,7 +524,7 @@ var createModule = function (exec, originNames, compiledNames, prebuilds = {}, a
524
524
  var _this = isModuleInit ? exports : window;
525
525
  var argsPromises = argsList.filter(isThenable);
526
526
  argsList = argsList.concat(exec.strs);
527
- argsList.push(compiledNames || []);
527
+ argsList.push(exec, argsList, compiledNames || []);
528
528
  if (!argsPromises.length) {
529
529
  return exec.apply(_this, argsList);
530
530
  }
@@ -50,6 +50,24 @@ var 三角函数 = {
50
50
  "csc"(a, n) {
51
51
  return mi2("csc", a, n);
52
52
  },
53
+ "arcsin"(a, n) {
54
+ return mi2("arcsin", a, n);
55
+ },
56
+ "arccos"(a, n) {
57
+ return mi2("arccos", a, n);
58
+ },
59
+ "arctan"(a, n) {
60
+ return mi2("arctan", a, n);
61
+ },
62
+ "arccot"(a, n) {
63
+ return mi2("arccot", a, n);
64
+ },
65
+ "arcsec"(a, n) {
66
+ return mi2("arcsec", a, n);
67
+ },
68
+ "arccsc"(a, n) {
69
+ return mi2("arccsc", a, n);
70
+ },
53
71
  };
54
72
 
55
73
  var funcmap = {
@@ -59,6 +77,12 @@ var funcmap = {
59
77
  "-"(...args) {
60
78
  return mo3("–", args);
61
79
  },
80
+ "+-"(...args) {
81
+ return mo3("±", args);
82
+ },
83
+ "-+"(...args) {
84
+ return mo3("∓", args);
85
+ },
62
86
  "*"(...args) {
63
87
  return args.join("");
64
88
  },
@@ -125,12 +149,18 @@ var unarymap = {
125
149
  "+"(a) {
126
150
  return unary("+", a);
127
151
  },
128
- "!"(a) {
129
- return unary("!", a);
130
- },
131
152
  "-"(a) {
132
153
  return unary("–", a);
133
154
  },
155
+ "+-"(a) {
156
+ return unary("±", a);
157
+ },
158
+ "-+"(a) {
159
+ return unary("∓", a);
160
+ },
161
+ "!"(a) {
162
+ return unary("!", a);
163
+ },
134
164
  "~"(a) {
135
165
  return unary("~", a);
136
166
  },
@@ -263,7 +293,7 @@ function toString(obj, p, deep) {
263
293
  }
264
294
  else f = unarymap[k];
265
295
  if (!f) {
266
- return mrow(`<mi>${k}</mi>${mrow(args instanceof Array ? args.join('<mo>,</mo>') : args, true)}`, false, deep);
296
+ return mrow(`<mi>${希腊[k] || k}</mi>${mrow(args instanceof Array ? args.join('<mo>,</mo>') : args, true)}`, false, deep);
267
297
  }
268
298
  if (args instanceof Array) {
269
299
  if (k === '*') {
@@ -294,6 +324,7 @@ function toString(obj, p, deep) {
294
324
  obj = 希腊[obj] || obj;
295
325
  if (typeof obj === "number") {
296
326
  if (obj === Infinity) obj = '∞';
327
+ if (obj < 0) obj = "–" + -obj;
297
328
  return mrow(mn(obj), -1, deep);
298
329
  }
299
330
  if (/^[\s,;]+$/.test(obj)) {
@@ -36,7 +36,7 @@ math(obj)
36
36
  ```
37
37
 
38
38
  2. 以数学公式的js表达式做为模板直接生成
39
- ```javascript
39
+ ```mathscript
40
40
  // 勾股定理可以表示为如下形式
41
41
  math`a**2+b**2=c**2`
42
42
  // 海伦-秦九韶公式可以表式为如下形式
@@ -46,21 +46,39 @@ math`S=sqrt(p*(p-a)*(p-b)*(p-c))`
46
46
 
47
47
  ## 常用语法及函数名如下
48
48
  * 加法
49
- ```javascript
49
+ ```mathscript
50
50
  1+2
51
51
  ```
52
52
  ```math
53
53
  1+2
54
54
  ```
55
55
  * 减法
56
- ```javascript
56
+ ```mathscript
57
57
  1-2
58
58
  ```
59
59
  ```math
60
60
  1-2
61
61
  ```
62
+ * 加减,正负,
63
+ ```mathscript
64
+ a +- 2;
65
+ a -+ 2;
66
+ +-a;
67
+ -+a;
68
+ // 分开写将识别为运算符加正负号
69
+ a + -2;
70
+ a - +2;
71
+ ```
72
+ ```math
73
+ a +- 2;
74
+ a -+ 2;
75
+ +-a;
76
+ -+a;
77
+ a + -2;
78
+ a - +2;
79
+ ```
62
80
  * 乘法
63
- ```javascript
81
+ ```mathscript
64
82
  1*2
65
83
  a*b
66
84
  2*a
@@ -70,7 +88,7 @@ math`S=sqrt(p*(p-a)*(p-b)*(p-c))`
70
88
  a*b
71
89
  2*a
72
90
  ```
73
- ```javascript
91
+ ```mathscript
74
92
  // 默认用`*`会自动转成`×`或`·`或省略
75
93
  // 如果自动生成的符号不符合预期
76
94
  // 可以使用`mul(a,b)`以强制生成`×`
@@ -82,56 +100,56 @@ mul(a,b),Mul(a,b),MUL(a,b)
82
100
  mul(a,b),Mul(a,b),MUL(a,b)
83
101
  ```
84
102
  * 分数
85
- ```javascript
103
+ ```mathscript
86
104
  分子/分母
87
105
  ```
88
106
  ```math
89
107
  分子/分母
90
108
  ```
91
109
  * 以除号表示除法
92
- ```javascript
110
+ ```mathscript
93
111
  div(被除数,除数)
94
112
  ```
95
113
  ```math
96
114
  div(被除数,除数)
97
115
  ```
98
116
  * 绝对值
99
- ```javascript
117
+ ```mathscript
100
118
  abs(a)
101
119
  ```
102
120
  ```math
103
121
  abs(a)
104
122
  ```
105
123
  * 阶乘: n!
106
- ```javascript
124
+ ```mathscript
107
125
  n!
108
126
  ```
109
127
  ```math
110
128
  n!
111
129
  ```
112
130
  * 幂
113
- ```javascript
131
+ ```mathscript
114
132
  底数 ** 指数
115
133
  ```
116
134
  ```math
117
135
  底数 ** 指数
118
136
  ```
119
137
  * 平方根
120
- ```javascript
138
+ ```mathscript
121
139
  sqrt(底数)
122
140
  ```
123
141
  ```math
124
142
  sqrt(底数)
125
143
  ```
126
144
  * 高次根式
127
- ```javascript
145
+ ```mathscript
128
146
  root(底数,指数)
129
147
  ```
130
148
  ```math
131
149
  root(底数,指数)
132
150
  ```
133
151
  * 函数
134
- ```javascript
152
+ ```mathscript
135
153
  f(x)=x**2
136
154
  f'(x)=2*x
137
155
  ```
@@ -141,7 +159,7 @@ mul(a,b),Mul(a,b),MUL(a,b)
141
159
  ```
142
160
 
143
161
  * 三角函数
144
- ```javascript
162
+ ```mathscript
145
163
  sin(theta);
146
164
  sin(theta,2);
147
165
  sin(theta**2);
@@ -155,7 +173,7 @@ sin(theta)**2;
155
173
  ```
156
174
 
157
175
  * 向量
158
- ```javascript
176
+ ```mathscript
159
177
  //vector(向量名,横坐标,纵坐标,竖坐标)
160
178
  vector(A,x,y)
161
179
  //坐标可以不传入
@@ -166,7 +184,7 @@ sin(theta)**2;
166
184
  vector(A)
167
185
  ```
168
186
  * 下标
169
- ```javascript
187
+ ```mathscript
170
188
  a[n]
171
189
  a[n+1]
172
190
  a_n
@@ -179,7 +197,7 @@ sin(theta)**2;
179
197
  a_(n+1)
180
198
  ```
181
199
  * 极限
182
- ```javascript
200
+ ```mathscript
183
201
  limit(公式主体,变量,目标)
184
202
  // 可以用 Infinity表示无穷大
185
203
  limit(1/n,n,+Infinity)
@@ -190,14 +208,14 @@ sin(theta)**2;
190
208
  ```
191
209
 
192
210
  * 积分
193
- ```javascript
211
+ ```mathscript
194
212
  integral(表达式,下界,上界)
195
213
  ```
196
214
  ```math
197
215
  integral(表达式,下界,上界)
198
216
  ```
199
217
  * 级数
200
- ```javascript
218
+ ```mathscript
201
219
  sigma(公式主体,n=1,+Infinity)
202
220
  series(公式主体,n=1,+Infinity)
203
221
  ```
@@ -206,28 +224,28 @@ sigma(公式主体,n=1,+Infinity)
206
224
  series(公式主体,n=1,+Infinity)
207
225
  ```
208
226
  * 矩阵
209
- ```javascript
227
+ ```mathscript
210
228
  [1,2;3,4]
211
229
  ```
212
230
  ```math
213
231
  [1,2;3,4]
214
232
  ```
215
233
  * 左除
216
- ```javascript
234
+ ```mathscript
217
235
  [1,2;3,4] \ [5;6]
218
236
  ```
219
237
  ```math
220
238
  [1,2;3,4]\[5;6]
221
239
  ```
222
240
  * 转置
223
- ```javascript
241
+ ```mathscript
224
242
  [1,2;3,4]'
225
243
  ```
226
244
  ```math
227
245
  [1,2;3,4]'
228
246
  ```
229
247
  * 离子
230
- ```javascript
248
+ ```mathscript
231
249
  H[+], O[2-]
232
250
  ```
233
251
  ```math
@@ -235,9 +253,8 @@ series(公式主体,n=1,+Infinity)
235
253
  ```
236
254
 
237
255
  ## 希腊字母对照表如下
238
-
256
+ 按此表中的英文单词命名的变量将自动转换为希腊字母
239
257
  ```javascript
240
- // 按此表中的英文单词命名的变量将自动转换为希腊字母
241
258
  alpha: "α", Alpha: "Α",
242
259
  beta: "β", Beta: "Β",
243
260
  gamma: "γ", Gamma: "‌Γ",
@@ -1203,7 +1203,7 @@ class Program {
1203
1203
  console.warn(
1204
1204
  "代码异常结束",
1205
1205
  `\r\n - 祖先标记: ${parents.slice(1).map(p => `${p.entry || ""}<red2>${p.tag || p.text || ""}</red2><gray>${p.row}:${p.col}</gray>`).join('')}`,
1206
- `\r\n - 内层入口: <yellow>${this.mindpath}</yellow>:${last.row}:${last.col} ${last.text || last.entry}`,
1206
+ `\r\n - 内层入口: <yellow>${this.mindpath}</yellow>:${queue.row}:${queue.col} ${queue.entry}`,
1207
1207
  );
1208
1208
  while (queue !== origin) {
1209
1209
  queue.error = "代码异常结束";
@@ -276,7 +276,9 @@ function solve(body, ox, dx) {
276
276
  if (cache.length && p <= cache[cache.length - 1]) {
277
277
  var p1 = p;
278
278
  var pt1 = pt;
279
+ var p2 = p;
279
280
  while (p1 <= cache[cache.length - 1]) {
281
+ p2 = p1;
280
282
  p1 = cache.pop();
281
283
  pt1 = cache.pop();
282
284
  bx = cache.pop();
@@ -285,7 +287,7 @@ function solve(body, ox, dx) {
285
287
  if (p === p1 && p > powermap[">>>"]) cache.push(bx, pt1, p1);
286
288
  continue;
287
289
  }
288
- var cx1 = make(body, bx, cx, p1 === p ? pt1 : null);
290
+ var cx1 = make(body, bx, cx, p === p2 ? pt1 : null);
289
291
  if (cx1 !== cx) {
290
292
  dx -= cx - cx1;
291
293
  cx = cx1;
@@ -321,7 +323,7 @@ function solve(body, ox, dx) {
321
323
  if (cache.length) {
322
324
  var bx = cache[0];
323
325
  var pt = cache[1];
324
- if (cx - bx >= 2) {
326
+ if (cx - bx >= 2 && cache[2] <= p) {
325
327
  cx = make(body, bx, cx, cache[1]);
326
328
  }
327
329
  }
@@ -82,4 +82,7 @@ tc("hwb(120 0 0)", "#0f0");
82
82
  tc("hwb(120turn 0 0)", "#f00");
83
83
  tc("calc(10 / 20)", "0.5");
84
84
  tc("calc(10 / 20)", "0.5");
85
+ tc("Math.log(f) / Math.LN2 / 10 | 0", "Math.log(f) * 0.14426950408889633 | 0");
86
+ tc("Math.log(f) / Math.LN2 / 10 * 10 | 0", "Math.log(f) * 1.4426950408889634 | 0");
87
+ tc("Math.log(f) / Math.LN2 / 10 ** 2 | 0", "Math.log(f) * 0.014426950408889633 | 0");
85
88
  // tf(path.join(__dirname, "../zimoli/spacechar_test.js"))
@@ -1515,7 +1515,7 @@ var createString = function (parsed) {
1515
1515
  (STRAP | EXPRESS | PROPERTY | COMMENT | VALUE) & lasttype
1516
1516
  && (STRAP | EXPRESS | PROPERTY | VALUE | LABEL) & o.type
1517
1517
  ) {
1518
- if (autospace || prev?.isdigit) result.push(" ");
1518
+ if (autospace || prev?.isdigit && patchspace) result.push(" ");
1519
1519
  }
1520
1520
  else if (p && o.type === STAMP && !/^[,;]/.test(o.text)) {
1521
1521
  if (result[result.length - 1] === " ");
@@ -2,30 +2,41 @@ const {
2
2
  STAMP, EXPRESS, SCOPED,
3
3
  createExpressList,
4
4
  skipAssignment,
5
+ createScoped,
6
+ createString,
5
7
  } = require("./common");
6
8
  var powermap = require("./powermap");
7
9
 
8
10
  class Math extends Program {
9
11
  number_reg = /^(\d+(\.\d+)?|\.\d+)$/;
12
+ powermap = Object.assign({}, powermap);
13
+ constructor() {
14
+ super();
15
+ var pmap = this.powermap;
16
+ pmap["+-"] = pmap["-+"] = powermap["+"];
17
+ pmap["×"] = pmap[".*"] = powermap["*"];
18
+ pmap["≈"] = pmap["~="] = pmap["=="];
19
+ pmap["≉"] = pmap["!≈"] = pmap["!~="] = pmap["~!="] = pmap["=="];
20
+ pmap["≠"] = powermap["!="];
21
+ pmap["≢"] = powermap["!=="];
22
+ pmap["^"] = powermap["**"];
23
+ pmap["_"] = powermap["?."];
24
+ pmap["'"] = powermap["?."];
25
+ this.stamps.push('\\', '_');
26
+ }
10
27
  }
28
+ Math.prototype.createScoped = createScoped;
29
+ Math.prototype.createString = createString;
11
30
  var math = new Math;
12
- math.stamps.push('\\', '_');
13
- var pmap = math.powermap = Object.assign({}, powermap);
14
- pmap["×"] = pmap[".*"] = powermap["*"];
15
- pmap["≈"] = pmap["~="] = pmap["=="];
16
- pmap["≉"] = pmap["!≈"] = pmap["!~="] = pmap["~!="] = pmap["=="];
17
- pmap["≠"] = powermap["!="];
18
- pmap["≢"] = powermap["!=="];
19
- pmap["^"] = powermap["**"];
20
- pmap["_"] = powermap["?."];
21
- pmap["'"] = powermap["?."];
31
+ var pmap = math.powermap;
22
32
  var puncmap = {
23
33
  "*": "×", // 叉乘
24
34
  '.*': '·',
25
35
  "!=": "≉",
26
36
  "!==": "≢",
27
37
  "~=": "≈",
28
- "-+": "±",
38
+ "-+": "",
39
+ "+-": "±",
29
40
  "!<": "≮",
30
41
  "!>": "≯",
31
42
  ">=": "≥",
@@ -204,7 +215,6 @@ var toFlat = function (exp) {
204
215
  }
205
216
  else {
206
217
  var args = getArgs(e);
207
- console.log(args)
208
218
  // 下标
209
219
  left = [make("_", left, ...args)];
210
220
  }
@@ -273,4 +283,5 @@ function main(text) {
273
283
  }
274
284
  res.pop();
275
285
  return uncup(res);
276
- }
286
+ }
287
+ main.MathScript = Math;
@@ -1,5 +1,5 @@
1
1
  var { STAMP, PROPERTY, SCOPED, VALUE, STRAP, EXPRESS, QUOTED, SPACE, COMMENT, createString: _createString, splice } = require("./common");
2
- var numberReg = /((?:[\+\-]+)?(?:\d+(?:\.\d*)?|\.\d+))([a-zH]+|%)?/;
2
+ var numberReg = /((?:\d+(?:\.\d*)?|\.\d+))([a-zH]+|%)?/;
3
3
  var createString = function (a) {
4
4
  a.autospace = false;
5
5
  return _createString(a);
@@ -78,6 +78,20 @@ test(`a >{b{a:b}}`, `a>b{a:b;}`);
78
78
  test(`a{>b{a:b}}`, `a>b{a:b;}`);
79
79
  test(`.type(@type,@media) {.@{type} {&:before{content:"@{media}";}}}.type(videoinput, "相机");`, `.videoinput:before{content:"相机";}`);
80
80
  test(`.type(@type,@media) {.@{type} {&:before{content:"@{media}";}}}.type(videoinput, 相机);`, `.videoinput:before{content:"相机";}`);
81
+ common.createString.debug = true;
82
+ Program.debug = true;
83
+ test(`@type(@len){
84
+ &[ntype="@{len}"] {
85
+ @w: @len/2+1.4;
86
+ >[nlist] {
87
+ width: @{w}em;
88
+ }
89
+ }
90
+ }
91
+ @type(1)
92
+ `, '');
93
+ Program.debug = false;
94
+ common.createString.debug = false;
81
95
  assert(素馨(`:not(a):not(b){c:d}`, 'abc'), `abc :not(a):not(b){c:d;}`);
82
96
  assert(素馨(`&:not(a):not(b){c:d}`, 'abc'), `abc:not(a):not(b){c:d;}`);
83
97
  assert(素馨(`:scope{&:not(a):not(b){c:d}}`, 'abc'), `abc:not(a):not(b){c:d;}`);
@@ -43,7 +43,7 @@
43
43
  <i18n-chooser></i18n-chooser>
44
44
  <script>
45
45
 
46
- var hosts = data.getItem("hosts");
46
+ var hosts = data.getInstance("hosts");
47
47
  if (!hosts.length) hosts.push({ key: location.host, name: location.host });
48
48
  function main(host) {
49
49
  var fields = refilm`
@@ -36,12 +36,17 @@ var replaceArg = function (arg) {
36
36
  function build(func, argNames, argsArr) {
37
37
  var newf = String(func).replace(regexps, rep);
38
38
  return Function.apply(null, argNames.map(replaceArg).concat("return " + newf))
39
- .apply(this, argsArr.map(replaceArg));
39
+ .apply(this, replaceArg(argsArr));
40
40
  }
41
41
  var arriswise = function (func, args = []) {
42
42
  if (isFunction(args.slice)) {
43
43
  // 兼容老方法
44
- return build.call(arguments[2] || this, func, args.slice(0, args.length >> 1), args.slice(args.length >> 1));
44
+ var argArr = args.slice(args.length - 3 >>> 1);
45
+ argArr.splice(argArr.length - 3, 2);
46
+ return build.call(arguments[2] || this, func,
47
+ args.slice(0, args.length - 3 >>> 1),
48
+ argArr,
49
+ );
45
50
  }
46
51
  var allArgumentsNames = args[args.length - 1];
47
52
  return build.call(this, func, allArgumentsNames, [].slice.call(args, 0));
@@ -141,7 +141,6 @@ var getGenerator = function (container, tagName = 'item', wrapItem = false) {
141
141
  if (childNodes.length > 1) element.with = Array.prototype.slice.call(childNodes, 1);
142
142
  }
143
143
  var newScope = createScope(container, index, com, wrapItem);
144
- element.$renders = [update.bind(container, newScope, index, wrapItem)];
145
144
  var newItem = render(element, newScope, scopes, false);
146
145
  if (element.with) newItem.with = render(element.with, newScope, scopes, false);
147
146
  return newItem;