OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.
TypeScript
import type { StickerItem, EmojiItem, StickerClip } from "./types";
import { DEFAULT_GRAPHIC_TRANSFORM } from "./types";
interface StickerCategory {
readonly id: string;
readonly name: string;
readonly icon?: string;
}
interface EmojiCategory {
readonly id: string;
readonly name: string;
readonly emojis: EmojiItem[];
}
export const EMOJI_CATEGORIES: EmojiCategory[] = [
{
id: "smileys",
name: "Smileys & Emotion",
emojis: [
{
id: "grinning",
emoji: "π",
name: "Grinning Face",
category: "smileys",
},
{
id: "joy",
emoji: "π",
name: "Face with Tears of Joy",
category: "smileys",
},
{
id: "heart_eyes",
emoji: "π",
name: "Smiling Face with Heart-Eyes",
category: "smileys",
},
{
id: "thinking",
emoji: "π€",
name: "Thinking Face",
category: "smileys",
},
{
id: "sunglasses",
emoji: "π",
name: "Smiling Face with Sunglasses",
category: "smileys",
},
{ id: "wink", emoji: "π", name: "Winking Face", category: "smileys" },
{ id: "thumbsup", emoji: "π", name: "Thumbs Up", category: "smileys" },
{ id: "clap", emoji: "π", name: "Clapping Hands", category: "smileys" },
{ id: "fire", emoji: "π₯", name: "Fire", category: "smileys" },
{ id: "heart", emoji: "β€οΈ", name: "Red Heart", category: "smileys" },
{ id: "star", emoji: "β", name: "Star", category: "smileys" },
{ id: "sparkles", emoji: "β¨", name: "Sparkles", category: "smileys" },
],
},
{
id: "gestures",
name: "Gestures",
emojis: [
{ id: "wave", emoji: "π", name: "Waving Hand", category: "gestures" },
{ id: "ok_hand", emoji: "π", name: "OK Hand", category: "gestures" },
{
id: "point_up",
emoji: "βοΈ",
name: "Index Pointing Up",
category: "gestures",
},
{
id: "point_right",
emoji: "π",
name: "Backhand Index Pointing Right",
category: "gestures",
},
{
id: "raised_hands",
emoji: "π",
name: "Raising Hands",
category: "gestures",
},
{ id: "pray", emoji: "π", name: "Folded Hands", category: "gestures" },
{
id: "muscle",
emoji: "πͺ",
name: "Flexed Biceps",
category: "gestures",
},
{ id: "v", emoji: "βοΈ", name: "Victory Hand", category: "gestures" },
],
},
{
id: "objects",
name: "Objects",
emojis: [
{ id: "camera", emoji: "π·", name: "Camera", category: "objects" },
{
id: "video_camera",
emoji: "πΉ",
name: "Video Camera",
category: "objects",
},
{
id: "microphone",
emoji: "π€",
name: "Microphone",
category: "objects",
},
{
id: "headphones",
emoji: "π§",
name: "Headphones",
category: "objects",
},
{
id: "movie_camera",
emoji: "π₯",
name: "Movie Camera",
category: "objects",
},
{
id: "clapper",
emoji: "π¬",
name: "Clapper Board",
category: "objects",
},
{ id: "trophy", emoji: "π", name: "Trophy", category: "objects" },
{ id: "medal", emoji: "π
", name: "Sports Medal", category: "objects" },
{ id: "bell", emoji: "π", name: "Bell", category: "objects" },
{ id: "megaphone", emoji: "π£", name: "Megaphone", category: "objects" },
],
},
{
id: "symbols",
name: "Symbols",
emojis: [
{ id: "check", emoji: "β
", name: "Check Mark", category: "symbols" },
{ id: "x", emoji: "β", name: "Cross Mark", category: "symbols" },
{
id: "question",
emoji: "β",
name: "Question Mark",
category: "symbols",
},
{
id: "exclamation",
emoji: "β",
name: "Exclamation Mark",
category: "symbols",
},
{ id: "100", emoji: "π―", name: "Hundred Points", category: "symbols" },
{
id: "arrow_right",
emoji: "β‘οΈ",
name: "Right Arrow",
category: "symbols",
},
{
id: "arrow_left",
emoji: "β¬
οΈ",
name: "Left Arrow",
category: "symbols",
},
{ id: "arrow_up", emoji: "β¬οΈ", name: "Up Arrow", category: "symbols" },
{
id: "arrow_down",
emoji: "β¬οΈ",
name: "Down Arrow",
category: "symbols",
},
{ id: "new", emoji: "π", name: "New", category: "symbols" },
{ id: "free", emoji: "π", name: "Free", category: "symbols" },
],
},
{
id: "nature",
name: "Nature",
emojis: [
{ id: "sun", emoji: "βοΈ", name: "Sun", category: "nature" },
{ id: "moon", emoji: "π", name: "Crescent Moon", category: "nature" },
{ id: "cloud", emoji: "βοΈ", name: "Cloud", category: "nature" },
{ id: "rainbow", emoji: "π", name: "Rainbow", category: "nature" },
{ id: "snowflake", emoji: "βοΈ", name: "Snowflake", category: "nature" },
{ id: "lightning", emoji: "β‘", name: "Lightning", category: "nature" },
{ id: "flower", emoji: "πΈ", name: "Cherry Blossom", category: "nature" },
{ id: "tree", emoji: "π³", name: "Deciduous Tree", category: "nature" },
],
},
];
export class StickerLibrary {
private stickers: Map<string, StickerItem> = new Map();
private categories: Map<string, StickerCategory> = new Map();
private emojiCategories: EmojiCategory[] = EMOJI_CATEGORIES;
constructor() {
this.initializeDefaultCategories();
}
private initializeDefaultCategories(): void {
const defaultCategories: StickerCategory[] = [
{ id: "arrows", name: "Arrows", icon: "β‘οΈ" },
{ id: "badges", name: "Badges", icon: "π·οΈ" },
{ id: "banners", name: "Banners", icon: "ποΈ" },
{ id: "callouts", name: "Callouts", icon: "π¬" },
{ id: "social", name: "Social Media", icon: "π±" },
{ id: "custom", name: "Custom", icon: "β¨" },
];
for (const category of defaultCategories) {
this.categories.set(category.id, category);
}
}
addSticker(sticker: StickerItem): void {
this.stickers.set(sticker.id, sticker);
}
removeSticker(stickerId: string): boolean {
return this.stickers.delete(stickerId);
}
getSticker(stickerId: string): StickerItem | undefined {
return this.stickers.get(stickerId);
}
getAllStickers(): StickerItem[] {
return Array.from(this.stickers.values());
}
getStickersByCategory(categoryId: string): StickerItem[] {
return Array.from(this.stickers.values()).filter(
(s) => s.category === categoryId,
);
}
searchStickers(query: string): StickerItem[] {
const lowerQuery = query.toLowerCase();
return Array.from(this.stickers.values()).filter(
(s) =>
s.name.toLowerCase().includes(lowerQuery) ||
s.tags?.some((t) => t.toLowerCase().includes(lowerQuery)),
);
}
addCategory(category: StickerCategory): void {
this.categories.set(category.id, category);
}
getCategories(): StickerCategory[] {
return Array.from(this.categories.values());
}
getCategory(categoryId: string): StickerCategory | undefined {
return this.categories.get(categoryId);
}
getEmojiCategories(): EmojiCategory[] {
return this.emojiCategories;
}
getEmojisByCategory(categoryId: string): EmojiItem[] {
const category = this.emojiCategories.find((c) => c.id === categoryId);
return category?.emojis || [];
}
getAllEmojis(): EmojiItem[] {
return this.emojiCategories.flatMap((c) => c.emojis);
}
searchEmojis(query: string): EmojiItem[] {
const lowerQuery = query.toLowerCase();
return this.getAllEmojis().filter((e) =>
e.name.toLowerCase().includes(lowerQuery),
);
}
getEmoji(emojiId: string): EmojiItem | undefined {
return this.getAllEmojis().find((e) => e.id === emojiId);
}
createStickerClip(
sticker: StickerItem,
trackId: string,
startTime: number,
duration: number,
): StickerClip {
return {
id: `sticker_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`,
trackId,
startTime,
duration,
type: "sticker",
imageUrl: sticker.imageUrl,
category: sticker.category,
name: sticker.name,
transform: { ...DEFAULT_GRAPHIC_TRANSFORM },
keyframes: [],
};
}
createEmojiClip(
emoji: EmojiItem,
trackId: string,
startTime: number,
duration: number,
): StickerClip {
const imageUrl = this.emojiToDataUrl(emoji.emoji);
return {
id: `emoji_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`,
trackId,
startTime,
duration,
type: "emoji",
imageUrl,
category: emoji.category,
name: emoji.name,
transform: { ...DEFAULT_GRAPHIC_TRANSFORM },
keyframes: [],
};
}
emojiToDataUrl(emoji: string, size: number = 128): string {
if (typeof document === "undefined") {
return `data:text/plain;base64,${btoa(emoji)}`;
}
const canvas = document.createElement("canvas");
canvas.width = size;
canvas.height = size;
const ctx = canvas.getContext("2d");
if (!ctx) {
return `data:text/plain;base64,${btoa(emoji)}`;
}
ctx.font = `${
size * 0.8
}px "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(emoji, size / 2, size / 2);
return canvas.toDataURL("image/png");
}
async importSticker(
file: File,
name: string,
category: string = "custom",
tags?: string[],
): Promise<StickerItem> {
const imageUrl = await this.fileToDataUrl(file);
const sticker: StickerItem = {
id: `custom_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`,
name,
category,
imageUrl,
tags,
};
this.addSticker(sticker);
return sticker;
}
private fileToDataUrl(file: File): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result as string);
reader.onerror = () => reject(new Error("Failed to read file"));
reader.readAsDataURL(file);
});
}
clearCustomStickers(): void {
for (const [id, sticker] of this.stickers) {
if (sticker.category === "custom") {
this.stickers.delete(id);
}
}
}
}
export const stickerLibrary = new StickerLibrary();