@lobehub/ui 1.140.2 → 1.140.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.
@@ -1,11 +1,12 @@
1
1
  import { ElementType, ReactNode } from 'react';
2
- import { CDN, CdnApi } from "../utils/genCdnUrl";
3
- type CdnFn = ({ pkg, version, path }: CdnApi) => string;
2
+ import { CDN, CdnApi, JsdelivrApi, JsdelivrCDN } from "../utils/genCdnUrl";
4
3
  export interface Config {
5
4
  aAs?: ElementType;
6
5
  customCdnFn?: CdnFn;
6
+ customJsdelivrFn?: JsdelivrFn;
7
7
  imgAs?: ElementType;
8
8
  imgUnoptimized?: boolean;
9
+ jsdelivrProxy?: JsdelivrCDN | 'custom';
9
10
  proxy?: CDN | 'custom';
10
11
  }
11
12
  export declare const ConfigContext: import("react").Context<Config | null>;
@@ -13,5 +14,8 @@ declare const ConfigProvider: import("react").NamedExoticComponent<{
13
14
  children: ReactNode;
14
15
  config: Config;
15
16
  }>;
17
+ export type CdnFn = ({ pkg, version, path }: CdnApi) => string;
16
18
  export declare const useCdnFn: () => CdnFn;
19
+ export type JsdelivrFn = ({ repo, path }: JsdelivrApi) => string;
20
+ export declare const useJsdelivrFn: () => JsdelivrFn;
17
21
  export default ConfigProvider;
@@ -1,5 +1,5 @@
1
1
  import { createContext, memo, useContext } from 'react';
2
- import { genCdnUrl } from "../utils/genCdnUrl";
2
+ import { genCdnUrl, genJsdelivrUrl } from "../utils/genCdnUrl";
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var ConfigContext = /*#__PURE__*/createContext(null);
5
5
  var ConfigProvider = /*#__PURE__*/memo(function (_ref) {
@@ -10,7 +10,10 @@ var ConfigProvider = /*#__PURE__*/memo(function (_ref) {
10
10
  children: children
11
11
  });
12
12
  });
