efront 3.36.2 → 3.36.5

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,17 +1,31 @@
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;
6
11
  }
7
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
+
8
22
  p4 {
9
23
  line-height: 1.8;
10
24
  display: block;
11
25
  margin: 20px 0;
12
26
  }
13
27
 
14
- p4 m{
28
+ p4 m {
15
29
  line-height: 1.2;
16
30
  display: inline-block;
17
31
  margin-right: 6px;
@@ -48,33 +62,107 @@
48
62
  padding: 2px 4px;
49
63
  }
50
64
 
65
+ [codearea] {
66
+ width: 100%;
67
+ height: 100%;
68
+ }
69
+
70
+ [codearea]>code {
71
+ overflow: auto;
72
+ width: 100%;
73
+ height: 100%;
74
+ padding: 10px 20px 600px 20px;
75
+ white-space: nowrap;
76
+ outline: none;
77
+ }
78
+
51
79
  markdown {
52
- margin: 0 -20px;
80
+ margin: -6px -20px 0 -10px;
81
+ }
82
+
83
+ [foot]>button {
84
+ padding: 0 20px;
85
+ }
86
+
87
+ .result {
88
+ position: absolute;
89
+ bottom: 0;
90
+ right: 0;
91
+ left: 0;
92
+ padding: 10px 20px;
93
+ border-top: 1px solid #333;
94
+ background: #fff;
95
+ display: block;
96
+ z-index: 1;
53
97
  }
54
98
  </style>
55
- <h2>
99
+ <xmenu -src="(t,i) in tags" @active="saveTagIndex(i)"></xmenu>
100
+ <h2 head>
56
101
  <span -bind="name"></span>
57
102
  <b -if="doc?.less" l>有样式表</b>
58
103
  <b -if="doc?.mark" w>有文档</b>
59
104
  <b -if="doc?.test" t>有测试代码</b>
60
105
  </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>
106
+ <div body -if="tags[0].actived">
107
+ <container -if="doc?.url" .src="doc.url">
108
+ </container>
109
+ <p4 envs>
110
+ <span -if="envs?.length">
111
+ 环境依赖项:&nbsp; <m -repeat="c in envs" -bind="c"> </m>
112
+ </span>
113
+ <span -else> 无环境依赖项 </span>
114
+ </p4>
115
+ <p4 imported>
116
+ <span -if="required?.length">
117
+ 导入项:&nbsp;<m -repeat="c in required" -bind="c"></m>
118
+ </span>
119
+ <span -else>
120
+ 无导入项
121
+ </span>
122
+ </p4>
123
+ </div>
124
+ <div body -elseif="tags[1].actived">
125
+ <div codearea #coder onkeyup="!event.isComposing&&updatecode()" onkeydown.tab="keytab(event)"></div>
126
+ <resultpad .result #coderesult></resultpad>
127
+ </div>
128
+ <div foot -if="tags[1].actived">
129
+ <a -if="doc?.test" @click="clearpad()">清理</a>
130
+ <a -if="doc?.test" @click="loadcode()">载入测试代码</a>
131
+ <btn @click="execute()">运行</btn>
132
+ </div>
77
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
+ });
78
166
  var 分析 = lazy(async function (com, props) {
79
167
  if (props.mark) props.url = '/mark/coms/' + com.replace(/\.js$/i, '.md');
80
168
  scope.doc = props;
@@ -97,11 +185,231 @@
97
185
  scope.required = required;
98
186
  scope.envs = Object.keys(envs);
99
187
  render.refresh();
188
+ if (tags[1].actived) loadcode();
100
189
  });
