@gfazioli/mantine-clock 3.0.0 → 4.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 +9 -3
- package/dist/cjs/Clock.cjs +48 -535
- package/dist/cjs/Clock.cjs.map +1 -1
- package/dist/cjs/ClockDigital.cjs +22 -25
- package/dist/cjs/ClockDigital.cjs.map +1 -1
- package/dist/cjs/ClockDigitalMediaVariables.cjs +76 -0
- package/dist/cjs/ClockDigitalMediaVariables.cjs.map +1 -0
- package/dist/cjs/ClockFaceStatic.cjs +96 -0
- package/dist/cjs/ClockFaceStatic.cjs.map +1 -0
- package/dist/cjs/RealClock.cjs +379 -0
- package/dist/cjs/RealClock.cjs.map +1 -0
- package/dist/cjs/clock-utils.cjs +63 -0
- package/dist/cjs/clock-utils.cjs.map +1 -0
- package/dist/cjs/geometry.cjs +2 -2
- package/dist/cjs/geometry.cjs.map +1 -1
- package/dist/cjs/hooks/use-clock-count-down.cjs +2 -2
- package/dist/cjs/hooks/use-clock-count-down.cjs.map +1 -1
- package/dist/cjs/hooks/use-clock.cjs +2 -2
- package/dist/cjs/hooks/use-clock.cjs.map +1 -1
- package/dist/esm/Clock.mjs +47 -534
- package/dist/esm/Clock.mjs.map +1 -1
- package/dist/esm/ClockDigital.mjs +23 -26
- package/dist/esm/ClockDigital.mjs.map +1 -1
- package/dist/esm/ClockDigitalMediaVariables.mjs +74 -0
- package/dist/esm/ClockDigitalMediaVariables.mjs.map +1 -0
- package/dist/esm/ClockFaceStatic.mjs +94 -0
- package/dist/esm/ClockFaceStatic.mjs.map +1 -0
- package/dist/esm/RealClock.mjs +377 -0
- package/dist/esm/RealClock.mjs.map +1 -0
- package/dist/esm/clock-utils.mjs +56 -0
- package/dist/esm/clock-utils.mjs.map +1 -0
- package/dist/esm/geometry.mjs +2 -2
- package/dist/esm/geometry.mjs.map +1 -1
- package/dist/esm/hooks/use-clock-count-down.mjs +2 -2
- package/dist/esm/hooks/use-clock-count-down.mjs.map +1 -1
- package/dist/esm/hooks/use-clock.mjs +2 -2
- package/dist/esm/hooks/use-clock.mjs.map +1 -1
- package/dist/types/Clock.d.ts +3 -3
- package/dist/types/ClockDigital.d.ts +5 -5
- package/dist/types/ClockDigitalMediaVariables.d.ts +9 -0
- package/dist/types/ClockFaceStatic.d.ts +18 -0
- package/dist/types/RealClock.d.ts +12 -0
- package/dist/types/clock-utils.d.ts +23 -0
- package/package.json +7 -1
package/dist/esm/Clock.mjs
CHANGED
|
@@ -1,34 +1,20 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
|
-
import
|
|
3
|
+
import timezone from 'dayjs/plugin/timezone';
|
|
4
4
|
import utc from 'dayjs/plugin/utc';
|
|
5
|
-
import React, { useState,
|
|
6
|
-
import { createVarsResolver,
|
|
5
|
+
import React, { useState, useRef, useMemo, useEffect } from 'react';
|
|
6
|
+
import { createVarsResolver, factory, useProps, useStyles, useMatches, px, getSize, Box, parseThemeColor } from '@mantine/core';
|
|
7
7
|
import { useCallbackRef, useMergedRef } from '@mantine/hooks';
|
|
8
|
+
import { round2, defaultClockProps, parseTimeValue } from './clock-utils.mjs';
|
|
8
9
|
import { ClockDigital } from './ClockDigital.mjs';
|
|
9
|
-
import {
|
|
10
|
+
import { ClockFaceStatic } from './ClockFaceStatic.mjs';
|
|
11
|
+
import { createGeometry } from './geometry.mjs';
|
|
12
|
+
import { RealClock } from './RealClock.mjs';
|
|
10
13
|
import classes from './Clock.module.css.mjs';
|
|
11
14
|
|
|
12
15
|
dayjs.extend(utc);
|
|
13
|
-
dayjs.extend(
|
|
14
|
-
const
|
|
15
|
-
const CENTER_DOT_RATIO = 0.034;
|
|
16
|
-
const COUNTERWEIGHT_MULTIPLIER = 3;
|
|
17
|
-
const round2 = (n) => Math.round(n * 100) / 100;
|
|
18
|
-
const defaultProps = {
|
|
19
|
-
size: 400,
|
|
20
|
-
hourHandSize: 0.017,
|
|
21
|
-
minuteHandSize: 0.011,
|
|
22
|
-
secondHandSize: 6e-3,
|
|
23
|
-
hourHandLength: 0.4,
|
|
24
|
-
minuteHandLength: 0.57,
|
|
25
|
-
secondHandLength: 0.68,
|
|
26
|
-
secondHandOpacity: 1,
|
|
27
|
-
minuteHandOpacity: 1,
|
|
28
|
-
hourHandOpacity: 1,
|
|
29
|
-
secondHandBehavior: "tick",
|
|
30
|
-
running: true
|
|
31
|
-
};
|
|
16
|
+
dayjs.extend(timezone);
|
|
17
|
+
const defaultProps = defaultClockProps;
|
|
32
18
|
const defaultClockSizes = {
|
|
33
19
|
xs: 100,
|
|
34
20
|
sm: 200,
|
|
@@ -36,515 +22,32 @@ const defaultClockSizes = {
|
|
|
36
22
|
lg: 480,
|
|
37
23
|
xl: 512
|
|
38
24
|
};
|
|
39
|
-
const
|
|
25
|
+
const varsResolver = createVarsResolver((theme, props) => {
|
|
40
26
|
const c = (color) => parseThemeColor({ color, theme }).value;
|
|
41
27
|
return {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
const varsResolver = createVarsResolver((theme, props) => {
|
|
61
|
-
const { size } = props;
|
|
62
|
-
if (size === "auto") {
|
|
63
|
-
return { root: buildCssVars(theme, "400px", props) };
|
|
64
|
-
}
|
|
65
|
-
const sizeValue = size || "md";
|
|
66
|
-
const clockSize = typeof sizeValue === "string" && sizeValue in defaultClockSizes ? defaultClockSizes[sizeValue] : sizeValue;
|
|
67
|
-
const effectiveSize = Math.round(px(getSize(clockSize, "clock-size")));
|
|
68
|
-
return { root: buildCssVars(theme, `${effectiveSize}px`, props) };
|
|
69
|
-
});
|
|
70
|
-
const parseTimeValue = (value) => {
|
|
71
|
-
if (!value) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
if (value instanceof Date) {
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
77
|
-
if (dayjs.isDayjs(value)) {
|
|
78
|
-
return value.toDate();
|
|
79
|
-
}
|
|
80
|
-
if (typeof value === "string") {
|
|
81
|
-
const timeRegex = /^(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?$/;
|
|
82
|
-
const match = value.match(timeRegex);
|
|
83
|
-
if (match) {
|
|
84
|
-
const hours = parseInt(match[1], 10);
|
|
85
|
-
const minutes = parseInt(match[2], 10);
|
|
86
|
-
const seconds = parseInt(match[3] || "0", 10);
|
|
87
|
-
const date = /* @__PURE__ */ new Date();
|
|
88
|
-
date.setHours(hours, minutes, seconds, 0);
|
|
89
|
-
return date;
|
|
28
|
+
root: {
|
|
29
|
+
"--clock-size": void 0,
|
|
30
|
+
"--clock-color": c(props.color || ""),
|
|
31
|
+
"--clock-hour-ticks-color": c(props.hourTicksColor || ""),
|
|
32
|
+
"--clock-hour-ticks-opacity": round2(props.hourTicksOpacity ?? 1).toString(),
|
|
33
|
+
"--clock-minute-ticks-color": c(props.minuteTicksColor || ""),
|
|
34
|
+
"--clock-minute-ticks-opacity": round2(props.minuteTicksOpacity ?? 1).toString(),
|
|
35
|
+
"--clock-primary-numbers-color": c(props.primaryNumbersColor || ""),
|
|
36
|
+
"--clock-primary-numbers-opacity": round2(props.primaryNumbersOpacity ?? 1).toString(),
|
|
37
|
+
"--clock-secondary-numbers-color": c(props.secondaryNumbersColor || ""),
|
|
38
|
+
"--clock-secondary-numbers-opacity": round2(props.secondaryNumbersOpacity ?? 1).toString(),
|
|
39
|
+
"--clock-second-hand-color": c(props.secondHandColor || ""),
|
|
40
|
+
"--clock-minute-hand-color": c(props.minuteHandColor || ""),
|
|
41
|
+
"--clock-hour-hand-color": c(props.hourHandColor || ""),
|
|
42
|
+
"--clock-seconds-arc-color": c(props.secondsArcColor || props.secondHandColor || ""),
|
|
43
|
+
"--clock-minutes-arc-color": c(props.minutesArcColor || props.minuteHandColor || ""),
|
|
44
|
+
"--clock-hours-arc-color": c(props.hoursArcColor || props.hourHandColor || "")
|
|
90
45
|
}
|
|
91
|
-
|
|
92
|
-
if (!isNaN(parsed.getTime())) {
|
|
93
|
-
return parsed;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return null;
|
|
97
|
-
};
|
|
98
|
-
const ClockFaceStatic = React.memo(
|
|
99
|
-
({
|
|
100
|
-
getStyles,
|
|
101
|
-
effectiveSize,
|
|
102
|
-
geometry,
|
|
103
|
-
hourTicksOpacity,
|
|
104
|
-
minuteTicksOpacity,
|
|
105
|
-
primaryNumbersOpacity,
|
|
106
|
-
secondaryNumbersOpacity,
|
|
107
|
-
hourNumbersDistance = 0.75,
|
|
108
|
-
primaryNumbersProps,
|
|
109
|
-
secondaryNumbersProps
|
|
110
|
-
}) => {
|
|
111
|
-
const clockRadius = Math.round(effectiveSize / 2);
|
|
112
|
-
const numberRadius = Math.round(clockRadius * hourNumbersDistance);
|
|
113
|
-
const tickOffset = Math.round(effectiveSize * TICK_OFFSET_RATIO);
|
|
114
|
-
return /* @__PURE__ */ React.createElement(Box, { ...getStyles("hourMarks") }, (hourTicksOpacity ?? 1) !== 0 && Array.from({ length: 12 }, (_, i) => {
|
|
115
|
-
const pos = geometry.tickPosition(i, 12, tickOffset);
|
|
116
|
-
const tickStyle = pos.positioning === "absolute" ? {
|
|
117
|
-
top: pos.y,
|
|
118
|
-
left: pos.x,
|
|
119
|
-
transformOrigin: pos.transformOrigin,
|
|
120
|
-
transform: `translate(-50%, -50%) rotate(${pos.angle}deg)`
|
|
121
|
-
} : {
|
|
122
|
-
top: pos.y,
|
|
123
|
-
left: "50%",
|
|
124
|
-
transformOrigin: pos.transformOrigin,
|
|
125
|
-
transform: `translateX(-50%) rotate(${pos.angle}deg)`
|
|
126
|
-
};
|
|
127
|
-
return /* @__PURE__ */ React.createElement(Box, { key: `hour-tick-${i}`, ...getStyles("hourTick", { style: tickStyle }) });
|
|
128
|
-
}), (minuteTicksOpacity ?? 1) !== 0 && Array.from({ length: 60 }, (_, i) => {
|
|
129
|
-
if (i % 5 === 0) {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
const pos = geometry.tickPosition(i, 60, tickOffset);
|
|
133
|
-
const tickStyle = pos.positioning === "absolute" ? {
|
|
134
|
-
top: pos.y,
|
|
135
|
-
left: pos.x,
|
|
136
|
-
transformOrigin: pos.transformOrigin,
|
|
137
|
-
transform: `translate(-50%, -50%) rotate(${pos.angle}deg)`
|
|
138
|
-
} : {
|
|
139
|
-
top: pos.y,
|
|
140
|
-
left: "50%",
|
|
141
|
-
transformOrigin: pos.transformOrigin,
|
|
142
|
-
transform: `translateX(-50%) rotate(${pos.angle}deg)`
|
|
143
|
-
};
|
|
144
|
-
return /* @__PURE__ */ React.createElement(Box, { key: `minute-tick-${i}`, ...getStyles("minuteTick", { style: tickStyle }) });
|
|
145
|
-
}), (primaryNumbersOpacity ?? 1) !== 0 && [12, 3, 6, 9].map((num) => {
|
|
146
|
-
const hourIndex = num === 12 ? 0 : num;
|
|
147
|
-
const pos = geometry.numberPosition(hourIndex, numberRadius);
|
|
148
|
-
return /* @__PURE__ */ React.createElement(
|
|
149
|
-
Text,
|
|
150
|
-
{
|
|
151
|
-
key: `primary-number-${num}`,
|
|
152
|
-
...primaryNumbersProps,
|
|
153
|
-
...getStyles("primaryNumber", {
|
|
154
|
-
className: getStyles("number").className,
|
|
155
|
-
style: {
|
|
156
|
-
left: pos.x,
|
|
157
|
-
top: pos.y
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
},
|
|
161
|
-
num
|
|
162
|
-
);
|
|
163
|
-
}), (secondaryNumbersOpacity ?? 1) !== 0 && [1, 2, 4, 5, 7, 8, 10, 11].map((num) => {
|
|
164
|
-
const pos = geometry.numberPosition(num, numberRadius);
|
|
165
|
-
return /* @__PURE__ */ React.createElement(
|
|
166
|
-
Text,
|
|
167
|
-
{
|
|
168
|
-
key: `secondary-number-${num}`,
|
|
169
|
-
...secondaryNumbersProps,
|
|
170
|
-
...getStyles("secondaryNumber", {
|
|
171
|
-
className: getStyles("number").className,
|
|
172
|
-
style: {
|
|
173
|
-
left: pos.x,
|
|
174
|
-
top: pos.y
|
|
175
|
-
}
|
|
176
|
-
})
|
|
177
|
-
},
|
|
178
|
-
num
|
|
179
|
-
);
|
|
180
|
-
}));
|
|
181
|
-
}
|
|
182
|
-
);
|
|
183
|
-
ClockFaceStatic.displayName = "ClockFaceStatic";
|
|
184
|
-
const RealClock = React.memo((props) => {
|
|
185
|
-
const {
|
|
186
|
-
time,
|
|
187
|
-
timezone: timezone2,
|
|
188
|
-
getStyles,
|
|
189
|
-
effectiveSize,
|
|
190
|
-
geometry,
|
|
191
|
-
hourHandSize,
|
|
192
|
-
minuteHandSize,
|
|
193
|
-
secondHandSize,
|
|
194
|
-
hourHandLength,
|
|
195
|
-
minuteHandLength,
|
|
196
|
-
secondHandLength,
|
|
197
|
-
secondHandBehavior,
|
|
198
|
-
secondHandOpacity,
|
|
199
|
-
minuteHandOpacity,
|
|
200
|
-
hourHandOpacity,
|
|
201
|
-
hourTicksOpacity,
|
|
202
|
-
minuteTicksOpacity,
|
|
203
|
-
primaryNumbersOpacity,
|
|
204
|
-
secondaryNumbersOpacity,
|
|
205
|
-
hourNumbersDistance = 0.75,
|
|
206
|
-
// Default distance for hour numbers
|
|
207
|
-
primaryNumbersProps,
|
|
208
|
-
secondaryNumbersProps,
|
|
209
|
-
withSecondsArc,
|
|
210
|
-
secondsArcFrom,
|
|
211
|
-
secondsArcDirection = "clockwise",
|
|
212
|
-
withMinutesArc,
|
|
213
|
-
minutesArcFrom,
|
|
214
|
-
minutesArcDirection = "clockwise",
|
|
215
|
-
withHoursArc,
|
|
216
|
-
hoursArcFrom,
|
|
217
|
-
hoursArcDirection = "clockwise",
|
|
218
|
-
secondsArcOpacity,
|
|
219
|
-
minutesArcOpacity,
|
|
220
|
-
hoursArcOpacity,
|
|
221
|
-
renderHourHand,
|
|
222
|
-
renderMinuteHand,
|
|
223
|
-
renderSecondHand,
|
|
224
|
-
sectors,
|
|
225
|
-
faceContent,
|
|
226
|
-
animateOnMount,
|
|
227
|
-
animateOnMountDuration
|
|
228
|
-
} = props;
|
|
229
|
-
const timezoneTime = timezone2 && timezone2 !== "" ? dayjs(time).tz(timezone2) : dayjs(time);
|
|
230
|
-
const hours = timezoneTime.hour() % 12;
|
|
231
|
-
const minutes = timezoneTime.minute();
|
|
232
|
-
const seconds = timezoneTime.second();
|
|
233
|
-
const milliseconds = timezoneTime.millisecond();
|
|
234
|
-
const hourAngle = hours * 30 + minutes * 0.5;
|
|
235
|
-
const minuteAngle = minutes * 6;
|
|
236
|
-
let secondAngle = 0;
|
|
237
|
-
switch (secondHandBehavior) {
|
|
238
|
-
case "tick-half":
|
|
239
|
-
secondAngle = (seconds + Math.floor(milliseconds / 500) * 0.5) * 6;
|
|
240
|
-
break;
|
|
241
|
-
case "tick-high-freq":
|
|
242
|
-
secondAngle = (seconds + Math.floor(milliseconds / 125) * 0.125) * 6;
|
|
243
|
-
break;
|
|
244
|
-
case "smooth":
|
|
245
|
-
secondAngle = (seconds + milliseconds / 1e3) * 6;
|
|
246
|
-
break;
|
|
247
|
-
case "tick":
|
|
248
|
-
default:
|
|
249
|
-
secondAngle = seconds * 6;
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
const [mountPhase, setMountPhase] = useState(
|
|
253
|
-
animateOnMount ? "initial" : "done"
|
|
254
|
-
);
|
|
255
|
-
useEffect(() => {
|
|
256
|
-
if (mountPhase === "initial") {
|
|
257
|
-
const rafId = requestAnimationFrame(() => {
|
|
258
|
-
setMountPhase("animating");
|
|
259
|
-
});
|
|
260
|
-
return () => cancelAnimationFrame(rafId);
|
|
261
|
-
} else if (mountPhase === "animating") {
|
|
262
|
-
const timer = setTimeout(
|
|
263
|
-
() => {
|
|
264
|
-
setMountPhase("done");
|
|
265
|
-
},
|
|
266
|
-
(animateOnMountDuration ?? 1e3) + 50
|
|
267
|
-
);
|
|
268
|
-
return () => clearTimeout(timer);
|
|
269
|
-
}
|
|
270
|
-
}, [mountPhase, animateOnMountDuration]);
|
|
271
|
-
const showTransition = mountPhase === "animating";
|
|
272
|
-
const handAngles = mountPhase === "initial" ? { hour: 0, minute: 0, second: 0 } : { hour: round2(hourAngle), minute: round2(minuteAngle), second: round2(secondAngle) };
|
|
273
|
-
const transitionStyle = showTransition ? {
|
|
274
|
-
transition: `transform ${animateOnMountDuration ?? 1e3}ms cubic-bezier(0.34, 1.56, 0.64, 1)`
|
|
275
|
-
} : void 0;
|
|
276
|
-
const size = effectiveSize;
|
|
277
|
-
const { centerX, centerY } = geometry;
|
|
278
|
-
const calculatedHourHandLength = geometry.handLength(
|
|
279
|
-
hourHandLength ?? defaultProps.hourHandLength
|
|
280
|
-
);
|
|
281
|
-
const calculatedMinuteHandLength = geometry.handLength(
|
|
282
|
-
minuteHandLength ?? defaultProps.minuteHandLength
|
|
283
|
-
);
|
|
284
|
-
const calculatedSecondHandLength = geometry.handLength(
|
|
285
|
-
secondHandLength ?? defaultProps.secondHandLength
|
|
286
|
-
);
|
|
287
|
-
const centerSize = Math.round(size * CENTER_DOT_RATIO);
|
|
288
|
-
const showSecArc = withSecondsArc === true && (secondsArcOpacity ?? 1) !== 0;
|
|
289
|
-
const showMinArc = withMinutesArc === true && (minutesArcOpacity ?? 1) !== 0;
|
|
290
|
-
const showHrArc = withHoursArc === true && (hoursArcOpacity ?? 1) !== 0;
|
|
291
|
-
const counterweightWidth = round2(
|
|
292
|
-
size * (secondHandSize ?? defaultProps.secondHandSize) * COUNTERWEIGHT_MULTIPLIER
|
|
293
|
-
);
|
|
294
|
-
return /* @__PURE__ */ React.createElement(
|
|
295
|
-
Box,
|
|
296
|
-
{
|
|
297
|
-
...getStyles("clockContainer", {
|
|
298
|
-
style: {
|
|
299
|
-
width: geometry.width,
|
|
300
|
-
height: geometry.height
|
|
301
|
-
}
|
|
302
|
-
})
|
|
303
|
-
},
|
|
304
|
-
/* @__PURE__ */ React.createElement(
|
|
305
|
-
Box,
|
|
306
|
-
{
|
|
307
|
-
...getStyles("glassWrapper", {
|
|
308
|
-
style: { width: geometry.width, height: geometry.height }
|
|
309
|
-
})
|
|
310
|
-
},
|
|
311
|
-
/* @__PURE__ */ React.createElement(
|
|
312
|
-
Box,
|
|
313
|
-
{
|
|
314
|
-
...getStyles("clockFace", {
|
|
315
|
-
style: {
|
|
316
|
-
width: geometry.width,
|
|
317
|
-
height: geometry.height,
|
|
318
|
-
borderRadius: geometry.borderRadius(),
|
|
319
|
-
clipPath: geometry.clipPath()
|
|
320
|
-
}
|
|
321
|
-
})
|
|
322
|
-
},
|
|
323
|
-
faceContent && /* @__PURE__ */ React.createElement(Box, { ...getStyles("faceContent") }, faceContent),
|
|
324
|
-
(showSecArc || showMinArc || showHrArc || sectors && sectors.length > 0) && /* @__PURE__ */ React.createElement(
|
|
325
|
-
"svg",
|
|
326
|
-
{
|
|
327
|
-
...getStyles("arcsLayer", {
|
|
328
|
-
style: { width: geometry.width, height: geometry.height }
|
|
329
|
-
}),
|
|
330
|
-
viewBox: `0 0 ${geometry.width} ${geometry.height}`
|
|
331
|
-
},
|
|
332
|
-
sectors && sectors.length > 0 && sectors.map((sector, idx) => {
|
|
333
|
-
const fromDate = parseTimeValue(sector.from);
|
|
334
|
-
const toDate = parseTimeValue(sector.to);
|
|
335
|
-
if (!fromDate || !toDate) {
|
|
336
|
-
return null;
|
|
337
|
-
}
|
|
338
|
-
const startAngle = hourAngleFromDate(fromDate, timezone2);
|
|
339
|
-
const endAngle = hourAngleFromDate(toDate, timezone2);
|
|
340
|
-
const sectorRadius = calculatedMinuteHandLength;
|
|
341
|
-
return /* @__PURE__ */ React.createElement(
|
|
342
|
-
"path",
|
|
343
|
-
{
|
|
344
|
-
key: `sector-${idx}`,
|
|
345
|
-
d: geometry.sectorPath(startAngle, endAngle, sectorRadius, "clockwise"),
|
|
346
|
-
fill: sector.color || "var(--clock-second-hand-color-resolved)",
|
|
347
|
-
fillOpacity: round2(sector.opacity ?? 0.2),
|
|
348
|
-
style: sector.interactive ? { cursor: "pointer" } : void 0,
|
|
349
|
-
role: sector.interactive ? "button" : void 0,
|
|
350
|
-
tabIndex: sector.interactive ? 0 : void 0,
|
|
351
|
-
"aria-label": sector.interactive ? sector.label : void 0,
|
|
352
|
-
onClick: sector.interactive && sector.onClick ? () => sector.onClick(sector) : void 0,
|
|
353
|
-
onKeyDown: sector.interactive && sector.onClick ? (e) => {
|
|
354
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
355
|
-
e.preventDefault();
|
|
356
|
-
sector.onClick(sector);
|
|
357
|
-
}
|
|
358
|
-
} : void 0,
|
|
359
|
-
onMouseEnter: sector.interactive && sector.onHover ? () => sector.onHover(sector, true) : void 0,
|
|
360
|
-
onMouseLeave: sector.interactive && sector.onHover ? () => sector.onHover(sector, false) : void 0
|
|
361
|
-
},
|
|
362
|
-
sector.label && /* @__PURE__ */ React.createElement("title", null, sector.label)
|
|
363
|
-
);
|
|
364
|
-
}),
|
|
365
|
-
showHrArc && /* @__PURE__ */ React.createElement(
|
|
366
|
-
"path",
|
|
367
|
-
{
|
|
368
|
-
d: geometry.sectorPath(
|
|
369
|
-
hourAngleFromDate(parseTimeValue(hoursArcFrom) ?? null, timezone2),
|
|
370
|
-
hourAngle,
|
|
371
|
-
calculatedHourHandLength,
|
|
372
|
-
hoursArcDirection
|
|
373
|
-
),
|
|
374
|
-
fill: "var(--clock-hours-arc-color-resolved)",
|
|
375
|
-
fillOpacity: round2(hoursArcOpacity ?? 1)
|
|
376
|
-
}
|
|
377
|
-
),
|
|
378
|
-
showMinArc && /* @__PURE__ */ React.createElement(
|
|
379
|
-
"path",
|
|
380
|
-
{
|
|
381
|
-
d: geometry.sectorPath(
|
|
382
|
-
minuteAngleFromDate(parseTimeValue(minutesArcFrom) ?? null, timezone2),
|
|
383
|
-
minuteAngle,
|
|
384
|
-
calculatedMinuteHandLength,
|
|
385
|
-
minutesArcDirection
|
|
386
|
-
),
|
|
387
|
-
fill: "var(--clock-minutes-arc-color-resolved)",
|
|
388
|
-
fillOpacity: round2(minutesArcOpacity ?? 1)
|
|
389
|
-
}
|
|
390
|
-
),
|
|
391
|
-
showSecArc && /* @__PURE__ */ React.createElement(
|
|
392
|
-
"path",
|
|
393
|
-
{
|
|
394
|
-
d: geometry.sectorPath(
|
|
395
|
-
secondAngleFromDate(parseTimeValue(secondsArcFrom) ?? null, timezone2),
|
|
396
|
-
secondAngle,
|
|
397
|
-
calculatedSecondHandLength,
|
|
398
|
-
secondsArcDirection
|
|
399
|
-
),
|
|
400
|
-
fill: "var(--clock-seconds-arc-color-resolved)",
|
|
401
|
-
fillOpacity: round2(secondsArcOpacity ?? 1)
|
|
402
|
-
}
|
|
403
|
-
)
|
|
404
|
-
),
|
|
405
|
-
/* @__PURE__ */ React.createElement(
|
|
406
|
-
ClockFaceStatic,
|
|
407
|
-
{
|
|
408
|
-
getStyles,
|
|
409
|
-
effectiveSize: size,
|
|
410
|
-
geometry,
|
|
411
|
-
hourTicksOpacity,
|
|
412
|
-
minuteTicksOpacity,
|
|
413
|
-
primaryNumbersOpacity,
|
|
414
|
-
secondaryNumbersOpacity,
|
|
415
|
-
hourNumbersDistance,
|
|
416
|
-
primaryNumbersProps,
|
|
417
|
-
secondaryNumbersProps
|
|
418
|
-
}
|
|
419
|
-
),
|
|
420
|
-
(hourHandOpacity ?? defaultProps.hourHandOpacity) !== 0 && (renderHourHand ? renderHourHand({
|
|
421
|
-
angle: handAngles.hour,
|
|
422
|
-
length: calculatedHourHandLength,
|
|
423
|
-
width: round2(size * (hourHandSize ?? defaultProps.hourHandSize)),
|
|
424
|
-
centerX: geometry.centerX,
|
|
425
|
-
centerY: geometry.centerY,
|
|
426
|
-
clockSize: size
|
|
427
|
-
}) : /* @__PURE__ */ React.createElement(
|
|
428
|
-
Box,
|
|
429
|
-
{
|
|
430
|
-
...getStyles("hand", {
|
|
431
|
-
className: getStyles("hourHand").className,
|
|
432
|
-
style: {
|
|
433
|
-
width: round2(size * (hourHandSize ?? defaultProps.hourHandSize)),
|
|
434
|
-
height: calculatedHourHandLength,
|
|
435
|
-
opacity: round2(hourHandOpacity ?? defaultProps.hourHandOpacity),
|
|
436
|
-
bottom: centerY,
|
|
437
|
-
left: centerX,
|
|
438
|
-
marginLeft: round2(-(size * (hourHandSize ?? defaultProps.hourHandSize)) / 2),
|
|
439
|
-
borderRadius: `${round2(size * (hourHandSize ?? defaultProps.hourHandSize))}px`,
|
|
440
|
-
transform: `rotate(${handAngles.hour}deg)`,
|
|
441
|
-
...transitionStyle
|
|
442
|
-
}
|
|
443
|
-
})
|
|
444
|
-
}
|
|
445
|
-
)),
|
|
446
|
-
(minuteHandOpacity ?? defaultProps.minuteHandOpacity) !== 0 && (renderMinuteHand ? renderMinuteHand({
|
|
447
|
-
angle: handAngles.minute,
|
|
448
|
-
length: calculatedMinuteHandLength,
|
|
449
|
-
width: round2(size * (minuteHandSize ?? defaultProps.minuteHandSize)),
|
|
450
|
-
centerX: geometry.centerX,
|
|
451
|
-
centerY: geometry.centerY,
|
|
452
|
-
clockSize: size
|
|
453
|
-
}) : /* @__PURE__ */ React.createElement(
|
|
454
|
-
Box,
|
|
455
|
-
{
|
|
456
|
-
...getStyles("hand", {
|
|
457
|
-
className: getStyles("minuteHand").className,
|
|
458
|
-
style: {
|
|
459
|
-
width: round2(size * (minuteHandSize ?? defaultProps.minuteHandSize)),
|
|
460
|
-
height: calculatedMinuteHandLength,
|
|
461
|
-
opacity: round2(minuteHandOpacity ?? defaultProps.minuteHandOpacity),
|
|
462
|
-
bottom: centerY,
|
|
463
|
-
left: centerX,
|
|
464
|
-
marginLeft: round2(
|
|
465
|
-
-(size * (minuteHandSize ?? defaultProps.minuteHandSize)) / 2
|
|
466
|
-
),
|
|
467
|
-
borderRadius: `${round2(size * (minuteHandSize ?? defaultProps.minuteHandSize))}px`,
|
|
468
|
-
transform: `rotate(${handAngles.minute}deg)`,
|
|
469
|
-
...transitionStyle
|
|
470
|
-
}
|
|
471
|
-
})
|
|
472
|
-
}
|
|
473
|
-
)),
|
|
474
|
-
(secondHandOpacity ?? defaultProps.secondHandOpacity) !== 0 && (renderSecondHand ? renderSecondHand({
|
|
475
|
-
angle: handAngles.second,
|
|
476
|
-
length: calculatedSecondHandLength,
|
|
477
|
-
width: round2(size * (secondHandSize ?? defaultProps.secondHandSize)),
|
|
478
|
-
centerX: geometry.centerX,
|
|
479
|
-
centerY: geometry.centerY,
|
|
480
|
-
clockSize: size
|
|
481
|
-
}) : /* @__PURE__ */ React.createElement(
|
|
482
|
-
Box,
|
|
483
|
-
{
|
|
484
|
-
...getStyles("secondHandContainer", {
|
|
485
|
-
style: {
|
|
486
|
-
width: round2(size * (secondHandSize ?? defaultProps.secondHandSize)),
|
|
487
|
-
height: calculatedSecondHandLength,
|
|
488
|
-
top: centerY - calculatedSecondHandLength,
|
|
489
|
-
left: centerX,
|
|
490
|
-
marginLeft: round2(
|
|
491
|
-
-(size * (secondHandSize ?? defaultProps.secondHandSize)) / 2
|
|
492
|
-
),
|
|
493
|
-
transformOrigin: `${round2(size * (secondHandSize ?? defaultProps.secondHandSize) / 2)}px ${calculatedSecondHandLength}px`,
|
|
494
|
-
transform: `rotate(${handAngles.second}deg)`,
|
|
495
|
-
...transitionStyle
|
|
496
|
-
}
|
|
497
|
-
})
|
|
498
|
-
},
|
|
499
|
-
/* @__PURE__ */ React.createElement(
|
|
500
|
-
Box,
|
|
501
|
-
{
|
|
502
|
-
...getStyles("secondHand", {
|
|
503
|
-
style: {
|
|
504
|
-
width: round2(size * (secondHandSize ?? defaultProps.secondHandSize)),
|
|
505
|
-
height: calculatedSecondHandLength,
|
|
506
|
-
opacity: round2(secondHandOpacity ?? defaultProps.secondHandOpacity)
|
|
507
|
-
}
|
|
508
|
-
})
|
|
509
|
-
}
|
|
510
|
-
),
|
|
511
|
-
/* @__PURE__ */ React.createElement(
|
|
512
|
-
Box,
|
|
513
|
-
{
|
|
514
|
-
...getStyles("secondHandCounterweight", {
|
|
515
|
-
style: {
|
|
516
|
-
width: counterweightWidth,
|
|
517
|
-
opacity: round2(secondHandOpacity ?? defaultProps.secondHandOpacity),
|
|
518
|
-
left: Math.round(
|
|
519
|
-
size * (secondHandSize ?? defaultProps.secondHandSize) / 2 - counterweightWidth / 2
|
|
520
|
-
)
|
|
521
|
-
}
|
|
522
|
-
})
|
|
523
|
-
}
|
|
524
|
-
)
|
|
525
|
-
)),
|
|
526
|
-
/* @__PURE__ */ React.createElement(Box, { ...getStyles("centerBlur") }),
|
|
527
|
-
/* @__PURE__ */ React.createElement(
|
|
528
|
-
Box,
|
|
529
|
-
{
|
|
530
|
-
...getStyles("centerDot", {
|
|
531
|
-
style: {
|
|
532
|
-
width: centerSize,
|
|
533
|
-
height: centerSize,
|
|
534
|
-
opacity: round2(secondHandOpacity ?? defaultProps.secondHandOpacity),
|
|
535
|
-
top: Math.round(centerY - centerSize / 2),
|
|
536
|
-
left: Math.round(centerX - centerSize / 2)
|
|
537
|
-
}
|
|
538
|
-
})
|
|
539
|
-
}
|
|
540
|
-
)
|
|
541
|
-
)
|
|
542
|
-
)
|
|
543
|
-
);
|
|
46
|
+
};
|
|
544
47
|
});
|
|
545
|
-
|
|
546
|
-
const
|
|
547
|
-
const props = useProps("Clock", defaultProps,
|
|
48
|
+
const Clock = factory((_props) => {
|
|
49
|
+
const { ref, ...restProps } = _props;
|
|
50
|
+
const props = useProps("Clock", defaultProps, restProps);
|
|
548
51
|
const [time, setTime] = useState(/* @__PURE__ */ new Date());
|
|
549
52
|
const [hasMounted, setHasMounted] = useState(false);
|
|
550
53
|
const intervalRef = useRef(null);
|
|
@@ -634,10 +137,14 @@ const Clock = factory((_props, ref) => {
|
|
|
634
137
|
vars,
|
|
635
138
|
varsResolver
|
|
636
139
|
});
|
|
637
|
-
const
|
|
140
|
+
const resolvedSize = useMatches(
|
|
141
|
+
typeof size === "object" && size !== null && !Array.isArray(size) ? size : { base: size ?? defaultProps.size }
|
|
142
|
+
);
|
|
143
|
+
const isAutoSize = resolvedSize === "auto";
|
|
144
|
+
const effectiveSize = isAutoSize ? measuredSize ?? 400 : Math.round(
|
|
638
145
|
px(
|
|
639
146
|
getSize(
|
|
640
|
-
typeof
|
|
147
|
+
typeof resolvedSize === "string" && resolvedSize in defaultClockSizes ? defaultClockSizes[resolvedSize] : resolvedSize || defaultProps.size,
|
|
641
148
|
"clock-size"
|
|
642
149
|
)
|
|
643
150
|
)
|
|
@@ -650,7 +157,7 @@ const Clock = factory((_props, ref) => {
|
|
|
650
157
|
setHasMounted(true);
|
|
651
158
|
}, []);
|
|
652
159
|
useEffect(() => {
|
|
653
|
-
if (
|
|
160
|
+
if (!isAutoSize || !hasMounted) {
|
|
654
161
|
return;
|
|
655
162
|
}
|
|
656
163
|
const element = containerRef.current;
|
|
@@ -669,7 +176,7 @@ const Clock = factory((_props, ref) => {
|
|
|
669
176
|
});
|
|
670
177
|
observer.observe(element);
|
|
671
178
|
return () => observer.disconnect();
|
|
672
|
-
}, [
|
|
179
|
+
}, [isAutoSize, hasMounted]);
|
|
673
180
|
const getEffectiveTime = () => {
|
|
674
181
|
const parsedValue = parseTimeValue(value);
|
|
675
182
|
if (!running) {
|
|
@@ -758,7 +265,10 @@ const Clock = factory((_props, ref) => {
|
|
|
758
265
|
Box,
|
|
759
266
|
{
|
|
760
267
|
...getStyles("root", {
|
|
761
|
-
style:
|
|
268
|
+
style: {
|
|
269
|
+
...{ "--clock-size": `${effectiveSize}px` },
|
|
270
|
+
...isAutoSize ? { width: "100%", height: "100%" } : { width: geometry.width, height: geometry.height }
|
|
271
|
+
}
|
|
762
272
|
}),
|
|
763
273
|
ref: mergedRef,
|
|
764
274
|
role: "img",
|
|
@@ -822,7 +332,10 @@ const Clock = factory((_props, ref) => {
|
|
|
822
332
|
Box,
|
|
823
333
|
{
|
|
824
334
|
...getStyles("root", {
|
|
825
|
-
style:
|
|
335
|
+
style: {
|
|
336
|
+
...{ "--clock-size": `${effectiveSize}px` },
|
|
337
|
+
...isAutoSize ? { width: "100%", height: "100%" } : { width: geometry.width, height: geometry.height }
|
|
338
|
+
}
|
|
826
339
|
}),
|
|
827
340
|
ref: mergedRef,
|
|
828
341
|
role: "img",
|