22// Distributed under the terms of the Modified BSD License.
33
44/**
5- * MIME bundle for rich display
5+ * MIME bundle for rich display.
66 */
77export interface IMimeBundle {
88 [ key : string ] : any ;
99}
1010
1111/**
12- * Display request from $$.display()
12+ * Display request from $$.display().
1313 */
1414export interface IDisplayData {
1515 data : IMimeBundle ;
@@ -20,59 +20,71 @@ export interface IDisplayData {
2020}
2121
2222/**
23- * Callbacks for display operations
23+ * Callbacks for display operations.
2424 */
2525export interface IDisplayCallbacks {
2626 onDisplay ?: ( data : IDisplayData ) => void ;
2727 onClear ?: ( wait : boolean ) => void ;
2828}
2929
3030/**
31- * Display helper class for rich output
31+ * Display helper class for rich output.
3232 * Provides methods like html(), svg(), png(), etc.
3333 */
3434export class DisplayHelper {
35- private _displayCallback ?: ( data : IDisplayData ) => void ;
36- private _clearCallback ?: ( wait : boolean ) => void ;
37- private _displayId ?: string ;
38- private _result ?: IMimeBundle ;
39-
35+ /**
36+ * Instantiate a new DisplayHelper.
37+ *
38+ * @param displayId - Optional display ID for update operations.
39+ */
4040 constructor ( displayId ?: string ) {
4141 this . _displayId = displayId ;
4242 }
4343
4444 /**
45- * Set the callbacks for display operations
45+ * Set the callbacks for display operations.
46+ *
47+ * @param callbacks - The callbacks for display and clear operations.
4648 */
4749 setCallbacks ( callbacks : IDisplayCallbacks ) : void {
4850 this . _displayCallback = callbacks . onDisplay ;
4951 this . _clearCallback = callbacks . onClear ;
5052 }
5153
5254 /**
53- * Get the result if set via display methods
55+ * Get the result if set via display methods.
56+ *
57+ * @returns The MIME bundle result, or undefined if not set.
5458 */
5559 getResult ( ) : IMimeBundle | undefined {
5660 return this . _result ;
5761 }
5862
5963 /**
60- * Clear the result
64+ * Clear the result.
6165 */
6266 clearResult ( ) : void {
6367 this . _result = undefined ;
6468 }
6569
6670 /**
67- * Create a new display with optional ID
68- * Usage: $$.display('my-id').html('<div>...</div>')
71+ * Create a new display with optional ID.
72+ *
73+ * @param id - Optional display ID for update operations.
74+ * @returns A new DisplayHelper instance.
75+ *
76+ * @example
77+ * $$.display('my-id').html('<div>...</div>')
6978 */
7079 display ( id ?: string ) : DisplayHelper {
7180 return new DisplayHelper ( id ) ;
7281 }
7382
7483 /**
75- * Display HTML content
84+ * Display HTML content.
85+ *
86+ * @param content - The HTML content to display.
87+ * @param metadata - Optional metadata for the display.
7688 */
7789 html ( content : string , metadata ?: Record < string , any > ) : void {
7890 this . _sendDisplay (
@@ -82,7 +94,10 @@ export class DisplayHelper {
8294 }
8395
8496 /**
85- * Display SVG content
97+ * Display SVG content.
98+ *
99+ * @param content - The SVG content to display.
100+ * @param metadata - Optional metadata for the display.
86101 */
87102 svg ( content : string , metadata ?: Record < string , any > ) : void {
88103 this . _sendDisplay (
@@ -95,7 +110,10 @@ export class DisplayHelper {
95110 }
96111
97112 /**
98- * Display PNG image (base64 encoded)
113+ * Display PNG image (base64 encoded).
114+ *
115+ * @param base64Content - The base64-encoded PNG data.
116+ * @param metadata - Optional metadata for the display.
99117 */
100118 png ( base64Content : string , metadata ?: Record < string , any > ) : void {
101119 this . _sendDisplay (
@@ -108,7 +126,10 @@ export class DisplayHelper {
108126 }
109127
110128 /**
111- * Display JPEG image (base64 encoded)
129+ * Display JPEG image (base64 encoded).
130+ *
131+ * @param base64Content - The base64-encoded JPEG data.
132+ * @param metadata - Optional metadata for the display.
112133 */
113134 jpeg ( base64Content : string , metadata ?: Record < string , any > ) : void {
114135 this . _sendDisplay (
@@ -121,14 +142,20 @@ export class DisplayHelper {
121142 }
122143
123144 /**
124- * Display plain text
145+ * Display plain text.
146+ *
147+ * @param content - The text content to display.
148+ * @param metadata - Optional metadata for the display.
125149 */
126150 text ( content : string , metadata ?: Record < string , any > ) : void {
127151 this . _sendDisplay ( { 'text/plain' : content } , metadata ) ;
128152 }
129153
130154 /**
131- * Display Markdown content
155+ * Display Markdown content.
156+ *
157+ * @param content - The Markdown content to display.
158+ * @param metadata - Optional metadata for the display.
132159 */
133160 markdown ( content : string , metadata ?: Record < string , any > ) : void {
134161 this . _sendDisplay (
@@ -138,7 +165,10 @@ export class DisplayHelper {
138165 }
139166
140167 /**
141- * Display LaTeX content
168+ * Display LaTeX content.
169+ *
170+ * @param content - The LaTeX content to display.
171+ * @param metadata - Optional metadata for the display.
142172 */
143173 latex ( content : string , metadata ?: Record < string , any > ) : void {
144174 this . _sendDisplay (
@@ -148,7 +178,10 @@ export class DisplayHelper {
148178 }
149179
150180 /**
151- * Display JSON content
181+ * Display JSON content.
182+ *
183+ * @param content - The JSON content to display.
184+ * @param metadata - Optional metadata for the display.
152185 */
153186 json ( content : any , metadata ?: Record < string , any > ) : void {
154187 this . _sendDisplay (
@@ -161,15 +194,20 @@ export class DisplayHelper {
161194 }
162195
163196 /**
164- * Display with custom MIME bundle
197+ * Display with custom MIME bundle.
198+ *
199+ * @param mimeBundle - The MIME bundle to display.
200+ * @param metadata - Optional metadata for the display.
165201 */
166202 mime ( mimeBundle : IMimeBundle , metadata ?: Record < string , any > ) : void {
167203 this . _sendDisplay ( mimeBundle , metadata ) ;
168204 }
169205
170206 /**
171- * Clear the current output
172- * @param options.wait If true, wait for new output before clearing
207+ * Clear the current output.
208+ *
209+ * @param options - Clear options.
210+ * @param options.wait - If true, wait for new output before clearing.
173211 */
174212 clear ( options : { wait ?: boolean } = { } ) : void {
175213 if ( this . _clearCallback ) {
@@ -178,7 +216,7 @@ export class DisplayHelper {
178216 }
179217
180218 /**
181- * Send display data
219+ * Send display data.
182220 */
183221 private _sendDisplay (
184222 data : IMimeBundle ,
@@ -197,4 +235,9 @@ export class DisplayHelper {
197235 this . _result = data ;
198236 }
199237 }
238+
239+ private _displayCallback ?: ( data : IDisplayData ) => void ;
240+ private _clearCallback ?: ( wait : boolean ) => void ;
241+ private _displayId ?: string ;
242+ private _result ?: IMimeBundle ;
200243}
0 commit comments