From 1d5444aae777e9f11db0d89f2b9b63c80e894f76 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 2 Nov 2020 15:37:42 +0900 Subject: [PATCH] Add new MFM animation syntax --- src/client/components/mfm.ts | 6 ++++ src/client/style.scss | 63 +++++++++++++++++++++++++++++------- src/mfm/language.ts | 2 ++ src/mfm/to-html.ts | 6 ++++ src/mfm/to-string.ts | 4 +++ 5 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/client/components/mfm.ts b/src/client/components/mfm.ts index 7e4fec284..e1216614a 100644 --- a/src/client/components/mfm.ts +++ b/src/client/components/mfm.ts @@ -131,6 +131,12 @@ export default defineComponent({ }, genEl(token.children)); } + case 'shake': { + return h('span', { + style: this.$store.state.device.animatedMfm ? 'display: inline-block; animation: anime-shake 0.5s ease infinite;' : 'display: inline-block;' + }, genEl(token.children)); + } + case 'url': { return [h(MkUrl, { key: Math.random(), diff --git a/src/client/style.scss b/src/client/style.scss index be9e37329..07abbe081 100644 --- a/src/client/style.scss +++ b/src/client/style.scss @@ -499,19 +499,58 @@ hr { 100% { transform: translateY(0); } } -// const gen = () => `translate(${Math.floor(Math.random() * 24) - 12}px, ${Math.floor(Math.random() * 24) - 12}px)` +// const val = () => `translate(${Math.floor(Math.random() * 20) - 10}px, ${Math.floor(Math.random() * 20) - 10}px)`; +// let css = ''; +// for (let i = 0; i <= 100; i += 5) { css += `${i}% { transform: ${val()} }\n`; } @keyframes anime-twitch { - 0% { transform: translate(0px, -9px); } - 10% { transform: translate(5px, -11px); } - 20% { transform: translate(-12px, 2px); } - 30% { transform: translate(10px, 4px); } - 40% { transform: translate(0px, 9px); } - 50% { transform: translate(-6px, 2px); } - 60% { transform: translate(-7px, 7px); } - 70% { transform: translate(14px, 7px); } - 80% { transform: translate(-5px, 10px); } - 90% { transform: translate(3px, -3px); } - 100% { transform: translate(10px, 8px); } + 0% { transform: translate(7px, -2px) } + 5% { transform: translate(-3px, 1px) } + 10% { transform: translate(-7px, -1px) } + 15% { transform: translate(0px, -1px) } + 20% { transform: translate(-8px, 6px) } + 25% { transform: translate(-4px, -3px) } + 30% { transform: translate(-4px, -6px) } + 35% { transform: translate(-8px, -8px) } + 40% { transform: translate(4px, 6px) } + 45% { transform: translate(-3px, 1px) } + 50% { transform: translate(2px, -10px) } + 55% { transform: translate(-7px, 0px) } + 60% { transform: translate(-2px, 4px) } + 65% { transform: translate(3px, -8px) } + 70% { transform: translate(6px, 7px) } + 75% { transform: translate(-7px, -2px) } + 80% { transform: translate(-7px, -8px) } + 85% { transform: translate(9px, 3px) } + 90% { transform: translate(-3px, -2px) } + 95% { transform: translate(-10px, 2px) } + 100% { transform: translate(-2px, -6px) } +} + +// const val = () => `translate(${Math.floor(Math.random() * 6) - 3}px, ${Math.floor(Math.random() * 6) - 3}px) rotate(${Math.floor(Math.random() * 24) - 12}deg)`; +// let css = ''; +// for (let i = 0; i <= 100; i += 5) { css += `${i}% { transform: ${val()} }\n`; } +@keyframes anime-shake { + 0% { transform: translate(-3px, -1px) rotate(-8deg) } + 5% { transform: translate(0px, -1px) rotate(-10deg) } + 10% { transform: translate(1px, -3px) rotate(0deg) } + 15% { transform: translate(1px, 1px) rotate(11deg) } + 20% { transform: translate(-2px, 1px) rotate(1deg) } + 25% { transform: translate(-1px, -2px) rotate(-2deg) } + 30% { transform: translate(-1px, 2px) rotate(-3deg) } + 35% { transform: translate(2px, 1px) rotate(6deg) } + 40% { transform: translate(-2px, -3px) rotate(-9deg) } + 45% { transform: translate(0px, -1px) rotate(-12deg) } + 50% { transform: translate(1px, 2px) rotate(10deg) } + 55% { transform: translate(0px, -3px) rotate(8deg) } + 60% { transform: translate(1px, -1px) rotate(8deg) } + 65% { transform: translate(0px, -1px) rotate(-7deg) } + 70% { transform: translate(-1px, -3px) rotate(6deg) } + 75% { transform: translate(0px, -2px) rotate(4deg) } + 80% { transform: translate(-2px, -1px) rotate(3deg) } + 85% { transform: translate(1px, -3px) rotate(-10deg) } + 90% { transform: translate(1px, 0px) rotate(3deg) } + 95% { transform: translate(-2px, 0px) rotate(-3deg) } + 100% { transform: translate(2px, 1px) rotate(2deg) } } @keyframes anime-tada { diff --git a/src/mfm/language.ts b/src/mfm/language.ts index f334301d1..61d642255 100644 --- a/src/mfm/language.ts +++ b/src/mfm/language.ts @@ -77,6 +77,7 @@ export const mfmLanguage = P.createLanguage({ r.jump, r.flip, r.twitch, + r.shake, r.inlineCode, r.mathInline, r.mention, @@ -124,6 +125,7 @@ export const mfmLanguage = P.createLanguage({ jump: r => P.regexp(/(.+?)<\/jump>/, 1).map(x => createTree('jump', r.inline.atLeast(1).tryParse(x), {})), flip: r => P.regexp(/(.+?)<\/flip>/, 1).map(x => createTree('flip', r.inline.atLeast(1).tryParse(x), {})), twitch: r => P.regexp(/(.+?)<\/twitch>/, 1).map(x => createTree('twitch', r.inline.atLeast(1).tryParse(x), {})), + shake: r => P.regexp(/(.+?)<\/shake>/, 1).map(x => createTree('shake', r.inline.atLeast(1).tryParse(x), {})), center: r => r.startOfLine.then(P.regexp(/
([\s\S]+?)<\/center>/, 1).map(x => createTree('center', r.inline.atLeast(1).tryParse(x), {}))), inlineCode: () => P.regexp(/`([^ยด\n]+?)`/, 1).map(x => createLeaf('inlineCode', { code: x })), mathBlock: r => r.startOfLine.then(P.regexp(/\\\[([\s\S]+?)\\\]/, 1).map(x => createLeaf('mathBlock', { formula: x.trim() }))), diff --git a/src/mfm/to-html.ts b/src/mfm/to-html.ts index d58bf386e..36680e374 100644 --- a/src/mfm/to-html.ts +++ b/src/mfm/to-html.ts @@ -73,6 +73,12 @@ export function toHtml(tokens: MfmForest | null, mentionedRemoteUsers: IMentione return el; }, + shake(token) { + const el = doc.createElement('i'); + appendChildren(token.children, el); + return el; + }, + flip(token) { const el = doc.createElement('span'); appendChildren(token.children, el); diff --git a/src/mfm/to-string.ts b/src/mfm/to-string.ts index a6e2a9916..6b8dcf2c3 100644 --- a/src/mfm/to-string.ts +++ b/src/mfm/to-string.ts @@ -52,6 +52,10 @@ export function toString(tokens: MfmForest | null, opts?: RestoreOptions): strin return `${appendChildren(token.children, opts)}`; }, + shake(token, opts) { + return `${appendChildren(token.children, opts)}`; + }, + flip(token, opts) { return `${appendChildren(token.children, opts)}`; },