@redocly/theme 0.1.0 → 0.1.1

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 (54) hide show
  1. package/{lib/src/index.ts → index.js} +0 -0
  2. package/package.json +1 -2
  3. package/LICENSE +0 -1
  4. package/lib/package.json +0 -91
  5. package/lib/src/Button/Button.tsx +0 -122
  6. package/lib/src/Button/index.ts +0 -1
  7. package/lib/src/CodeBlock/CodeBlock.ts +0 -125
  8. package/lib/src/CodeBlock/index.ts +0 -1
  9. package/lib/src/CopyButton/CopyButton.tsx +0 -26
  10. package/lib/src/CopyButton/CopyButtonWrapper.tsx +0 -52
  11. package/lib/src/CopyButton/index.ts +0 -2
  12. package/lib/src/Headings/Headings.ts +0 -23
  13. package/lib/src/Headings/index.ts +0 -1
  14. package/lib/src/JsonViewer/JsonViewer.tsx +0 -130
  15. package/lib/src/JsonViewer/index.ts +0 -1
  16. package/lib/src/JsonViewer/styled.ts +0 -103
  17. package/lib/src/Logo/Logo.tsx +0 -23
  18. package/lib/src/Navbar/Navbar.tsx +0 -60
  19. package/lib/src/Navbar/NavbarItem.tsx +0 -90
  20. package/lib/src/Navbar/NavbarMenu.tsx +0 -29
  21. package/lib/src/Panel/CodePanel.ts +0 -31
  22. package/lib/src/Panel/ContentPanel.ts +0 -43
  23. package/lib/src/Panel/DarkHeader.ts +0 -8
  24. package/lib/src/Panel/Panel.ts +0 -18
  25. package/lib/src/Panel/PanelBody.ts +0 -30
  26. package/lib/src/Panel/PanelComponent.tsx +0 -73
  27. package/lib/src/Panel/PanelHeader.ts +0 -25
  28. package/lib/src/Panel/PanelHeaderTitle.ts +0 -11
  29. package/lib/src/Panel/index.ts +0 -7
  30. package/lib/src/SamplesPanelControls/SamplesPanelControls.ts +0 -70
  31. package/lib/src/SamplesPanelControls/index.ts +0 -1
  32. package/lib/src/SidebarLogo/SidebarLogo.tsx +0 -47
  33. package/lib/src/SidebarLogo/index.ts +0 -1
  34. package/lib/src/SourceCode/SourceCode.tsx +0 -67
  35. package/lib/src/SourceCode/index.ts +0 -1
  36. package/lib/src/Tooltip/Tooltip.tsx +0 -171
  37. package/lib/src/Tooltip/index.ts +0 -1
  38. package/lib/src/globalStyle.ts +0 -512
  39. package/lib/src/hooks/index.ts +0 -3
  40. package/lib/src/hooks/useControl.ts +0 -20
  41. package/lib/src/hooks/useMount.ts +0 -8
  42. package/lib/src/hooks/useUnmount.ts +0 -10
  43. package/lib/src/icons/ShelfIcon/ShelfIcon.tsx +0 -45
  44. package/lib/src/icons/ShelfIcon/index.ts +0 -2
  45. package/lib/src/icons/index.ts +0 -1
  46. package/lib/src/mocks/Link.tsx +0 -7
  47. package/lib/src/mocks/utils.ts +0 -3
  48. package/lib/src/utils/ClipboardService.ts +0 -92
  49. package/lib/src/utils/css-variables.ts +0 -2
  50. package/lib/src/utils/highlight.ts +0 -81
  51. package/lib/src/utils/index.ts +0 -6
  52. package/lib/src/utils/jsonToHtml.ts +0 -122
  53. package/lib/src/utils/media-css.ts +0 -16
  54. package/lib/src/utils/theme-helpers.ts +0 -34
@@ -1,92 +0,0 @@
1
- export class ClipboardService {
2
- static isSupported(): boolean {
3
- return (
4
- typeof document !== 'undefined' &&
5
- !!document.queryCommandSupported &&
6
- document.queryCommandSupported('copy')
7
- );
8
- }
9
-
10
- static selectElement(element: HTMLDivElement | null): void {
11
- if (!element) {
12
- return;
13
- }
14
- let range;
15
- let selection;
16
- if ((document.body as any).createTextRange) {
17
- range = (document.body as any).createTextRange();
18
- range.moveToElementText(element);
19
- range.select();
20
- } else if (document.createRange && window.getSelection) {
21
- selection = window.getSelection();
22
- range = document.createRange();
23
- range.selectNodeContents(element);
24
- selection?.removeAllRanges();
25
- selection?.addRange(range);
26
- }
27
- }
28
-
29
- static deselect(): void {
30
- if ((document as any).selection) {
31
- (document as any).selection.empty();
32
- } else if (window.getSelection) {
33
- const selection = window.getSelection();
34
- if (selection) {
35
- selection.removeAllRanges();
36
- }
37
- }
38
- }
39
-
40
- static copySelected(): boolean {
41
- let result;
42
- try {
43
- result = document.execCommand('copy');
44
- } catch (err) {
45
- result = false;
46
- }
47
- return result;
48
- }
49
-
50
- static copyElement(element: HTMLDivElement | null): boolean {
51
- ClipboardService.selectElement(element);
52
- const res = ClipboardService.copySelected();
53
- if (res) {
54
- ClipboardService.deselect();
55
- }
56
- return res;
57
- }
58
-
59
- static copyCustom(text: string): boolean {
60
- const textArea = document.createElement('textarea');
61
- textArea.style.position = 'fixed';
62
- textArea.style.top = '0';
63
- textArea.style.left = '0';
64
-
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
-
70
- // We don't need padding, reducing the size if it does flash render.
71
- textArea.style.padding = '0';
72
-
73
- // Clean up any borders.
74
- textArea.style.border = 'none';
75
- textArea.style.outline = 'none';
76
- textArea.style.boxShadow = 'none';
77
-
78
- // Avoid flash of white box if rendered for any reason.
79
- textArea.style.background = 'transparent';
80
-
81
- textArea.value = text;
82
-
83
- document.body.appendChild(textArea);
84
-
85
- textArea.select();
86
-
87
- const res = ClipboardService.copySelected();
88
-
89
- document.body.removeChild(textArea);
90
- return res;
91
- }
92
- }
@@ -1,2 +0,0 @@
1
- export const getCssColorVariable = (color: string | undefined, defaultValue = 'inherit'): string =>
2
- color?.startsWith('--') ? `var(${color})` : color || defaultValue;
@@ -1,81 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
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';
@@ -1,122 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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
- }
@@ -1,34 +0,0 @@
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
- }