@bsv/overlay-express 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,188 +1,219 @@
1
- export default () => `<!DOCTYPE html>
1
+ export type UIConfig = {
2
+ faviconUrl?: string;
3
+ backgroundColor?: string;
4
+ primaryColor?: string;
5
+ secondaryColor?: string;
6
+ fontFamily?: string;
7
+ headingFontFamily?: string;
8
+ additionalStyles?: string;
9
+ sectionBackgroundColor?: string;
10
+ linkColor?: string;
11
+ hoverColor?: string;
12
+ borderColor?: string;
13
+ };
14
+
15
+ export default (config: UIConfig = {}): string => {
16
+ const {
17
+ faviconUrl = 'https://bsvblockchain.org/favicon.ico',
18
+ backgroundColor = '#282E33',
19
+ primaryColor = '#B6C2CF',
20
+ secondaryColor = '#579DFF',
21
+ fontFamily = 'Arial, sans-serif',
22
+ headingFontFamily = 'Arial Black, Gadget, sans-serif',
23
+ additionalStyles = '',
24
+ sectionBackgroundColor = '#323940',
25
+ linkColor = '#579DFF',
26
+ hoverColor = '#3A4147',
27
+ borderColor = '#B6C2CF',
28
+ } = config;
29
+
30
+ return `<!DOCTYPE html>
2
31
  <html>
3
32
  <head>
4
33
  <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
34
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
35
  <title>Overlay Services</title>
36
+ <link rel="icon" type="image/x-icon" href="${faviconUrl}">
7
37
  <style>
38
+ :root {
39
+ --background-color: ${backgroundColor};
40
+ --primary-color: ${primaryColor};
41
+ --secondary-color: ${secondaryColor};
42
+ --font-family: ${fontFamily};
43
+ --heading-font-family: ${headingFontFamily};
44
+ --section-background-color: ${sectionBackgroundColor};
45
+ --link-color: ${linkColor};
46
+ --hover-color: ${hoverColor};
47
+ --border-color: ${borderColor};
48
+ }
49
+
8
50
  body {
9
- font-family: Arial;
10
- background-color: #282E33;
11
- overflow: hidden;
51
+ font-family: var(--font-family);
52
+ background-color: var(--background-color);
53
+ margin: 0;
54
+ padding: 0;
12
55
  }
13
56
 
