@liner-fe/illust 0.1.3 → 0.1.4

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,11 @@
1
1
  # @liner-fe/illust
2
2
 
3
+ ## 0.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - e5cfc5c: ESM으로 전부 마이그레이션
8
+
3
9
  ## 0.1.3
4
10
 
5
11
  ### 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,97 @@
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/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
+ // src/components/index.tsx
64
+ import { jsx } from "react/jsx-runtime";
65
+ var Illust = /* @__PURE__ */ __name((props) => {
66
+ const { src, width, margin } = props;
67
+ const { sourcePrefix, currentSourceByColorTheme } = useIllust({
68
+ darkSrc: src.dark,
69
+ src: src.light
70
+ });
71
+ const aspectRatio = illustSize[currentSourceByColorTheme] ? illustSize[currentSourceByColorTheme].width / illustSize[currentSourceByColorTheme].height : void 0;
72
+ const css = {
73
+ width,
74
+ margin
75
+ };
76
+ const source = `${sourcePrefix}${currentSourceByColorTheme}.webp`;
77
+ return /* @__PURE__ */ jsx("div", { style: css, children: /* @__PURE__ */ jsx(
78
+ "img",
79
+ {
80
+ ...props,
81
+ alt: currentSourceByColorTheme,
82
+ src: source,
83
+ width,
84
+ height: aspectRatio ? width / aspectRatio : width
85
+ }
86
+ ) });
87
+ }, "Illust");
88
+
89
+ // src/utils/illust.ts
90
+ var prefetchIllust = /* @__PURE__ */ __name(async ({
91
+ name,
92
+ isDark = false
93
+ }) => await fetch(`${ILLUST}${isDark ? "/dark/" : "/light/"}${name}.webp`), "prefetchIllust");
94
+ export {
95
+ Illust,
96
+ prefetchIllust
97
+ };
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@liner-fe/illust",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
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
18
  "@liner-fe/design-token": "workspace:^",
17
19
  "react": "^18.2.0",
@@ -1,6 +1,5 @@
1
1
  import { illustSize } from '../constants/size';
2
- import Image, { ImageProps } from 'next/image';
3
- import { CSSProperties } from 'react';
2
+ import { CSSProperties, DetailedHTMLProps, ImgHTMLAttributes } from 'react';
4
3
  import { useIllust } from '../hooks/useIllust';
5
4
  import { IllustType } from '../types/illust';
6
5
  import { Property } from 'csstype';
@@ -10,7 +9,8 @@ export interface Source<T extends false | true = true> {
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>;
@@ -36,13 +36,12 @@ export const Illust = (props: IllustProps) => {
36
36
 
37
37
  return (
38
38
  <div style={css}>
39
- <Image
39
+ <img
40
40
  {...props}
41
41
  alt={currentSourceByColorTheme}
42
42
  src={source}
43
43
  width={width}
44
44
  height={aspectRatio ? width / aspectRatio : width}
45
- unoptimized
46
45
  />
47
46
  </div>
48
47
  );