mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 01:47:39 -07:00
add border mfm
This commit is contained in:
parent
48f77e071b
commit
bb13125935
2 changed files with 31 additions and 0 deletions
|
@ -14,6 +14,7 @@ import MkA from "@/components/global/MkA.vue";
|
||||||
import { host } from "@/config";
|
import { host } from "@/config";
|
||||||
import { reducedMotion } from "@/scripts/reduced-motion";
|
import { reducedMotion } from "@/scripts/reduced-motion";
|
||||||
import { defaultStore } from "@/store";
|
import { defaultStore } from "@/store";
|
||||||
|
import { safeParseFloat } from "@/scripts/safe-parse";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
|
@ -70,6 +71,11 @@ export default defineComponent({
|
||||||
// : null
|
// : null
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
const validColor = (c: unknown): string | null => {
|
||||||
|
if (typeof c !== 'string') return null;
|
||||||
|
return c.match(/^[0-9a-f]{3,6}$/i) ? c : null;
|
||||||
|
};
|
||||||
|
|
||||||
const genEl = (ast: mfm.MfmNode[]) =>
|
const genEl = (ast: mfm.MfmNode[]) =>
|
||||||
concat(
|
concat(
|
||||||
ast.map((token, index): VNode[] => {
|
ast.map((token, index): VNode[] => {
|
||||||
|
@ -300,6 +306,20 @@ export default defineComponent({
|
||||||
style = `background-color: #${color};`;
|
style = `background-color: #${color};`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'border': {
|
||||||
|
let color = validColor(token.props.args.color);
|
||||||
|
color = color ? `#${color}` : 'var(--accent)';
|
||||||
|
let b_style = token.props.args.style;
|
||||||
|
if (
|
||||||
|
typeof b_style !== 'string' ||
|
||||||
|
!['hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset']
|
||||||
|
.includes(b_style)
|
||||||
|
) b_style = 'solid';
|
||||||
|
const width = safeParseFloat(token.props.args.width) ?? 1;
|
||||||
|
const radius = safeParseFloat(token.props.args.radius) ?? 0;
|
||||||
|
style = `border: ${width}px ${b_style} ${color}; border-radius: ${radius}px;${token.props.args.noclip ? '' : ' overflow: clip;'}`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "small": {
|
case "small": {
|
||||||
return h(
|
return h(
|
||||||
"small",
|
"small",
|
||||||
|
|
11
packages/client/src/scripts/safe-parse.ts
Normal file
11
packages/client/src/scripts/safe-parse.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function safeParseFloat(str: unknown): number | null {
|
||||||
|
if (typeof str !== 'string' || str === '') return null;
|
||||||
|
const num = parseFloat(str);
|
||||||
|
if (isNaN(num)) return null;
|
||||||
|
return num;
|
||||||
|
}
|
Loading…
Reference in a new issue