@liner-fe/illust 0.1.3 → 0.1.5

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @liner-fe/illust
2
2
 
3
+ ## 0.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 99448a8: illust design token 의존성 삭제
8
+
9
+ ## 0.1.4
10
+
11
+ ### Patch Changes
12
+
13
+ - e5cfc5c: ESM으로 전부 마이그레이션
14
+
3
15
  ## 0.1.3
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,19 @@
1
+ import { defineConfig } from 'tsup';
2
+ import { nodeExternalsPlugin } from 'esbuild-node-externals';
3
+
4
+ export default defineConfig({
5
+ entry: ['src/index.ts'],
6
+ outDir: 'lib',
7
+ // 이거는 무슨 옵션일까?
8
+ // splitting: false,
9
+ format: 'esm',
10
+ bundle: true,
11
+ minify: false,
12
+ keepNames: true,
13
+ jsxFactory: 'React.createElement',
14
+ jsxFragment: 'Fragment',
15
+ tsconfig: './tsconfig.build.json',
16
+ platform: 'neutral',
17
+ dts: true,
18
+ esbuildPlugins: [nodeExternalsPlugin()],
19
+ });
package/lib/index.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { DetailedHTMLProps, ImgHTMLAttributes } from 'react';
3
+ import { Property } from 'csstype';
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"];
7
+
8
+ type LightIllustType = (typeof illustNames)[number];
9
+ type DarkIllustType = (typeof darkIllustNames)[number];
10
+ type IllustType = DarkIllustType | LightIllustType;
11
+
12
+ interface Source<T extends false | true = true> {
13
+ name: IllustType;
14
+ inverse?: T;
15
+ }
16
+ interface IllustProps extends Omit<DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, 'src'> {
17
+ width: number;
18
+ src: {
19
+ light: Source<false>;
20
+ dark?: Source;
21
+ };
22
+ margin?: Property.Margin<string>;
23
+ }
24
+ declare const Illust: (props: IllustProps) => react_jsx_runtime.JSX.Element;
25
+
26
+ declare const prefetchIllust: ({ name, isDark, }: {
27
+ name: IllustType;
28
+ isDark?: boolean;
29
+ }) => Promise<Response>;
30
+
31
+ export { Illust, type IllustProps, type Source, prefetchIllust };
package/lib/index.js ADDED
@@ -0,0 +1,89 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/constants/size.ts
5
+ var ratio = {
6
+ "4:3": { width: 180, height: 135 },
7
+ "1:1": { width: 250, height: 250 }
8
+ };
9
+ var illustSize = {
10
+ "hero-gift": ratio["1:1"],
11
+ "hero-search": ratio["1:1"],
12
+ "mini-documents-2": ratio["1:1"],
13
+ "mini-documents-3": ratio["1:1"],
14
+ "mini-documents-4": ratio["1:1"],
15
+ "mini-documents-5": ratio["1:1"],
16
+ "mini-documents": ratio["1:1"],
17
+ "mini-egg": ratio["1:1"],
18
+ "mini-gift": ratio["1:1"],
19
+ "mini-graduation_hat": ratio["1:1"],
20
+ "mini-search": ratio["1:1"],
21
+ "mini-ticket": ratio["1:1"],
22
+ "mini-window": ratio["1:1"],
23
+ "spot-catch_star": ratio["4:3"],
24
+ "spot-clap": ratio["4:3"],
25
+ "spot-empty": ratio["4:3"],
26
+ "spot-no_search": ratio["4:3"],
27
+ "spot-search-2": ratio["4:3"],
28
+ "spot-search-3": ratio["4:3"],
29
+ "spot-search-4": ratio["4:3"],
30
+ "spot-search-5": ratio["4:3"],
31
+ "spot-search": ratio["4:3"],
32
+ "spot-write": ratio["4:3"],
33
+ "spot-gift": ratio["4:3"],
34
+ "mini-empty": ratio["1:1"],
35
+ "spot-team": ratio["4:3"]
36
+ };
37
+
38
+ // src/constants/path.ts
39
+ var ILLUST = "https://assets.getliner.com/common/illust";
40
+ var DARK_MODE_ILLUST_PREFIX = `${ILLUST}/dark/`;
41
+ var LIGHT_MODE_ILLUST_PREFIX = `${ILLUST}/light/`;
42
+
43
+ // src/components/index.tsx
44
+ import { jsx, jsxs } from "react/jsx-runtime";
45
+ var Illust = /* @__PURE__ */ __name((props) => {
46
+ const { src, width, margin } = props;
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;
51
+ const css = {
52
+ width,
53
+ margin
54
+ };
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
+ ] });
79
+ }, "Illust");
80
+
81
+ // src/utils/illust.ts
82
+ var prefetchIllust = /* @__PURE__ */ __name(async ({
83
+ name,
84
+ isDark = false
85
+ }) => await fetch(`${ILLUST}${isDark ? "/dark/" : "/light/"}${name}.webp`), "prefetchIllust");
86
+ export {
87
+ Illust,
88
+ prefetchIllust
89
+ };
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "@liner-fe/illust",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
+ "type": "module",
4
5
  "scripts": {
5
- "build": ""
6
+ "build": "yarn tsup --config ./config/tsup/tsup.config.ts"
6
7
  },
7
- "sideEffects": false,
8
8
  "publishConfig": {
9
- "access": "public"
9
+ "access": "public",
10
+ "main": "./lib/index.js"
10
11
  },
11
12
  "files": [
12
13
  "*"
13
14
  ],
14
- "main": "./src/index.ts",
15
+ "main": "./lib/index.js",
16
+ "types": "./lib/index.d.ts",
15
17
  "dependencies": {
16
- "@liner-fe/design-token": "workspace:^",
17
18
  "react": "^18.2.0",
18
19
  "react-dom": "^18.2.0"
19
20
  },
@@ -1,16 +1,16 @@
1
1
  import { illustSize } from '../constants/size';
2
- import Image, { ImageProps } from 'next/image';
3
- import { CSSProperties } from 'react';
4
- import { useIllust } from '../hooks/useIllust';
2
+ import { CSSProperties, DetailedHTMLProps, ImgHTMLAttributes } from 'react';
5
3
  import { IllustType } from '../types/illust';
6
4
  import { Property } from 'csstype';
5
+ import { DARK_MODE_ILLUST_PREFIX, LIGHT_MODE_ILLUST_PREFIX } from '@/constants/path';
7
6
 
8
7
  export interface Source<T extends false | true = true> {
9
8
  name: IllustType;
10
9
  inverse?: T;
11
10
  }
12
11
 
13
- export interface IllustProps extends Omit<ImageProps, 'alt' | 'width' | 'height' | 'fill' | 'src'> {
12
+ export interface IllustProps
13
+ extends Omit<DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, 'src'> {
14
14
  width: number;
15
15
  src: { light: Source<false>; dark?: Source };
16
16
  margin?: Property.Margin<string>;
@@ -18,13 +18,16 @@ export interface IllustProps extends Omit<ImageProps, 'alt' | 'width' | 'height'
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 aspectRatio = illustSize[currentSourceByColorTheme]
27
- ? illustSize[currentSourceByColorTheme].width / illustSize[currentSourceByColorTheme].height
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,17 +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
- <Image
40
+ <img
40
41
  {...props}
41
- alt={currentSourceByColorTheme}
42
- src={source}
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}
45
- unoptimized
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'}
46
56
  />
47
57
  </div>
48
58
  );
@@ -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
- };