文字数が多い場合は動きを無効に

This commit is contained in:
syuilo 2018-08-05 19:20:26 +09:00
parent 559e6d0722
commit a3c8bf74e9
2 changed files with 36 additions and 17 deletions

View file

@ -183,6 +183,7 @@
"showdown-highlightjs-extension": "0.1.2", "showdown-highlightjs-extension": "0.1.2",
"single-line-log": "1.1.2", "single-line-log": "1.1.2",
"speakeasy": "2.0.0", "speakeasy": "2.0.0",
"stringz": "1.0.0",
"style-loader": "0.21.0", "style-loader": "0.21.0",
"stylus": "0.54.5", "stylus": "0.54.5",
"stylus-loader": "3.0.2", "stylus-loader": "3.0.2",

View file

@ -1,5 +1,6 @@
import Vue from 'vue'; import Vue from 'vue';
import * as emojilib from 'emojilib'; import * as emojilib from 'emojilib';
import { length } from 'stringz';
import parse from '../../../../../mfm/parse'; import parse from '../../../../../mfm/parse';
import getAcct from '../../../../../misc/acct/render'; import getAcct from '../../../../../misc/acct/render';
import { url } from '../../../config'; import { url } from '../../../config';
@ -43,7 +44,7 @@ export default Vue.component('misskey-flavored-markdown', {
// Parse ast to DOM // Parse ast to DOM
const els = flatten(ast.map(token => { const els = flatten(ast.map(token => {
switch (token.type) { switch (token.type) {
case 'text': case 'text': {
const text = token.content.replace(/(\r\n|\n|\r)/g, '\n'); const text = token.content.replace(/(\r\n|\n|\r)/g, '\n');
if (this.shouldBreak) { if (this.shouldBreak) {
@ -54,41 +55,48 @@ export default Vue.component('misskey-flavored-markdown', {
} else { } else {
return createElement('span', text.replace(/\n/g, ' ')); return createElement('span', text.replace(/\n/g, ' '));
} }
}
case 'bold': case 'bold': {
return createElement('b', token.bold); return createElement('b', token.bold);
}
case 'big': case 'big': {
const isLong = length(token.big) > 10;
return (createElement as any)('strong', { return (createElement as any)('strong', {
attrs: { attrs: {
style: 'display: inline-block; font-size: 200%;' style: 'display: inline-block; font-size: 200%;'
}, },
directives: [this.$store.state.settings.disableAnimatedMfm ? {} : { directives: [this.$store.state.settings.disableAnimatedMfm || isLong ? {} : {
name: 'animate-css', name: 'animate-css',
value: { classes: 'tada', iteration: 'infinite' } value: { classes: 'tada', iteration: 'infinite' }
}] }]
}, token.big); }, token.big);
}
case 'motion': case 'motion': {
const isLong = length(token.motion) > 10;
return (createElement as any)('span', { return (createElement as any)('span', {
attrs: { attrs: {
style: 'display: inline-block;' style: 'display: inline-block;'
}, },
directives: [this.$store.state.settings.disableAnimatedMfm ? {} : { directives: [this.$store.state.settings.disableAnimatedMfm || isLong ? {} : {
name: 'animate-css', name: 'animate-css',
value: { classes: 'rubberBand', iteration: 'infinite' } value: { classes: 'rubberBand', iteration: 'infinite' }
}] }]
}, token.motion); }, token.motion);
}
case 'url': case 'url': {
return createElement(MkUrl, { return createElement(MkUrl, {
props: { props: {
url: token.content, url: token.content,
target: '_blank' target: '_blank'
} }
}); });
}
case 'link': case 'link': {
return createElement('a', { return createElement('a', {
attrs: { attrs: {
class: 'link', class: 'link',
@ -97,8 +105,9 @@ export default Vue.component('misskey-flavored-markdown', {
title: token.url title: token.url
} }
}, token.title); }, token.title);
}
case 'mention': case 'mention': {
return (createElement as any)('a', { return (createElement as any)('a', {
attrs: { attrs: {
href: `${url}/@${getAcct(token)}`, href: `${url}/@${getAcct(token)}`,
@ -110,16 +119,18 @@ export default Vue.component('misskey-flavored-markdown', {
value: token.content value: token.content
}] }]
}, token.content); }, token.content);
}
case 'hashtag': case 'hashtag': {
return createElement('a', { return createElement('a', {
attrs: { attrs: {
href: `${url}/tags/${encodeURIComponent(token.hashtag)}`, href: `${url}/tags/${encodeURIComponent(token.hashtag)}`,
target: '_blank' target: '_blank'
} }
}, token.content); }, token.content);
}
case 'code': case 'code': {
return createElement('pre', { return createElement('pre', {
class: 'code' class: 'code'
}, [ }, [
@ -129,15 +140,17 @@ export default Vue.component('misskey-flavored-markdown', {
} }
}) })
]); ]);
}
case 'inline-code': case 'inline-code': {
return createElement('code', { return createElement('code', {
domProps: { domProps: {
innerHTML: token.html innerHTML: token.html
} }
}); });
}
case 'quote': case 'quote': {
const text2 = token.quote.replace(/(\r\n|\n|\r)/g, '\n'); const text2 = token.quote.replace(/(\r\n|\n|\r)/g, '\n');
if (this.shouldBreak) { if (this.shouldBreak) {
@ -156,27 +169,32 @@ export default Vue.component('misskey-flavored-markdown', {
} }
}, text2.replace(/\n/g, ' ')); }, text2.replace(/\n/g, ' '));
} }
}
case 'title': case 'title': {
return createElement('div', { return createElement('div', {
attrs: { attrs: {
class: 'title' class: 'title'
} }
}, token.title); }, token.title);
}
case 'emoji': case 'emoji': {
const emoji = emojilib.lib[token.emoji]; const emoji = emojilib.lib[token.emoji];
return createElement('span', emoji ? emoji.char : token.content); return createElement('span', emoji ? emoji.char : token.content);
}
case 'search': case 'search': {
return createElement(MkGoogle, { return createElement(MkGoogle, {
props: { props: {
q: token.query q: token.query
} }
}); });
}
default: default: {
console.log('unknown ast type:', token.type); console.log('unknown ast type:', token.type);
}
} }
})); }));