@liner-fe/illust 0.1.4 → 0.1.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.
- package/CHANGELOG.md +12 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +29 -37
- package/package.json +1 -2
- package/src/components/index.tsx +22 -11
- package/src/constants/name.ts +6 -0
- package/src/hooks/useIllust.ts +0 -27
package/CHANGELOG.md
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { DetailedHTMLProps, ImgHTMLAttributes } from 'react';
|
|
3
3
|
import { Property } from 'csstype';
|
|
4
4
|
|
|
5
|
-
declare const illustNames: readonly ["hero-gift", "hero-search", "mini-approve", "mini-documents-2", "mini-documents-3", "mini-documents-4", "mini-documents-5", "mini-documents", "mini-egg", "mini-empty-message", "mini-empty", "mini-gift", "mini-graduation_hat", "mini-not-search", "mini-not-ticket-2", "mini-private", "mini-search", "mini-ticket", "mini-ticket-3", "mini-window", "spot-catch_star", "spot-clap", "spot-empty", "spot-gift", "spot-no_search", "spot-search-2", "spot-search-3", "spot-search-4", "spot-search-5", "spot-search", "spot-sign_up", "spot-team", "spot-write", "mini-sign", "mini-pots", "mini-erase", "mini-rocket"];
|
|
6
|
-
declare const darkIllustNames: readonly ["hero-gift", "hero-search", "mini-approve", "mini-documents-2", "mini-documents-3", "mini-documents-4", "mini-documents-5", "mini-documents", "mini-egg", "mini-empty-message", "mini-empty", "mini-gift", "mini-graduation_hat", "mini-not-search", "mini-not-ticket-2", "mini-private", "mini-search", "mini-ticket", "mini-ticket-3", "mini-window", "spot-catch_star", "spot-clap", "spot-empty", "spot-gift", "spot-no_search", "spot-search-2", "spot-search-3", "spot-search-4", "spot-search-5", "spot-search", "spot-sign_up", "spot-team", "spot-write", "mini-sign", "mini-pots", "mini-erase", "mini-rocket"];
|
|
5
|
+
declare const illustNames: readonly ["hero-gift", "hero-search", "mini-approve", "mini-documents-2", "mini-documents-3", "mini-documents-4", "mini-documents-5", "mini-documents", "mini-egg", "mini-empty-message", "mini-empty", "mini-gift", "mini-graduation_hat", "mini-not-search", "mini-not-ticket-2", "mini-private", "mini-search", "mini-ticket", "mini-ticket-3", "mini-window", "spot-catch_star", "spot-clap", "spot-empty", "spot-gift", "spot-no_search", "spot-search-2", "spot-search-3", "spot-search-4", "spot-search-5", "spot-search", "spot-sign_up", "spot-team", "spot-write", "mini-sign", "mini-pots", "mini-erase", "mini-rocket", "mini-empty-history", "mini-upload", "mini-empty-search"];
|
|
6
|
+
declare const darkIllustNames: readonly ["hero-gift", "hero-search", "mini-approve", "mini-documents-2", "mini-documents-3", "mini-documents-4", "mini-documents-5", "mini-documents", "mini-egg", "mini-empty-message", "mini-empty", "mini-gift", "mini-graduation_hat", "mini-not-search", "mini-not-ticket-2", "mini-private", "mini-search", "mini-ticket", "mini-ticket-3", "mini-window", "spot-catch_star", "spot-clap", "spot-empty", "spot-gift", "spot-no_search", "spot-search-2", "spot-search-3", "spot-search-4", "spot-search-5", "spot-search", "spot-sign_up", "spot-team", "spot-write", "mini-sign", "mini-pots", "mini-erase", "mini-rocket", "mini-empty-history", "mini-upload", "mini-empty-search"];
|
|
7
7
|
|
|
8
8
|
type LightIllustType = (typeof illustNames)[number];
|
|
9
9
|
type DarkIllustType = (typeof darkIllustNames)[number];
|
package/lib/index.js
CHANGED
|
@@ -40,50 +40,42 @@ var ILLUST = "https://assets.getliner.com/common/illust";
|
|
|
40
40
|
var DARK_MODE_ILLUST_PREFIX = `${ILLUST}/dark/`;
|
|
41
41
|
var LIGHT_MODE_ILLUST_PREFIX = `${ILLUST}/light/`;
|
|
42
42
|
|
|
43
|
-
// src/hooks/useIllust.ts
|
|
44
|
-
import { useDarkTheme } from "@liner-fe/design-token";
|
|
45
|
-
var useIllust = /* @__PURE__ */ __name(({ darkSrc, src }) => {
|
|
46
|
-
const { isDarkMode } = useDarkTheme();
|
|
47
|
-
const sourcePrefix = (() => {
|
|
48
|
-
if (isDarkMode) {
|
|
49
|
-
if (darkSrc?.inverse) {
|
|
50
|
-
return LIGHT_MODE_ILLUST_PREFIX;
|
|
51
|
-
}
|
|
52
|
-
return DARK_MODE_ILLUST_PREFIX;
|
|
53
|
-
}
|
|
54
|
-
if (src.inverse === false) {
|
|
55
|
-
return DARK_MODE_ILLUST_PREFIX;
|
|
56
|
-
}
|
|
57
|
-
return LIGHT_MODE_ILLUST_PREFIX;
|
|
58
|
-
})();
|
|
59
|
-
const currentSourceByColorTheme = isDarkMode ? darkSrc?.name || src.name : src.name;
|
|
60
|
-
return { sourcePrefix, currentSourceByColorTheme, isDarkMode };
|
|
61
|
-
}, "useIllust");
|
|
62
|
-
|
|
63
43
|
// src/components/index.tsx
|
|
64
|
-
import { jsx } from "react/jsx-runtime";
|
|
44
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
65
45
|
var Illust = /* @__PURE__ */ __name((props) => {
|
|
66
46
|
const { src, width, margin } = props;
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const aspectRatio = illustSize[currentSourceByColorTheme] ? illustSize[currentSourceByColorTheme].width / illustSize[currentSourceByColorTheme].height : void 0;
|
|
47
|
+
const darkSource = src.dark?.name || src.light.name;
|
|
48
|
+
const lightSource = src.light.name;
|
|
49
|
+
const aspectRatioDark = illustSize[darkSource] ? illustSize[darkSource].width / illustSize[darkSource].height : void 0;
|
|
50
|
+
const aspectRatio = illustSize[lightSource] ? illustSize[lightSource].width / illustSize[lightSource].height : void 0;
|
|
72
51
|
const css = {
|
|
73
52
|
width,
|
|
74
53
|
margin
|
|
75
54
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
55
|
+
return /* @__PURE__ */ jsxs("div", { style: css, children: [
|
|
56
|
+
/* @__PURE__ */ jsx(
|
|
57
|
+
"img",
|
|
58
|
+
{
|
|
59
|
+
...props,
|
|
60
|
+
alt: lightSource,
|
|
61
|
+
src: `${src.light.inverse === false ? DARK_MODE_ILLUST_PREFIX : LIGHT_MODE_ILLUST_PREFIX}${lightSource}.webp`,
|
|
62
|
+
width,
|
|
63
|
+
height: aspectRatio ? width / aspectRatio : width,
|
|
64
|
+
"data-hide-on-theme": "dark"
|
|
65
|
+
}
|
|
66
|
+
),
|
|
67
|
+
/* @__PURE__ */ jsx(
|
|
68
|
+
"img",
|
|
69
|
+
{
|
|
70
|
+
...props,
|
|
71
|
+
alt: darkSource,
|
|
72
|
+
src: `${src.dark?.inverse ? LIGHT_MODE_ILLUST_PREFIX : DARK_MODE_ILLUST_PREFIX}${darkSource}.webp`,
|
|
73
|
+
width,
|
|
74
|
+
height: aspectRatioDark ? width / aspectRatioDark : width,
|
|
75
|
+
"data-hide-on-theme": "light"
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
] });
|
|
87
79
|
}, "Illust");
|
|
88
80
|
|
|
89
81
|
// src/utils/illust.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liner-fe/illust",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "yarn tsup --config ./config/tsup/tsup.config.ts"
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"main": "./lib/index.js",
|
|
16
16
|
"types": "./lib/index.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@liner-fe/design-token": "workspace:^",
|
|
19
18
|
"react": "^18.2.0",
|
|
20
19
|
"react-dom": "^18.2.0"
|
|
21
20
|
},
|
package/src/components/index.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { illustSize } from '../constants/size';
|
|
2
2
|
import { CSSProperties, DetailedHTMLProps, ImgHTMLAttributes } from 'react';
|
|
3
|
-
import { useIllust } from '../hooks/useIllust';
|
|
4
3
|
import { IllustType } from '../types/illust';
|
|
5
4
|
import { Property } from 'csstype';
|
|
5
|
+
import { DARK_MODE_ILLUST_PREFIX, LIGHT_MODE_ILLUST_PREFIX } from '@/constants/path';
|
|
6
6
|
|
|
7
7
|
export interface Source<T extends false | true = true> {
|
|
8
8
|
name: IllustType;
|
|
@@ -18,13 +18,16 @@ export interface IllustProps
|
|
|
18
18
|
|
|
19
19
|
export const Illust = (props: IllustProps) => {
|
|
20
20
|
const { src, width, margin } = props;
|
|
21
|
-
const { sourcePrefix, currentSourceByColorTheme } = useIllust({
|
|
22
|
-
darkSrc: src.dark,
|
|
23
|
-
src: src.light,
|
|
24
|
-
});
|
|
25
21
|
|
|
26
|
-
const
|
|
27
|
-
|
|
22
|
+
const darkSource = src.dark?.name || src.light.name;
|
|
23
|
+
const lightSource = src.light.name;
|
|
24
|
+
|
|
25
|
+
const aspectRatioDark = illustSize[darkSource]
|
|
26
|
+
? illustSize[darkSource].width / illustSize[darkSource].height
|
|
27
|
+
: undefined;
|
|
28
|
+
|
|
29
|
+
const aspectRatio = illustSize[lightSource]
|
|
30
|
+
? illustSize[lightSource].width / illustSize[lightSource].height
|
|
28
31
|
: undefined;
|
|
29
32
|
|
|
30
33
|
const css: CSSProperties = {
|
|
@@ -32,16 +35,24 @@ export const Illust = (props: IllustProps) => {
|
|
|
32
35
|
margin,
|
|
33
36
|
};
|
|
34
37
|
|
|
35
|
-
const source = `${sourcePrefix}${currentSourceByColorTheme}.webp`;
|
|
36
|
-
|
|
37
38
|
return (
|
|
38
39
|
<div style={css}>
|
|
39
40
|
<img
|
|
40
41
|
{...props}
|
|
41
|
-
alt={
|
|
42
|
-
src={
|
|
42
|
+
alt={lightSource}
|
|
43
|
+
src={`${src.light.inverse === false ? DARK_MODE_ILLUST_PREFIX : LIGHT_MODE_ILLUST_PREFIX}${lightSource}.webp`}
|
|
43
44
|
width={width}
|
|
44
45
|
height={aspectRatio ? width / aspectRatio : width}
|
|
46
|
+
data-hide-on-theme={'dark'}
|
|
47
|
+
/>
|
|
48
|
+
{/* dark */}
|
|
49
|
+
<img
|
|
50
|
+
{...props}
|
|
51
|
+
alt={darkSource}
|
|
52
|
+
src={`${src.dark?.inverse ? LIGHT_MODE_ILLUST_PREFIX : DARK_MODE_ILLUST_PREFIX}${darkSource}.webp`}
|
|
53
|
+
width={width}
|
|
54
|
+
height={aspectRatioDark ? width / aspectRatioDark : width}
|
|
55
|
+
data-hide-on-theme={'light'}
|
|
45
56
|
/>
|
|
46
57
|
</div>
|
|
47
58
|
);
|
package/src/constants/name.ts
CHANGED
|
@@ -36,6 +36,9 @@ export const illustNames = [
|
|
|
36
36
|
'mini-pots',
|
|
37
37
|
'mini-erase',
|
|
38
38
|
'mini-rocket',
|
|
39
|
+
'mini-empty-history',
|
|
40
|
+
'mini-upload',
|
|
41
|
+
'mini-empty-search',
|
|
39
42
|
] as const;
|
|
40
43
|
export const darkIllustNames = [
|
|
41
44
|
'hero-gift',
|
|
@@ -75,4 +78,7 @@ export const darkIllustNames = [
|
|
|
75
78
|
'mini-pots',
|
|
76
79
|
'mini-erase',
|
|
77
80
|
'mini-rocket',
|
|
81
|
+
'mini-empty-history',
|
|
82
|
+
'mini-upload',
|
|
83
|
+
'mini-empty-search',
|
|
78
84
|
] as const;
|
package/src/hooks/useIllust.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Source } from '../components/index';
|
|
2
|
-
import { DARK_MODE_ILLUST_PREFIX, LIGHT_MODE_ILLUST_PREFIX } from '../constants/path';
|
|
3
|
-
import { useDarkTheme } from '@liner-fe/design-token';
|
|
4
|
-
|
|
5
|
-
export const useIllust = ({ darkSrc, src }: { darkSrc?: Source; src: Source<false> }) => {
|
|
6
|
-
const { isDarkMode } = useDarkTheme();
|
|
7
|
-
|
|
8
|
-
const sourcePrefix = (() => {
|
|
9
|
-
if (isDarkMode) {
|
|
10
|
-
if (darkSrc?.inverse) {
|
|
11
|
-
return LIGHT_MODE_ILLUST_PREFIX;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return DARK_MODE_ILLUST_PREFIX;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (src.inverse === false) {
|
|
18
|
-
return DARK_MODE_ILLUST_PREFIX;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return LIGHT_MODE_ILLUST_PREFIX;
|
|
22
|
-
})();
|
|
23
|
-
|
|
24
|
-
const currentSourceByColorTheme = isDarkMode ? darkSrc?.name || src.name : src.name;
|
|
25
|
-
|
|
26
|
-
return { sourcePrefix, currentSourceByColorTheme, isDarkMode };
|
|
27
|
-
};
|