moved reduced motion query to script
This commit is contained in:
parent
9eb1e90ed3
commit
b398001533
5 changed files with 27 additions and 28 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "calckey",
|
"name": "calckey",
|
||||||
"version": "12.119.0-calc.18-rc.3",
|
"version": "12.119.0-calc.18-rc.4",
|
||||||
"codename": "aqua",
|
"codename": "aqua",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -65,18 +65,18 @@
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onMounted, onUnmounted, ref } from 'vue';
|
import { onMounted, onUnmounted, ref } from 'vue';
|
||||||
|
import { reducedMotion } from '@/scripts/reduced-motion';
|
||||||
|
|
||||||
const particles = ref([]);
|
const particles = ref([]);
|
||||||
const el = ref<HTMLElement>();
|
const el = ref<HTMLElement>();
|
||||||
const width = ref(0);
|
const width = ref(0);
|
||||||
const height = ref(0);
|
const height = ref(0);
|
||||||
const colors = ['#eb6f92', '#9ccfd8', '#f6c177', '#f6c177', '#f6c177'];
|
const colors = ['#eb6f92', '#9ccfd8', '#f6c177', '#f6c177', '#f6c177'];
|
||||||
const reducedQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
||||||
let stop = false;
|
let stop = false;
|
||||||
let ro: ResizeObserver | undefined;
|
let ro: ResizeObserver | undefined;
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (!reducedQuery.matches) {
|
if (!reducedMotion()) {
|
||||||
ro = new ResizeObserver((entries, observer) => {
|
ro = new ResizeObserver((entries, observer) => {
|
||||||
width.value = el.value?.offsetWidth + 64;
|
width.value = el.value?.offsetWidth + 64;
|
||||||
height.value = el.value?.offsetHeight + 64;
|
height.value = el.value?.offsetHeight + 64;
|
||||||
|
|
|
@ -156,12 +156,6 @@ const props = withDefaults(defineProps<{
|
||||||
0% { filter: hue-rotate(0deg) contrast(150%) saturate(150%); }
|
0% { filter: hue-rotate(0deg) contrast(150%) saturate(150%); }
|
||||||
100% { filter: hue-rotate(360deg) contrast(150%) saturate(150%); }
|
100% { filter: hue-rotate(360deg) contrast(150%) saturate(150%); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@media(prefers-reduced-motion) {
|
|
||||||
span[class^='mfm'], span[class*=' mfm'] {
|
|
||||||
animation: none !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { VNode, defineComponent, h } from 'vue';
|
import { defineComponent, h } from 'vue';
|
||||||
import * as mfm from 'mfm-js';
|
import * as mfm from 'mfm-js';
|
||||||
|
import type { VNode } from 'vue';
|
||||||
import MkUrl from '@/components/global/MkUrl.vue';
|
import MkUrl from '@/components/global/MkUrl.vue';
|
||||||
import MkLink from '@/components/MkLink.vue';
|
import MkLink from '@/components/MkLink.vue';
|
||||||
import MkMention from '@/components/MkMention.vue';
|
import MkMention from '@/components/MkMention.vue';
|
||||||
|
@ -12,6 +13,7 @@ import MkSparkle from '@/components/MkSparkle.vue';
|
||||||
import MkA from '@/components/global/MkA.vue';
|
import MkA from '@/components/global/MkA.vue';
|
||||||
import { host } from '@/config';
|
import { host } from '@/config';
|
||||||
import { MFM_TAGS } from '@/scripts/mfm-tags';
|
import { MFM_TAGS } from '@/scripts/mfm-tags';
|
||||||
|
import { reducedMotion } from '@/scripts/reduced-motion';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
|
@ -92,22 +94,22 @@ export default defineComponent({
|
||||||
switch (token.props.name) {
|
switch (token.props.name) {
|
||||||
case 'tada': {
|
case 'tada': {
|
||||||
const speed = validTime(token.props.args.speed) || '1s';
|
const speed = validTime(token.props.args.speed) || '1s';
|
||||||
style = 'font-size: 150%;' + (this.$store.state.animatedMfm ? `animation: tada ${speed} linear infinite both;` : '');
|
style = 'font-size: 150%;' + (this.$store.state.animatedMfm && !reducedMotion() ? `animation: tada ${speed} linear infinite both;` : '');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'jelly': {
|
case 'jelly': {
|
||||||
const speed = validTime(token.props.args.speed) || '1s';
|
const speed = validTime(token.props.args.speed) || '1s';
|
||||||
style = (this.$store.state.animatedMfm ? `animation: mfm-rubberBand ${speed} linear infinite both;` : '');
|
style = (this.$store.state.animatedMfm && !reducedMotion() ? `animation: mfm-rubberBand ${speed} linear infinite both;` : '');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'twitch': {
|
case 'twitch': {
|
||||||
const speed = validTime(token.props.args.speed) || '0.5s';
|
const speed = validTime(token.props.args.speed) || '0.5s';
|
||||||
style = this.$store.state.animatedMfm ? `animation: mfm-twitch ${speed} ease infinite;` : '';
|
style = this.$store.state.animatedMfm && !reducedMotion() ? `animation: mfm-twitch ${speed} ease infinite;` : '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'shake': {
|
case 'shake': {
|
||||||
const speed = validTime(token.props.args.speed) || '0.5s';
|
const speed = validTime(token.props.args.speed) || '0.5s';
|
||||||
style = this.$store.state.animatedMfm ? `animation: mfm-shake ${speed} ease infinite;` : '';
|
style = this.$store.state.animatedMfm && !reducedMotion() ? `animation: mfm-shake ${speed} ease infinite;` : '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'spin': {
|
case 'spin': {
|
||||||
|
@ -120,19 +122,30 @@ export default defineComponent({
|
||||||
token.props.args.y ? 'mfm-spinY' :
|
token.props.args.y ? 'mfm-spinY' :
|
||||||
'mfm-spin';
|
'mfm-spin';
|
||||||
const speed = validTime(token.props.args.speed) || '1.5s';
|
const speed = validTime(token.props.args.speed) || '1.5s';
|
||||||
style = this.$store.state.animatedMfm ? `animation: ${anime} ${speed} linear infinite; animation-direction: ${direction};` : '';
|
style = this.$store.state.animatedMfm && !reducedMotion() ? `animation: ${anime} ${speed} linear infinite; animation-direction: ${direction};` : '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'jump': {
|
case 'jump': {
|
||||||
const speed = validTime(token.props.args.speed) || '0.75s';
|
const speed = validTime(token.props.args.speed) || '0.75s';
|
||||||
style = this.$store.state.animatedMfm ? `animation: mfm-jump ${speed} linear infinite;` : '';
|
style = this.$store.state.animatedMfm && !reducedMotion() ? `animation: mfm-jump ${speed} linear infinite;` : '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'bounce': {
|
case 'bounce': {
|
||||||
const speed = validTime(token.props.args.speed) || '0.75s';
|
const speed = validTime(token.props.args.speed) || '0.75s';
|
||||||
style = this.$store.state.animatedMfm ? `animation: mfm-bounce ${speed} linear infinite; transform-origin: center bottom;` : '';
|
style = this.$store.state.animatedMfm && !reducedMotion() ? `animation: mfm-bounce ${speed} linear infinite; transform-origin: center bottom;` : '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'rainbow': {
|
||||||
|
const speed = validTime(token.props.args.speed) || '1s';
|
||||||
|
style = this.$store.state.animatedMfm && !reducedMotion() ? `animation: mfm-rainbow ${speed} linear infinite;` : '';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'sparkle': {
|
||||||
|
if (!this.$store.state.animatedMfm && !reducedMotion()) {
|
||||||
|
return genEl(token.children);
|
||||||
|
}
|
||||||
|
return h(MkSparkle, {}, genEl(token.children));
|
||||||
|
}
|
||||||
case 'flip': {
|
case 'flip': {
|
||||||
const transform =
|
const transform =
|
||||||
(token.props.args.h && token.props.args.v) ? 'scale(-1, -1)' :
|
(token.props.args.h && token.props.args.v) ? 'scale(-1, -1)' :
|
||||||
|
@ -173,17 +186,6 @@ export default defineComponent({
|
||||||
class: '_mfm_blur_',
|
class: '_mfm_blur_',
|
||||||
}, genEl(token.children));
|
}, genEl(token.children));
|
||||||
}
|
}
|
||||||
case 'rainbow': {
|
|
||||||
const speed = validTime(token.props.args.speed) || '1s';
|
|
||||||
style = this.$store.state.animatedMfm ? `animation: mfm-rainbow ${speed} linear infinite;` : '';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'sparkle': {
|
|
||||||
if (!this.$store.state.animatedMfm) {
|
|
||||||
return genEl(token.children);
|
|
||||||
}
|
|
||||||
return h(MkSparkle, {}, genEl(token.children));
|
|
||||||
}
|
|
||||||
case 'rotate': {
|
case 'rotate': {
|
||||||
const rotate =
|
const rotate =
|
||||||
token.props.args.x ? 'perspective(128px) rotateX' :
|
token.props.args.x ? 'perspective(128px) rotateX' :
|
||||||
|
|
3
packages/client/src/scripts/reduced-motion.ts
Normal file
3
packages/client/src/scripts/reduced-motion.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export function reducedMotion(): boolean {
|
||||||
|
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||||
|
}
|
Loading…
Reference in a new issue