@sigx/lynx-icons-fa-free 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,82 +1,114 @@
1
- import { createRequire as e } from "node:module";
2
- import { dirname as t, join as n } from "node:path";
3
- //#region src/index.ts
4
- var r = e(import.meta.url), i = {
5
- solid: "@fortawesome/free-solid-svg-icons",
6
- regular: "@fortawesome/free-regular-svg-icons",
7
- brands: "@fortawesome/free-brands-svg-icons"
8
- }, a = {
9
- solid: "fa-solid-900.ttf",
10
- regular: "fa-regular-400.ttf",
11
- brands: "fa-brands-400.ttf"
12
- }, o = /* @__PURE__ */ new Map();
13
- function s(e) {
14
- if (o.has(e)) return o.get(e) ?? null;
15
- let t = i[e];
16
- if (!t) return o.set(e, null), null;
17
- try {
18
- let n = r(t);
19
- return o.set(e, n), n;
20
- } catch {
21
- return o.set(e, null), null;
22
- }
1
+ import { createRequire } from 'node:module';
2
+ import { dirname, join } from 'node:path';
3
+ const require = createRequire(import.meta.url);
4
+ const STYLE_TO_PACKAGE = {
5
+ solid: '@fortawesome/free-solid-svg-icons',
6
+ regular: '@fortawesome/free-regular-svg-icons',
7
+ brands: '@fortawesome/free-brands-svg-icons',
8
+ };
9
+ const STYLE_TO_TTF = {
10
+ solid: 'fa-solid-900.ttf',
11
+ regular: 'fa-regular-400.ttf',
12
+ brands: 'fa-brands-400.ttf',
13
+ };
14
+ const moduleCache = new Map();
15
+ function loadStyleModule(style) {
16
+ if (moduleCache.has(style))
17
+ return moduleCache.get(style) ?? null;
18
+ const pkg = STYLE_TO_PACKAGE[style];
19
+ if (!pkg) {
20
+ moduleCache.set(style, null);
21
+ return null;
22
+ }
23
+ try {
24
+ const mod = require(pkg);
25
+ moduleCache.set(style, mod);
26
+ return mod;
27
+ }
28
+ catch {
29
+ moduleCache.set(style, null);
30
+ return null;
31
+ }
23
32
  }
24
- function c(e) {
25
- return "fa" + e.split("-").map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join("");
33
+ /** Convert kebab-case glyph name → FA's PascalCase export name (`faChevronRight`). */
34
+ function exportNameFor(name) {
35
+ return 'fa' + name.split('-').map((seg) => seg.charAt(0).toUpperCase() + seg.slice(1)).join('');
26
36
  }
27
- function l(e) {
28
- let t = e.slice(2);
29
- if (t.length === 0) return "";
30
- let n = t.charAt(0).toLowerCase();
31
- for (let e = 1; e < t.length; e++) {
32
- let r = t.charAt(e);
33
- r >= "A" && r <= "Z" ? n += "-" + r.toLowerCase() : n += r;
34
- }
35
- return n;
37
+ /**
38
+ * Inverse of `exportNameFor`: `faChevronRight` → `chevron-right`.
39
+ * Used by `listGlyphs` to walk `Object.keys(module)` and emit canonical names.
40
+ */
41
+ function kebabFromExportName(exportName) {
42
+ // Strip the leading `fa` prefix.
43
+ const body = exportName.slice(2);
44
+ if (body.length === 0)
45
+ return '';
46
+ // Split on each uppercase letter and join with `-`, lowercasing everything.
47
+ let out = body.charAt(0).toLowerCase();
48
+ for (let i = 1; i < body.length; i++) {
49
+ const ch = body.charAt(i);
50
+ if (ch >= 'A' && ch <= 'Z') {
51
+ out += '-' + ch.toLowerCase();
52
+ }
53
+ else {
54
+ out += ch;
55
+ }
56
+ }
57
+ return out;
36
58
  }
37
- function u() {
38
- try {
39
- return n(t(r.resolve("@fortawesome/fontawesome-free/package.json")), "webfonts");
40
- } catch {
41
- return null;
42
- }
59
+ function webfontsDir() {
60
+ try {
61
+ const pkgJson = require.resolve('@fortawesome/fontawesome-free/package.json');
62
+ return join(dirname(pkgJson), 'webfonts');
63
+ }
64
+ catch {
65
+ return null;
66
+ }
43
67
  }
44
- var d = {
45
- styles: [
46
- "solid",
47
- "regular",
48
- "brands"
49
- ],
50
- getGlyph(e, t) {
51
- let n = s(e);
52
- if (!n) return null;
53
- let r = n[c(t)];
54
- if (!r || !Array.isArray(r.icon)) return null;
55
- let [i, a, , o, l] = r.icon, u = parseInt(o, 16);
56
- return Number.isFinite(u) ? {
57
- codepoint: u,
58
- svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${i} ${a}" fill="__COLOR__"><path d="${l}"/></svg>`
59
- } : null;
60
- },
61
- getFontPath(e) {
62
- let t = a[e];
63
- if (!t) return null;
64
- let r = u();
65
- return r ? n(r, t) : null;
66
- },
67
- listGlyphs(e) {
68
- let t = s(e);
69
- if (!t) return [];
70
- let n = [];
71
- for (let [e, r] of Object.entries(t)) {
72
- if (!e.startsWith("fa") || e.length < 3) continue;
73
- let t = e.charAt(2);
74
- t < "A" || t > "Z" || !r || typeof r != "object" || !Array.isArray(r.icon) || n.push(l(e));
75
- }
76
- return n;
77
- }
68
+ const adapter = {
69
+ styles: ['solid', 'regular', 'brands'],
70
+ getGlyph(style, name) {
71
+ const mod = loadStyleModule(style);
72
+ if (!mod)
73
+ return null;
74
+ const entry = mod[exportNameFor(name)];
75
+ if (!entry || !Array.isArray(entry.icon))
76
+ return null;
77
+ const [w, h, , unicodeHex, path] = entry.icon;
78
+ const codepoint = parseInt(unicodeHex, 16);
79
+ if (!Number.isFinite(codepoint))
80
+ return null;
81
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" fill="__COLOR__"><path d="${path}"/></svg>`;
82
+ return { codepoint, svg };
83
+ },
84
+ getFontPath(style) {
85
+ const filename = STYLE_TO_TTF[style];
86
+ if (!filename)
87
+ return null;
88
+ const dir = webfontsDir();
89
+ if (!dir)
90
+ return null;
91
+ return join(dir, filename);
92
+ },
93
+ listGlyphs(style) {
94
+ const mod = loadStyleModule(style);
95
+ if (!mod)
96
+ return [];
97
+ const out = [];
98
+ for (const [key, entry] of Object.entries(mod)) {
99
+ // The FA modules also export `prefix` ('fas' / 'far' / 'fab') and a
100
+ // single-letter alias matching the prefix. Filter to real icon
101
+ // entries — objects with a numeric icon[0] and a string icon[4].
102
+ if (!key.startsWith('fa') || key.length < 3)
103
+ continue;
104
+ const ch = key.charAt(2);
105
+ if (ch < 'A' || ch > 'Z')
106
+ continue; // skip `fas`, `far`, `fab`
107
+ if (!entry || typeof entry !== 'object' || !Array.isArray(entry.icon))
108
+ continue;
109
+ out.push(kebabFromExportName(key));
110
+ }
111
+ return out;
112
+ },
78
113
  };
79
- //#endregion
80
- export { d as default };
81
-
82
- //# sourceMappingURL=index.js.map
114
+ export default adapter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sigx/lynx-icons-fa-free",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Font Awesome Free adapter for @sigx/lynx-icons. Provides solid/regular/brands styles via the official @fortawesome/* packages.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "@fortawesome/free-brands-svg-icons": "^6.0.0",
24
24
  "@fortawesome/free-regular-svg-icons": "^6.0.0",
25
25
  "@fortawesome/free-solid-svg-icons": "^6.0.0",
26
- "@sigx/lynx-icons": "^0.4.0"
26
+ "@sigx/lynx-icons": "^0.4.1"
27
27
  },
28
28
  "peerDependenciesMeta": {
29
29
  "@fortawesome/free-brands-svg-icons": {
@@ -38,10 +38,10 @@
38
38
  "@fortawesome/free-brands-svg-icons": "^6.7.2",
39
39
  "@fortawesome/free-regular-svg-icons": "^6.7.2",
40
40
  "@fortawesome/free-solid-svg-icons": "^6.7.2",
41
- "@sigx/vite": "^0.4.3",
42
41
  "@types/node": "^25.7.0",
42
+ "@typescript/native-preview": "7.0.0-dev.20260511.1",
43
43
  "typescript": "^6.0.3",
44
- "@sigx/lynx-icons": "^0.4.0"
44
+ "@sigx/lynx-icons": "^0.4.1"
45
45
  },
46
46
  "author": "Andreas Ekdahl",
47
47
  "license": "MIT",
@@ -66,7 +66,8 @@
66
66
  "fontawesome"
67
67
  ],
68
68
  "scripts": {
69
- "build": "vite build && tsgo --emitDeclarationOnly",
70
- "dev": "vite build --watch"
69
+ "build": "node ../../scripts/clean.mjs dist && tsgo",
70
+ "dev": "tsgo --watch",
71
+ "clean": "node ../../scripts/clean.mjs dist .turbo"
71
72
  }
72
73
  }
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\nimport type { GlyphData, IconAdapter } from '@sigx/lynx-icons';\n\nconst require = createRequire(import.meta.url);\n\nconst STYLE_TO_PACKAGE: Record<string, string> = {\n solid: '@fortawesome/free-solid-svg-icons',\n regular: '@fortawesome/free-regular-svg-icons',\n brands: '@fortawesome/free-brands-svg-icons',\n};\n\nconst STYLE_TO_TTF: Record<string, string> = {\n solid: 'fa-solid-900.ttf',\n regular: 'fa-regular-400.ttf',\n brands: 'fa-brands-400.ttf',\n};\n\ninterface FaIconEntry {\n prefix: string;\n iconName: string;\n icon: [number, number, unknown[], string, string];\n}\n\nconst moduleCache = new Map<string, Record<string, FaIconEntry> | null>();\n\nfunction loadStyleModule(style: string): Record<string, FaIconEntry> | null {\n if (moduleCache.has(style)) return moduleCache.get(style) ?? null;\n const pkg = STYLE_TO_PACKAGE[style];\n if (!pkg) {\n moduleCache.set(style, null);\n return null;\n }\n try {\n const mod = require(pkg) as Record<string, FaIconEntry>;\n moduleCache.set(style, mod);\n return mod;\n } catch {\n moduleCache.set(style, null);\n return null;\n }\n}\n\n/** Convert kebab-case glyph name → FA's PascalCase export name (`faChevronRight`). */\nfunction exportNameFor(name: string): string {\n return 'fa' + name.split('-').map((seg) => seg.charAt(0).toUpperCase() + seg.slice(1)).join('');\n}\n\n/**\n * Inverse of `exportNameFor`: `faChevronRight` → `chevron-right`.\n * Used by `listGlyphs` to walk `Object.keys(module)` and emit canonical names.\n */\nfunction kebabFromExportName(exportName: string): string {\n // Strip the leading `fa` prefix.\n const body = exportName.slice(2);\n if (body.length === 0) return '';\n // Split on each uppercase letter and join with `-`, lowercasing everything.\n let out = body.charAt(0).toLowerCase();\n for (let i = 1; i < body.length; i++) {\n const ch = body.charAt(i);\n if (ch >= 'A' && ch <= 'Z') {\n out += '-' + ch.toLowerCase();\n } else {\n out += ch;\n }\n }\n return out;\n}\n\nfunction webfontsDir(): string | null {\n try {\n const pkgJson = require.resolve('@fortawesome/fontawesome-free/package.json');\n return join(dirname(pkgJson), 'webfonts');\n } catch {\n return null;\n }\n}\n\nconst adapter: IconAdapter = {\n styles: ['solid', 'regular', 'brands'],\n\n getGlyph(style: string, name: string): GlyphData | null {\n const mod = loadStyleModule(style);\n if (!mod) return null;\n const entry = mod[exportNameFor(name)];\n if (!entry || !Array.isArray(entry.icon)) return null;\n const [w, h, , unicodeHex, path] = entry.icon;\n const codepoint = parseInt(unicodeHex, 16);\n if (!Number.isFinite(codepoint)) return null;\n const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 ${w} ${h}\" fill=\"__COLOR__\"><path d=\"${path}\"/></svg>`;\n return { codepoint, svg };\n },\n\n getFontPath(style: string): string | null {\n const filename = STYLE_TO_TTF[style];\n if (!filename) return null;\n const dir = webfontsDir();\n if (!dir) return null;\n return join(dir, filename);\n },\n\n listGlyphs(style: string): string[] {\n const mod = loadStyleModule(style);\n if (!mod) return [];\n const out: string[] = [];\n for (const [key, entry] of Object.entries(mod)) {\n // The FA modules also export `prefix` ('fas' / 'far' / 'fab') and a\n // single-letter alias matching the prefix. Filter to real icon\n // entries — objects with a numeric icon[0] and a string icon[4].\n if (!key.startsWith('fa') || key.length < 3) continue;\n const ch = key.charAt(2);\n if (ch < 'A' || ch > 'Z') continue; // skip `fas`, `far`, `fab`\n if (!entry || typeof entry !== 'object' || !Array.isArray((entry as FaIconEntry).icon)) continue;\n out.push(kebabFromExportName(key));\n }\n return out;\n },\n};\n\nexport default adapter;\n"],"mappings":";;;AAIA,IAAM,IAAU,EAAc,OAAO,KAAK,IAAI,EAExC,IAA2C;CAC7C,OAAO;CACP,SAAS;CACT,QAAQ;CACX,EAEK,IAAuC;CACzC,OAAO;CACP,SAAS;CACT,QAAQ;CAC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