@chao-component/bag-animation-ui 1.0.2 → 1.0.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/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +105 -69
- package/dist/index.mjs +105 -69
- package/package.json +8 -3
- package/scripts/copy-assets.js +66 -0
- package/vite-plugin.js +86 -0
- package/webpack-plugin.js +70 -0
package/dist/index.d.mts
CHANGED
|
@@ -8,8 +8,11 @@ interface BagAnimationProps {
|
|
|
8
8
|
defaultImage?: string;
|
|
9
9
|
defaultImageAlt?: string;
|
|
10
10
|
swipeHintText?: string;
|
|
11
|
+
showMask?: boolean;
|
|
12
|
+
maskOpacity?: number;
|
|
13
|
+
maskBlur?: number;
|
|
11
14
|
}
|
|
12
|
-
declare function BagAnimation({ isAnimating, setIsAnimating, doneFunction, frames, defaultImage, defaultImageAlt, swipeHintText }: BagAnimationProps): react_jsx_runtime.JSX.Element;
|
|
15
|
+
declare function BagAnimation({ isAnimating, setIsAnimating, doneFunction, frames, defaultImage, defaultImageAlt, swipeHintText, showMask, maskOpacity, maskBlur }: BagAnimationProps): react_jsx_runtime.JSX.Element;
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* 获取打包后的资源路径
|
package/dist/index.d.ts
CHANGED
|
@@ -8,8 +8,11 @@ interface BagAnimationProps {
|
|
|
8
8
|
defaultImage?: string;
|
|
9
9
|
defaultImageAlt?: string;
|
|
10
10
|
swipeHintText?: string;
|
|
11
|
+
showMask?: boolean;
|
|
12
|
+
maskOpacity?: number;
|
|
13
|
+
maskBlur?: number;
|
|
11
14
|
}
|
|
12
|
-
declare function BagAnimation({ isAnimating, setIsAnimating, doneFunction, frames, defaultImage, defaultImageAlt, swipeHintText }: BagAnimationProps): react_jsx_runtime.JSX.Element;
|
|
15
|
+
declare function BagAnimation({ isAnimating, setIsAnimating, doneFunction, frames, defaultImage, defaultImageAlt, swipeHintText, showMask, maskOpacity, maskBlur }: BagAnimationProps): react_jsx_runtime.JSX.Element;
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* 获取打包后的资源路径
|
package/dist/index.js
CHANGED
|
@@ -808,7 +808,10 @@ function BagAnimation({
|
|
|
808
808
|
frames = defaultAnimationFrames,
|
|
809
809
|
defaultImage = defaultImagePath,
|
|
810
810
|
defaultImageAlt = "Weedza Mystery Box",
|
|
811
|
-
swipeHintText = "Swipe to open"
|
|
811
|
+
swipeHintText = "Swipe to open",
|
|
812
|
+
showMask = true,
|
|
813
|
+
maskOpacity = 0.7,
|
|
814
|
+
maskBlur = 8
|
|
812
815
|
}) {
|
|
813
816
|
const [frame, setFrame] = (0, import_react.useState)(0);
|
|
814
817
|
const [isPausedAtThird, setIsPausedAtThird] = (0, import_react.useState)(false);
|
|
@@ -1028,79 +1031,112 @@ function BagAnimation({
|
|
|
1028
1031
|
}
|
|
1029
1032
|
};
|
|
1030
1033
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1031
|
-
isAnimating && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1032
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1033
|
-
"
|
|
1034
|
+
isAnimating && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1035
|
+
showMask && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1036
|
+
"div",
|
|
1034
1037
|
{
|
|
1035
|
-
|
|
1036
|
-
onMouseDown,
|
|
1037
|
-
onMouseMove,
|
|
1038
|
-
onMouseUp,
|
|
1039
|
-
onMouseLeave: onMouseUp,
|
|
1040
|
-
onTouchStart: (e) => {
|
|
1041
|
-
if (isPausedAtThird && canvasRef.current) {
|
|
1042
|
-
const touch = e.touches[0];
|
|
1043
|
-
const rect = canvasRef.current.getBoundingClientRect();
|
|
1044
|
-
const touchGap = touch.clientX - rect.left;
|
|
1045
|
-
const initialProgress = Math.max(0, Math.min(100, touchGap / rect.width * 100));
|
|
1046
|
-
setThirdFrameProgress(initialProgress);
|
|
1047
|
-
setShowSwipeHint(false);
|
|
1048
|
-
}
|
|
1049
|
-
},
|
|
1050
|
-
onTouchMove: (e) => {
|
|
1051
|
-
if (!isPausedAtThird || !canvasRef.current || hasTriggeredFourthFrame.current) return;
|
|
1052
|
-
const touch = e.touches[0];
|
|
1053
|
-
const rect = canvasRef.current.getBoundingClientRect();
|
|
1054
|
-
const relativeX = touch.clientX - rect.left;
|
|
1055
|
-
const canvasWidth = rect.width;
|
|
1056
|
-
const progress = Math.max(0, Math.min(100, relativeX / canvasWidth * 100));
|
|
1057
|
-
setThirdFrameProgress(progress);
|
|
1058
|
-
if (progress >= 95 && !hasTriggeredFourthFrame.current) {
|
|
1059
|
-
hasTriggeredFourthFrame.current = true;
|
|
1060
|
-
setIsPausedAtThird(false);
|
|
1061
|
-
setThirdFrameProgress(0);
|
|
1062
|
-
setFrame(3);
|
|
1063
|
-
}
|
|
1064
|
-
},
|
|
1065
|
-
onTouchEnd: (e) => {
|
|
1066
|
-
if (isPausedAtThird) {
|
|
1067
|
-
e.preventDefault();
|
|
1068
|
-
setThirdFrameProgress(0);
|
|
1069
|
-
setShowSwipeHint(true);
|
|
1070
|
-
}
|
|
1071
|
-
},
|
|
1072
|
-
className: "select-none cursor-pointer w-full h-full object-contain",
|
|
1038
|
+
className: "fixed inset-0 z-[9998]",
|
|
1073
1039
|
style: {
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
//
|
|
1078
|
-
|
|
1079
|
-
|
|
1040
|
+
backgroundColor: `rgba(0, 0, 0, ${maskOpacity})`,
|
|
1041
|
+
backdropFilter: `blur(${maskBlur}px)`,
|
|
1042
|
+
WebkitBackdropFilter: `blur(${maskBlur}px)`
|
|
1043
|
+
// Safari 支持
|
|
1044
|
+
},
|
|
1045
|
+
onClick: (e) => {
|
|
1046
|
+
e.stopPropagation();
|
|
1080
1047
|
}
|
|
1081
1048
|
}
|
|
1082
1049
|
),
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
"
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1050
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1051
|
+
"div",
|
|
1052
|
+
{
|
|
1053
|
+
className: "fixed inset-0 z-[9999] flex items-center justify-center pointer-events-none",
|
|
1054
|
+
style: { pointerEvents: "none" },
|
|
1055
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1056
|
+
"div",
|
|
1057
|
+
{
|
|
1058
|
+
className: "relative w-full max-w-[90vw] max-h-[90vh] flex items-center justify-center pointer-events-auto",
|
|
1059
|
+
style: { pointerEvents: "auto" },
|
|
1060
|
+
children: [
|
|
1061
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1062
|
+
"canvas",
|
|
1063
|
+
{
|
|
1064
|
+
ref: canvasRef,
|
|
1065
|
+
onMouseDown,
|
|
1066
|
+
onMouseMove,
|
|
1067
|
+
onMouseUp,
|
|
1068
|
+
onMouseLeave: onMouseUp,
|
|
1069
|
+
onTouchStart: (e) => {
|
|
1070
|
+
if (isPausedAtThird && canvasRef.current) {
|
|
1071
|
+
const touch = e.touches[0];
|
|
1072
|
+
const rect = canvasRef.current.getBoundingClientRect();
|
|
1073
|
+
const touchGap = touch.clientX - rect.left;
|
|
1074
|
+
const initialProgress = Math.max(0, Math.min(100, touchGap / rect.width * 100));
|
|
1075
|
+
setThirdFrameProgress(initialProgress);
|
|
1076
|
+
setShowSwipeHint(false);
|
|
1077
|
+
}
|
|
1078
|
+
},
|
|
1079
|
+
onTouchMove: (e) => {
|
|
1080
|
+
if (!isPausedAtThird || !canvasRef.current || hasTriggeredFourthFrame.current) return;
|
|
1081
|
+
const touch = e.touches[0];
|
|
1082
|
+
const rect = canvasRef.current.getBoundingClientRect();
|
|
1083
|
+
const relativeX = touch.clientX - rect.left;
|
|
1084
|
+
const canvasWidth = rect.width;
|
|
1085
|
+
const progress = Math.max(0, Math.min(100, relativeX / canvasWidth * 100));
|
|
1086
|
+
setThirdFrameProgress(progress);
|
|
1087
|
+
if (progress >= 95 && !hasTriggeredFourthFrame.current) {
|
|
1088
|
+
hasTriggeredFourthFrame.current = true;
|
|
1089
|
+
setIsPausedAtThird(false);
|
|
1090
|
+
setThirdFrameProgress(0);
|
|
1091
|
+
setFrame(3);
|
|
1092
|
+
}
|
|
1093
|
+
},
|
|
1094
|
+
onTouchEnd: (e) => {
|
|
1095
|
+
if (isPausedAtThird) {
|
|
1096
|
+
e.preventDefault();
|
|
1097
|
+
setThirdFrameProgress(0);
|
|
1098
|
+
setShowSwipeHint(true);
|
|
1099
|
+
}
|
|
1100
|
+
},
|
|
1101
|
+
className: "select-none cursor-pointer w-full h-full object-contain",
|
|
1102
|
+
style: {
|
|
1103
|
+
imageRendering: "pixelated",
|
|
1104
|
+
cursor: isPausedAtThird ? "grab" : "pointer",
|
|
1105
|
+
touchAction: "none",
|
|
1106
|
+
// 防止默認觸摸行為
|
|
1107
|
+
userSelect: "none",
|
|
1108
|
+
// 防止選中
|
|
1109
|
+
maxWidth: "100%",
|
|
1110
|
+
maxHeight: "100%"
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
),
|
|
1114
|
+
isPausedAtThird && showSwipeHint && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "absolute bottom-8 left-1/2 transform -translate-x-1/2 bg-black/70 text-white px-6 py-3 rounded-full text-sm md:text-base font-medium animate-pulse pointer-events-none z-20", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
1115
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1116
|
+
"svg",
|
|
1117
|
+
{
|
|
1118
|
+
className: "w-5 h-5 md:w-6 md:h-6",
|
|
1119
|
+
fill: "none",
|
|
1120
|
+
stroke: "currentColor",
|
|
1121
|
+
viewBox: "0 0 24 24",
|
|
1122
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1123
|
+
"path",
|
|
1124
|
+
{
|
|
1125
|
+
strokeLinecap: "round",
|
|
1126
|
+
strokeLinejoin: "round",
|
|
1127
|
+
strokeWidth: 2,
|
|
1128
|
+
d: "M13 7l5 5m0 0l-5 5m5-5H6"
|
|
1129
|
+
}
|
|
1130
|
+
)
|
|
1131
|
+
}
|
|
1132
|
+
),
|
|
1133
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: swipeHintText })
|
|
1134
|
+
] }) })
|
|
1135
|
+
]
|
|
1136
|
+
}
|
|
1137
|
+
)
|
|
1138
|
+
}
|
|
1139
|
+
)
|
|
1104
1140
|
] }),
|
|
1105
1141
|
!isAnimating && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1106
1142
|
"img",
|
package/dist/index.mjs
CHANGED
|
@@ -792,7 +792,10 @@ function BagAnimation({
|
|
|
792
792
|
frames = defaultAnimationFrames,
|
|
793
793
|
defaultImage = defaultImagePath,
|
|
794
794
|
defaultImageAlt = "Weedza Mystery Box",
|
|
795
|
-
swipeHintText = "Swipe to open"
|
|
795
|
+
swipeHintText = "Swipe to open",
|
|
796
|
+
showMask = true,
|
|
797
|
+
maskOpacity = 0.7,
|
|
798
|
+
maskBlur = 8
|
|
796
799
|
}) {
|
|
797
800
|
const [frame, setFrame] = useState(0);
|
|
798
801
|
const [isPausedAtThird, setIsPausedAtThird] = useState(false);
|
|
@@ -1012,79 +1015,112 @@ function BagAnimation({
|
|
|
1012
1015
|
}
|
|
1013
1016
|
};
|
|
1014
1017
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1015
|
-
isAnimating && /* @__PURE__ */ jsxs(
|
|
1016
|
-
/* @__PURE__ */ jsx(
|
|
1017
|
-
"
|
|
1018
|
+
isAnimating && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1019
|
+
showMask && /* @__PURE__ */ jsx(
|
|
1020
|
+
"div",
|
|
1018
1021
|
{
|
|
1019
|
-
|
|
1020
|
-
onMouseDown,
|
|
1021
|
-
onMouseMove,
|
|
1022
|
-
onMouseUp,
|
|
1023
|
-
onMouseLeave: onMouseUp,
|
|
1024
|
-
onTouchStart: (e) => {
|
|
1025
|
-
if (isPausedAtThird && canvasRef.current) {
|
|
1026
|
-
const touch = e.touches[0];
|
|
1027
|
-
const rect = canvasRef.current.getBoundingClientRect();
|
|
1028
|
-
const touchGap = touch.clientX - rect.left;
|
|
1029
|
-
const initialProgress = Math.max(0, Math.min(100, touchGap / rect.width * 100));
|
|
1030
|
-
setThirdFrameProgress(initialProgress);
|
|
1031
|
-
setShowSwipeHint(false);
|
|
1032
|
-
}
|
|
1033
|
-
},
|
|
1034
|
-
onTouchMove: (e) => {
|
|
1035
|
-
if (!isPausedAtThird || !canvasRef.current || hasTriggeredFourthFrame.current) return;
|
|
1036
|
-
const touch = e.touches[0];
|
|
1037
|
-
const rect = canvasRef.current.getBoundingClientRect();
|
|
1038
|
-
const relativeX = touch.clientX - rect.left;
|
|
1039
|
-
const canvasWidth = rect.width;
|
|
1040
|
-
const progress = Math.max(0, Math.min(100, relativeX / canvasWidth * 100));
|
|
1041
|
-
setThirdFrameProgress(progress);
|
|
1042
|
-
if (progress >= 95 && !hasTriggeredFourthFrame.current) {
|
|
1043
|
-
hasTriggeredFourthFrame.current = true;
|
|
1044
|
-
setIsPausedAtThird(false);
|
|
1045
|
-
setThirdFrameProgress(0);
|
|
1046
|
-
setFrame(3);
|
|
1047
|
-
}
|
|
1048
|
-
},
|
|
1049
|
-
onTouchEnd: (e) => {
|
|
1050
|
-
if (isPausedAtThird) {
|
|
1051
|
-
e.preventDefault();
|
|
1052
|
-
setThirdFrameProgress(0);
|
|
1053
|
-
setShowSwipeHint(true);
|
|
1054
|
-
}
|
|
1055
|
-
},
|
|
1056
|
-
className: "select-none cursor-pointer w-full h-full object-contain",
|
|
1022
|
+
className: "fixed inset-0 z-[9998]",
|
|
1057
1023
|
style: {
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
//
|
|
1062
|
-
|
|
1063
|
-
|
|
1024
|
+
backgroundColor: `rgba(0, 0, 0, ${maskOpacity})`,
|
|
1025
|
+
backdropFilter: `blur(${maskBlur}px)`,
|
|
1026
|
+
WebkitBackdropFilter: `blur(${maskBlur}px)`
|
|
1027
|
+
// Safari 支持
|
|
1028
|
+
},
|
|
1029
|
+
onClick: (e) => {
|
|
1030
|
+
e.stopPropagation();
|
|
1064
1031
|
}
|
|
1065
1032
|
}
|
|
1066
1033
|
),
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
"
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1034
|
+
/* @__PURE__ */ jsx(
|
|
1035
|
+
"div",
|
|
1036
|
+
{
|
|
1037
|
+
className: "fixed inset-0 z-[9999] flex items-center justify-center pointer-events-none",
|
|
1038
|
+
style: { pointerEvents: "none" },
|
|
1039
|
+
children: /* @__PURE__ */ jsxs(
|
|
1040
|
+
"div",
|
|
1041
|
+
{
|
|
1042
|
+
className: "relative w-full max-w-[90vw] max-h-[90vh] flex items-center justify-center pointer-events-auto",
|
|
1043
|
+
style: { pointerEvents: "auto" },
|
|
1044
|
+
children: [
|
|
1045
|
+
/* @__PURE__ */ jsx(
|
|
1046
|
+
"canvas",
|
|
1047
|
+
{
|
|
1048
|
+
ref: canvasRef,
|
|
1049
|
+
onMouseDown,
|
|
1050
|
+
onMouseMove,
|
|
1051
|
+
onMouseUp,
|
|
1052
|
+
onMouseLeave: onMouseUp,
|
|
1053
|
+
onTouchStart: (e) => {
|
|
1054
|
+
if (isPausedAtThird && canvasRef.current) {
|
|
1055
|
+
const touch = e.touches[0];
|
|
1056
|
+
const rect = canvasRef.current.getBoundingClientRect();
|
|
1057
|
+
const touchGap = touch.clientX - rect.left;
|
|
1058
|
+
const initialProgress = Math.max(0, Math.min(100, touchGap / rect.width * 100));
|
|
1059
|
+
setThirdFrameProgress(initialProgress);
|
|
1060
|
+
setShowSwipeHint(false);
|
|
1061
|
+
}
|
|
1062
|
+
},
|
|
1063
|
+
onTouchMove: (e) => {
|
|
1064
|
+
if (!isPausedAtThird || !canvasRef.current || hasTriggeredFourthFrame.current) return;
|
|
1065
|
+
const touch = e.touches[0];
|
|
1066
|
+
const rect = canvasRef.current.getBoundingClientRect();
|
|
1067
|
+
const relativeX = touch.clientX - rect.left;
|
|
1068
|
+
const canvasWidth = rect.width;
|
|
1069
|
+
const progress = Math.max(0, Math.min(100, relativeX / canvasWidth * 100));
|
|
1070
|
+
setThirdFrameProgress(progress);
|
|
1071
|
+
if (progress >= 95 && !hasTriggeredFourthFrame.current) {
|
|
1072
|
+
hasTriggeredFourthFrame.current = true;
|
|
1073
|
+
setIsPausedAtThird(false);
|
|
1074
|
+
setThirdFrameProgress(0);
|
|
1075
|
+
setFrame(3);
|
|
1076
|
+
}
|
|
1077
|
+
},
|
|
1078
|
+
onTouchEnd: (e) => {
|
|
1079
|
+
if (isPausedAtThird) {
|
|
1080
|
+
e.preventDefault();
|
|
1081
|
+
setThirdFrameProgress(0);
|
|
1082
|
+
setShowSwipeHint(true);
|
|
1083
|
+
}
|
|
1084
|
+
},
|
|
1085
|
+
className: "select-none cursor-pointer w-full h-full object-contain",
|
|
1086
|
+
style: {
|
|
1087
|
+
imageRendering: "pixelated",
|
|
1088
|
+
cursor: isPausedAtThird ? "grab" : "pointer",
|
|
1089
|
+
touchAction: "none",
|
|
1090
|
+
// 防止默認觸摸行為
|
|
1091
|
+
userSelect: "none",
|
|
1092
|
+
// 防止選中
|
|
1093
|
+
maxWidth: "100%",
|
|
1094
|
+
maxHeight: "100%"
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
),
|
|
1098
|
+
isPausedAtThird && showSwipeHint && /* @__PURE__ */ jsx("div", { className: "absolute bottom-8 left-1/2 transform -translate-x-1/2 bg-black/70 text-white px-6 py-3 rounded-full text-sm md:text-base font-medium animate-pulse pointer-events-none z-20", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1099
|
+
/* @__PURE__ */ jsx(
|
|
1100
|
+
"svg",
|
|
1101
|
+
{
|
|
1102
|
+
className: "w-5 h-5 md:w-6 md:h-6",
|
|
1103
|
+
fill: "none",
|
|
1104
|
+
stroke: "currentColor",
|
|
1105
|
+
viewBox: "0 0 24 24",
|
|
1106
|
+
children: /* @__PURE__ */ jsx(
|
|
1107
|
+
"path",
|
|
1108
|
+
{
|
|
1109
|
+
strokeLinecap: "round",
|
|
1110
|
+
strokeLinejoin: "round",
|
|
1111
|
+
strokeWidth: 2,
|
|
1112
|
+
d: "M13 7l5 5m0 0l-5 5m5-5H6"
|
|
1113
|
+
}
|
|
1114
|
+
)
|
|
1115
|
+
}
|
|
1116
|
+
),
|
|
1117
|
+
/* @__PURE__ */ jsx("span", { children: swipeHintText })
|
|
1118
|
+
] }) })
|
|
1119
|
+
]
|
|
1120
|
+
}
|
|
1121
|
+
)
|
|
1122
|
+
}
|
|
1123
|
+
)
|
|
1088
1124
|
] }),
|
|
1089
1125
|
!isAnimating && /* @__PURE__ */ jsx(
|
|
1090
1126
|
"img",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chao-component/bag-animation-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,10 +9,15 @@
|
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"import": "./dist/index.mjs",
|
|
11
11
|
"require": "./dist/index.js"
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
"./vite-plugin": "./vite-plugin.js",
|
|
14
|
+
"./webpack-plugin": "./webpack-plugin.js"
|
|
13
15
|
},
|
|
14
16
|
"files": [
|
|
15
|
-
"dist"
|
|
17
|
+
"dist",
|
|
18
|
+
"vite-plugin.js",
|
|
19
|
+
"webpack-plugin.js",
|
|
20
|
+
"scripts"
|
|
16
21
|
],
|
|
17
22
|
"directories": {
|
|
18
23
|
"assets": "dist/assets"
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 安装脚本:自动复制资源文件到项目的 public 目录
|
|
5
|
+
*
|
|
6
|
+
* 使用方法:
|
|
7
|
+
* 1. 在 package.json 中添加 postinstall 脚本:
|
|
8
|
+
* "scripts": {
|
|
9
|
+
* "postinstall": "node node_modules/@chao-component/bag-animation-ui/scripts/copy-assets.js"
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* 2. 或者手动运行:
|
|
13
|
+
* node node_modules/@chao-component/bag-animation-ui/scripts/copy-assets.js
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const { copyFileSync, mkdirSync, readdirSync, existsSync } = require('fs');
|
|
17
|
+
const { join, resolve } = require('path');
|
|
18
|
+
|
|
19
|
+
function copyDir(src, dest) {
|
|
20
|
+
if (!existsSync(src)) {
|
|
21
|
+
console.warn(`⚠️ Source directory not found: ${src}`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!existsSync(dest)) {
|
|
26
|
+
mkdirSync(dest, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const entries = readdirSync(src, { withFileTypes: true });
|
|
30
|
+
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
const srcPath = join(src, entry.name);
|
|
33
|
+
const destPath = join(dest, entry.name);
|
|
34
|
+
|
|
35
|
+
if (entry.isDirectory()) {
|
|
36
|
+
copyDir(srcPath, destPath);
|
|
37
|
+
} else {
|
|
38
|
+
copyFileSync(srcPath, destPath);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function main() {
|
|
44
|
+
const packageName = '@chao-component/bag-animation-ui';
|
|
45
|
+
const publicDir = process.argv[2] || 'public';
|
|
46
|
+
|
|
47
|
+
// 查找包的位置
|
|
48
|
+
const packagePath = resolve(__dirname, '..', 'dist', 'assets');
|
|
49
|
+
const targetPath = resolve(process.cwd(), publicDir, 'assets');
|
|
50
|
+
|
|
51
|
+
console.log(`📦 Copying assets from ${packageName}...`);
|
|
52
|
+
console.log(` Source: ${packagePath}`);
|
|
53
|
+
console.log(` Target: ${targetPath}`);
|
|
54
|
+
|
|
55
|
+
if (existsSync(packagePath)) {
|
|
56
|
+
copyDir(packagePath, targetPath);
|
|
57
|
+
console.log(`✅ Assets copied successfully to ${publicDir}/assets`);
|
|
58
|
+
} else {
|
|
59
|
+
console.error(`❌ Error: Package assets not found at ${packagePath}`);
|
|
60
|
+
console.error(` Make sure ${packageName} is installed correctly.`);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main();
|
|
66
|
+
|
package/vite-plugin.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite 插件:自动复制 @chao-component/bag-animation-ui 的资源文件到 public 目录
|
|
3
|
+
*
|
|
4
|
+
* 使用方法:
|
|
5
|
+
* 在 vite.config.js/ts 中:
|
|
6
|
+
*
|
|
7
|
+
* import { bagAnimationAssets } from '@chao-component/bag-animation-ui/vite-plugin';
|
|
8
|
+
*
|
|
9
|
+
* export default {
|
|
10
|
+
* plugins: [
|
|
11
|
+
* bagAnimationAssets(),
|
|
12
|
+
* // ... 其他插件
|
|
13
|
+
* ]
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { copyFileSync, mkdirSync, readdirSync, existsSync, statSync } from 'fs';
|
|
18
|
+
import { join, dirname, resolve } from 'path';
|
|
19
|
+
import { fileURLToPath } from 'url';
|
|
20
|
+
|
|
21
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
22
|
+
const __dirname = dirname(__filename);
|
|
23
|
+
|
|
24
|
+
function copyDir(src, dest) {
|
|
25
|
+
if (!existsSync(src)) return;
|
|
26
|
+
|
|
27
|
+
if (!existsSync(dest)) {
|
|
28
|
+
mkdirSync(dest, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const entries = readdirSync(src, { withFileTypes: true });
|
|
32
|
+
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
const srcPath = join(src, entry.name);
|
|
35
|
+
const destPath = join(dest, entry.name);
|
|
36
|
+
|
|
37
|
+
if (entry.isDirectory()) {
|
|
38
|
+
copyDir(srcPath, destPath);
|
|
39
|
+
} else {
|
|
40
|
+
copyFileSync(srcPath, destPath);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function bagAnimationAssets(options = {}) {
|
|
46
|
+
const {
|
|
47
|
+
publicDir = 'public',
|
|
48
|
+
packageName = '@chao-component/bag-animation-ui'
|
|
49
|
+
} = options;
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
name: 'bag-animation-assets',
|
|
53
|
+
apply: 'serve', // 只在开发服务器时应用
|
|
54
|
+
buildStart() {
|
|
55
|
+
try {
|
|
56
|
+
// 查找 node_modules 中的包
|
|
57
|
+
const packagePath = resolve(process.cwd(), 'node_modules', packageName, 'dist', 'assets');
|
|
58
|
+
const targetPath = resolve(process.cwd(), publicDir, 'assets');
|
|
59
|
+
|
|
60
|
+
if (existsSync(packagePath)) {
|
|
61
|
+
copyDir(packagePath, targetPath);
|
|
62
|
+
console.log(`✅ [bag-animation-assets] Assets copied to ${publicDir}/assets`);
|
|
63
|
+
} else {
|
|
64
|
+
console.warn(`⚠️ [bag-animation-assets] Package assets not found at ${packagePath}`);
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(`❌ [bag-animation-assets] Error copying assets:`, error);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
buildEnd() {
|
|
71
|
+
// 构建时也复制资源
|
|
72
|
+
try {
|
|
73
|
+
const packagePath = resolve(process.cwd(), 'node_modules', packageName, 'dist', 'assets');
|
|
74
|
+
const targetPath = resolve(process.cwd(), publicDir, 'assets');
|
|
75
|
+
|
|
76
|
+
if (existsSync(packagePath)) {
|
|
77
|
+
copyDir(packagePath, targetPath);
|
|
78
|
+
console.log(`✅ [bag-animation-assets] Assets copied to ${publicDir}/assets`);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error(`❌ [bag-animation-assets] Error copying assets:`, error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webpack 插件:自动复制 @chao-component/bag-animation-ui 的资源文件到 public 目录
|
|
3
|
+
*
|
|
4
|
+
* 使用方法:
|
|
5
|
+
* 在 webpack.config.js 中:
|
|
6
|
+
*
|
|
7
|
+
* const { BagAnimationAssetsPlugin } = require('@chao-component/bag-animation-ui/webpack-plugin');
|
|
8
|
+
*
|
|
9
|
+
* module.exports = {
|
|
10
|
+
* plugins: [
|
|
11
|
+
* new BagAnimationAssetsPlugin(),
|
|
12
|
+
* // ... 其他插件
|
|
13
|
+
* ]
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { copyFileSync, mkdirSync, readdirSync, existsSync } = require('fs');
|
|
18
|
+
const { join, resolve } = require('path');
|
|
19
|
+
|
|
20
|
+
function copyDir(src, dest) {
|
|
21
|
+
if (!existsSync(src)) return;
|
|
22
|
+
|
|
23
|
+
if (!existsSync(dest)) {
|
|
24
|
+
mkdirSync(dest, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const entries = readdirSync(src, { withFileTypes: true });
|
|
28
|
+
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
const srcPath = join(src, entry.name);
|
|
31
|
+
const destPath = join(dest, entry.name);
|
|
32
|
+
|
|
33
|
+
if (entry.isDirectory()) {
|
|
34
|
+
copyDir(srcPath, destPath);
|
|
35
|
+
} else {
|
|
36
|
+
copyFileSync(srcPath, destPath);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class BagAnimationAssetsPlugin {
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
this.options = {
|
|
44
|
+
publicDir: options.publicDir || 'public',
|
|
45
|
+
packageName: options.packageName || '@chao-component/bag-animation-ui'
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
apply(compiler) {
|
|
50
|
+
compiler.hooks.beforeRun.tapAsync('BagAnimationAssetsPlugin', (compilation, callback) => {
|
|
51
|
+
try {
|
|
52
|
+
const packagePath = resolve(process.cwd(), 'node_modules', this.options.packageName, 'dist', 'assets');
|
|
53
|
+
const targetPath = resolve(process.cwd(), this.options.publicDir, 'assets');
|
|
54
|
+
|
|
55
|
+
if (existsSync(packagePath)) {
|
|
56
|
+
copyDir(packagePath, targetPath);
|
|
57
|
+
console.log(`✅ [bag-animation-assets] Assets copied to ${this.options.publicDir}/assets`);
|
|
58
|
+
} else {
|
|
59
|
+
console.warn(`⚠️ [bag-animation-assets] Package assets not found at ${packagePath}`);
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(`❌ [bag-animation-assets] Error copying assets:`, error);
|
|
63
|
+
}
|
|
64
|
+
callback();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = { BagAnimationAssetsPlugin };
|
|
70
|
+
|