Add new MFM animation syntax

This commit is contained in:
syuilo 2020-11-02 15:37:42 +09:00
parent 3d063c95d1
commit d44cb7f256
5 changed files with 69 additions and 12 deletions

View File

@ -131,6 +131,12 @@ export default defineComponent({
}, genEl(token.children)); }, 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': { case 'url': {
return [h(MkUrl, { return [h(MkUrl, {
key: Math.random(), key: Math.random(),

View File

@ -499,19 +499,58 @@ hr {
100% { transform: translateY(0); } 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 { @keyframes anime-twitch {
0% { transform: translate(0px, -9px); } 0% { transform: translate(7px, -2px) }
10% { transform: translate(5px, -11px); } 5% { transform: translate(-3px, 1px) }
20% { transform: translate(-12px, 2px); } 10% { transform: translate(-7px, -1px) }
30% { transform: translate(10px, 4px); } 15% { transform: translate(0px, -1px) }
40% { transform: translate(0px, 9px); } 20% { transform: translate(-8px, 6px) }
50% { transform: translate(-6px, 2px); } 25% { transform: translate(-4px, -3px) }
60% { transform: translate(-7px, 7px); } 30% { transform: translate(-4px, -6px) }
70% { transform: translate(14px, 7px); } 35% { transform: translate(-8px, -8px) }
80% { transform: translate(-5px, 10px); } 40% { transform: translate(4px, 6px) }
90% { transform: translate(3px, -3px); } 45% { transform: translate(-3px, 1px) }
100% { transform: translate(10px, 8px); } 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 { @keyframes anime-tada {

View File

@ -77,6 +77,7 @@ export const mfmLanguage = P.createLanguage({
r.jump, r.jump,
r.flip, r.flip,
r.twitch, r.twitch,
r.shake,
r.inlineCode, r.inlineCode,
r.mathInline, r.mathInline,
r.mention, r.mention,
@ -124,6 +125,7 @@ export const mfmLanguage = P.createLanguage({
jump: r => P.regexp(/<jump>(.+?)<\/jump>/, 1).map(x => createTree('jump', r.inline.atLeast(1).tryParse(x), {})), jump: r => P.regexp(/<jump>(.+?)<\/jump>/, 1).map(x => createTree('jump', r.inline.atLeast(1).tryParse(x), {})),
flip: r => P.regexp(/<flip>(.+?)<\/flip>/, 1).map(x => createTree('flip', r.inline.atLeast(1).tryParse(x), {})), flip: r => P.regexp(/<flip>(.+?)<\/flip>/, 1).map(x => createTree('flip', r.inline.atLeast(1).tryParse(x), {})),
twitch: r => P.regexp(/<twitch>(.+?)<\/twitch>/, 1).map(x => createTree('twitch', r.inline.atLeast(1).tryParse(x), {})), twitch: r => P.regexp(/<twitch>(.+?)<\/twitch>/, 1).map(x => createTree('twitch', r.inline.atLeast(1).tryParse(x), {})),
shake: r => P.regexp(/<shake>(.+?)<\/shake>/, 1).map(x => createTree('shake', r.inline.atLeast(1).tryParse(x), {})),
center: r => r.startOfLine.then(P.regexp(/<center>([\s\S]+?)<\/center>/, 1).map(x => createTree('center', r.inline.atLeast(1).tryParse(x), {}))), center: r => r.startOfLine.then(P.regexp(/<center>([\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 })), 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() }))), mathBlock: r => r.startOfLine.then(P.regexp(/\\\[([\s\S]+?)\\\]/, 1).map(x => createLeaf('mathBlock', { formula: x.trim() }))),

View File

@ -73,6 +73,12 @@ export function toHtml(tokens: MfmForest | null, mentionedRemoteUsers: IMentione
return el; return el;
}, },
shake(token) {
const el = doc.createElement('i');
appendChildren(token.children, el);
return el;
},
flip(token) { flip(token) {
const el = doc.createElement('span'); const el = doc.createElement('span');
appendChildren(token.children, el); appendChildren(token.children, el);

View File

@ -52,6 +52,10 @@ export function toString(tokens: MfmForest | null, opts?: RestoreOptions): strin
return `<twitch>${appendChildren(token.children, opts)}</twitch>`; return `<twitch>${appendChildren(token.children, opts)}</twitch>`;
}, },
shake(token, opts) {
return `<shake>${appendChildren(token.children, opts)}</shake>`;
},
flip(token, opts) { flip(token, opts) {
return `<flip>${appendChildren(token.children, opts)}</flip>`; return `<flip>${appendChildren(token.children, opts)}</flip>`;
}, },