-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14875a6
commit 6e09de5
Showing
4 changed files
with
111 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,60 @@ | ||
import { CdnFn, JsdelivrFn } from '@/ConfigProvider'; | ||
|
||
export type EmojiType = 'anim' | 'flat' | 'modern' | 'mono' | 'pure' | '3d'; | ||
|
||
function isFlagEmoji(emoji: string) { | ||
export function isFlagEmoji(emoji: string) { | ||
const flagRegex = /(?:\uD83C[\uDDE6-\uDDFF]){2}/; | ||
return flagRegex.test(emoji); | ||
} | ||
|
||
function emojiToUnicode(emoji: string) { | ||
export function emojiToUnicode(emoji: string) { | ||
return [...emoji].map((char) => char?.codePointAt(0)?.toString(16)).join('-'); | ||
} | ||
|
||
export const genEmojiUrl = (emoji: string, type: EmojiType) => { | ||
if (isFlagEmoji(emoji)) | ||
return `https://jsdelivr.lobehub-inc.cn/gh/RealityRipple/emoji/noto/${emojiToUnicode(emoji)}.png`; | ||
if (type === 'pure') return null; | ||
export const genEmojiUrl = ( | ||
emoji: string, | ||
type: EmojiType, | ||
{ genCdnUrl, genJsdelivrUrl }: { genCdnUrl: CdnFn; genJsdelivrUrl: JsdelivrFn }, | ||
) => { | ||
const ext = ['anim', '3d'].includes(type) ? 'webp' : 'svg'; | ||
return `https://jsdelivr.lobehub-inc.cn/gh/lobehub/fluent-emoji/packages/${type}/assets/${emojiToUnicode(emoji)}.${ext}`; | ||
|
||
switch (type) { | ||
case 'pure': { | ||
return null; | ||
} | ||
case 'anim': { | ||
return genJsdelivrUrl({ | ||
path: `packages/${type}/assets/${emojiToUnicode(emoji)}.${ext}`, | ||
repo: 'lobehub/fluent-emoji', | ||
}); | ||
} | ||
case '3d': { | ||
return genCdnUrl({ | ||
path: `assets/${emojiToUnicode(emoji)}.${ext}`, | ||
pkg: '@lobehub/fluent-emoji-3d', | ||
version: '1.1.0', | ||
}); | ||
} | ||
case 'flat': { | ||
return genCdnUrl({ | ||
path: `assets/${emojiToUnicode(emoji)}.${ext}`, | ||
pkg: '@lobehub/fluent-emoji-flat', | ||
version: '1.1.0', | ||
}); | ||
} | ||
case 'modern': { | ||
return genCdnUrl({ | ||
path: `assets/${emojiToUnicode(emoji)}.${ext}`, | ||
pkg: '@lobehub/fluent-emoji-modern', | ||
version: '1.0.0', | ||
}); | ||
} | ||
case 'mono': { | ||
return genCdnUrl({ | ||
path: `assets/${emojiToUnicode(emoji)}.${ext}`, | ||
pkg: '@lobehub/fluent-emoji-mono', | ||
version: '1.1.0', | ||
}); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters