2020-02-14 23:31:24 +09:00
|
|
|
<template>
|
2020-02-14 23:55:13 +09:00
|
|
|
<svg class="mbcofsoe" viewBox="0 0 10 10" preserveAspectRatio="none">
|
2022-08-05 23:51:15 +09:00
|
|
|
<circle
|
|
|
|
v-for="(angle, i) in graduations"
|
|
|
|
:key="i"
|
|
|
|
:cx="5 + (Math.sin(angle) * (5 - graduationsPadding))"
|
|
|
|
:cy="5 - (Math.cos(angle) * (5 - graduationsPadding))"
|
|
|
|
:r="i % 5 == 0 ? 0.125 : 0.05"
|
|
|
|
:fill="i % 5 == 0 ? majorGraduationColor : minorGraduationColor"
|
2021-07-19 23:31:27 +09:00
|
|
|
/>
|
2020-02-14 23:31:24 +09:00
|
|
|
|
2022-08-05 23:51:15 +09:00
|
|
|
<template v-if="props.numbers">
|
|
|
|
<text
|
|
|
|
v-for="(angle, i) in texts"
|
|
|
|
:x="5 + (Math.sin(angle) * (5 - textsPadding))"
|
|
|
|
:y="5 - (Math.cos(angle) * (5 - textsPadding))"
|
|
|
|
text-anchor="middle"
|
|
|
|
dominant-baseline="middle"
|
|
|
|
font-family="Verdana"
|
|
|
|
font-size="0.75"
|
|
|
|
fill="currentColor"
|
|
|
|
>
|
|
|
|
{{ i === 0 ? (props.twentyfour ? '24' : '12') : i }}
|
|
|
|
</text>
|
|
|
|
</template>
|
|
|
|
|
2020-02-14 23:31:24 +09:00
|
|
|
<line
|
|
|
|
:x1="5 - (Math.sin(sAngle) * (sHandLengthRatio * handsTailLength))"
|
|
|
|
:y1="5 + (Math.cos(sAngle) * (sHandLengthRatio * handsTailLength))"
|
|
|
|
:x2="5 + (Math.sin(sAngle) * ((sHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:y2="5 - (Math.cos(sAngle) * ((sHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:stroke="sHandColor"
|
2021-07-19 23:31:27 +09:00
|
|
|
:stroke-width="thickness / 2"
|
2021-07-19 23:48:22 +09:00
|
|
|
stroke-linecap="round"
|
2021-07-19 23:31:27 +09:00
|
|
|
/>
|
2020-02-14 23:31:24 +09:00
|
|
|
|
|
|
|
<line
|
|
|
|
:x1="5 - (Math.sin(mAngle) * (mHandLengthRatio * handsTailLength))"
|
|
|
|
:y1="5 + (Math.cos(mAngle) * (mHandLengthRatio * handsTailLength))"
|
|
|
|
:x2="5 + (Math.sin(mAngle) * ((mHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:y2="5 - (Math.cos(mAngle) * ((mHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:stroke="mHandColor"
|
2021-07-19 23:31:27 +09:00
|
|
|
:stroke-width="thickness"
|
2021-07-19 23:48:22 +09:00
|
|
|
stroke-linecap="round"
|
2021-07-19 23:31:27 +09:00
|
|
|
/>
|
2020-02-14 23:31:24 +09:00
|
|
|
|
|
|
|
<line
|
|
|
|
:x1="5 - (Math.sin(hAngle) * (hHandLengthRatio * handsTailLength))"
|
|
|
|
:y1="5 + (Math.cos(hAngle) * (hHandLengthRatio * handsTailLength))"
|
|
|
|
:x2="5 + (Math.sin(hAngle) * ((hHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:y2="5 - (Math.cos(hAngle) * ((hHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:stroke="hHandColor"
|
2021-07-19 23:31:27 +09:00
|
|
|
:stroke-width="thickness"
|
2021-07-19 23:48:22 +09:00
|
|
|
stroke-linecap="round"
|
2021-07-19 23:31:27 +09:00
|
|
|
/>
|
2020-02-14 23:31:24 +09:00
|
|
|
</svg>
|
|
|
|
</template>
|
|
|
|
|
2022-01-11 00:05:18 +09:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { ref, computed, onMounted, onBeforeUnmount } from 'vue';
|
2022-05-01 22:51:07 +09:00
|
|
|
import tinycolor from 'tinycolor2';
|
2020-02-14 23:31:24 +09:00
|
|
|
|
2022-08-05 23:51:15 +09:00
|
|
|
const graduationsPadding = 0.5;
|
|
|
|
const textsPadding = 0.5;
|
|
|
|
const handsPadding = 1;
|
|
|
|
const handsTailLength = 0.7;
|
|
|
|
const hHandLengthRatio = 0.75;
|
|
|
|
const mHandLengthRatio = 1;
|
|
|
|
const sHandLengthRatio = 1;
|
|
|
|
const graduations = (() => {
|
|
|
|
const angles: number[] = [];
|
|
|
|
for (let i = 0; i < 60; i++) {
|
|
|
|
const angle = Math.PI * i / 30;
|
|
|
|
angles.push(angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return angles;
|
|
|
|
})();
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
numbers?: boolean;
|
|
|
|
thickness?: number;
|
|
|
|
offset?: number;
|
|
|
|
twentyfour?: boolean;
|
2022-01-11 00:05:18 +09:00
|
|
|
}>(), {
|
2022-08-05 23:51:15 +09:00
|
|
|
numbers: false,
|
2022-01-11 00:05:18 +09:00
|
|
|
thickness: 0.1,
|
2022-08-05 23:51:15 +09:00
|
|
|
offset: 0 - new Date().getTimezoneOffset(),
|
|
|
|
twentyfour: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const texts = computed(() => {
|
|
|
|
const angles: number[] = [];
|
|
|
|
const times = props.twentyfour ? 24 : 12;
|
|
|
|
for (let i = 0; i < times; i++) {
|
|
|
|
const angle = Math.PI * i / (times / 2);
|
|
|
|
angles.push(angle);
|
|
|
|
}
|
|
|
|
return angles;
|
2022-01-11 00:05:18 +09:00
|
|
|
});
|
2020-02-14 23:31:24 +09:00
|
|
|
|
2022-01-11 00:05:18 +09:00
|
|
|
const now = ref(new Date());
|
2022-08-05 23:51:15 +09:00
|
|
|
now.value.setMinutes(now.value.getMinutes() + (new Date().getTimezoneOffset() + props.offset));
|
|
|
|
|
2022-01-11 00:05:18 +09:00
|
|
|
const enabled = ref(true);
|
|
|
|
const computedStyle = getComputedStyle(document.documentElement);
|
|
|
|
const dark = computed(() => tinycolor(computedStyle.getPropertyValue('--bg')).isDark());
|
|
|
|
const majorGraduationColor = computed(() => dark.value ? 'rgba(255, 255, 255, 0.3)' : 'rgba(0, 0, 0, 0.3)');
|
|
|
|
const minorGraduationColor = computed(() => dark.value ? 'rgba(255, 255, 255, 0.2)' : 'rgba(0, 0, 0, 0.2)');
|
|
|
|
const sHandColor = computed(() => dark.value ? 'rgba(255, 255, 255, 0.5)' : 'rgba(0, 0, 0, 0.3)');
|
|
|
|
const mHandColor = computed(() => tinycolor(computedStyle.getPropertyValue('--fg')).toHexString());
|
|
|
|
const hHandColor = computed(() => tinycolor(computedStyle.getPropertyValue('--accent')).toHexString());
|
|
|
|
const s = computed(() => now.value.getSeconds());
|
|
|
|
const m = computed(() => now.value.getMinutes());
|
|
|
|
const h = computed(() => now.value.getHours());
|
2022-08-05 23:51:15 +09:00
|
|
|
const hAngle = computed(() => Math.PI * (h.value % (props.twentyfour ? 24 : 12) + (m.value + s.value / 60) / 60) / (props.twentyfour ? 12 : 6));
|
2022-01-11 00:05:18 +09:00
|
|
|
const mAngle = computed(() => Math.PI * (m.value + s.value / 60) / 30);
|
|
|
|
const sAngle = computed(() => Math.PI * s.value / 30);
|
2020-02-14 23:31:24 +09:00
|
|
|
|
2022-01-11 00:05:18 +09:00
|
|
|
function tick() {
|
|
|
|
now.value = new Date();
|
2022-08-05 23:51:15 +09:00
|
|
|
now.value.setMinutes(now.value.getMinutes() + (new Date().getTimezoneOffset() + props.offset));
|
2022-01-11 00:05:18 +09:00
|
|
|
}
|
2020-02-14 23:31:24 +09:00
|
|
|
|
2022-01-11 00:05:18 +09:00
|
|
|
onMounted(() => {
|
|
|
|
const update = () => {
|
|
|
|
if (enabled.value) {
|
|
|
|
tick();
|
2022-01-16 10:14:14 +09:00
|
|
|
window.setTimeout(update, 1000);
|
2020-02-14 23:31:24 +09:00
|
|
|
}
|
2022-01-11 00:05:18 +09:00
|
|
|
};
|
|
|
|
update();
|
|
|
|
});
|
2020-02-14 23:31:24 +09:00
|
|
|
|
2022-01-11 00:05:18 +09:00
|
|
|
onBeforeUnmount(() => {
|
|
|
|
enabled.value = false;
|
2020-02-14 23:31:24 +09:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2020-02-14 23:55:13 +09:00
|
|
|
.mbcofsoe {
|
2020-02-14 23:31:24 +09:00
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
</style>
|