@redocly/theme 0.1.0 → 0.1.3

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 (206) hide show
  1. package/Button/Button.d.ts +17 -0
  2. package/Button/Button.js +34 -0
  3. package/{lib/src/Button/index.ts → Button/index.d.ts} +0 -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/{lib/src/CodeBlock/index.ts → CodeBlock/index.d.ts} +0 -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/{lib/src/CopyButton/index.ts → CopyButton/index.d.ts} +0 -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/{lib/src/Headings/index.ts → Headings/index.d.ts} +0 -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/{lib/src/JsonViewer/index.ts → JsonViewer/index.d.ts} +0 -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/{lib/src/Panel/index.ts → Panel/index.d.ts} +0 -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/{lib/src/SamplesPanelControls/index.ts → SamplesPanelControls/index.d.ts} +0 -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/{lib/src/SidebarLogo/index.ts → SidebarLogo/index.d.ts} +0 -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/{lib/src/SourceCode/index.ts → SourceCode/index.d.ts} +0 -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/{lib/src/Tooltip/index.ts → Tooltip/index.d.ts} +0 -0
  66. package/Tooltip/index.js +1 -0
  67. package/globalStyle.d.ts +1 -0
  68. package/globalStyle.js +7 -0
  69. package/{lib/src/hooks/index.ts → hooks/index.d.ts} +0 -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/{lib/src/icons/ShelfIcon/index.ts → icons/ShelfIcon/index.d.ts} +0 -0
  80. package/icons/ShelfIcon/index.js +1 -0
  81. package/{lib/src/icons/index.ts → icons/index.d.ts} +0 -0
  82. package/icons/index.js +1 -0
  83. package/{lib/src/index.ts → index.d.ts} +0 -0
  84. package/index.js +14 -0
  85. package/mocks/Link.d.ts +2 -0
  86. package/mocks/Link.js +17 -0
  87. package/mocks/utils.d.ts +1 -0
  88. package/mocks/utils.js +3 -0
  89. package/package.json +1 -5
  90. package/src/Button/Button.stories.tsx +74 -0
  91. package/{lib/src → src}/Button/Button.tsx +0 -0
  92. package/src/Button/__tests__/Button.test.tsx +42 -0
  93. package/src/Button/__tests__/__snapshots__/Button.test.tsx.snap +274 -0
  94. package/src/Button/index.ts +1 -0
  95. package/{lib/src → src}/CodeBlock/CodeBlock.ts +0 -0
  96. package/src/CodeBlock/__tests__/CodeBlock.test.tsx +12 -0
  97. package/src/CodeBlock/__tests__/__snapshots__/CodeBlock.test.tsx.snap +140 -0
  98. package/src/CodeBlock/index.ts +1 -0
  99. package/src/CopyButton/CopyButton.stories.tsx +18 -0
  100. package/{lib/src → src}/CopyButton/CopyButton.tsx +0 -0
  101. package/{lib/src → src}/CopyButton/CopyButtonWrapper.tsx +0 -0
  102. package/src/CopyButton/__tests__/CopyButton.test.tsx +35 -0
  103. package/src/CopyButton/__tests__/CopyButtonWrapper.test.tsx +16 -0
  104. package/src/CopyButton/__tests__/__snapshots__/CopyButton.test.tsx.snap +55 -0
  105. package/src/CopyButton/__tests__/__snapshots__/CopyButtonWrapper.test.tsx.snap +46 -0
  106. package/src/CopyButton/index.ts +2 -0
  107. package/src/Headings/Headings.stories.tsx +36 -0
  108. package/{lib/src → src}/Headings/Headings.ts +0 -0
  109. package/src/Headings/__tests__/Headings.test.tsx +24 -0
  110. package/src/Headings/__tests__/__snapshots__/Headings.test.tsx.snap +57 -0
  111. package/src/Headings/index.ts +1 -0
  112. package/src/Introduction.stories.mdx +7 -0
  113. package/src/JsonViewer/JsonViewer.stories.tsx +57 -0
  114. package/{lib/src → src}/JsonViewer/JsonViewer.tsx +0 -0
  115. package/src/JsonViewer/__tests__/JsonViewer.test.tsx +82 -0
  116. package/src/JsonViewer/__tests__/__snapshots__/JsonViewer.test.tsx.snap +2728 -0
  117. package/src/JsonViewer/index.ts +1 -0
  118. package/{lib/src → src}/JsonViewer/styled.ts +0 -0
  119. package/{lib/src → src}/Logo/Logo.tsx +0 -0
  120. package/src/Navbar/Navbar.stories.tsx +38 -0
  121. package/{lib/src → src}/Navbar/Navbar.tsx +0 -0
  122. package/{lib/src → src}/Navbar/NavbarItem.tsx +0 -0
  123. package/{lib/src → src}/Navbar/NavbarMenu.tsx +0 -0
  124. package/src/Panel/CodePanel.stories.tsx +27 -0
  125. package/{lib/src → src}/Panel/CodePanel.ts +0 -0
  126. package/src/Panel/ContentPanel.stories.tsx +27 -0
  127. package/{lib/src → src}/Panel/ContentPanel.ts +0 -0
  128. package/{lib/src → src}/Panel/DarkHeader.ts +0 -0
  129. package/src/Panel/Panel.stories.tsx +58 -0
  130. package/{lib/src → src}/Panel/Panel.ts +0 -0
  131. package/{lib/src → src}/Panel/PanelBody.ts +0 -0
  132. package/{lib/src → src}/Panel/PanelComponent.tsx +0 -0
  133. package/{lib/src → src}/Panel/PanelHeader.ts +0 -0
  134. package/{lib/src → src}/Panel/PanelHeaderTitle.ts +0 -0
  135. package/src/Panel/__tests__/CodePanel.test.tsx +26 -0
  136. package/src/Panel/__tests__/ContentPanel.test.tsx +26 -0
  137. package/src/Panel/__tests__/Panel.test.tsx +54 -0
  138. package/src/Panel/__tests__/__snapshots__/CodePanel.test.tsx.snap +258 -0
  139. package/src/Panel/__tests__/__snapshots__/ContentPanel.test.tsx.snap +278 -0
  140. package/src/Panel/__tests__/__snapshots__/Panel.test.tsx.snap +398 -0
  141. package/src/Panel/index.ts +7 -0
  142. package/src/SamplesPanelControls/SamplesControlButton.stories.tsx +18 -0
  143. package/{lib/src → src}/SamplesPanelControls/SamplesPanelControls.ts +0 -0
  144. package/src/SamplesPanelControls/__tests__/SamplesPanelControls.test.tsx +36 -0
  145. package/src/SamplesPanelControls/__tests__/__snapshots__/SamplesPanelControls.test.tsx.snap +228 -0
  146. package/src/SamplesPanelControls/index.ts +1 -0
  147. package/src/SidebarLogo/SidebarLogo.stories.tsx +21 -0
  148. package/{lib/src → src}/SidebarLogo/SidebarLogo.tsx +0 -0
  149. package/src/SidebarLogo/__tests__/SidebarLogo.test.tsx +32 -0
  150. package/src/SidebarLogo/__tests__/__snapshots__/SidebarLogo.test.tsx.snap +62 -0
  151. package/src/SidebarLogo/index.ts +1 -0
  152. package/src/SourceCode/SourceCode.stories.tsx +29 -0
  153. package/{lib/src → src}/SourceCode/SourceCode.tsx +0 -0
  154. package/src/SourceCode/__tests__/SourceCode.test.tsx +47 -0
  155. package/src/SourceCode/__tests__/__snapshots__/SourceCode.test.tsx.snap +786 -0
  156. package/src/SourceCode/index.ts +1 -0
  157. package/src/Tooltip/Tooltip.stories.tsx +27 -0
  158. package/{lib/src → src}/Tooltip/Tooltip.tsx +0 -0
  159. package/src/Tooltip/__tests__/Tooltip.test.tsx +41 -0
  160. package/src/Tooltip/__tests__/__snapshots__/Tooltip.test.tsx.snap +83 -0
  161. package/src/Tooltip/index.ts +1 -0
  162. package/{lib/src → src}/globalStyle.ts +0 -0
  163. package/src/hooks/index.ts +3 -0
  164. package/{lib/src → src}/hooks/useControl.ts +0 -0
  165. package/{lib/src → src}/hooks/useMount.ts +0 -0
  166. package/{lib/src → src}/hooks/useUnmount.ts +0 -0
  167. package/src/icons/ShelfIcon/ShelfIcon.stories.tsx +36 -0
  168. package/{lib/src → src}/icons/ShelfIcon/ShelfIcon.tsx +0 -0
  169. package/src/icons/ShelfIcon/__tests__/ShelfIcon.test.tsx +54 -0
  170. package/src/icons/ShelfIcon/__tests__/__snapshots__/ShelfIcon.test.tsx.snap +235 -0
  171. package/src/icons/ShelfIcon/index.ts +2 -0
  172. package/src/icons/index.ts +1 -0
  173. package/src/index.ts +14 -0
  174. package/{lib/src → src}/mocks/Link.tsx +0 -0
  175. package/{lib/src → src}/mocks/utils.ts +0 -0
  176. package/{lib/src → src}/utils/ClipboardService.ts +0 -0
  177. package/src/utils/__tests__/ClipboardService.test.ts +24 -0
  178. package/src/utils/__tests__/__snapshots__/highlight.test.ts.snap +5 -0
  179. package/src/utils/__tests__/__snapshots__/jsonToHtml.test.ts.snap +5 -0
  180. package/src/utils/__tests__/css-variables.test.ts +20 -0
  181. package/src/utils/__tests__/highlight.test.ts +51 -0
  182. package/src/utils/__tests__/jsonToHtml.test.ts +40 -0
  183. package/src/utils/__tests__/media-css.test.ts +20 -0
  184. package/src/utils/__tests__/theme-helpers.test.ts +25 -0
  185. package/{lib/src → src}/utils/css-variables.ts +0 -0
  186. package/{lib/src → src}/utils/highlight.ts +0 -0
  187. package/{lib/src → src}/utils/index.ts +0 -0
  188. package/{lib/src → src}/utils/jsonToHtml.ts +0 -0
  189. package/{lib/src → src}/utils/media-css.ts +0 -0
  190. package/{lib/src → src}/utils/theme-helpers.ts +0 -0
  191. package/utils/ClipboardService.d.ts +8 -0
  192. package/utils/ClipboardService.js +83 -0
  193. package/utils/css-variables.d.ts +1 -0
  194. package/utils/css-variables.js +4 -0
  195. package/utils/highlight.d.ts +32 -0
  196. package/utils/highlight.js +65 -0
  197. package/utils/index.d.ts +6 -0
  198. package/utils/index.js +6 -0
  199. package/utils/jsonToHtml.d.ts +1 -0
  200. package/utils/jsonToHtml.js +116 -0
  201. package/utils/media-css.d.ts +12 -0
  202. package/utils/media-css.js +9 -0
  203. package/utils/theme-helpers.d.ts +3 -0
  204. package/utils/theme-helpers.js +27 -0
  205. package/LICENSE +0 -1
  206. package/lib/package.json +0 -91
