efront 4.11.2 → 4.11.4
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.
- package/coms/basic/assert.js +5 -3
- package/coms/compile/Html_test.js +1 -0
- package/coms/compile/Javascript.js +5 -1
- package/coms/compile/Javascript_test.js +14 -2
- package/coms/compile/Program.js +6 -3
- package/coms/compile/common.js +1 -1
- package/coms/docs/markdown.js +5 -3
- package/coms/frame/route.js +15 -15
- package/coms/zimoli/render.js +45 -61
- package/coms/zimoli/view.less +0 -1
- package/coms//350/214/250/350/217/260/tab.js +34 -0
- package/coms//350/214/250/350/217/260//344/270/212/350/211/262.xht +99 -0
- package/coms//350/214/250/350/217/260//345/205/211/346/240/207.js +1 -0
- package/coms//350/214/250/350/217/260//346/211/253/346/217/217.js +12 -0
- package/coms/{docs/codecolor.js → /350/214/250/350/217/260//346/240/207/347/255/276/345/214/226.js} +2 -1
- package/coms//350/214/250/350/217/260//346/270/262/346/237/223.js +45 -0
- package/coms//350/214/250/350/217/260//347/274/226/350/276/221/346/241/206.xht +132 -0
- package/coms//350/214/250/350/217/260//350/257/255/350/250/200.js +210 -0
- package/coms//350/214/250/350/217/260//350/277/275/345/212/240/345/205/211/346/240/207.js +62 -0
- package/docs//347/273/204/344/273/266.xht +8 -162
- package/package.json +1 -1
- package/public/efront.js +1 -1
- package/coms/docs/codetext.xht +0 -386
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<编辑框 e-class="上色.className" e-style="{whiteSpace:'pre'}" onkeyup="!event.isComposing&&updatecode(event)"
|
|
2
|
+
onkeydown.tab="keytab(event)" onkeyup.enter="tab(false)">
|
|
3
|
+
</编辑框>
|
|
4
|
+
<script>
|
|
5
|
+
var coder = this;
|
|
6
|
+
care(coder, function ([text, type]) {
|
|
7
|
+
try {
|
|
8
|
+
var colored = 上色.text(type, text);
|
|
9
|
+
coder.innerHTML = colored;
|
|
10
|
+
coder.type = type;
|
|
11
|
+
} catch {
|
|
12
|
+
if (typeof text === 'string') coder.innerHTML = 渲染.encode(text);
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
var markAnchorOffset = function () {
|
|
16
|
+
var { anchorNode, anchorOffset } = document.getSelection();
|
|
17
|
+
if (!anchorNode || !coder) return;
|
|
18
|
+
var [c] = coder.children;
|
|
19
|
+
if (anchorNode.nodeType === 1) {
|
|
20
|
+
var node = document.createTextNode(光标);
|
|
21
|
+
anchorNode.insertBefore(node, anchorNode.childNodes[anchorOffset])
|
|
22
|
+
}
|
|
23
|
+
else if (anchorNode.nodeType === 3) {
|
|
24
|
+
anchorNode.nodeValue = anchorNode.nodeValue.slice(0, anchorOffset) + 光标 + anchorNode.nodeValue.slice(anchorOffset);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var unmarkAnchorOffset = function () {
|
|
28
|
+
var c = coder;
|
|
29
|
+
var node = c.firstChild;
|
|
30
|
+
while (node) {
|
|
31
|
+
if (node.nodeType === 1) {
|
|
32
|
+
if (node.innerText.indexOf(光标) >= 0) {
|
|
33
|
+
node = node.firstChild;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (node.nodeType === 3) {
|
|
38
|
+
if (node.nodeValue.indexOf(光标) >= 0) break;
|
|
39
|
+
}
|
|
40
|
+
node = node.nextSibling;
|
|
41
|
+
}
|
|
42
|
+
if (node) {
|
|
43
|
+
var offset = node.nodeValue.indexOf(光标);
|
|
44
|
+
node.nodeValue = node.nodeValue.slice(0, offset) + node.nodeValue.slice(offset + 1);
|
|
45
|
+
document.getSelection().setBaseAndExtent(node, offset, node, offset);
|
|
46
|
+
if (!node.nodeValue) {
|
|
47
|
+
remove(node);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
var getAnchorOffset = function () {
|
|
52
|
+
var { anchorNode, anchorOffset } = document.getSelection();
|
|
53
|
+
var [c] = coder.children;
|
|
54
|
+
if (anchorNode === c || !anchorNode) return -anchorOffset;
|
|
55
|
+
var sibling = anchorNode.previousSibling ? anchorNode.previousSibling : anchorNode.parentNode.previousSibling;
|
|
56
|
+
while (sibling && sibling !== c) {
|
|
57
|
+
switch (sibling.nodeType) {
|
|
58
|
+
case 1:
|
|
59
|
+
anchorOffset += sibling.innerText.length || 1;
|
|
60
|
+
break;
|
|
61
|
+
case 3:
|
|
62
|
+
anchorOffset += sibling.nodeValue.length;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
sibling = sibling.previousSibling ? sibling.previousSibling : sibling.parentNode.previousSibling;
|
|
66
|
+
}
|
|
67
|
+
return anchorOffset;
|
|
68
|
+
};
|
|
69
|
+
var setAnchorOffset = function (anchorOffset) {
|
|
70
|
+
var [c] = coder.children;
|
|
71
|
+
if (anchorOffset < 0) {
|
|
72
|
+
anchorOffset = -anchorOffset;
|
|
73
|
+
if (anchorOffset > c.childNodes.length) anchorOffset = c.childNodes.length;
|
|
74
|
+
return document.getSelection().setBaseAndExtent(c, anchorOffset, c, anchorOffset);
|
|
75
|
+
}
|
|
76
|
+
var offset = anchorOffset;
|
|
77
|
+
var child = c.firstChild;
|
|
78
|
+
while (child) {
|
|
79
|
+
var delta = 0;
|
|
80
|
+
switch (child.nodeType) {
|
|
81
|
+
case 1:
|
|
82
|
+
delta = child.innerText.length || 1;
|
|
83
|
+
break;
|
|
84
|
+
case 3:
|
|
85
|
+
delta = child.nodeValue.length;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (delta >= offset) {
|
|
89
|
+
if (child.nodeType === 1) {
|
|
90
|
+
if (child.firstChild) {
|
|
91
|
+
child = child.firstChild;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
offset -= 1;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
offset -= delta;
|
|
100
|
+
if (offset <= 0) break;
|
|
101
|
+
child = child.nextSibling;
|
|
102
|
+
}
|
|
103
|
+
if (!child) child = c, offset = c.childNodes.length;
|
|
104
|
+
return document.getSelection().setBaseAndExtent(child, offset, child, offset);
|
|
105
|
+
}
|
|
106
|
+
var trimspace = (_, a) => a ? "" : " ";
|
|
107
|
+
var jstext = "";
|
|
108
|
+
var 更新 = function (colored) {
|
|
109
|
+
var { scrollTop, scrollLeft } = coder;
|
|
110
|
+
coder.innerHTML = colored;
|
|
111
|
+
coder.scrollTop = scrollTop;
|
|
112
|
+
coder.scrollLeft = scrollLeft;
|
|
113
|
+
};
|
|
114
|
+
var updatecode = lazy(function (event) {
|
|
115
|
+
var trimreg = /[\s\u00a0\u2002\u0080]+([\}\{\;\[\]\(\)\,\>\<\+\-\*\&\^\/%!~:?])*/g;
|
|
116
|
+
var innerText = coder.innerText;
|
|
117
|
+
if (jstext.replace(trimreg, trimspace).trim() === innerText.replace(trimreg, trimspace).trim()) return;
|
|
118
|
+
jstext = innerText;
|
|
119
|
+
markAnchorOffset();
|
|
120
|
+
var innerText = coder.innerText;
|
|
121
|
+
unmarkAnchorOffset();
|
|
122
|
+
var text = 上色.text(coder.type, innerText);
|
|
123
|
+
更新(text);
|
|
124
|
+
unmarkAnchorOffset();
|
|
125
|
+
return;
|
|
126
|
+
});
|
|
127
|
+
var keytab = function (event) {
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
tab();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
</script>
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
var { SCOPED, QUOTED, SPACE, STAMP, STRAP, EXPRESS, PROPERTY } = compile$common;
|
|
2
|
+
var asm = new compile$Javascript;
|
|
3
|
+
asm.straps = [
|
|
4
|
+
"include", "includelib",
|
|
5
|
+
"typedef",
|
|
6
|
+
"proto",
|
|
7
|
+
'equ', "and", 'or', 'not', "sizeof",
|
|
8
|
+
"invoke", "offset", 'addr',
|
|
9
|
+
"end", "start",
|
|
10
|
+
"proc", "endp", "uses",
|
|
11
|
+
"macro", 'struct', "ends",
|
|
12
|
+
".if", ".elseif", '.else', '.break', '.endif', '.while', '.endw', "db", 'real4', 'real8', 'dw', 'dd', 'dq', 'byte', 'word', 'dword', 'qword', 'tword', 'dt',
|
|
13
|
+
];
|
|
14
|
+
asm.control_reg = /^\.[\w]+$/;
|
|
15
|
+
asm.stamps = [",", ":", "<", ">", "=", "&", "|", "*", "~", "!", "+", "-", '/'];
|
|
16
|
+
asm.quotes = [
|
|
17
|
+
["'", "'"],
|
|
18
|
+
['"', '"']
|
|
19
|
+
];
|
|
20
|
+
asm.comments = [
|
|
21
|
+
[";", /(?=[\r\n\u2028\u2029])/]
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
var go = new compile$Javascript;
|
|
25
|
+
go.straps = ["var", 'for', 'package', "import", 'type', 'func', 'struct', 'return', 'go', 'const', 'if', 'else', 'switch', 'case', 'default', 'range'];
|
|
26
|
+
go.istype = function (o) {
|
|
27
|
+
var last = o.prev;
|
|
28
|
+
if (!last) return;
|
|
29
|
+
if (last.type === EXPRESS) return true;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
var typescript = new compile$Javascript;
|
|
33
|
+
typescript.straps = typescript.straps.concat(
|
|
34
|
+
"interface", "implements", "declare", "module", "namespace",
|
|
35
|
+
"readonly", "private", "asserts", "is",
|
|
36
|
+
"enum", "type");
|
|
37
|
+
typescript.tags[0].push("{");
|
|
38
|
+
var js = new compile$Javascript;
|
|
39
|
+
js.tags[0].push("{");
|
|
40
|
+
var json = new compile$Javascript;
|
|
41
|
+
json.inExpress = true;
|
|
42
|
+
var gl = new compile$Javascript;
|
|
43
|
+
gl.straps = gl.straps.concat(
|
|
44
|
+
"in", "out", "inout", "uniform", "buffer", "shared",
|
|
45
|
+
"highp", "mediump", "lowp",
|
|
46
|
+
"invariant", "const", "varying", "attribute",
|
|
47
|
+
"sampler2D", "texture2D",
|
|
48
|
+
"sampler3D", "texture3D",
|
|
49
|
+
"coherent", "volatile", "restrict", "readonly", "writeonly",
|
|
50
|
+
"flat", "noperspective", "smooth",
|
|
51
|
+
"packed", "shared", "std140", "std340", "row_major", "colum_major",
|
|
52
|
+
"location", "set", "binding", "offset", "index", "xfb_buffer", "xfb_offset", "local_size",
|
|
53
|
+
"void",
|
|
54
|
+
'require', 'enable', 'disable', 'warn',
|
|
55
|
+
'struct',
|
|
56
|
+
'float', 'int',
|
|
57
|
+
'vec4', 'vec3', 'vec2',
|
|
58
|
+
'mat4', 'mat3', 'mat2',
|
|
59
|
+
'bool', 'const', 'precision',
|
|
60
|
+
"step", "smoothstep",
|
|
61
|
+
"mix", "clamp"
|
|
62
|
+
);
|
|
63
|
+
var rust = new compile$Javascript;
|
|
64
|
+
rust.powermap = Object.assign({}, rust.powermap);
|
|
65
|
+
rust.powermap["->"] = 0;
|
|
66
|
+
rust.straps = ["let", 'use', 'mut', 'fn', 'if', 'else', 'loop', 'while', 'for', 'in', 'break', 'true', 'false', 'struct', 'enum', 'impl', 'self', 'match', 'pub', 'mod', 'trait'];
|
|
67
|
+
var struct_reg = /^(while|do|for|with|switch|case|default|if|else|try|catch|finally|loop|import|export)$/;
|
|
68
|
+
|
|
69
|
+
gl.setType = function (o) {
|
|
70
|
+
var { type } = o;
|
|
71
|
+
var queue = o.queue;
|
|
72
|
+
var last = o.prev;
|
|
73
|
+
if (type & (SCOPED | EXPRESS | PROPERTY)) {
|
|
74
|
+
if (last && last === queue[queue.length - 1] && last.type & (EXPRESS | STRAP | PROPERTY)) {
|
|
75
|
+
last.istype = !struct_reg.test(last.text);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
var 素心 = new compile$素馨.素心;
|
|
80
|
+
素心.scopes.push(['[', ']']);
|
|
81
|
+
素心.straps.push('important',
|
|
82
|
+
'after', 'backdrop', 'before',
|
|
83
|
+
'cue', 'cue-range',
|
|
84
|
+
'file-selector-button', 'first-letter', 'last-letter', 'first-line',
|
|
85
|
+
'grammer-error', 'highlight', 'marker', 'part',
|
|
86
|
+
'placeholder', 'selection', 'slotted', 'spelling-error', 'target-text',
|
|
87
|
+
'view-transition', 'view-transition-group', 'view-transition-image-pair', 'view-transition-new', 'view-transition-old',
|
|
88
|
+
'active', 'any-link', 'autofill',
|
|
89
|
+
'blank',
|
|
90
|
+
'checked', 'current',
|
|
91
|
+
'dir', 'default', 'defined', 'disabled',
|
|
92
|
+
'empty', 'enabled',
|
|
93
|
+
'first', 'first-child', 'first-of-type', 'future', 'focus', 'focus-visible', 'focus-within', 'fullscreen',
|
|
94
|
+
'has', 'host', 'host-context', 'hover',
|
|
95
|
+
'indeterminate', 'in-range', 'invalid', 'is',
|
|
96
|
+
'lang', 'last-child', 'last-of-type', 'left', 'link', 'local-link',
|
|
97
|
+
'modal',
|
|
98
|
+
'not', 'nth-child', 'nth-col', 'nth-last-child', 'nth-last-col', 'nth-last-of-type', 'nth-of-type',
|
|
99
|
+
"only-child", 'only-of-type', 'optional', 'out-of-range',
|
|
100
|
+
'past', 'picture-in-picture', 'placeholder-shown', 'paused', 'playing',
|
|
101
|
+
'read-only', 'read-write', 'required', 'right', 'root',
|
|
102
|
+
'scope', 'state',
|
|
103
|
+
'target', 'target-within',
|
|
104
|
+
'user-invalid',
|
|
105
|
+
'valid', 'visited',
|
|
106
|
+
'where'
|
|
107
|
+
);
|
|
108
|
+
素心.stamps.push("=");
|
|
109
|
+
var setless = function (c) {
|
|
110
|
+
var set = function (o) {
|
|
111
|
+
if (o.type === PROPERTY) {
|
|
112
|
+
var q = o.queue;
|
|
113
|
+
if (q.type === SCOPED && q.entry !== "{") return;
|
|
114
|
+
var next = o.next;
|
|
115
|
+
if (next && (next.type !== STAMP || !/^[\:\=]$/.test(next.text))) {
|
|
116
|
+
o.text = `<selector>${o.text}</selector>`;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (next && (next.type === STAMP && next.text === ':')) {
|
|
120
|
+
while (next && next.type !== SCOPED) {
|
|
121
|
+
if (next.type === STAMP && next.text === ';') return;
|
|
122
|
+
next = next.next;
|
|
123
|
+
}
|
|
124
|
+
if (next) o.text = `<selector>${o.text}</selector>`;
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (o.type === EXPRESS) {
|
|
129
|
+
var next = o.next;
|
|
130
|
+
if (next?.type === SCOPED) return;
|
|
131
|
+
if (!o.length) o.type = QUOTED;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (o.type === STRAP) {
|
|
135
|
+
if (!o.isprop) return o.type = EXPRESS;
|
|
136
|
+
var p = o.prev;
|
|
137
|
+
if (!/^@/.test(o.text) && (!p || p.type !== STAMP || !/\:$/.test(p.text))) o.type = PROPERTY;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (o.type === SCOPED && o.length) {
|
|
142
|
+
o.forEach(set);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
c.forEach(set);
|
|
146
|
+
};
|
|
147
|
+
var 语言 = {
|
|
148
|
+
javascript(a) {
|
|
149
|
+
return 扫描(a, js);
|
|
150
|
+
},
|
|
151
|
+
typescript(a) {
|
|
152
|
+
return 扫描(a, typescript);
|
|
153
|
+
},
|
|
154
|
+
go(a) {
|
|
155
|
+
return 扫描(a, go);
|
|
156
|
+
},
|
|
157
|
+
json(a) {
|
|
158
|
+
return 扫描(a, json);
|
|
159
|
+
},
|
|
160
|
+
less(a) {
|
|
161
|
+
var c = 扫描(a, 素心);
|
|
162
|
+
setless(c);
|
|
163
|
+
return c;
|
|
164
|
+
},
|
|
165
|
+
rs(a) {
|
|
166
|
+
return 扫描(a, rust);
|
|
167
|
+
},
|
|
168
|
+
glsl(a) {
|
|
169
|
+
return 扫描(a, gl);
|
|
170
|
+
},
|
|
171
|
+
asm(a) {
|
|
172
|
+
return 扫描(a, asm);
|
|
173
|
+
},
|
|
174
|
+
html(a) {
|
|
175
|
+
var code = 扫描(a, 'html');
|
|
176
|
+
var scoped = code.scoped;
|
|
177
|
+
backEach(scoped.richNodes, n => {
|
|
178
|
+
if (n.isScript || n.isStyle) {
|
|
179
|
+
var s = n.isScript ? js : 素心;
|
|
180
|
+
var c = [];
|
|
181
|
+
compile$common.createString(n).replace(/^(\s*\<\!--)([\s\S]*)(--\!?\>\s*)$|^[\s\S]*$/, (m, p, a, f) => {
|
|
182
|
+
if (!a) {
|
|
183
|
+
c = 扫描(m, s);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
c = 扫描(a, s);
|
|
187
|
+
c.unshift(
|
|
188
|
+
{ type: compile$common.COMMENT, text: p },
|
|
189
|
+
);
|
|
190
|
+
c.push(
|
|
191
|
+
{ type: compile$common.COMMENT, text: f }
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
if (n.isStyle) setless(c);
|
|
195
|
+
});
|
|
196
|
+
n.splice(0, n.length, ...c);
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
return code;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
语言.gl = 语言.glsl;
|
|
204
|
+
语言.cmd = 语言.bat;
|
|
205
|
+
语言.css = 语言.less;
|
|
206
|
+
语言.cjs = 语言.mjs = 语言.jsx = 语言.js = 语言.javascript;
|
|
207
|
+
语言.tsx = 语言.ts = 语言.typescript;
|
|
208
|
+
语言.xht = 语言.jsp = 语言.asp = 语言.php = 语言.xml = 语言.html;
|
|
209
|
+
语言.vue = 语言.xht;
|
|
210
|
+
return 语言;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var { QUOTED, SCOPED } = compile$common;
|
|
2
|
+
var patchBlink = function (code, index, blink) {
|
|
3
|
+
for (var cx = 0, dx = code.length; cx < dx; cx++) {
|
|
4
|
+
var c = code[cx];
|
|
5
|
+
var haschildren = c => c.type === SCOPED || c.type === QUOTED && c.length;
|
|
6
|
+
if (c.start === index) {
|
|
7
|
+
if (haschildren(c)) {
|
|
8
|
+
c.entry = blink + c.entry;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
c.blink = 0;
|
|
12
|
+
c.text = blink + c.text;
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
else if (c.start < index && c.end > index) {
|
|
17
|
+
if (haschildren(c)) {
|
|
18
|
+
return patchBlink(c, index, blink);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
c.blink = index - c.start;
|
|
22
|
+
c.text = c.text.slice(0, c.blink) + blink + c.text.slice(c.blink);
|
|
23
|
+
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (c.end === index) {
|
|
28
|
+
if (haschildren(c)) {
|
|
29
|
+
c.leave += blink;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
c.blink = c.text.length;
|
|
33
|
+
c.text += blink;
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
else if (c.start > index) {
|
|
38
|
+
if (cx === 0) {
|
|
39
|
+
if (code.entry) return code.entry += blink, true;
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
var p = code[cx - 1];
|
|
44
|
+
if (haschildren(p)) {
|
|
45
|
+
p.leave += blink;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
p.blink = p.text.length;
|
|
49
|
+
p.text = p.text + blink;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (code.leave) {
|
|
56
|
+
code.leave = blink + code.leave;
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (c) return c.text += blink, true;
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
return patchBlink;
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
height: 100%;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
[codearea]
|
|
73
|
+
[codearea]>cigu {
|
|
74
74
|
overflow: auto;
|
|
75
75
|
display: block;
|
|
76
76
|
white-space: pre;
|
|
@@ -125,8 +125,8 @@
|
|
|
125
125
|
</span>
|
|
126
126
|
</p4>
|
|
127
127
|
</div>
|
|
128
|
-
<div body
|
|
129
|
-
#coder
|
|
128
|
+
<div body codearea -elseif="tags[1].actived">
|
|
129
|
+
<cigu contenteditable #coder></cigu>
|
|
130
130
|
</div>
|
|
131
131
|
<resultpad -if="tags[1].actived" .result #coderesult></resultpad>
|
|
132
132
|
<div foot -if="tags[1].actived">
|
|
@@ -136,6 +136,7 @@
|
|
|
136
136
|
</div>
|
|
137
137
|
</form>
|
|
138
138
|
<script>
|
|
139
|
+
var cigu = 茨菰$编辑框;
|
|
139
140
|
var required, doc, envs;
|
|
140
141
|
var commaps = Object.create(null);
|
|
141
142
|
var form = view;
|
|
@@ -259,164 +260,12 @@
|
|
|
259
260
|
else {
|
|
260
261
|
initcode('');
|
|
261
262
|
}
|
|
262
|
-
|
|
263
|
-
execute();
|
|
263
|
+
// execute();
|
|
264
264
|
};
|
|
265
|
-
var blink = "\u0080";
|
|
266
|
-
var markAnchorOffset = function () {
|
|
267
|
-
var { anchorNode, anchorOffset } = document.getSelection();
|
|
268
|
-
if (!anchorNode || !coder) return;
|
|
269
|
-
var [c] = coder.children;
|
|
270
|
-
if (anchorNode.nodeType === 1) {
|
|
271
|
-
var node = document.createTextNode(blink);
|
|
272
|
-
anchorNode.insertBefore(node, anchorNode.childNodes[anchorOffset])
|
|
273
|
-
}
|
|
274
|
-
else if (anchorNode.nodeType === 3) {
|
|
275
|
-
anchorNode.nodeValue = anchorNode.nodeValue.slice(0, anchorOffset) + blink + anchorNode.nodeValue.slice(anchorOffset);
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
var unmarkAnchorOffset = function () {
|
|
279
|
-
var [c] = coder.children;
|
|
280
|
-
var node = c.firstChild;
|
|
281
|
-
while (node) {
|
|
282
|
-
if (node.nodeType === 1) {
|
|
283
|
-
if (node.innerText.indexOf(blink) >= 0) {
|
|
284
|
-
node = node.firstChild;
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
else if (node.nodeType === 3) {
|
|
289
|
-
if (node.nodeValue.indexOf(blink) >= 0) break;
|
|
290
|
-
}
|
|
291
|
-
node = node.nextSibling;
|
|
292
|
-
}
|
|
293
|
-
if (node) {
|
|
294
|
-
var offset = node.nodeValue.indexOf(blink);
|
|
295
|
-
node.nodeValue = node.nodeValue.slice(0, offset) + node.nodeValue.slice(offset + 1);
|
|
296
|
-
document.getSelection().setBaseAndExtent(node, offset, node, offset);
|
|
297
|
-
if (!node.nodeValue) {
|
|
298
|
-
remove(node);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
var getAnchorOffset = function () {
|
|
303
|
-
var { anchorNode, anchorOffset } = document.getSelection();
|
|
304
|
-
var [c] = coder.children;
|
|
305
|
-
if (anchorNode === c || !anchorNode) return -anchorOffset;
|
|
306
|
-
var sibling = anchorNode.previousSibling ? anchorNode.previousSibling : anchorNode.parentNode.previousSibling;
|
|
307
|
-
while (sibling && sibling !== c) {
|
|
308
|
-
switch (sibling.nodeType) {
|
|
309
|
-
case 1:
|
|
310
|
-
anchorOffset += sibling.innerText.length || 1;
|
|
311
|
-
break;
|
|
312
|
-
case 3:
|
|
313
|
-
anchorOffset += sibling.nodeValue.length;
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
sibling = sibling.previousSibling ? sibling.previousSibling : sibling.parentNode.previousSibling;
|
|
317
|
-
}
|
|
318
|
-
return anchorOffset;
|
|
319
|
-
};
|
|
320
|
-
var setAnchorOffset = function (anchorOffset) {
|
|
321
|
-
var [c] = coder.children;
|
|
322
|
-
if (anchorOffset < 0) {
|
|
323
|
-
anchorOffset = -anchorOffset;
|
|
324
|
-
if (anchorOffset > c.childNodes.length) anchorOffset = c.childNodes.length;
|
|
325
|
-
return document.getSelection().setBaseAndExtent(c, anchorOffset, c, anchorOffset);
|
|
326
|
-
}
|
|
327
|
-
var offset = anchorOffset;
|
|
328
|
-
var child = c.firstChild;
|
|
329
|
-
while (child) {
|
|
330
|
-
var delta = 0;
|
|
331
|
-
switch (child.nodeType) {
|
|
332
|
-
case 1:
|
|
333
|
-
delta = child.innerText.length || 1;
|
|
334
|
-
break;
|
|
335
|
-
case 3:
|
|
336
|
-
delta = child.nodeValue.length;
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
if (delta >= offset) {
|
|
340
|
-
if (child.nodeType === 1) {
|
|
341
|
-
if (child.firstChild) {
|
|
342
|
-
child = child.firstChild;
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
offset -= 1;
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
break;
|
|
349
|
-
}
|
|
350
|
-
offset -= delta;
|
|
351
|
-
if (offset <= 0) break;
|
|
352
|
-
child = child.nextSibling;
|
|
353
|
-
}
|
|
354
|
-
if (!child) child = c, offset = c.childNodes.length;
|
|
355
|
-
return document.getSelection().setBaseAndExtent(child, offset, child, offset);
|
|
356
|
-
}
|
|
357
265
|
var initcode = function (innerText) {
|
|
358
|
-
|
|
359
|
-
var colored = codetext("js", innerText, blink);
|
|
360
|
-
} catch { return; }
|
|
361
|
-
var innerHTML = coder.innerHTML.replace(/\s*contenteditable\=[^\s\>]+/i, '');
|
|
362
|
-
if (innerHTML === colored) return;
|
|
363
|
-
var [c0] = coder.children;
|
|
364
|
-
var contentLength = c0 ? innerText.length : 0;
|
|
365
|
-
var scrollTop = c0 ? c0.scrollTop : 0;
|
|
366
|
-
var scrollLeft = c0 ? c0.scrollLeft : 0;
|
|
367
|
-
coder.innerHTML = colored;
|
|
368
|
-
var [c] = coder.children;
|
|
369
|
-
c.scrollTop = scrollTop;
|
|
370
|
-
c.scrollLeft = scrollLeft;
|
|
371
|
-
c.contentEditable = true;
|
|
266
|
+
cast(coder, [innerText, 'js']);
|
|
372
267
|
};
|
|
373
|
-
|
|
374
|
-
var ensp = s => Array(s + 1).join("\u2002"/*&ensp*/);
|
|
375
|
-
var getEnspBefore = function (node) {
|
|
376
|
-
if (!node) return 0;
|
|
377
|
-
while (node && (node.nodeType !== 1 || !/^br$/i.test(node.tagName))) {
|
|
378
|
-
node = node.previousSibling;
|
|
379
|
-
}
|
|
380
|
-
if (node) {
|
|
381
|
-
var next = node.nextSibling;
|
|
382
|
-
if (next) {
|
|
383
|
-
next = /^[\u2002\u0020\u00a0]+/.exec(next.nodeValue);
|
|
384
|
-
if (next) return next[0].length;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
var ontab = function (forcetab) {
|
|
389
|
-
var selection = document.getSelection();
|
|
390
|
-
var { anchorNode, anchorOffset } = selection;
|
|
391
|
-
if (anchorNode.nodeType === 1) {
|
|
392
|
-
var child = anchorNode.childNodes[anchorOffset];
|
|
393
|
-
var spaceSize = 4;
|
|
394
|
-
if (child.nodeType === 1) spaceSize = getEnspBefore(child?.previousSibling?.previousSibling || anchorNode);
|
|
395
|
-
if (!spaceSize && forcetab !== false) spaceSize = 4;
|
|
396
|
-
if (!spaceSize) return;
|
|
397
|
-
var space = document.createTextNode(ensp(spaceSize));
|
|
398
|
-
anchorNode.insertBefore(space, child);
|
|
399
|
-
selection.setBaseAndExtent(space, spaceSize, space, spaceSize);
|
|
400
|
-
}
|
|
401
|
-
else if (anchorNode.nodeType === 3) {
|
|
402
|
-
if (forcetab === 0) return;
|
|
403
|
-
anchorNode.nodeValue = anchorNode.nodeValue.slice(0, anchorOffset) + ensp(4) + anchorNode.nodeValue.slice(anchorOffset);
|
|
404
|
-
anchorOffset += 4;
|
|
405
|
-
selection.setBaseAndExtent(anchorNode, anchorOffset, anchorNode, anchorOffset);
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
var updatecode = lazy(function (event) {
|
|
409
|
-
var trimreg = /[\s\u00a0\u2002\u0080]+([\}\{\;\[\]\(\)\,\>\<\+\-\*\&\^\/%!~:?])*/g;
|
|
410
|
-
var innerText = coder.innerText;
|
|
411
|
-
if (jstext.replace(trimreg, trimspace).trim() === innerText.replace(trimreg, trimspace).trim()) return;
|
|
412
|
-
markAnchorOffset();
|
|
413
|
-
var innerText = coder.innerText;
|
|
414
|
-
unmarkAnchorOffset();
|
|
415
|
-
initcode(innerText);
|
|
416
|
-
unmarkAnchorOffset();
|
|
417
|
-
jstext = coder.innerText;
|
|
418
|
-
jschanged = true;
|
|
419
|
-
});
|
|
268
|
+
|
|
420
269
|
var jschanged = false;
|
|
421
270
|
var execute = async function () {
|
|
422
271
|
try {
|
|
@@ -424,6 +273,7 @@
|
|
|
424
273
|
if (live) live = live[1];
|
|
425
274
|
var commap = initCommap(live);
|
|
426
275
|
remove(coderesult.childNodes);
|
|
276
|
+
var jstext = coder.innerText;
|
|
427
277
|
jstext = jstext.replace(/[\u2002\u00a0]/g, ' ');
|
|
428
278
|
data.patchInstance("docscode", { codetext: jstext })
|
|
429
279
|
var code = compile$scanner2(jstext);
|
|
@@ -465,10 +315,6 @@
|
|
|
465
315
|
var clearpad = function () {
|
|
466
316
|
remove(this.coderesult.childNodes);
|
|
467
317
|
};
|
|
468
|
-
var keytab = function (event) {
|
|
469
|
-
event.preventDefault();
|
|
470
|
-
ontab();
|
|
471
|
-
};
|
|
472
318
|
|
|
473
319
|
var saveTagIndex = function (i) {
|
|
474
320
|
data.setInstance("docscode", { tagIndex: i });
|