@redocly/theme 0.1.2 → 0.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/Button/Button.d.ts +17 -0
- package/Button/Button.js +60 -0
- package/Button/index.d.ts +1 -0
- package/Button/index.js +17 -0
- package/CodeBlock/CodeBlock.d.ts +1 -0
- package/CodeBlock/CodeBlock.js +13 -0
- package/CodeBlock/index.d.ts +1 -0
- package/CodeBlock/index.js +17 -0
- package/CopyButton/CopyButton.d.ts +6 -0
- package/CopyButton/CopyButton.js +73 -0
- package/CopyButton/CopyButtonWrapper.d.ts +9 -0
- package/CopyButton/CopyButtonWrapper.js +40 -0
- package/CopyButton/index.d.ts +2 -0
- package/CopyButton/index.js +18 -0
- package/Headings/Headings.d.ts +3 -0
- package/Headings/Headings.js +16 -0
- package/Headings/index.d.ts +1 -0
- package/Headings/index.js +17 -0
- package/JsonViewer/JsonViewer.d.ts +10 -0
- package/JsonViewer/JsonViewer.js +98 -0
- package/JsonViewer/index.d.ts +1 -0
- package/JsonViewer/index.js +17 -0
- package/JsonViewer/styled.d.ts +1 -0
- package/JsonViewer/styled.js +10 -0
- package/Logo/Logo.d.ts +10 -0
- package/Logo/Logo.js +32 -0
- package/Navbar/Navbar.d.ts +9 -0
- package/Navbar/Navbar.js +30 -0
- package/Navbar/NavbarItem.d.ts +40 -0
- package/Navbar/NavbarItem.js +50 -0
- package/Navbar/NavbarMenu.d.ts +4 -0
- package/Navbar/NavbarMenu.js +35 -0
- package/Panel/CodePanel.d.ts +1 -0
- package/Panel/CodePanel.js +19 -0
- package/Panel/ContentPanel.d.ts +1 -0
- package/Panel/ContentPanel.js +18 -0
- package/Panel/DarkHeader.d.ts +1 -0
- package/Panel/DarkHeader.js +10 -0
- package/Panel/Panel.d.ts +2 -0
- package/Panel/Panel.js +16 -0
- package/Panel/PanelBody.d.ts +6 -0
- package/Panel/PanelBody.js +41 -0
- package/Panel/PanelComponent.d.ts +10 -0
- package/Panel/PanelComponent.js +47 -0
- package/Panel/PanelHeader.d.ts +7 -0
- package/Panel/PanelHeader.js +22 -0
- package/Panel/PanelHeaderTitle.d.ts +1 -0
- package/Panel/PanelHeaderTitle.js +13 -0
- package/Panel/index.d.ts +7 -0
- package/Panel/index.js +23 -0
- package/SamplesPanelControls/SamplesPanelControls.d.ts +4 -0
- package/SamplesPanelControls/SamplesPanelControls.js +23 -0
- package/SamplesPanelControls/index.d.ts +1 -0
- package/SamplesPanelControls/index.js +17 -0
- package/SidebarLogo/SidebarLogo.d.ts +9 -0
- package/SidebarLogo/SidebarLogo.js +36 -0
- package/SidebarLogo/index.d.ts +1 -0
- package/SidebarLogo/index.js +17 -0
- package/SourceCode/SourceCode.d.ts +24 -0
- package/SourceCode/SourceCode.js +36 -0
- package/SourceCode/index.d.ts +1 -0
- package/SourceCode/index.js +17 -0
- package/Tooltip/Tooltip.d.ts +12 -0
- package/Tooltip/Tooltip.js +84 -0
- package/Tooltip/index.d.ts +1 -0
- package/Tooltip/index.js +17 -0
- package/globalStyle.d.ts +1 -0
- package/globalStyle.js +10 -0
- package/hooks/index.d.ts +3 -0
- package/hooks/index.js +19 -0
- package/hooks/useControl.d.ts +6 -0
- package/hooks/useControl.js +16 -0
- package/hooks/useMount.d.ts +1 -0
- package/hooks/useMount.js +11 -0
- package/hooks/useUnmount.d.ts +1 -0
- package/hooks/useUnmount.js +13 -0
- package/icons/ShelfIcon/ShelfIcon.d.ts +10 -0
- package/icons/ShelfIcon/ShelfIcon.js +59 -0
- package/icons/ShelfIcon/index.d.ts +2 -0
- package/icons/ShelfIcon/index.js +5 -0
- package/icons/index.d.ts +1 -0
- package/icons/index.js +17 -0
- package/index.d.ts +14 -0
- package/index.js +30 -14
- package/mocks/Link.d.ts +2 -0
- package/mocks/Link.js +21 -0
- package/mocks/utils.d.ts +1 -0
- package/mocks/utils.js +7 -0
- package/package.json +2 -78
- package/src/Button/Button.stories.tsx +74 -0
- package/src/Button/Button.tsx +122 -0
- package/src/Button/__tests__/Button.test.tsx +42 -0
- package/src/Button/__tests__/__snapshots__/Button.test.tsx.snap +274 -0
- package/src/Button/index.ts +1 -0
- package/src/CodeBlock/CodeBlock.ts +125 -0
- package/src/CodeBlock/__tests__/CodeBlock.test.tsx +12 -0
- package/src/CodeBlock/__tests__/__snapshots__/CodeBlock.test.tsx.snap +140 -0
- package/src/CodeBlock/index.ts +1 -0
- package/src/CopyButton/CopyButton.stories.tsx +18 -0
- package/src/CopyButton/CopyButton.tsx +26 -0
- package/src/CopyButton/CopyButtonWrapper.tsx +52 -0
- package/src/CopyButton/__tests__/CopyButton.test.tsx +35 -0
- package/src/CopyButton/__tests__/CopyButtonWrapper.test.tsx +16 -0
- package/src/CopyButton/__tests__/__snapshots__/CopyButton.test.tsx.snap +55 -0
- package/src/CopyButton/__tests__/__snapshots__/CopyButtonWrapper.test.tsx.snap +46 -0
- package/src/CopyButton/index.ts +2 -0
- package/src/Headings/Headings.stories.tsx +36 -0
- package/src/Headings/Headings.ts +23 -0
- package/src/Headings/__tests__/Headings.test.tsx +24 -0
- package/src/Headings/__tests__/__snapshots__/Headings.test.tsx.snap +57 -0
- package/src/Headings/index.ts +1 -0
- package/src/Introduction.stories.mdx +7 -0
- package/src/JsonViewer/JsonViewer.stories.tsx +57 -0
- package/src/JsonViewer/JsonViewer.tsx +130 -0
- package/src/JsonViewer/__tests__/JsonViewer.test.tsx +82 -0
- package/src/JsonViewer/__tests__/__snapshots__/JsonViewer.test.tsx.snap +2728 -0
- package/src/JsonViewer/index.ts +1 -0
- package/src/JsonViewer/styled.ts +103 -0
- package/src/Logo/Logo.tsx +23 -0
- package/src/Navbar/Navbar.stories.tsx +38 -0
- package/src/Navbar/Navbar.tsx +60 -0
- package/src/Navbar/NavbarItem.tsx +90 -0
- package/src/Navbar/NavbarMenu.tsx +29 -0
- package/src/Panel/CodePanel.stories.tsx +27 -0
- package/src/Panel/CodePanel.ts +31 -0
- package/src/Panel/ContentPanel.stories.tsx +27 -0
- package/src/Panel/ContentPanel.ts +43 -0
- package/src/Panel/DarkHeader.ts +8 -0
- package/src/Panel/Panel.stories.tsx +58 -0
- package/src/Panel/Panel.ts +18 -0
- package/src/Panel/PanelBody.ts +30 -0
- package/src/Panel/PanelComponent.tsx +73 -0
- package/src/Panel/PanelHeader.ts +25 -0
- package/src/Panel/PanelHeaderTitle.ts +11 -0
- package/src/Panel/__tests__/CodePanel.test.tsx +26 -0
- package/src/Panel/__tests__/ContentPanel.test.tsx +26 -0
- package/src/Panel/__tests__/Panel.test.tsx +54 -0
- package/src/Panel/__tests__/__snapshots__/CodePanel.test.tsx.snap +258 -0
- package/src/Panel/__tests__/__snapshots__/ContentPanel.test.tsx.snap +278 -0
- package/src/Panel/__tests__/__snapshots__/Panel.test.tsx.snap +398 -0
- package/src/Panel/index.ts +7 -0
- package/src/SamplesPanelControls/SamplesControlButton.stories.tsx +18 -0
- package/src/SamplesPanelControls/SamplesPanelControls.ts +70 -0
- package/src/SamplesPanelControls/__tests__/SamplesPanelControls.test.tsx +36 -0
- package/src/SamplesPanelControls/__tests__/__snapshots__/SamplesPanelControls.test.tsx.snap +228 -0
- package/src/SamplesPanelControls/index.ts +1 -0
- package/src/SidebarLogo/SidebarLogo.stories.tsx +21 -0
- package/src/SidebarLogo/SidebarLogo.tsx +47 -0
- package/src/SidebarLogo/__tests__/SidebarLogo.test.tsx +32 -0
- package/src/SidebarLogo/__tests__/__snapshots__/SidebarLogo.test.tsx.snap +62 -0
- package/src/SidebarLogo/index.ts +1 -0
- package/src/SourceCode/SourceCode.stories.tsx +29 -0
- package/src/SourceCode/SourceCode.tsx +67 -0
- package/src/SourceCode/__tests__/SourceCode.test.tsx +47 -0
- package/src/SourceCode/__tests__/__snapshots__/SourceCode.test.tsx.snap +786 -0
- package/src/SourceCode/index.ts +1 -0
- package/src/Tooltip/Tooltip.stories.tsx +27 -0
- package/src/Tooltip/Tooltip.tsx +171 -0
- package/src/Tooltip/__tests__/Tooltip.test.tsx +41 -0
- package/src/Tooltip/__tests__/__snapshots__/Tooltip.test.tsx.snap +83 -0
- package/src/Tooltip/index.ts +1 -0
- package/src/globalStyle.ts +512 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useControl.ts +20 -0
- package/src/hooks/useMount.ts +8 -0
- package/src/hooks/useUnmount.ts +10 -0
- package/src/icons/ShelfIcon/ShelfIcon.stories.tsx +36 -0
- package/src/icons/ShelfIcon/ShelfIcon.tsx +45 -0
- package/src/icons/ShelfIcon/__tests__/ShelfIcon.test.tsx +54 -0
- package/src/icons/ShelfIcon/__tests__/__snapshots__/ShelfIcon.test.tsx.snap +235 -0
- package/src/icons/ShelfIcon/index.ts +2 -0
- package/src/icons/index.ts +1 -0
- package/src/index.ts +14 -0
- package/src/mocks/Link.tsx +7 -0
- package/src/mocks/utils.ts +3 -0
- package/src/utils/ClipboardService.ts +92 -0
- package/src/utils/__tests__/ClipboardService.test.ts +24 -0
- package/src/utils/__tests__/__snapshots__/highlight.test.ts.snap +5 -0
- package/src/utils/__tests__/__snapshots__/jsonToHtml.test.ts.snap +5 -0
- package/src/utils/__tests__/css-variables.test.ts +20 -0
- package/src/utils/__tests__/highlight.test.ts +51 -0
- package/src/utils/__tests__/jsonToHtml.test.ts +40 -0
- package/src/utils/__tests__/media-css.test.ts +20 -0
- package/src/utils/__tests__/theme-helpers.test.ts +25 -0
- package/src/utils/css-variables.ts +2 -0
- package/src/utils/highlight.ts +81 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/jsonToHtml.ts +122 -0
- package/src/utils/media-css.ts +16 -0
- package/src/utils/theme-helpers.ts +34 -0
- package/utils/ClipboardService.d.ts +8 -0
- package/utils/ClipboardService.js +86 -0
- package/utils/css-variables.d.ts +1 -0
- package/utils/css-variables.js +8 -0
- package/utils/highlight.d.ts +32 -0
- package/utils/highlight.js +93 -0
- package/utils/index.d.ts +6 -0
- package/utils/index.js +22 -0
- package/utils/jsonToHtml.d.ts +1 -0
- package/utils/jsonToHtml.js +120 -0
- package/utils/media-css.d.ts +12 -0
- package/utils/media-css.js +13 -0
- package/utils/theme-helpers.d.ts +3 -0
- package/utils/theme-helpers.js +32 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as Prism from 'prismjs';
|
|
2
|
+
import 'prismjs/components/prism-bash.js';
|
|
3
|
+
import 'prismjs/components/prism-c.js';
|
|
4
|
+
import 'prismjs/components/prism-clike.js';
|
|
5
|
+
import 'prismjs/components/prism-coffeescript.js';
|
|
6
|
+
import 'prismjs/components/prism-cpp.js';
|
|
7
|
+
import 'prismjs/components/prism-csharp.js';
|
|
8
|
+
import 'prismjs/components/prism-go.js';
|
|
9
|
+
import 'prismjs/components/prism-http.js';
|
|
10
|
+
import 'prismjs/components/prism-java.js';
|
|
11
|
+
import 'prismjs/components/prism-lua.js';
|
|
12
|
+
import 'prismjs/components/prism-markup-templating.js'; // dep of php
|
|
13
|
+
import 'prismjs/components/prism-markup.js'; // xml
|
|
14
|
+
import 'prismjs/components/prism-objectivec.js';
|
|
15
|
+
import 'prismjs/components/prism-perl.js';
|
|
16
|
+
import 'prismjs/components/prism-php.js';
|
|
17
|
+
import 'prismjs/components/prism-python.js';
|
|
18
|
+
import 'prismjs/components/prism-ruby.js';
|
|
19
|
+
import 'prismjs/components/prism-scala.js';
|
|
20
|
+
import 'prismjs/components/prism-sql.js';
|
|
21
|
+
import 'prismjs/components/prism-swift.js';
|
|
22
|
+
import 'prismjs/components/prism-graphql.js';
|
|
23
|
+
|
|
24
|
+
const DEFAULT_LANG = 'clike';
|
|
25
|
+
|
|
26
|
+
Prism.languages.insertBefore(
|
|
27
|
+
'javascript',
|
|
28
|
+
'string',
|
|
29
|
+
{
|
|
30
|
+
'property string': {
|
|
31
|
+
pattern: /([{,]\s*)"(?:\\.|[^\\"\r\n])*"(?=\s*:)/i,
|
|
32
|
+
lookbehind: true,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
undefined,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
Prism.languages.insertBefore(
|
|
39
|
+
'javascript',
|
|
40
|
+
'punctuation',
|
|
41
|
+
{
|
|
42
|
+
property: {
|
|
43
|
+
pattern: /([{,]\s*)[a-z]\w*(?=\s*:)/i,
|
|
44
|
+
lookbehind: true,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
undefined,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* map language names to Prism.js names
|
|
52
|
+
*/
|
|
53
|
+
export function mapLang(lang: string): string {
|
|
54
|
+
return (
|
|
55
|
+
{
|
|
56
|
+
json: 'js',
|
|
57
|
+
'c++': 'cpp',
|
|
58
|
+
'c#': 'csharp',
|
|
59
|
+
'objective-c': 'objectivec',
|
|
60
|
+
shell: 'bash',
|
|
61
|
+
viml: 'vim',
|
|
62
|
+
curl: 'bash',
|
|
63
|
+
'node.js': 'js',
|
|
64
|
+
}[lang] || DEFAULT_LANG
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Highlight source code string using Prism.js
|
|
70
|
+
* @param source source code to highlight
|
|
71
|
+
* @param lang highlight language
|
|
72
|
+
* @return highlighted source code as **html string**
|
|
73
|
+
*/
|
|
74
|
+
export function highlight(source: string | number | boolean, lang: string = DEFAULT_LANG): string {
|
|
75
|
+
lang = lang.toLowerCase();
|
|
76
|
+
let grammar = Prism.languages[lang];
|
|
77
|
+
if (!grammar) {
|
|
78
|
+
grammar = Prism.languages[mapLang(lang)];
|
|
79
|
+
}
|
|
80
|
+
return Prism.highlight(source.toString(), grammar, lang);
|
|
81
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Moved from reference-docs
|
|
2
|
+
let level = 1;
|
|
3
|
+
|
|
4
|
+
export function jsonToHTML(json: JSON | Record<string, unknown>, maxExpandLevel: number): string {
|
|
5
|
+
level = 1;
|
|
6
|
+
let output = '';
|
|
7
|
+
output += '<div data-cy="json-sample" class="redoc-json">';
|
|
8
|
+
output += '<code>';
|
|
9
|
+
output += valueToHTML(json, maxExpandLevel);
|
|
10
|
+
output += '</code>';
|
|
11
|
+
output += '</div>';
|
|
12
|
+
return output;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function htmlEncode(t: any) {
|
|
16
|
+
return t !== undefined
|
|
17
|
+
? t
|
|
18
|
+
.toString()
|
|
19
|
+
.replace(/&/g, '&')
|
|
20
|
+
.replace(/"/g, '"')
|
|
21
|
+
.replace(/</g, '<')
|
|
22
|
+
.replace(/>/g, '>')
|
|
23
|
+
: '';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function stringifyStringLiteral(str: string) {
|
|
27
|
+
return JSON.stringify(str).slice(1, -1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function decorateWithSpan(value: any, className: string) {
|
|
31
|
+
return '<span class="' + className + '">' + htmlEncode(value) + '</span>';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function punctuation(val: any) {
|
|
35
|
+
return '<span class="token punctuation">' + val + '</span>';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function valueToHTML(value: any, maxExpandLevel: number) {
|
|
39
|
+
const valueType = typeof value;
|
|
40
|
+
let output = '';
|
|
41
|
+
if (value === undefined || value === null) {
|
|
42
|
+
output += decorateWithSpan('null', 'token keyword');
|
|
43
|
+
} else if (value && value.constructor === Array) {
|
|
44
|
+
level++;
|
|
45
|
+
output += arrayToHTML(value, maxExpandLevel);
|
|
46
|
+
level--;
|
|
47
|
+
} else if (value && value.constructor === Date) {
|
|
48
|
+
output += decorateWithSpan('"' + value.toISOString() + '"', 'token string');
|
|
49
|
+
} else if (valueType === 'object') {
|
|
50
|
+
level++;
|
|
51
|
+
output += objectToHTML(value, maxExpandLevel);
|
|
52
|
+
level--;
|
|
53
|
+
} else if (valueType === 'number') {
|
|
54
|
+
output += decorateWithSpan(value, 'token number');
|
|
55
|
+
} else if (valueType === 'string') {
|
|
56
|
+
if (/^(http|https):\/\/[^\s]+$/.test(value)) {
|
|
57
|
+
output +=
|
|
58
|
+
decorateWithSpan('"', 'token string') +
|
|
59
|
+
'<a href="' +
|
|
60
|
+
encodeURI(value) +
|
|
61
|
+
'">' +
|
|
62
|
+
htmlEncode(stringifyStringLiteral(value)) +
|
|
63
|
+
'</a>' +
|
|
64
|
+
decorateWithSpan('"', 'token string');
|
|
65
|
+
} else {
|
|
66
|
+
output += decorateWithSpan('"' + stringifyStringLiteral(value) + '"', 'token string');
|
|
67
|
+
}
|
|
68
|
+
} else if (valueType === 'boolean') {
|
|
69
|
+
output += decorateWithSpan(value, 'token boolean');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return output;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function arrayToHTML(json: any, maxExpandLevel: number) {
|
|
76
|
+
const collapsed = level > maxExpandLevel ? 'collapsed' : '';
|
|
77
|
+
let output = `<button class="collapser" aria-label="${
|
|
78
|
+
level > maxExpandLevel + 1 ? 'expand' : 'collapse'
|
|
79
|
+
}"></button>${punctuation('[')}<span class="ellipsis"></span><ul class="array collapsible">`;
|
|
80
|
+
let hasContents = false;
|
|
81
|
+
const length = json.length;
|
|
82
|
+
for (let i = 0; i < length; i++) {
|
|
83
|
+
hasContents = true;
|
|
84
|
+
output += '<li><div class="hoverable ' + collapsed + '">';
|
|
85
|
+
output += valueToHTML(json[i], maxExpandLevel);
|
|
86
|
+
if (i < length - 1) {
|
|
87
|
+
output += ',';
|
|
88
|
+
}
|
|
89
|
+
output += '</div></li>';
|
|
90
|
+
}
|
|
91
|
+
output += `</ul>${punctuation(']')}`;
|
|
92
|
+
if (!hasContents) {
|
|
93
|
+
output = punctuation('[ ]');
|
|
94
|
+
}
|
|
95
|
+
return output;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function objectToHTML(json: any, maxExpandLevel: number) {
|
|
99
|
+
const collapsed = level > maxExpandLevel ? 'collapsed' : '';
|
|
100
|
+
const keys = Object.keys(json);
|
|
101
|
+
const length = keys.length;
|
|
102
|
+
let output = `<button class="collapser" aria-label="${
|
|
103
|
+
level > maxExpandLevel + 1 ? 'expand' : 'collapse'
|
|
104
|
+
}"></button>${punctuation('{')}<span class="ellipsis"></span><ul class="obj collapsible">`;
|
|
105
|
+
let hasContents = false;
|
|
106
|
+
for (let i = 0; i < length; i++) {
|
|
107
|
+
const key = keys[i];
|
|
108
|
+
hasContents = true;
|
|
109
|
+
output += '<li><div class="hoverable ' + collapsed + '">';
|
|
110
|
+
output += '<span class="property token string">"' + htmlEncode(key) + '"</span>: ';
|
|
111
|
+
output += valueToHTML(json[key], maxExpandLevel);
|
|
112
|
+
if (i < length - 1) {
|
|
113
|
+
output += punctuation(',');
|
|
114
|
+
}
|
|
115
|
+
output += '</div></li>';
|
|
116
|
+
}
|
|
117
|
+
output += `</ul>${punctuation('}')}`;
|
|
118
|
+
if (!hasContents) {
|
|
119
|
+
output = punctuation('{ }');
|
|
120
|
+
}
|
|
121
|
+
return output;
|
|
122
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type MediaQueries = {
|
|
2
|
+
print: string;
|
|
3
|
+
small: string;
|
|
4
|
+
medium: string;
|
|
5
|
+
large: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const breakpoints = { small: '50rem', medium: '85rem', large: '105rem' };
|
|
9
|
+
|
|
10
|
+
export function generateMediaQueries(breakpoints: Omit<MediaQueries, 'print'>): MediaQueries {
|
|
11
|
+
const result = <Record<string, string>>{ print: '@media print' };
|
|
12
|
+
for (const [key, value] of Object.entries(breakpoints)) {
|
|
13
|
+
result[key] = `@media screen and (min-width: ${value})`;
|
|
14
|
+
}
|
|
15
|
+
return result as MediaQueries;
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FlattenSimpleInterpolation } from 'styled-components';
|
|
2
|
+
import { css } from 'styled-components';
|
|
3
|
+
|
|
4
|
+
const typographyProperties = Object.entries({
|
|
5
|
+
fontSize: 'font-size',
|
|
6
|
+
fontWeight: 'font-weight',
|
|
7
|
+
fontFamily: 'font-family',
|
|
8
|
+
lineHeight: 'line-height',
|
|
9
|
+
color: 'color',
|
|
10
|
+
textTransform: 'text-transform',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export function getTypographyCssRulesByComponentName(
|
|
14
|
+
componentName: string,
|
|
15
|
+
fallbackName?: string,
|
|
16
|
+
): Record<string, string> {
|
|
17
|
+
const result = {} as Record<string, string>;
|
|
18
|
+
for (const [styledPropertyName, cssPropertyName] of typographyProperties) {
|
|
19
|
+
const cssVariable = `--${componentName}-${cssPropertyName}`;
|
|
20
|
+
const fallbackVariable = fallbackName ? `,var(--${fallbackName}-${cssPropertyName})` : '';
|
|
21
|
+
|
|
22
|
+
result[styledPropertyName] = `var(${cssVariable}${fallbackVariable})`;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function typography(
|
|
28
|
+
componentName: string,
|
|
29
|
+
fallbackName?: string,
|
|
30
|
+
): FlattenSimpleInterpolation {
|
|
31
|
+
return css`
|
|
32
|
+
${getTypographyCssRulesByComponentName(componentName, fallbackName)}
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class ClipboardService {
|
|
2
|
+
static isSupported(): boolean;
|
|
3
|
+
static selectElement(element: HTMLDivElement | null): void;
|
|
4
|
+
static deselect(): void;
|
|
5
|
+
static copySelected(): boolean;
|
|
6
|
+
static copyElement(element: HTMLDivElement | null): boolean;
|
|
7
|
+
static copyCustom(text: string): boolean;
|
|
8
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClipboardService = void 0;
|
|
4
|
+
var ClipboardService = /** @class */ (function () {
|
|
5
|
+
function ClipboardService() {
|
|
6
|
+
}
|
|
7
|
+
ClipboardService.isSupported = function () {
|
|
8
|
+
return (typeof document !== 'undefined' &&
|
|
9
|
+
!!document.queryCommandSupported &&
|
|
10
|
+
document.queryCommandSupported('copy'));
|
|
11
|
+
};
|
|
12
|
+
ClipboardService.selectElement = function (element) {
|
|
13
|
+
if (!element) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
var range;
|
|
17
|
+
var selection;
|
|
18
|
+
if (document.body.createTextRange) {
|
|
19
|
+
range = document.body.createTextRange();
|
|
20
|
+
range.moveToElementText(element);
|
|
21
|
+
range.select();
|
|
22
|
+
}
|
|
23
|
+
else if (document.createRange && window.getSelection) {
|
|
24
|
+
selection = window.getSelection();
|
|
25
|
+
range = document.createRange();
|
|
26
|
+
range.selectNodeContents(element);
|
|
27
|
+
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
28
|
+
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
ClipboardService.deselect = function () {
|
|
32
|
+
if (document.selection) {
|
|
33
|
+
document.selection.empty();
|
|
34
|
+
}
|
|
35
|
+
else if (window.getSelection) {
|
|
36
|
+
var selection = window.getSelection();
|
|
37
|
+
if (selection) {
|
|
38
|
+
selection.removeAllRanges();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
ClipboardService.copySelected = function () {
|
|
43
|
+
var result;
|
|
44
|
+
try {
|
|
45
|
+
result = document.execCommand('copy');
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
result = false;
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
ClipboardService.copyElement = function (element) {
|
|
53
|
+
ClipboardService.selectElement(element);
|
|
54
|
+
var res = ClipboardService.copySelected();
|
|
55
|
+
if (res) {
|
|
56
|
+
ClipboardService.deselect();
|
|
57
|
+
}
|
|
58
|
+
return res;
|
|
59
|
+
};
|
|
60
|
+
ClipboardService.copyCustom = function (text) {
|
|
61
|
+
var textArea = document.createElement('textarea');
|
|
62
|
+
textArea.style.position = 'fixed';
|
|
63
|
+
textArea.style.top = '0';
|
|
64
|
+
textArea.style.left = '0';
|
|
65
|
+
// Ensure it has a small width and height. Setting to 1px / 1em
|
|
66
|
+
// doesn't work as this gives a negative w/h on some browsers.
|
|
67
|
+
textArea.style.width = '2em';
|
|
68
|
+
textArea.style.height = '2em';
|
|
69
|
+
// We don't need padding, reducing the size if it does flash render.
|
|
70
|
+
textArea.style.padding = '0';
|
|
71
|
+
// Clean up any borders.
|
|
72
|
+
textArea.style.border = 'none';
|
|
73
|
+
textArea.style.outline = 'none';
|
|
74
|
+
textArea.style.boxShadow = 'none';
|
|
75
|
+
// Avoid flash of white box if rendered for any reason.
|
|
76
|
+
textArea.style.background = 'transparent';
|
|
77
|
+
textArea.value = text;
|
|
78
|
+
document.body.appendChild(textArea);
|
|
79
|
+
textArea.select();
|
|
80
|
+
var res = ClipboardService.copySelected();
|
|
81
|
+
document.body.removeChild(textArea);
|
|
82
|
+
return res;
|
|
83
|
+
};
|
|
84
|
+
return ClipboardService;
|
|
85
|
+
}());
|
|
86
|
+
exports.ClipboardService = ClipboardService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getCssColorVariable: (color: string | undefined, defaultValue?: string) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCssColorVariable = void 0;
|
|
4
|
+
var getCssColorVariable = function (color, defaultValue) {
|
|
5
|
+
if (defaultValue === void 0) { defaultValue = 'inherit'; }
|
|
6
|
+
return (color === null || color === void 0 ? void 0 : color.startsWith('--')) ? "var(".concat(color, ")") : color || defaultValue;
|
|
7
|
+
};
|
|
8
|
+
exports.getCssColorVariable = getCssColorVariable;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import 'prismjs/components/prism-bash.js';
|
|
2
|
+
import 'prismjs/components/prism-c.js';
|
|
3
|
+
import 'prismjs/components/prism-clike.js';
|
|
4
|
+
import 'prismjs/components/prism-coffeescript.js';
|
|
5
|
+
import 'prismjs/components/prism-cpp.js';
|
|
6
|
+
import 'prismjs/components/prism-csharp.js';
|
|
7
|
+
import 'prismjs/components/prism-go.js';
|
|
8
|
+
import 'prismjs/components/prism-http.js';
|
|
9
|
+
import 'prismjs/components/prism-java.js';
|
|
10
|
+
import 'prismjs/components/prism-lua.js';
|
|
11
|
+
import 'prismjs/components/prism-markup-templating.js';
|
|
12
|
+
import 'prismjs/components/prism-markup.js';
|
|
13
|
+
import 'prismjs/components/prism-objectivec.js';
|
|
14
|
+
import 'prismjs/components/prism-perl.js';
|
|
15
|
+
import 'prismjs/components/prism-php.js';
|
|
16
|
+
import 'prismjs/components/prism-python.js';
|
|
17
|
+
import 'prismjs/components/prism-ruby.js';
|
|
18
|
+
import 'prismjs/components/prism-scala.js';
|
|
19
|
+
import 'prismjs/components/prism-sql.js';
|
|
20
|
+
import 'prismjs/components/prism-swift.js';
|
|
21
|
+
import 'prismjs/components/prism-graphql.js';
|
|
22
|
+
/**
|
|
23
|
+
* map language names to Prism.js names
|
|
24
|
+
*/
|
|
25
|
+
export declare function mapLang(lang: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Highlight source code string using Prism.js
|
|
28
|
+
* @param source source code to highlight
|
|
29
|
+
* @param lang highlight language
|
|
30
|
+
* @return highlighted source code as **html string**
|
|
31
|
+
*/
|
|
32
|
+
export declare function highlight(source: string | number | boolean, lang?: string): string;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.highlight = exports.mapLang = void 0;
|
|
27
|
+
var Prism = __importStar(require("prismjs"));
|
|
28
|
+
require("prismjs/components/prism-bash.js");
|
|
29
|
+
require("prismjs/components/prism-c.js");
|
|
30
|
+
require("prismjs/components/prism-clike.js");
|
|
31
|
+
require("prismjs/components/prism-coffeescript.js");
|
|
32
|
+
require("prismjs/components/prism-cpp.js");
|
|
33
|
+
require("prismjs/components/prism-csharp.js");
|
|
34
|
+
require("prismjs/components/prism-go.js");
|
|
35
|
+
require("prismjs/components/prism-http.js");
|
|
36
|
+
require("prismjs/components/prism-java.js");
|
|
37
|
+
require("prismjs/components/prism-lua.js");
|
|
38
|
+
require("prismjs/components/prism-markup-templating.js"); // dep of php
|
|
39
|
+
require("prismjs/components/prism-markup.js"); // xml
|
|
40
|
+
require("prismjs/components/prism-objectivec.js");
|
|
41
|
+
require("prismjs/components/prism-perl.js");
|
|
42
|
+
require("prismjs/components/prism-php.js");
|
|
43
|
+
require("prismjs/components/prism-python.js");
|
|
44
|
+
require("prismjs/components/prism-ruby.js");
|
|
45
|
+
require("prismjs/components/prism-scala.js");
|
|
46
|
+
require("prismjs/components/prism-sql.js");
|
|
47
|
+
require("prismjs/components/prism-swift.js");
|
|
48
|
+
require("prismjs/components/prism-graphql.js");
|
|
49
|
+
var DEFAULT_LANG = 'clike';
|
|
50
|
+
Prism.languages.insertBefore('javascript', 'string', {
|
|
51
|
+
'property string': {
|
|
52
|
+
pattern: /([{,]\s*)"(?:\\.|[^\\"\r\n])*"(?=\s*:)/i,
|
|
53
|
+
lookbehind: true,
|
|
54
|
+
},
|
|
55
|
+
}, undefined);
|
|
56
|
+
Prism.languages.insertBefore('javascript', 'punctuation', {
|
|
57
|
+
property: {
|
|
58
|
+
pattern: /([{,]\s*)[a-z]\w*(?=\s*:)/i,
|
|
59
|
+
lookbehind: true,
|
|
60
|
+
},
|
|
61
|
+
}, undefined);
|
|
62
|
+
/**
|
|
63
|
+
* map language names to Prism.js names
|
|
64
|
+
*/
|
|
65
|
+
function mapLang(lang) {
|
|
66
|
+
return ({
|
|
67
|
+
json: 'js',
|
|
68
|
+
'c++': 'cpp',
|
|
69
|
+
'c#': 'csharp',
|
|
70
|
+
'objective-c': 'objectivec',
|
|
71
|
+
shell: 'bash',
|
|
72
|
+
viml: 'vim',
|
|
73
|
+
curl: 'bash',
|
|
74
|
+
'node.js': 'js',
|
|
75
|
+
}[lang] || DEFAULT_LANG);
|
|
76
|
+
}
|
|
77
|
+
exports.mapLang = mapLang;
|
|
78
|
+
/**
|
|
79
|
+
* Highlight source code string using Prism.js
|
|
80
|
+
* @param source source code to highlight
|
|
81
|
+
* @param lang highlight language
|
|
82
|
+
* @return highlighted source code as **html string**
|
|
83
|
+
*/
|
|
84
|
+
function highlight(source, lang) {
|
|
85
|
+
if (lang === void 0) { lang = DEFAULT_LANG; }
|
|
86
|
+
lang = lang.toLowerCase();
|
|
87
|
+
var grammar = Prism.languages[lang];
|
|
88
|
+
if (!grammar) {
|
|
89
|
+
grammar = Prism.languages[mapLang(lang)];
|
|
90
|
+
}
|
|
91
|
+
return Prism.highlight(source.toString(), grammar, lang);
|
|
92
|
+
}
|
|
93
|
+
exports.highlight = highlight;
|
package/utils/index.d.ts
ADDED
package/utils/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ClipboardService"), exports);
|
|
18
|
+
__exportStar(require("./css-variables"), exports);
|
|
19
|
+
__exportStar(require("./highlight"), exports);
|
|
20
|
+
__exportStar(require("./jsonToHtml"), exports);
|
|
21
|
+
__exportStar(require("./media-css"), exports);
|
|
22
|
+
__exportStar(require("./theme-helpers"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function jsonToHTML(json: JSON | Record<string, unknown>, maxExpandLevel: number): string;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsonToHTML = void 0;
|
|
4
|
+
// Moved from reference-docs
|
|
5
|
+
var level = 1;
|
|
6
|
+
function jsonToHTML(json, maxExpandLevel) {
|
|
7
|
+
level = 1;
|
|
8
|
+
var output = '';
|
|
9
|
+
output += '<div data-cy="json-sample" class="redoc-json">';
|
|
10
|
+
output += '<code>';
|
|
11
|
+
output += valueToHTML(json, maxExpandLevel);
|
|
12
|
+
output += '</code>';
|
|
13
|
+
output += '</div>';
|
|
14
|
+
return output;
|
|
15
|
+
}
|
|
16
|
+
exports.jsonToHTML = jsonToHTML;
|
|
17
|
+
function htmlEncode(t) {
|
|
18
|
+
return t !== undefined
|
|
19
|
+
? t
|
|
20
|
+
.toString()
|
|
21
|
+
.replace(/&/g, '&')
|
|
22
|
+
.replace(/"/g, '"')
|
|
23
|
+
.replace(/</g, '<')
|
|
24
|
+
.replace(/>/g, '>')
|
|
25
|
+
: '';
|
|
26
|
+
}
|
|
27
|
+
function stringifyStringLiteral(str) {
|
|
28
|
+
return JSON.stringify(str).slice(1, -1);
|
|
29
|
+
}
|
|
30
|
+
function decorateWithSpan(value, className) {
|
|
31
|
+
return '<span class="' + className + '">' + htmlEncode(value) + '</span>';
|
|
32
|
+
}
|
|
33
|
+
function punctuation(val) {
|
|
34
|
+
return '<span class="token punctuation">' + val + '</span>';
|
|
35
|
+
}
|
|
36
|
+
function valueToHTML(value, maxExpandLevel) {
|
|
37
|
+
var valueType = typeof value;
|
|
38
|
+
var output = '';
|
|
39
|
+
if (value === undefined || value === null) {
|
|
40
|
+
output += decorateWithSpan('null', 'token keyword');
|
|
41
|
+
}
|
|
42
|
+
else if (value && value.constructor === Array) {
|
|
43
|
+
level++;
|
|
44
|
+
output += arrayToHTML(value, maxExpandLevel);
|
|
45
|
+
level--;
|
|
46
|
+
}
|
|
47
|
+
else if (value && value.constructor === Date) {
|
|
48
|
+
output += decorateWithSpan('"' + value.toISOString() + '"', 'token string');
|
|
49
|
+
}
|
|
50
|
+
else if (valueType === 'object') {
|
|
51
|
+
level++;
|
|
52
|
+
output += objectToHTML(value, maxExpandLevel);
|
|
53
|
+
level--;
|
|
54
|
+
}
|
|
55
|
+
else if (valueType === 'number') {
|
|
56
|
+
output += decorateWithSpan(value, 'token number');
|
|
57
|
+
}
|
|
58
|
+
else if (valueType === 'string') {
|
|
59
|
+
if (/^(http|https):\/\/[^\s]+$/.test(value)) {
|
|
60
|
+
output +=
|
|
61
|
+
decorateWithSpan('"', 'token string') +
|
|
62
|
+
'<a href="' +
|
|
63
|
+
encodeURI(value) +
|
|
64
|
+
'">' +
|
|
65
|
+
htmlEncode(stringifyStringLiteral(value)) +
|
|
66
|
+
'</a>' +
|
|
67
|
+
decorateWithSpan('"', 'token string');
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
output += decorateWithSpan('"' + stringifyStringLiteral(value) + '"', 'token string');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (valueType === 'boolean') {
|
|
74
|
+
output += decorateWithSpan(value, 'token boolean');
|
|
75
|
+
}
|
|
76
|
+
return output;
|
|
77
|
+
}
|
|
78
|
+
function arrayToHTML(json, maxExpandLevel) {
|
|
79
|
+
var collapsed = level > maxExpandLevel ? 'collapsed' : '';
|
|
80
|
+
var output = "<button class=\"collapser\" aria-label=\"".concat(level > maxExpandLevel + 1 ? 'expand' : 'collapse', "\"></button>").concat(punctuation('['), "<span class=\"ellipsis\"></span><ul class=\"array collapsible\">");
|
|
81
|
+
var hasContents = false;
|
|
82
|
+
var length = json.length;
|
|
83
|
+
for (var i = 0; i < length; i++) {
|
|
84
|
+
hasContents = true;
|
|
85
|
+
output += '<li><div class="hoverable ' + collapsed + '">';
|
|
86
|
+
output += valueToHTML(json[i], maxExpandLevel);
|
|
87
|
+
if (i < length - 1) {
|
|
88
|
+
output += ',';
|
|
89
|
+
}
|
|
90
|
+
output += '</div></li>';
|
|
91
|
+
}
|
|
92
|
+
output += "</ul>".concat(punctuation(']'));
|
|
93
|
+
if (!hasContents) {
|
|
94
|
+
output = punctuation('[ ]');
|
|
95
|
+
}
|
|
96
|
+
return output;
|
|
97
|
+
}
|
|
98
|
+
function objectToHTML(json, maxExpandLevel) {
|
|
99
|
+
var collapsed = level > maxExpandLevel ? 'collapsed' : '';
|
|
100
|
+
var keys = Object.keys(json);
|
|
101
|
+
var length = keys.length;
|
|
102
|
+
var output = "<button class=\"collapser\" aria-label=\"".concat(level > maxExpandLevel + 1 ? 'expand' : 'collapse', "\"></button>").concat(punctuation('{'), "<span class=\"ellipsis\"></span><ul class=\"obj collapsible\">");
|
|
103
|
+
var hasContents = false;
|
|
104
|
+
for (var i = 0; i < length; i++) {
|
|
105
|
+
var key = keys[i];
|
|
106
|
+
hasContents = true;
|
|
107
|
+
output += '<li><div class="hoverable ' + collapsed + '">';
|
|
108
|
+
output += '<span class="property token string">"' + htmlEncode(key) + '"</span>: ';
|
|
109
|
+
output += valueToHTML(json[key], maxExpandLevel);
|
|
110
|
+
if (i < length - 1) {
|
|
111
|
+
output += punctuation(',');
|
|
112
|
+
}
|
|
113
|
+
output += '</div></li>';
|
|
114
|
+
}
|
|
115
|
+
output += "</ul>".concat(punctuation('}'));
|
|
116
|
+
if (!hasContents) {
|
|
117
|
+
output = punctuation('{ }');
|
|
118
|
+
}
|
|
119
|
+
return output;
|
|
120
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare type MediaQueries = {
|
|
2
|
+
print: string;
|
|
3
|
+
small: string;
|
|
4
|
+
medium: string;
|
|
5
|
+
large: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const breakpoints: {
|
|
8
|
+
small: string;
|
|
9
|
+
medium: string;
|
|
10
|
+
large: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function generateMediaQueries(breakpoints: Omit<MediaQueries, 'print'>): MediaQueries;
|