@redocly/theme 0.1.12 → 0.1.13
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/CodeBlock/CodeBlock.js +2 -1
- package/Markdown/StyledMarkdown.d.ts +0 -2
- package/Markdown/StyledMarkdown.js +5 -16
- package/Markdown/index.d.ts +0 -1
- package/Markdown/index.js +0 -1
- package/OperationBadge/OperationBadge.js +1 -1
- package/globalStyle.js +1 -1
- package/package.json +1 -1
- package/src/CodeBlock/CodeBlock.ts +3 -42
- package/src/Markdown/StyledMarkdown.tsx +14 -28
- package/src/Markdown/index.ts +0 -1
- package/src/OperationBadge/OperationBadge.ts +5 -2
- package/src/globalStyle.ts +36 -0
- package/src/ui/Typography.tsx +10 -87
- package/src/utils/ClipboardService.ts +3 -86
- package/src/utils/theme-helpers.ts +46 -0
- package/ui/Typography.d.ts +2 -71
- package/ui/Typography.js +15 -93
- package/utils/ClipboardService.d.ts +1 -5
- package/utils/ClipboardService.js +2 -73
- package/utils/theme-helpers.d.ts +1 -0
- package/utils/theme-helpers.js +42 -2
- package/Markdown/CodeSample/CodeSample.d.ts +0 -8
- package/Markdown/CodeSample/CodeSample.js +0 -30
- package/Markdown/CodeSample/index.d.ts +0 -3
- package/Markdown/CodeSample/index.js +0 -19
- package/Markdown/CodeSample/styled.d.ts +0 -5
- package/Markdown/CodeSample/styled.js +0 -109
- package/Markdown/CodeSample/types.d.ts +0 -9
- package/Markdown/CodeSample/types.js +0 -2
- package/src/Markdown/CodeSample/CodeSample.tsx +0 -39
- package/src/Markdown/CodeSample/index.ts +0 -3
- package/src/Markdown/CodeSample/styled.ts +0 -289
- package/src/Markdown/CodeSample/types.ts +0 -40
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
-
}) : function(o, v) {
|
|
20
|
-
o["default"] = v;
|
|
21
|
-
});
|
|
22
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
-
if (mod && mod.__esModule) return mod;
|
|
24
|
-
var result = {};
|
|
25
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
-
__setModuleDefault(result, mod);
|
|
27
|
-
return result;
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Wrapper = exports.DoneIndicator = exports.CopyCodeButton = exports.CodeSampleButtonContainer = exports.CodeButton = void 0;
|
|
31
|
-
var polished_1 = require("polished");
|
|
32
|
-
var styled_components_1 = __importStar(require("styled-components"));
|
|
33
|
-
var Typography_1 = require("../../ui/Typography");
|
|
34
|
-
function genTokens(tokens) {
|
|
35
|
-
var _a;
|
|
36
|
-
if (!tokens) {
|
|
37
|
-
return '';
|
|
38
|
-
}
|
|
39
|
-
var res = '';
|
|
40
|
-
for (var _i = 0, _b = Object.keys(tokens); _i < _b.length; _i++) {
|
|
41
|
-
var token = _b[_i];
|
|
42
|
-
if (token !== 'default') {
|
|
43
|
-
res += ".token.".concat(token, " { color: ").concat((_a = tokens[token]) === null || _a === void 0 ? void 0 : _a.color, "; }\n");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (tokens.default) {
|
|
47
|
-
return (0, styled_components_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n pre& {\n ", "\n }\n ", "\n "], ["\n pre& {\n ", "\n }\n ", "\n "])), (0, Typography_1.typography)(tokens.default), res);
|
|
48
|
-
}
|
|
49
|
-
return res;
|
|
50
|
-
}
|
|
51
|
-
var getCodeBlockBackgroundColor = function (theme) {
|
|
52
|
-
return Array.isArray(theme.codeBlock.backgroundColor)
|
|
53
|
-
? theme.codeBlock.backgroundColor[0]
|
|
54
|
-
: theme.codeBlock.backgroundColor;
|
|
55
|
-
};
|
|
56
|
-
exports.CodeButton = (0, styled_components_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n padding: 0 5px;\n border-radius: 4px;\n"], ["\n padding: 0 5px;\n border-radius: 4px;\n"])));
|
|
57
|
-
exports.CodeSampleButtonContainer = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n position: absolute;\n top: 12px;\n right: 5px;\n"], ["\n position: absolute;\n top: 12px;\n right: 5px;\n"])));
|
|
58
|
-
exports.CopyCodeButton = styled_components_1.default.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n ", "\n display: none;\n\n &:hover {\n cursor: pointer;\n }\n"], ["\n ", "\n display: none;\n\n &:hover {\n cursor: pointer;\n }\n"])), exports.CodeButton);
|
|
59
|
-
exports.DoneIndicator = styled_components_1.default.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n ", "\n cursor: default;\n"], ["\n ", "\n cursor: default;\n"])), exports.CodeButton);
|
|
60
|
-
var lightStyleCodeButton = (0, styled_components_1.css)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n ", ",\n ", " {\n color: ", ";\n }\n\n ", ":hover {\n color: ", ";\n outline: 1px solid ", ";\n }\n"], ["\n ", ",\n ", " {\n color: ", ";\n }\n\n ", ":hover {\n color: ", ";\n outline: 1px solid ", ";\n }\n"])), exports.CopyCodeButton, exports.DoneIndicator, function (_a) {
|
|
61
|
-
var theme = _a.theme;
|
|
62
|
-
return theme.codeBlock.copyButton.visibleText;
|
|
63
|
-
}, exports.CopyCodeButton, function (_a) {
|
|
64
|
-
var theme = _a.theme;
|
|
65
|
-
return theme.codeBlock.copyButton.visibleText;
|
|
66
|
-
}, function (_a) {
|
|
67
|
-
var theme = _a.theme;
|
|
68
|
-
return theme.codeBlock.copyButton.visibleText;
|
|
69
|
-
});
|
|
70
|
-
var darkStyleCodeButton = (0, styled_components_1.css)(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n ", ",\n ", " {\n color: ", ";\n }\n\n ", ":hover {\n color: white;\n color: ", ";\n background-color: ", ";\n }\n"], ["\n ", ",\n ", " {\n color: ", ";\n }\n\n ", ":hover {\n color: white;\n color: ", ";\n background-color: ", ";\n }\n"])), exports.CopyCodeButton, exports.DoneIndicator, function (_a) {
|
|
71
|
-
var theme = _a.theme;
|
|
72
|
-
return theme.codeBlock.copyButton.visibleText;
|
|
73
|
-
}, exports.CopyCodeButton, function (_a) {
|
|
74
|
-
var theme = _a.theme;
|
|
75
|
-
return theme.codeBlock.copyButton.contrastText;
|
|
76
|
-
}, function (_a) {
|
|
77
|
-
var theme = _a.theme;
|
|
78
|
-
return theme.codeBlock.copyButton.background;
|
|
79
|
-
});
|
|
80
|
-
var lightStyleTokens = (0, styled_components_1.css)(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n .token.comment,\n .token.prolog,\n .token.doctype,\n .token.cdata {\n color: #999988;\n font-style: italic;\n }\n\n .token.namespace {\n opacity: 0.7;\n }\n\n .token.string,\n .token.attr-value {\n color: #e3116c;\n }\n .token.punctuation,\n .token.operator {\n color: #393a34; /* no highlight */\n }\n\n .token.entity,\n .token.url,\n .token.symbol,\n .token.number,\n .token.boolean,\n .token.variable,\n .token.constant,\n .token.property,\n .token.regex,\n .token.inserted {\n color: #36acaa;\n }\n\n .token.atrule,\n .token.keyword,\n .token.attr-name,\n .language-autohotkey .token.selector {\n color: #00a4db;\n }\n\n .token.function,\n .token.deleted,\n .language-autohotkey .token.tag {\n color: #9a050f;\n }\n\n .token.tag,\n .token.selector,\n .language-autohotkey .token.keyword {\n color: #00009f;\n }\n"], ["\n .token.comment,\n .token.prolog,\n .token.doctype,\n .token.cdata {\n color: #999988;\n font-style: italic;\n }\n\n .token.namespace {\n opacity: 0.7;\n }\n\n .token.string,\n .token.attr-value {\n color: #e3116c;\n }\n .token.punctuation,\n .token.operator {\n color: #393a34; /* no highlight */\n }\n\n .token.entity,\n .token.url,\n .token.symbol,\n .token.number,\n .token.boolean,\n .token.variable,\n .token.constant,\n .token.property,\n .token.regex,\n .token.inserted {\n color: #36acaa;\n }\n\n .token.atrule,\n .token.keyword,\n .token.attr-name,\n .language-autohotkey .token.selector {\n color: #00a4db;\n }\n\n .token.function,\n .token.deleted,\n .language-autohotkey .token.tag {\n color: #9a050f;\n }\n\n .token.tag,\n .token.selector,\n .language-autohotkey .token.keyword {\n color: #00009f;\n }\n"])));
|
|
81
|
-
var darkStyleTokens = (0, styled_components_1.css)(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n .token.comment,\n .token.prolog,\n .token.doctype,\n .token.cdata {\n color: hsl(30, 20%, 50%);\n }\n\n .token.property,\n .token.tag,\n .token.number,\n .token.constant,\n .token.symbol {\n color: #62bff9;\n }\n .token.boolean {\n color: firebrick;\n }\n .token.selector,\n .token.attr-name,\n .token.string,\n .token.char,\n .token.builtin,\n .token.inserted {\n color: #a0fbaa;\n & + a,\n & + a:visited {\n color: #4ed2ba;\n text-decoration: underline;\n }\n }\n .token.operator,\n .token.entity,\n .token.url,\n .token.variable {\n color: hsl(40, 90%, 60%);\n }\n .token.atrule,\n .token.attr-value,\n .token.keyword {\n color: hsl(350, 40%, 70%);\n }\n .token.regex,\n .token.important {\n color: #e90;\n }\n\n .token.deleted {\n color: red;\n }\n"], ["\n .token.comment,\n .token.prolog,\n .token.doctype,\n .token.cdata {\n color: hsl(30, 20%, 50%);\n }\n\n .token.property,\n .token.tag,\n .token.number,\n .token.constant,\n .token.symbol {\n color: #62bff9;\n }\n .token.boolean {\n color: firebrick;\n }\n .token.selector,\n .token.attr-name,\n .token.string,\n .token.char,\n .token.builtin,\n .token.inserted {\n color: #a0fbaa;\n & + a,\n & + a:visited {\n color: #4ed2ba;\n text-decoration: underline;\n }\n }\n .token.operator,\n .token.entity,\n .token.url,\n .token.variable {\n color: hsl(40, 90%, 60%);\n }\n .token.atrule,\n .token.attr-value,\n .token.keyword {\n color: hsl(350, 40%, 70%);\n }\n .token.regex,\n .token.important {\n color: #e90;\n }\n\n .token.deleted {\n color: red;\n }\n"])));
|
|
82
|
-
exports.Wrapper = styled_components_1.default.div(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n overflow: auto;\n border-radius: 4px;\n position: relative;\n\n ", "\n\n &:hover {\n ", " ", " {\n display: block;\n }\n }\n\n pre {\n white-space: ", ";\n color: white;\n padding: 12px 14px 15px 14px;\n overflow-x: auto;\n line-height: normal;\n border-radius: 4px;\n\n font-family: ", ";\n background-color: ", ";\n\n code {\n background-color: transparent;\n border: 0;\n padding: 0;\n\n color: ", ";\n\n &:before,\n &:after {\n content: none;\n }\n }\n }\n\n pre[class*='language-'] {\n padding: 1em;\n margin: 0.5em 0;\n overflow: auto;\n border: 0;\n border-radius: ", ";\n }\n\n code[class='language-text'] {\n line-height: 1.2em;\n display: inline-flex;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n }\n\n code[class*='language-'],\n pre[class*='language-'] {\n text-align: left;\n white-space: pre;\n word-spacing: normal;\n word-break: normal;\n word-wrap: normal;\n line-height: 1.5;\n -moz-tab-size: 4;\n -o-tab-size: 4;\n tab-size: 4;\n -webkit-hyphens: none;\n -moz-hyphens: none;\n -ms-hyphens: none;\n hyphens: none;\n\n .token.important,\n .token.bold {\n font-weight: bold;\n }\n .token.italic {\n font-style: italic;\n }\n .token.entity {\n cursor: help;\n }\n .token.punctuation {\n opacity: 0.7;\n }\n .namespace {\n opacity: 0.7;\n }\n\n ", "\n ", "\n }\n"], ["\n overflow: auto;\n border-radius: 4px;\n position: relative;\n\n ", "\n\n &:hover {\n ", " ", " {\n display: block;\n }\n }\n\n pre {\n white-space: ", ";\n color: white;\n padding: 12px 14px 15px 14px;\n overflow-x: auto;\n line-height: normal;\n border-radius: 4px;\n\n font-family: ", ";\n background-color: ", ";\n\n code {\n background-color: transparent;\n border: 0;\n padding: 0;\n\n color: ", ";\n\n &:before,\n &:after {\n content: none;\n }\n }\n }\n\n pre[class*='language-'] {\n padding: 1em;\n margin: 0.5em 0;\n overflow: auto;\n border: 0;\n border-radius: ", ";\n }\n\n code[class='language-text'] {\n line-height: 1.2em;\n display: inline-flex;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n }\n\n code[class*='language-'],\n pre[class*='language-'] {\n text-align: left;\n white-space: pre;\n word-spacing: normal;\n word-break: normal;\n word-wrap: normal;\n line-height: 1.5;\n -moz-tab-size: 4;\n -o-tab-size: 4;\n tab-size: 4;\n -webkit-hyphens: none;\n -moz-hyphens: none;\n -ms-hyphens: none;\n hyphens: none;\n\n .token.important,\n .token.bold {\n font-weight: bold;\n }\n .token.italic {\n font-style: italic;\n }\n .token.entity {\n cursor: help;\n }\n .token.punctuation {\n opacity: 0.7;\n }\n .namespace {\n opacity: 0.7;\n }\n\n ", "\n ", "\n }\n"])), function (_a) {
|
|
83
|
-
var theme = _a.theme;
|
|
84
|
-
return (0, polished_1.getLuminance)(getCodeBlockBackgroundColor(theme)) < 0.25
|
|
85
|
-
? darkStyleCodeButton
|
|
86
|
-
: lightStyleCodeButton;
|
|
87
|
-
}, exports.CodeSampleButtonContainer, exports.CopyCodeButton, function (_a) {
|
|
88
|
-
var theme = _a.theme;
|
|
89
|
-
return (theme.typography.code.wrap ? 'pre-wrap' : 'pre');
|
|
90
|
-
}, function (_a) {
|
|
91
|
-
var theme = _a.theme;
|
|
92
|
-
return theme.typography.code.fontFamily;
|
|
93
|
-
}, function (_a) {
|
|
94
|
-
var theme = _a.theme;
|
|
95
|
-
return theme.codeBlock.backgroundColor;
|
|
96
|
-
}, function (_a) {
|
|
97
|
-
var theme = _a.theme;
|
|
98
|
-
return (0, polished_1.getLuminance)(theme.codeBlock.backgroundColor) < 0.5 ? 'white' : '#393A34';
|
|
99
|
-
}, function (_a) {
|
|
100
|
-
var theme = _a.theme;
|
|
101
|
-
return theme.shape.borderRadius;
|
|
102
|
-
}, function (_a) {
|
|
103
|
-
var theme = _a.theme;
|
|
104
|
-
return (0, polished_1.getLuminance)(getCodeBlockBackgroundColor(theme)) < 0.5 ? darkStyleTokens : lightStyleTokens;
|
|
105
|
-
}, function (_a) {
|
|
106
|
-
var theme = _a.theme;
|
|
107
|
-
return genTokens(theme.codeBlock.tokens);
|
|
108
|
-
});
|
|
109
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ITypography } from '../../ui/Typography';
|
|
2
|
-
export declare type Token = 'comment' | 'prolog' | 'doctype' | 'cdata' | 'punctuation' | 'property' | 'tag' | 'number' | 'constant' | 'symbol' | 'boolean' | 'selector' | 'string' | 'char' | 'builtin' | 'inserted' | 'operator' | 'entity' | 'url' | 'variable' | 'atrule' | 'keyword' | 'regex' | 'important' | 'important' | 'bold' | 'italic' | 'entity' | 'deleted';
|
|
3
|
-
export declare type Tokens = {
|
|
4
|
-
[P in Token]?: {
|
|
5
|
-
color: string;
|
|
6
|
-
};
|
|
7
|
-
} & {
|
|
8
|
-
default?: ITypography;
|
|
9
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import { ClipboardService } from '@theme/utils/ClipboardService';
|
|
4
|
-
import {
|
|
5
|
-
Wrapper,
|
|
6
|
-
DoneIndicator,
|
|
7
|
-
CopyCodeButton,
|
|
8
|
-
CodeSampleButtonContainer,
|
|
9
|
-
} from '@theme/Markdown/CodeSample/styled';
|
|
10
|
-
|
|
11
|
-
type CodeSampleProps = {
|
|
12
|
-
language: string;
|
|
13
|
-
highlighted: string;
|
|
14
|
-
rawContent: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export function CodeSample({ rawContent, highlighted, language }: CodeSampleProps): JSX.Element {
|
|
18
|
-
const langClassName = language ? `language-${language}` : '';
|
|
19
|
-
|
|
20
|
-
const [isCopied, setIsCopied] = useState(false);
|
|
21
|
-
|
|
22
|
-
const copyCode = (code: string) => {
|
|
23
|
-
ClipboardService.copyCustom(code);
|
|
24
|
-
setIsCopied(true);
|
|
25
|
-
setTimeout(() => setIsCopied(false), 1500);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<Wrapper className="code-sample" data-component-name="Markdown/CodeSample/CodeSample">
|
|
30
|
-
<CodeSampleButtonContainer onClick={() => copyCode(rawContent)}>
|
|
31
|
-
{!isCopied && <CopyCodeButton title="Copy the code snippet">Copy</CopyCodeButton>}
|
|
32
|
-
{isCopied && <DoneIndicator>Copied</DoneIndicator>}
|
|
33
|
-
</CodeSampleButtonContainer>
|
|
34
|
-
<pre className={langClassName}>
|
|
35
|
-
<code className={langClassName} dangerouslySetInnerHTML={{ __html: highlighted }} />
|
|
36
|
-
</pre>
|
|
37
|
-
</Wrapper>
|
|
38
|
-
);
|
|
39
|
-
}
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { getLuminance } from 'polished';
|
|
2
|
-
import styled, { css } from 'styled-components';
|
|
3
|
-
|
|
4
|
-
import { typography } from '@theme/ui/Typography';
|
|
5
|
-
import type { Tokens, Token } from '@theme/Markdown/CodeSample/types';
|
|
6
|
-
import { AppTheme } from '@theme/types/portal';
|
|
7
|
-
|
|
8
|
-
function genTokens(tokens?: Tokens | null) {
|
|
9
|
-
if (!tokens) {
|
|
10
|
-
return '';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let res = '';
|
|
14
|
-
|
|
15
|
-
for (const token of Object.keys(tokens)) {
|
|
16
|
-
if (token !== 'default') {
|
|
17
|
-
res += `.token.${token} { color: ${tokens[token as Token]?.color}; }\n`;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (tokens.default) {
|
|
22
|
-
return css`
|
|
23
|
-
pre& {
|
|
24
|
-
${typography(tokens.default)}
|
|
25
|
-
}
|
|
26
|
-
${res}
|
|
27
|
-
`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return res;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const getCodeBlockBackgroundColor = (theme: AppTheme) =>
|
|
34
|
-
Array.isArray(theme.codeBlock.backgroundColor)
|
|
35
|
-
? theme.codeBlock.backgroundColor[0]
|
|
36
|
-
: theme.codeBlock.backgroundColor;
|
|
37
|
-
|
|
38
|
-
export const CodeButton = css`
|
|
39
|
-
padding: 0 5px;
|
|
40
|
-
border-radius: 4px;
|
|
41
|
-
`;
|
|
42
|
-
|
|
43
|
-
export const CodeSampleButtonContainer = styled.div`
|
|
44
|
-
position: absolute;
|
|
45
|
-
top: 12px;
|
|
46
|
-
right: 5px;
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
export const CopyCodeButton = styled.div`
|
|
50
|
-
${CodeButton}
|
|
51
|
-
display: none;
|
|
52
|
-
|
|
53
|
-
&:hover {
|
|
54
|
-
cursor: pointer;
|
|
55
|
-
}
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
export const DoneIndicator = styled.div`
|
|
59
|
-
${CodeButton}
|
|
60
|
-
cursor: default;
|
|
61
|
-
`;
|
|
62
|
-
|
|
63
|
-
const lightStyleCodeButton = css`
|
|
64
|
-
${CopyCodeButton},
|
|
65
|
-
${DoneIndicator} {
|
|
66
|
-
color: ${({ theme }) => theme.codeBlock.copyButton.visibleText};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
${CopyCodeButton}:hover {
|
|
70
|
-
color: ${({ theme }) => theme.codeBlock.copyButton.visibleText};
|
|
71
|
-
outline: 1px solid ${({ theme }) => theme.codeBlock.copyButton.visibleText};
|
|
72
|
-
}
|
|
73
|
-
`;
|
|
74
|
-
|
|
75
|
-
const darkStyleCodeButton = css`
|
|
76
|
-
${CopyCodeButton},
|
|
77
|
-
${DoneIndicator} {
|
|
78
|
-
color: ${({ theme }) => theme.codeBlock.copyButton.visibleText};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
${CopyCodeButton}:hover {
|
|
82
|
-
color: white;
|
|
83
|
-
color: ${({ theme }) => theme.codeBlock.copyButton.contrastText};
|
|
84
|
-
background-color: ${({ theme }) => theme.codeBlock.copyButton.background};
|
|
85
|
-
}
|
|
86
|
-
`;
|
|
87
|
-
|
|
88
|
-
const lightStyleTokens = css`
|
|
89
|
-
.token.comment,
|
|
90
|
-
.token.prolog,
|
|
91
|
-
.token.doctype,
|
|
92
|
-
.token.cdata {
|
|
93
|
-
color: #999988;
|
|
94
|
-
font-style: italic;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
.token.namespace {
|
|
98
|
-
opacity: 0.7;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.token.string,
|
|
102
|
-
.token.attr-value {
|
|
103
|
-
color: #e3116c;
|
|
104
|
-
}
|
|
105
|
-
.token.punctuation,
|
|
106
|
-
.token.operator {
|
|
107
|
-
color: #393a34; /* no highlight */
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
.token.entity,
|
|
111
|
-
.token.url,
|
|
112
|
-
.token.symbol,
|
|
113
|
-
.token.number,
|
|
114
|
-
.token.boolean,
|
|
115
|
-
.token.variable,
|
|
116
|
-
.token.constant,
|
|
117
|
-
.token.property,
|
|
118
|
-
.token.regex,
|
|
119
|
-
.token.inserted {
|
|
120
|
-
color: #36acaa;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
.token.atrule,
|
|
124
|
-
.token.keyword,
|
|
125
|
-
.token.attr-name,
|
|
126
|
-
.language-autohotkey .token.selector {
|
|
127
|
-
color: #00a4db;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
.token.function,
|
|
131
|
-
.token.deleted,
|
|
132
|
-
.language-autohotkey .token.tag {
|
|
133
|
-
color: #9a050f;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
.token.tag,
|
|
137
|
-
.token.selector,
|
|
138
|
-
.language-autohotkey .token.keyword {
|
|
139
|
-
color: #00009f;
|
|
140
|
-
}
|
|
141
|
-
`;
|
|
142
|
-
|
|
143
|
-
const darkStyleTokens = css`
|
|
144
|
-
.token.comment,
|
|
145
|
-
.token.prolog,
|
|
146
|
-
.token.doctype,
|
|
147
|
-
.token.cdata {
|
|
148
|
-
color: hsl(30, 20%, 50%);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
.token.property,
|
|
152
|
-
.token.tag,
|
|
153
|
-
.token.number,
|
|
154
|
-
.token.constant,
|
|
155
|
-
.token.symbol {
|
|
156
|
-
color: #62bff9;
|
|
157
|
-
}
|
|
158
|
-
.token.boolean {
|
|
159
|
-
color: firebrick;
|
|
160
|
-
}
|
|
161
|
-
.token.selector,
|
|
162
|
-
.token.attr-name,
|
|
163
|
-
.token.string,
|
|
164
|
-
.token.char,
|
|
165
|
-
.token.builtin,
|
|
166
|
-
.token.inserted {
|
|
167
|
-
color: #a0fbaa;
|
|
168
|
-
& + a,
|
|
169
|
-
& + a:visited {
|
|
170
|
-
color: #4ed2ba;
|
|
171
|
-
text-decoration: underline;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
.token.operator,
|
|
175
|
-
.token.entity,
|
|
176
|
-
.token.url,
|
|
177
|
-
.token.variable {
|
|
178
|
-
color: hsl(40, 90%, 60%);
|
|
179
|
-
}
|
|
180
|
-
.token.atrule,
|
|
181
|
-
.token.attr-value,
|
|
182
|
-
.token.keyword {
|
|
183
|
-
color: hsl(350, 40%, 70%);
|
|
184
|
-
}
|
|
185
|
-
.token.regex,
|
|
186
|
-
.token.important {
|
|
187
|
-
color: #e90;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
.token.deleted {
|
|
191
|
-
color: red;
|
|
192
|
-
}
|
|
193
|
-
`;
|
|
194
|
-
|
|
195
|
-
export const Wrapper = styled.div`
|
|
196
|
-
overflow: auto;
|
|
197
|
-
border-radius: 4px;
|
|
198
|
-
position: relative;
|
|
199
|
-
|
|
200
|
-
${({ theme }) =>
|
|
201
|
-
getLuminance(getCodeBlockBackgroundColor(theme)) < 0.25
|
|
202
|
-
? darkStyleCodeButton
|
|
203
|
-
: lightStyleCodeButton}
|
|
204
|
-
|
|
205
|
-
&:hover {
|
|
206
|
-
${CodeSampleButtonContainer} ${CopyCodeButton} {
|
|
207
|
-
display: block;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
pre {
|
|
212
|
-
white-space: ${({ theme }) => (theme.typography.code.wrap ? 'pre-wrap' : 'pre')};
|
|
213
|
-
color: white;
|
|
214
|
-
padding: 12px 14px 15px 14px;
|
|
215
|
-
overflow-x: auto;
|
|
216
|
-
line-height: normal;
|
|
217
|
-
border-radius: 4px;
|
|
218
|
-
|
|
219
|
-
font-family: ${({ theme }) => theme.typography.code.fontFamily};
|
|
220
|
-
background-color: ${({ theme }) => theme.codeBlock.backgroundColor};
|
|
221
|
-
|
|
222
|
-
code {
|
|
223
|
-
background-color: transparent;
|
|
224
|
-
border: 0;
|
|
225
|
-
padding: 0;
|
|
226
|
-
|
|
227
|
-
color: ${({ theme }) =>
|
|
228
|
-
getLuminance(theme.codeBlock.backgroundColor) < 0.5 ? 'white' : '#393A34'};
|
|
229
|
-
|
|
230
|
-
&:before,
|
|
231
|
-
&:after {
|
|
232
|
-
content: none;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
pre[class*='language-'] {
|
|
238
|
-
padding: 1em;
|
|
239
|
-
margin: 0.5em 0;
|
|
240
|
-
overflow: auto;
|
|
241
|
-
border: 0;
|
|
242
|
-
border-radius: ${({ theme }) => theme.shape.borderRadius};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
code[class='language-text'] {
|
|
246
|
-
line-height: 1.2em;
|
|
247
|
-
display: inline-flex;
|
|
248
|
-
white-space: pre-wrap;
|
|
249
|
-
overflow-wrap: anywhere;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
code[class*='language-'],
|
|
253
|
-
pre[class*='language-'] {
|
|
254
|
-
text-align: left;
|
|
255
|
-
white-space: pre;
|
|
256
|
-
word-spacing: normal;
|
|
257
|
-
word-break: normal;
|
|
258
|
-
word-wrap: normal;
|
|
259
|
-
line-height: 1.5;
|
|
260
|
-
-moz-tab-size: 4;
|
|
261
|
-
-o-tab-size: 4;
|
|
262
|
-
tab-size: 4;
|
|
263
|
-
-webkit-hyphens: none;
|
|
264
|
-
-moz-hyphens: none;
|
|
265
|
-
-ms-hyphens: none;
|
|
266
|
-
hyphens: none;
|
|
267
|
-
|
|
268
|
-
.token.important,
|
|
269
|
-
.token.bold {
|
|
270
|
-
font-weight: bold;
|
|
271
|
-
}
|
|
272
|
-
.token.italic {
|
|
273
|
-
font-style: italic;
|
|
274
|
-
}
|
|
275
|
-
.token.entity {
|
|
276
|
-
cursor: help;
|
|
277
|
-
}
|
|
278
|
-
.token.punctuation {
|
|
279
|
-
opacity: 0.7;
|
|
280
|
-
}
|
|
281
|
-
.namespace {
|
|
282
|
-
opacity: 0.7;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
${({ theme }) =>
|
|
286
|
-
getLuminance(getCodeBlockBackgroundColor(theme)) < 0.5 ? darkStyleTokens : lightStyleTokens}
|
|
287
|
-
${({ theme }) => genTokens(theme.codeBlock.tokens)}
|
|
288
|
-
}
|
|
289
|
-
`;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { ITypography } from '@theme/ui/Typography';
|
|
2
|
-
|
|
3
|
-
export type Token =
|
|
4
|
-
| 'comment'
|
|
5
|
-
| 'prolog'
|
|
6
|
-
| 'doctype'
|
|
7
|
-
| 'cdata'
|
|
8
|
-
| 'punctuation'
|
|
9
|
-
| 'property'
|
|
10
|
-
| 'tag'
|
|
11
|
-
| 'number'
|
|
12
|
-
| 'constant'
|
|
13
|
-
| 'symbol'
|
|
14
|
-
| 'boolean'
|
|
15
|
-
| 'selector'
|
|
16
|
-
| 'string'
|
|
17
|
-
| 'char'
|
|
18
|
-
| 'builtin'
|
|
19
|
-
| 'inserted'
|
|
20
|
-
| 'operator'
|
|
21
|
-
| 'entity'
|
|
22
|
-
| 'url'
|
|
23
|
-
| 'variable'
|
|
24
|
-
| 'atrule'
|
|
25
|
-
| 'keyword'
|
|
26
|
-
| 'regex'
|
|
27
|
-
| 'important'
|
|
28
|
-
| 'important'
|
|
29
|
-
| 'bold'
|
|
30
|
-
| 'italic'
|
|
31
|
-
| 'entity'
|
|
32
|
-
| 'deleted';
|
|
33
|
-
|
|
34
|
-
export type Tokens = {
|
|
35
|
-
[P in Token]?: {
|
|
36
|
-
color: string;
|
|
37
|
-
};
|
|
38
|
-
} & {
|
|
39
|
-
default?: ITypography;
|
|
40
|
-
};
|