@liner-fe/illust 0.1.1
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/.gitignore +1 -0
- package/CHANGELOG.md +7 -0
- package/config/tsup/tsup.config.ts +19 -0
- package/lib/index.d.ts +31 -0
- package/lib/index.js +3064 -0
- package/package.json +28 -0
- package/src/components/index.tsx +49 -0
- package/src/constants/name.ts +78 -0
- package/src/constants/path.ts +4 -0
- package/src/constants/size.ts +35 -0
- package/src/hooks/useIllust.ts +27 -0
- package/src/index.ts +2 -0
- package/src/types/illust.ts +5 -0
- package/src/utils/illust.ts +10 -0
- package/tsconfig.build.json +35 -0
- package/tsconfig.json +29 -0
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@liner-fe/illust",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "yarn tsup --config ./config/tsup/tsup.config.ts"
|
|
6
|
+
},
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"main": "./lib/index.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"*"
|
|
14
|
+
],
|
|
15
|
+
"main": "./lib/index.js",
|
|
16
|
+
"types": "./lib/index.d.ts",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@liner-fe/design-token": "workspace:^",
|
|
19
|
+
"react": "^18.2.0",
|
|
20
|
+
"react-dom": "^18.2.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/react": "^18.2.12",
|
|
24
|
+
"@types/react-dom": "^18.2.5",
|
|
25
|
+
"esbuild-node-externals": "1.18.0",
|
|
26
|
+
"tsup": "^8.5.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { illustSize } from '../constants/size';
|
|
2
|
+
import Image, { ImageProps } from 'next/image';
|
|
3
|
+
import { CSSProperties } from 'react';
|
|
4
|
+
import { useIllust } from '../hooks/useIllust';
|
|
5
|
+
import { IllustType } from '../types/illust';
|
|
6
|
+
import { Property } from 'csstype';
|
|
7
|
+
|
|
8
|
+
export interface Source<T extends false | true = true> {
|
|
9
|
+
name: IllustType;
|
|
10
|
+
inverse?: T;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface IllustProps extends Omit<ImageProps, 'alt' | 'width' | 'height' | 'fill' | 'src'> {
|
|
14
|
+
width: number;
|
|
15
|
+
src: { light: Source<false>; dark?: Source };
|
|
16
|
+
margin?: Property.Margin<string>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const Illust = (props: IllustProps) => {
|
|
20
|
+
const { src, width, margin } = props;
|
|
21
|
+
const { sourcePrefix, currentSourceByColorTheme } = useIllust({
|
|
22
|
+
darkSrc: src.dark,
|
|
23
|
+
src: src.light,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const aspectRatio = illustSize[currentSourceByColorTheme]
|
|
27
|
+
? illustSize[currentSourceByColorTheme].width / illustSize[currentSourceByColorTheme].height
|
|
28
|
+
: undefined;
|
|
29
|
+
|
|
30
|
+
const css: CSSProperties = {
|
|
31
|
+
width,
|
|
32
|
+
margin,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const source = `${sourcePrefix}${currentSourceByColorTheme}.webp`;
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div style={css}>
|
|
39
|
+
<Image
|
|
40
|
+
{...props}
|
|
41
|
+
alt={currentSourceByColorTheme}
|
|
42
|
+
src={source}
|
|
43
|
+
width={width}
|
|
44
|
+
height={aspectRatio ? width / aspectRatio : width}
|
|
45
|
+
unoptimized
|
|
46
|
+
/>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export const illustNames = [
|
|
2
|
+
'hero-gift',
|
|
3
|
+
'hero-search',
|
|
4
|
+
'mini-approve',
|
|
5
|
+
'mini-documents-2',
|
|
6
|
+
'mini-documents-3',
|
|
7
|
+
'mini-documents-4',
|
|
8
|
+
'mini-documents-5',
|
|
9
|
+
'mini-documents',
|
|
10
|
+
'mini-egg',
|
|
11
|
+
'mini-empty-message',
|
|
12
|
+
'mini-empty',
|
|
13
|
+
'mini-gift',
|
|
14
|
+
'mini-graduation_hat',
|
|
15
|
+
'mini-not-search',
|
|
16
|
+
'mini-not-ticket-2',
|
|
17
|
+
'mini-private',
|
|
18
|
+
'mini-search',
|
|
19
|
+
'mini-ticket',
|
|
20
|
+
'mini-ticket-3',
|
|
21
|
+
'mini-window',
|
|
22
|
+
'spot-catch_star',
|
|
23
|
+
'spot-clap',
|
|
24
|
+
'spot-empty',
|
|
25
|
+
'spot-gift',
|
|
26
|
+
'spot-no_search',
|
|
27
|
+
'spot-search-2',
|
|
28
|
+
'spot-search-3',
|
|
29
|
+
'spot-search-4',
|
|
30
|
+
'spot-search-5',
|
|
31
|
+
'spot-search',
|
|
32
|
+
'spot-sign_up',
|
|
33
|
+
'spot-team',
|
|
34
|
+
'spot-write',
|
|
35
|
+
'mini-sign',
|
|
36
|
+
'mini-pots',
|
|
37
|
+
'mini-erase',
|
|
38
|
+
'mini-rocket',
|
|
39
|
+
] as const;
|
|
40
|
+
export const darkIllustNames = [
|
|
41
|
+
'hero-gift',
|
|
42
|
+
'hero-search',
|
|
43
|
+
'mini-approve',
|
|
44
|
+
'mini-documents-2',
|
|
45
|
+
'mini-documents-3',
|
|
46
|
+
'mini-documents-4',
|
|
47
|
+
'mini-documents-5',
|
|
48
|
+
'mini-documents',
|
|
49
|
+
'mini-egg',
|
|
50
|
+
'mini-empty-message',
|
|
51
|
+
'mini-empty',
|
|
52
|
+
'mini-gift',
|
|
53
|
+
'mini-graduation_hat',
|
|
54
|
+
'mini-not-search',
|
|
55
|
+
'mini-not-ticket-2',
|
|
56
|
+
'mini-private',
|
|
57
|
+
'mini-search',
|
|
58
|
+
'mini-ticket',
|
|
59
|
+
'mini-ticket-3',
|
|
60
|
+
'mini-window',
|
|
61
|
+
'spot-catch_star',
|
|
62
|
+
'spot-clap',
|
|
63
|
+
'spot-empty',
|
|
64
|
+
'spot-gift',
|
|
65
|
+
'spot-no_search',
|
|
66
|
+
'spot-search-2',
|
|
67
|
+
'spot-search-3',
|
|
68
|
+
'spot-search-4',
|
|
69
|
+
'spot-search-5',
|
|
70
|
+
'spot-search',
|
|
71
|
+
'spot-sign_up',
|
|
72
|
+
'spot-team',
|
|
73
|
+
'spot-write',
|
|
74
|
+
'mini-sign',
|
|
75
|
+
'mini-pots',
|
|
76
|
+
'mini-erase',
|
|
77
|
+
'mini-rocket',
|
|
78
|
+
] as const;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IllustType } from '../types/illust';
|
|
2
|
+
|
|
3
|
+
const ratio = {
|
|
4
|
+
'4:3': { width: 180, height: 135 },
|
|
5
|
+
'1:1': { width: 250, height: 250 },
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const illustSize: Partial<Record<IllustType, { width: number; height: number }>> = {
|
|
9
|
+
'hero-gift': ratio['1:1'],
|
|
10
|
+
'hero-search': ratio['1:1'],
|
|
11
|
+
'mini-documents-2': ratio['1:1'],
|
|
12
|
+
'mini-documents-3': ratio['1:1'],
|
|
13
|
+
'mini-documents-4': ratio['1:1'],
|
|
14
|
+
'mini-documents-5': ratio['1:1'],
|
|
15
|
+
'mini-documents': ratio['1:1'],
|
|
16
|
+
'mini-egg': ratio['1:1'],
|
|
17
|
+
'mini-gift': ratio['1:1'],
|
|
18
|
+
'mini-graduation_hat': ratio['1:1'],
|
|
19
|
+
'mini-search': ratio['1:1'],
|
|
20
|
+
'mini-ticket': ratio['1:1'],
|
|
21
|
+
'mini-window': ratio['1:1'],
|
|
22
|
+
'spot-catch_star': ratio['4:3'],
|
|
23
|
+
'spot-clap': ratio['4:3'],
|
|
24
|
+
'spot-empty': ratio['4:3'],
|
|
25
|
+
'spot-no_search': ratio['4:3'],
|
|
26
|
+
'spot-search-2': ratio['4:3'],
|
|
27
|
+
'spot-search-3': ratio['4:3'],
|
|
28
|
+
'spot-search-4': ratio['4:3'],
|
|
29
|
+
'spot-search-5': ratio['4:3'],
|
|
30
|
+
'spot-search': ratio['4:3'],
|
|
31
|
+
'spot-write': ratio['4:3'],
|
|
32
|
+
'spot-gift': ratio['4:3'],
|
|
33
|
+
'mini-empty': ratio['1:1'],
|
|
34
|
+
'spot-team': ratio['4:3'],
|
|
35
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ILLUST } from '../constants/path';
|
|
2
|
+
import { IllustType } from '../types/illust';
|
|
3
|
+
|
|
4
|
+
export const prefetchIllust = async ({
|
|
5
|
+
name,
|
|
6
|
+
isDark = false,
|
|
7
|
+
}: {
|
|
8
|
+
name: IllustType;
|
|
9
|
+
isDark?: boolean;
|
|
10
|
+
}) => await fetch(`${ILLUST}${isDark ? '/dark/' : '/light/'}${name}.webp`);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"emitDeclarationOnly": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"incremental": false,
|
|
9
|
+
"jsx": "react-jsx",
|
|
10
|
+
"rootDir": "src",
|
|
11
|
+
"outDir": "lib",
|
|
12
|
+
"module": "ESNext",
|
|
13
|
+
"moduleResolution": "Bundler",
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"declaration": true,
|
|
17
|
+
"strict": true,
|
|
18
|
+
"noImplicitAny": true,
|
|
19
|
+
"resolveJsonModule": true,
|
|
20
|
+
"baseUrl": ".",
|
|
21
|
+
"plugins": [
|
|
22
|
+
{
|
|
23
|
+
"name": "next"
|
|
24
|
+
}
|
|
25
|
+
// {
|
|
26
|
+
// "name": "typescript-plugin-css-modules"
|
|
27
|
+
// }
|
|
28
|
+
],
|
|
29
|
+
"paths": {
|
|
30
|
+
"@/*": ["./src/*"]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"include": ["next-env.d.ts", "src/**/*.ts", "src/**/*.tsx", ".next/types/**/*.ts"],
|
|
34
|
+
"exclude": ["node_modules", "**/*.stories.ts", "**/*.stories.tsx"]
|
|
35
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"noEmit": false,
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"jsx": "preserve",
|
|
11
|
+
"incremental": true,
|
|
12
|
+
"baseUrl": ".",
|
|
13
|
+
"module": "ESNext",
|
|
14
|
+
"moduleResolution": "Bundler",
|
|
15
|
+
"plugins": [
|
|
16
|
+
{
|
|
17
|
+
"name": "next"
|
|
18
|
+
}
|
|
19
|
+
// {
|
|
20
|
+
// "name": "typescript-plugin-css-modules"
|
|
21
|
+
// }
|
|
22
|
+
],
|
|
23
|
+
"paths": {
|
|
24
|
+
"@/*": ["./src/*"]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "../illust/src/utils/illust.ts", "../illust/src/types/illust.ts"],
|
|
28
|
+
"exclude": ["node_modules"]
|
|
29
|
+
}
|