13
- var fallback = function fallback(_ref2) {
13
+
14
+ // useCdnFn
15
+
16
+ var cdnFallback = function cdnFallback(_ref2) {
14
17
  var pkg = _ref2.pkg,
15
18
  version = _ref2.version,
16
19
  path = _ref2.path;
@@ -23,7 +26,7 @@ var fallback = function fallback(_ref2) {
23
26
  };
24
27
  export var useCdnFn = function useCdnFn() {
25
28
  var config = useContext(ConfigContext);
26
- if (!config) return fallback;
29
+ if (!config) return cdnFallback;
27
30
  if ((config === null || config === void 0 ? void 0 : config.proxy) !== 'custom') return function (_ref3) {
28
31
  var pkg = _ref3.pkg,
29
32
  version = _ref3.version,
@@ -35,6 +38,32 @@ export var useCdnFn = function useCdnFn() {
35
38
  version: version
36
39
  });
37
40
  };
38
- return (config === null || config === void 0 ? void 0 : config.customCdnFn) || fallback;
41
+ return (config === null || config === void 0 ? void 0 : config.customCdnFn) || cdnFallback;
42
+ };
43
+
44
+ // useJsdelivrFn
45
+
46
+ var JsdelivrFallback = function JsdelivrFallback(_ref4) {
47
+ var repo = _ref4.repo,
48
+ path = _ref4.path;
49
+ return genJsdelivrUrl({
50
+ path: path,
51
+ proxy: 'lobehub',
52
+ repo: repo
53
+ });
54
+ };
55
+ export var useJsdelivrFn = function useJsdelivrFn() {
56
+ var config = useContext(ConfigContext);
57
+ if (!config) return JsdelivrFallback;
58
+ if ((config === null || config === void 0 ? void 0 : config.proxy) !== 'custom') return function (_ref5) {
59
+ var repo = _ref5.repo,
60
+ path = _ref5.path;
61
+ return genJsdelivrUrl({
62
+ path: path,
63
+ proxy: config.proxy,
64
+ repo: repo
65
+ });
66
+ };
67
+ return (config === null || config === void 0 ? void 0 : config.customJsdelivrFn) || JsdelivrFallback;
39
68
  };
40
69
  export default ConfigProvider;
@@ -4,6 +4,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
4
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
5
  import { memo, useMemo, useState } from 'react';
6
6
  import { Center } from 'react-layout-kit';
7
+ import { useCdnFn, useJsdelivrFn } from "../ConfigProvider";
7
8
  import Img from "../Img";
8
9
  import { useStyles } from "./style";
9
10
  import { genEmojiUrl } from "./utils";
@@ -21,12 +22,18 @@ var FluentEmoji = /*#__PURE__*/memo(function (_ref) {
21
22
  _useState2 = _slicedToArray(_useState, 2),
22
23
  loadingFail = _useState2[0],
23
24
  setLoadingFail = _useState2[1];
25
+ var genJsdelivrUrl = useJsdelivrFn();
26
+ var genCdnUrl = useCdnFn();
24
27
  var _useStyles = useStyles(),
25
28
  cx = _useStyles.cx,
26
29
  styles = _useStyles.styles;
27
30
  var emojiUrl = useMemo(function () {
28
- return genEmojiUrl(emoji, type);
29
- }, [type, emoji]);
31
+ return genEmojiUrl(emoji, type, {
32
+ genCdnUrl: genCdnUrl,
33
+ genJsdelivrUrl: genJsdelivrUrl
34
+ });
35
+ }, [type, emoji, genJsdelivrUrl, genCdnUrl]);
36
+ console.log(emojiUrl);
30
37
  if (type === 'pure' || !emojiUrl || loadingFail) return /*#__PURE__*/_jsx(Center, {
31
38
  className: cx(styles.container, className),
32
39
  flex: 'none',
@@ -1,2 +1,8 @@
1
+ import { CdnFn, JsdelivrFn } from "../ConfigProvider";
1
2
  export type EmojiType = 'anim' | 'flat' | 'modern' | 'mono' | 'pure' | '3d';
2
- export declare const genEmojiUrl: (emoji: string, type: EmojiType) => string | null;
3
+ export declare function isFlagEmoji(emoji: string): boolean;
4
+ export declare function emojiToUnicode(emoji: string): string;
5
+ export declare const genEmojiUrl: (emoji: string, type: EmojiType, { genCdnUrl, genJsdelivrUrl }: {
6
+ genCdnUrl: CdnFn;
7
+ genJsdelivrUrl: JsdelivrFn;
8
+ }) => string | null;
@@ -1,17 +1,61 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- function isFlagEmoji(emoji) {
2
+ export function isFlagEmoji(emoji) {
3
3
  var flagRegex = /(?:\uD83C[\uDDE6-\uDDFF]){2}/;
4
4
  return flagRegex.test(emoji);
5
5
  }
6
- function emojiToUnicode(emoji) {
6
+ export function emojiToUnicode(emoji) {
7
7
  return _toConsumableArray(emoji).map(function (char) {
8
8
  var _char$codePointAt;
9
9
  return char === null || char === void 0 || (_char$codePointAt = char.codePointAt(0)) === null || _char$codePointAt === void 0 ? void 0 : _char$codePointAt.toString(16);
10
10
  }).join('-');
11
11
  }
12
- export var genEmojiUrl = function genEmojiUrl(emoji, type) {
13
- if (isFlagEmoji(emoji)) return "https://jsdelivr.lobehub-inc.cn/gh/RealityRipple/emoji/noto/".concat(emojiToUnicode(emoji), ".png");
14
- if (type === 'pure') return null;
12
+ export var genEmojiUrl = function genEmojiUrl(emoji, type, _ref) {
13
+ var genCdnUrl = _ref.genCdnUrl,
14
+ genJsdelivrUrl = _ref.genJsdelivrUrl;
15
15
  var ext = ['anim', '3d'].includes(type) ? 'webp' : 'svg';
16
- return "https://jsdelivr.lobehub-inc.cn/gh/lobehub/fluent-emoji/packages/".concat(type, "/assets/").concat(emojiToUnicode(emoji), ".").concat(ext);
16
+ switch (type) {
17
+ case 'pure':
18
+ {
19
+ return null;
20
+ }
21
+ case 'anim':
22
+ {
23
+ return genJsdelivrUrl({
24
+ path: "packages/".concat(type, "/assets/").concat(emojiToUnicode(emoji), ".").concat(ext),
25
+ repo: 'lobehub/fluent-emoji'
26
+ });
27
+ }
28
+ case '3d':
29
+ {
30
+ return genCdnUrl({
31
+ path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
32
+ pkg: '@lobehub/fluent-emoji-3d',
33
+ version: '1.1.0'
34
+ });
35
+ }
36
+ case 'flat':
37
+ {
38
+ return genCdnUrl({
39
+ path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
40
+ pkg: '@lobehub/fluent-emoji-flat',
41
+ version: '1.1.0'
42
+ });
43
+ }
44
+ case 'modern':
45
+ {
46
+ return genCdnUrl({
47
+ path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
48
+ pkg: '@lobehub/fluent-emoji-modern',
49
+ version: '1.0.0'
50
+ });
51
+ }
52
+ case 'mono':
53
+ {
54
+ return genCdnUrl({
55
+ path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
56
+ pkg: '@lobehub/fluent-emoji-mono',
57
+ version: '1.1.0'
58
+ });
59
+ }
60
+ }
17
61
  };
@@ -6,3 +6,10 @@ export interface CdnApi {
6
6
  version?: string;
7
7
  }
8
8
  export declare const genCdnUrl: ({ pkg, version, path, proxy }: CdnApi) => string;
9
+ export type JsdelivrCDN = 'jsdelivr' | 'lobehub';
10
+ export interface JsdelivrApi {
11
+ path: string;
12
+ proxy?: JsdelivrCDN;
13
+ repo: string;
14
+ }
15
+ export declare const genJsdelivrUrl: ({ path, proxy, repo }: JsdelivrApi) => string;
@@ -17,4 +17,21 @@ export var genCdnUrl = function genCdnUrl(_ref) {
17
17
  return urlJoin(ALIYUN_API, pkg, version, 'files', path);
18
18
  }
19
19
  }
20
+ };
21
+ var JSDELIVR_API = 'https://fastly.jsdelivr.net';
22
+ var LOBEHUB_API = 'https://jsdelivr.lobeobjects.space';
23
+ export var genJsdelivrUrl = function genJsdelivrUrl(_ref2) {
24
+ var path = _ref2.path,
25
+ proxy = _ref2.proxy,
26
+ repo = _ref2.repo;
27
+ switch (proxy) {
28
+ case 'jsdelivr':
29
+ {
30
+ return urlJoin(JSDELIVR_API, 'gh', repo, path);
31
+ }
32
+ default:
33
+ {
34
+ return urlJoin(LOBEHUB_API, 'gh', repo, path);
35
+ }
36
+ }
20
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.140.2",
3
+ "version": "1.140.3",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",