efront 4.9.1 → 4.9.2

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.
@@ -87,7 +87,8 @@ function filterTime(time, formater) {
87
87
  var [year1, month1, date1, hour1, minute1, second1, milli1, day1] = getSplitedDate(now);
88
88
  var today = new Date(year1, month1 - 1, date1);
89
89
  var thatday = new Date(year, month - 1, date);
90
- var delta = (today - thatday) / 24 / 3600000;
90
+ var delta = (today - thatday) / 24 / 3600000 | 0;
91
+ var deltaSeconds = (new Date(year1, month1 - 1, date1, hour1, minute1, second1) - new Date(year, month - 1, date, hour, minute, second)) / 1000;
91
92
  if (minute === 0 && second === 0) var time = hour + "点整";
92
93
  else if (minute === 30 && second === 0) time = hour + "点半";
93
94
  else time = `${hour}:${fixLength(minute)}`;
@@ -103,18 +104,25 @@ function filterTime(time, formater) {
103
104
  }
104
105
  return `星期` + days[day] + time;
105
106
  }
107
+ if (deltaSeconds >= 0 && deltaSeconds < 60) {
108
+ return `刚刚`;
109
+ }
110
+ if (deltaSeconds < 0) {
111
+ if (deltaSeconds > -60) {
112
+ return `${-deltaSeconds | 0}秒后`;
113
+ }
114
+ if (deltaSeconds >= -3600) {
115
+ return `还有${-deltaSeconds / 60 | 0}分钟`;
116
+ }
117
+ if (deltaSeconds > -86400) {
118
+ var a = -deltaSeconds / 3600 | 0;
119
+ var b = (-deltaSeconds + (deltaSeconds / 3600 | 0) * 3600) / 60 | 0;
120
+ if (b === 0) return `还有${a}小时`;
121
+ return `还有${a}小时${b}分钟`;
122
+ }
123
+ }
106
124
  switch (delta) {
107
125
  case 0:
108
- if (minute === minute1 && hour === hour1) {
109
- if (second <= second1) return `刚刚`;
110
- return `${second - second1}秒后`;
111
- }
112
- else if (value > now) {
113
- if (hour === hour1) {
114
- return `${minute - minute1}分钟后`;
115
- }
116
- return `还有${hour - hour1}小时${minute - minute1}分钟`;
117
- }
118
126
  return time;
119
127
  case -1:
120
128
  return "明天" + time;
@@ -2,6 +2,17 @@ assert(filterTime(''), ``);
2
2
  assert(filterTime(null), '');
3
3
  assert(filterTime(undefined), '');
4
4
  assert(filterTime("我出生的第二年"), `我出生的第二年`);
5
+ assert(filterTime(+new Date + 86300000), '还有23小时58分钟');
6
+ assert(filterTime(+new Date + 110000), '还有1分钟');
7
+ assert(filterTime(+new Date + 120000), '还有2分钟');
8
+ assert(filterTime(+new Date + 60000), '还有1分钟');
9
+ assert(filterTime(+new Date + 59000), '59秒后');
10
+ assert(filterTime(+new Date + 58000), '58秒后');
11
+ assert(filterTime(+new Date + 8000), '8秒后');
12
+ assert(filterTime(+new Date + 1000), '1秒后');
13
+ assert(filterTime(+new Date), '刚刚');
14
+ assert(filterTime(+new Date), '刚刚');
15
+ assert(filterTime(+new Date - 59000), '刚刚');
5
16
  assert(filterTime(new Date(2024, 3, 3), `y年M月d日 h:mm`), '2024年4月3日 0:00');
6
17
  assert(filterTime(new Date(2024, 3, 3), `y年M月d日 h:mm`), '2024年4月3日 0:00');
7
18
  assert(filterTime(new Date(2024, 3, 3, 19, 26, 2, 100), `y年M月d日 h:mm:ss.SSS`), '2024年4月3日 19:26:02.100');
@@ -7,6 +7,7 @@
7
7
  color: #d4d4d4;
8
8
  font-family: Consolas, "Courier New", monospace;
9
9
  vertical-align: top;
10
+ text-decoration-line: none;
10
11
  }
11
12
 
