1- // Import Panel class
21import { Panel } from './Panel.js' ;
32
4- // Core extension management class
53class ExtensionManager {
64 constructor ( browserAPI = null ) {
75 this . browserAPI = browserAPI || ( typeof browser !== 'undefined' ? browser : chrome ) ;
@@ -47,36 +45,47 @@ class ExtensionManager {
4745 await this . openPanel ( message . panelType || 'welcome' , message . data ) ;
4846 break ;
4947 default :
50-
5148 break ;
5249 }
5350 } catch ( error ) {
5451 console . error ( error ) ;
5552 }
5653 }
5754
55+ async loadCoreCSS ( ) {
56+ if ( document . getElementById ( 'carbon-visualizer-core-css' ) ) return ;
57+
58+ try {
59+ const cssUrl = this . browserAPI . runtime . getURL ( 'src/styles/core.css' ) ;
60+ const response = await fetch ( cssUrl ) ;
61+ const css = await response . text ( ) ;
62+
63+ const style = document . createElement ( 'style' ) ;
64+ style . id = 'carbon-visualizer-core-css' ;
65+ style . textContent = css ;
66+ document . head . appendChild ( style ) ;
67+ } catch ( error ) {
68+ console . error ( error ) ;
69+ }
70+ }
5871
5972 async togglePanel ( panelType ) {
6073 try {
6174 const panel = this . panels . get ( panelType ) ;
6275
6376 if ( panel && panel . isVisible ) {
64- // Panel is visible -> close it
6577 this . closePanel ( panelType ) ;
6678 } else {
67- // Panel doesn't exist or is hidden -> open it
6879 await this . openPanel ( panelType ) ;
6980 }
70- }
71- catch ( error ) {
81+ } catch ( error ) {
7282 console . error ( 'Error in togglePanel():' , error ) ;
7383 }
7484 }
7585
7686 cleanupOrphanedPanels ( ) {
77- // Remove any orphaned panels from DOM that aren't tracked in our map
7887 const orphanedPanels = document . querySelectorAll ( '.cv-panel' ) ;
79- orphanedPanels . forEach ( panel => {
88+ orphanedPanels . forEach ( ( panel ) => {
8089 panel . remove ( ) ;
8190 } ) ;
8291
@@ -91,39 +100,33 @@ class ExtensionManager {
91100 async openPanel ( panelType , data = { } ) {
92101 let panel = this . panels . get ( panelType ) ;
93102
94- // Always create a fresh panel to avoid state issues
103+ // Create a new panel if one does not already exist
95104 if ( ! panel ) {
96105 panel = new Panel ( panelType , data , this . browserAPI ) ;
97106 this . panels . set ( panelType , panel ) ;
98107 }
99108
100109 // Always reinitialize to ensure clean state
101110 await panel . initialize ( ) ;
102-
103- // Show the panel
104111 await panel . show ( ) ;
105112 }
106113
107114 closePanel ( panelType ) {
108115 const panel = this . panels . get ( panelType ) ;
109116 if ( panel ) {
110117 panel . hide ( ) ;
111- // Don't delete from map - keep for reuse
112118 }
113119 }
114120
115121 closeAllPanels ( ) {
116- // Hide all tracked panels immediately
117122 for ( const [ type , panel ] of this . panels ) {
118123 if ( panel && panel . container ) {
119124 panel . hideImmediate ( ) ;
120125 }
121126 }
122127
123- // Clear the panels map
128+ // Clear the panels map and remove orphaned panels from DOM
124129 this . panels . clear ( ) ;
125-
126- // Also remove any orphaned panels from DOM
127130 this . cleanupOrphanedPanels ( ) ;
128131 }
129132
@@ -133,5 +136,4 @@ class ExtensionManager {
133136 // async showResults(assessmentData) { ... }
134137}
135138
136- // Export the class for dynamic imports
137139export { ExtensionManager } ;
0 commit comments