2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-12 03:37:45 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-02-14 15:31:24 +01:00
|
|
|
<template>
|
2023-05-24 10:50:15 +02:00
|
|
|
<MkContainer :naked="widgetProps.transparent" :showHeader="false" data-cy-mkw-clock>
|
2023-06-01 10:19:46 +02:00
|
|
|
<div
|
|
|
|
:class="[$style.root, {
|
|
|
|
[$style.small]: widgetProps.size === 'small',
|
|
|
|
[$style.medium]: widgetProps.size === 'medium',
|
|
|
|
[$style.large]: widgetProps.size === 'large',
|
|
|
|
}]"
|
|
|
|
>
|
2023-05-24 10:50:15 +02:00
|
|
|
<div v-if="widgetProps.label === 'tz' || widgetProps.label === 'timeAndTz'" class="_monospace" :class="[$style.label, $style.a]">{{ tzAbbrev }}</div>
|
2022-08-06 07:02:03 +02:00
|
|
|
<MkAnalogClock
|
2023-05-24 10:50:15 +02:00
|
|
|
:class="$style.clock"
|
2022-08-06 07:02:03 +02:00
|
|
|
:thickness="widgetProps.thickness"
|
|
|
|
:offset="tzOffset"
|
|
|
|
:graduations="widgetProps.graduations"
|
2023-05-19 09:20:53 +02:00
|
|
|
:fadeGraduations="widgetProps.fadeGraduations"
|
2022-08-06 07:02:03 +02:00
|
|
|
:twentyfour="widgetProps.twentyFour"
|
2023-05-19 09:20:53 +02:00
|
|
|
:sAnimation="widgetProps.sAnimation"
|
2022-08-06 07:02:03 +02:00
|
|
|
/>
|
2023-05-24 10:50:15 +02:00
|
|
|
<MkDigitalClock v-if="widgetProps.label === 'time' || widgetProps.label === 'timeAndTz'" :class="[$style.label, $style.c]" class="_monospace" :showS="false" :offset="tzOffset"/>
|
|
|
|
<div v-if="widgetProps.label === 'tz' || widgetProps.label === 'timeAndTz'" class="_monospace" :class="[$style.label, $style.d]">{{ tzOffsetLabel }}</div>
|
2020-07-11 03:13:11 +02:00
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkContainer>
|
2020-02-14 15:31:24 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { computed } from 'vue';
|
2023-12-21 03:36:45 +01:00
|
|
|
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2022-08-30 17:24:33 +02:00
|
|
|
import MkAnalogClock from '@/components/MkAnalogClock.vue';
|
|
|
|
import MkDigitalClock from '@/components/MkDigitalClock.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { timezones } from '@/scripts/timezones.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const name = 'clock';
|
|
|
|
|
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2020-02-14 15:31:24 +01:00
|
|
|
},
|
2022-08-06 07:02:03 +02:00
|
|
|
size: {
|
|
|
|
type: 'radio' as const,
|
|
|
|
default: 'medium',
|
|
|
|
options: [{
|
|
|
|
value: 'small', label: i18n.ts.small,
|
|
|
|
}, {
|
|
|
|
value: 'medium', label: i18n.ts.medium,
|
|
|
|
}, {
|
|
|
|
value: 'large', label: i18n.ts.large,
|
|
|
|
}],
|
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
thickness: {
|
|
|
|
type: 'radio' as const,
|
2022-08-06 09:39:09 +02:00
|
|
|
default: 0.2,
|
2022-01-08 12:30:01 +01:00
|
|
|
options: [{
|
2022-08-05 16:51:15 +02:00
|
|
|
value: 0.1, label: 'thin',
|
2022-01-08 12:30:01 +01:00
|
|
|
}, {
|
2022-08-05 16:51:15 +02:00
|
|
|
value: 0.2, label: 'medium',
|
2022-01-08 12:30:01 +01:00
|
|
|
}, {
|
2022-08-05 16:51:15 +02:00
|
|
|
value: 0.3, label: 'thick',
|
|
|
|
}],
|
|
|
|
},
|
2022-08-06 07:02:03 +02:00
|
|
|
graduations: {
|
|
|
|
type: 'radio' as const,
|
2022-08-06 09:39:09 +02:00
|
|
|
default: 'numbers',
|
2022-08-06 07:02:03 +02:00
|
|
|
options: [{
|
|
|
|
value: 'none', label: 'None',
|
|
|
|
}, {
|
|
|
|
value: 'dots', label: 'Dots',
|
|
|
|
}, {
|
|
|
|
value: 'numbers', label: 'Numbers',
|
|
|
|
}],
|
2022-08-05 16:51:15 +02:00
|
|
|
},
|
2022-08-06 09:39:09 +02:00
|
|
|
fadeGraduations: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
|
|
|
},
|
2022-08-30 19:19:25 +02:00
|
|
|
sAnimation: {
|
|
|
|
type: 'radio' as const,
|
|
|
|
default: 'elastic',
|
|
|
|
options: [{
|
|
|
|
value: 'none', label: 'None',
|
|
|
|
}, {
|
|
|
|
value: 'elastic', label: 'Elastic',
|
|
|
|
}, {
|
|
|
|
value: 'easeOut', label: 'Ease out',
|
|
|
|
}],
|
|
|
|
},
|
2022-08-05 16:51:15 +02:00
|
|
|
twentyFour: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
|
|
|
},
|
2022-08-06 11:15:13 +02:00
|
|
|
label: {
|
|
|
|
type: 'radio' as const,
|
|
|
|
default: 'none',
|
|
|
|
options: [{
|
|
|
|
value: 'none', label: 'None',
|
|
|
|
}, {
|
|
|
|
value: 'time', label: 'Time',
|
|
|
|
}, {
|
|
|
|
value: 'tz', label: 'TZ',
|
|
|
|
}, {
|
|
|
|
value: 'timeAndTz', label: 'Time + TZ',
|
|
|
|
}],
|
2022-08-05 16:51:15 +02:00
|
|
|
},
|
|
|
|
timezone: {
|
|
|
|
type: 'enum' as const,
|
|
|
|
default: null,
|
|
|
|
enum: [...timezones.map((tz) => ({
|
|
|
|
label: tz.name,
|
|
|
|
value: tz.name.toLowerCase(),
|
|
|
|
})), {
|
|
|
|
label: '(auto)',
|
|
|
|
value: null,
|
2022-01-08 12:30:01 +01:00
|
|
|
}],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
2023-05-19 09:20:53 +02:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const tzAbbrev = computed(() => (widgetProps.timezone === null
|
2022-08-05 16:51:15 +02:00
|
|
|
? timezones.find((tz) => tz.name.toLowerCase() === Intl.DateTimeFormat().resolvedOptions().timeZone.toLowerCase())?.abbrev
|
|
|
|
: timezones.find((tz) => tz.name.toLowerCase() === widgetProps.timezone)?.abbrev) ?? '?');
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const tzOffset = computed(() => widgetProps.timezone === null
|
2022-08-05 16:51:15 +02:00
|
|
|
? 0 - new Date().getTimezoneOffset()
|
|
|
|
: timezones.find((tz) => tz.name.toLowerCase() === widgetProps.timezone)?.offset ?? 0);
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const tzOffsetLabel = computed(() => (tzOffset.value >= 0 ? '+' : '-') + Math.floor(tzOffset.value / 60).toString().padStart(2, '0') + ':' + (tzOffset.value % 60).toString().padStart(2, '0'));
|
2022-08-05 16:51:15 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-02-14 15:31:24 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-05-24 10:50:15 +02:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2022-08-05 16:51:15 +02:00
|
|
|
position: relative;
|
|
|
|
|
2022-08-06 07:02:03 +02:00
|
|
|
&.small {
|
2022-08-06 11:15:13 +02:00
|
|
|
padding: 12px;
|
2022-08-06 07:02:03 +02:00
|
|
|
|
|
|
|
> .clock {
|
|
|
|
height: 100px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.medium {
|
2022-08-06 11:15:13 +02:00
|
|
|
padding: 14px;
|
2022-08-06 07:02:03 +02:00
|
|
|
|
|
|
|
> .clock {
|
|
|
|
height: 150px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.large {
|
|
|
|
padding: 16px;
|
|
|
|
|
|
|
|
> .clock {
|
|
|
|
height: 200px;
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 15:31:24 +01:00
|
|
|
}
|
2023-05-24 10:50:15 +02:00
|
|
|
|
|
|
|
.label {
|
|
|
|
position: absolute;
|
|
|
|
opacity: 0.7;
|
|
|
|
|
|
|
|
&.a {
|
|
|
|
top: 14px;
|
|
|
|
left: 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.b {
|
|
|
|
top: 14px;
|
|
|
|
right: 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.c {
|
|
|
|
bottom: 14px;
|
|
|
|
left: 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.d {
|
|
|
|
bottom: 14px;
|
|
|
|
right: 14px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.clock {
|
|
|
|
margin: auto;
|
|
|
|
}
|
2020-02-14 15:31:24 +01:00
|
|
|
</style>
|