@@ -7,6 +7,8 @@ import MesloLGSNFRegular from "../res/fonts/MesloLGSNFRegular.ttf";
77import robotoMono from "../res/fonts/RobotoMono.ttf" ;
88
99const fonts = new Map ( ) ;
10+ const customFontNames = new Set ( ) ;
11+ const CUSTOM_FONTS_KEY = "custom_fonts" ;
1012
1113add (
1214 "Fira Code" ,
@@ -121,10 +123,47 @@ add(
121123}` ,
122124) ;
123125
126+ // Load custom fonts on module initialization
127+ loadCustomFonts ( ) ;
128+
124129function add ( name , css ) {
125130 fonts . set ( name , css ) ;
126131}
127132
133+ function addCustom ( name , css ) {
134+ fonts . set ( name , css ) ;
135+ customFontNames . add ( name ) ;
136+ saveCustomFonts ( ) ;
137+ }
138+
139+ function saveCustomFonts ( ) {
140+ const customFonts = { } ;
141+
142+ for ( const name of customFontNames ) {
143+ const css = fonts . get ( name ) ;
144+ if ( css ) {
145+ customFonts [ name ] = css ;
146+ }
147+ }
148+
149+ localStorage . setItem ( CUSTOM_FONTS_KEY , JSON . stringify ( customFonts ) ) ;
150+ }
151+
152+ function loadCustomFonts ( ) {
153+ try {
154+ const customFonts = localStorage . getItem ( CUSTOM_FONTS_KEY ) ;
155+ if ( customFonts ) {
156+ const parsed = JSON . parse ( customFonts ) ;
157+ for ( const [ name , css ] of Object . entries ( parsed ) ) {
158+ fonts . set ( name , css ) ;
159+ customFontNames . add ( name ) ;
160+ }
161+ }
162+ } catch ( error ) {
163+ console . error ( "Failed to load custom fonts:" , error ) ;
164+ }
165+ }
166+
128167function get ( name ) {
129168 return fonts . get ( name ) ;
130169}
@@ -134,7 +173,12 @@ function getNames() {
134173}
135174
136175function remove ( name ) {
137- return fonts . delete ( name ) ;
176+ const result = fonts . delete ( name ) ;
177+ if ( result ) {
178+ customFontNames . delete ( name ) ;
179+ saveCustomFonts ( ) ;
180+ }
181+ return result ;
138182}
139183
140184function has ( name ) {
@@ -224,6 +268,7 @@ async function loadFont(name) {
224268
225269export default {
226270 add,
271+ addCustom,
227272 get,
228273 getNames,
229274 remove,
0 commit comments