api-render-ui 1.1.3 → 1.1.5
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.
- package/Readme.md +30 -0
- package/dist/index.cjs +139 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +139 -26
- package/dist/index.js.map +1 -1
- package/example/animal.html +1082 -1020
- package/package.json +1 -1
- package/src/api-render-ui.css +76 -24
- package/src/api-render-ui.ts +76 -3
- package/src/inlined-styles.ts +76 -24
- package/src/model.ts +45 -0
package/dist/index.js
CHANGED
|
@@ -1,13 +1,55 @@
|
|
|
1
1
|
// src/inlined-styles.ts
|
|
2
2
|
var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
3
3
|
align-items: flex-start;
|
|
4
|
-
background: white;
|
|
4
|
+
background: var(--surface, white);
|
|
5
5
|
display: inline-flex;
|
|
6
6
|
flex-direction: column;
|
|
7
7
|
gap: 5px;
|
|
8
8
|
justify-content: flex-start;
|
|
9
9
|
width: 100%
|
|
10
10
|
}
|
|
11
|
+
/* Theme variables and mappings */
|
|
12
|
+
:root {
|
|
13
|
+
--Labels---Vibrant---Controls-Primary-\u221A: #404040;
|
|
14
|
+
--primary: #404040;
|
|
15
|
+
--main-color: #404040; /* main / primary color */
|
|
16
|
+
--aux-color: #a9c7ef; /* auxiliary color for hover / accents */
|
|
17
|
+
--embellish-color: #ced8e7; /* embellishment color for active states */
|
|
18
|
+
--surface: white;
|
|
19
|
+
--text: black;
|
|
20
|
+
--even-bg: rgb(235, 239, 244);
|
|
21
|
+
--odd-bg: rgb(250, 246, 246);
|
|
22
|
+
--hover-bg: var(--aux-color, rgb(169, 199, 239));
|
|
23
|
+
--active-bg: var(--embellish-color, rgb(206, 216, 231));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.codigma-theme-light {
|
|
27
|
+
--main-color: #404040;
|
|
28
|
+
--aux-color: #a9c7ef;
|
|
29
|
+
--embellish-color: #ced8e7;
|
|
30
|
+
--primary: var(--main-color);
|
|
31
|
+
--Labels---Vibrant---Controls-Primary-\u221A: var(--main-color);
|
|
32
|
+
--surface: white;
|
|
33
|
+
--text: black;
|
|
34
|
+
--even-bg: rgb(235, 239, 244);
|
|
35
|
+
--odd-bg: rgb(250, 246, 246);
|
|
36
|
+
--hover-bg: var(--aux-color);
|
|
37
|
+
--active-bg: var(--embellish-color);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.codigma-theme-dark {
|
|
41
|
+
--main-color: #9fb8ff;
|
|
42
|
+
--aux-color: #334155;
|
|
43
|
+
--embellish-color: #22303a;
|
|
44
|
+
--primary: var(--main-color);
|
|
45
|
+
--Labels---Vibrant---Controls-Primary-\u221A: var(--main-color);
|
|
46
|
+
--surface: #1f1f1f;
|
|
47
|
+
--text: #e6e6e6;
|
|
48
|
+
--even-bg: #2a2a2a;
|
|
49
|
+
--odd-bg: #222222;
|
|
50
|
+
--hover-bg: var(--aux-color);
|
|
51
|
+
--active-bg: var(--embellish-color);
|
|
52
|
+
}
|
|
11
53
|
.codigma-apioperator {
|
|
12
54
|
align-items: center;
|
|
13
55
|
align-self: stretch;
|
|
@@ -18,18 +60,21 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
18
60
|
justify-content: flex-start
|
|
19
61
|
}
|
|
20
62
|
.codigma-apioperator:nth-child(even) {
|
|
21
|
-
|
|
63
|
+
color: var(--main-color, var(--primary, #404040));
|
|
22
64
|
}
|
|
23
65
|
.codigma-apioperator:nth-child(odd) {
|
|
24
|
-
|
|
66
|
+
color: var(--main-color, var(--primary, #404040));
|
|
25
67
|
}
|
|
26
68
|
|
|
27
69
|
.codigma-apioperator:hover {
|
|
28
70
|
cursor: pointer;
|
|
29
|
-
|
|
71
|
+
color: var(--text, black);
|
|
72
|
+
background-color: var(--hover-bg, rgba(169,199,239,0.12));
|
|
73
|
+
transition: background-color .12s ease, color .12s ease;
|
|
74
|
+
border-radius: 4px;
|
|
30
75
|
}
|
|
31
76
|
.codigma-apioperator:active {
|
|
32
|
-
|
|
77
|
+
color: var(--main-color, var(--primary, #404040));
|
|
33
78
|
}
|
|
34
79
|
.codigma-method {
|
|
35
80
|
align-items: center;
|
|
@@ -45,18 +90,18 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
45
90
|
justify-content: center
|
|
46
91
|
}
|
|
47
92
|
.codigma-get {
|
|
48
|
-
color: var(--
|
|
93
|
+
color: var(--main-color, var(--primary, #404040));
|
|
49
94
|
word-wrap: break-word
|
|
50
95
|
}
|
|
51
96
|
.codigma-requrl {
|
|
52
|
-
color: black;
|
|
97
|
+
color: var(--text, black);
|
|
53
98
|
flex: 1 1 0;
|
|
54
99
|
word-wrap: break-word
|
|
55
100
|
}
|
|
56
101
|
/**********************apiunit css style*************************/
|
|
57
102
|
.codigma-apiunit {
|
|
58
103
|
align-items: flex-start;
|
|
59
|
-
background: white;
|
|
104
|
+
background: var(--surface, white);
|
|
60
105
|
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
|
|
61
106
|
display: inline-flex;
|
|
62
107
|
flex-direction: column;
|
|
@@ -67,8 +112,8 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
67
112
|
.codigma-apiunit-apioperator {
|
|
68
113
|
align-items: center;
|
|
69
114
|
align-self: stretch;
|
|
70
|
-
border-bottom: 1px var(--
|
|
71
|
-
border-top: 1px var(--
|
|
115
|
+
border-bottom: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
116
|
+
border-top: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
72
117
|
display: inline-flex;
|
|
73
118
|
gap: 10px;
|
|
74
119
|
height: 48px;
|
|
@@ -89,17 +134,18 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
89
134
|
justify-content: center
|
|
90
135
|
}
|
|
91
136
|
.codigma-apiunit-post {
|
|
92
|
-
color: var(--
|
|
137
|
+
color: var(--main-color, var(--primary, #404040));
|
|
93
138
|
word-wrap: break-word
|
|
94
139
|
}
|
|
95
140
|
.codigma-apiunit-requrl {
|
|
96
|
-
color: black;
|
|
141
|
+
color: var(--text, black);
|
|
97
142
|
flex: 1 1 0;
|
|
98
143
|
word-wrap: break-word;
|
|
99
144
|
border-left: 0;
|
|
100
145
|
border-right: 0;
|
|
101
146
|
border-top: 0;
|
|
102
|
-
border-bottom: 1px solid
|
|
147
|
+
border-bottom: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
148
|
+
height: 70%;
|
|
103
149
|
}
|
|
104
150
|
.codigma-apiunit-send-button {
|
|
105
151
|
align-items: center;
|
|
@@ -110,7 +156,7 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
110
156
|
width: 88px
|
|
111
157
|
}
|
|
112
158
|
.codigma-apiunit-send {
|
|
113
|
-
color: black;
|
|
159
|
+
color: var(--text, black);
|
|
114
160
|
word-wrap: break-word
|
|
115
161
|
}
|
|
116
162
|
.codigma-apiunit-send-button:hover {
|
|
@@ -139,7 +185,7 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
139
185
|
}
|
|
140
186
|
.codigma-apiunit-parameters-cnr {
|
|
141
187
|
align-items: center;
|
|
142
|
-
background: white;
|
|
188
|
+
background: var(--surface, white);
|
|
143
189
|
display: flex;
|
|
144
190
|
height: 42px;
|
|
145
191
|
justify-content: space-between;
|
|
@@ -148,7 +194,7 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
148
194
|
.codigma-apiunit-parakeyvalues {
|
|
149
195
|
align-items: flex-start;
|
|
150
196
|
align-self: stretch;
|
|
151
|
-
background: white;
|
|
197
|
+
background: var(--surface, white);
|
|
152
198
|
display: inline-flex;
|
|
153
199
|
flex-direction: column;
|
|
154
200
|
flex: 1 1 0;
|
|
@@ -166,11 +212,11 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
166
212
|
}
|
|
167
213
|
.codigma-apiunit-valuetext {
|
|
168
214
|
align-self: stretch;
|
|
169
|
-
background: white;
|
|
215
|
+
background: var(--surface, white);
|
|
170
216
|
border-left: 0;
|
|
171
217
|
border-right: 0;
|
|
172
218
|
border-top: 0;
|
|
173
|
-
border-bottom: 1px var(--
|
|
219
|
+
border-bottom: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
174
220
|
padding: 10px;
|
|
175
221
|
width: 161px
|
|
176
222
|
}
|
|
@@ -195,21 +241,21 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
195
241
|
.codigma-apiunit-parakeyvalues {
|
|
196
242
|
align-items: flex-start;
|
|
197
243
|
align-self: stretch;
|
|
198
|
-
background: white;
|
|
244
|
+
background: var(--surface, white);
|
|
199
245
|
display: flex;
|
|
200
246
|
flex: 1 1 0;
|
|
201
247
|
gap: 10px;
|
|
202
248
|
justify-content: flex-start;
|
|
203
249
|
outline-offset: -1px;
|
|
204
|
-
outline: 1px var(--
|
|
250
|
+
outline: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
205
251
|
overflow: hidden;
|
|
206
252
|
padding: 10px
|
|
207
253
|
}
|
|
208
254
|
.codigma-apiunit-reqresponse {
|
|
209
255
|
align-items: flex-start;
|
|
210
256
|
align-self: stretch;
|
|
211
|
-
background: white;
|
|
212
|
-
border-top: 1px var(--
|
|
257
|
+
background: var(--surface, white);
|
|
258
|
+
border-top: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
213
259
|
display: flex;
|
|
214
260
|
flex-direction: column;
|
|
215
261
|
flex: 1 1 0;
|
|
@@ -227,7 +273,7 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
227
273
|
}
|
|
228
274
|
.codigma-apiunit-responsetitle {
|
|
229
275
|
align-items: center;
|
|
230
|
-
border-bottom: 1px var(--
|
|
276
|
+
border-bottom: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
231
277
|
display: flex;
|
|
232
278
|
height: 42px;
|
|
233
279
|
justify-content: space-between;
|
|
@@ -236,7 +282,7 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
236
282
|
.codigma-apiunit-response-cnr {
|
|
237
283
|
align-items: center;
|
|
238
284
|
align-self: stretch;
|
|
239
|
-
background: white;
|
|
285
|
+
background: var(--surface, white);
|
|
240
286
|
display: flex;
|
|
241
287
|
justify-content: space-between;
|
|
242
288
|
padding-top: 2px;
|
|
@@ -248,6 +294,12 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
248
294
|
flex: 1 1 0;
|
|
249
295
|
min-height: 5rem;
|
|
250
296
|
/* padding: 2px */
|
|
297
|
+
}
|
|
298
|
+
.codigma-apiunit-apioperator:hover {
|
|
299
|
+
cursor: pointer;
|
|
300
|
+
color: var(--text, black);
|
|
301
|
+
background-color: var(--hover-bg, rgba(169,199,239,0.08));
|
|
302
|
+
transition: background-color .12s ease, color .12s ease;
|
|
251
303
|
}`;
|
|
252
304
|
|
|
253
305
|
// src/api-render-ui.ts
|
|
@@ -261,7 +313,9 @@ var ApiRenderer = class _ApiRenderer {
|
|
|
261
313
|
mountPoint: document?.body,
|
|
262
314
|
// 默认挂载到body
|
|
263
315
|
className: "Apioperatorlist codigma-apioperatorlist",
|
|
264
|
-
layerName: "apioperatorlist"
|
|
316
|
+
layerName: "apioperatorlist",
|
|
317
|
+
// theme: can be a string like 'light' or 'dark', or an object palette
|
|
318
|
+
theme: "light"
|
|
265
319
|
}, options);
|
|
266
320
|
this.container = null;
|
|
267
321
|
}
|
|
@@ -280,6 +334,47 @@ var ApiRenderer = class _ApiRenderer {
|
|
|
280
334
|
if (!mountElement) {
|
|
281
335
|
throw new Error("Invalid mount point specified");
|
|
282
336
|
}
|
|
337
|
+
try {
|
|
338
|
+
const themeOpt = this.options.theme;
|
|
339
|
+
if (typeof themeOpt === "string") {
|
|
340
|
+
mountElement.classList.add(`codigma-theme-${themeOpt}`);
|
|
341
|
+
} else if (themeOpt && typeof themeOpt === "object") {
|
|
342
|
+
const palette = themeOpt;
|
|
343
|
+
const setVar = (key, value) => {
|
|
344
|
+
if (value == null) return;
|
|
345
|
+
const varName = key.startsWith("--") ? key : `--${key}`;
|
|
346
|
+
try {
|
|
347
|
+
mountElement.style.setProperty(varName, String(value));
|
|
348
|
+
} catch {
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
if (palette.main) {
|
|
352
|
+
setVar("--main-color", palette.main);
|
|
353
|
+
setVar("--primary", palette.main);
|
|
354
|
+
setVar("--Labels---Vibrant---Controls-Primary-\u221A", palette.main);
|
|
355
|
+
}
|
|
356
|
+
if (palette.aux) {
|
|
357
|
+
setVar("--aux-color", palette.aux);
|
|
358
|
+
setVar("--hover-bg", palette.aux);
|
|
359
|
+
}
|
|
360
|
+
if (palette.embellish || palette.embellishment) {
|
|
361
|
+
setVar("--embellish-color", palette.embellish || palette.embellishment);
|
|
362
|
+
setVar("--active-bg", palette.embellish || palette.embellishment);
|
|
363
|
+
}
|
|
364
|
+
if (palette.primary) {
|
|
365
|
+
setVar("--primary", palette.primary);
|
|
366
|
+
setVar("--Labels---Vibrant---Controls-Primary-\u221A", palette.primary);
|
|
367
|
+
setVar("--main-color", palette.primary);
|
|
368
|
+
}
|
|
369
|
+
if (palette["--even-bg"]) setVar("--even-bg", palette["--even-bg"]);
|
|
370
|
+
if (palette["--odd-bg"]) setVar("--odd-bg", palette["--odd-bg"]);
|
|
371
|
+
if (palette.surface) setVar("--surface", palette.surface);
|
|
372
|
+
Object.entries(palette).forEach(([k, v]) => {
|
|
373
|
+
if (k.startsWith("--")) setVar(k, v);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
} catch (e) {
|
|
377
|
+
}
|
|
283
378
|
if (apiSpec["openapi"] && apiSpec["openapi"].startsWith("3.") || apiSpec["swagger"] && apiSpec["swagger"].startsWith("2.")) {
|
|
284
379
|
const countApi = countOpenAPI(apiSpec);
|
|
285
380
|
const apiOperatorList = parseOpenApiSpec(apiSpec, currentServer, serviceName);
|
|
@@ -1201,7 +1296,7 @@ function createSvg() {
|
|
|
1201
1296
|
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
1202
1297
|
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1203
1298
|
path.setAttribute("d", "M5.5 8.5L10.5 13.5L15.5 8.5");
|
|
1204
|
-
path.setAttribute("stroke", "var(--
|
|
1299
|
+
path.setAttribute("stroke", "var(--main-color, var(--primary, #404040) )");
|
|
1205
1300
|
path.setAttribute("stroke-width", "2");
|
|
1206
1301
|
path.setAttribute("stroke-linecap", "round");
|
|
1207
1302
|
path.setAttribute("stroke-linejoin", "round");
|
|
@@ -1369,6 +1464,9 @@ function parseOpenApiSpec(openapiSpec, currentServer, serviceName) {
|
|
|
1369
1464
|
url = openapiSpec.servers[0].url + path;
|
|
1370
1465
|
}
|
|
1371
1466
|
const apiOperator = {
|
|
1467
|
+
id: uuid(),
|
|
1468
|
+
label: path,
|
|
1469
|
+
children: [],
|
|
1372
1470
|
method: method.toUpperCase(),
|
|
1373
1471
|
url,
|
|
1374
1472
|
rawApiInfo: operation,
|
|
@@ -1461,6 +1559,21 @@ function parseOpenApiSpec(openapiSpec, currentServer, serviceName) {
|
|
|
1461
1559
|
});
|
|
1462
1560
|
return apiOperatorList;
|
|
1463
1561
|
}
|
|
1562
|
+
function uuid() {
|
|
1563
|
+
let s = [];
|
|
1564
|
+
const hexDigits = "0123456789abcdef";
|
|
1565
|
+
for (let i = 0; i < 28; i++) {
|
|
1566
|
+
const start = Math.floor(Math.random() * 16);
|
|
1567
|
+
s[i] = hexDigits.substring(start, start + 1);
|
|
1568
|
+
}
|
|
1569
|
+
s[14] = "4";
|
|
1570
|
+
const start1 = s[19] & 3 | 8;
|
|
1571
|
+
s[19] = hexDigits.substring(start1, start1 + 1);
|
|
1572
|
+
s[8] = s[13] = s[18] = s[23] = "-";
|
|
1573
|
+
s[0] = "a";
|
|
1574
|
+
var uuid2 = s.join("");
|
|
1575
|
+
return uuid2;
|
|
1576
|
+
}
|
|
1464
1577
|
function countOpenAPI(openapiSpec) {
|
|
1465
1578
|
let apiCount = 0;
|
|
1466
1579
|
const pathEntries = [];
|