time-runner 1.0.0
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/README.md +104 -0
- package/dist/TimeRunner.d.ts +37 -0
- package/dist/Tools.d.ts +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/time-runner.css +1 -0
- package/dist/time-runner.d.ts +2 -0
- package/dist/time-runner.es.js +393 -0
- package/dist/time-runner.umd.js +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# 时间/计时/倒计时组件
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
这是一个展示时间、计时、倒计时的组件。
|
|
6
|
+
基于 React 开发。 主要功能包括:
|
|
7
|
+
- 展示当前时间
|
|
8
|
+
- 展示显示计时(电脑锁屏、笔记本盒盖不中断计时)
|
|
9
|
+
- 展示倒计时
|
|
10
|
+
- 些许动画效果
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
```bash
|
|
15
|
+
npm i time-runner
|
|
16
|
+
```
|
|
17
|
+
或者
|
|
18
|
+
```bash
|
|
19
|
+
yarn add time-runner
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 页面引入
|
|
23
|
+
```bash
|
|
24
|
+
import { TimeRunner } from "time-runner";
|
|
25
|
+
import "time-runner/dist/time-runner.css";
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 使用说明
|
|
29
|
+
```react
|
|
30
|
+
|
|
31
|
+
// 当前时间
|
|
32
|
+
<TimeRunner />
|
|
33
|
+
// 计时器
|
|
34
|
+
<TimeRunner showType="count" />
|
|
35
|
+
// 倒计时
|
|
36
|
+
<TimeRunner showType="2025-10-31" />
|
|
37
|
+
|
|
38
|
+
// 当前时间 + 翻牌效果
|
|
39
|
+
<TimeRunner mode="card" />
|
|
40
|
+
// 计时器 + 翻牌效果
|
|
41
|
+
<TimeRunner mode="card" showType="count" />
|
|
42
|
+
// 倒计时 + 翻牌效果
|
|
43
|
+
<TimeRunner mode="card" showType="2025-10-31" />
|
|
44
|
+
|
|
45
|
+
// 当前时间 + 翻转(左右)
|
|
46
|
+
<TimeRunner mode="cube-h" />
|
|
47
|
+
// 计时器 + 翻转(左右)
|
|
48
|
+
<TimeRunner mode="cube-h" showType="count" />
|
|
49
|
+
// 倒计时 + 翻转(左右)
|
|
50
|
+
<TimeRunner mode="cube-h" showType="2025-10-31" />
|
|
51
|
+
|
|
52
|
+
// 当前时间 + 翻转(上下)
|
|
53
|
+
<TimeRunner mode="cube-v" />
|
|
54
|
+
// 计时器 + 翻转(上下)
|
|
55
|
+
<TimeRunner mode="cube-v" showType="count" />
|
|
56
|
+
// 倒计时 + 翻转(上下)
|
|
57
|
+
<TimeRunner mode="cube-v" showType="2025-10-31" />
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 组件属性(props)
|
|
63
|
+
```js
|
|
64
|
+
/**
|
|
65
|
+
* 显示模式,默认:default
|
|
66
|
+
* default: 当前时间
|
|
67
|
+
* count: 计时器
|
|
68
|
+
* 指定时间:倒计时。
|
|
69
|
+
*/
|
|
70
|
+
showType?: string;
|
|
71
|
+
/**
|
|
72
|
+
* 动画模式,
|
|
73
|
+
* card:卡片
|
|
74
|
+
* cube-v:上下翻转
|
|
75
|
+
* cube-h:左右翻转
|
|
76
|
+
*/
|
|
77
|
+
mode?: TransMode;
|
|
78
|
+
/** 倒计时结束后执行的方法 */
|
|
79
|
+
finishCountFn?: Function;
|
|
80
|
+
/** 尺寸,默认40 */
|
|
81
|
+
size?: number;
|
|
82
|
+
/** 自定义样式类名 */
|
|
83
|
+
className?: string;
|
|
84
|
+
/** 背景颜色 */
|
|
85
|
+
bgColor?: string;
|
|
86
|
+
/** 边框颜色 */
|
|
87
|
+
borderColor?: string;
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 倒计时传入日期的格式
|
|
91
|
+
```
|
|
92
|
+
"YYYY-MM-DD",
|
|
93
|
+
"YYYY/MM/DD",
|
|
94
|
+
"YYYY-MM-DD HH:mm",
|
|
95
|
+
"YYYY/MM/DD HH:mm",
|
|
96
|
+
"YYYY-MM-DD HH:mm:ss",
|
|
97
|
+
"YYYY/MM/DD HH:mm:ss",
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# 更新日志
|
|
102
|
+
|
|
103
|
+
## [1.0.0] - 2025-10-07
|
|
104
|
+
### 首次发布
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 翻转模式类型:
|
|
3
|
+
*
|
|
4
|
+
* card: 翻牌翻转
|
|
5
|
+
* cube-v: 立方体上下翻转
|
|
6
|
+
* cube-h: 立方体左右翻转
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
type TransMode = "card" | "cube-v" | "cube-h";
|
|
10
|
+
interface PropsType {
|
|
11
|
+
/**
|
|
12
|
+
* 显示模式,默认:default
|
|
13
|
+
* default: 当前时间
|
|
14
|
+
* count: 计时器
|
|
15
|
+
* 指定时间:倒计时。
|
|
16
|
+
*/
|
|
17
|
+
showType?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 动画模式,
|
|
20
|
+
* card:卡片
|
|
21
|
+
* cube-v:上下翻转
|
|
22
|
+
* cube-h:左右翻转
|
|
23
|
+
*/
|
|
24
|
+
mode?: TransMode;
|
|
25
|
+
/** 尺寸,默认40 */
|
|
26
|
+
size?: number;
|
|
27
|
+
/** 自定义样式类名 */
|
|
28
|
+
className?: string;
|
|
29
|
+
/** 背景颜色 */
|
|
30
|
+
bgColor?: string;
|
|
31
|
+
/** 边框颜色 */
|
|
32
|
+
borderColor?: string;
|
|
33
|
+
/** 倒计时结束后执行的方法 */
|
|
34
|
+
finishCountFn?: Function;
|
|
35
|
+
}
|
|
36
|
+
declare const TimeCountdown: (props: PropsType) => import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export default TimeCountdown;
|
package/dist/Tools.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.time-runner{width:max-content;display:flex;justify-content:space-between;align-items:center;margin:0 auto;-webkit-user-select:none;user-select:none;position:relative;font-variant-numeric:tabular-nums}.time-runner span{font-size:var(--card-size, 40px);margin:0 3px;padding-bottom:3px;display:inline-block}.time-runner>p{margin:0 3px}.time-runner>div{font-size:var(--card-size, 40px)}.time-runner>div>p{color:#333}.clock-card{position:relative;height:var(--card-h, 80px);width:var(--card-w, 50px);box-shadow:0 1px 5px #333;border-radius:6px}.clock-card:before{content:"";position:absolute;top:50%;left:0;background-color:#999;width:100%;height:1.5px;z-index:3;overflow:hidden}.clock-card .clock-f,.clock-card .clock-b{width:100%;height:100%;position:absolute;top:0;left:0}.clock-card .clock-f p,.clock-card .clock-b p{position:absolute;left:0;height:50%;width:100%;margin-bottom:0;text-align:center;font-size:var(--card-size, 40px);background-color:var(--bgColor, #333);color:#fff;overflow:hidden;border-left:solid 1px var(--borderColor, #999);border-right:solid 1px var(--borderColor, #999)}.clock-card .clock-f p:nth-child(1),.clock-card .clock-b p:nth-child(1){top:0;border-top:solid 1px var(--borderColor, #999)}.clock-card .clock-f p:nth-child(2),.clock-card .clock-b p:nth-child(2){bottom:0;border-bottom:solid 1px var(--borderColor, #999)}.clock-card .clock-f p:nth-child(1){line-height:calc(var(--card-h, 80px) - 2px);transform-origin:bottom;backface-visibility:hidden;border-radius:7px 7px 0 0}.clock-card .clock-f p:nth-child(2){line-height:2px;border-radius:0 0 6px 6px}.clock-card .clock-f.run p:nth-child(1){transition:var(--delay) ease-in-out;transform:perspective(50px) rotateX(-180deg)}.clock-card .clock-b p:nth-child(1){line-height:calc(var(--card-h, 80px) - 2px);border-radius:7px 7px 0 0}.clock-card .clock-b p:nth-child(2){line-height:2px;transform-origin:top;transform:perspective(50px) rotateX(179.99deg);backface-visibility:hidden;border-radius:0 0 6px 6px}.clock-card .clock-b.run p:nth-child(2){transition:var(--delay) ease-in-out;transform:rotateX(0);z-index:2}.clock-cube-3d-v{width:var(--card-w, 50px);height:var(--card-h, 80px);position:relative;perspective:300px}.clock-cube-3d-v div{width:100%;height:100%;transform-style:preserve-3d;transform-origin:center center var(--transy)}.clock-cube-3d-v p{width:100%;height:100%;line-height:var(--card-h, 80px);text-align:center;font-size:var(--card-size, 40px);background-color:var(--bgColor, #333);border:solid 1px var(--borderColor, #999);color:#fff;margin-bottom:0;box-shadow:0 1px 2px #333;border-radius:2px}.clock-cube-3d-v p:nth-child(1){position:absolute;transform-origin:0 100%;transform:translateY(-100%) rotateX(90deg)}.clock-cube-3d-v.run div{transform:rotateX(-90deg);transition:var(--delay)}.clock-cube-3d-h{width:var(--card-w, 50px);height:var(--card-h, 80px);position:relative;perspective:300px}.clock-cube-3d-h div{width:100%;height:100%;transform-style:preserve-3d;transform-origin:center center var(--transx)}.clock-cube-3d-h p{width:100%;height:100%;line-height:var(--card-h, 80px);text-align:center;font-size:var(--card-size, 40px);background-color:var(--bgColor, #333);border:solid 1px var(--borderColor, #999);color:#fff;margin-bottom:0;box-shadow:0 1px 2px #333;border-radius:2px}.clock-cube-3d-h p:nth-child(1){position:absolute;transform-origin:100% 0;transform:translate(-100%) rotateY(-90deg)}.clock-cube-3d-h.run div{transform:rotateY(90deg);transition:var(--delay)}
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import { jsx as c, Fragment as et, jsxs as W } from "react/jsx-runtime";
|
|
2
|
+
import { memo as ft, useState as ct, useRef as lt, useEffect as K } from "react";
|
|
3
|
+
function ht(m) {
|
|
4
|
+
return m && m.__esModule && Object.prototype.hasOwnProperty.call(m, "default") ? m.default : m;
|
|
5
|
+
}
|
|
6
|
+
var G = { exports: {} }, mt = G.exports, it;
|
|
7
|
+
function $t() {
|
|
8
|
+
return it || (it = 1, (function(m, d) {
|
|
9
|
+
(function(l, v) {
|
|
10
|
+
m.exports = v();
|
|
11
|
+
})(mt, (function() {
|
|
12
|
+
var l = 1e3, v = 6e4, Y = 36e5, k = "millisecond", g = "second", O = "minute", f = "hour", D = "day", x = "week", b = "month", Z = "quarter", $ = "year", S = "date", V = "Invalid Date", q = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, X = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, _ = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(s) {
|
|
13
|
+
var r = ["th", "st", "nd", "rd"], t = s % 100;
|
|
14
|
+
return "[" + s + (r[(t - 20) % 10] || r[t] || r[0]) + "]";
|
|
15
|
+
} }, A = function(s, r, t) {
|
|
16
|
+
var n = String(s);
|
|
17
|
+
return !n || n.length >= r ? s : "" + Array(r + 1 - n.length).join(t) + s;
|
|
18
|
+
}, z = { s: A, z: function(s) {
|
|
19
|
+
var r = -s.utcOffset(), t = Math.abs(r), n = Math.floor(t / 60), e = t % 60;
|
|
20
|
+
return (r <= 0 ? "+" : "-") + A(n, 2, "0") + ":" + A(e, 2, "0");
|
|
21
|
+
}, m: function s(r, t) {
|
|
22
|
+
if (r.date() < t.date()) return -s(t, r);
|
|
23
|
+
var n = 12 * (t.year() - r.year()) + (t.month() - r.month()), e = r.clone().add(n, b), i = t - e < 0, a = r.clone().add(n + (i ? -1 : 1), b);
|
|
24
|
+
return +(-(n + (t - e) / (i ? e - a : a - e)) || 0);
|
|
25
|
+
}, a: function(s) {
|
|
26
|
+
return s < 0 ? Math.ceil(s) || 0 : Math.floor(s);
|
|
27
|
+
}, p: function(s) {
|
|
28
|
+
return { M: b, y: $, w: x, d: D, D: S, h: f, m: O, s: g, ms: k, Q: Z }[s] || String(s || "").toLowerCase().replace(/s$/, "");
|
|
29
|
+
}, u: function(s) {
|
|
30
|
+
return s === void 0;
|
|
31
|
+
} }, j = "en", H = {};
|
|
32
|
+
H[j] = _;
|
|
33
|
+
var nt = "$isDayjsObject", tt = function(s) {
|
|
34
|
+
return s instanceof B || !(!s || !s[nt]);
|
|
35
|
+
}, P = function s(r, t, n) {
|
|
36
|
+
var e;
|
|
37
|
+
if (!r) return j;
|
|
38
|
+
if (typeof r == "string") {
|
|
39
|
+
var i = r.toLowerCase();
|
|
40
|
+
H[i] && (e = i), t && (H[i] = t, e = i);
|
|
41
|
+
var a = r.split("-");
|
|
42
|
+
if (!e && a.length > 1) return s(a[0]);
|
|
43
|
+
} else {
|
|
44
|
+
var o = r.name;
|
|
45
|
+
H[o] = r, e = o;
|
|
46
|
+
}
|
|
47
|
+
return !n && e && (j = e), e || !n && j;
|
|
48
|
+
}, p = function(s, r) {
|
|
49
|
+
if (tt(s)) return s.clone();
|
|
50
|
+
var t = typeof r == "object" ? r : {};
|
|
51
|
+
return t.date = s, t.args = arguments, new B(t);
|
|
52
|
+
}, u = z;
|
|
53
|
+
u.l = P, u.i = tt, u.w = function(s, r) {
|
|
54
|
+
return p(s, { locale: r.$L, utc: r.$u, x: r.$x, $offset: r.$offset });
|
|
55
|
+
};
|
|
56
|
+
var B = (function() {
|
|
57
|
+
function s(t) {
|
|
58
|
+
this.$L = P(t.locale, null, !0), this.parse(t), this.$x = this.$x || t.x || {}, this[nt] = !0;
|
|
59
|
+
}
|
|
60
|
+
var r = s.prototype;
|
|
61
|
+
return r.parse = function(t) {
|
|
62
|
+
this.$d = (function(n) {
|
|
63
|
+
var e = n.date, i = n.utc;
|
|
64
|
+
if (e === null) return /* @__PURE__ */ new Date(NaN);
|
|
65
|
+
if (u.u(e)) return /* @__PURE__ */ new Date();
|
|
66
|
+
if (e instanceof Date) return new Date(e);
|
|
67
|
+
if (typeof e == "string" && !/Z$/i.test(e)) {
|
|
68
|
+
var a = e.match(q);
|
|
69
|
+
if (a) {
|
|
70
|
+
var o = a[2] - 1 || 0, h = (a[7] || "0").substring(0, 3);
|
|
71
|
+
return i ? new Date(Date.UTC(a[1], o, a[3] || 1, a[4] || 0, a[5] || 0, a[6] || 0, h)) : new Date(a[1], o, a[3] || 1, a[4] || 0, a[5] || 0, a[6] || 0, h);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return new Date(e);
|
|
75
|
+
})(t), this.init();
|
|
76
|
+
}, r.init = function() {
|
|
77
|
+
var t = this.$d;
|
|
78
|
+
this.$y = t.getFullYear(), this.$M = t.getMonth(), this.$D = t.getDate(), this.$W = t.getDay(), this.$H = t.getHours(), this.$m = t.getMinutes(), this.$s = t.getSeconds(), this.$ms = t.getMilliseconds();
|
|
79
|
+
}, r.$utils = function() {
|
|
80
|
+
return u;
|
|
81
|
+
}, r.isValid = function() {
|
|
82
|
+
return this.$d.toString() !== V;
|
|
83
|
+
}, r.isSame = function(t, n) {
|
|
84
|
+
var e = p(t);
|
|
85
|
+
return this.startOf(n) <= e && e <= this.endOf(n);
|
|
86
|
+
}, r.isAfter = function(t, n) {
|
|
87
|
+
return p(t) < this.startOf(n);
|
|
88
|
+
}, r.isBefore = function(t, n) {
|
|
89
|
+
return this.endOf(n) < p(t);
|
|
90
|
+
}, r.$g = function(t, n, e) {
|
|
91
|
+
return u.u(t) ? this[n] : this.set(e, t);
|
|
92
|
+
}, r.unix = function() {
|
|
93
|
+
return Math.floor(this.valueOf() / 1e3);
|
|
94
|
+
}, r.valueOf = function() {
|
|
95
|
+
return this.$d.getTime();
|
|
96
|
+
}, r.startOf = function(t, n) {
|
|
97
|
+
var e = this, i = !!u.u(n) || n, a = u.p(t), o = function(N, w) {
|
|
98
|
+
var C = u.w(e.$u ? Date.UTC(e.$y, w, N) : new Date(e.$y, w, N), e);
|
|
99
|
+
return i ? C : C.endOf(D);
|
|
100
|
+
}, h = function(N, w) {
|
|
101
|
+
return u.w(e.toDate()[N].apply(e.toDate("s"), (i ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(w)), e);
|
|
102
|
+
}, M = this.$W, y = this.$M, T = this.$D, F = "set" + (this.$u ? "UTC" : "");
|
|
103
|
+
switch (a) {
|
|
104
|
+
case $:
|
|
105
|
+
return i ? o(1, 0) : o(31, 11);
|
|
106
|
+
case b:
|
|
107
|
+
return i ? o(1, y) : o(0, y + 1);
|
|
108
|
+
case x:
|
|
109
|
+
var L = this.$locale().weekStart || 0, R = (M < L ? M + 7 : M) - L;
|
|
110
|
+
return o(i ? T - R : T + (6 - R), y);
|
|
111
|
+
case D:
|
|
112
|
+
case S:
|
|
113
|
+
return h(F + "Hours", 0);
|
|
114
|
+
case f:
|
|
115
|
+
return h(F + "Minutes", 1);
|
|
116
|
+
case O:
|
|
117
|
+
return h(F + "Seconds", 2);
|
|
118
|
+
case g:
|
|
119
|
+
return h(F + "Milliseconds", 3);
|
|
120
|
+
default:
|
|
121
|
+
return this.clone();
|
|
122
|
+
}
|
|
123
|
+
}, r.endOf = function(t) {
|
|
124
|
+
return this.startOf(t, !1);
|
|
125
|
+
}, r.$set = function(t, n) {
|
|
126
|
+
var e, i = u.p(t), a = "set" + (this.$u ? "UTC" : ""), o = (e = {}, e[D] = a + "Date", e[S] = a + "Date", e[b] = a + "Month", e[$] = a + "FullYear", e[f] = a + "Hours", e[O] = a + "Minutes", e[g] = a + "Seconds", e[k] = a + "Milliseconds", e)[i], h = i === D ? this.$D + (n - this.$W) : n;
|
|
127
|
+
if (i === b || i === $) {
|
|
128
|
+
var M = this.clone().set(S, 1);
|
|
129
|
+
M.$d[o](h), M.init(), this.$d = M.set(S, Math.min(this.$D, M.daysInMonth())).$d;
|
|
130
|
+
} else o && this.$d[o](h);
|
|
131
|
+
return this.init(), this;
|
|
132
|
+
}, r.set = function(t, n) {
|
|
133
|
+
return this.clone().$set(t, n);
|
|
134
|
+
}, r.get = function(t) {
|
|
135
|
+
return this[u.p(t)]();
|
|
136
|
+
}, r.add = function(t, n) {
|
|
137
|
+
var e, i = this;
|
|
138
|
+
t = Number(t);
|
|
139
|
+
var a = u.p(n), o = function(y) {
|
|
140
|
+
var T = p(i);
|
|
141
|
+
return u.w(T.date(T.date() + Math.round(y * t)), i);
|
|
142
|
+
};
|
|
143
|
+
if (a === b) return this.set(b, this.$M + t);
|
|
144
|
+
if (a === $) return this.set($, this.$y + t);
|
|
145
|
+
if (a === D) return o(1);
|
|
146
|
+
if (a === x) return o(7);
|
|
147
|
+
var h = (e = {}, e[O] = v, e[f] = Y, e[g] = l, e)[a] || 1, M = this.$d.getTime() + t * h;
|
|
148
|
+
return u.w(M, this);
|
|
149
|
+
}, r.subtract = function(t, n) {
|
|
150
|
+
return this.add(-1 * t, n);
|
|
151
|
+
}, r.format = function(t) {
|
|
152
|
+
var n = this, e = this.$locale();
|
|
153
|
+
if (!this.isValid()) return e.invalidDate || V;
|
|
154
|
+
var i = t || "YYYY-MM-DDTHH:mm:ssZ", a = u.z(this), o = this.$H, h = this.$m, M = this.$M, y = e.weekdays, T = e.months, F = e.meridiem, L = function(w, C, U, Q) {
|
|
155
|
+
return w && (w[C] || w(n, i)) || U[C].slice(0, Q);
|
|
156
|
+
}, R = function(w) {
|
|
157
|
+
return u.s(o % 12 || 12, w, "0");
|
|
158
|
+
}, N = F || function(w, C, U) {
|
|
159
|
+
var Q = w < 12 ? "AM" : "PM";
|
|
160
|
+
return U ? Q.toLowerCase() : Q;
|
|
161
|
+
};
|
|
162
|
+
return i.replace(X, (function(w, C) {
|
|
163
|
+
return C || (function(U) {
|
|
164
|
+
switch (U) {
|
|
165
|
+
case "YY":
|
|
166
|
+
return String(n.$y).slice(-2);
|
|
167
|
+
case "YYYY":
|
|
168
|
+
return u.s(n.$y, 4, "0");
|
|
169
|
+
case "M":
|
|
170
|
+
return M + 1;
|
|
171
|
+
case "MM":
|
|
172
|
+
return u.s(M + 1, 2, "0");
|
|
173
|
+
case "MMM":
|
|
174
|
+
return L(e.monthsShort, M, T, 3);
|
|
175
|
+
case "MMMM":
|
|
176
|
+
return L(T, M);
|
|
177
|
+
case "D":
|
|
178
|
+
return n.$D;
|
|
179
|
+
case "DD":
|
|
180
|
+
return u.s(n.$D, 2, "0");
|
|
181
|
+
case "d":
|
|
182
|
+
return String(n.$W);
|
|
183
|
+
case "dd":
|
|
184
|
+
return L(e.weekdaysMin, n.$W, y, 2);
|
|
185
|
+
case "ddd":
|
|
186
|
+
return L(e.weekdaysShort, n.$W, y, 3);
|
|
187
|
+
case "dddd":
|
|
188
|
+
return y[n.$W];
|
|
189
|
+
case "H":
|
|
190
|
+
return String(o);
|
|
191
|
+
case "HH":
|
|
192
|
+
return u.s(o, 2, "0");
|
|
193
|
+
case "h":
|
|
194
|
+
return R(1);
|
|
195
|
+
case "hh":
|
|
196
|
+
return R(2);
|
|
197
|
+
case "a":
|
|
198
|
+
return N(o, h, !0);
|
|
199
|
+
case "A":
|
|
200
|
+
return N(o, h, !1);
|
|
201
|
+
case "m":
|
|
202
|
+
return String(h);
|
|
203
|
+
case "mm":
|
|
204
|
+
return u.s(h, 2, "0");
|
|
205
|
+
case "s":
|
|
206
|
+
return String(n.$s);
|
|
207
|
+
case "ss":
|
|
208
|
+
return u.s(n.$s, 2, "0");
|
|
209
|
+
case "SSS":
|
|
210
|
+
return u.s(n.$ms, 3, "0");
|
|
211
|
+
case "Z":
|
|
212
|
+
return a;
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
})(w) || a.replace(":", "");
|
|
216
|
+
}));
|
|
217
|
+
}, r.utcOffset = function() {
|
|
218
|
+
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
|
|
219
|
+
}, r.diff = function(t, n, e) {
|
|
220
|
+
var i, a = this, o = u.p(n), h = p(t), M = (h.utcOffset() - this.utcOffset()) * v, y = this - h, T = function() {
|
|
221
|
+
return u.m(a, h);
|
|
222
|
+
};
|
|
223
|
+
switch (o) {
|
|
224
|
+
case $:
|
|
225
|
+
i = T() / 12;
|
|
226
|
+
break;
|
|
227
|
+
case b:
|
|
228
|
+
i = T();
|
|
229
|
+
break;
|
|
230
|
+
case Z:
|
|
231
|
+
i = T() / 3;
|
|
232
|
+
break;
|
|
233
|
+
case x:
|
|
234
|
+
i = (y - M) / 6048e5;
|
|
235
|
+
break;
|
|
236
|
+
case D:
|
|
237
|
+
i = (y - M) / 864e5;
|
|
238
|
+
break;
|
|
239
|
+
case f:
|
|
240
|
+
i = y / Y;
|
|
241
|
+
break;
|
|
242
|
+
case O:
|
|
243
|
+
i = y / v;
|
|
244
|
+
break;
|
|
245
|
+
case g:
|
|
246
|
+
i = y / l;
|
|
247
|
+
break;
|
|
248
|
+
default:
|
|
249
|
+
i = y;
|
|
250
|
+
}
|
|
251
|
+
return e ? i : u.a(i);
|
|
252
|
+
}, r.daysInMonth = function() {
|
|
253
|
+
return this.endOf(b).$D;
|
|
254
|
+
}, r.$locale = function() {
|
|
255
|
+
return H[this.$L];
|
|
256
|
+
}, r.locale = function(t, n) {
|
|
257
|
+
if (!t) return this.$L;
|
|
258
|
+
var e = this.clone(), i = P(t, n, !0);
|
|
259
|
+
return i && (e.$L = i), e;
|
|
260
|
+
}, r.clone = function() {
|
|
261
|
+
return u.w(this.$d, this);
|
|
262
|
+
}, r.toDate = function() {
|
|
263
|
+
return new Date(this.valueOf());
|
|
264
|
+
}, r.toJSON = function() {
|
|
265
|
+
return this.isValid() ? this.toISOString() : null;
|
|
266
|
+
}, r.toISOString = function() {
|
|
267
|
+
return this.$d.toISOString();
|
|
268
|
+
}, r.toString = function() {
|
|
269
|
+
return this.$d.toUTCString();
|
|
270
|
+
}, s;
|
|
271
|
+
})(), st = B.prototype;
|
|
272
|
+
return p.prototype = st, [["$ms", k], ["$s", g], ["$m", O], ["$H", f], ["$W", D], ["$M", b], ["$y", $], ["$D", S]].forEach((function(s) {
|
|
273
|
+
st[s[1]] = function(r) {
|
|
274
|
+
return this.$g(r, s[0], s[1]);
|
|
275
|
+
};
|
|
276
|
+
})), p.extend = function(s, r) {
|
|
277
|
+
return s.$i || (s(r, B, p), s.$i = !0), p;
|
|
278
|
+
}, p.locale = P, p.isDayjs = tt, p.unix = function(s) {
|
|
279
|
+
return p(1e3 * s);
|
|
280
|
+
}, p.en = H[j], p.Ls = H, p.p = {}, p;
|
|
281
|
+
}));
|
|
282
|
+
})(G)), G.exports;
|
|
283
|
+
}
|
|
284
|
+
var pt = $t();
|
|
285
|
+
const J = /* @__PURE__ */ ht(pt), E = 60, Mt = [
|
|
286
|
+
"YYYY-MM-DD",
|
|
287
|
+
"YYYY/MM/DD",
|
|
288
|
+
"YYYY-MM-DD HH:mm",
|
|
289
|
+
"YYYY/MM/DD HH:mm",
|
|
290
|
+
"YYYY-MM-DD HH:mm:ss",
|
|
291
|
+
"YYYY/MM/DD HH:mm:ss"
|
|
292
|
+
], at = (m) => {
|
|
293
|
+
if (!rt(m))
|
|
294
|
+
return "00:00:00";
|
|
295
|
+
const d = J(m).diff(J());
|
|
296
|
+
if (d <= 0)
|
|
297
|
+
return "00:00:00";
|
|
298
|
+
const l = Math.floor(d / 1e3), v = Math.floor(l / 86400), Y = Math.floor(l % 86400 / 3600), k = Math.floor(l % 3600 / 60), g = l % 60;
|
|
299
|
+
return `${v ? `${v}:` : ""}${`${Y}`.padStart(2, "0")}:${`${k}`.padStart(2, "0")}:${`${g}`.padStart(2, "0")}`;
|
|
300
|
+
}, ut = (m) => {
|
|
301
|
+
const d = (l) => `${l}`.padStart(2, "0");
|
|
302
|
+
return `${d(Math.floor(m / E / E))}:${d(Math.floor(m / E) % E)}:${d(m % E)}`;
|
|
303
|
+
}, rt = (m) => Mt.some((d) => J(m, d, !0).isValid()), ot = "HH:mm:ss", dt = 900, gt = (m) => {
|
|
304
|
+
const { mode: d, showType: l = "default", size: v = 40, className: Y, bgColor: k, borderColor: g, finishCountFn: O } = m, [f, D] = ct(
|
|
305
|
+
l === "count" ? ut(0) : l === "default" ? J().format(ot) : at(l)
|
|
306
|
+
), x = lt({
|
|
307
|
+
t: null
|
|
308
|
+
}), b = {
|
|
309
|
+
"--card-size": `${v}px`,
|
|
310
|
+
"--card-w": `${v * 1.25}px`,
|
|
311
|
+
"--card-h": `${v * 2}px`,
|
|
312
|
+
// 下面两个必须是一个确定的数字,不能是表达式
|
|
313
|
+
"--transx": `${-v * 1.25 / 2}px`,
|
|
314
|
+
"--transy": `${-v}px`,
|
|
315
|
+
"--delay": `${dt / 1e3}s`,
|
|
316
|
+
"--bgColor": k,
|
|
317
|
+
"--borderColor": g
|
|
318
|
+
};
|
|
319
|
+
K(() => {
|
|
320
|
+
let $ = Date.now();
|
|
321
|
+
x.current.t && (clearInterval(x.current.t), x.current.t = null, $ = Date.now()), x.current.t = setInterval(() => {
|
|
322
|
+
let S = () => "";
|
|
323
|
+
l === "count" ? S = () => ut(Math.floor((Date.now() - $) / 1e3)) : l === "default" ? S = () => J().format(ot) : S = () => at(l), D(S());
|
|
324
|
+
}, 1e3);
|
|
325
|
+
}, [l]), K(() => {
|
|
326
|
+
rt(l) && f === "00:00:00" && O && setTimeout(() => {
|
|
327
|
+
O();
|
|
328
|
+
}, 1e3);
|
|
329
|
+
}, [f, l, O]);
|
|
330
|
+
const Z = () => {
|
|
331
|
+
if (!f)
|
|
332
|
+
return null;
|
|
333
|
+
const $ = f.split(":"), S = $[$.length - 3].split(""), V = $[$.length - 2].split(""), q = $[$.length - 1].split(""), X = $.length === 4 ? $[0].split("") : [], _ = rt(l), A = X.map((j, H) => /* @__PURE__ */ c(I, { mode: d, time: +j, limit: _ ? -9 : 9 }, H)), z = /* @__PURE__ */ c("span", { children: ":" });
|
|
334
|
+
return /* @__PURE__ */ W(et, { children: [
|
|
335
|
+
A.length ? /* @__PURE__ */ W(et, { children: [
|
|
336
|
+
A,
|
|
337
|
+
_ ? /* @__PURE__ */ c("p", { children: "天" }) : z
|
|
338
|
+
] }) : null,
|
|
339
|
+
/* @__PURE__ */ c(I, { mode: d, time: +S[0], limit: _ ? -2 : 2 }),
|
|
340
|
+
/* @__PURE__ */ c(I, { mode: d, time: +S[1], limit: _ ? -9 : 9 }),
|
|
341
|
+
_ ? /* @__PURE__ */ c("p", { children: "小时" }) : z,
|
|
342
|
+
/* @__PURE__ */ c(I, { mode: d, time: +V[0], limit: _ ? -5 : 5 }),
|
|
343
|
+
/* @__PURE__ */ c(I, { mode: d, time: +V[1], limit: _ ? -9 : 9 }),
|
|
344
|
+
_ ? /* @__PURE__ */ c("p", { children: "分" }) : z,
|
|
345
|
+
/* @__PURE__ */ c(I, { mode: d, time: +q[0], limit: _ ? -5 : 5 }),
|
|
346
|
+
/* @__PURE__ */ c(I, { mode: d, time: +q[1], limit: _ ? -9 : 9 }),
|
|
347
|
+
_ && /* @__PURE__ */ c("p", { children: "秒" })
|
|
348
|
+
] });
|
|
349
|
+
};
|
|
350
|
+
return /* @__PURE__ */ c("div", { className: `time-runner ${Y || ""}`, style: b, children: Z() });
|
|
351
|
+
}, Dt = (m) => {
|
|
352
|
+
const { time: d, limit: l, mode: v } = m, [Y, k] = ct(!1), g = lt({
|
|
353
|
+
t: d
|
|
354
|
+
});
|
|
355
|
+
return K(() => {
|
|
356
|
+
d !== g.current.t && k(!0);
|
|
357
|
+
}, [d]), K(() => {
|
|
358
|
+
Y && setTimeout(() => {
|
|
359
|
+
g.current.t = d, k(!1);
|
|
360
|
+
}, dt);
|
|
361
|
+
}, [Y, d]), /* @__PURE__ */ c(et, { children: (() => {
|
|
362
|
+
const { t: f } = g.current;
|
|
363
|
+
let D = f;
|
|
364
|
+
switch (l > 0 ? D = f >= l ? 0 : f + 1 : D = f <= 0 ? Math.abs(l) : f - 1, v) {
|
|
365
|
+
case "card":
|
|
366
|
+
return /* @__PURE__ */ W("div", { className: "clock-card", children: [
|
|
367
|
+
/* @__PURE__ */ W("div", { className: `clock-b ${Y ? "run" : ""}`, children: [
|
|
368
|
+
/* @__PURE__ */ c("p", { children: D }),
|
|
369
|
+
/* @__PURE__ */ c("p", { children: D })
|
|
370
|
+
] }),
|
|
371
|
+
/* @__PURE__ */ W("div", { className: `clock-f ${Y ? "run" : ""}`, children: [
|
|
372
|
+
/* @__PURE__ */ c("p", { children: f }),
|
|
373
|
+
/* @__PURE__ */ c("p", { children: f })
|
|
374
|
+
] })
|
|
375
|
+
] });
|
|
376
|
+
case "cube-v":
|
|
377
|
+
return /* @__PURE__ */ c("div", { className: `clock-cube-3d-v ${Y ? "run" : ""}`, children: /* @__PURE__ */ W("div", { children: [
|
|
378
|
+
/* @__PURE__ */ c("p", { children: D }),
|
|
379
|
+
/* @__PURE__ */ c("p", { children: f })
|
|
380
|
+
] }) });
|
|
381
|
+
case "cube-h":
|
|
382
|
+
return /* @__PURE__ */ c("div", { className: `clock-cube-3d-h ${Y ? "run" : ""}`, children: /* @__PURE__ */ W("div", { children: [
|
|
383
|
+
/* @__PURE__ */ c("p", { children: D }),
|
|
384
|
+
/* @__PURE__ */ c("p", { children: f })
|
|
385
|
+
] }) });
|
|
386
|
+
default:
|
|
387
|
+
return /* @__PURE__ */ c("div", { children: /* @__PURE__ */ c("p", { children: f }) });
|
|
388
|
+
}
|
|
389
|
+
})() });
|
|
390
|
+
}, I = ft(Dt);
|
|
391
|
+
export {
|
|
392
|
+
gt as TimeRunner
|
|
393
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(j,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],o):(j=typeof globalThis<"u"?globalThis:j||self,o(j["time-runner"]={},j.jsxRuntime,j.React))})(this,(function(j,o,H){"use strict";function ut($){return $&&$.__esModule&&Object.prototype.hasOwnProperty.call($,"default")?$.default:$}var P={exports:{}},ft=P.exports,rt;function lt(){return rt||(rt=1,(function($,l){(function(f,v){$.exports=v()})(ft,(function(){var f=1e3,v=6e4,Y=36e5,x="millisecond",g="second",b="minute",d="hour",D="day",k="week",O="month",B="quarter",m="year",S="date",z="Invalid Date",Q=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,tt=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,T={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(s){var r=["th","st","nd","rd"],t=s%100;return"["+s+(r[(t-20)%10]||r[t]||r[0])+"]"}},A=function(s,r,t){var n=String(s);return!n||n.length>=r?s:""+Array(r+1-n.length).join(t)+s},U={s:A,z:function(s){var r=-s.utcOffset(),t=Math.abs(r),n=Math.floor(t/60),e=t%60;return(r<=0?"+":"-")+A(n,2,"0")+":"+A(e,2,"0")},m:function s(r,t){if(r.date()<t.date())return-s(t,r);var n=12*(t.year()-r.year())+(t.month()-r.month()),e=r.clone().add(n,O),i=t-e<0,a=r.clone().add(n+(i?-1:1),O);return+(-(n+(t-e)/(i?e-a:a-e))||0)},a:function(s){return s<0?Math.ceil(s)||0:Math.floor(s)},p:function(s){return{M:O,y:m,w:k,d:D,D:S,h:d,m:b,s:g,ms:x,Q:B}[s]||String(s||"").toLowerCase().replace(/s$/,"")},u:function(s){return s===void 0}},F="en",C={};C[F]=T;var ot="$isDayjsObject",et=function(s){return s instanceof K||!(!s||!s[ot])},G=function s(r,t,n){var e;if(!r)return F;if(typeof r=="string"){var i=r.toLowerCase();C[i]&&(e=i),t&&(C[i]=t,e=i);var a=r.split("-");if(!e&&a.length>1)return s(a[0])}else{var u=r.name;C[u]=r,e=u}return!n&&e&&(F=e),e||!n&&F},p=function(s,r){if(et(s))return s.clone();var t=typeof r=="object"?r:{};return t.date=s,t.args=arguments,new K(t)},c=U;c.l=G,c.i=et,c.w=function(s,r){return p(s,{locale:r.$L,utc:r.$u,x:r.$x,$offset:r.$offset})};var K=(function(){function s(t){this.$L=G(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[ot]=!0}var r=s.prototype;return r.parse=function(t){this.$d=(function(n){var e=n.date,i=n.utc;if(e===null)return new Date(NaN);if(c.u(e))return new Date;if(e instanceof Date)return new Date(e);if(typeof e=="string"&&!/Z$/i.test(e)){var a=e.match(Q);if(a){var u=a[2]-1||0,h=(a[7]||"0").substring(0,3);return i?new Date(Date.UTC(a[1],u,a[3]||1,a[4]||0,a[5]||0,a[6]||0,h)):new Date(a[1],u,a[3]||1,a[4]||0,a[5]||0,a[6]||0,h)}}return new Date(e)})(t),this.init()},r.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},r.$utils=function(){return c},r.isValid=function(){return this.$d.toString()!==z},r.isSame=function(t,n){var e=p(t);return this.startOf(n)<=e&&e<=this.endOf(n)},r.isAfter=function(t,n){return p(t)<this.startOf(n)},r.isBefore=function(t,n){return this.endOf(n)<p(t)},r.$g=function(t,n,e){return c.u(t)?this[n]:this.set(e,t)},r.unix=function(){return Math.floor(this.valueOf()/1e3)},r.valueOf=function(){return this.$d.getTime()},r.startOf=function(t,n){var e=this,i=!!c.u(n)||n,a=c.p(t),u=function(W,w){var L=c.w(e.$u?Date.UTC(e.$y,w,W):new Date(e.$y,w,W),e);return i?L:L.endOf(D)},h=function(W,w){return c.w(e.toDate()[W].apply(e.toDate("s"),(i?[0,0,0,0]:[23,59,59,999]).slice(w)),e)},M=this.$W,y=this.$M,_=this.$D,E="set"+(this.$u?"UTC":"");switch(a){case m:return i?u(1,0):u(31,11);case O:return i?u(1,y):u(0,y+1);case k:var I=this.$locale().weekStart||0,J=(M<I?M+7:M)-I;return u(i?_-J:_+(6-J),y);case D:case S:return h(E+"Hours",0);case d:return h(E+"Minutes",1);case b:return h(E+"Seconds",2);case g:return h(E+"Milliseconds",3);default:return this.clone()}},r.endOf=function(t){return this.startOf(t,!1)},r.$set=function(t,n){var e,i=c.p(t),a="set"+(this.$u?"UTC":""),u=(e={},e[D]=a+"Date",e[S]=a+"Date",e[O]=a+"Month",e[m]=a+"FullYear",e[d]=a+"Hours",e[b]=a+"Minutes",e[g]=a+"Seconds",e[x]=a+"Milliseconds",e)[i],h=i===D?this.$D+(n-this.$W):n;if(i===O||i===m){var M=this.clone().set(S,1);M.$d[u](h),M.init(),this.$d=M.set(S,Math.min(this.$D,M.daysInMonth())).$d}else u&&this.$d[u](h);return this.init(),this},r.set=function(t,n){return this.clone().$set(t,n)},r.get=function(t){return this[c.p(t)]()},r.add=function(t,n){var e,i=this;t=Number(t);var a=c.p(n),u=function(y){var _=p(i);return c.w(_.date(_.date()+Math.round(y*t)),i)};if(a===O)return this.set(O,this.$M+t);if(a===m)return this.set(m,this.$y+t);if(a===D)return u(1);if(a===k)return u(7);var h=(e={},e[b]=v,e[d]=Y,e[g]=f,e)[a]||1,M=this.$d.getTime()+t*h;return c.w(M,this)},r.subtract=function(t,n){return this.add(-1*t,n)},r.format=function(t){var n=this,e=this.$locale();if(!this.isValid())return e.invalidDate||z;var i=t||"YYYY-MM-DDTHH:mm:ssZ",a=c.z(this),u=this.$H,h=this.$m,M=this.$M,y=e.weekdays,_=e.months,E=e.meridiem,I=function(w,L,Z,X){return w&&(w[L]||w(n,i))||Z[L].slice(0,X)},J=function(w){return c.s(u%12||12,w,"0")},W=E||function(w,L,Z){var X=w<12?"AM":"PM";return Z?X.toLowerCase():X};return i.replace(tt,(function(w,L){return L||(function(Z){switch(Z){case"YY":return String(n.$y).slice(-2);case"YYYY":return c.s(n.$y,4,"0");case"M":return M+1;case"MM":return c.s(M+1,2,"0");case"MMM":return I(e.monthsShort,M,_,3);case"MMMM":return I(_,M);case"D":return n.$D;case"DD":return c.s(n.$D,2,"0");case"d":return String(n.$W);case"dd":return I(e.weekdaysMin,n.$W,y,2);case"ddd":return I(e.weekdaysShort,n.$W,y,3);case"dddd":return y[n.$W];case"H":return String(u);case"HH":return c.s(u,2,"0");case"h":return J(1);case"hh":return J(2);case"a":return W(u,h,!0);case"A":return W(u,h,!1);case"m":return String(h);case"mm":return c.s(h,2,"0");case"s":return String(n.$s);case"ss":return c.s(n.$s,2,"0");case"SSS":return c.s(n.$ms,3,"0");case"Z":return a}return null})(w)||a.replace(":","")}))},r.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},r.diff=function(t,n,e){var i,a=this,u=c.p(n),h=p(t),M=(h.utcOffset()-this.utcOffset())*v,y=this-h,_=function(){return c.m(a,h)};switch(u){case m:i=_()/12;break;case O:i=_();break;case B:i=_()/3;break;case k:i=(y-M)/6048e5;break;case D:i=(y-M)/864e5;break;case d:i=y/Y;break;case b:i=y/v;break;case g:i=y/f;break;default:i=y}return e?i:c.a(i)},r.daysInMonth=function(){return this.endOf(O).$D},r.$locale=function(){return C[this.$L]},r.locale=function(t,n){if(!t)return this.$L;var e=this.clone(),i=G(t,n,!0);return i&&(e.$L=i),e},r.clone=function(){return c.w(this.$d,this)},r.toDate=function(){return new Date(this.valueOf())},r.toJSON=function(){return this.isValid()?this.toISOString():null},r.toISOString=function(){return this.$d.toISOString()},r.toString=function(){return this.$d.toUTCString()},s})(),ct=K.prototype;return p.prototype=ct,[["$ms",x],["$s",g],["$m",b],["$H",d],["$W",D],["$M",O],["$y",m],["$D",S]].forEach((function(s){ct[s[1]]=function(r){return this.$g(r,s[0],s[1])}})),p.extend=function(s,r){return s.$i||(s(r,K,p),s.$i=!0),p},p.locale=G,p.isDayjs=et,p.unix=function(s){return p(1e3*s)},p.en=C[F],p.Ls=C,p.p={},p}))})(P)),P.exports}var dt=lt();const V=ut(dt),q=60,ht=["YYYY-MM-DD","YYYY/MM/DD","YYYY-MM-DD HH:mm","YYYY/MM/DD HH:mm","YYYY-MM-DD HH:mm:ss","YYYY/MM/DD HH:mm:ss"],nt=$=>{if(!R($))return"00:00:00";const l=V($).diff(V());if(l<=0)return"00:00:00";const f=Math.floor(l/1e3),v=Math.floor(f/86400),Y=Math.floor(f%86400/3600),x=Math.floor(f%3600/60),g=f%60;return`${v?`${v}:`:""}${`${Y}`.padStart(2,"0")}:${`${x}`.padStart(2,"0")}:${`${g}`.padStart(2,"0")}`},st=$=>{const l=f=>`${f}`.padStart(2,"0");return`${l(Math.floor($/q/q))}:${l(Math.floor($/q)%q)}:${l($%q)}`},R=$=>ht.some(l=>V($,l,!0).isValid()),it="HH:mm:ss",at=900,$t=$=>{const{mode:l,showType:f="default",size:v=40,className:Y,bgColor:x,borderColor:g,finishCountFn:b}=$,[d,D]=H.useState(f==="count"?st(0):f==="default"?V().format(it):nt(f)),k=H.useRef({t:null}),O={"--card-size":`${v}px`,"--card-w":`${v*1.25}px`,"--card-h":`${v*2}px`,"--transx":`${-v*1.25/2}px`,"--transy":`${-v}px`,"--delay":`${at/1e3}s`,"--bgColor":x,"--borderColor":g};H.useEffect(()=>{let m=Date.now();k.current.t&&(clearInterval(k.current.t),k.current.t=null,m=Date.now()),k.current.t=setInterval(()=>{let S=()=>"";f==="count"?S=()=>st(Math.floor((Date.now()-m)/1e3)):f==="default"?S=()=>V().format(it):S=()=>nt(f),D(S())},1e3)},[f]),H.useEffect(()=>{R(f)&&d==="00:00:00"&&b&&setTimeout(()=>{b()},1e3)},[d,f,b]);const B=()=>{if(!d)return null;const m=d.split(":"),S=m[m.length-3].split(""),z=m[m.length-2].split(""),Q=m[m.length-1].split(""),tt=m.length===4?m[0].split(""):[],T=R(f),A=tt.map((F,C)=>o.jsx(N,{mode:l,time:+F,limit:T?-9:9},C)),U=o.jsx("span",{children:":"});return o.jsxs(o.Fragment,{children:[A.length?o.jsxs(o.Fragment,{children:[A,T?o.jsx("p",{children:"天"}):U]}):null,o.jsx(N,{mode:l,time:+S[0],limit:T?-2:2}),o.jsx(N,{mode:l,time:+S[1],limit:T?-9:9}),T?o.jsx("p",{children:"小时"}):U,o.jsx(N,{mode:l,time:+z[0],limit:T?-5:5}),o.jsx(N,{mode:l,time:+z[1],limit:T?-9:9}),T?o.jsx("p",{children:"分"}):U,o.jsx(N,{mode:l,time:+Q[0],limit:T?-5:5}),o.jsx(N,{mode:l,time:+Q[1],limit:T?-9:9}),T&&o.jsx("p",{children:"秒"})]})};return o.jsx("div",{className:`time-runner ${Y||""}`,style:O,children:B()})},mt=$=>{const{time:l,limit:f,mode:v}=$,[Y,x]=H.useState(!1),g=H.useRef({t:l});H.useEffect(()=>{l!==g.current.t&&x(!0)},[l]),H.useEffect(()=>{Y&&setTimeout(()=>{g.current.t=l,x(!1)},at)},[Y,l]);const b=()=>{const{t:d}=g.current;let D=d;switch(f>0?D=d>=f?0:d+1:D=d<=0?Math.abs(f):d-1,v){case"card":return o.jsxs("div",{className:"clock-card",children:[o.jsxs("div",{className:`clock-b ${Y?"run":""}`,children:[o.jsx("p",{children:D}),o.jsx("p",{children:D})]}),o.jsxs("div",{className:`clock-f ${Y?"run":""}`,children:[o.jsx("p",{children:d}),o.jsx("p",{children:d})]})]});case"cube-v":return o.jsx("div",{className:`clock-cube-3d-v ${Y?"run":""}`,children:o.jsxs("div",{children:[o.jsx("p",{children:D}),o.jsx("p",{children:d})]})});case"cube-h":return o.jsx("div",{className:`clock-cube-3d-h ${Y?"run":""}`,children:o.jsxs("div",{children:[o.jsx("p",{children:D}),o.jsx("p",{children:d})]})});default:return o.jsx("div",{children:o.jsx("p",{children:d})})}};return o.jsx(o.Fragment,{children:b()})},N=H.memo(mt);j.TimeRunner=$t,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "time-runner",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Displaying timer, current time, and countdown with light animation effects(React component)",
|
|
5
|
+
"keywords": ["react", "countdown", "timer", "hook", "card", "less", "animation", "vite"],
|
|
6
|
+
"main": "./dist/time-runner.umd.js",
|
|
7
|
+
"module": "./dist/time-runner.es.js",
|
|
8
|
+
"types": "./dist/time-runner.d.ts",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"author": "feiqi",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "vite build",
|
|
14
|
+
"dev": "vite --port 3001"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": ">=16.8.0",
|
|
21
|
+
"react-dom": ">=16.8.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/react": "^18.2.56",
|
|
25
|
+
"@typescript-eslint/parser": "^8.44.0",
|
|
26
|
+
"@vitejs/plugin-react": "^5.0.4",
|
|
27
|
+
"eslint": "^8.56.0",
|
|
28
|
+
"eslint-plugin-react": "^7.33.2",
|
|
29
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
30
|
+
"eslint-plugin-react-refresh": "^0.4.5",
|
|
31
|
+
"less": "^4.4.1",
|
|
32
|
+
"react": "18.2.0",
|
|
33
|
+
"react-dom": "18.2.0",
|
|
34
|
+
"typescript": "^5.9.3",
|
|
35
|
+
"vite": "^7.1.8",
|
|
36
|
+
"vite-plugin-dts": "^4.5.4",
|
|
37
|
+
"vite-plugin-eslint": "^1.8.1"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"dayjs": "^1.11.18"
|
|
41
|
+
}
|
|
42
|
+
}
|