@lobehub/ui 1.140.3 → 1.141.0
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/es/ConfigProvider/index.d.ts +1 -5
- package/es/ConfigProvider/index.js +14 -24
- package/es/FluentEmoji/index.js +4 -9
- package/es/FluentEmoji/utils.d.ts +6 -5
- package/es/FluentEmoji/utils.js +26 -15
- package/es/utils/genCdnUrl.d.ts +0 -7
- package/es/utils/genCdnUrl.js +22 -17
- package/package.json +1 -1
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { ElementType, ReactNode } from 'react';
|
|
2
|
-
import { CDN, CdnApi
|
|
2
|
+
import { CDN, CdnApi } from "../utils/genCdnUrl";
|
|
3
3
|
export interface Config {
|
|
4
4
|
aAs?: ElementType;
|
|
5
5
|
customCdnFn?: CdnFn;
|
|
6
|
-
customJsdelivrFn?: JsdelivrFn;
|
|
7
6
|
imgAs?: ElementType;
|
|
8
7
|
imgUnoptimized?: boolean;
|
|
9
|
-
jsdelivrProxy?: JsdelivrCDN | 'custom';
|
|
10
8
|
proxy?: CDN | 'custom';
|
|
11
9
|
}
|
|
12
10
|
export declare const ConfigContext: import("react").Context<Config | null>;
|
|
@@ -16,6 +14,4 @@ declare const ConfigProvider: import("react").NamedExoticComponent<{
|
|
|
16
14
|
}>;
|
|
17
15
|
export type CdnFn = ({ pkg, version, path }: CdnApi) => string;
|
|
18
16
|
export declare const useCdnFn: () => CdnFn;
|
|
19
|
-
export type JsdelivrFn = ({ repo, path }: JsdelivrApi) => string;
|
|
20
|
-
export declare const useJsdelivrFn: () => JsdelivrFn;
|
|
21
17
|
export default ConfigProvider;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, memo, useContext } from 'react';
|
|
2
|
-
import { genCdnUrl
|
|
2
|
+
import { genCdnUrl } 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) {
|
|
@@ -42,28 +42,18 @@ export var useCdnFn = function useCdnFn() {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
// useJsdelivrFn
|
|
45
|
+
// export type JsdelivrFn = ({ repo, path }: JsdelivrApi) => string;
|
|
46
|
+
//
|
|
47
|
+
// const JsdelivrFallback: JsdelivrFn = ({ repo, path }) =>
|
|
48
|
+
// genJsdelivrUrl({ path, proxy: 'lobehub', repo });
|
|
49
|
+
//
|
|
50
|
+
// export const useJsdelivrFn = (): JsdelivrFn => {
|
|
51
|
+
// const config = useContext(ConfigContext);
|
|
52
|
+
// if (!config) return JsdelivrFallback;
|
|
53
|
+
// if (config?.proxy !== 'custom')
|
|
54
|
+
// return ({ repo, path }) => genJsdelivrUrl({ path, proxy: config.proxy as any, repo });
|
|
55
|
+
// return config?.customJsdelivrFn || JsdelivrFallback;
|
|
56
|
+
// };
|
|
57
|
+
//
|
|
45
58
|
|
|
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;
|
|
68
|
-
};
|
|
69
59
|
export default ConfigProvider;
|
package/es/FluentEmoji/index.js
CHANGED
|
@@ -4,7 +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
|
|
7
|
+
import { useCdnFn } from "../ConfigProvider";
|
|
8
8
|
import Img from "../Img";
|
|
9
9
|
import { useStyles } from "./style";
|
|
10
10
|
import { genEmojiUrl } from "./utils";
|
|
@@ -22,18 +22,13 @@ var FluentEmoji = /*#__PURE__*/memo(function (_ref) {
|
|
|
22
22
|
_useState2 = _slicedToArray(_useState, 2),
|
|
23
23
|
loadingFail = _useState2[0],
|
|
24
24
|
setLoadingFail = _useState2[1];
|
|
25
|
-
var genJsdelivrUrl = useJsdelivrFn();
|
|
26
25
|
var genCdnUrl = useCdnFn();
|
|
27
26
|
var _useStyles = useStyles(),
|
|
28
27
|
cx = _useStyles.cx,
|
|
29
28
|
styles = _useStyles.styles;
|
|
30
29
|
var emojiUrl = useMemo(function () {
|
|
31
|
-
return genEmojiUrl(emoji, type
|
|
32
|
-
|
|
33
|
-
genJsdelivrUrl: genJsdelivrUrl
|
|
34
|
-
});
|
|
35
|
-
}, [type, emoji, genJsdelivrUrl, genCdnUrl]);
|
|
36
|
-
console.log(emojiUrl);
|
|
30
|
+
return genEmojiUrl(emoji, type);
|
|
31
|
+
}, [type, emoji]);
|
|
37
32
|
if (type === 'pure' || !emojiUrl || loadingFail) return /*#__PURE__*/_jsx(Center, {
|
|
38
33
|
className: cx(styles.container, className),
|
|
39
34
|
flex: 'none',
|
|
@@ -52,7 +47,7 @@ var FluentEmoji = /*#__PURE__*/memo(function (_ref) {
|
|
|
52
47
|
onError: function onError() {
|
|
53
48
|
return setLoadingFail(true);
|
|
54
49
|
},
|
|
55
|
-
src: emojiUrl,
|
|
50
|
+
src: genCdnUrl(emojiUrl),
|
|
56
51
|
style: _objectSpread({
|
|
57
52
|
flex: 'none'
|
|
58
53
|
}, style),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { CdnFn, JsdelivrFn } from "../ConfigProvider";
|
|
2
1
|
export type EmojiType = 'anim' | 'flat' | 'modern' | 'mono' | 'pure' | '3d';
|
|
3
2
|
export declare function isFlagEmoji(emoji: string): boolean;
|
|
4
3
|
export declare function emojiToUnicode(emoji: string): string;
|
|
5
|
-
export declare
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
export declare function emojiAnimPkg(emoji: string): "@lobehub/fluent-emoji-anim-1" | "@lobehub/fluent-emoji-anim-2" | "@lobehub/fluent-emoji-anim-3" | "@lobehub/fluent-emoji-anim-4";
|
|
5
|
+
export declare const genEmojiUrl: (emoji: string, type: EmojiType) => {
|
|
6
|
+
path: string;
|
|
7
|
+
pkg: string;
|
|
8
|
+
version: string;
|
|
9
|
+
} | null;
|
package/es/FluentEmoji/utils.js
CHANGED
|
@@ -9,9 +9,19 @@ export function emojiToUnicode(emoji) {
|
|
|
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
|
|
13
|
-
var
|
|
14
|
-
|
|
12
|
+
export function emojiAnimPkg(emoji) {
|
|
13
|
+
var mainPart = emojiToUnicode(emoji).split('-')[0];
|
|
14
|
+
if (mainPart < '1f469') {
|
|
15
|
+
return '@lobehub/fluent-emoji-anim-1';
|
|
16
|
+
} else if (mainPart >= '1f469' && mainPart < '1f620') {
|
|
17
|
+
return '@lobehub/fluent-emoji-anim-2';
|
|
18
|
+
} else if (mainPart >= '1f620' && mainPart < '1f9a0') {
|
|
19
|
+
return '@lobehub/fluent-emoji-anim-3';
|
|
20
|
+
} else {
|
|
21
|
+
return '@lobehub/fluent-emoji-anim-4';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export var genEmojiUrl = function genEmojiUrl(emoji, type) {
|
|
15
25
|
var ext = ['anim', '3d'].includes(type) ? 'webp' : 'svg';
|
|
16
26
|
switch (type) {
|
|
17
27
|
case 'pure':
|
|
@@ -20,42 +30,43 @@ export var genEmojiUrl = function genEmojiUrl(emoji, type, _ref) {
|
|
|
20
30
|
}
|
|
21
31
|
case 'anim':
|
|
22
32
|
{
|
|
23
|
-
return
|
|
24
|
-
path: "
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
return {
|
|
34
|
+
path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
|
|
35
|
+
pkg: emojiAnimPkg(emoji),
|
|
36
|
+
version: '1.0.0'
|
|
37
|
+
};
|
|
27
38
|
}
|
|
28
39
|
case '3d':
|
|
29
40
|
{
|
|
30
|
-
return
|
|
41
|
+
return {
|
|
31
42
|
path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
|
|
32
43
|
pkg: '@lobehub/fluent-emoji-3d',
|
|
33
44
|
version: '1.1.0'
|
|
34
|
-
}
|
|
45
|
+
};
|
|
35
46
|
}
|
|
36
47
|
case 'flat':
|
|
37
48
|
{
|
|
38
|
-
return
|
|
49
|
+
return {
|
|
39
50
|
path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
|
|
40
51
|
pkg: '@lobehub/fluent-emoji-flat',
|
|
41
52
|
version: '1.1.0'
|
|
42
|
-
}
|
|
53
|
+
};
|
|
43
54
|
}
|
|
44
55
|
case 'modern':
|
|
45
56
|
{
|
|
46
|
-
return
|
|
57
|
+
return {
|
|
47
58
|
path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
|
|
48
59
|
pkg: '@lobehub/fluent-emoji-modern',
|
|
49
60
|
version: '1.0.0'
|
|
50
|
-
}
|
|
61
|
+
};
|
|
51
62
|
}
|
|
52
63
|
case 'mono':
|
|
53
64
|
{
|
|
54
|
-
return
|
|
65
|
+
return {
|
|
55
66
|
path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
|
|
56
67
|
pkg: '@lobehub/fluent-emoji-mono',
|
|
57
68
|
version: '1.1.0'
|
|
58
|
-
}
|
|
69
|
+
};
|
|
59
70
|
}
|
|
60
71
|
}
|
|
61
72
|
};
|
package/es/utils/genCdnUrl.d.ts
CHANGED
|
@@ -6,10 +6,3 @@ 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;
|
package/es/utils/genCdnUrl.js
CHANGED
|
@@ -18,20 +18,25 @@ export var genCdnUrl = function genCdnUrl(_ref) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
21
|
+
|
|
22
|
+
// export type JsdelivrCDN = 'jsdelivr' | 'lobehub';
|
|
23
|
+
//
|
|
24
|
+
// const JSDELIVR_API = 'https://fastly.jsdelivr.net';
|
|
25
|
+
// const LOBEHUB_API = 'https://jsdelivr.lobeobjects.space';
|
|
26
|
+
//
|
|
27
|
+
// export interface JsdelivrApi {
|
|
28
|
+
// path: string;
|
|
29
|
+
// proxy?: JsdelivrCDN;
|
|
30
|
+
// repo: string;
|
|
31
|
+
// }
|
|
32
|
+
//
|
|
33
|
+
// export const genJsdelivrUrl = ({ path, proxy, repo }: JsdelivrApi): string => {
|
|
34
|
+
// switch (proxy) {
|
|
35
|
+
// case 'jsdelivr': {
|
|
36
|
+
// return urlJoin(JSDELIVR_API, 'gh', repo, path);
|
|
37
|
+
// }
|
|
38
|
+
// default: {
|
|
39
|
+
// return urlJoin(LOBEHUB_API, 'gh', repo, path);
|
|
40
|
+
// }
|
|
41
|
+
// }
|
|
42
|
+
// };
|