-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extract emojis in text & use appropriate font to generate & int…
…egrate them into final mesh
- Loading branch information
Showing
15 changed files
with
339 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
export type StringPart = { | ||
type: 'text' | 'emoji'; | ||
value: string; | ||
}; | ||
|
||
export default function extractEmoji(str: string) { | ||
const emojiRE = /(\p{EPres}|\p{ExtPict})+/gu; | ||
|
||
const extraction: StringPart[] = []; | ||
const execList: RegExpExecArray[] = []; | ||
let exec: RegExpExecArray | null = null; | ||
|
||
while ((exec = emojiRE.exec(str))) { | ||
execList.push(exec); | ||
} | ||
|
||
// No emoji at all | ||
if (!execList.length) { | ||
extraction.push({ | ||
type: 'text', | ||
value: str, | ||
}); | ||
} else { | ||
if (execList[0].index) { | ||
extraction.push({ | ||
type: 'text', | ||
value: str.substring(0, execList[0].index), | ||
}); | ||
} | ||
|
||
for (const [i, e] of execList.entries()) { | ||
extraction.push({ | ||
type: 'emoji', | ||
value: e[0], | ||
}); | ||
|
||
const eLength = e[0].length; // Emoji lenght | ||
const eEndIdx = e.index + eLength; // Emoji end index in string | ||
const nextEmojiIdx = execList[i + 1]?.index ?? 0; // Next emoji index | ||
|
||
// Handle text between current emoji & next one | ||
if (nextEmojiIdx > eEndIdx) { | ||
extraction.push({ | ||
type: 'text', | ||
value: str.substring(eEndIdx, execList[i + 1].index), | ||
}); | ||
} | ||
// Handle text between last emoji & end of string | ||
else if (i === execList.length - 1 && eEndIdx < str.length) { | ||
extraction.push({ | ||
type: 'text', | ||
value: str.substring(eEndIdx, str.length), | ||
}); | ||
} | ||
} | ||
} | ||
|
||
return extraction; | ||
} |
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
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
Binary file not shown.
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
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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,9 +1,12 @@ | ||
/* eslint-disable camelcase */ | ||
import chango from './chango'; | ||
import open_sans from './open_sans'; | ||
import NotoEmojiRegular from './NotoEmoji-Regular'; | ||
|
||
// base64 -i font.ttf -o tmp.txt | ||
export default { | ||
chango, | ||
open_sans, | ||
Roboto: open_sans, // Default, for test purpose | ||
'NotoEmoji-Regular': NotoEmojiRegular, | ||
} as Record<string, string>; |
Empty file.
Oops, something went wrong.