43 lines
2.1 KiB
TypeScript
43 lines
2.1 KiB
TypeScript
import catalog from "./xmind-marker-catalog.json" with { type: "json" };
|
|
|
|
export type XmindMarker = { id: string; name: string; asset: string; hidden: boolean };
|
|
export type XmindMarkerGroup = { id: string; label: string; hidden: boolean; markers: XmindMarker[] };
|
|
export const XMIND_MARKER_GROUPS: XmindMarkerGroup[] = catalog;
|
|
// The client resolves shared IDs to their first catalog entry.
|
|
const markers = new Map<string, XmindMarker & { groupId: string }>();
|
|
for (const group of catalog) {
|
|
for (const marker of group.markers) {
|
|
if (!markers.has(marker.id)) markers.set(marker.id, { ...marker, groupId: group.id });
|
|
}
|
|
}
|
|
const aliases: Record<string, string> = {
|
|
"🔴": "tag-red", "🟠": "tag-orange", "🟡": "tag-yellow", "🟢": "tag-green", "🔵": "tag-blue", "🟣": "tag-dark-purple", "⚪": "tag-grey",
|
|
"✅": "task-done", "▶️": "task-start", "◔": "task-quarter", "◑": "task-half", "◕": "task-3quar", "🚧": "task-5oct",
|
|
"🚩": "flag-red", "⭐": "star-red", "🌟": "star-yellow", "👤": "people-blue",
|
|
"❗": "c_simbol-exclam", "❓": "c_simbol-question", "💡": "symbol-idea", "❤️": "c_symbol_heart", "⚡": "symbol-lightning", "📌": "symbol-pin",
|
|
...Object.fromEntries(Array.from({ length: 9 }, (_, index) => [`${index + 1}️⃣`, `priority-${index + 1}`])),
|
|
};
|
|
|
|
export function getXmindMarker(name: string) {
|
|
return markers.get(name.startsWith("xmind:") ? name.slice(6) : aliases[name] || name);
|
|
}
|
|
|
|
export function xmindMarkerName(id: string) {
|
|
return `xmind:${id}`;
|
|
}
|
|
|
|
export function getXmindMarkerIds(emojis: { name: string }[] = []) {
|
|
return [...new Set(emojis.flatMap(emoji => {
|
|
const marker = getXmindMarker(emoji.name);
|
|
return marker ? [marker.id] : [];
|
|
}))];
|
|
}
|
|
|
|
/** Native markers are mutually exclusive within each group. Unrelated emoji stay intact. */
|
|
export function toggleXmindMarker(emojis: { name: string }[], markerId: string, remove: boolean) {
|
|
const marker = getXmindMarker(markerId);
|
|
if (!marker) return emojis;
|
|
const remaining = emojis.filter(emoji => getXmindMarker(emoji.name)?.groupId !== marker.groupId);
|
|
return remove ? remaining : [...remaining, { name: xmindMarkerName(markerId) }];
|
|
}
|