efront 4.11.1 → 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.
Files changed (36) hide show
  1. package/coms/basic/assert.js +5 -3
  2. package/coms/compile/Html_test.js +1 -0
  3. package/coms/compile/Javascript.js +5 -1
  4. package/coms/compile/Javascript_test.js +14 -2
  5. package/coms/compile/Program.js +14 -4
  6. package/coms/compile/common.js +1 -1
  7. package/coms/compile//347/264/240/351/246/250.js +25 -19
  8. package/coms/compile//347/264/240/351/246/250_test.js +1 -0
  9. package/coms/docs/markdown.js +5 -3
  10. package/coms/frame/chat.js +1 -1
  11. package/coms/frame/route.js +15 -15
  12. package/coms/kugou/api.js +1 -1
  13. package/coms/kugou/player.js +3 -0
  14. package/coms/zimoli/addClass.js +19 -16
  15. package/coms/zimoli/css.js +12 -1
  16. package/coms/zimoli/getGenerator.js +9 -15
  17. package/coms/zimoli/menuList.js +29 -23
  18. package/coms/zimoli/on.js +8 -0
  19. package/coms/zimoli/removeClass.js +4 -6
  20. package/coms/zimoli/render.js +154 -112
  21. package/coms/zimoli/table.js +2 -0
  22. package/coms/zimoli/vbox.js +2 -1
  23. package/coms/zimoli/view.less +0 -1
  24. package/coms//350/214/250/350/217/260/tab.js +34 -0
  25. package/coms//350/214/250/350/217/260//344/270/212/350/211/262.xht +99 -0
  26. package/coms//350/214/250/350/217/260//345/205/211/346/240/207.js +1 -0
  27. package/coms//350/214/250/350/217/260//346/211/253/346/217/217.js +12 -0
  28. package/coms/{docs/codecolor.js → /350/214/250/350/217/260//346/240/207/347/255/276/345/214/226.js} +2 -1
  29. package/coms//350/214/250/350/217/260//346/270/262/346/237/223.js +45 -0
  30. package/coms//350/214/250/350/217/260//347/274/226/350/276/221/346/241/206.xht +132 -0
  31. package/coms//350/214/250/350/217/260//350/257/255/350/250/200.js +210 -0
  32. package/coms//350/214/250/350/217/260//350/277/275/345/212/240/345/205/211/346/240/207.js +62 -0
  33. package/docs//347/273/204/344/273/266.xht +8 -162
  34. package/package.json +1 -1
  35. package/public/efront.js +1 -1
  36. package/coms/docs/codetext.xht +0 -385
@@ -109,13 +109,19 @@ function rebuild(element) {
109
109
  }
110
110
  var variableReg = /([^\:\,\+\=\-\!%\^\|\/\&\*\!\;\?\>\<~\{\}\s\[\]\(\)]|\?\s*\.(?=[^\d])|\s*\.\s*)+/g;
111
111
  var variableOnlyReg = new RegExp(`^${variableReg.source}$`);
112
+ var getScopeList = function (element) {
113
+ return element.$parentScopes.concat([element.$scope]);
114
+ };
112
115
  var createGetter = function (target, search, isprop = true) {
113
116
  if (!search) return function () { };
114
117
  if (/^\{/.test(search)) search = `(${search})`;
115
118
  search = renderExpress(search);
116
- if (isprop) return $$eval.bind(target, search, null);
117
- if (variableOnlyReg.test(search)) return $$eval.bind(target, search + "(event)", null);
118
- else return $$eval.bind(target, search, null);
119
+ var scopes = getScopeList(target);
120
+ if (isprop) var getter = $$eval.bind(target, search, scopes);
121
+ else if (variableOnlyReg.test(search)) getter = $$eval.bind(target, search + "(event)", scopes);
122
+ else getter = $$eval.bind(target, search, scopes);
123
+ getter.scopes = scopes;
124
+ return getter;
119
125
  };
120
126
  var createComment = function (renders, type, expression) {
121
127
  var comment = document.createComment(`${type} ${expression}`);
@@ -155,11 +161,11 @@ class Repeater {
155
161
  this.trackBy = trackBy;
156
162
  this.srcName = srcName;
157
163
  }
158
- createScope(item, k, i) {
164
+ createScope(item, k, i, wraped) {
159
165
  var scope = {
160
166
  $key: k,
161
- $item: item,
162
- $index: i
167
+ $item: wraped || item,
168
+ $index: i,
163
169
  };
164
170
  if (this.keyName !== "$key") {
165
171
  scope[this.keyName] = k;
@@ -389,6 +395,14 @@ var parseIfWithRepeat = function (ifExpression, repeatExpression) {
389
395
  };
390
396
  };
391
397
 
398
+ var mountElementIds = function (element, ids) {
399
+ var scope = element.$scope;
400
+ if (!scope) return;
401
+ for (var id of ids) {
402
+ if (isHandled(scope[id]) && scope[id] !== element) throw new Error(i18n`同一个id不能使用两次:` + id);
403
+ scope[id] = element;
404
+ }
405
+ }
392
406
  var renderStructure = function (element) {
393
407
  var $struct = element.$struct;
394
408
  if ($struct.if) var { name: ifkey, key, value: ifexp } = $struct.if;
@@ -440,27 +454,36 @@ var structures = {
440
454
  };
441
455
  structures["else-if"] = structures.elseif = structures.else;
442
456
  structures["for-each"] = structures.foreach = structures.for = structures.each = structures.repeat;
443
- var createBinder = function (binder) {
457
+ var createMapper = function (write, mapper) {
444
458
  return function (search) {
445
- var getter = createGetter(this, `(${search})`);
446
- var oldValue;
459
+ var getter = isArray(search) ? search.map(s => createGetter(this, s)) : createGetter(this, search);
460
+ var oldValue = mapper();
461
+ this.$renders.push(function () {
462
+ var value = mapper(isArray(getter) ? getter.map(g => g(this)) : getter(this));
463
+ var changes = getChanges(value, oldValue);
464
+ if (!changes) return;
465
+ oldValue = value;
466
+ var targetValue = Object.create(null);
467
+ for (var k in changes) {
468
+ targetValue[k] = !isHandled(value[k]) ? "" : value[k];
469
+ }
470
+ write(this, targetValue);
471
+ });
472
+ }
473
+ }
474
+ var createBinder2 = function (write, read) {
475
+ return function (search) {
476
+ var getter = createGetter(this, search);
477
+ var oldValue = isFunction(read) ? read(this) : undefined;
447
478
  this.$renders.push(function () {
448
479
  var value = getter(this);
449
480
  if (shallowEqual(value, oldValue)) return;
450
481
  var oldv = oldValue;
451
482
  oldValue = value;
452
- if (isNode(value) || isArray(value)) {
453
- if (value !== this.firstChild) {
454
- remove(this.childNodes);
455
- appendChild(this, value);
456
- }
457
- } else {
458
- if (isEmpty(value)) value = '';
459
- if (binder(this) !== value) binder(this, value, oldv);
460
- }
483
+ if (!isHandled(value)) value = '';
484
+ write(this, value, oldv);
461
485
  });
462
-
463
- }
486
+ };
464
487
  }
465
488
 
466
489
  var src2 = function (search) {
@@ -481,28 +504,41 @@ var src2 = function (search) {
481
504
  cast(this, origin);
482
505
  });
483
506
  }
507
+
484
508
  var directives = {
485
- bind: createBinder(text),
486
- html: createBinder(html),
487
- hide: createBinder(function (elem, value) {
488
- if (arguments.length === 1) return elem.style.display === 'none';
489
- elem.style.display = value ? 'none' : '';
509
+ text: createBinder2(function (elem, value) {
510
+ elem.innerText = value;
490
511
  }),
491
- show: createBinder(function (elem, value) {
492
- if (arguments.length === 1) return elem.style.display !== 'none';
493
- elem.style.display = value ? '' : 'none';
494
- }),
495
- style: createBinder(function (elem, value, oldValue) {
496
- if (isString(value)) value = parseKV(value, ';', ':');
497
- if (isString(oldValue)) oldValue = parseKV(oldValue, ";", ":");
498
- var changed = getChanges(value, oldValue);
499
- var targetValue = Object.create(null);
500
- for (var k in changed) {
501
- targetValue[k] = isEmpty(value[k]) ? "" : value[k];
512
+ bind: createBinder2(function (elem, value) {
513
+ if (isNode(value) || isArray(value)) {
514
+ if (value !== elem.firstChild) {
515
+ remove(elem.childNodes);
516
+ appendChild(elem, value);
517
+ }
518
+ }
519
+ else {
520
+ elem.innerText = value;
502
521
  }
503
- value = targetValue;
504
- css(elem, value);
505
522
  }),
523
+ html: createBinder2(function (elem, value) {
524
+ elem.innerHTML = value;
525
+ }),
526
+ hide: createBinder2(function (elem, value) {
527
+ var display = value ? 'none' : '';
528
+ var style = elem.style;
529
+ if (style.display !== display) style.display = display;
530
+ }, function (elem) {
531
+ return elem.style.display === 'none';
532
+ }),
533
+ show: createBinder2(function (elem, value) {
534
+ var display = value ? '' : 'none';
535
+ var style = elem.style;
536
+ if (style.display !== display) style.display = display;
537
+ }, function (elem) {
538
+ return elem.style.display === 'none';
539
+ }),
540
+ style: createMapper(css, css.styleToMap),
541
+ class: createMapper(addClass, addClass.classToMap),
506
542
  src(src) {
507
543
  var parsedSrc = this.$src;
508
544
  return src2.call(this, parsedSrc && /[\{\[\s]/.test(src) ? parsedSrc.srcName : src);
@@ -545,7 +581,7 @@ var directives = {
545
581
  var change = getstr || "'value' in this?this.value:this.innerHTML";
546
582
  }
547
583
  setter2 = null;
548
- var changeme = $$eval.bind(this, search + "=" + change, null);
584
+ var changeme = $$eval.bind(this, search + "=" + change, getScopeList(this));
549
585
  var onchange = function () {
550
586
  changeme(this);
551
587
  var value = getter(this);
@@ -558,43 +594,7 @@ var directives = {
558
594
  eventsBinders.forEach(on => on(target, onchange, true));
559
595
  },
560
596
 
561
- "class"(search) {
562
- var getter = createGetter(this, search);
563
- var generatedClassNames = {};
564
- var oldValue;
565
- this.$renders.push(function () {
566
- var className = getter(this);
567
- if (deepEqual(oldValue, className)) return;
568
- oldValue = className;
569
- var originalClassNames = [];
570
- this.className.split(/\s+/).map(function (k) {
571
- if (k && !hasOwnProperty.call(generatedClassNames, k) && !hasOwnProperty.call(originalClassNames, k)) {
572
- if (!/^\d+$/.test(k)) originalClassNames.push(originalClassNames[k] = k);
573
- }
574
- });
575
- var deltaClassNames = [];
576
- if (isString(className)) {
577
- className.split(/\s+/).map(function (k) {
578
- if (!hasOwnProperty.call(originalClassNames, k)) {
579
- if (!/^\d+$/.test(k)) deltaClassNames.push(deltaClassNames[k] = k);
580
- }
581
- });
582
- } else if (isObject(className)) {
583
- for (var k in className) {
584
- if (!hasOwnProperty.call(originalClassNames, k) && className[k]) {
585
- if (!/^\d+$/.test(k)) deltaClassNames.push(deltaClassNames[k] = k);
586
- }
587
- }
588
- }
589
- var destClassName = originalClassNames.concat(deltaClassNames).join(" ");
590
- generatedClassNames = deltaClassNames;
591
- if (this.className !== destClassName) {
592
- this.className = destClassName;
593
- }
594
- });
595
- },
596
597
  };
597
- directives.text = directives.bind;
598
598
  // property binder
599
599
  var binders = {
600
600
  _(attr, search) {
@@ -672,12 +672,9 @@ var createEmiter = function (on) {
672
672
  }
673
673
  var res;
674
674
  if (scope) {
675
- var temp = this.$scope;
676
- this.$parentScopes.push(temp);
677
- this.$scope = scope;
675
+ getter.scopes.push(scope);
678
676
  res = getter(this, e);
679
- this.$parentScopes.pop();
680
- this.$scope = temp;
677
+ getter.scopes.pop();
681
678
  }
682
679
  else {
683
680
  res = getter(this, e);
@@ -735,6 +732,8 @@ function renderRest(element, struct, replacer = element) {
735
732
  }
736
733
  if (binds.src) directives.src.call(element, binds.src);
737
734
  if (renders && renders.length) element.$renders.push.apply(element.$renders, renders);
735
+ if (!isElement(replacer)) replacer = element;
736
+ struct.ons.forEach(([on, key, value]) => on.call(element, replacer, key, value));
738
737
  }
739
738
 
740
739
  function renderElement(element, scope = element.$scope, parentScopes = element.$parentScopes, once) {
@@ -759,18 +758,17 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
759
758
  }
760
759
  element.$parentScopes = parentScopes || [];
761
760
  var s = createStructure(element);
761
+ element.$struct = s;
762
+ mountElementIds(element, s.ids);
762
763
  if (isEmpty(s.once)) s.once = once;
763
764
  element.$eval = $eval;
764
765
  }
766
+ element.$scope = scope;
765
767
  if (element.$renderid <= -1) element = renderStructure(element);
766
768
  if (!element) return;
767
769
  if (!element || element.$renderid < 0 || element.nodeType !== 1) {
768
770
  return element;
769
771
  }
770
- for (var id of element.$struct.ids) {
771
- if (scope[id] && scope[id] !== element) throw new Error(i18n`同一个id不能使用两次:` + id);
772
- scope[id] = element;
773
- }
774
772
  var isFirstRender = !element.$renderid;
775
773
 
776
774
  if (isFirstRender) {
@@ -779,8 +777,9 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
779
777
  if (parentNode) {
780
778
  if (parentNode.$renderid > 1 || isMounted(parentNode)) element.$renderid = 2;
781
779
  }
780
+ var $struct = element.$struct;
782
781
  element.$renders = element.$renders || element.renders ? [].concat(element.$renders || [], element.renders || []) : [];
783
- var { copys, binds, once } = element.$struct;
782
+ var { copys, binds, once } = $struct;
784
783
  if (once) element.$renderid = 9;
785
784
  if (binds.src) {
786
785
  element.$src = parseRepeat(binds.src);
@@ -790,15 +789,20 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
790
789
  var constructor = getFromScopes(tagName, scope, parentScopes);
791
790
  if (isFunction(constructor)) {
792
791
  var replacer = constructor.call(scope, element, scope, parentScopes);
793
- if (isNode(replacer) && element !== replacer) {
794
- if (!replacer.$scope) replacer.$scope = scope;
795
- if (!replacer.$parentScopes) replacer.$parentScopes = parentScopes;
792
+ if (element === replacer) {
793
+ var struct1 = createStructure(element, false);
794
+ renderRest(element, struct1);
795
+ element.$scope = scope;
796
+ }
797
+ else if (isNode(replacer)) {
796
798
  if (isElement(replacer) && !replacer.$renderid) {
799
+ if (!replacer.$scope) replacer.$scope = scope;
800
+ if (!replacer.$parentScopes) replacer.$parentScopes = parentScopes;
797
801
  createStructure(replacer);
798
802
  if (replacer.children && replacer.children.length) renderElement(replacer.children, replacer.$scope, replacer.$parentScopes, once);
799
803
  renderRest(replacer, replacer.$struct);
800
- replacer.$struct.ons.forEach(([on, key, value]) => on.call(replacer, replacer, key, value));
801
804
  }
805
+
802
806
  copyAttribute(replacer, copys);
803
807
  if (nextSibling) appendChild.before(nextSibling, replacer);
804
808
  else if (parentNode) appendChild(parentNode, replacer);
@@ -814,7 +818,7 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
814
818
  if (element.children && element.children.length) renderElement(element.children, scope, parentScopes, once);
815
819
  }
816
820
  if (!isFirstRender) return element;
817
- renderRest(element, element.$struct, replacer);
821
+ renderRest(element, $struct, replacer);
818
822
  if (isNode(replacer) && replacer !== element) {
819
823
  if (!replacer.$renders) replacer.$renders = [];
820
824
  replacer.$renders.push.apply(replacer.$renders, element.$renders);
@@ -823,9 +827,6 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
823
827
  }
824
828
  element = replacer;
825
829
  }
826
- else {
827
- element.$struct.ons.forEach(([on, key, value]) => on.call(element, element, key, value));
828
- }
829
830
  if (element.$renders.length) {
830
831
  if (element.$renderid !== 9) {
831
832
  onmounted(element, addRenderElement);
@@ -844,26 +845,60 @@ var createEval = function (deep) {
844
845
  while (deep-- > 0) {
845
846
  context[deep] = `with($parentScopes[${deep}])`;
846
847
  }
847
- return new Function("$parentScopes", "$scope", "code", "event", `${context.join('')}with($scope)return eval(code)`);
848
+ return new Function("$parentScopes", "code", "event", `${context.join('')}return eval(code)`);
848
849
  };
849
850
  var evalcontexts = [createEval(0)];
850
851
 
851
- function $$eval(search, scope, target = this, event) {
852
- var needpop = scope && scope !== this.$scope;
853
- if (needpop) {
854
- this.$parentScopes.push(this.$scope);
855
- this.$scope = scope;
856
- }
857
- var length = this.$parentScopes ? this.$parentScopes.length : 0;
852
+ function $$eval(search, scopes, target = this, event) {
853
+ var length = scopes.length;
858
854
  if (!evalcontexts[length]) evalcontexts[length] = createEval(length);
859
855
  var eval2 = evalcontexts[length];
860
- var res = eval2.call(target, this.$parentScopes, this.$scope, search, event);
861
- if (needpop) this.$scope = this.$parentScopes.pop();
856
+ var res = eval2.call(target, scopes, search, event);
862
857
  return res;
863
858
  }
864
859
 
865
860
  function $eval(search, scope, event) {
866
- return $$eval.call(this, search, scope, this, event);
861
+ var scopes = getScopeList(this);
862
+ if (isHandled(scope) && scope !== this.$scope) scopes.push(scope);
863
+ return $$eval.call(this, search, scopes, this, event);
864
+ }
865
+
866
+ var merge = function (dst, src) {
867
+ if (!isHandled(src)) return dst;
868
+ if (!isHandled(dst)) return src;
869
+ if (isArray(dst)) {
870
+ return dst.concat(src);
871
+ }
872
+ if (isObject(dst)) return Object.assign(dst, src);
873
+ return src;
874
+ };
875
+ var pushb = function (dist, b) {
876
+ if (isArray(b)) dist.push(...b);
877
+ else if (isHandled(b)) dist.push(b);
878
+ };
879
+ var mergeStruct = function (struct1, struct2) {
880
+ if (!isObject(struct1)) return struct2;
881
+ if (!isObject(struct2)) return struct1;
882
+ for (var k in struct2) if (k !== 'binds') {
883
+ struct1[k] = merge(struct1[k], struct2[k]);
884
+ }
885
+ var binds1 = struct1.binds;
886
+ var binds2 = struct2.binds;
887
+ for (var k in binds2) {
888
+ if (/^(class|style)$/.test(k)) {
889
+ var dist = [];
890
+ pushb(dist, binds1[k]);
891
+ pushb(dist, binds2[k]);
892
+ if (dist.length) {
893
+ if (dist.length === 1) dist = dist[0];
894
+ binds1[k] = dist;
895
+ }
896
+ }
897
+ else {
898
+ binds1[k] = binds2[k];
899
+ }
900
+ }
901
+ return struct1;
867
902
  }
868
903
 
869
904
  class Struct {
@@ -881,9 +916,15 @@ class Struct {
881
916
  }
882
917
 
883
918
 
884
- function createStructure(element) {
919
+ var pushid = function (ids, name) {
920
+ ids.push(name);
921
+ var name1 = name.replace(/\-([a-z])/ig, (_, a) => a.toUpperCase());
922
+ if (name1 !== name) ids.push(name1);
923
+ };
924
+
925
+ function createStructure(element, useExists) {
885
926
  if (isArrayLike(element)) return Array.prototype.map.call(element, createStructure);
886
- if (element.$struct) return element.$struct;
927
+ if (useExists !== false && element.$struct) return element.$struct;
887
928
  if (element.nodeType !== 1) return;
888
929
  // 处理结构流
889
930
  var attributes = element.attributes;
@@ -904,11 +945,11 @@ function createStructure(element) {
904
945
  var { name, value } = attr;
905
946
  if (/^\$/.test(name)) continue;
906
947
  if (name === 'elementid' || name === 'renderid' || name === 'id') {
907
- ids.push(value);
948
+ pushid(ids, value);
908
949
  continue;
909
950
  }
910
951
  if (/^#/.test(name)) {
911
- ids.push(name.slice(1), name.slice(1).replace(/\-([a-z])/ig, (_, a) => a.toUpperCase()));
952
+ pushid(ids, name.slice(1));
912
953
  element.removeAttribute(name);
913
954
  continue;
914
955
  };
@@ -952,7 +993,7 @@ function createStructure(element) {
952
993
  // ng-html,ng-src,ng-text,ng-model,ng-style,ng-class,...
953
994
  var key = name.replace(/^(ng|v|[^\_\:\.]*?)\-|^[\:\_\.]|^v\-bind\:/i, "").toLowerCase();
954
995
  if (directives.hasOwnProperty(key) || /^([\_\:\.]|v\-bind\:)/.test(name)) {
955
- binds[key] = value;
996
+ if (value) binds[key] = value;
956
997
  element.removeAttribute(name);
957
998
  }
958
999
  // ng-click on-click v-click @click @mousedown ...
@@ -960,11 +1001,11 @@ function createStructure(element) {
960
1001
  var match = emiter_reg.exec(name);
961
1002
  var ngon = (match[1] || match[0]).toLowerCase() === 'once' ? 'once' : 'on';
962
1003
  element.removeAttribute(name);
963
- ons.push([emiters[ngon], name.replace(emiter_reg, ''), value]);
1004
+ if (value) ons.push([emiters[ngon], name.replace(emiter_reg, ''), value]);
964
1005
  }
965
1006
  // placeholder_ href_ checked_ ...
966
1007
  else if (/[_@\:\.]$/.test(name)) {
967
- attr1[name.replace(/[_@\:\.]$/, "")] = value;
1008
+ if (value) attr1[name.replace(/[_@\:\.]$/, "")] = value;
968
1009
  element.removeAttribute(name);
969
1010
  }
970
1011
  // title alt name type placeholder href checked ...
@@ -1034,4 +1075,5 @@ render.register = function (key, name) {
1034
1075
  }
1035
1076
  };
1036
1077
  render.getFromScopes = getFromScopes;
1037
- render.struct = createStructure;
1078
+ render.struct = createStructure;
1079
+ render.mergeStruct = mergeStruct;
@@ -307,6 +307,7 @@ var setFixedColumn = function (remark) {
307
307
  markRowTds(tr, remark);
308
308
  });
309
309
  if (!isTableRow(thead)) thead = thead.querySelector('tr');
310
+ if (!thead) return;
310
311
  var children = Array.prototype.slice.call(thead.children);
311
312
  var lastChild = children[children.length - 1];
312
313
  var lastFieldChild = children[children.length - 2];
@@ -573,6 +574,7 @@ function table(elem) {
573
574
  pagination
574
575
  };
575
576
  render(this, $scope, this.$parentScopes.concat(this.$scope));
577
+ if (isMounted(table)) setFixedColumn.call(table);
576
578
  $scope.data = Table.from(fields, await data);
577
579
  $scope.data.callback = function () {
578
580
  render.digest();
@@ -148,8 +148,9 @@ function ybox(generator) {
148
148
  wheelTime = event.timeStamp;
149
149
  return;
150
150
  }
151
- var deltay = -event.deltaY;
152
151
  if (event.moveLocked) return;
152
+ var deltay = -event.deltaY;
153
+ if (!deltay && _box.bindX) deltay = -event.deltaX;
153
154
  event.moveLocked = true;
154
155
  var box;
155
156
  if (deltay > 0) {
@@ -27,7 +27,6 @@ body>& {
27
27
  >[body] {
28
28
  padding: 6px 20px 6px 6px;
29
29
  margin-right: -20px;
30
- background: #f2f4f622;
31
30
  display: block;
32
31
  width: auto;
33
32
  height: 100%;
@@ -0,0 +1,34 @@
1
+ var ensp = s => Array(s + 1).join("\u2002"/*&ensp*/);
2
+ var getEnspBefore = function (node) {
3
+ if (!node) return 0;
4
+ while (node && (node.nodeType !== 1 || !/^br$/i.test(node.tagName))) {
5
+ node = node.previousSibling;
6
+ }
7
+ if (node) {
8
+ var next = node.nextSibling;
9
+ if (next) {
10
+ next = /^[\u2002\u0020\u00a0]+/.exec(next.nodeValue);
11
+ if (next) return next[0].length;
12
+ }
13
+ }
14
+ };
15
+ return function (forcetab) {
16
+ var selection = document.getSelection();
17
+ var { anchorNode, anchorOffset } = selection;
18
+ if (anchorNode.nodeType === 1) {
19
+ var child = anchorNode.childNodes[anchorOffset];
20
+ var spaceSize = 4;
21
+ if (child.nodeType === 1) spaceSize = getEnspBefore(child?.previousSibling?.previousSibling || anchorNode);
22
+ if (!spaceSize && forcetab !== false) spaceSize = 4;
23
+ if (!spaceSize) return;
24
+ var space = document.createTextNode(ensp(spaceSize));
25
+ anchorNode.insertBefore(space, child);
26
+ selection.setBaseAndExtent(space, spaceSize, space, spaceSize);
27
+ }
28
+ else if (anchorNode.nodeType === 3) {
29
+ if (forcetab === 0) return;
30
+ anchorNode.nodeValue = anchorNode.nodeValue.slice(0, anchorOffset) + ensp(4) + anchorNode.nodeValue.slice(anchorOffset);
31
+ anchorOffset += 4;
32
+ selection.setBaseAndExtent(anchorNode, anchorOffset, anchorNode, anchorOffset);
33
+ }
34
+ };
@@ -0,0 +1,99 @@
1
+ <style>
2
+ :scope {
3
+ white-space: pre-wrap;
4
+ line-height: 1.36;
5
+ word-break: break-all;
6
+ padding: 10px 20px;
7
+ border-radius: 3px;
8
+ display: inline-block;
9
+ background: #2c2c2c;
10
+ color: #d4d4d4;
11
+ font-family: Consolas, "Courier New", monospace;
12
+ vertical-align: top;
13
+ text-decoration-line: none;
14
+ tab-size: 4;
15
+ }
16
+
17
+ stamp {
18
+ color: #808080;
19
+ }
20
+
21
+ strap,
22
+ value {
23
+ color: #569cd6;
24
+ }
25
+
26
+ regexp {
27
+ color: #d16969;
28
+ }
29
+
30
+ text {
31
+ color: #ce9178;
32
+ }
33
+
34
+ flow {
35
+ color: #c586c0;
36
+ }
37
+
38
+ digit {
39
+ color: #b5cea8;
40
+ }
41
+
42
+ label {
43
+ color: #569cd6;
44
+ }
45
+
46
+ selector {
47
+ color: #d7ba7d;
48
+ }
49
+
50
+ @deep(@num, @color) {
51
+ deep@num {
52
+ color: @color;
53
+ }
54
+ }
55
+
56
+ @deep(0, #ffd700);
57
+ @deep(1, #da70d6);
58
+ @deep(2, #179fff);
59
+ @deep(3, #ffd700);
60
+ @deep(4, #da70d6);
61
+ @deep(5, #179fff);
62
+ @deep(6, #ffd700);
63
+ @deep(7, #da70d6);
64
+ @deep(8, #179fff);
65
+ @deep(9, #ffd700);
66
+ @deep(10, #da70d6);
67
+ @deep(11, #179fff);
68
+ @deep(12, #ffd700);
69
+ @deep(13, #da70d6);
70
+ @deep(14, #179fff);
71
+ @deep(15, #ffd700);
72
+ @deep(16, #da70d6);
73
+ @deep(17, #179fff);
74
+
75
+ express,
76
+ property {
77
+ color: #9cdcfe;
78
+ }
79
+
80
+ invoke,
81
+ method {
82
+ color: #dcdcaa;
83
+ }
84
+
85
+ predef {
86
+ color: #4ec9b0;
87
+ }
88
+
89
+ outside {
90
+ color: #4fc1ff;
91
+ }
92
+
93
+ comment {
94
+ color: #6a9955;
95
+ }
96
+ </style>
97
+ <script>
98
+ 茨菰$渲染;
99
+ </script>
@@ -0,0 +1 @@
1
+ return "\u0080";
@@ -0,0 +1,12 @@
1
+ var { STAMP, PIECE, SPACE } = compile$common;
2
+ return function (a, type) {
3
+ if (光标) var index = a.indexOf(光标);
4
+ if (index >= 0) a = a.slice(0, index) + a.slice(index + 1);
5
+ var c = compile$scanner2(a, type);
6
+ if (index >= 0) {
7
+ c.scoped;
8
+ var patched = 追加光标(c, index, 光标);
9
+ if (!patched) c.push({ type: SPACE, text: 光标 });
10
+ }
11
+ return c;
12
+ }
@@ -153,4 +153,5 @@ var codecolor = function (c, encode) {
153
153
  };
154
154
  c.forEach(setcolor);
155
155
  return c;
156
- }
156
+ }
157
+ return codecolor;
@@ -0,0 +1,45 @@
1
+
2
+ var { SCOPED, QUOTED, SPACE, STAMP, STRAP, EXPRESS, PROPERTY } = compile$common;
3
+ var encode = function (text) {
4
+ return text.replace(/[\<\>\|]/g, a => `&#${a.charCodeAt()};`);
5
+ };
6
+
7
+ var rows = function (type, text) {
8
+ if (typeof text !== 'string') {
9
+ console.log(text)
10
+ return [];
11
+ }
12
+ type = type.toLowerCase();
13
+ if (type in 语言) {
14
+ var c = 语言[type](text);
15
+ 标签化(c, encode);
16
+ text = c.toString();
17
+
18
+ }
19
+ else text = encode(text);
20
+
21
+ var codes = text.split(/\r\n|\r|\n/);
22
+ var minSpace = Infinity;
23
+ for (var c of codes) {
24
+ var m = /^\s+/.exec(c);
25
+ if (!m) {
26
+ minSpace = 0;
27
+ break;
28
+ }
29
+ if (m[0].length < minSpace) {
30
+ minSpace = m[0].length;
31
+ }
32
+ }
33
+ if (minSpace > 0 && minSpace < Infinity) codes = codes.map(c => /^\s+/.test(c) ? c.slice(minSpace) : c);
34
+ return codes;
35
+ }
36
+ function 茨菰(type, text) {
37
+ return `<code type=${type}>${rows(type, text).join("<br/>")}</code>`;
38
+ }
39
+ 茨菰.text = function (type, text) {
40
+ return `${rows(type, text).join("<br/>")}`;
41
+ };
42
+
43
+ 茨菰.rows = rows;
44
+ 茨菰.encode = encode;
45
+ return 茨菰;