@@ -0,0 +1,51 @@
1
+ import * as Prism from 'prismjs';
2
+
3
+ import { highlight, mapLang } from '../highlight';
4
+
5
+ jest.mock('prismjs', () => {
6
+ const original = jest.requireActual('prismjs');
7
+ return {
8
+ __isModule: true,
9
+ ...original,
10
+ highlight: jest.fn().mockImplementation((...args) => {
11
+ return original.highlight(...args);
12
+ }),
13
+ };
14
+ });
15
+
16
+ describe('highlight', () => {
17
+ beforeEach(() => {
18
+ jest.clearAllMocks();
19
+ });
20
+
21
+ it('should work with correct lang name', () => {
22
+ const highlighted = highlight('int name = "John"', 'cpp');
23
+
24
+ expect(highlighted).toMatchSnapshot();
25
+ });
26
+
27
+ it('should work with mapped lang name', () => {
28
+ const highlighted = highlight('int name = "John"', 'c++');
29
+
30
+ expect(highlighted).toMatchSnapshot();
31
+ });
32
+
33
+ it('should have default value for lang', () => {
34
+ const highlightSpy = jest.spyOn(Prism, 'highlight');
35
+
36
+ highlight('i++');
37
+
38
+ expect(highlightSpy).toBeCalledTimes(1);
39
+ expect(highlightSpy).toBeCalledWith('i++', expect.any(Object), 'clike');
40
+ });
41
+
42
+ describe('mapLang', () => {
43
+ it('should work with known lang', () => {
44
+ expect(mapLang('node.js')).toBe('js');
45
+ });
46
+
47
+ it('should work with unknown lang', () => {
48
+ expect(mapLang('ada')).toBe('clike');
49
+ });
50
+ });
51
+ });
@@ -0,0 +1,40 @@
1
+ import { jsonToHTML } from '../jsonToHtml';
2
+
3
+ const data = {
4
+ id: '600dc3b5d617e547a0e74cb9',
5
+ name: 'Mitchell Fitzgerald',
6
+ about: 'lorem ipsum',
7
+ address: '48 Avenue, City, North',
8
+ company: 'Test',
9
+ bio: null,
10
+ nicknames: [
11
+ 'Mitch',
12
+ 'Fitz',
13
+ { title: 'MitFitz', createdAt: new Date('2022-04-19T11:46:00.019Z') },
14
+ ],
15
+ age: 27,
16
+ isBanned: true,
17
+ link: 'https://google.com',
18
+ emptyArray: [],
19
+ empty: {},
20
+ contacts: {
21
+ phone: {
22
+ code: '+1',
23
+ rest: '999',
24
+ },
25
+ },
26
+ };
27
+
28
+ describe('jsonToHTML', () => {
29
+ it('should work with maxExpandLevel 1', () => {
30
+ const result = jsonToHTML(data, 1);
31
+
32
+ expect(result).toMatchSnapshot();
33
+ });
34
+
35
+ it('should work with maxExpandLevel 3', () => {
36
+ const result = jsonToHTML(data, 3);
37
+
38
+ expect(result).toMatchSnapshot();
39
+ });
40
+ });
@@ -0,0 +1,20 @@
1
+ import { generateMediaQueries } from '../media-css';
2
+
3
+ describe('media-css helpers', () => {
4
+ describe('generateMediaQueries function', () => {
5
+ it('generate media queries according to breakpoints', () => {
6
+ expect(
7
+ generateMediaQueries({
8
+ small: '50rem',
9
+ medium: '85rem',
10
+ large: '105rem',
11
+ }),
12
+ ).toEqual({
13
+ large: '@media screen and (min-width: 105rem)',
14
+ medium: '@media screen and (min-width: 85rem)',
15
+ print: '@media print',
16
+ small: '@media screen and (min-width: 50rem)',
17
+ });
18
+ });
19
+ });
20
+ });
@@ -0,0 +1,25 @@
1
+ import { getTypographyCssRulesByComponentName } from '../theme-helpers';
2
+
3
+ describe('getTypographyCssRulesByComponentName', () => {
4
+ it('should return object with defined css variable for component', () => {
5
+ expect(getTypographyCssRulesByComponentName('component')).toEqual({
6
+ fontSize: 'var(--component-font-size)',
7
+ fontWeight: 'var(--component-font-weight)',
8
+ fontFamily: 'var(--component-font-family)',
9
+ lineHeight: 'var(--component-line-height)',
10
+ color: 'var(--component-color)',
11
+ textTransform: 'var(--component-text-transform)',
12
+ });
13
+ });
14
+
15
+ it('should return object with fallback', () => {
16
+ expect(getTypographyCssRulesByComponentName('component', 'component1')).toEqual({
17
+ fontSize: 'var(--component-font-size,var(--component1-font-size))',
18
+ fontWeight: 'var(--component-font-weight,var(--component1-font-weight))',
19
+ fontFamily: 'var(--component-font-family,var(--component1-font-family))',
20
+ lineHeight: 'var(--component-line-height,var(--component1-line-height))',
21
+ color: 'var(--component-color,var(--component1-color))',
22
+ textTransform: 'var(--component-text-transform,var(--component1-text-transform))',
23
+ });
24
+ });
25
+ });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -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;
package/LICENSE DELETED
@@ -1 +0,0 @@
1
- (c) Copyright 2022 Redocly Inc, all rights reserved.
package/lib/package.json DELETED
@@ -1,91 +0,0 @@
1
- {
2
- "name": "@redocly/theme",
3
- "version": "0.1.0",
4
- "description": "Shared UI components",
5
- "author": "team@redocly.com",
6
- "license": "SEE LICENSE IN LICENSE",
7
- "main": "index.js",
8
- "typings": "index.d.ts",
9
- "files": [
10
- "lib"
11
- ],
12
- "scripts": {
13
- "start": "npm run storybook",
14
- "storybook": "start-storybook -p 6006",
15
- "build-storybook": "build-storybook",
16
- "clean": "rm -rf lib",
17
- "compile": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
18
- "build:copy": " cp -R src package.json .npmignore lib/",
19
- "build": "npm run clean && npm run compile && npm run build:copy",
20
- "build:watch": "npm run build && tsc --watch -p tsconfig.build.json & tsc-alias -w -p tsconfig.build.json",
21
- "deploy": "npm publish lib",
22
- "lint": "eslint . --ext .ts,.tsx --cache",
23
- "lint:fix": "eslint . --ext .ts,.tsx --fix",
24
- "prettier-base": "prettier \"**/*.{json,js,jsx,ts,tsx,yml,yaml,html,md}\"",
25
- "prettier": "npm run prettier-base -- --write",
26
- "prettier:check": "npm run prettier-base -- --check",
27
- "ts:check": "tsc --noEmit --skipLibCheck",
28
- "test": "jest",
29
- "test:watch": "jest --watch",
30
- "test:coverage": "jest --coverage",
31
- "prepare": "husky install",
32
- "chromatic": "chromatic --exit-zero-on-changes"
33
- },
34
- "peerDependencies": {
35
- "prismjs": "^1.28.0",
36
- "react": "^17.0.2",
37
- "react-dom": "^17.0.2",
38
- "styled-components": "^5.3.1"
39
- },
40
- "devDependencies": {
41
- "@storybook/addon-actions": "^6.4.22",
42
- "@storybook/addon-essentials": "^6.4.22",
43
- "@storybook/addon-interactions": "^6.4.22",
44
- "@storybook/addon-links": "^6.4.22",
45
- "@storybook/builder-webpack5": "^6.4.22",
46
- "@storybook/core-common": "^6.4.22",
47
- "@storybook/manager-webpack5": "^6.4.22",
48
- "@storybook/node-logger": "^6.4.22",
49
- "@storybook/preset-create-react-app": "^4.1.0",
50
- "@storybook/react": "^6.4.22",
51
- "@storybook/testing-library": "^0.0.11",
52
- "@testing-library/jest-dom": "^5.16.4",
53
- "@testing-library/react": "^12.1.4",
54
- "@testing-library/user-event": "^13.5.0",
55
- "@types/jest": "^27.4.1",
56
- "@types/node": "^16.11.26",
57
- "@types/prismjs": "^1.26.0",
58
- "@types/react": "^17.0.43",
59
- "@types/react-dom": "^17.0.14",
60
- "@types/styled-components": "^5.1.25",
61
- "@typescript-eslint/eslint-plugin": "^5.21.0",
62
- "@typescript-eslint/parser": "^5.22.0",
63
- "chromatic": "^6.5.4",
64
- "esbuild": "^0.14.38",
65
- "eslint": "^8.13.0",
66
- "eslint-config-prettier": "^8.5.0",
67
- "eslint-import-resolver-typescript": "^2.7.1",
68
- "eslint-plugin-import": "^2.26.0",
69
- "eslint-plugin-jest": "^26.1.4",
70
- "eslint-plugin-react": "^7.29.4",
71
- "eslint-plugin-react-hooks": "^4.5.0",
72
- "eslint-plugin-storybook": "^0.5.11",
73
- "husky": "^7.0.4",
74
- "jest": "^27.5.1",
75
- "jest-styled-components": "^7.0.8",
76
- "lint-staged": "^12.4.1",
77
- "prettier": "2.6.2",
78
- "react": "^17.0.2",
79
- "react-dom": "^17.0.2",
80
- "react-refresh": "^0.13.0",
81
- "react-scripts": "5.0.1",
82
- "styled-components": "^5.3.5",
83
- "ts-jest": "^27.1.4",
84
- "tsc-alias": "^1.6.7",
85
- "typescript": "^4.6.3",
86
- "webpack": "^5.72.0"
87
- },
88
- "lint-staged": {
89
- "**/*": "prettier --write --ignore-unknown"
90
- }
91
- }