Codepoint allocation doesn't support multiple custom icons
🐛 bug
### Package
- [ ] lucide
- [ ] lucide-angular (old version)
- [ ] @lucide/angular (new version)
- [ ] @lucide/astro
- [ ] lucide-flutter
- [ ] lucide-preact
- [ ] lucide-react
- [ ] lucide-react-native
- [ ] lucide-solid
- [ ] lucide-static
- [ ] lucide-svelte (old version)
- [ ] @lucide/svelte (new version)
- [ ] lucide-vue
- [ ] lucide-vue-next
- [ ] lucide-astro
- [ ] @lucide/icons
- [ ] Figma plugin
- [x] source/main
- [ ] other/not relevant
### Version
master
### Can you reproduce this in the latest version?
- [x] Yes
- [ ] No
### Browser
- [ ] Chrome/Chromium
- [ ] Firefox
- [ ] Safari
- [ ] Edge
- [ ] iOS Safari
- [ ] Opera
- [x] Other/not relevant
### Operating system
- [ ] Windows
- [ ] Linux
- [ ] macOS
- [ ] ChromeOS
- [ ] iOS
- [ ] Android
- [x] Other/not relevant
### Description
I am maintaining a private fork of Lucide because of some custom icons I have added. When updating my fork from version 0.x to 1.x, the font generation starting assigning the same codepoint to all of my custom icons. When looking up where the codepoints are allocated, I found the following issue:
The relevant part of the current implementation of [`allocateCodePoints`](https://github.com/lucide-icons/lucide/blob/3c62e4bfef50fb88dd9618439b46811af912ba4a/tools/build-font/src/allocateCodepoints.ts#L23) looks the following:
```ts
const baseCodePoints = await getLatestCodePoints();
const endCodePoint = Math.max(...Object.values(baseCodePoints));
await Promise.all(
iconsWithAliases.map(async ([iconName, aliases]) => {
if (!baseCodePoints[iconName]) {
console.log('Code point not found creating new one for', iconName);
baseCodePoints[iconName] = endCodePoint + 1;
}
aliases.forEach((alias, index) => {
if (baseCodePoints[alias]) {
return;
}
console.log('Code point not found creating new one for', alias);
baseCodePoints[alias] = endCodePoint + index + 1;
});
}),
);
```
If the code doesn't find a specific icon in the list downloaded from Vercel, it assigns it `endCodePoint + 1`. However, `endCodePoint` is not increased, which results in all custom icons getting the same codepoint assigned.
In my private fork, I crudely fixed the issue by modifying the code in the following way:
```ts
const baseCodePoints = await getLatestCodePoints();
var endCodePoint = Math.max(...Object.values(baseCodePoints));
await Promise.all(
iconsWithAliases.map(async ([iconName, aliases]) => {
if (!baseCodePoints[iconName]) {
console.log('Code point not found creating new one for', iconName);
baseCodePoints[iconName] = ++endCodePoint;
}
aliases.forEach((alias) => {
if (baseCodePoints[alias]) {
return;
}
console.log('Code point not found creating new one for', alias);
baseCodePoints[alias] = ++endCodePoint;
});
}),
);
```
I am not sure, if this is how things are intended to work. It works for me, at least. If the solution is fine, I surely can create a pull request.
### Steps to reproduce
1. Add multiple new icons
2. Run `build:font`
3. Look at the bottom of `lucide-font/codepoints.json` to find all added icons with the same codepoint
### Checklist
- [x] I have searched if someone has submitted a similar issue before and there weren't any. (Please make sure to also search closed issues, as this issue might already have been resolved.)
6 条评论