Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0.0 (Font Regeneration and Tree Shaking Error Fix) #20

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 3.0.0 (2023-10-20)

### Bug Fixes

- fix tree shaking build error by removing unavailable icon code points ([0a2c568](https://github.com/victoreronmosele/flutter-vector-icons/commit/0a2c568dde91e2b60f715b55bda0a364eaa7cfe8))

### Features

- add `FontAwesome6_Brands`, `FontAwesome6_Solid`, and `FontAwesome6_Regular` ([07ec0cf](https://github.com/victoreronmosele/flutter-vector-icons/commit/07ec0cfa795d7fb0f92ae2ce2937e0dddb7b45ca))

# [2.0.0](https://github.com/pd4d10/flutter-vector-icons/compare/v1.0.0...v2.0.0) (2022-09-17)

### Features
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class MyWidget extends StatelessWidget {
// FontAwesome5Brands
// FontAwesome5Regular
// FontAwesome5Solid
// FontAwesome6Brands
// FontAwesome6Regular
// FontAwesome6Solid

icon: Icon(MaterialCommunityIcons.star),
onPressed: () {
Expand All @@ -52,6 +55,7 @@ class MyWidget extends StatelessWidget {

| flutter-vector-icons | react-native-vector-icons |
| -------------------- | ------------------------- |
| 3.x | 10.x |
| 2.x | 9.x |
| 1.x | 8.x |

Expand Down
54 changes: 52 additions & 2 deletions codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ const fonts = await fetch(`${metaApi}/flat`).then(async (res) => {
};
});
});
const fontsNoFa5 = fonts.filter((v) => !v.name.includes("FontAwesome5"));
const fontsNoFa5AndFa6 = fonts.filter((v) => !v.name.includes("FontAwesome5") && !v.name.includes("FontAwesome6"));
const fontsFa5 = fonts.filter((v) => v.name.includes("FontAwesome5"));
const fontsFa6 = fonts.filter((v) => v.name.includes("FontAwesome6"));


for (const { name, fileName, fontUrl } of fonts) {
console.log("download font:", name);
Expand Down Expand Up @@ -96,7 +98,16 @@ fonts.forEach(({ name }) => {
Deno.writeTextFileSync(resolve("lib/flutter_vector_icons.dart"), entryCode);

const webData: Record<string, Record<string, number>> = {};
for (const { name, glyphmapsUrl } of fontsNoFa5) {

// Excluding the following code points as Flutter web builds with treeshaking
// fail with the following error:
//
// `Codepoint [codePoint] not found in font, aborting.`
//
const excludedMaterialCommunityPoint = 63116;
const excludedFontAwesome5Point = 62694;

for (const { name, glyphmapsUrl } of fontsNoFa5AndFa6) {
console.log(`write ${name}.dart`);

const iconMap: Record<string, number> = await fetch(glyphmapsUrl).then(
Expand All @@ -109,6 +120,10 @@ static const _family = '${name}';
static const _package = 'flutter_vector_icons';`;

for (const [key, value] of Object.entries(iconMap)) {
if (value == excludedMaterialCommunityPoint) {
continue;
}

webData[name][normalizeKey(key)] = value;

code += `static const ${normalizeKey(
Expand Down Expand Up @@ -149,6 +164,11 @@ static const _package = 'flutter_vector_icons';`;
if (codePoint == null) {
throw new Error(`codePoint null: ${name}, ${key}`);
}

if (codePoint == excludedFontAwesome5Point) {
continue;
}

code += `static const ${normalizeKey(
key
)} = IconData(${codePoint}, fontFamily: _family, fontPackage: _package);`;
Expand All @@ -158,6 +178,36 @@ static const _package = 'flutter_vector_icons';`;
Deno.writeTextFileSync(resolve(`lib/src/${snakeCase(name)}.dart`), code);
});


console.log("fetch fa6 meta");
const fa6Meta = await fetch(`${blobApi}/glyphmaps/FontAwesome6Free_meta.json`).then((res) => res.json());

const fa6GlyphMap = await fetch(`${blobApi}/glyphmaps/FontAwesome6Free.json`).then((res) => res.json());

fontsFa6.forEach(({ name }) => {
console.log("write dart file", name);

let code = `import 'package:flutter/widgets.dart'; class ${upperFirstCase(camelCase(name))} {
static const _family = '${name}';
static const _package = 'flutter_vector_icons';`;

// FontAwesome6_Brands -> brands
const groupKey = name.split("_")[1].toLowerCase();
webData[name] = {};
for (const key of fa6Meta[groupKey]) {
webData[name][normalizeKey(key)] = fa6GlyphMap[key];

const codePoint = fa6GlyphMap[key];
if (codePoint == null) {
throw new Error(`codePoint null: ${name}, ${key}`);
}
code += `static const ${normalizeKey(key)} = IconData(${codePoint}, fontFamily: _family, fontPackage: _package);`;
}
code += "}";

Deno.writeTextFileSync(resolve(`lib/src/${snakeCase(name)}.dart`), code);
});

console.log(`write web data`);
Deno.writeTextFileSync(
resolve("example/lib/data.dart"),
Expand Down
Loading