efront 3.36.2 → 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.
@@ -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.2",
3
+ "version": "3.36.3",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {