openapi-explorer 0.9.310 → 0.9.314

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.
Files changed (121) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/dist/{openapi-explorer.min.js → browser/openapi-explorer.min.js} +3 -3
  3. package/dist/{openapi-explorer.min.js.map → browser/openapi-explorer.min.js.map} +0 -0
  4. package/dist/es/components/api-request.js +936 -0
  5. package/dist/es/components/api-response.js +184 -0
  6. package/dist/es/components/json-tree.js +67 -0
  7. package/{src → dist/es}/components/mime-types.js +11 -17
  8. package/dist/es/components/schema-table.js +156 -0
  9. package/dist/es/components/schema-tree.js +191 -0
  10. package/dist/es/components/tag-input.js +67 -0
  11. package/{src → dist/es}/openapi-explorer-oauth-handler.js +2 -2
  12. package/{src → dist/es}/openapi-explorer.js +364 -371
  13. package/dist/es/styles/advanced-search-styles.js +2 -0
  14. package/dist/es/styles/api-request-styles.js +2 -0
  15. package/dist/es/styles/border-styles.js +2 -0
  16. package/dist/es/styles/endpoint-styles.js +2 -0
  17. package/dist/es/styles/flex-styles.js +2 -0
  18. package/dist/es/styles/font-styles.js +2 -0
  19. package/dist/es/styles/info-styles.js +2 -0
  20. package/dist/es/styles/input-styles.js +4 -0
  21. package/dist/es/styles/nav-styles.js +2 -0
  22. package/dist/es/styles/prism-styles.js +2 -0
  23. package/dist/es/styles/schema-styles.js +2 -0
  24. package/dist/es/styles/tab-styles.js +2 -0
  25. package/dist/es/styles/table-styles.js +2 -0
  26. package/dist/es/templates/advance-search-template.js +37 -0
  27. package/dist/es/templates/callback-template.js +7 -0
  28. package/dist/es/templates/code-samples-template.js +26 -0
  29. package/dist/es/templates/components-template.js +17 -0
  30. package/dist/es/templates/endpoint-template.js +94 -0
  31. package/dist/es/templates/expanded-endpoint-template.js +32 -0
  32. package/{src → dist/es}/templates/focused-endpoint-template.js +15 -15
  33. package/dist/es/templates/navbar-template.js +46 -0
  34. package/dist/es/templates/overview-template.js +9 -0
  35. package/dist/es/templates/responsiveViewMainBodyTemplate.js +30 -0
  36. package/dist/es/templates/security-scheme-template.js +330 -0
  37. package/dist/es/templates/server-template.js +42 -0
  38. package/{src → dist/es}/utils/color-utils.js +53 -16
  39. package/{src → dist/es}/utils/common-utils.js +18 -18
  40. package/{src → dist/es}/utils/schema-utils.js +248 -124
  41. package/{src → dist/es}/utils/spec-parser.js +112 -71
  42. package/dist/es/utils/theme.js +75 -0
  43. package/{src → dist/es}/utils/xml/xml.js +41 -38
  44. package/dist/lib/components/api-request.js +957 -0
  45. package/dist/lib/components/api-response.js +206 -0
  46. package/dist/lib/components/json-tree.js +82 -0
  47. package/dist/lib/components/mime-types.js +70 -0
  48. package/dist/lib/components/schema-table.js +170 -0
  49. package/dist/lib/components/schema-tree.js +206 -0
  50. package/dist/lib/components/tag-input.js +76 -0
  51. package/dist/lib/openapi-explorer-oauth-handler.js +19 -0
  52. package/dist/lib/openapi-explorer.js +817 -0
  53. package/dist/lib/styles/advanced-search-styles.js +10 -0
  54. package/dist/lib/styles/api-request-styles.js +10 -0
  55. package/dist/lib/styles/border-styles.js +10 -0
  56. package/dist/lib/styles/endpoint-styles.js +10 -0
  57. package/dist/lib/styles/flex-styles.js +10 -0
  58. package/dist/lib/styles/font-styles.js +10 -0
  59. package/dist/lib/styles/info-styles.js +10 -0
  60. package/dist/lib/styles/input-styles.js +11 -0
  61. package/dist/lib/styles/nav-styles.js +10 -0
  62. package/dist/lib/styles/prism-styles.js +10 -0
  63. package/dist/lib/styles/schema-styles.js +10 -0
  64. package/dist/lib/styles/tab-styles.js +10 -0
  65. package/dist/lib/styles/table-styles.js +10 -0
  66. package/dist/lib/templates/advance-search-template.js +42 -0
  67. package/dist/lib/templates/callback-template.js +12 -0
  68. package/dist/lib/templates/code-samples-template.js +36 -0
  69. package/dist/lib/templates/components-template.js +27 -0
  70. package/dist/lib/templates/endpoint-template.js +111 -0
  71. package/dist/lib/templates/expanded-endpoint-template.js +48 -0
  72. package/dist/lib/templates/focused-endpoint-template.js +95 -0
  73. package/dist/lib/templates/navbar-template.js +54 -0
  74. package/dist/lib/templates/overview-template.js +16 -0
  75. package/dist/lib/templates/responsiveViewMainBodyTemplate.js +47 -0
  76. package/dist/lib/templates/security-scheme-template.js +342 -0
  77. package/dist/lib/templates/server-template.js +49 -0
  78. package/dist/lib/utils/color-utils.js +112 -0
  79. package/dist/lib/utils/common-utils.js +156 -0
  80. package/dist/lib/utils/schema-utils.js +743 -0
  81. package/dist/lib/utils/spec-parser.js +361 -0
  82. package/dist/lib/utils/theme.js +84 -0
  83. package/dist/lib/utils/xml/xml.js +239 -0
  84. package/package.json +19 -6
  85. package/dist/openapi-explorer.min.js.LICENSE.txt +0 -71
  86. package/dist/openapi-explorer.min.js.LICENSE.txt.gz +0 -0
  87. package/dist/openapi-explorer.min.js.gz +0 -0
  88. package/dist/openapi-explorer.min.js.map.gz +0 -0
  89. package/dist/report.html +0 -38
  90. package/src/components/api-request.js +0 -1244
  91. package/src/components/api-response.js +0 -340
  92. package/src/components/json-tree.js +0 -129
  93. package/src/components/schema-table.js +0 -250
  94. package/src/components/schema-tree.js +0 -280
  95. package/src/components/tag-input.js +0 -109
  96. package/src/styles/advanced-search-styles.js +0 -84
  97. package/src/styles/api-request-styles.js +0 -111
  98. package/src/styles/border-styles.js +0 -24
  99. package/src/styles/css/main.css +0 -24
  100. package/src/styles/endpoint-styles.js +0 -222
  101. package/src/styles/flex-styles.js +0 -15
  102. package/src/styles/font-styles.js +0 -266
  103. package/src/styles/info-styles.js +0 -20
  104. package/src/styles/input-styles.js +0 -236
  105. package/src/styles/nav-styles.js +0 -141
  106. package/src/styles/prism-styles.js +0 -107
  107. package/src/styles/schema-styles.js +0 -121
  108. package/src/styles/tab-styles.js +0 -44
  109. package/src/styles/table-styles.js +0 -48
  110. package/src/templates/advance-search-template.js +0 -81
  111. package/src/templates/callback-template.js +0 -63
  112. package/src/templates/code-samples-template.js +0 -35
  113. package/src/templates/components-template.js +0 -43
  114. package/src/templates/endpoint-template.js +0 -175
  115. package/src/templates/expanded-endpoint-template.js +0 -104
  116. package/src/templates/navbar-template.js +0 -175
  117. package/src/templates/overview-template.js +0 -58
  118. package/src/templates/responsiveViewMainBodyTemplate.js +0 -72
  119. package/src/templates/security-scheme-template.js +0 -487
  120. package/src/templates/server-template.js +0 -106
  121. package/src/utils/theme.js +0 -163
@@ -0,0 +1,361 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = ProcessSpec;
5
+
6
+ var _openapiResolver = _interopRequireDefault(require("openapi-resolver/dist/openapi-resolver.browser"));
7
+
8
+ var _marked = require("marked");
9
+
10
+ var _commonUtils = require("./common-utils");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ async function ProcessSpec(specUrlOrObject, serverUrl = '') {
15
+ const inputSpecIsAUrl = typeof specUrlOrObject === 'string' && specUrlOrObject.match(/^http/) || typeof specUrlOrObject === 'object' && typeof specUrlOrObject.href === 'string';
16
+ let jsonParsedSpec;
17
+
18
+ try {
19
+ jsonParsedSpec = await (0, _openapiResolver.default)(specUrlOrObject);
20
+ } catch (error) {
21
+ // eslint-disable-next-line no-console
22
+ console.error('Error parsing specification', error);
23
+ throw Error('SpecificationNotFound');
24
+ }
25
+
26
+ if (!jsonParsedSpec) {
27
+ throw Error('SpecificationNotFound');
28
+ } // Tags with Paths and WebHooks
29
+
30
+
31
+ const tags = groupByTags(jsonParsedSpec); // Components
32
+
33
+ const components = getComponents(jsonParsedSpec); // Info Description Headers
34
+
35
+ const infoDescriptionHeaders = jsonParsedSpec.info && jsonParsedSpec.info.description ? getHeadersFromMarkdown(jsonParsedSpec.info.description) : []; // Security Scheme
36
+
37
+ const securitySchemes = [];
38
+
39
+ if (jsonParsedSpec.components && jsonParsedSpec.components.securitySchemes) {
40
+ Object.entries(jsonParsedSpec.components.securitySchemes).forEach(kv => {
41
+ const securityObj = {
42
+ apiKeyId: kv[0],
43
+ ...kv[1]
44
+ };
45
+ securityObj.value = '';
46
+ securityObj.finalKeyValue = '';
47
+
48
+ if (kv[1].type === 'apiKey' || kv[1].type === 'http') {
49
+ securityObj.name = kv[1].name || 'Authorization';
50
+ securityObj.user = '';
51
+ securityObj.password = '';
52
+ } else if (kv[1].type === 'oauth2') {
53
+ securityObj.name = 'Authorization';
54
+ securityObj.clientId = '';
55
+ securityObj.clientSecret = '';
56
+ }
57
+
58
+ securitySchemes.push(securityObj);
59
+ });
60
+ } // Updated Security Type Display Text based on Type
61
+
62
+
63
+ securitySchemes.forEach(v => {
64
+ if (v.type === 'http') {
65
+ v.typeDisplay = v.scheme === 'basic' ? 'HTTP Basic' : 'HTTP Bearer';
66
+ } else if (v.type === 'apiKey') {
67
+ v.typeDisplay = `API Key (${v.name})`;
68
+ } else if (v.type === 'oauth2') {
69
+ v.typeDisplay = 'OAuth2.0';
70
+ } else {
71
+ v.typeDisplay = v.type;
72
+ }
73
+ }); // Servers
74
+
75
+ let servers = [];
76
+
77
+ if (Array.isArray(jsonParsedSpec.servers) && jsonParsedSpec.servers.length) {
78
+ jsonParsedSpec.servers.forEach(v => {
79
+ let computedUrl = v.url.trim();
80
+
81
+ if (!(computedUrl.startsWith('http') || computedUrl.startsWith('//') || computedUrl.startsWith('{'))) {
82
+ if (window.location.origin.startsWith('http')) {
83
+ v.url = window.location.origin + v.url;
84
+ computedUrl = v.url;
85
+ }
86
+ } // Apply server-variables to generate final computed-url
87
+
88
+
89
+ if (v.variables) {
90
+ Object.entries(v.variables).forEach(kv => {
91
+ const regex = new RegExp(`{${kv[0]}}`, 'g');
92
+ computedUrl = computedUrl.replace(regex, kv[1].default || '');
93
+ kv[1].value = kv[1].default || '';
94
+ });
95
+ }
96
+
97
+ v.computedUrl = computedUrl;
98
+ });
99
+
100
+ if (serverUrl && !jsonParsedSpec.servers.some(s => s.url === serverUrl || s.computedUrl === serverUrl)) {
101
+ jsonParsedSpec.servers.push({
102
+ url: serverUrl,
103
+ computedUrl: serverUrl
104
+ });
105
+ }
106
+ } else if (serverUrl) {
107
+ jsonParsedSpec.servers = [{
108
+ url: serverUrl,
109
+ computedUrl: serverUrl
110
+ }];
111
+ } else if (inputSpecIsAUrl) {
112
+ jsonParsedSpec.servers = [{
113
+ url: new URL(specUrlOrObject).origin,
114
+ computedUrl: new URL(specUrlOrObject).origin
115
+ }];
116
+ } else if (window.location.origin.startsWith('http')) {
117
+ jsonParsedSpec.servers = [{
118
+ url: window.location.origin,
119
+ computedUrl: window.location.origin
120
+ }];
121
+ } else {
122
+ jsonParsedSpec.servers = [{
123
+ url: 'http://localhost',
124
+ computedUrl: 'http://localhost'
125
+ }];
126
+ }
127
+
128
+ servers = jsonParsedSpec.servers;
129
+ const parsedSpec = {
130
+ info: jsonParsedSpec.info,
131
+ infoDescriptionHeaders,
132
+ tags,
133
+ components,
134
+ // pathGroups,
135
+ externalDocs: jsonParsedSpec.externalDocs,
136
+ securitySchemes,
137
+ servers
138
+ };
139
+ return parsedSpec;
140
+ }
141
+
142
+ function getHeadersFromMarkdown(markdownContent) {
143
+ const tokens = _marked.marked.lexer(markdownContent);
144
+
145
+ const headers = tokens.filter(v => v.type === 'heading' && v.depth <= 2);
146
+ return headers || [];
147
+ }
148
+
149
+ function getComponents(openApiSpec) {
150
+ if (!openApiSpec.components) {
151
+ return [];
152
+ }
153
+
154
+ const components = [];
155
+
156
+ for (const component in openApiSpec.components) {
157
+ const subComponents = Object.keys(openApiSpec.components[component]).map(sComponent => ({
158
+ expanded: true,
159
+ id: `${component.toLowerCase()}-${sComponent.toLowerCase()}`.replace(_commonUtils.invalidCharsRegEx, '-'),
160
+ name: sComponent,
161
+ component: openApiSpec.components[component][sComponent]
162
+ })).sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
163
+ let cmpDescription;
164
+ let cmpName;
165
+
166
+ switch (component) {
167
+ case 'schemas':
168
+ cmpName = 'Schemas';
169
+ cmpDescription = '';
170
+ break;
171
+
172
+ case 'responses':
173
+ cmpName = 'Responses';
174
+ cmpDescription = 'Describes responses from an API Operation, including design-time, static links to operations based on the response.';
175
+ break;
176
+
177
+ case 'parameters':
178
+ cmpName = 'Parameters';
179
+ cmpDescription = 'Describes operation parameters. A unique parameter is defined by a combination of a name and location.';
180
+ break;
181
+
182
+ case 'examples':
183
+ cmpName = 'Examples';
184
+ cmpDescription = 'List of Examples for operations, can be requests, responses and objects examples.';
185
+ break;
186
+
187
+ case 'requestBodies':
188
+ break;
189
+
190
+ case 'headers':
191
+ cmpName = 'Headers';
192
+ cmpDescription = 'Headers follows the structure of the Parameters but they are explicitly in "header"';
193
+ break;
194
+
195
+ case 'securitySchemes':
196
+ break;
197
+
198
+ case 'links':
199
+ cmpName = 'Links';
200
+ cmpDescription = 'Links represent a possible design-time link for a response. The presence of a link does not guarantee the caller\'s ability to successfully invoke it, rather it provides a known relationship and traversal mechanism between responses and other operations.';
201
+ break;
202
+
203
+ case 'callbacks':
204
+ cmpName = 'Callbacks'; // eslint-disable-next-line max-len
205
+
206
+ cmpDescription = 'A map of possible out-of band callbacks related to the parent operation. Each value in the map is a Path Item Object that describes a set of requests that may be initiated by the API provider and the expected responses. The key value used to identify the path item object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation.';
207
+ break;
208
+
209
+ default:
210
+ cmpName = component;
211
+ cmpDescription = component;
212
+ break;
213
+ }
214
+
215
+ if (cmpName) {
216
+ components.push({
217
+ show: true,
218
+ name: cmpName,
219
+ description: cmpDescription,
220
+ subComponents
221
+ });
222
+ }
223
+ }
224
+
225
+ return components;
226
+ }
227
+
228
+ function groupByTags(openApiSpec) {
229
+ const supportedMethods = ['get', 'put', 'post', 'delete', 'patch', 'head', 'options']; // this is also used for ordering endpoints by methods
230
+
231
+ const tags = openApiSpec.tags && Array.isArray(openApiSpec.tags) ? openApiSpec.tags.map(t => ({
232
+ show: true,
233
+ elementId: `tag--${t.name.replace(_commonUtils.invalidCharsRegEx, '-')}`,
234
+ name: t.name,
235
+ description: t.description || '',
236
+ headers: t.description ? getHeadersFromMarkdown(t.description) : [],
237
+ paths: [],
238
+ expanded: t['x-tag-expanded'] !== false
239
+ })) : [];
240
+ const pathsAndWebhooks = openApiSpec.paths || {};
241
+
242
+ if (openApiSpec.webhooks) {
243
+ for (const [key, value] of Object.entries(openApiSpec.webhooks)) {
244
+ value._type = 'webhook'; // eslint-disable-line no-underscore-dangle
245
+
246
+ pathsAndWebhooks[key] = value;
247
+ }
248
+ } // For each path find the tag and push it into the corresponding tag
249
+
250
+
251
+ for (const pathOrHookName in pathsAndWebhooks) {
252
+ const commonParams = pathsAndWebhooks[pathOrHookName].parameters;
253
+ const commonPathProp = {
254
+ servers: pathsAndWebhooks[pathOrHookName].servers || [],
255
+ parameters: pathsAndWebhooks[pathOrHookName].parameters || []
256
+ };
257
+ const isWebhook = pathsAndWebhooks[pathOrHookName]._type === 'webhook'; // eslint-disable-line no-underscore-dangle
258
+
259
+ supportedMethods.forEach(methodName => {
260
+ if (pathsAndWebhooks[pathOrHookName][methodName]) {
261
+ const pathOrHookObj = openApiSpec.paths[pathOrHookName][methodName]; // If path.methods are tagged, else generate it from path
262
+
263
+ const pathTags = Array.isArray(pathOrHookObj.tags) ? pathOrHookObj.tags : pathOrHookObj.tags && [pathOrHookObj.tags] || [];
264
+
265
+ if (pathTags.length === 0) {
266
+ pathTags.push('General ⦂');
267
+ }
268
+
269
+ pathTags.forEach(tag => {
270
+ let tagObj;
271
+ let specTagsItem;
272
+
273
+ if (openApiSpec.tags) {
274
+ specTagsItem = openApiSpec.tags.find(v => v.name.toLowerCase() === tag.toLowerCase());
275
+ }
276
+
277
+ tagObj = tags.find(v => v.name === tag);
278
+
279
+ if (!tagObj) {
280
+ tagObj = {
281
+ show: true,
282
+ elementId: `tag--${tag.replace(_commonUtils.invalidCharsRegEx, '-')}`,
283
+ name: tag,
284
+ description: specTagsItem && specTagsItem.description || '',
285
+ headers: specTagsItem && specTagsItem.description ? getHeadersFromMarkdown(specTagsItem.description) : [],
286
+ paths: [],
287
+ expanded: specTagsItem ? specTagsItem['x-tag-expanded'] !== false : true
288
+ };
289
+ tags.push(tagObj);
290
+ } // Generate a short summary which is broken
291
+
292
+
293
+ let shortSummary = (pathOrHookObj.summary || pathOrHookObj.description || `${methodName.toUpperCase()} ${pathOrHookName}`).trim();
294
+
295
+ if (shortSummary.length > 100) {
296
+ shortSummary = shortSummary.split(/[.|!|?]\s|[\r?\n]/)[0]; // take the first line (period or carriage return)
297
+ } // Merge Common Parameters with This methods parameters
298
+
299
+
300
+ let finalParameters = [];
301
+
302
+ if (commonParams) {
303
+ if (pathOrHookObj.parameters) {
304
+ finalParameters = commonParams.filter(commonParam => {
305
+ if (!pathOrHookObj.parameters.some(param => commonParam.name === param.name && commonParam.in === param.in)) {
306
+ return commonParam;
307
+ }
308
+
309
+ return undefined;
310
+ }).concat(pathOrHookObj.parameters);
311
+ } else {
312
+ finalParameters = commonParams.slice(0);
313
+ }
314
+ } else {
315
+ finalParameters = pathOrHookObj.parameters ? pathOrHookObj.parameters.slice(0) : [];
316
+ } // Remove bad callbacks
317
+
318
+
319
+ if (pathOrHookObj.callbacks) {
320
+ for (const [callbackName, callbackConfig] of Object.entries(pathOrHookObj.callbacks)) {
321
+ const originalCallbackEntries = Object.entries(callbackConfig);
322
+ const filteredCallbacks = originalCallbackEntries.filter(entry => typeof entry[1] === 'object') || [];
323
+ pathOrHookObj.callbacks[callbackName] = Object.fromEntries(filteredCallbacks);
324
+
325
+ if (filteredCallbacks.length !== originalCallbackEntries.length) {
326
+ console.warn(`OpenAPI Explorer: Invalid Callback found in ${callbackName}`); // eslint-disable-line no-console
327
+ }
328
+ }
329
+ } // Update Responses
330
+
331
+
332
+ tagObj.paths.push({
333
+ show: true,
334
+ expanded: false,
335
+ isWebhook,
336
+ expandedAtLeastOnce: false,
337
+ summary: pathOrHookObj.summary || '',
338
+ description: pathOrHookObj.description || '',
339
+ shortSummary,
340
+ method: methodName,
341
+ path: pathOrHookName,
342
+ operationId: pathOrHookObj.operationId,
343
+ elementId: `${methodName}-${pathOrHookName.replace(_commonUtils.invalidCharsRegEx, '-')}`,
344
+ servers: pathOrHookObj.servers ? commonPathProp.servers.concat(pathOrHookObj.servers) : commonPathProp.servers,
345
+ parameters: finalParameters,
346
+ requestBody: pathOrHookObj.requestBody,
347
+ responses: pathOrHookObj.responses,
348
+ callbacks: pathOrHookObj.callbacks,
349
+ deprecated: pathOrHookObj.deprecated,
350
+ security: pathOrHookObj.security,
351
+ // commonSummary: commonPathProp.summary,
352
+ // commonDescription: commonPathProp.description,
353
+ xCodeSamples: pathOrHookObj['x-codeSamples'] || pathOrHookObj['x-code-samples'] || ''
354
+ });
355
+ }); // End of tag path create
356
+ }
357
+ }); // End of Methods
358
+ }
359
+
360
+ return tags.filter(tag => tag.paths && tag.paths.length > 0);
361
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = setTheme;
5
+
6
+ var _litElement = require("lit-element");
7
+
8
+ var _color = _interopRequireDefault(require("color"));
9
+
10
+ var _colorUtils = _interopRequireDefault(require("./color-utils"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ /* Generates an schema object containing type and constraint info */
15
+ // TODO: possible drive theme from:
16
+
17
+ /*
18
+ if (!this.theme || !'light, dark,'.includes(`${this.theme},`)) {
19
+ this.theme = (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) ? 'light' : 'dark';
20
+ }
21
+ */
22
+ function setTheme(theme = {}) {
23
+ const bg1 = theme.bg1 ? theme.bg1 : '#ffffff';
24
+ const fg1 = theme.fg1 ? theme.fg1 : '#444444';
25
+ const bg2 = theme.bg2 ? theme.bg2 : _colorUtils.default.color.brightness(bg1, -5); // or '#fafafa'
26
+
27
+ const bg3 = theme.bg3 ? theme.bg3 : _colorUtils.default.color.brightness(bg1, -15); // or '#f6f6f6'
28
+
29
+ const lightBg = theme.bg3 ? theme.bg3 : _colorUtils.default.color.brightness(bg1, -45);
30
+ const fg2 = theme.fg2 ? theme.fg2 : _colorUtils.default.color.brightness(fg1, 17); // or '#555'
31
+
32
+ const fg3 = theme.fg3 ? theme.fg3 : _colorUtils.default.color.brightness(fg1, 30); // or #666
33
+
34
+ const lightFg = theme.fg3 ? theme.fg3 : _colorUtils.default.color.brightness(fg1, 70); // or #999
35
+
36
+ const inlineCodeFg = theme.inlineCodeFg ? theme.inlineCodeFg : 'brown';
37
+ const selectionBg = '#444';
38
+ const selectionFg = '#eee';
39
+ const headerColor = theme.headerColor ? theme.headerColor : _colorUtils.default.color.brightness(bg1, -180);
40
+ const navBgColor = theme.navBgColor ? theme.navBgColor : _colorUtils.default.color.brightness(bg1, -180);
41
+ const navTextColor = theme.navTextColor ? theme.navTextColor : _colorUtils.default.color.opacity(_colorUtils.default.color.invert(navBgColor), '0.65');
42
+ const navHoverBgColor = theme.navHoverBgColor ? theme.navHoverBgColor : _colorUtils.default.color.brightness(navBgColor, -15);
43
+ const navHoverTextColor = theme.navHoverTextColor ? theme.navHoverTextColor : _colorUtils.default.color.invert(navBgColor);
44
+ const overlayBg = 'rgba(0, 0, 0, 0.4)';
45
+ const defaultColors = [`--purple: ${getComputedStyle(this).getPropertyValue('--purple').trim() || '#6f42c1'}`, `--red: ${getComputedStyle(this).getPropertyValue('--red').trim() || '#dc3545'}`, `--orange: ${getComputedStyle(this).getPropertyValue('--orange').trim() || '#fd7e14'}`, `--yellow: ${getComputedStyle(this).getPropertyValue('--yellow').trim() || '#ffc107'}`, `--green: ${getComputedStyle(this).getPropertyValue('--green').trim() || '#28a745'}`, `--blue: ${getComputedStyle(this).getPropertyValue('--blue').trim() || '#38b3f9'}`, '--pink: #e83e8c', '--white: #fff', ''];
46
+ const lightColors = [`--light-purple: ${(0, _color.default)(getComputedStyle(this).getPropertyValue('--purple').trim() || '#6f42c1').lightness(96).hex()}`, `--light-red: ${(0, _color.default)(getComputedStyle(this).getPropertyValue('--red').trim() || '#dc3545').lightness(96).hex()}`, `--light-orange: ${(0, _color.default)(getComputedStyle(this).getPropertyValue('--orange').trim() || '#fd7e14').lightness(96).hex()}`, `--light-yellow: ${(0, _color.default)(getComputedStyle(this).getPropertyValue('--yellow').trim() || '#ffc107').lightness(96).hex()}`, `--light-green: ${(0, _color.default)(getComputedStyle(this).getPropertyValue('--green').trim() || '#28a745').lightness(96).hex()}`, `--light-blue: ${(0, _color.default)(getComputedStyle(this).getPropertyValue('--blue').trim() || '#38b3f9').lightness(96).hex()}`, ''];
47
+ const newTheme = {
48
+ bg1,
49
+ bg2,
50
+ bg3,
51
+ lightBg,
52
+ fg1,
53
+ fg2,
54
+ fg3,
55
+ lightFg,
56
+ inlineCodeFg,
57
+ selectionBg,
58
+ selectionFg,
59
+ overlayBg,
60
+ navBgColor,
61
+ navTextColor,
62
+ navHoverBgColor,
63
+ navHoverTextColor,
64
+ headerColor,
65
+ headerColorInvert: _colorUtils.default.color.invert(headerColor),
66
+ headerColorDarker: _colorUtils.default.color.brightness(headerColor, -20),
67
+ headerColorBorder: _colorUtils.default.color.brightness(headerColor, 10),
68
+ borderColor: theme.borderColor || _colorUtils.default.color.brightness(bg1, -38),
69
+ lightBorderColor: theme.lightBorderColor || _colorUtils.default.color.brightness(bg1, -23),
70
+ codeBorderColor: theme.codeBorderColor || 'transparent',
71
+ inputBg: theme.inputBg || _colorUtils.default.color.brightness(bg1, 10),
72
+ // #fff
73
+ placeHolder: theme.placeHolder || _colorUtils.default.color.brightness(lightFg, 20),
74
+ // #dedede
75
+ hoverColor: theme.hoverColor || _colorUtils.default.color.brightness(bg1, -5),
76
+ // # f1f1f1
77
+ codeBg: theme.codeBg || _colorUtils.default.color.opacity(_colorUtils.default.color.brightness(bg1, -15), 0.7),
78
+ codeFg: theme.codeFg || '#666',
79
+ codePropertyColor: theme.codePropertyColor || '#905',
80
+ codeKeywordColor: theme.codeKeywordColor || '#07a',
81
+ codeOperatorColor: theme.codeOperatorColor || '#9a6e3a'
82
+ };
83
+ return (0, _litElement.html)` <style>*,:after,:before{box-sizing:border-box}:host{--border-radius:2px;--layout:${this.layout || 'column'};--nav-item-padding:${this.navItemSpacing === 'relaxed' ? '10px' : this.navItemSpacing === 'compact' ? '5px 10px' : '7px 10px'};--resp-area-height:${this.responseAreaHeight};--font-size-small:${this.fontSize === 'default' ? '12px' : this.fontSize === 'large' ? '13px' : '14px'};--font-size-mono:${this.fontSize === 'default' ? '13px' : this.fontSize === 'large' ? '14px' : '15px'};--font-size-regular:${this.fontSize === 'default' ? '14px' : this.fontSize === 'large' ? '15px' : '16px'};--dialog-z-index:1000;--bg:${newTheme.bg1};--bg2:${newTheme.bg2};--bg3:${newTheme.bg3};--light-bg:${newTheme.lightBg};--fg:${newTheme.fg1};--fg2:${newTheme.fg2};--fg3:${newTheme.fg3};--light-fg:${newTheme.lightFg};--selection-bg:${newTheme.selectionBg};--selection-fg:${newTheme.selectionFg};--overlay-bg:${newTheme.overlayBg};--border-color:${newTheme.borderColor};--light-border-color:${newTheme.lightBorderColor};--code-border-color:${newTheme.codeBorderColor};--input-bg:${newTheme.inputBg};--placeholder-color:${newTheme.placeHolder};--hover-color:${newTheme.hoverColor};${defaultColors.join(';\n')} ${lightColors.join(';\n')} --header-bg:${newTheme.headerColor};--header-fg:${newTheme.headerColorInvert};--header-color-darker:${newTheme.headerColorDarker};--header-color-border:${newTheme.headerColorBorder};--nav-bg-color:${newTheme.navBgColor};--nav-text-color:${newTheme.navTextColor};--nav-hover-bg-color:${newTheme.navHoverBgColor};--nav-hover-text-color:${newTheme.navHoverTextColor};--code-bg:${newTheme.codeBg};--code-fg:${newTheme.codeFg};--inline-code-fg:${newTheme.inlineCodeFg};--code-property-color:${newTheme.codePropertyColor};--code-keyword-color:${newTheme.codeKeywordColor};--code-operator-color:${newTheme.codeOperatorColor};--primary-color:${theme.primaryColor};--secondary-color:${theme.secondaryColor};--primary-btn-text-color:${_colorUtils.default.color.selectTextColorFromBackground(theme.primaryColor)}}</style>`;
84
+ }
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = xml;
5
+
6
+ /* eslint-disable no-underscore-dangle */
7
+ const XML_CHARACTER_MAP = {
8
+ '&': '&amp;',
9
+ '"': '&quot;',
10
+ "'": '&apos;',
11
+ '<': '&lt;',
12
+ '>': '&gt;'
13
+ };
14
+
15
+ function escapeForXML(string) {
16
+ return string && string.replace ? string.replace(/([&"<>'])/g, function (str, item) {
17
+ return XML_CHARACTER_MAP[item];
18
+ }) : string;
19
+ }
20
+
21
+ const DEFAULT_INDENT = ' ';
22
+
23
+ function xml(input, rawOptions) {
24
+ let options = rawOptions;
25
+
26
+ if (typeof options !== 'object') {
27
+ options = {
28
+ indent: options
29
+ };
30
+ }
31
+
32
+ let output = '';
33
+ const indent = !options.indent ? '' : options.indent === true ? DEFAULT_INDENT : options.indent;
34
+ let instant = true;
35
+
36
+ function delay(func) {
37
+ if (!instant) {
38
+ func();
39
+ } else {
40
+ process.nextTick(func);
41
+ }
42
+ }
43
+
44
+ function append(_, out) {
45
+ if (out !== undefined) {
46
+ output += out;
47
+ }
48
+ }
49
+
50
+ function add(value, last) {
51
+ format(append, resolve(value, indent, indent ? 1 : 0), last);
52
+ }
53
+
54
+ function addXmlDeclaration(declaration) {
55
+ const encoding = declaration.encoding || 'UTF-8';
56
+ const attr = {
57
+ version: '1.0',
58
+ encoding: encoding
59
+ };
60
+
61
+ if (declaration.standalone) {
62
+ attr.standalone = declaration.standalone;
63
+ }
64
+
65
+ add({
66
+ '?xml': {
67
+ _attr: attr
68
+ }
69
+ });
70
+ output = output.replace('/>', '?>');
71
+ } // disable delay delayed
72
+
73
+
74
+ delay(function () {
75
+ instant = false;
76
+ });
77
+
78
+ if (options.declaration) {
79
+ addXmlDeclaration(options.declaration);
80
+ }
81
+
82
+ if (input && input.forEach) {
83
+ input.forEach(function (value, i) {
84
+ add(value, i + 1 === input.length);
85
+ });
86
+ } else {
87
+ add(input, true);
88
+ }
89
+
90
+ return output;
91
+ }
92
+
93
+ function create_indent(character, count) {
94
+ return new Array(count || 0).join(character || '');
95
+ }
96
+
97
+ function resolve(data, indent, indent_count_raw) {
98
+ const indent_count = indent_count_raw || 0;
99
+ const indent_spaces = create_indent(indent, indent_count);
100
+ let name;
101
+ let values = data;
102
+ const interrupt = false;
103
+
104
+ if (typeof data === 'object') {
105
+ const keys = Object.keys(data);
106
+ name = keys[0];
107
+ values = data[name];
108
+
109
+ if (values && values._elem) {
110
+ values._elem.name = name;
111
+ values._elem.icount = indent_count;
112
+ values._elem.indent = indent;
113
+ values._elem.indents = indent_spaces;
114
+ values._elem.interrupt = values;
115
+ return values._elem;
116
+ }
117
+ }
118
+
119
+ const attributes = [];
120
+ const content = [];
121
+ let isStringContent;
122
+
123
+ function get_attributes(obj) {
124
+ const keys = Object.keys(obj);
125
+ keys.forEach(function (key) {
126
+ attributes.push(attribute(key, obj[key]));
127
+ });
128
+ }
129
+
130
+ switch (typeof values) {
131
+ case 'object':
132
+ if (values === null) {
133
+ break;
134
+ }
135
+
136
+ if (values._attr) {
137
+ get_attributes(values._attr);
138
+ }
139
+
140
+ if (values._cdata) {
141
+ content.push(`${`<![CDATA[${values._cdata}`.replace(/\]\]>/g, ']]]]><![CDATA[>')}]]>`);
142
+ }
143
+
144
+ if (values.forEach) {
145
+ isStringContent = false;
146
+ content.push('');
147
+ values.forEach(function (value) {
148
+ if (typeof value === 'object') {
149
+ const _name = Object.keys(value)[0];
150
+
151
+ if (_name === '_attr') {
152
+ get_attributes(value._attr);
153
+ } else {
154
+ content.push(resolve(value, indent, indent_count + 1));
155
+ }
156
+ } else {
157
+ // string
158
+ content.pop();
159
+ isStringContent = true;
160
+ content.push(escapeForXML(value));
161
+ }
162
+ });
163
+
164
+ if (!isStringContent) {
165
+ content.push('');
166
+ }
167
+ }
168
+
169
+ break;
170
+
171
+ default:
172
+ // string
173
+ content.push(escapeForXML(values));
174
+ }
175
+
176
+ return {
177
+ name: name,
178
+ interrupt: interrupt,
179
+ attributes: attributes,
180
+ content: content,
181
+ icount: indent_count,
182
+ indents: indent_spaces,
183
+ indent: indent
184
+ };
185
+ }
186
+
187
+ function format(append, elem, end) {
188
+ if (typeof elem !== 'object') {
189
+ append(false, elem);
190
+ return;
191
+ }
192
+
193
+ const len = elem.interrupt ? 1 : elem.content.length;
194
+
195
+ function proceed() {
196
+ while (elem.content.length) {
197
+ const value = elem.content.shift();
198
+
199
+ if (value === undefined) {
200
+ continue;
201
+ }
202
+
203
+ if (interrupt(value)) {
204
+ return;
205
+ }
206
+
207
+ format(append, value);
208
+ }
209
+
210
+ append(false, (len > 1 ? elem.indents : '') + (elem.name ? `</${elem.name}>` : '') + (elem.indent && !end ? '\n' : ''));
211
+ }
212
+
213
+ function interrupt(value) {
214
+ if (value.interrupt) {
215
+ value.interrupt.append = append;
216
+ value.interrupt.end = proceed;
217
+ value.interrupt = false;
218
+ append(true);
219
+ return true;
220
+ }
221
+
222
+ return false;
223
+ }
224
+
225
+ append(false, elem.indents + (elem.name ? `<${elem.name}` : '') + (elem.attributes.length ? ` ${elem.attributes.join(' ')}` : '') + (len ? elem.name ? '>' : '' : elem.name ? '/>' : '') + (elem.indent && len > 1 ? '\n' : ''));
226
+
227
+ if (!len) {
228
+ append(false, elem.indent ? '\n' : '');
229
+ return;
230
+ }
231
+
232
+ if (!interrupt(elem)) {
233
+ proceed();
234
+ }
235
+ }
236
+
237
+ function attribute(key, value) {
238
+ return `${key}=` + `"${escapeForXML(value)}"`;
239
+ }