@lobehub/ui 1.140.2 → 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.
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ElementType, ReactNode } from 'react';
|
|
2
2
|
import { CDN, CdnApi } from "../utils/genCdnUrl";
|
|
3
|
-
type CdnFn = ({ pkg, version, path }: CdnApi) => string;
|
|
4
3
|
export interface Config {
|
|
5
4
|
aAs?: ElementType;
|
|
6
5
|
customCdnFn?: CdnFn;
|
|
@@ -13,5 +12,6 @@ declare const ConfigProvider: import("react").NamedExoticComponent<{
|
|
|
13
12
|
children: ReactNode;
|
|
14
13
|
config: Config;
|
|
15
14
|
}>;
|
|
15
|
+
export type CdnFn = ({ pkg, version, path }: CdnApi) => string;
|
|
16
16
|
export declare const useCdnFn: () => CdnFn;
|
|
17
17
|
export default ConfigProvider;
|
|
@@ -10,7 +10,10 @@ var ConfigProvider = /*#__PURE__*/memo(function (_ref) {
|
|
|
10
10
|
children: children
|
|
11
11
|
});
|
|
12
12
|
});
|
|
13
|
-
|
|
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
|
|
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,22 @@ export var useCdnFn = function useCdnFn() {
|
|
|
35
38
|
version: version
|
|
36
39
|
});
|
|
37
40
|
};
|
|
38
|
-
return (config === null || config === void 0 ? void 0 : config.customCdnFn) ||
|
|
41
|
+
return (config === null || config === void 0 ? void 0 : config.customCdnFn) || cdnFallback;
|
|
39
42
|
};
|
|
43
|
+
|
|
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
|
+
//
|
|
58
|
+
|
|
40
59
|
export default ConfigProvider;
|
package/es/FluentEmoji/index.js
CHANGED
|
@@ -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 } from "../ConfigProvider";
|
|
7
8
|
import Img from "../Img";
|
|
8
9
|
import { useStyles } from "./style";
|
|
9
10
|
import { genEmojiUrl } from "./utils";
|
|
@@ -21,6 +22,7 @@ var FluentEmoji = /*#__PURE__*/memo(function (_ref) {
|
|
|
21
22
|
_useState2 = _slicedToArray(_useState, 2),
|
|
22
23
|
loadingFail = _useState2[0],
|
|
23
24
|
setLoadingFail = _useState2[1];
|
|
25
|
+
var genCdnUrl = useCdnFn();
|
|
24
26
|
var _useStyles = useStyles(),
|
|
25
27
|
cx = _useStyles.cx,
|
|
26
28
|
styles = _useStyles.styles;
|
|
@@ -45,7 +47,7 @@ var FluentEmoji = /*#__PURE__*/memo(function (_ref) {
|
|
|
45
47
|
onError: function onError() {
|
|
46
48
|
return setLoadingFail(true);
|
|
47
49
|
},
|
|
48
|
-
src: emojiUrl,
|
|
50
|
+
src: genCdnUrl(emojiUrl),
|
|
49
51
|
style: _objectSpread({
|
|
50
52
|
flex: 'none'
|
|
51
53
|
}, style),
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export type EmojiType = 'anim' | 'flat' | 'modern' | 'mono' | 'pure' | '3d';
|
|
2
|
-
export declare
|
|
2
|
+
export declare function isFlagEmoji(emoji: string): boolean;
|
|
3
|
+
export declare function emojiToUnicode(emoji: string): string;
|
|
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
|
@@ -1,17 +1,72 @@
|
|
|
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 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
|
+
}
|
|
12
24
|
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;
|
|
15
25
|
var ext = ['anim', '3d'].includes(type) ? 'webp' : 'svg';
|
|
16
|
-
|
|
26
|
+
switch (type) {
|
|
27
|
+
case 'pure':
|
|
28
|
+
{
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
case 'anim':
|
|
32
|
+
{
|
|
33
|
+
return {
|
|
34
|
+
path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
|
|
35
|
+
pkg: emojiAnimPkg(emoji),
|
|
36
|
+
version: '1.0.0'
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
case '3d':
|
|
40
|
+
{
|
|
41
|
+
return {
|
|
42
|
+
path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
|
|
43
|
+
pkg: '@lobehub/fluent-emoji-3d',
|
|
44
|
+
version: '1.1.0'
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
case 'flat':
|
|
48
|
+
{
|
|
49
|
+
return {
|
|
50
|
+
path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
|
|
51
|
+
pkg: '@lobehub/fluent-emoji-flat',
|
|
52
|
+
version: '1.1.0'
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
case 'modern':
|
|
56
|
+
{
|
|
57
|
+
return {
|
|
58
|
+
path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
|
|
59
|
+
pkg: '@lobehub/fluent-emoji-modern',
|
|
60
|
+
version: '1.0.0'
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
case 'mono':
|
|
64
|
+
{
|
|
65
|
+
return {
|
|
66
|
+
path: "assets/".concat(emojiToUnicode(emoji), ".").concat(ext),
|
|
67
|
+
pkg: '@lobehub/fluent-emoji-mono',
|
|
68
|
+
version: '1.1.0'
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
17
72
|
};
|
package/es/utils/genCdnUrl.js
CHANGED
|
@@ -17,4 +17,26 @@ export var genCdnUrl = function genCdnUrl(_ref) {
|
|
|
17
17
|
return urlJoin(ALIYUN_API, pkg, version, 'files', path);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
};
|
|
20
|
+
};
|
|
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
|
+
// };
|