101
- var page = document.createElement("component");
190
+ var loadcode = async function () {
191
+ var modName = scope.name.replace(/\.js$/, '_test');
192
+ if (scope.doc.test) {
193
+ var xhr = await cross('get', "./components:" + modName + '.js');
194
+ var codetext = xhr.responseText;
195
+ var code = compile$scanner2(codetext);
196
+ var envs = code.envs;
197
+ var vars = code.vars;
198
+ var commName = modName.replace(/^[\s\S]*\//, '');
199
+ var lessName = commName + ".less", lessData;
200
+ var cssWrap = `css-` + +new Date;
201
+ if (scope.doc.test.indexOf(lessName) >= 0) {
202
+ lessData = await cross("get", "./components:" + modName + ".less");
203
+ lessData = compile$richcss(lessData.responseText, "." + cssWrap);
204
+ if (code.isExpressQueue()) {
205
+ codetext = `return cless(${codetext},\`${lessData}\`,"${cssWrap}")`;
206
+ }
207
+ else {
208
+ var entryName;
209
+ if (vars.main) entryName = "main";
210
+ else if (vars.Main) entryName = 'Main';
211
+ else if (vars.MAIN) entryName = "MAIN";
212
+ else if (vars[commName]) entryName = commName;
213
+ if (entryName) codetext += `\r\nreturn cless(${entryName},\`${lessData}\`,"${cssWrap}")`;
214
+ }
215
+ }
216
+ else {
217
+ if (code.isExpressQueue()) codetext = "return " + codetext;
218
+ else if (vars.main) codetext += '\r\nreturn main';
219
+ else if (vars.Main) codetext += '\r\nreturn Main';
220
+ else if (vars.MAIN) codetext += "\r\nreturn MAIN";
221
+ else if (vars[modName]) codetext += "\r\nreturn " + modName;
222
+ }
223
+ var templateName = commName;
224
+ if (envs.template) templateName = 'template';
225
+ if (envs[templateName]) {
226
+ delete envs[templateName];
227
+ var template = await cross("get", './components:' + modName + ".html");
228
+ codetext = `var ${templateName}={toString(){return \`${template.responseText}\`}};\r\n` + codetext;
229
+ }
230
+ initcode(codetext);
231
+ }
232
+ else {
233
+ initcode('');
234
+ }
235
+ scope.codetext = scope.coder.innerText;
236
+ execute();
237
+ };
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
+ }
275
+ var getAnchorOffset = function () {
276
+ var { anchorNode, anchorOffset } = document.getSelection();
277
+ var [c] = scope.coder.children;
278
+ if (anchorNode === c || !anchorNode) return -anchorOffset;
279
+ var sibling = anchorNode.previousSibling ? anchorNode.previousSibling : anchorNode.parentNode.previousSibling;
280
+ while (sibling && sibling !== c) {
281
+ switch (sibling.nodeType) {
282
+ case 1:
283
+ anchorOffset += sibling.innerText.length || 1;
284
+ break;
285
+ case 3:
286
+ anchorOffset += sibling.nodeValue.length;
287
+ break;
288
+ }
289
+ sibling = sibling.previousSibling ? sibling.previousSibling : sibling.parentNode.previousSibling;
290
+ }
291
+ return anchorOffset;
292
+ };
293
+ var setAnchorOffset = function (anchorOffset) {
294
+ var [c] = scope.coder.children;
295
+ if (anchorOffset < 0) {
296
+ anchorOffset = -anchorOffset;
297
+ if (anchorOffset > c.childNodes.length) anchorOffset = c.childNodes.length;
298
+ return document.getSelection().setBaseAndExtent(c, anchorOffset, c, anchorOffset);
299
+ }
300
+ var offset = anchorOffset;
301
+ var child = c.firstChild;
302
+ while (child) {
303
+ var delta = 0;
304
+ switch (child.nodeType) {
305
+ case 1:
306
+ delta = child.innerText.length || 1;
307
+ break;
308
+ case 3:
309
+ delta = child.nodeValue.length;
310
+ break;
311
+ }
312
+ if (delta >= offset) {
313
+ if (child.nodeType === 1) {
314
+ if (child.firstChild) {
315
+ child = child.firstChild;
316
+ continue;
317
+ }
318
+ offset -= 1;
319
+ break;
320
+ }
321
+ break;
322
+ }
323
+ offset -= delta;
324
+ if (offset <= 0) break;
325
+ child = child.nextSibling;
326
+ }
327
+ if (!child) child = c, offset = c.childNodes.length;
328
+ return document.getSelection().setBaseAndExtent(child, offset, child, offset);
329
+ }
330
+ var initcode = function (innerText) {
331
+ try {
332
+ var colored = codetext("js", innerText, blink);
333
+ } catch { return; }
334
+ var innerHTML = scope.coder.innerHTML.replace(/\s*contenteditable\=[^\s\>]+/i, '');
335
+ if (innerHTML === colored) return;
336
+ var [c0] = scope.coder.children;
337
+ var contentLength = c0 ? innerText.length : 0;
338
+ var scrollTop = c0 ? c0.scrollTop : 0;
339
+ var scrollLeft = c0 ? c0.scrollLeft : 0;
340
+ scope.coder.innerHTML = colored;
341
+ var [c] = scope.coder.children;
342
+ c.scrollTop = scrollTop;
343
+ c.scrollLeft = scrollLeft;
344
+ c.contentEditable = true;
345
+ };
346
+ var updatecode = lazy(function () {
347
+ markAnchorOffset();
348
+ var innerText = scope.coder.innerText;
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;
353
+ initcode(innerText);
354
+ unmarkAnchorOffset();
355
+ scope.codetext = scope.coder.innerText;
356
+ });
357
+ var execute = async function () {
358
+ try {
359
+ var live = /^([\s\S]+)\//.exec(scope.name);
360
+ if (live) live = live[1];
361
+ var commap = initCommap(live);
362
+ remove(scope.coderesult.childNodes);
363
+ var codetext = scope.codetext.replace(/[\u2002\u00a0]/g, ' ');
364
+ data.patchInstance("docscode", { codetext: codetext })
365
+ var code = compile$scanner2(codetext);
366
+ var envs = code.envs;
367
+ var argNames = Object.keys(envs);
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 })));
369
+ var func = createFunction("", codetext, argNames, code.async, code.yield);
370
+ var res = func.apply(window, args);
371
+ if (isFunction(res)) {
372
+ res = res.call(res);
373
+ }
374
+ if (isElement(res) || isArray(res)) {
375
+ appendChild(scope.coderesult, res);
376
+ }
377
+ } catch (e) {
378
+ alert(String(e), 'error');
379
+ throw e;
380
+ }
381
+ };
382
+ var tags = [
383
+ { name: "简介" },
384
+ { name: "试试" }
385
+ ];
386
+ tags[data.getInstance("docscode").tagIndex | 0].actived = true;
387
+ var actived = tags.map(t => t.actived);
388
+ var xmenu = menu;
389
+ var page = view();
390
+ on("submit")(page, e => e.preventDefault());
102
391
  page.innerHTML = template;
103
392
  var scope = {
393
+ btn: button,
104
394
  container,
395
+ view,
396
+ tags,
397
+ a: button,
398
+ codetext: "",
399
+ xmenu: menu,
400
+ loadcode,
401
+ clearpad() {
402
+ remove(this.coderesult.childNodes);
403
+ },
404
+ execute,
405
+ updatecode,
406
+ saveTagIndex(i) {
407
+ data.setInstance("docscode", { tagIndex: i });
408
+ if (i === 1 && !scope.codetext) requestAnimationFrame(loadcode);
409
+ },
410
+ keytab(event) {
411
+ event.preventDefault();
412
+ }
105
413
  };
106
414
  render(page, scope);
107
415
  function main(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.36.2",
3
+ "version": "3.36.5",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {