@@ -73,65 +73,65 @@ export class ConfigClass {
7373 this . file = config_object as { config : ConfigDefinition } ;
7474 this . widgets = this . file . config ?. widgets || [ ] ;
7575 }
76- }
7776
78- export async function getWidgetsHtml ( configObject : ConfigClass , zip : JSZip ) {
79- let htmlWidgets = await Promise . all (
80- configObject . widgets . map ( async ( element , index ) => {
81- const type = element . type ;
82-
83- if ( ! ( type in typeTemplateMap ) ) {
84- console . error ( "No template found for type" , type ) ;
85- return ;
86- }
87-
88- // Create the thing
89- let template = document . getElementById ( typeTemplateMap [ type ] ) as HTMLTemplateElement ;
90- let clone = template . content . cloneNode ( true ) as DocumentFragment ;
91-
92- const widgetText = clone . querySelector ( ".widget-text" ) as HTMLElement | null ;
93- const inputElement = clone . querySelector ( ".widget-input" ) as HTMLInputElement | null ;
94-
95- if ( "text" in element && widgetText ) widgetText . innerText = element . text ;
96-
97- if ( type === "switch" ) {
98- ( clone . querySelector ( ".widget-switch-input" ) as HTMLInputElement ) . checked = ! (
99- element . default === "disabled"
100- ) ;
101- } else if ( type === "slider" || type === "number" || type === "value" ) {
102- if ( element . value . default ) inputElement ! . valueAsNumber = element . value . default ;
103- if ( element . value . range ) {
104- inputElement ! . min = element . value . range [ 0 ] . toString ( ) ;
105- inputElement ! . max = element . value . range [ 1 ] . toString ( ) ;
106- }
107- if ( element . value . step ) {
108- inputElement ! . step = element . value . step . toString ( ) ;
109- }
77+ async getWidgetsHtml ( zip : JSZip ) {
78+ let htmlWidgets = await Promise . all (
79+ this . widgets . map ( async ( element , index ) => {
80+ const type = element . type ;
11081
111- let suffix = "" ;
112-
113- if ( "suffix" in element . value && element . value . suffix ) {
114- suffix = element . value . suffix ;
115- } else if ( element . value . type === "percent" ) {
116- suffix = " (%)" ;
82+ if ( ! ( type in typeTemplateMap ) ) {
83+ console . error ( "No template found for type" , type ) ;
84+ return ;
11785 }
11886
119- if ( suffix && widgetText ) widgetText . innerText += suffix ;
120- } else if ( type === "image" ) {
121- const imageFile = await zip . file ( element . file ) ?. async ( "blob" ) ;
122- if ( imageFile ) {
123- ( clone . querySelector ( ".widget-image" ) as HTMLImageElement ) . src =
124- URL . createObjectURL ( imageFile ) ;
87+ // Create the thing
88+ let template = document . getElementById ( typeTemplateMap [ type ] ) as HTMLTemplateElement ;
89+ let clone = template . content . cloneNode ( true ) as DocumentFragment ;
90+
91+ const widgetText = clone . querySelector ( ".widget-text" ) as HTMLElement | null ;
92+ const inputElement = clone . querySelector ( ".widget-input" ) as HTMLInputElement | null ;
93+
94+ if ( "text" in element && widgetText ) widgetText . innerText = element . text ;
95+
96+ if ( type === "switch" ) {
97+ ( clone . querySelector ( ".widget-switch-input" ) as HTMLInputElement ) . checked = ! (
98+ element . default === "disabled"
99+ ) ;
100+ } else if ( type === "slider" || type === "number" || type === "value" ) {
101+ if ( element . value . default ) inputElement ! . valueAsNumber = element . value . default ;
102+ if ( element . value . range ) {
103+ inputElement ! . min = element . value . range [ 0 ] . toString ( ) ;
104+ inputElement ! . max = element . value . range [ 1 ] . toString ( ) ;
105+ }
106+ if ( element . value . step ) {
107+ inputElement ! . step = element . value . step . toString ( ) ;
108+ }
109+
110+ let suffix = "" ;
111+
112+ if ( "suffix" in element . value && element . value . suffix ) {
113+ suffix = element . value . suffix ;
114+ } else if ( element . value . type === "percent" ) {
115+ suffix = " (%)" ;
116+ }
117+
118+ if ( suffix && widgetText ) widgetText . innerText += suffix ;
119+ } else if ( type === "image" ) {
120+ const imageFile = await zip . file ( element . file ) ?. async ( "blob" ) ;
121+ if ( imageFile ) {
122+ ( clone . querySelector ( ".widget-image" ) as HTMLImageElement ) . src =
123+ URL . createObjectURL ( imageFile ) ;
124+ }
125125 }
126- }
127126
128- // Set input ID
129- if ( inputElement ) inputElement . id = "widget-input-" + index . toString ( ) ;
127+ // Set input ID
128+ if ( inputElement ) inputElement . id = "widget-input-" + index . toString ( ) ;
130129
131- return clone ;
132- } )
133- ) ;
130+ return clone ;
131+ } )
132+ ) ;
134133
135- // Return array of HTML elements
136- return htmlWidgets . filter ( ( element ) => element !== undefined ) ;
134+ // Return array of HTML elements
135+ return htmlWidgets . filter ( ( element ) => element !== undefined ) ;
136+ }
137137}
0 commit comments