@@ -36,32 +36,15 @@ module.exports = class Render {
36
36
this . display = display ;
37
37
}
38
38
39
- /**
40
- * @param {string } format
41
- */
42
- getHTML ( format ) {
43
- const globalFormat = this . display . formats . find ( currentFormat => currentFormat . name === `GLOBAL` ) ;
44
-
39
+ generate ( format ) {
45
40
let size = {
46
41
width : 880 ,
47
42
height : 480
48
43
} ;
49
44
50
- let parts ;
51
-
52
- /** @type {{baseX: number, baseY: number, baseWidth: number, baseHeight: number, x: number, y: number, width: number, height: number, color?: string} } */
53
- let window ;
54
-
55
- /** @type {FieldInfo } */
56
- let windowTitle ;
45
+ const globalFormat = this . display . formats . find ( currentFormat => currentFormat . name === `GLOBAL` ) ;
57
46
58
- /** @type {RecordInfo } */
59
- let topMostFormat ;
60
- if ( format ) {
61
- topMostFormat = this . display . formats . find ( currentFormat => currentFormat . name === format ) ;
62
- } else {
63
- topMostFormat = globalFormat ;
64
- }
47
+ let parts ;
65
48
66
49
if ( globalFormat ) {
67
50
const displaySize = globalFormat . keywords . find ( keyword => keyword . name === `DSPSIZ` ) ;
@@ -80,10 +63,77 @@ module.exports = class Render {
80
63
}
81
64
}
82
65
83
- if ( topMostFormat ) {
84
- if ( topMostFormat . isWindow ) {
85
- const { x, y, width, height } = topMostFormat . windowSize ;
86
- window = {
66
+ let css = [
67
+ `#container {` ,
68
+ ` font-family: monospace;` ,
69
+ ` font-size: 18px;` ,
70
+ ` border: solid black 1px;` ,
71
+ ` width: ${ size . width } px;` ,
72
+ ` height: ${ size . height } px;` ,
73
+ ` position: absolute;` ,
74
+ ` --g: transparent calc(100% - 1px), #ebebeb 0;` ,
75
+ ` letter-spacing: 0.15px;` ,
76
+ ` color: ${ colors . GRN } ;` ,
77
+ ` background:` ,
78
+ // ` linear-gradient(to right, var(--g)),`,
79
+ // ` linear-gradient(to bottom, var(--g)), `,
80
+ ` black;` ,
81
+ ` background-size:` ,
82
+ ` 11px 100%,` ,
83
+ ` 100% 20px;` ,
84
+ `}` ,
85
+ `@keyframes blinker {` ,
86
+ ` 50% {` ,
87
+ ` opacity: 0;` ,
88
+ ` }` ,
89
+ `}` ,
90
+ ] . join ( ` ` ) ;
91
+
92
+ let body = `<div id="container">` ;
93
+
94
+ const content = this . getHTML ( format ) ;
95
+ css += content . css ;
96
+ body += content . body ;
97
+
98
+ return [
99
+ `<html>` ,
100
+ `<style>${ css } </style>` ,
101
+ `<body>${ body } </body>` ,
102
+ `</html>`
103
+ ] . join ( `` ) ;
104
+ }
105
+
106
+ /**
107
+ * @param {string } format
108
+ */
109
+ getHTML ( format ) {
110
+ let parts ;
111
+
112
+ /** @type {RecordInfo } */
113
+ let windowFormat ;
114
+
115
+ /** @type {{baseX: number, baseY: number, baseWidth: number, baseHeight: number, x: number, y: number, width: number, height: number, color?: string} } */
116
+ let windowConfig ;
117
+
118
+ /** @type {FieldInfo } */
119
+ let windowTitle ;
120
+
121
+ /** @type {RecordInfo } */
122
+ let recordFormat ;
123
+ if ( format ) {
124
+ recordFormat = this . display . formats . find ( currentFormat => currentFormat . name === format ) ;
125
+ }
126
+
127
+ if ( recordFormat ) {
128
+ if ( recordFormat . isWindow ) {
129
+ if ( recordFormat . windowReference ) {
130
+ windowFormat = this . display . formats . find ( currentFormat => currentFormat . name === recordFormat . windowReference ) ;
131
+ } else {
132
+ windowFormat = recordFormat ;
133
+ }
134
+
135
+ const { x, y, width, height } = windowFormat . windowSize ;
136
+ windowConfig = {
87
137
baseX : x ,
88
138
baseY : y ,
89
139
baseWidth : width ,
@@ -94,20 +144,20 @@ module.exports = class Render {
94
144
height : ( height - 1 ) * 20
95
145
} ;
96
146
97
- const borderInfo = topMostFormat . keywords . find ( keyword => keyword . name === `WDWBORDER` ) ;
147
+ const borderInfo = windowFormat . keywords . find ( keyword => keyword . name === `WDWBORDER` ) ;
98
148
if ( borderInfo ) {
99
149
parts = Render . parseParms ( borderInfo . value ) ;
100
150
101
151
parts . forEach ( ( part , index ) => {
102
152
switch ( part . toUpperCase ( ) ) {
103
153
case `*COLOR` :
104
- window . color = parts [ index + 1 ] ;
154
+ windowConfig . color = parts [ index + 1 ] ;
105
155
break ;
106
156
}
107
157
} ) ;
108
158
}
109
159
110
- const windowInfo = topMostFormat . keywords . find ( keyword => keyword . name === `WDWTITLE` ) ;
160
+ const windowInfo = windowFormat . keywords . find ( keyword => keyword . name === `WDWTITLE` ) ;
111
161
if ( windowInfo ) {
112
162
windowTitle = new FieldInfo ( `WINDOWTITLE` ) ;
113
163
windowTitle . type = `char` ;
@@ -158,18 +208,18 @@ module.exports = class Render {
158
208
159
209
const txtLength = windowTitle . value . length ;
160
210
161
- const yPosition = ( window . baseY ) + ( yPositionValue === `top` ? 0 : window . baseHeight ) ;
162
- let xPosition = ( window . baseX + 1 ) ;
211
+ const yPosition = ( windowConfig . baseY ) + ( yPositionValue === `top` ? 0 : windowConfig . baseHeight ) ;
212
+ let xPosition = ( windowConfig . baseX + 1 ) ;
163
213
164
214
switch ( xPositionValue ) {
165
215
case `center` :
166
- xPosition = ( window . baseX + 1 ) + Math . floor ( ( window . baseWidth / 2 ) - ( txtLength / 2 ) ) ;
216
+ xPosition = ( windowConfig . baseX + 1 ) + Math . floor ( ( windowConfig . baseWidth / 2 ) - ( txtLength / 2 ) ) ;
167
217
break ;
168
218
case `right` :
169
- xPosition = ( window . baseX + 1 ) + window . baseWidth - txtLength ;
219
+ xPosition = ( windowConfig . baseX + 1 ) + windowConfig . baseWidth - txtLength ;
170
220
break ;
171
221
case `left` :
172
- xPosition = ( window . baseX + 1 ) ;
222
+ xPosition = ( windowConfig . baseX + 1 ) ;
173
223
break ;
174
224
}
175
225
@@ -183,58 +233,42 @@ module.exports = class Render {
183
233
}
184
234
}
185
235
186
- let css = [
187
- `#container {` ,
188
- ` font-family: monospace;` ,
189
- ` font-size: 18px;` ,
190
- ` border: solid black 1px;` ,
191
- ` width: ${ size . width } px;` ,
192
- ` height: ${ size . height } px;` ,
193
- ` position: absolute;` ,
194
- ` --g: transparent calc(100% - 1px), #ebebeb 0;` ,
195
- ` letter-spacing: 0.15px;` ,
196
- ` color: ${ colors . GRN } ;` ,
197
- ` background:` ,
198
- // ` linear-gradient(to right, var(--g)),`,
199
- // ` linear-gradient(to bottom, var(--g)), `,
200
- ` black;` ,
201
- ` background-size:` ,
202
- ` 11px 100%,` ,
203
- ` 100% 20px;` ,
204
- `}` ,
205
- `@keyframes blinker {` ,
206
- ` 50% {` ,
207
- ` opacity: 0;` ,
208
- ` }` ,
209
- `}` ,
210
- ] . join ( ` ` ) ;
236
+ let css = `` ;
237
+ let body = `` ;
211
238
239
+ if ( windowFormat ) {
212
240
// If this is a window, add the window CSS
213
- if ( window ) {
214
- const windowColor = colors [ window . color ] || colors . BLU ;
215
- css += [
216
- `#window {`,
217
- ` position: absolute;` ,
218
- ` width: ${ window . width } px;` ,
219
- ` height: ${ window . height } px;` ,
220
- ` top: ${ window . y } px;` ,
221
- ` left: ${ window . x } px;` ,
222
- ` border: solid ${ windowColor } 2px;` ,
223
- `}` ,
224
- ] . join ( ` ` ) ;
225
- }
241
+ if ( windowConfig ) {
242
+ const windowColor = colors [ windowConfig . color ] || colors . BLU ;
243
+ css += [
244
+ `# ${ windowFormat . name } {`,
245
+ ` position: absolute;` ,
246
+ ` width: ${ windowConfig . width } px;` ,
247
+ ` height: ${ windowConfig . height } px;` ,
248
+ ` top: ${ windowConfig . y } px;` ,
249
+ ` left: ${ windowConfig . x } px;` ,
250
+ ` border: solid ${ windowColor } 2px;` ,
251
+ `}` ,
252
+ ] . join ( ` ` ) ;
253
+ }
226
254
227
- let body = `<div id="container">` ;
255
+ if ( windowTitle ) {
256
+ const windowContent = Render . getContent ( windowTitle ) ;
228
257
229
- if ( windowTitle ) {
230
- const windowContent = Render . getContent ( windowTitle ) ;
258
+ css += windowContent . css ;
259
+ body += windowContent . body ;
260
+ }
231
261
232
- css += windowContent . css ;
233
- body += windowContent . body ;
234
- }
262
+ if ( windowConfig ) {
263
+ body += `<div id=" ${ windowFormat . name } ">` ;
264
+ }
235
265
236
- if ( window ) {
237
- body += `<div id="window">` ;
266
+ if ( windowFormat . name !== format ) {
267
+ const windowContent = this . getFormatContent ( windowFormat . name ) ;
268
+
269
+ css += windowContent . css ;
270
+ body += windowContent . body ;
271
+ }
238
272
}
239
273
240
274
if ( format ) {
@@ -257,18 +291,14 @@ module.exports = class Render {
257
291
} ) ;
258
292
}
259
293
260
- if ( window ) {
294
+ if ( windowFormat && windowConfig ) {
261
295
body += `</div>` ;
262
296
}
263
297
264
- body += `</div>` ;
265
-
266
- return [
267
- `<html>` ,
268
- `<style>${ css } </style>` ,
269
- `<body>${ body } </body>` ,
270
- `</html>`
271
- ] . join ( `` ) ;
298
+ return {
299
+ css,
300
+ body
301
+ }
272
302
}
273
303
274
304
/**
0 commit comments