12
13
  stamp {
@@ -27,7 +27,10 @@ var prototype = {
27
27
  return child;
28
28
  },
29
29
  appendChild(child) {
30
+ var _appendChild = this.appendChild
31
+ delete this.appendChild;
30
32
  appendChild(this, child, false);
33
+ if (_appendChild) this.appendChild = _appendChild;
31
34
  return child;
32
35
  },
33
36
  appendTo(target) {
@@ -12,7 +12,7 @@ var abs = Math.abs;
12
12
  */
13
13
  function slider() {
14
14
  var [autoplay, circle = true] = arguments;
15
- var outter = container.cloneNode();
15
+ var outter = null;
16
16
  {
17
17
  for (let cx = 0, dx = arguments.length; cx < dx; cx++) {
18
18
  let arg = arguments[cx];
@@ -25,6 +25,7 @@ function slider() {
25
25
  }
26
26
  }
27
27
  }
28
+ if (!outter) outter = container.cloneNode();
28
29
  var _imageMain = _slider.cloneNode();
29
30
  var _imageHelp = _slider.cloneNode();
30
31
  outter.src = function (index) {
@@ -5,7 +5,7 @@ render(page, {
5
5
  btn: button,
6
6
  slider(element) {
7
7
  var images = [1, 2, 3].map(function (i) {
8
- var ele = createElement(div);
8
+ var ele = document.createElement("div");
9
9
  text(ele, i);
10
10
  return ele;
11
11
  });
@@ -1,12 +1,11 @@
1
1
  & {
2
- height: 100px;
3
2
  width: 100%;
4
3
  background: #000;
5
4
  color: #fff;
6
5
  text-align: center;
7
6
  line-height: 100px;
8
7
  font-size: 60px;
9
- position: absolute;
8
+ position: relative;
10
9
  >div{
11
10
  position: relative;
12
11
  display: inline-block;
@@ -14,6 +13,9 @@
14
13
  height: 80px;
15
14
  }
16
15
  }
16
+ btn{
17
+ font-size: 14px;
18
+ }
17
19
 
18
20
  .slider {
19
21
  width: 100%;
@@ -99,7 +99,7 @@
99
99
  z-index: 1;
100
100
  }
101
101
  </style>
102
- <form onclick="event.preventDefault()">
102
+ <form onsubmit="event.preventDefault()">
103
103
  <xmenu -src="(t,i) in tags" @active="saveTagIndex(i)"></xmenu>
104
104
  <h2 head>
105
105
  <span -bind="name"></span>
@@ -125,8 +125,8 @@
125
125
  </span>
126
126
  </p4>
127
127
  </div>
128
- <div body onkeyup="!event.isComposing&&updatecode()" onkeydown.tab="keytab(event)" #coder codearea
129
- -elseif="tags[1].actived">
128
+ <div body onkeyup="!event.isComposing&&updatecode(event)" onkeydown.tab="keytab(event)" onkeyup.enter="ontab(false)"
129
+ #coder codearea -elseif="tags[1].actived">
130
130
  </div>
131
131
  <resultpad -if="tags[1].actived" .result #coderesult></resultpad>
132
132
  <div foot -if="tags[1].actived">
@@ -370,7 +370,42 @@
370
370
  c.contentEditable = true;
371
371
  };
372
372
  var trimspace = (_, a) => a ? "" : " ";
373
- var updatecode = lazy(function () {
373
+ var ensp = s => Array(s + 1).join("\u2002"/*&ensp*/);
374
+ var getEnspBefore = function (node) {
375
+ if (!node) return 0;
376
+ while (node && (node.nodeType !== 1 || !/^br$/i.test(node.tagName))) {
377
+ console.log(node)
378
+ node = node.previousSibling;
379
+ }
380
+ if (node) {
381
+ var next = node.nextSibling;
382
+ if (next) {
383
+ next = /^\u2002+/.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) {
374
409
  var trimreg = /[\s\u00a0\u2002\u0080]+([\}\{\;\[\]\(\)\,\>\<\+\-\*\&\^\/%!~:?])*/g;
375
410
  var innerText = coder.innerText;
376
411
  if (jstext.replace(trimreg, trimspace).trim() === innerText.replace(trimreg, trimspace).trim()) return;
@@ -424,6 +459,7 @@
424
459
  };
425
460
  var keytab = function (event) {
426
461
  event.preventDefault();
462
+ ontab();
427
463
  };
428
464
 
429
465
  var saveTagIndex = function (i) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.9.1",
3
+ "version": "4.9.2",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {