@sangwonl/pocato-react 0.1.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.
- package/dist/index.d.ts +29 -0
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
import { PocaCardOptions } from '@sangwonl/pocato-core';
|
|
4
|
+
|
|
5
|
+
interface PocaCardHandle {
|
|
6
|
+
flip(): void;
|
|
7
|
+
wiggle(): void;
|
|
8
|
+
reset(): void;
|
|
9
|
+
}
|
|
10
|
+
interface PocaCardProps {
|
|
11
|
+
type: PocaCardOptions['type'];
|
|
12
|
+
baseImage: string;
|
|
13
|
+
popupImage?: string;
|
|
14
|
+
maskImage?: string;
|
|
15
|
+
backImage?: string;
|
|
16
|
+
flippable?: boolean;
|
|
17
|
+
initialFlipped?: boolean;
|
|
18
|
+
customShader?: string;
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
backContent?: ReactNode;
|
|
21
|
+
onFlip?: (flipped: boolean) => void;
|
|
22
|
+
onReady?: () => void;
|
|
23
|
+
onError?: (error: Error) => void;
|
|
24
|
+
style?: CSSProperties;
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
declare const PocaCard: react.ForwardRefExoticComponent<PocaCardProps & react.RefAttributes<PocaCardHandle>>;
|
|
28
|
+
|
|
29
|
+
export { PocaCard, type PocaCardHandle, type PocaCardProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/PocaCard.tsx
|
|
2
|
+
import {
|
|
3
|
+
forwardRef,
|
|
4
|
+
useEffect,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
useRef,
|
|
7
|
+
useState
|
|
8
|
+
} from "react";
|
|
9
|
+
import { createPortal } from "react-dom";
|
|
10
|
+
import { PocaCard as CorePocaCard } from "@sangwonl/pocato-core";
|
|
11
|
+
import { jsxs } from "react/jsx-runtime";
|
|
12
|
+
var PocaCard = forwardRef(
|
|
13
|
+
(props, ref) => {
|
|
14
|
+
const containerRef = useRef(null);
|
|
15
|
+
const cardRef = useRef(null);
|
|
16
|
+
const [portalTargets, setPortalTargets] = useState({ front: null, back: null });
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!containerRef.current) return;
|
|
19
|
+
const card = new CorePocaCard(containerRef.current, {
|
|
20
|
+
type: props.type,
|
|
21
|
+
baseImage: props.baseImage,
|
|
22
|
+
popupImage: props.popupImage,
|
|
23
|
+
maskImage: props.maskImage,
|
|
24
|
+
backImage: props.backImage,
|
|
25
|
+
flippable: props.flippable,
|
|
26
|
+
initialFlipped: props.initialFlipped,
|
|
27
|
+
customShader: props.customShader
|
|
28
|
+
});
|
|
29
|
+
cardRef.current = card;
|
|
30
|
+
setPortalTargets({
|
|
31
|
+
front: card.getFrontContentEl(),
|
|
32
|
+
back: card.getBackContentEl()
|
|
33
|
+
});
|
|
34
|
+
return () => {
|
|
35
|
+
card.destroy();
|
|
36
|
+
cardRef.current = null;
|
|
37
|
+
setPortalTargets({ front: null, back: null });
|
|
38
|
+
};
|
|
39
|
+
}, [props.type]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
cardRef.current?.updateOptions({
|
|
42
|
+
baseImage: props.baseImage,
|
|
43
|
+
popupImage: props.popupImage,
|
|
44
|
+
maskImage: props.maskImage
|
|
45
|
+
});
|
|
46
|
+
}, [props.baseImage, props.popupImage, props.maskImage]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (props.customShader) {
|
|
49
|
+
cardRef.current?.updateOptions({ customShader: props.customShader });
|
|
50
|
+
}
|
|
51
|
+
}, [props.customShader]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const card = cardRef.current;
|
|
54
|
+
if (!card) return;
|
|
55
|
+
const onFlip = props.onFlip;
|
|
56
|
+
const onReady = props.onReady;
|
|
57
|
+
const onError = props.onError;
|
|
58
|
+
if (onFlip) card.on("flip", onFlip);
|
|
59
|
+
if (onReady) card.on("ready", onReady);
|
|
60
|
+
if (onError) card.on("error", onError);
|
|
61
|
+
return () => {
|
|
62
|
+
if (onFlip) card.off("flip", onFlip);
|
|
63
|
+
if (onReady) card.off("ready", onReady);
|
|
64
|
+
if (onError) card.off("error", onError);
|
|
65
|
+
};
|
|
66
|
+
}, [props.onFlip, props.onReady, props.onError]);
|
|
67
|
+
useImperativeHandle(ref, () => ({
|
|
68
|
+
flip: () => cardRef.current?.flip(),
|
|
69
|
+
wiggle: () => cardRef.current?.wiggle(),
|
|
70
|
+
reset: () => cardRef.current?.reset()
|
|
71
|
+
}));
|
|
72
|
+
return /* @__PURE__ */ jsxs(
|
|
73
|
+
"div",
|
|
74
|
+
{
|
|
75
|
+
ref: containerRef,
|
|
76
|
+
style: props.style,
|
|
77
|
+
className: props.className,
|
|
78
|
+
children: [
|
|
79
|
+
portalTargets.front && props.children && createPortal(props.children, portalTargets.front),
|
|
80
|
+
portalTargets.back && props.backContent && createPortal(props.backContent, portalTargets.back)
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
PocaCard.displayName = "PocaCard";
|
|
87
|
+
export {
|
|
88
|
+
PocaCard
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/PocaCard.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n} from 'react'\nimport { createPortal } from 'react-dom'\nimport { PocaCard as CorePocaCard, type PocaCardOptions } from '@sangwonl/pocato-core'\n\nexport interface PocaCardHandle {\n flip(): void\n wiggle(): void\n reset(): void\n}\n\nexport interface PocaCardProps {\n type: PocaCardOptions['type']\n baseImage: string\n popupImage?: string\n maskImage?: string\n backImage?: string\n flippable?: boolean\n initialFlipped?: boolean\n customShader?: string\n children?: ReactNode\n backContent?: ReactNode\n onFlip?: (flipped: boolean) => void\n onReady?: () => void\n onError?: (error: Error) => void\n style?: CSSProperties\n className?: string\n}\n\nexport const PocaCard = forwardRef<PocaCardHandle, PocaCardProps>(\n (props, ref) => {\n const containerRef = useRef<HTMLDivElement>(null)\n const cardRef = useRef<CorePocaCard | null>(null)\n const [portalTargets, setPortalTargets] = useState<{\n front: HTMLElement | null\n back: HTMLElement | null\n }>({ front: null, back: null })\n\n // Create/destroy core instance\n useEffect(() => {\n if (!containerRef.current) return\n\n const card = new CorePocaCard(containerRef.current, {\n type: props.type,\n baseImage: props.baseImage,\n popupImage: props.popupImage,\n maskImage: props.maskImage,\n backImage: props.backImage,\n flippable: props.flippable,\n initialFlipped: props.initialFlipped,\n customShader: props.customShader,\n })\n\n cardRef.current = card\n setPortalTargets({\n front: card.getFrontContentEl(),\n back: card.getBackContentEl(),\n })\n\n return () => {\n card.destroy()\n cardRef.current = null\n setPortalTargets({ front: null, back: null })\n }\n // Re-create only when type changes (major config change)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props.type])\n\n // Sync image options\n useEffect(() => {\n cardRef.current?.updateOptions({\n baseImage: props.baseImage,\n popupImage: props.popupImage,\n maskImage: props.maskImage,\n })\n }, [props.baseImage, props.popupImage, props.maskImage])\n\n // Sync custom shader\n useEffect(() => {\n if (props.customShader) {\n cardRef.current?.updateOptions({ customShader: props.customShader })\n }\n }, [props.customShader])\n\n // Bind events\n useEffect(() => {\n const card = cardRef.current\n if (!card) return\n\n const onFlip = props.onFlip\n const onReady = props.onReady\n const onError = props.onError\n\n if (onFlip) card.on('flip', onFlip)\n if (onReady) card.on('ready', onReady)\n if (onError) card.on('error', onError)\n\n return () => {\n if (onFlip) card.off('flip', onFlip)\n if (onReady) card.off('ready', onReady)\n if (onError) card.off('error', onError)\n }\n }, [props.onFlip, props.onReady, props.onError])\n\n // Expose imperative handle\n useImperativeHandle(ref, () => ({\n flip: () => cardRef.current?.flip(),\n wiggle: () => cardRef.current?.wiggle(),\n reset: () => cardRef.current?.reset(),\n }))\n\n return (\n <div\n ref={containerRef}\n style={props.style}\n className={props.className}\n >\n {portalTargets.front && props.children && createPortal(props.children, portalTargets.front)}\n {portalTargets.back && props.backContent && createPortal(props.backContent, portalTargets.back)}\n </div>\n )\n },\n)\n\nPocaCard.displayName = 'PocaCard'\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,oBAAoB;AAC7B,SAAS,YAAY,oBAA0C;AA6GzD;AAnFC,IAAM,WAAW;AAAA,EACtB,CAAC,OAAO,QAAQ;AACd,UAAM,eAAe,OAAuB,IAAI;AAChD,UAAM,UAAU,OAA4B,IAAI;AAChD,UAAM,CAAC,eAAe,gBAAgB,IAAI,SAGvC,EAAE,OAAO,MAAM,MAAM,KAAK,CAAC;AAG9B,cAAU,MAAM;AACd,UAAI,CAAC,aAAa,QAAS;AAE3B,YAAM,OAAO,IAAI,aAAa,aAAa,SAAS;AAAA,QAClD,MAAM,MAAM;AAAA,QACZ,WAAW,MAAM;AAAA,QACjB,YAAY,MAAM;AAAA,QAClB,WAAW,MAAM;AAAA,QACjB,WAAW,MAAM;AAAA,QACjB,WAAW,MAAM;AAAA,QACjB,gBAAgB,MAAM;AAAA,QACtB,cAAc,MAAM;AAAA,MACtB,CAAC;AAED,cAAQ,UAAU;AAClB,uBAAiB;AAAA,QACf,OAAO,KAAK,kBAAkB;AAAA,QAC9B,MAAM,KAAK,iBAAiB;AAAA,MAC9B,CAAC;AAED,aAAO,MAAM;AACX,aAAK,QAAQ;AACb,gBAAQ,UAAU;AAClB,yBAAiB,EAAE,OAAO,MAAM,MAAM,KAAK,CAAC;AAAA,MAC9C;AAAA,IAGF,GAAG,CAAC,MAAM,IAAI,CAAC;AAGf,cAAU,MAAM;AAC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I;AAAA;AAAA;AAAA,IAChG;AAAA,EAEJ;AACF;AAEA,SAAS,cAAc;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sangwonl/pocato-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"author": "Sangwon Lee <gamzabaw@gmail.com>",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/sangwonl/pocato"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": ["dist"],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup",
|
|
25
|
+
"dev": "tsup --watch"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@sangwonl/pocato-core": "0.1.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
32
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsup": "^8.0.0",
|
|
36
|
+
"typescript": "^5.8.0",
|
|
37
|
+
"react": "^19.0.0",
|
|
38
|
+
"@types/react": "^19.0.0"
|
|
39
|
+
}
|
|
40
|
+
}
|