-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.ts
89 lines (82 loc) · 1.98 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type { Plugin, ExtensionComponent, GrammarRule, HighlightingRule } from 'carta-md';
import remarkGemoji from 'remark-gemoji';
import { fade, scale, type TransitionConfig } from 'svelte/transition';
import Emoji from './Emoji.svelte';
import BezierEasing from 'bezier-easing';
export * from './default.css?inline';
export interface EmojiExtensionOptions {
/**
* Custom in transition. See https://svelte.dev/docs#run-time-svelte-transition.
*/
inTransition?: (node: Element) => TransitionConfig;
/**
* Custom out transition. See https://svelte.dev/docs#run-time-svelte-transition.
*/
outTransition?: (node: Element) => TransitionConfig;
}
interface ComponentProps {
inTransition: (node: Element) => TransitionConfig;
outTransition: (node: Element) => TransitionConfig;
}
/**
* Carta emoji plugin. Adds support to render emojis as well as an emojis snippet.
*/
export const emoji = (options?: EmojiExtensionOptions): Plugin => {
const inTransition =
options?.inTransition ??
((node: Element) =>
scale(node, {
duration: 150,
easing: BezierEasing(0.05, 0.68, 0.2, 1.15)
}));
const outTransition =
options?.inTransition ??
((node: Element) =>
fade(node, {
duration: 100
}));
const emojiComponent: ExtensionComponent<ComponentProps> = {
component: Emoji,
parent: 'input',
props: {
inTransition,
outTransition
}
};
const grammar = {
name: 'emoji',
type: 'inline',
definition: {
match: ':[a-zA-Z_]+:',
name: 'markup.emoji.markdown'
}
} satisfies GrammarRule;
const highlighting = {
light: {
scope: 'markup.emoji',
settings: {
foreground: '#3bf'
}
},
dark: {
scope: 'markup.emoji',
settings: {
foreground: '#4dacfa'
}
}
} satisfies HighlightingRule;
return {
transformers: [
{
execution: 'sync',
type: 'remark',
transform({ processor }) {
processor.use(remarkGemoji);
}
}
],
components: [emojiComponent],
grammarRules: [grammar],
highlightingRules: [highlighting]
};
};