efront 3.36.1 → 3.36.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.
@@ -503,7 +503,7 @@ var directives = {
503
503
  }),
504
504
  src(src) {
505
505
  var parsedSrc = this.$src;
506
- return src2.call(this, parsedSrc ? parsedSrc.srcName : src);
506
+ return src2.call(this, parsedSrc && /[\{\[\s]/.test(src) ? parsedSrc.srcName : src);
507
507
  },
508
508
  model(search, target) {
509
509
  var getter = createGetter(this, search);
@@ -2,7 +2,7 @@
2
2
 
3
3
  var fs = require("fs").promises;
4
4
  var path = require("path");
5
- var comm_file_reg = /\.([tj]sx?|xht|md|less)$/i;
5
+ var comm_file_reg = /\.([tj]sx?|xht|md|less|html)$/i;
6
6
  var basepath = path.join(String(__efront), 'coms');
7
7
  if (req.id) {
8
8
  var compath = path.join(basepath, req.id);
package/docs/main.xht CHANGED
@@ -150,7 +150,13 @@
150
150
  var map = Object.create(null);
151
151
  var children = [];
152
152
  for (var a of c.children) {
153
- if (!/\.([jt]sx?|xht)$/i.test(a) || /_test\.([tj]sx?|xht)$/i.test(a)) {
153
+ if (/_test\.([tj]sx?|xht|html|less|md)$/i.test(a)) {
154
+ var testName = a.replace(/\.\w+$/g, '');
155
+ if (!map[testName]) map[testName] = [];
156
+ map[testName].push(a);
157
+ continue;
158
+ }
159
+ else if (!/\.([jt]sx?|xht)$/i.test(a)) {
154
160
  map[a.replace(/\.\w+$/g, a => a.toLowerCase())] = a;
155
161
  continue;
156
162
  }
@@ -159,7 +165,7 @@
159
165
  for (var cc of children) {
160
166
  cc.data = {
161
167
  mark: !!map[cc.name.replace(/\.[tj]sx?$/i, ".md")],
162
- test: !!map[cc.name.replace(/\.[tj]sx?$/i, "_test.js")],
168
+ test: map[cc.name.replace(/\.[tj]sx?$/i, "_test")],
163
169
  less: !!map[cc.name.replace(/\.[tj]sx?$/i, ".less")]
164
170
  }
165
171
  if (cc.data.less) cc.name += "<f less></f>"
package/docs/mark.xht CHANGED
@@ -55,86 +55,6 @@
55
55
  border: 1.2px solid #0007;
56
56
  }
57
57
 
58
- code {
59
- padding: 10px 20px;
60
- border-radius: 3px;
61
- display: inline-block;
62
- background: #333;
63
- color: #d4d4d4;
64
- vertical-align: top;
65
- }
66
-
67
- strap,
68
- value {
69
- color: #569cd6;
70
- }
71
-
72
- regexp {
73
- color: #d16969;
74
- }
75
-
76
- text {
77
- color: #ce9178;
78
- }
79
-
80
- flow {
81
- color: #c586c0;
82
- }
83
-
84
- digit {
85
- color: #b5cea8;
86
- }
87
-
88
- label {
89
- color: #569cd6;
90
- }
91
-
92
- @deep(@num, @color) {
93
- deep@num {
94
- color: @color;
95
- }
96
- }
97
-
98
- @deep(0, #ffd700);
99
- @deep(1, #da70d6);
100
- @deep(2, #179fff);
101
- @deep(3, #ffd700);
102
- @deep(4, #da70d6);
103
- @deep(5, #179fff);
104
- @deep(6, #ffd700);
105
- @deep(7, #da70d6);
106
- @deep(8, #179fff);
107
- @deep(9, #ffd700);
108
- @deep(10, #da70d6);
109
- @deep(11, #179fff);
110
- @deep(12, #ffd700);
111
- @deep(13, #da70d6);
112
- @deep(14, #179fff);
113
- @deep(15, #ffd700);
114
- @deep(16, #da70d6);
115
- @deep(17, #179fff);
116
-
117
- express,
118
- property {
119
- color: #9cdcfe;
120
- }
121
-
122
- invoke,
123
- method {
124
- color: #dcdcaa;
125
- }
126
-
127
- predef {
128
- color: #4ec9b0;
129
- }
130
-
131
- outside {
132
- color: #4fc1ff;
133
- }
134
-
135
- comment {
136
- color: #6a9955;
137
- }
138
58
  </style>
139
59
  <script>
140
60
  var history = [];
@@ -325,22 +325,23 @@
325
325
  { name: "斯洛文尼亚语", id: "slo", lang: 'sl' },
326
326
  ];
327
327
  supports.forEach(s => s.key = s.id);
328
- var getAllText = function (data, e) {
328
+ var getAllText = function (data, f) {
329
329
  try {
330
- if (/^\s*<!doctype\s/i.test(data)) return [];
331
- if (/\.(xht|vue)$/i.test(e.name)) {
330
+ if (/^\s*(\<\!--[\s\S]*?--\>\s*)*<!doctype\s/i.test(data)) return [];
331
+ if (/\.(xht|vue)$/i.test(f.name)) {
332
332
  var { scripts, outerHTML: htmltext, attributes = '', tagName, styles } = compile$scanner2(data, 'html').scoped;
333
333
  data = compile$wraphtml(htmltext) + ";\r\n" + scripts.join("\r\n");
334
334
  }
335
- else if (/\.html?$/i.test(e.name)) {
335
+ else if (/\.html?$/i.test(f.name)) {
336
336
  data = compile$wraphtml(data);
337
337
  }
338
338
  var code = compile$scanner2(String(data));
339
339
  return compile$translate.getI18nPrefixed(code);
340
340
  }
341
341
  catch (e) {
342
- alert("提取出错了", "error");
343
- throw e;
342
+ alert("提取文本时存在异常", "error");
343
+ console.error(e, f.path);
344
+ return [];
344
345
  }
345
346
  };
346
347
  var 已找到的字符串 = [];
@@ -523,7 +524,7 @@
523
524
  var liang = 0, fanyi = {};
524
525
  for (var { lang: k, id } of supports) {
525
526
  if (!d[k]) continue;
526
- if (preMap[d[k]]) continue loop;
527
+ if (preMap[d[k]] && preMap[d[k]] !== d) continue loop;
527
528
  preMap[d[k]] = d;
528
529
  liang++;
529
530
  fanyi[id] = d[k];
@@ -1,8 +1,26 @@
1
1
  <style>
2
2
  :scope {
3
3
  line-height: 1.2;
4
- padding: 0 20px;
5
4
  display: block;
5
+ height: 100%;
6
+ width: 100%;
7
+ }
8
+
9
+ xmenu {
10
+ z-index: 2;
11
+ }
12
+
13
+ [body] {
14
+ border-top: 42px solid transparent;
15
+ margin-top: -82px;
16
+ padding-top: 40px;
17
+ padding-bottom: 0 !important;
18
+ border-bottom: 46px solid transparent;
19
+ }
20
+
21
+ textarea {
22
+ outline: none;
23
+ white-space: nowrap;
6
24
  }
7
25
 
8
26
  p4 {
@@ -11,7 +29,7 @@
11
29
  margin: 20px 0;
12
30
  }
13
31
 
14
- p4 m{
32
+ p4 m {
15
33
  line-height: 1.2;
16
34
  display: inline-block;
17
35
  margin-right: 6px;
@@ -48,32 +66,73 @@
48
66
  padding: 2px 4px;
49
67
  }
50
68
 
69
+ [codearea] {
70
+ width: 100%;
71
+ height: 100%;
72
+ }
73
+
74
+ [codearea]>code {
75
+ overflow: auto;
76
+ width: 100%;
77
+ height: 100%;
78
+ padding-bottom: 600px;
79
+ white-space: nowrap;
80
+ }
81
+
51
82
  markdown {
52
- margin: 0 -20px;
83
+ margin: -6px -20px 0 -10px;
84
+ }
85
+
86
+ button {
87
+ padding: 0 20px;
88
+ }
89
+
90
+ .result {
91
+ position: absolute;
92
+ bottom: 0;
93
+ right: 0;
94
+ left: 0;
95
+ padding: 10px 20px;
96
+ border-top: 1px solid #333;
97
+ background: #fff;
98
+ display: block;
99
+ z-index: 1;
53
100
  }
54
101
  </style>
55
- <h2>
102
+ <xmenu -src="(t,i) in tags" @active="saveTagIndex(i)"></xmenu>
103
+ <h2 head>
56
104
  <span -bind="name"></span>
57
105
  <b -if="doc?.less" l>有样式表</b>
58
106
  <b -if="doc?.mark" w>有文档</b>
59
107
  <b -if="doc?.test" t>有测试代码</b>
60
108
  </h2>
61
- <container -if="doc?.url" .src="doc.url">
62
- </container>
63
- <p4 envs>
64
- <span -if="envs?.length">
65
- 环境依赖项:&nbsp; <m -repeat="c in envs" -bind="c"> </m>
66
- </span>
67
- <span -else> 无环境依赖项 </span>
68
- </p4>
69
- <p4 imported>
70
- <span -if="required?.length">
71
- 导入项:&nbsp;<m -repeat="c in required" -bind="c"></m>
72
- </span>
73
- <span -else>
74
- 无导入项
75
- </span>
76
- </p4>
109
+ <div body -if="tags[0].actived">
110
+ <container -if="doc?.url" .src="doc.url">
111
+ </container>
112
+ <p4 envs>
113
+ <span -if="envs?.length">
114
+ 环境依赖项:&nbsp; <m -repeat="c in envs" -bind="c"> </m>
115
+ </span>
116
+ <span -else> 无环境依赖项 </span>
117
+ </p4>
118
+ <p4 imported>
119
+ <span -if="required?.length">
120
+ 导入项:&nbsp;<m -repeat="c in required" -bind="c"></m>
121
+ </span>
122
+ <span -else>
123
+ 无导入项
124
+ </span>
125
+ </p4>
126
+ </div>
127
+ <div body -elseif="tags[1].actived">
128
+ <div codearea #coder onkeyup="updatecode()"></div>
129
+ <resultpad .result #coderesult></resultpad>
130
+ </div>
131
+ <div foot -if="tags[1].actived">
132
+ <a -if="doc?.test" @click="clearpad()">清理</a>
133
+ <a -if="doc?.test" @click="loadcode()">载入测试代码</a>
134
+ <btn @click="execute()">运行</btn>
135
+ </div>
77
136
  <script>
78
137
  var 分析 = lazy(async function (com, props) {
79
138
  if (props.mark) props.url = '/mark/coms/' + com.replace(/\.js$/i, '.md');
@@ -97,11 +156,178 @@
97
156
  scope.required = required;
98
157
  scope.envs = Object.keys(envs);
99
158
  render.refresh();
159
+ if (tags[1].actived) loadcode();
160
+ });
161
+ var loadcode = async function () {
162
+ var modName = scope.name.replace(/\.js$/, '_test');
163
+ if (scope.doc.test) {
164
+ var xhr = await cross('get', "./components:" + modName + '.js');
165
+ var codetext = xhr.responseText;
166
+ var code = compile$scanner2(codetext);
167
+ var envs = code.envs;
168
+ var vars = code.vars;
169
+ var commName = modName.replace(/^[\s\S]*\//, '');
170
+ var lessName = commName + ".less", lessData;
171
+ var cssWrap = `css-` + +new Date;
172
+ if (scope.doc.test.indexOf(lessName) >= 0) {
173
+ lessData = await cross("get", "./components:" + modName + ".less");
174
+ lessData = compile$richcss(lessData.responseText, "." + cssWrap);
175
+ if (code.isExpressQueue()) {
176
+ codetext = `return cless(${codetext},\`${lessData}\`,"${cssWrap}")`;
177
+ }
178
+ else {
179
+ var entryName;
180
+ if (vars.main) entryName = "main";
181
+ else if (vars.Main) entryName = 'Main';
182
+ else if (vars.MAIN) entryName = "MAIN";
183
+ else if (vars[commName]) entryName = commName;
184
+ if (entryName) codetext += `\r\nreturn cless(${entryName},\`${lessData}\`,"${cssWrap}")`;
185
+ }
186
+ }
187
+ else {
188
+ if (code.isExpressQueue()) codetext = "return " + codetext;
189
+ else if (vars.main) codetext += '\r\nreturn main';
190
+ else if (vars.Main) codetext += '\r\nreturn Main';
191
+ else if (vars.MAIN) codetext += "\r\nreturn MAIN";
192
+ else if (vars[modName]) codetext += "\r\nreturn " + modName;
193
+ }
194
+ var templateName = commName;
195
+ if (envs.template) templateName = 'template';
196
+ if (envs[templateName]) {
197
+ delete envs[templateName];
198
+ var template = await cross("get", './components:' + modName + ".html");
199
+ codetext = `var ${templateName}={toString(){return \`${template.responseText}\`}};\r\n` + codetext;
200
+ }
201
+ initcode(codetext);
202
+ }
203
+ else {
204
+ initcode('');
205
+ }
206
+ scope.codetext = scope.coder.innerText;
207
+ execute();
208
+ };
209
+
210
+ var getAnchorOffset = function () {
211
+ var { anchorNode, anchorOffset } = document.getSelection();
212
+ var [c] = scope.coder.children;
213
+ if (anchorNode === c || !anchorNode) return -anchorOffset;
214
+ var sibling = anchorNode.previousSibling ? anchorNode.previousSibling : anchorNode.parentNode.previousSibling;
215
+ while (sibling && sibling !== c) {
216
+ switch (sibling.nodeType) {
217
+ case 1:
218
+ anchorOffset += sibling.innerText.length || 1;
219
+ break;
220
+ case 3:
221
+ anchorOffset += sibling.nodeValue.length;
222
+ break;
223
+ }
224
+ sibling = sibling.previousSibling ? sibling.previousSibling : sibling.parentNode.previousSibling;
225
+ }
226
+ return anchorOffset;
227
+ };
228
+ var setAnchorOffset = function (anchorOffset) {
229
+ var [c] = scope.coder.children;
230
+ if (anchorOffset < 0) {
231
+ anchorOffset = -anchorOffset;
232
+ if (anchorOffset > c.childNodes.length) anchorOffset = c.childNodes.length;
233
+ return document.getSelection().setBaseAndExtent(c, anchorOffset, c, anchorOffset);
234
+ }
235
+ var offset = anchorOffset;
236
+ var child = c.firstChild;
237
+ while (child) {
238
+ var delta = 0;
239
+ switch (child.nodeType) {
240
+ case 1:
241
+ delta = child.innerText.length || 1;
242
+ break;
243
+ case 3:
244
+ delta = child.nodeValue.length;
245
+ break;
246
+ }
247
+ if (delta >= offset) {
248
+ if (child.nodeType === 1) {
249
+ child = child.firstChild;
250
+ continue;
251
+ }
252
+ break;
253
+ }
254
+ offset -= delta;
255
+ if (offset <= 0) break;
256
+ child = child.nextSibling;
257
+ }
258
+ if (!child) child = c, offset = c.childNodes.length;
259
+ return document.getSelection().setBaseAndExtent(child, offset, child, offset);
260
+ }
261
+ var initcode = function (innerText) {
262
+ var colored = codetext("js", innerText);
263
+ var offset = getAnchorOffset();
264
+ var innerHTML = scope.coder.innerHTML.replace(/\s*contenteditable\=[^\s\>]+/i, '');
265
+ if (innerHTML === colored) return;
266
+ var [c0] = scope.coder.children;
267
+ var nodesCount = c0 ? c0.childNodes.length : 0;
268
+ scope.coder.innerHTML = colored;
269
+ var [c] = scope.coder.children;
270
+ if (nodesCount < c.childNodes.length) {
271
+ if (offset < 0) offset--;
272
+ else if (offset > 0) offset++;
273
+ }
274
+ c.contentEditable = true;
275
+ setAnchorOffset(offset);
276
+ };
277
+ var updatecode = lazy(function (event) {
278
+ var innerText = scope.coder.innerText;
279
+ if (scope.codetext.replace(/[\s\u00a0]+/g, ' ').trim() === innerText.replace(/[\s\u00a0]+/g, ' ').trim()) return;
280
+ initcode(innerText);
281
+ scope.codetext = scope.coder.innerText;
100
282
  });
101
- var page = document.createElement("component");
283
+ var execute = async function () {
284
+ try {
285
+ remove(scope.coderesult.childNodes);
286
+ var codetext = scope.codetext.replace(/[\u2002\u00a0]/g, ' ');
287
+ data.patchInstance("docscode", { codetext: codetext })
288
+ var code = compile$scanner2(codetext);
289
+ var envs = code.envs;
290
+ var argNames = Object.keys(envs);
291
+ var args = await Promise.all(argNames.map(a => init(a)));
292
+ var func = createFunction("", codetext, argNames, code.async, code.yield);
293
+ var res = func.apply(window, args);
294
+ if (isFunction(res)) {
295
+ res = res.call(res);
296
+ }
297
+ if (isElement(res) || isArray(res)) {
298
+ appendChild(scope.coderesult, res);
299
+ }
300
+ } catch (e) {
301
+ alert(String(e), 'error');
302
+ }
303
+ };
304
+ var tags = [
305
+ { name: "简介" },
306
+ { name: "试试" }
307
+ ];
308
+ tags[data.getInstance("docscode").tagIndex | 0].actived = true;
309
+ var actived = tags.map(t => t.actived);
310
+ var xmenu = menu;
311
+ var page = view();
102
312
  page.innerHTML = template;
103
313
  var scope = {
314
+ btn: button,
104
315
  container,
316
+ view,
317
+ tags,
318
+ a: button,
319
+ codetext: "",
320
+ xmenu: menu,
321
+ loadcode,
322
+ clearpad() {
323
+ remove(this.coderesult.childNodes);
324
+ },
325
+ execute,
326
+ updatecode,
327
+ saveTagIndex(i) {
328
+ data.setInstance("docscode", { tagIndex: i });
329
+ if (i === 1 && !scope.codetext) loadcode();
330
+ },
105
331
  };
106
332
  render(page, scope);
107
333
  function main(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.36.1",
3
+ "version": "3.36.3",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {