@lobehub/ui 1.94.4 → 1.94.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.
@@ -18,17 +18,18 @@ var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref) {
18
18
  cx = _useStyles.cx;
19
19
  var _useThemeMode = useThemeMode(),
20
20
  isDarkMode = _useThemeMode.isDarkMode;
21
- var useCodeToHtml = useHighlight(function (s) {
22
- return s.useCodeToHtml;
23
- });
24
- var _useCodeToHtml = useCodeToHtml(children.trim(), language, isDarkMode),
25
- data = _useCodeToHtml.data,
26
- isLoading = _useCodeToHtml.isLoading;
21
+ var _useHighlight = useHighlight(children.trim(), language, isDarkMode),
22
+ data = _useHighlight.data,
23
+ isLoading = _useHighlight.isLoading;
27
24
  return /*#__PURE__*/_jsxs(_Fragment, {
28
- children: [isLoading ? /*#__PURE__*/_jsx("code", {
25
+ children: [isLoading ? /*#__PURE__*/_jsx("div", {
29
26
  className: cx(styles.unshiki, className),
30
27
  style: style,
31
- children: children
28
+ children: /*#__PURE__*/_jsx("pre", {
29
+ children: /*#__PURE__*/_jsx("code", {
30
+ children: children
31
+ })
32
+ })
32
33
  }) : /*#__PURE__*/_jsx("div", {
33
34
  className: cx(styles.shiki, className),
34
35
  dangerouslySetInnerHTML: {
@@ -12,6 +12,6 @@ export var useStyles = createStyles(function (_ref) {
12
12
  loading: cx(stylish.blur, css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 10;\n top: 0;\n right: 0;\n\n display: flex;\n align-items: center;\n justify-content: center;\n\n height: 34px;\n padding: 0 8px;\n\n font-family: ", ";\n color: ", ";\n\n border-radius: ", ";\n "])), token.fontFamilyCode, token.colorTextTertiary, token.borderRadius)),
13
13
  prism: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n pre {\n overflow: auto;\n font-family: ", " !important;\n }\n "])), token.fontFamilyCode),
14
14
  shiki: cx("".concat(prefix, "-shiki"), css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n margin: 0;\n padding: 0;\n\n .shiki {\n overflow-x: auto;\n margin: 0;\n padding: 0;\n background: none !important;\n }\n "])))),
15
- unshiki: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n padding: 8px;\n "])))
15
+ unshiki: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n color: ", ";\n "])), token.colorTextDescription)
16
16
  };
17
17
  });
@@ -16,6 +16,6 @@ export var useStyles = createStyles(function (_ref, type) {
16
16
  container: cx(prefix, type !== 'pure' && typeStylish, css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n overflow: auto;\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 background: none !important;\n }\n\n code {\n background: transparent !important;\n }\n "])), token.borderRadius, token.motionEaseOut, buttonHoverCls, langHoverCls, type === 'pure' ? 0 : "16px 24px")),
17
17
  header: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n padding: 4px 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 right: 0;\n bottom: 8px;\n\n font-family: ", ";\n color: ", ";\n\n opacity: 0;\n\n transition: opacity 0.1s;\n "])), token.fontFamilyCode, token.colorTextSecondary)),
19
- select: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n .ant-select-selection-item {\n min-width: 100px;\n padding-inline-end: 0 !important;\n color: ", ";\n text-align: center;\n }\n\n input {\n text-align: center;\n }\n "])), token.colorTextDescription)
19
+ select: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n .ant-select-selection-item {\n min-width: 100px;\n padding-inline-end: 0 !important;\n color: ", ";\n text-align: center;\n }\n "])), token.colorTextDescription)
20
20
  };
21
21
  });
@@ -1,2 +1,2 @@
1
- declare const _default: string[];
1
+ declare const _default: readonly ["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", "文言"];
2
2
  export default _default;
@@ -1,10 +1,3 @@
1
- import { type Highlighter } from 'shikiji';
2
- import { type SWRResponse } from 'swr';
3
1
  export declare const FALLBACK_LANG = "markdown";
4
- interface Store {
5
- highlighter?: Highlighter;
6
- initHighlighter: () => Promise<Highlighter>;
7
- useCodeToHtml: (text: string, language: string, isDarkMode: boolean) => SWRResponse<string>;
8
- }
9
- export declare const useHighlight: import("zustand/traditional").UseBoundStoreWithEqualityFn<import("zustand/vanilla").StoreApi<Store>>;
2
+ export declare const useHighlight: (text: string, language: string, isDarkMode: boolean) => import("swr/_internal").SWRResponse<string, any, any>;
10
3
  export { default as languageMap } from './languageMap';
@@ -2,99 +2,68 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  import { getHighlighter } from 'shikiji';
4
4
  import useSWR from 'swr';
5
- import { shallow } from 'zustand/shallow';
6
- import { createWithEqualityFn } from 'zustand/traditional';
7
5
  import { themeConfig } from "../Highlighter/theme";
8
- import languageMap from "./languageMap";
9
6
  export var FALLBACK_LANG = 'markdown';
10
- var FALLBACK_LANGS = ['ts', 'typescript', 'js', 'javascript', 'markdown', 'md'];
11
- var THEME = [themeConfig(true), themeConfig(false)];
12
- export var useHighlight = createWithEqualityFn(function (set, get) {
13
- return {
14
- highlighter: undefined,
15
- initHighlighter: function () {
16
- var _initHighlighter = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
17
- var highlighter;
18
- return _regeneratorRuntime.wrap(function _callee$(_context) {
19
- while (1) switch (_context.prev = _context.next) {
20
- case 0:
21
- highlighter = get().highlighter;
22
- if (!highlighter) {
23
- _context.next = 5;
24
- break;
25
- }
26
- return _context.abrupt("return", highlighter);
27
- case 5:
28
- _context.next = 7;
29
- return getHighlighter({
30
- langs: FALLBACK_LANGS,
31
- themes: THEME
32
- });
33
- case 7:
34
- highlighter = _context.sent;
35
- set({
36
- highlighter: highlighter
37
- });
38
- return _context.abrupt("return", highlighter);
39
- case 10:
40
- case "end":
41
- return _context.stop();
7
+ var FALLBACK_LANGS = [FALLBACK_LANG];
8
+ var cacheHighlighter;
9
+ var initHighlighter = /*#__PURE__*/function () {
10
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(lang) {
11
+ var highlighter;
12
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
13
+ while (1) switch (_context.prev = _context.next) {
14
+ case 0:
15
+ highlighter = cacheHighlighter;
16
+ if (!(highlighter && FALLBACK_LANGS.includes(lang))) {
17
+ _context.next = 5;
18
+ break;
42
19
  }
43
- }, _callee);
44
- }));
45
- function initHighlighter() {
46
- return _initHighlighter.apply(this, arguments);
20
+ return _context.abrupt("return", highlighter);
21
+ case 5:
22
+ FALLBACK_LANGS.push(lang);
23
+ _context.next = 8;
24
+ return getHighlighter({
25
+ langs: FALLBACK_LANGS,
26
+ themes: [themeConfig(true), themeConfig(false)]
27
+ });
28
+ case 8:
29
+ highlighter = _context.sent;
30
+ cacheHighlighter = highlighter;
31
+ return _context.abrupt("return", highlighter);
32
+ case 11:
33
+ case "end":
34
+ return _context.stop();
47
35
  }
48
- return initHighlighter;
49
- }(),
50
- useCodeToHtml: function useCodeToHtml(text, language, isDarkMode) {
51
- return useSWR([text, language, Number(isDarkMode)].join('-'), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
52
- var theme, lang, highlighter, html;
53
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
54
- while (1) switch (_context2.prev = _context2.next) {
55
- case 0:
56
- theme = isDarkMode ? 'dark' : 'light';
57
- lang = language;
58
- _context2.prev = 2;
59
- _context2.next = 5;
60
- return get().initHighlighter();
61
- case 5:
62
- highlighter = _context2.sent;
63
- if (FALLBACK_LANGS.includes(lang)) {
64
- _context2.next = 13;
65
- break;
66
- }
67
- if (!languageMap.includes(lang)) {
68
- _context2.next = 12;
69
- break;
70
- }
71
- _context2.next = 10;
72
- return highlighter === null || highlighter === void 0 ? void 0 : highlighter.loadLanguage(lang);
73
- case 10:
74
- _context2.next = 13;
75
- break;
76
- case 12:
77
- lang = FALLBACK_LANG;
78
- case 13:
79
- _context2.next = 15;
80
- return highlighter === null || highlighter === void 0 ? void 0 : highlighter.codeToHtml(text, {
81
- lang: lang,
82
- theme: theme
83
- });
84
- case 15:
85
- html = _context2.sent;
86
- return _context2.abrupt("return", html);
87
- case 19:
88
- _context2.prev = 19;
89
- _context2.t0 = _context2["catch"](2);
90
- return _context2.abrupt("return", "<code>".concat(text, "</code>"));
91
- case 22:
92
- case "end":
93
- return _context2.stop();
94
- }
95
- }, _callee2, null, [[2, 19]]);
96
- })));
97
- }
36
+ }, _callee);
37
+ }));
38
+ return function initHighlighter(_x) {
39
+ return _ref.apply(this, arguments);
98
40
  };
99
- }, shallow);
41
+ }();
42
+ export var useHighlight = function useHighlight(text, language, isDarkMode) {
43
+ return useSWR([text, language, Number(isDarkMode)].join('-'), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
44
+ var highlighter, html;
45
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
46
+ while (1) switch (_context2.prev = _context2.next) {
47
+ case 0:
48
+ _context2.prev = 0;
49
+ _context2.next = 3;
50
+ return initHighlighter(language);
51
+ case 3:
52
+ highlighter = _context2.sent;
53
+ html = highlighter === null || highlighter === void 0 ? void 0 : highlighter.codeToHtml(text, {
54
+ lang: language,
55
+ theme: isDarkMode ? 'dark' : 'light'
56
+ });
57
+ return _context2.abrupt("return", html);
58
+ case 8:
59
+ _context2.prev = 8;
60
+ _context2.t0 = _context2["catch"](0);
61
+ return _context2.abrupt("return", "<pre><code>".concat(text, "</code></pre>"));
62
+ case 11:
63
+ case "end":
64
+ return _context2.stop();
65
+ }
66
+ }, _callee2, null, [[0, 8]]);
67
+ })));
68
+ };
100
69
  export { default as languageMap } from "./languageMap";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.94.4",
3
+ "version": "1.94.6",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",