14
- * {
15
- color: #B6C2CF;
57
+ h1, h2, h3 {
58
+ font-family: var(--heading-font-family);
16
59
  }
17
60
 
18
- .main {
19
- height: 100vh;
20
- word-wrap: break-word;
21
- display: flex;
22
- flex-direction: row;
61
+ * {
62
+ color: var(--primary-color);
23
63
  }
24
64
 
25
65
  a {
26
- color: #579DFF;
66
+ color: var(--link-color);
67
+ text-decoration: none;
27
68
  }
28
69
 
29
- .docs_heading {
30
- text-align: center;
31
- padding-bottom: 0.5em;
32
- border-bottom: thin solid #B6C2CF;
70
+ a:hover {
71
+ color: var(--secondary-color);
33
72
  }
34
73
 
35
- .topic_container {
36
- padding-top: 1.5em;
74
+ .main {
75
+ display: flex;
76
+ flex-direction: row;
77
+ height: 100vh;
78
+ overflow: hidden;
37
79
  }
38
80
 
39
- .provider_container {
40
- padding-top: 1.5em;
81
+ .column_left, .column_right {
82
+ padding: 1.5em;
83
+ overflow-y: auto;
41
84
  }
42
85
 
43
- li {
44
- display: block;
45
- padding: 0.2em;
46
- margin-top: 0.5em;
47
- width: 10em;
48
- border-radius: 5%;
86
+ .column_left {
87
+ width: 35%;
88
+ background-color: var(--section-background-color);
49
89
  }
50
90
 
51
- .list_a {
52
- display: block;
53
- width: 10em;
54
- color: #B6C2CF;
55
- text-decoration: none;
91
+ .column_right {
92
+ width: 65%;
93
+ border-left: 1px solid var(--border-color);
56
94
  }
57
95
 
58
- li:hover,
59
- li:active {
60
- cursor: pointer;
61
- background-color: #323940;
96
+ .docs_heading {
97
+ text-align: center;
98
+ padding-bottom: 0.5em;
99
+ border-bottom: 1px solid var(--border-color);
62
100
  }
63
101
 
64
102
  ul {
65
103
  list-style-type: none;
66
- margin-top: 1em;
104
+ padding: 0;
67
105
  }
68
106
 
69
- .column_left {
70
- display: flex;
71
- flex-direction: column;
72
- float: left;
73
- width: 40%;
74
- height: 100vh;
75
- overflow-y: scroll;
76
- padding-top: 1.5em;
107
+ li {
108
+ margin: 0.5em 0;
77
109
  }
78
110
 
79
- .column_right {
80
- display: flex;
81
- flex-direction: column;
82
- float: right;
83
- width: 60%;
84
- height: 100vh;
85
- overflow-y: scroll;
86
- border-left: thin solid #B6C2CF;
87
- padding-top: 1.5em;
111
+ li a {
112
+ display: block;
113
+ padding: 0.5em;
114
+ background-color: transparent;
115
+ border-radius: 5px;
116
+ transition: background-color 0.3s;
88
117
  }
89
118
 
90
- @media screen and (max-width: 850px) {
119
+ li a:hover {
120
+ background-color: var(--hover-color);
121
+ cursor: pointer;
122
+ }
91
123
 
124
+ /* Responsive design */
125
+ @media screen and (max-width: 850px) {
92
126
  .main {
93
- width: 100vw;
94
- float: none;
95
- overflow-y: scroll;
96
- display: block;
127
+ flex-direction: column;
97
128
  }
98
129
 
99
- .column_left {
100
- width: 100vw;
101
- height: auto;
102
- float: none;
103
- overflow-y: visible;
104
- display: block;
130
+ .column_left, .column_right {
131
+ width: 100%;
105
132
  }
106
133
 
107
134
  .column_right {
108
- width: 100vw;
109
- height: auto;
110
- float: none;
111
- overflow-y: visible;
112
- display: block;
113
- border: none;
135
+ border-left: none;
136
+ border-top: 1px solid var(--border-color);
114
137
  }
115
-
116
138
  }
139
+
140
+ ${additionalStyles}
117
141
  </style>
118
142
  <script src="https://cdn.jsdelivr.net/npm/showdown@2.0.3/dist/showdown.min.js"></script>
119
143
  <script>
120
- const showdown = window.showdown
121
-
122
- const Convert = (md) => {
123
- let converter = new showdown.Converter()
124
- let converted = converter.makeHtml(md)
125
- return converted
126
- }
127
-
128
- window.managerDocumentation = async (manager) => {
129
- let res = await window.fetch(\`/getDocumentationForTopicManager?manager=\${manager}\`)
130
- let docs = await res.json()
131
- let managerReadme = Convert(docs)
132
- document.getElementById('documentation_container').innerHTML = managerReadme
133
- document.getElementById('documentation_title').innerHTML = \`<h1 class="docs_heading">\${manager + ' Topic Manager'}</h1>\`
134
- }
135
-
136
- window.topicDocumentation = async (provider) => {
137
- let res = await window.fetch(\`/getDocumentationForLookupServiceProvider?lookupServices=\${provider}\`)
138
- let docs = await res.json()
139
- let providerReadme = Convert(docs)
140
- document.getElementById('documentation_container').innerHTML = providerReadme
141
- document.getElementById('documentation_title').innerHTML = \`<h1 class="docs_heading">\${provider + ' Lookup Service'}</h1>\`
142
- }
143
-
144
- window.fetch('/listTopicManagers')
145
- .then((res) => {
146
- return res.json()
147
- })
148
- .then((managers) => {
149
- for (i = 0; i < managers.length; i++) {
150
- let li = document.createElement('li')
151
- li.innerHTML = \`<a class="list_a" onclick="window.managerDocumentation('\${managers[i]}')">\${managers[i]}</a>\`
152
- manager_list.appendChild(li)
153
- }
154
- })
155
- .catch(() => {
156
- let message = document.createElement('h4')
157
- message.innerText = 'Something went wrong!'
158
- manager_list.insertBefore(message, manager_list.children[0])
159
- })
160
-
161
- window.fetch('/listLookupServiceProviders')
162
- .then((res) => {
163
- return res.json()
164
- })
165
- .then((providers) => {
166
- for (i = 0; i < providers.length; i++) {
167
- let li = document.createElement('li')
168
- li.innerHTML = \`<a class="list_a" onclick="window.topicDocumentation('\${providers[i]}')">\${providers[i]}</a>\`
169
- provider_list.appendChild(li)
170
- }
171
- })
172
- .catch(() => {
173
- let message = document.createElement('h4')
174
- message.innerText = 'Something went wrong!'
175
- provider_list.insertBefore(message, provider_list.children[0])
176
- })
177
- </script>
144
+ const showdown = window.showdown;
145
+
146
+ const Convert = (md) => {
147
+ let converter = new showdown.Converter();
148
+ return converter.makeHtml(md);
149
+ };
150
+
151
+ window.managerDocumentation = async (manager) => {
152
+ try {
153
+ let res = await fetch(\`/getDocumentationForTopicManager?manager=\${manager}\`);
154
+ let docs = await res.text();
155
+ let managerReadme = Convert(docs);
156
+ document.getElementById('documentation_container').innerHTML = managerReadme;
157
+ document.getElementById('documentation_title').innerHTML = \`<h1 class="docs_heading">\${manager} Topic Manager</h1>\`;
158
+ } catch (error) {
159
+ console.error('Error fetching manager documentation:', error);
160
+ }
161
+ };
162
+
163
+ window.topicDocumentation = async (provider) => {
164
+ try {
165
+ let res = await fetch(\`/getDocumentationForLookupServiceProvider?lookupServices=\${provider}\`);
166
+ let docs = await res.text();
167
+ let providerReadme = Convert(docs);
168
+ document.getElementById('documentation_container').innerHTML = providerReadme;
169
+ document.getElementById('documentation_title').innerHTML = \`<h1 class="docs_heading">\${provider} Lookup Service</h1>\`;
170
+ } catch (error) {
171
+ console.error('Error fetching provider documentation:', error);
172
+ }
173
+ };
174
+
175
+ document.addEventListener('DOMContentLoaded', () => {
176
+ fetch('/listTopicManagers')
177
+ .then(res => res.json())
178
+ .then(managers => {
179
+ const managerList = document.getElementById('manager_list');
180
+ managers.forEach(manager => {
181
+ let li = document.createElement('li');
182
+ li.innerHTML = \`<a onclick="window.managerDocumentation('\${manager}')">\${manager}</a>\`;
183
+ managerList.appendChild(li);
184
+ });
185
+ })
186
+ .catch(() => {
187
+ let message = document.createElement('h4');
188
+ message.innerText = 'Something went wrong!';
189
+ manager_list.insertBefore(message, manager_list.children[0]);
190
+ });
191
+
192
+ fetch('/listLookupServiceProviders')
193
+ .then(res => res.json())
194
+ .then(providers => {
195
+ const providerList = document.getElementById('provider_list');
196
+ providers.forEach(provider => {
197
+ let li = document.createElement('li');
198
+ li.innerHTML = \`<a onclick="window.topicDocumentation('\${provider}')">\${provider}</a>\`;
199
+ providerList.appendChild(li);
200
+ });
201
+ })
202
+ .catch(() => {
203
+ let message = document.createElement('h4');
204
+ message.innerText = 'Something went wrong!';
205
+ provider_list.insertBefore(message, provider_list.children[0]);
206
+ });
207
+ });
208
+ </script>
178
209
  </head>
179
210
 
180
211
  <body>
181
- <div class='main'>
212
+ <div class="main">
182
213
  <div class="column_left">
183
214
  <div class="page_head">
184
- <h1>Hello Overlay Services</h1>
185
- <p>Learn more on <a href='https://github.com/bitcoin-sv/overlay-services'>GitHub</a></p>
215
+ <h1>Welcome to Overlay Services</h1>
216
+ <p>Learn more on <a href="https://github.com/bitcoin-sv/overlay-services" target="_blank">GitHub</a></p>
186
217
  </div>
187
218
  <div class="topic_container">
188
219
  <h2>Endpoint Documentation:</h2>
@@ -193,13 +224,12 @@ export default () => `<!DOCTYPE html>
193
224
  <h3>Supported Lookup Service Providers:</h3>
194
225
  <ul id="provider_list"></ul>
195
226
  </div>
196
- <br />
197
227
  </div>
198
228
  <div class="column_right">
199
229
  <div id="documentation_title"></div>
200
- <div id="documentation_container" style="margin-left: 1.5em">
201
- </div>
230
+ <div id="documentation_container" style="margin-left: 1.5em"></div>
202
231
  </div>
203
232
  </div>
204
233
  </body>
205
- </html>`
234
+ </html>`;
235
+ };