@redocly/theme 0.1.1 → 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.
Files changed (203) hide show
  1. package/Button/Button.d.ts +17 -0
  2. package/Button/Button.js +34 -0
  3. package/Button/index.d.ts +1 -0
  4. package/Button/index.js +1 -0
  5. package/CodeBlock/CodeBlock.d.ts +1 -0
  6. package/CodeBlock/CodeBlock.js +7 -0
  7. package/CodeBlock/index.d.ts +1 -0
  8. package/CodeBlock/index.js +1 -0
  9. package/CopyButton/CopyButton.d.ts +6 -0
  10. package/CopyButton/CopyButton.js +69 -0
  11. package/CopyButton/CopyButtonWrapper.d.ts +9 -0
  12. package/CopyButton/CopyButtonWrapper.js +37 -0
  13. package/CopyButton/index.d.ts +2 -0
  14. package/CopyButton/index.js +2 -0
  15. package/Headings/Headings.d.ts +3 -0
  16. package/Headings/Headings.js +10 -0
  17. package/Headings/index.d.ts +1 -0
  18. package/Headings/index.js +1 -0
  19. package/JsonViewer/JsonViewer.d.ts +10 -0
  20. package/JsonViewer/JsonViewer.js +92 -0
  21. package/JsonViewer/index.d.ts +1 -0
  22. package/JsonViewer/index.js +1 -0
  23. package/JsonViewer/styled.d.ts +1 -0
  24. package/JsonViewer/styled.js +7 -0
  25. package/Logo/Logo.d.ts +10 -0
  26. package/Logo/Logo.js +25 -0
  27. package/Navbar/Navbar.d.ts +9 -0
  28. package/Navbar/Navbar.js +23 -0
  29. package/Navbar/NavbarItem.d.ts +40 -0
  30. package/Navbar/NavbarItem.js +43 -0
  31. package/Navbar/NavbarMenu.d.ts +4 -0
  32. package/Navbar/NavbarMenu.js +29 -0
  33. package/Panel/CodePanel.d.ts +1 -0
  34. package/Panel/CodePanel.js +13 -0
  35. package/Panel/ContentPanel.d.ts +1 -0
  36. package/Panel/ContentPanel.js +12 -0
  37. package/Panel/DarkHeader.d.ts +1 -0
  38. package/Panel/DarkHeader.js +7 -0
  39. package/Panel/Panel.d.ts +2 -0
  40. package/Panel/Panel.js +10 -0
  41. package/Panel/PanelBody.d.ts +6 -0
  42. package/Panel/PanelBody.js +15 -0
  43. package/Panel/PanelComponent.d.ts +10 -0
  44. package/Panel/PanelComponent.js +40 -0
  45. package/Panel/PanelHeader.d.ts +7 -0
  46. package/Panel/PanelHeader.js +16 -0
  47. package/Panel/PanelHeaderTitle.d.ts +1 -0
  48. package/Panel/PanelHeaderTitle.js +7 -0
  49. package/Panel/index.d.ts +7 -0
  50. package/Panel/index.js +7 -0
  51. package/SamplesPanelControls/SamplesPanelControls.d.ts +4 -0
  52. package/SamplesPanelControls/SamplesPanelControls.js +17 -0
  53. package/SamplesPanelControls/index.d.ts +1 -0
  54. package/SamplesPanelControls/index.js +1 -0
  55. package/SidebarLogo/SidebarLogo.d.ts +9 -0
  56. package/SidebarLogo/SidebarLogo.js +29 -0
  57. package/SidebarLogo/index.d.ts +1 -0
  58. package/SidebarLogo/index.js +1 -0
  59. package/SourceCode/SourceCode.d.ts +24 -0
  60. package/SourceCode/SourceCode.js +31 -0
  61. package/SourceCode/index.d.ts +1 -0
  62. package/SourceCode/index.js +1 -0
  63. package/Tooltip/Tooltip.d.ts +12 -0
  64. package/Tooltip/Tooltip.js +57 -0
  65. package/Tooltip/index.d.ts +1 -0
  66. package/Tooltip/index.js +1 -0
  67. package/globalStyle.d.ts +1 -0
  68. package/globalStyle.js +7 -0
  69. package/hooks/index.d.ts +3 -0
  70. package/hooks/index.js +3 -0
  71. package/hooks/useControl.d.ts +6 -0
  72. package/hooks/useControl.js +12 -0
  73. package/hooks/useMount.d.ts +1 -0
  74. package/hooks/useMount.js +7 -0
  75. package/hooks/useUnmount.d.ts +1 -0
  76. package/hooks/useUnmount.js +9 -0
  77. package/icons/ShelfIcon/ShelfIcon.d.ts +10 -0
  78. package/icons/ShelfIcon/ShelfIcon.js +33 -0
  79. package/icons/ShelfIcon/index.d.ts +2 -0
  80. package/icons/ShelfIcon/index.js +1 -0
  81. package/icons/index.d.ts +1 -0
  82. package/icons/index.js +1 -0
  83. package/index.d.ts +14 -0
  84. package/mocks/Link.d.ts +2 -0
  85. package/mocks/Link.js +17 -0
  86. package/mocks/utils.d.ts +1 -0
  87. package/mocks/utils.js +3 -0
  88. package/package.json +2 -78
  89. package/src/Button/Button.stories.tsx +74 -0
  90. package/src/Button/Button.tsx +122 -0
  91. package/src/Button/__tests__/Button.test.tsx +42 -0
  92. package/src/Button/__tests__/__snapshots__/Button.test.tsx.snap +274 -0
  93. package/src/Button/index.ts +1 -0
  94. package/src/CodeBlock/CodeBlock.ts +125 -0
  95. package/src/CodeBlock/__tests__/CodeBlock.test.tsx +12 -0
  96. package/src/CodeBlock/__tests__/__snapshots__/CodeBlock.test.tsx.snap +140 -0
  97. package/src/CodeBlock/index.ts +1 -0
  98. package/src/CopyButton/CopyButton.stories.tsx +18 -0
  99. package/src/CopyButton/CopyButton.tsx +26 -0
  100. package/src/CopyButton/CopyButtonWrapper.tsx +52 -0
  101. package/src/CopyButton/__tests__/CopyButton.test.tsx +35 -0
  102. package/src/CopyButton/__tests__/CopyButtonWrapper.test.tsx +16 -0
  103. package/src/CopyButton/__tests__/__snapshots__/CopyButton.test.tsx.snap +55 -0
  104. package/src/CopyButton/__tests__/__snapshots__/CopyButtonWrapper.test.tsx.snap +46 -0
  105. package/src/CopyButton/index.ts +2 -0
  106. package/src/Headings/Headings.stories.tsx +36 -0
  107. package/src/Headings/Headings.ts +23 -0
  108. package/src/Headings/__tests__/Headings.test.tsx +24 -0
  109. package/src/Headings/__tests__/__snapshots__/Headings.test.tsx.snap +57 -0
  110. package/src/Headings/index.ts +1 -0
  111. package/src/Introduction.stories.mdx +7 -0
  112. package/src/JsonViewer/JsonViewer.stories.tsx +57 -0
  113. package/src/JsonViewer/JsonViewer.tsx +130 -0
  114. package/src/JsonViewer/__tests__/JsonViewer.test.tsx +82 -0
  115. package/src/JsonViewer/__tests__/__snapshots__/JsonViewer.test.tsx.snap +2728 -0
  116. package/src/JsonViewer/index.ts +1 -0
  117. package/src/JsonViewer/styled.ts +103 -0
  118. package/src/Logo/Logo.tsx +23 -0
  119. package/src/Navbar/Navbar.stories.tsx +38 -0
  120. package/src/Navbar/Navbar.tsx +60 -0
  121. package/src/Navbar/NavbarItem.tsx +90 -0
  122. package/src/Navbar/NavbarMenu.tsx +29 -0
  123. package/src/Panel/CodePanel.stories.tsx +27 -0
  124. package/src/Panel/CodePanel.ts +31 -0
  125. package/src/Panel/ContentPanel.stories.tsx +27 -0
  126. package/src/Panel/ContentPanel.ts +43 -0
  127. package/src/Panel/DarkHeader.ts +8 -0
  128. package/src/Panel/Panel.stories.tsx +58 -0
  129. package/src/Panel/Panel.ts +18 -0
  130. package/src/Panel/PanelBody.ts +30 -0
  131. package/src/Panel/PanelComponent.tsx +73 -0
  132. package/src/Panel/PanelHeader.ts +25 -0
  133. package/src/Panel/PanelHeaderTitle.ts +11 -0
  134. package/src/Panel/__tests__/CodePanel.test.tsx +26 -0
  135. package/src/Panel/__tests__/ContentPanel.test.tsx +26 -0
  136. package/src/Panel/__tests__/Panel.test.tsx +54 -0
  137. package/src/Panel/__tests__/__snapshots__/CodePanel.test.tsx.snap +258 -0
  138. package/src/Panel/__tests__/__snapshots__/ContentPanel.test.tsx.snap +278 -0
  139. package/src/Panel/__tests__/__snapshots__/Panel.test.tsx.snap +398 -0
  140. package/src/Panel/index.ts +7 -0
  141. package/src/SamplesPanelControls/SamplesControlButton.stories.tsx +18 -0
  142. package/src/SamplesPanelControls/SamplesPanelControls.ts +70 -0
  143. package/src/SamplesPanelControls/__tests__/SamplesPanelControls.test.tsx +36 -0
  144. package/src/SamplesPanelControls/__tests__/__snapshots__/SamplesPanelControls.test.tsx.snap +228 -0
  145. package/src/SamplesPanelControls/index.ts +1 -0
  146. package/src/SidebarLogo/SidebarLogo.stories.tsx +21 -0
  147. package/src/SidebarLogo/SidebarLogo.tsx +47 -0
  148. package/src/SidebarLogo/__tests__/SidebarLogo.test.tsx +32 -0
  149. package/src/SidebarLogo/__tests__/__snapshots__/SidebarLogo.test.tsx.snap +62 -0
  150. package/src/SidebarLogo/index.ts +1 -0
  151. package/src/SourceCode/SourceCode.stories.tsx +29 -0
  152. package/src/SourceCode/SourceCode.tsx +67 -0
  153. package/src/SourceCode/__tests__/SourceCode.test.tsx +47 -0
  154. package/src/SourceCode/__tests__/__snapshots__/SourceCode.test.tsx.snap +786 -0
  155. package/src/SourceCode/index.ts +1 -0
  156. package/src/Tooltip/Tooltip.stories.tsx +27 -0
  157. package/src/Tooltip/Tooltip.tsx +171 -0
  158. package/src/Tooltip/__tests__/Tooltip.test.tsx +41 -0
  159. package/src/Tooltip/__tests__/__snapshots__/Tooltip.test.tsx.snap +83 -0
  160. package/src/Tooltip/index.ts +1 -0
  161. package/src/globalStyle.ts +512 -0
  162. package/src/hooks/index.ts +3 -0
  163. package/src/hooks/useControl.ts +20 -0
  164. package/src/hooks/useMount.ts +8 -0
  165. package/src/hooks/useUnmount.ts +10 -0
  166. package/src/icons/ShelfIcon/ShelfIcon.stories.tsx +36 -0
  167. package/src/icons/ShelfIcon/ShelfIcon.tsx +45 -0
  168. package/src/icons/ShelfIcon/__tests__/ShelfIcon.test.tsx +54 -0
  169. package/src/icons/ShelfIcon/__tests__/__snapshots__/ShelfIcon.test.tsx.snap +235 -0
  170. package/src/icons/ShelfIcon/index.ts +2 -0
  171. package/src/icons/index.ts +1 -0
  172. package/src/index.ts +14 -0
  173. package/src/mocks/Link.tsx +7 -0
  174. package/src/mocks/utils.ts +3 -0
  175. package/src/utils/ClipboardService.ts +92 -0
  176. package/src/utils/__tests__/ClipboardService.test.ts +24 -0
  177. package/src/utils/__tests__/__snapshots__/highlight.test.ts.snap +5 -0
  178. package/src/utils/__tests__/__snapshots__/jsonToHtml.test.ts.snap +5 -0
  179. package/src/utils/__tests__/css-variables.test.ts +20 -0
  180. package/src/utils/__tests__/highlight.test.ts +51 -0
  181. package/src/utils/__tests__/jsonToHtml.test.ts +40 -0
  182. package/src/utils/__tests__/media-css.test.ts +20 -0
  183. package/src/utils/__tests__/theme-helpers.test.ts +25 -0
  184. package/src/utils/css-variables.ts +2 -0
  185. package/src/utils/highlight.ts +81 -0
  186. package/src/utils/index.ts +6 -0
  187. package/src/utils/jsonToHtml.ts +122 -0
  188. package/src/utils/media-css.ts +16 -0
  189. package/src/utils/theme-helpers.ts +34 -0
  190. package/utils/ClipboardService.d.ts +8 -0
  191. package/utils/ClipboardService.js +83 -0
  192. package/utils/css-variables.d.ts +1 -0
  193. package/utils/css-variables.js +4 -0
  194. package/utils/highlight.d.ts +32 -0
  195. package/utils/highlight.js +65 -0
  196. package/utils/index.d.ts +6 -0
  197. package/utils/index.js +6 -0
  198. package/utils/jsonToHtml.d.ts +1 -0
  199. package/utils/jsonToHtml.js +116 -0
  200. package/utils/media-css.d.ts +12 -0
  201. package/utils/media-css.js +9 -0
  202. package/utils/theme-helpers.d.ts +3 -0
  203. package/utils/theme-helpers.js +27 -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,6 @@
