@@ -11,6 +11,7 @@ import {
1111 SYSTEM_PROMPT_TEMPLATE_VERSION ,
1212 DOWNLOAD_BEHAVIOR_VERSION ,
1313 DEFAULT_REMOTE_CONFIG ,
14+ CSS_PRESETS ,
1415} from "../lib/constants.js" ;
1516import { makeId } from "../lib/utils/helpers.js" ;
1617import { setHtmlToMarkdownMaxDepth } from "./dom/message-text.js" ;
@@ -32,6 +33,7 @@ export async function loadStateFromStorage() {
3233 STORAGE_KEYS . savedItems ,
3334 STORAGE_KEYS . remoteAnnouncement ,
3435 STORAGE_KEYS . dismissedAnnouncements ,
36+ STORAGE_KEYS . cssSnippets ,
3537 "bds_locale_updates" ,
3638 ] ) ;
3739
@@ -107,6 +109,7 @@ export async function loadStateFromStorage() {
107109 }
108110
109111 state . skills = normalizeSkills ( values [ STORAGE_KEYS . skills ] ) ;
112+ state . cssSnippets = normalizeCssSnippets ( values [ STORAGE_KEYS . cssSnippets ] ) ;
110113 state . memories = normalizeMemories ( values [ STORAGE_KEYS . memories ] ) ;
111114 state . characters = normalizeCharacters ( values [ STORAGE_KEYS . characters ] ) ;
112115 state . projects = normalizeProjects ( values [ STORAGE_KEYS . projects ] ) ;
@@ -337,6 +340,70 @@ export function normalizeSavedItems(raw) {
337340 } ) ) ;
338341}
339342
343+ export function normalizeCssSnippets ( raw ) {
344+ const defaultPresets = [
345+ {
346+ id : "preset-reducePadding" ,
347+ name : "presetReducePadding" ,
348+ css : CSS_PRESETS . reducePadding . css ,
349+ active : false ,
350+ isPreset : true ,
351+ } ,
352+ {
353+ id : "preset-widerMessages" ,
354+ name : "presetWiderMessages" ,
355+ css : CSS_PRESETS . widerMessages . css ,
356+ active : false ,
357+ isPreset : true ,
358+ } ,
359+ {
360+ id : "preset-compact" ,
361+ name : "presetCompact" ,
362+ css : CSS_PRESETS . compact . css ,
363+ active : false ,
364+ isPreset : true ,
365+ } ,
366+ {
367+ id : "preset-betterCodeFont" ,
368+ name : "presetBetterCodeFont" ,
369+ css : CSS_PRESETS . betterCodeFont . css ,
370+ active : false ,
371+ isPreset : true ,
372+ } ,
373+ ] ;
374+
375+ if ( ! Array . isArray ( raw ) ) {
376+ return defaultPresets ;
377+ }
378+
379+ const map = new Map ( raw . map ( ( item ) => [ item . id , item ] ) ) ;
380+
381+ const finalPresets = defaultPresets . map ( ( preset ) => {
382+ const existing = map . get ( preset . id ) ;
383+ if ( existing ) {
384+ map . delete ( preset . id ) ;
385+ return {
386+ ...preset ,
387+ css : existing . css !== undefined ? existing . css : preset . css ,
388+ active : ! ! existing . active ,
389+ } ;
390+ }
391+ return preset ;
392+ } ) ;
393+
394+ const customSnippets = Array . from ( map . values ( ) )
395+ . map ( ( item ) => ( {
396+ id : String ( item . id || makeId ( ) ) ,
397+ name : String ( item . name || "Snippet" ) ,
398+ css : String ( item . css || "" ) ,
399+ active : ! ! item . active ,
400+ isPreset : false ,
401+ } ) )
402+ . filter ( ( item ) => item . css . trim ( ) . length > 0 ) ;
403+
404+ return [ ...finalPresets , ...customSnippets ] ;
405+ }
406+
340407// ── Storage change listener ──
341408
342409export function bindStorageChangeListener ( ) {
@@ -423,6 +490,14 @@ export function bindStorageChangeListener() {
423490 if ( state . ui ) state . ui . refreshSavedItems ( ) ;
424491 }
425492
493+ if ( changes [ STORAGE_KEYS . cssSnippets ] ) {
494+ state . cssSnippets = normalizeCssSnippets ( changes [ STORAGE_KEYS . cssSnippets ] . newValue ) ;
495+ if ( state . ui && typeof state . ui . refreshCssSnippets === 'function' ) {
496+ state . ui . refreshCssSnippets ( ) ;
497+ }
498+ window . dispatchEvent ( new CustomEvent ( "bds:cssSnippetsChanged" ) ) ;
499+ }
500+
426501 if ( changes [ STORAGE_KEYS . remoteAnnouncement ] ) {
427502 state . remoteAnnouncements = Array . isArray ( changes [ STORAGE_KEYS . remoteAnnouncement ] . newValue ) ? changes [ STORAGE_KEYS . remoteAnnouncement ] . newValue : [ ] ;
428503 window . dispatchEvent ( new CustomEvent ( "bds:remote-announcement-updated" , { detail : state . remoteAnnouncements } ) ) ;
0 commit comments