@yuntijs/ui 1.2.0-beta.5 → 1.2.0-beta.6

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.
@@ -13,6 +13,8 @@ export interface FullFeaturedHighlighterProps extends DivProps {
13
13
  */
14
14
  language: string;
15
15
  contentStyle?: React.CSSProperties;
16
+ enableTransformer?: boolean;
17
+ theme?: string;
16
18
  }
17
19
  export declare const FullFeaturedHighlighter: import("react").NamedExoticComponent<FullFeaturedHighlighterProps>;
18
20
  export * from './SyntaxHighlighter';
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
- var _excluded = ["children", "language", "className", "style", "allowChangeLanguage", "fileName", "icon", "contentStyle"];
4
+ var _excluded = ["children", "language", "className", "style", "allowChangeLanguage", "fileName", "icon", "contentStyle", "enableTransformer", "theme"];
5
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
7
  import { ActionIcon, CopyButton } from '@lobehub/ui';
@@ -31,6 +31,8 @@ export var FullFeaturedHighlighter = /*#__PURE__*/memo(function (_ref) {
31
31
  fileName = _ref.fileName,
32
32
  icon = _ref.icon,
33
33
  contentStyle = _ref.contentStyle,
34
+ enableTransformer = _ref.enableTransformer,
35
+ theme = _ref.theme,
34
36
  rest = _objectWithoutProperties(_ref, _excluded);
35
37
  var _useState = useState(true),
36
38
  _useState2 = _slicedToArray(_useState, 2),
@@ -90,11 +92,13 @@ export var FullFeaturedHighlighter = /*#__PURE__*/memo(function (_ref) {
90
92
  }
91
93
  })]
92
94
  }), /*#__PURE__*/_jsx(SyntaxHighlighter, {
95
+ enableTransformer: enableTransformer,
93
96
  language: lang === null || lang === void 0 ? void 0 : lang.toLowerCase(),
94
97
  style: expand ? contentStyle : _objectSpread(_objectSpread({}, contentStyle), {}, {
95
98
  height: 0,
96
99
  overflow: 'hidden'
97
100
  }),
101
+ theme: theme,
98
102
  children: children
99
103
  })]
100
104
  }));
@@ -3,5 +3,7 @@ import { DivProps } from "../../types";
3
3
  export interface SyntaxHighlighterProps extends DivProps {
4
4
  children: string;
5
5
  language: string;
6
+ enableTransformer?: boolean;
7
+ theme?: string;
6
8
  }
7
9
  export declare const SyntaxHighlighter: import("react").NamedExoticComponent<SyntaxHighlighterProps>;
@@ -1,5 +1,4 @@
1
1
  import { Icon } from '@lobehub/ui';
2
- import { useThemeMode } from 'antd-style';
3
2
  import { Loader2 } from 'lucide-react';
4
3
  import { memo } from 'react';
5
4
  import { Flexbox } from 'react-layout-kit';
@@ -11,19 +10,21 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
11
10
  export var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref) {
12
11
  var children = _ref.children,
13
12
  language = _ref.language,
13
+ enableTransformer = _ref.enableTransformer,
14
+ theme = _ref.theme,
14
15
  className = _ref.className,
15
16
  style = _ref.style;
16
- var _useStyles = useStyles(),
17
+ var _useStyles = useStyles({
18
+ theme: theme
19
+ }),
17
20
  styles = _useStyles.styles,
18
21
  cx = _useStyles.cx;
19
- var _useThemeMode = useThemeMode(),
20
- isDarkMode = _useThemeMode.isDarkMode;
21
- var _useHighlight = useHighlight(children.trim(), language, isDarkMode),
22
+ var _useHighlight = useHighlight(children.trim(), language, enableTransformer, theme),
22
23
  data = _useHighlight.data,
23
24
  isLoading = _useHighlight.isLoading;
24
25
  return /*#__PURE__*/_jsxs(_Fragment, {
25
26
  children: [isLoading || !data ? /*#__PURE__*/_jsx("div", {
26
- className: cx(styles.unshiki, className),
27
+ className: cx(styles.shiki, className),
27
28
  style: style,
28
29
  children: /*#__PURE__*/_jsx("pre", {
29
30
  children: /*#__PURE__*/_jsx("div", {
@@ -1,5 +1,6 @@
1
- export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
1
+ export declare const useStyles: (props?: {
2
+ theme?: string | undefined;
3
+ } | undefined) => import("antd-style").ReturnStyles<{
2
4
  loading: string;
3
5
  shiki: string;
4
- unshiki: import("antd-style").SerializedStyles;
5
6
  }>;
@@ -1,16 +1,16 @@
1
1
  import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
2
2
  var _templateObject, _templateObject2, _templateObject3;
3
3
  import { createStyles } from 'antd-style';
4
- export var useStyles = createStyles(function (_ref) {
4
+ export var useStyles = createStyles(function (_ref, _ref2) {
5
5
  var css = _ref.css,
6
6
  token = _ref.token,
7
7
  cx = _ref.cx,
8
8
  prefixCls = _ref.prefixCls,
9
9
  stylish = _ref.stylish;
10
+ var theme = _ref2.theme;
10
11
  var prefix = "".concat(prefixCls, "-highlighter");
11
12
  return {
12
- loading: cx(stylish.blur, css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 10;\n inset-block-start: 0;\n inset-inline-end: 0;\n\n height: 34px;\n padding-block: 0;\n padding-inline: 8px;\n\n font-family: ", ";\n color: ", ";\n\n border-radius: ", ";\n "])), token.fontFamilyCode, token.colorTextTertiary, token.borderRadius)),
13
- shiki: cx("".concat(prefix, "-shiki"), css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n overflow: auto;\n margin: 0;\n padding: 0;\n\n .shiki {\n overflow: unset;\n margin: 0;\n padding: 0;\n background: none !important;\n\n code {\n display: block;\n\n .line {\n display: inline-block;\n\n width: calc(100% + 32px);\n margin-block: 0;\n margin-inline: -16px;\n padding-block: 0;\n padding-inline: 16px;\n }\n }\n\n &.has-focused {\n .line:not(.focused) {\n opacity: 0.5;\n }\n }\n\n .highlighted {\n background: ", ";\n\n &.warning {\n background: ", ";\n }\n\n &.error {\n background: ", ";\n }\n }\n\n .highlighted-word {\n padding-block: 0.1em;\n padding-inline: 0.2em;\n\n background: ", ";\n border: 1px solid ", ";\n border-radius: ", "px;\n }\n\n .diff {\n &.remove {\n background: ", ";\n\n &::before {\n content: '-';\n\n position: absolute;\n inset-inline-start: 4px;\n\n display: inline-block;\n\n color: ", ";\n }\n }\n\n &.add {\n background: ", ";\n\n &::before {\n content: '+';\n\n position: absolute;\n inset-inline-start: 4px;\n\n display: inline-block;\n\n color: ", ";\n }\n }\n }\n }\n "])), token.colorFillTertiary, token.colorWarningBg, token.colorErrorBg, token.colorFillTertiary, token.colorBorderSecondary, token.borderRadius, token.colorErrorBg, token.colorErrorText, token.colorSuccessBg, token.colorSuccessText)),
14
- unshiki: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n overflow: auto;\n margin: 0;\n padding: 0;\n color: ", ";\n "])), token.colorTextDescription)
13
+ loading: cx(stylish.blur, css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 10;\n inset-block-start: 0;\n inset-inline-end: 0;\n\n height: 34px;\n padding-block: 0;\n padding-inline: 8px;\n\n font-family: ", ";\n color: ", ";\n\n border-radius: ", ";\n "])), token.fontFamilyCode, token.colorTextTertiary, token.borderRadius)),
14
+ shiki: cx("".concat(prefix, "-shiki"), css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n overflow: hidden;\n margin: 0;\n padding: 0;\n\n & > pre {\n overflow: auto;\n margin: 0;\n padding: 0;\n ", "\n\n code {\n display: block;\n\n .line {\n display: inline-block;\n\n width: calc(100% + 32px);\n margin-block: 0;\n margin-inline: -16px;\n padding-block: 0;\n padding-inline: 16px;\n }\n }\n\n &.has-focused {\n .line:not(.focused) {\n opacity: 0.5;\n }\n }\n\n .highlighted {\n background: ", ";\n\n &.warning {\n background: ", ";\n }\n\n &.error {\n background: ", ";\n }\n }\n\n .highlighted-word {\n padding-block: 0.1em;\n padding-inline: 0.2em;\n\n background: ", ";\n border: 1px solid ", ";\n border-radius: ", "px;\n }\n\n .diff {\n &.remove {\n background: ", ";\n\n &::before {\n content: '-';\n\n position: absolute;\n inset-inline-start: 4px;\n\n display: inline-block;\n\n color: ", ";\n }\n }\n\n &.add {\n background: ", ";\n\n &::before {\n content: '+';\n\n position: absolute;\n inset-inline-start: 4px;\n\n display: inline-block;\n\n color: ", ";\n }\n }\n }\n }\n "])), !theme && css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n background: none !important;\n "]))), token.colorFillTertiary, token.colorWarningBg, token.colorErrorBg, token.colorFillTertiary, token.colorBorderSecondary, token.borderRadius, token.colorErrorBg, token.colorErrorText, token.colorSuccessBg, token.colorSuccessText))
15
15
  };
16
16
  });
@@ -44,6 +44,8 @@ export interface HighlighterProps extends DivProps {
44
44
  * @default false
45
45
  */
46
46
  wrap?: boolean;
47
+ enableTransformer?: boolean;
48
+ theme?: string;
47
49
  }
48
50
  export declare const Highlighter: React.NamedExoticComponent<HighlighterProps>;
49
51
  export * from './FullFeatured';
@@ -2,7 +2,7 @@
2
2
 
3
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- var _excluded = ["fullFeatured", "copyButtonSize", "children", "language", "className", "style", "copyable", "showLanguage", "type", "spotlight", "allowChangeLanguage", "fileName", "icon", "contentStyle", "wrap"];
5
+ var _excluded = ["fullFeatured", "copyButtonSize", "children", "language", "className", "style", "copyable", "showLanguage", "type", "spotlight", "allowChangeLanguage", "fileName", "icon", "contentStyle", "wrap", "enableTransformer", "theme"];
6
6
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
7
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
8
  import { CopyButton, Spotlight, Tag } from '@lobehub/ui';
@@ -32,11 +32,13 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
32
32
  icon = _ref.icon,
33
33
  contentStyle = _ref.contentStyle,
34
34
  wrap = _ref.wrap,
35
+ enableTransformer = _ref.enableTransformer,
36
+ theme = _ref.theme,
35
37
  rest = _objectWithoutProperties(_ref, _excluded);
36
38
  var _useStyles = useStyles(type),
37
39
  styles = _useStyles.styles,
38
40
  cx = _useStyles.cx;
39
- var container = cx(styles.container, !wrap && styles.nowrap, className);
41
+ var container = cx(styles.container, wrap && styles.wrap, className);
40
42
  if (fullFeatured) return /*#__PURE__*/_jsx(FullFeaturedHighlighter, _objectSpread(_objectSpread({
41
43
  allowChangeLanguage: allowChangeLanguage,
42
44
  className: className,
@@ -44,7 +46,8 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
44
46
  fileName: fileName,
45
47
  icon: icon,
46
48
  language: language,
47
- style: style
49
+ style: style,
50
+ theme: theme
48
51
  }, rest), {}, {
49
52
  children: children
50
53
  }));
@@ -66,8 +69,10 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
66
69
  }), /*#__PURE__*/_jsx("div", {
67
70
  className: styles.scroller,
68
71
  children: /*#__PURE__*/_jsx(SyntaxHighlighter, {
72
+ enableTransformer: enableTransformer,
69
73
  language: language === null || language === void 0 ? void 0 : language.toLowerCase(),
70
74
  style: contentStyle,
75
+ theme: theme,
71
76
  children: children
72
77
  })
73
78
  })]
@@ -3,7 +3,7 @@ export declare const useStyles: (props?: "ghost" | "block" | "pure" | undefined)
3
3
  container: string;
4
4
  header: import("antd-style").SerializedStyles;
5
5
  lang: string;
6
- nowrap: import("antd-style").SerializedStyles;
6
+ wrap: import("antd-style").SerializedStyles;
7
7
  scroller: import("antd-style").SerializedStyles;
8
8
  select: import("antd-style").SerializedStyles;
9
9
  }>;
@@ -13,10 +13,10 @@ export var useStyles = createStyles(function (_ref, type) {
13
13
  var typeStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background-color: ", ";\n border: 1px solid ", ";\n\n &:hover {\n background-color: ", ";\n }\n "])), type === 'block' ? token.colorFillTertiary : 'transparent', type === 'block' ? 'transparent' : token.colorBorder, type === 'block' ? token.colorFillTertiary : token.colorFillQuaternary);
14
14
  return {
15
15
  button: cx(buttonHoverCls, css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 2;\n inset-block-start: ", ";\n inset-inline-end: ", ";\n\n opacity: 0;\n "])), type === 'pure' ? 0 : '12px', type === 'pure' ? 0 : '12px')),
16
- container: cx(prefix, type !== 'pure' && typeStylish, css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n border-radius: ", "px;\n transition: background-color 100ms ", ";\n\n &:hover {\n .", " {\n opacity: 1;\n }\n\n .", " {\n opacity: 1;\n }\n }\n\n .prism-code {\n background: none !important;\n }\n\n pre {\n overflow: auto hidden;\n\n margin: 0 !important;\n padding: ", " !important;\n\n white-space: break-spaces;\n\n background: none !important;\n }\n\n code {\n background: transparent !important;\n }\n "])), token.borderRadius, token.motionEaseOut, buttonHoverCls, langHoverCls, type === 'pure' ? 0 : "16px")),
16
+ container: cx(prefix, type !== 'pure' && typeStylish, css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n border-radius: ", "px;\n transition: background-color 100ms ", ";\n\n &:hover {\n .", " {\n opacity: 1;\n }\n\n .", " {\n opacity: 1;\n }\n }\n\n .prism-code {\n background: none !important;\n }\n\n pre {\n margin: 0 !important;\n padding: ", " !important;\n }\n "])), token.borderRadius, token.motionEaseOut, buttonHoverCls, langHoverCls, type === 'pure' ? 0 : "16px")),
17
17
  header: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n padding-block: 4px;\n padding-inline: 8px;\n background: ", ";\n "])), token.colorFillQuaternary),
18
18
  lang: cx(langHoverCls, stylish.blur, css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 2;\n inset-block-end: 12px;\n inset-inline-end: 4px;\n\n font-family: ", ";\n color: ", ";\n\n opacity: 0;\n\n transition: opacity 0.1s;\n "])), token.fontFamilyCode, token.colorTextSecondary)),
19
- nowrap: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n code {\n text-wrap: nowrap !important;\n }\n "]))),
19
+ wrap: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n pre {\n white-space: break-spaces;\n }\n "]))),
20
20
  scroller: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n overflow: auto;\n width: 100%;\n height: 100%;\n "]))),
21
21
  select: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n user-select: none;\n font-size: 14px;\n color: ", ";\n .", "-select-selection-item {\n min-width: 100px;\n padding-inline-end: 0 !important;\n color: ", ";\n text-align: center;\n }\n "])), token.colorTextDescription, prefixCls, token.colorTextDescription)
22
22
  };
@@ -1 +1 @@
1
- export var languageMap = ['abap', 'actionscript-3', 'ada', 'apache', 'apex', 'apl', 'applescript', 'ara', 'asm', 'astro', 'awk', 'ballerina', 'bat', 'beancount', 'berry', 'bibtex', 'bicep', 'blade', 'c', 'cadence', 'clarity', 'clojure', 'cmake', 'cobol', 'codeql', 'coffee', 'cpp', 'crystal', 'csharp', 'css', 'cue', 'cypher', 'd', 'dart', 'dax', 'diff', 'docker', 'dream-maker', 'elixir', 'elm', 'erb', 'erlang', 'fish', 'fsharp', 'gdresource', 'gdscript', 'gdshader', 'gherkin', 'git-commit', 'git-rebase', 'glimmer-js', 'glimmer-ts', 'glsl', 'gnuplot', 'go', 'graphql', 'groovy', 'hack', 'haml', 'handlebars', 'haskell', 'hcl', 'hjson', 'hlsl', 'html', 'http', 'imba', 'ini', 'java', 'javascript', 'jinja-html', 'jison', 'json', 'json5', 'jsonc', 'jsonl', 'jsonnet', 'jssm', 'jsx', 'julia', 'kotlin', 'kusto', 'latex', 'less', 'liquid', 'lisp', 'logo', 'lua', 'make', 'markdown', 'marko', 'matlab', 'mdc', 'mdx', 'mermaid', 'mojo', 'narrat', 'nextflow', 'nginx', 'nim', 'nix', 'objective-c', 'objective-cpp', 'ocaml', 'pascal', 'perl', 'php', 'plsql', 'postcss', 'powerquery', 'powershell', 'prisma', 'prolog', 'proto', 'pug', 'puppet', 'purescript', 'python', 'r', 'raku', 'razor', 'reg', 'rel', 'riscv', 'rst', 'ruby', 'rust', 'sas', 'sass', 'scala', 'scheme', 'scss', 'shaderlab', 'shellscript', 'shellsession', 'smalltalk', 'solidity', 'sparql', 'splunk', 'sql', 'ssh-config', 'stata', 'stylus', 'svelte', 'swift', 'system-verilog', 'tasl', 'tcl', 'tex', 'toml', 'tsx', 'turtle', 'twig', 'typescript', 'v', 'vb', 'verilog', 'vhdl', 'viml', 'vue', 'vue-html', 'vyper', 'wasm', 'wenyan', 'wgsl', 'wolfram', 'xml', 'xsl', 'yaml', 'zenscript', 'zig', 'bash', 'batch', 'be', 'c#', 'cdc', 'clj', 'cmd', 'console', 'cql', 'cs', 'dockerfile', 'erl', 'f#', 'fs', 'fsl', 'gjs', 'gts', 'hbs', 'hs', 'jade', 'js', 'kql', 'makefile', 'md', 'nar', 'nf', 'objc', 'perl6', 'properties', 'ps', 'ps1', 'py', 'ql', 'rb', 'rs', 'sh', 'shader', 'shell', 'spl', 'styl', 'ts', 'vim', 'vimscript', 'vy', 'yml', 'zsh', '文言'];
1
+ export var languageMap = ['abap', 'actionscript-3', 'ada', 'apache', 'apex', 'apl', 'applescript', 'ara', 'asm', 'astro', 'awk', 'ballerina', 'bat', 'beancount', 'berry', 'bibtex', 'bicep', 'blade', 'c', 'cadence', 'clarity', 'clojure', 'cmake', 'cobol', 'codeql', 'coffee', 'cpp', 'crystal', 'csharp', 'css', 'cue', 'cypher', 'd', 'dart', 'dax', 'diff', 'docker', 'dream-maker', 'elixir', 'elm', 'erb', 'erlang', 'fish', 'fsharp', 'gdresource', 'gdscript', 'gdshader', 'gherkin', 'git-commit', 'git-rebase', 'glimmer-js', 'glimmer-ts', 'glsl', 'gnuplot', 'go', 'graphql', 'groovy', 'hack', 'haml', 'handlebars', 'haskell', 'hcl', 'hjson', 'hlsl', 'html', 'http', 'imba', 'ini', 'java', 'javascript', 'jinja-html', 'jison', 'json', 'json5', 'jsonc', 'jsonl', 'jsonnet', 'jssm', 'jsx', 'julia', 'kotlin', 'kusto', 'latex', 'less', 'liquid', 'lisp', 'logo', 'lua', 'make', 'markdown', 'marko', 'matlab', 'mdc', 'mdx', 'mermaid', 'mojo', 'narrat', 'nextflow', 'nginx', 'nim', 'nix', 'objective-c', 'objective-cpp', 'ocaml', 'pascal', 'perl', 'php', 'plsql', 'postcss', 'powerquery', 'powershell', 'prisma', 'prolog', 'proto', 'pug', 'puppet', 'purescript', 'python', 'r', 'raku', 'razor', 'reg', 'rel', 'riscv', 'rst', 'ruby', 'rust', 'sas', 'sass', 'scala', 'scheme', 'scss', 'shaderlab', 'shellscript', 'shellsession', 'smalltalk', 'solidity', 'sparql', 'splunk', 'sql', 'ssh-config', 'stata', 'stylus', 'svelte', 'swift', 'system-verilog', 'tasl', 'tcl', 'tex', 'toml', 'tsx', 'turtle', 'twig', 'typescript', 'v', 'vb', 'verilog', 'vhdl', 'viml', 'vue', 'vue-html', 'vyper', 'wasm', 'wenyan', 'wgsl', 'wolfram', 'xml', 'xsl', 'yaml', 'zenscript', 'zig', 'bash', 'batch', 'be', 'c#', 'cdc', 'clj', 'cmd', 'console', 'cql', 'cs', 'dockerfile', 'erl', 'f#', 'fs', 'fsl', 'gjs', 'gts', 'hbs', 'hs', 'jade', 'js', 'kql', 'makefile', 'md', 'nar', 'nf', 'objc', 'perl6', 'properties', 'ps', 'ps1', 'py', 'ql', 'rb', 'rs', 'sh', 'shader', 'shell', 'shellsession', 'spl', 'styl', 'ts', 'vim', 'vimscript', 'vy', 'yml', 'zsh', '文言'];
@@ -0,0 +1 @@
1
+ export declare const themeMap: string[];
@@ -0,0 +1 @@
1
+ export var themeMap = ['catppuccin-latte', 'everforest-light', 'github-light', 'github-light-default', 'github-light-high-contrast', 'gruvbox-light-hard', 'gruvbox-light-medium', 'gruvbox-light-soft', 'kanagawa-lotus', 'light-plus', 'material-theme-lighter', 'min-light', 'one-light', 'rose-pine-dawn', 'slack-ochin', 'snazzy-light', 'solarized-light', 'vitesse-light', 'andromeeda', 'aurora-x', 'ayu-dark', 'catppuccin-frappe', 'catppuccin-macchiato', 'catppuccin-mocha', 'dark-plus', 'dracula', 'dracula-soft', 'everforest-dark', 'github-dark', 'github-dark-default', 'github-dark-dimmed', 'github-dark-high-contrast', 'gruvbox-dark-hard', 'gruvbox-dark-medium', 'gruvbox-dark-soft', 'houston', 'kanagawa-dragon', 'kanagawa-wave', 'laserwave', 'material-theme', 'material-theme-darker', 'material-theme-ocean', 'material-theme-palenight', 'min-dark', 'monokai', 'night-owl', 'nord', 'one-dark-pro', 'plastic', 'poimandres', 'red', 'rose-pine', 'rose-pine-moon', 'slack-dark', 'solarized-dark', 'synthwave-84', 'tokyo-night', 'vesper', 'vitesse-black', 'vitesse-dark'];
@@ -1,3 +1,11 @@
1
+ import type { codeToHtml } from 'shiki';
2
+ import { SWRResponse } from 'swr';
1
3
  export declare const FALLBACK_LANG = "txt";
2
- export declare const useHighlight: (text: string, lang: string, enableTransformer?: boolean) => import("swr/dist/_internal").SWRResponse<string, any, any>;
4
+ declare const MD5_LENGTH_THRESHOLD = 10000;
5
+ declare const loadShiki: () => Promise<typeof codeToHtml>;
6
+ declare const shikiPromise: Promise<typeof codeToHtml>;
7
+ declare const escapeHtml: (str: string) => string;
8
+ export declare const useHighlight: (text: string, lang: string, enableTransformer?: boolean, theme?: string) => SWRResponse<string, Error>;
3
9
  export { languageMap } from './languageMap';
10
+ export { themeMap } from './themeMap';
11
+ export { escapeHtml, loadShiki, MD5_LENGTH_THRESHOLD, shikiPromise };
@@ -3,78 +3,156 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  import { transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight } from '@shikijs/transformers';
4
4
  import { useTheme, useThemeMode } from 'antd-style';
5
5
  import { useMemo } from 'react';
6
- import { codeToHtml } from 'shiki';
7
6
  import useSWR from 'swr';
8
7
  import { Md5 } from 'ts-md5';
9
8
  import { languageMap } from "./languageMap";
9
+ import { themeMap } from "./themeMap";
10
10
  export var FALLBACK_LANG = 'txt';
11
11
 
12
- // @Todo: use worker to improve performance
13
- export var useHighlight = function useHighlight(text, lang, enableTransformer) {
12
+ // 应用级缓存,避免重复计算
13
+ var MD5_LENGTH_THRESHOLD = 10000; // 超过该长度使用异步MD5
14
+
15
+ // 颜色替换映射类型
16
+
17
+ // 懒加载 shiki
18
+ var loadShiki = function loadShiki() {
19
+ return import('shiki').then(function (mod) {
20
+ return mod.codeToHtml;
21
+ });
22
+ };
23
+ var shikiPromise = loadShiki();
24
+
25
+ // 辅助函数:安全的HTML转义
26
+ var escapeHtml = function escapeHtml(str) {
27
+ return str.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#039;');
28
+ };
29
+
30
+ // 主高亮组件
31
+ export var useHighlight = function useHighlight(text, lang, enableTransformer, theme) {
14
32
  var _useThemeMode = useThemeMode(),
15
33
  isDarkMode = _useThemeMode.isDarkMode;
34
+ var antTheme = useTheme();
16
35
  var language = lang.toLowerCase();
36
+
37
+ // 匹配支持的语言
17
38
  var matchedLanguage = useMemo(function () {
18
39
  return languageMap.includes(language) ? language : FALLBACK_LANG;
19
40
  }, [language]);
20
- var theme = useTheme();
41
+ // 匹配支持的主题
42
+ var matchedTheme = useMemo(function () {
43
+ return themeMap.includes(theme) ? theme : undefined;
44
+ }, [theme]);
45
+
46
+ // 优化 transformer 创建
21
47
  var transformers = useMemo(function () {
22
48
  if (!enableTransformer) return;
23
49
  return [transformerNotationDiff(), transformerNotationHighlight(), transformerNotationWordHighlight(), transformerNotationFocus(), transformerNotationErrorLevel()];
24
50
  }, [enableTransformer]);
25
- var key = useMemo(function () {
26
- return Md5.hashStr(text);
27
- }, [text]);
51
+
52
+ // 优化颜色替换配置
53
+ var colorReplacements = useMemo(function () {
54
+ return {
55
+ 'slack-dark': {
56
+ '#4ec9b0': antTheme.yellow,
57
+ '#569cd6': antTheme.colorError,
58
+ '#6a9955': antTheme.gray,
59
+ '#9cdcfe': antTheme.colorText,
60
+ '#b5cea8': antTheme.purple10,
61
+ '#c586c0': antTheme.colorInfo,
62
+ '#ce9178': antTheme.colorSuccess,
63
+ '#dcdcaa': antTheme.colorWarning,
64
+ '#e6e6e6': antTheme.colorText
65
+ },
66
+ 'slack-ochin': {
67
+ '#002339': antTheme.colorText,
68
+ '#0991b6': antTheme.colorError,
69
+ '#174781': antTheme.purple10,
70
+ '#2f86d2': antTheme.colorText,
71
+ '#357b42': antTheme.gray,
72
+ '#7b30d0': antTheme.colorInfo,
73
+ '#7eb233': antTheme.colorWarningTextActive,
74
+ '#a44185': antTheme.colorSuccess,
75
+ '#dc3eb7': antTheme.yellow11
76
+ }
77
+ };
78
+ }, [antTheme]);
79
+
80
+ // 构建 shiki 主题
28
81
  var shikiTheme = useMemo(function () {
82
+ if (matchedTheme) {
83
+ return matchedTheme;
84
+ }
29
85
  if (language === 'md') {
30
86
  return isDarkMode ? 'catppuccin-mocha' : 'catppuccin-latte';
31
87
  }
32
88
  return isDarkMode ? 'slack-dark' : 'slack-ochin';
33
- }, [isDarkMode, language]);
34
- return useSWR([matchedLanguage, isDarkMode ? 'd' : 'l', key].join('-'), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
89
+ }, [isDarkMode, language, matchedTheme]);
90
+
91
+ // 构建缓存键
92
+ var cacheKey = useMemo(function () {
93
+ // 长文本使用 hash
94
+ var hash = text.length < MD5_LENGTH_THRESHOLD ? text : Md5.hashStr(text);
95
+ return [matchedLanguage, shikiTheme, hash].join('-');
96
+ }, [text, matchedLanguage, shikiTheme]);
97
+
98
+ // 使用SWR获取高亮HTML
99
+ return useSWR(cacheKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
100
+ var codeToHtml, html, _codeToHtml, _html, fallbackHtml;
35
101
  return _regeneratorRuntime.wrap(function _callee$(_context) {
36
102
  while (1) switch (_context.prev = _context.next) {
37
103
  case 0:
38
104
  _context.prev = 0;
39
- return _context.abrupt("return", codeToHtml(text, {
40
- colorReplacements: {
41
- 'slack-dark': {
42
- '#4ec9b0': theme.yellow,
43
- '#569cd6': theme.colorError,
44
- '#6a9955': theme.gray,
45
- '#9cdcfe': theme.colorText,
46
- '#b5cea8': theme.purple10,
47
- '#c586c0': theme.colorInfo,
48
- '#ce9178': theme.colorSuccess,
49
- '#dcdcaa': theme.colorWarning,
50
- '#e6e6e6': theme.colorText
51
- },
52
- 'slack-ochin': {
53
- '#002339': theme.colorText,
54
- '#0991b6': theme.colorError,
55
- '#174781': theme.purple10,
56
- '#2f86d2': theme.colorText,
57
- '#357b42': theme.gray,
58
- '#7b30d0': theme.colorInfo,
59
- '#7eb233': theme.colorWarningTextActive,
60
- '#a44185': theme.colorSuccess,
61
- '#dc3eb7': theme.yellow11
62
- }
63
- },
105
+ _context.next = 3;
106
+ return shikiPromise;
107
+ case 3:
108
+ codeToHtml = _context.sent;
109
+ _context.next = 6;
110
+ return codeToHtml(text, {
111
+ colorReplacements: colorReplacements,
64
112
  lang: matchedLanguage,
65
113
  theme: shikiTheme,
66
114
  transformers: transformers
67
- }));
68
- case 4:
69
- _context.prev = 4;
115
+ });
116
+ case 6:
117
+ html = _context.sent;
118
+ return _context.abrupt("return", html);
119
+ case 10:
120
+ _context.prev = 10;
70
121
  _context.t0 = _context["catch"](0);
71
- console.warn('shiki Highlight error:', _context.t0);
72
- return _context.abrupt("return", text);
73
- case 8:
122
+ console.warn('高级渲染失败:', _context.t0);
123
+ _context.prev = 13;
124
+ _context.next = 16;
125
+ return shikiPromise;
126
+ case 16:
127
+ _codeToHtml = _context.sent;
128
+ _context.next = 19;
129
+ return _codeToHtml(text, {
130
+ lang: matchedLanguage,
131
+ theme: shikiTheme
132
+ });
133
+ case 19:
134
+ _html = _context.sent;
135
+ return _context.abrupt("return", _html);
136
+ case 23:
137
+ _context.prev = 23;
138
+ _context.t1 = _context["catch"](13);
139
+ // 最终降级到纯文本
140
+ fallbackHtml = "<pre class=\"fallback\"><code>".concat(escapeHtml(text), "</code></pre>");
141
+ return _context.abrupt("return", fallbackHtml);
142
+ case 27:
74
143
  case "end":
75
144
  return _context.stop();
76
145
  }
77
- }, _callee, null, [[0, 4]]);
78
- })));
146
+ }, _callee, null, [[0, 10], [13, 23]]);
147
+ })), {
148
+ dedupingInterval: 3000,
149
+ // 3秒内相同请求只执行一次
150
+ errorRetryCount: 2,
151
+ // 最多重试2次
152
+ revalidateOnFocus: false,
153
+ revalidateOnReconnect: false
154
+ });
79
155
  };
80
- export { languageMap } from "./languageMap";
156
+ export { languageMap } from "./languageMap";
157
+ export { themeMap } from "./themeMap";
158
+ export { escapeHtml, loadShiki, MD5_LENGTH_THRESHOLD, shikiPromise };
package/es/index.d.ts CHANGED
@@ -34,6 +34,7 @@ export * from './ChatMarkdown';
34
34
  export * from './CodeEditor';
35
35
  export * from './EditableMessage';
36
36
  export * from './Highlighter';
37
+ export * from './hooks/useHighlight';
37
38
  export * from './styles';
38
39
  export * from './useSpeechSynthes';
39
40
  export * from './WaveformIcon';
package/es/index.js CHANGED
@@ -38,6 +38,7 @@ export * from "./ChatMarkdown";
38
38
  export * from "./CodeEditor";
39
39
  export * from "./EditableMessage";
40
40
  export * from "./Highlighter";
41
+ export * from "./hooks/useHighlight";
41
42
  export * from "./styles";
42
43
 
43
44
  // ~ custom @lobehub/tts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuntijs/ui",
3
- "version": "1.2.0-beta.5",
3
+ "version": "1.2.0-beta.6",
4
4
  "description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
5
5
  "keywords": [
6
6
  "yuntijs",