1
+ export * from './ClipboardService';
2
+ export * from './css-variables';
3
+ export * from './highlight';
4
+ export * from './jsonToHtml';
5
+ export * from './media-css';
6
+ export * from './theme-helpers';
@@ -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, '&amp;')
20
+ .replace(/"/g, '&quot;')
21
+ .replace(/</g, '&lt;')
22
+ .replace(/>/g, '&gt;')
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,83 @@
1
+ var ClipboardService = /** @class */ (function () {
2
+ function ClipboardService() {
3
+ }
4
+ ClipboardService.isSupported = function () {
5
+ return (typeof document !== 'undefined' &&
6
+ !!document.queryCommandSupported &&
7
+ document.queryCommandSupported('copy'));
8
+ };
9
+ ClipboardService.selectElement = function (element) {
10
+ if (!element) {
11
+ return;
12
+ }
13
+ var range;
14
+ var selection;
15
+ if (document.body.createTextRange) {
16
+ range = document.body.createTextRange();
17
+ range.moveToElementText(element);
18
+ range.select();
19
+ }
20
+ else if (document.createRange && window.getSelection) {
21
+ selection = window.getSelection();
22
+ range = document.createRange();
23
+ range.selectNodeContents(element);
24
+ selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
25
+ selection === null || selection === void 0 ? void 0 : selection.addRange(range);
26
+ }
27
+ };
28
+ ClipboardService.deselect = function () {
29
+ if (document.selection) {
30
+ document.selection.empty();
31
+ }
32
+ else if (window.getSelection) {
33
+ var selection = window.getSelection();
34
+ if (selection) {
35
+ selection.removeAllRanges();
36
+ }
37
+ }
38
+ };
39
+ ClipboardService.copySelected = function () {
40
+ var result;
41
+ try {
42
+ result = document.execCommand('copy');
43
+ }
44
+ catch (err) {
45
+ result = false;
46
+ }
47
+ return result;
48
+ };
49
+ ClipboardService.copyElement = function (element) {
50
+ ClipboardService.selectElement(element);
51
+ var res = ClipboardService.copySelected();
52
+ if (res) {
53
+ ClipboardService.deselect();
54
+ }
55
+ return res;
56
+ };
57
+ ClipboardService.copyCustom = function (text) {
58
+ var textArea = document.createElement('textarea');
59
+ textArea.style.position = 'fixed';
60
+ textArea.style.top = '0';
61
+ textArea.style.left = '0';
62
+ // Ensure it has a small width and height. Setting to 1px / 1em
63
+ // doesn't work as this gives a negative w/h on some browsers.
64
+ textArea.style.width = '2em';
65
+ textArea.style.height = '2em';
66
+ // We don't need padding, reducing the size if it does flash render.
67
+ textArea.style.padding = '0';
68
+ // Clean up any borders.
69
+ textArea.style.border = 'none';
70
+ textArea.style.outline = 'none';
71
+ textArea.style.boxShadow = 'none';
72
+ // Avoid flash of white box if rendered for any reason.
73
+ textArea.style.background = 'transparent';
74
+ textArea.value = text;
75
+ document.body.appendChild(textArea);
76
+ textArea.select();
77
+ var res = ClipboardService.copySelected();
78
+ document.body.removeChild(textArea);
79
+ return res;
80
+ };
81
+ return ClipboardService;
82
+ }());
83
+ export { ClipboardService };
@@ -0,0 +1 @@
1
+ export declare const getCssColorVariable: (color: string | undefined, defaultValue?: string) => string;
@@ -0,0 +1,4 @@
1
+ export var getCssColorVariable = function (color, defaultValue) {
2
+ if (defaultValue === void 0) { defaultValue = 'inherit'; }
3
+ return (color === null || color === void 0 ? void 0 : color.startsWith('--')) ? "var(".concat(color, ")") : color || defaultValue;
4
+ };
@@ -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,65 @@
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
+ var DEFAULT_LANG = 'clike';
24
+ Prism.languages.insertBefore('javascript', 'string', {
25
+ 'property string': {
26
+ pattern: /([{,]\s*)"(?:\\.|[^\\"\r\n])*"(?=\s*:)/i,
27
+ lookbehind: true,
28
+ },
29
+ }, undefined);
30
+ Prism.languages.insertBefore('javascript', 'punctuation', {
31
+ property: {
32
+ pattern: /([{,]\s*)[a-z]\w*(?=\s*:)/i,
33
+ lookbehind: true,
34
+ },
35
+ }, undefined);
36
+ /**
37
+ * map language names to Prism.js names
38
+ */
39
+ export function mapLang(lang) {
40
+ return ({
41
+ json: 'js',
42
+ 'c++': 'cpp',
43
+ 'c#': 'csharp',
44
+ 'objective-c': 'objectivec',
45
+ shell: 'bash',
46
+ viml: 'vim',
47
+ curl: 'bash',
48
+ 'node.js': 'js',
49
+ }[lang] || DEFAULT_LANG);
50
+ }
51
+ /**
52
+ * Highlight source code string using Prism.js
53
+ * @param source source code to highlight
54
+ * @param lang highlight language
55
+ * @return highlighted source code as **html string**
56
+ */
57
+ export function highlight(source, lang) {
58
+ if (lang === void 0) { lang = DEFAULT_LANG; }
59
+ lang = lang.toLowerCase();
60
+ var grammar = Prism.languages[lang];
61
+ if (!grammar) {
62
+ grammar = Prism.languages[mapLang(lang)];
63
+ }
64
+ return Prism.highlight(source.toString(), grammar, lang);
65
+ }
@@ -0,0 +1,6 @@
1
+ export * from './ClipboardService';
2
+ export * from './css-variables';
3
+ export * from './highlight';
4
+ export * from './jsonToHtml';
5
+ export * from './media-css';
6
+ export * from './theme-helpers';
package/utils/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from './ClipboardService';
2
+ export * from './css-variables';
3
+ export * from './highlight';
4
+ export * from './jsonToHtml';
5
+ export * from './media-css';
6
+ export * from './theme-helpers';
@@ -0,0 +1 @@
1
+ export declare function jsonToHTML(json: JSON | Record<string, unknown>, maxExpandLevel: number): string;
@@ -0,0 +1,116 @@
1
+ // Moved from reference-docs
2
+ var level = 1;
3
+ export function jsonToHTML(json, maxExpandLevel) {
4
+ level = 1;
5
+ var output = '';
6
+ output += '<div data-cy="json-sample" class="redoc-json">';
7
+ output += '<code>';
8
+ output += valueToHTML(json, maxExpandLevel);
9
+ output += '</code>';
10
+ output += '</div>';
11
+ return output;
12
+ }
13
+ function htmlEncode(t) {
14
+ return t !== undefined
15
+ ? t
16
+ .toString()
17
+ .replace(/&/g, '&amp;')
18
+ .replace(/"/g, '&quot;')
19
+ .replace(/</g, '&lt;')
20
+ .replace(/>/g, '&gt;')
21
+ : '';
22
+ }
23
+ function stringifyStringLiteral(str) {
24
+ return JSON.stringify(str).slice(1, -1);
25
+ }
26
+ function decorateWithSpan(value, className) {
27
+ return '<span class="' + className + '">' + htmlEncode(value) + '</span>';
28
+ }
29
+ function punctuation(val) {
30
+ return '<span class="token punctuation">' + val + '</span>';
31
+ }
32
+ function valueToHTML(value, maxExpandLevel) {
33
+ var valueType = typeof value;
34
+ var output = '';
35
+ if (value === undefined || value === null) {
36
+ output += decorateWithSpan('null', 'token keyword');
37
+ }
38
+ else if (value && value.constructor === Array) {
39
+ level++;
40
+ output += arrayToHTML(value, maxExpandLevel);
41
+ level--;
42
+ }
43
+ else if (value && value.constructor === Date) {
44
+ output += decorateWithSpan('"' + value.toISOString() + '"', 'token string');
45
+ }
46
+ else if (valueType === 'object') {
47
+ level++;
48
+ output += objectToHTML(value, maxExpandLevel);
49
+ level--;
50
+ }
51
+ else if (valueType === 'number') {
52
+ output += decorateWithSpan(value, 'token number');
53
+ }
54
+ else if (valueType === 'string') {
55
+ if (/^(http|https):\/\/[^\s]+$/.test(value)) {
56
+ output +=
57
+ decorateWithSpan('"', 'token string') +
58
+ '<a href="' +
59
+ encodeURI(value) +
60
+ '">' +
61
+ htmlEncode(stringifyStringLiteral(value)) +
62
+ '</a>' +
63
+ decorateWithSpan('"', 'token string');
64
+ }
65
+ else {
66
+ output += decorateWithSpan('"' + stringifyStringLiteral(value) + '"', 'token string');
67
+ }
68
+ }
69
+ else if (valueType === 'boolean') {
70
+ output += decorateWithSpan(value, 'token boolean');
71
+ }
72
+ return output;
73
+ }
74
+ function arrayToHTML(json, maxExpandLevel) {
75
+ var collapsed = level > maxExpandLevel ? 'collapsed' : '';
76
+ var output = "<button class=\"collapser\" aria-label=\"".concat(level > maxExpandLevel + 1 ? 'expand' : 'collapse', "\"></button>").concat(punctuation('['), "<span class=\"ellipsis\"></span><ul class=\"array collapsible\">");
77
+ var hasContents = false;
78
+ var length = json.length;
79
+ for (var i = 0; i < length; i++) {
80
+ hasContents = true;
81
+ output += '<li><div class="hoverable ' + collapsed + '">';
82
+ output += valueToHTML(json[i], maxExpandLevel);
83
+ if (i < length - 1) {
84
+ output += ',';
85
+ }
86
+ output += '</div></li>';
87
+ }
88
+ output += "</ul>".concat(punctuation(']'));
89
+ if (!hasContents) {
90
+ output = punctuation('[ ]');
91
+ }
92
+ return output;
93
+ }
94
+ function objectToHTML(json, maxExpandLevel) {
95
+ var collapsed = level > maxExpandLevel ? 'collapsed' : '';
96
+ var keys = Object.keys(json);
97
+ var length = keys.length;
98
+ var output = "<button class=\"collapser\" aria-label=\"".concat(level > maxExpandLevel + 1 ? 'expand' : 'collapse', "\"></button>").concat(punctuation('{'), "<span class=\"ellipsis\"></span><ul class=\"obj collapsible\">");
99
+ var hasContents = false;
100
+ for (var i = 0; i < length; i++) {
101
+ var key = keys[i];
102
+ hasContents = true;
103
+ output += '<li><div class="hoverable ' + collapsed + '">';
104
+ output += '<span class="property token string">"' + htmlEncode(key) + '"</span>: ';
105
+ output += valueToHTML(json[key], maxExpandLevel);
106
+ if (i < length - 1) {
107
+ output += punctuation(',');
108
+ }
109
+ output += '</div></li>';
110
+ }
111
+ output += "</ul>".concat(punctuation('}'));
112
+ if (!hasContents) {
113
+ output = punctuation('{ }');
114
+ }
115
+ return output;
116
+ }
@@ -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;
@@ -0,0 +1,9 @@
1
+ export var breakpoints = { small: '50rem', medium: '85rem', large: '105rem' };
2
+ export function generateMediaQueries(breakpoints) {
3
+ var result = { print: '@media print' };
4
+ for (var _i = 0, _a = Object.entries(breakpoints); _i < _a.length; _i++) {
5
+ var _b = _a[_i], key = _b[0], value = _b[1];
6
+ result[key] = "@media screen and (min-width: ".concat(value, ")");
7
+ }
8
+ return result;
9
+ }
@@ -0,0 +1,3 @@
1
+ import type { FlattenSimpleInterpolation } from 'styled-components';
2
+ export declare function getTypographyCssRulesByComponentName(componentName: string, fallbackName?: string): Record<string, string>;
3
+ export declare function typography(componentName: string, fallbackName?: string): FlattenSimpleInterpolation;
@@ -0,0 +1,27 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ import { css } from 'styled-components';
6
+ var typographyProperties = Object.entries({
7
+ fontSize: 'font-size',
8
+ fontWeight: 'font-weight',
9
+ fontFamily: 'font-family',
10
+ lineHeight: 'line-height',
11
+ color: 'color',
12
+ textTransform: 'text-transform',
13
+ });
14
+ export function getTypographyCssRulesByComponentName(componentName, fallbackName) {
15
+ var result = {};
16
+ for (var _i = 0, typographyProperties_1 = typographyProperties; _i < typographyProperties_1.length; _i++) {
17
+ var _a = typographyProperties_1[_i], styledPropertyName = _a[0], cssPropertyName = _a[1];
18
+ var cssVariable = "--".concat(componentName, "-").concat(cssPropertyName);
19
+ var fallbackVariable = fallbackName ? ",var(--".concat(fallbackName, "-").concat(cssPropertyName, ")") : '';
20
+ result[styledPropertyName] = "var(".concat(cssVariable).concat(fallbackVariable, ")");
21
+ }
22
+ return result;
23
+ }
24
+ export function typography(componentName, fallbackName) {
25
+ return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n "], ["\n ", "\n "])), getTypographyCssRulesByComponentName(componentName, fallbackName));
26
+ }
27
+ var templateObject_1;