@cos-design/photo-postcard 3.7.3 → 4.0.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/core/index.d.ts +1 -0
- package/dist/core/index.js +178 -0
- package/dist/core/packages/photoPostcard/src/core.d.ts +1 -0
- package/dist/core/packages/photoPostcard/src/element.d.ts +1 -0
- package/dist/core/packages/photoPostcard/src/react.d.ts +3 -0
- package/dist/core/packages/photoPostcard/src/vue.d.ts +2 -0
- package/dist/core/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/core/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/core/packages/shared/src/index.d.ts +11 -0
- package/dist/core/packages/shared/src/math.d.ts +2 -0
- package/dist/core/packages/shared/src/photo.d.ts +15 -0
- package/dist/core/packages/shared/src/pointer.d.ts +14 -0
- package/dist/core/packages/shared/src/react/index.d.ts +30 -0
- package/dist/core/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/core/packages/shared/src/size.d.ts +8 -0
- package/dist/core/packages/shared/src/visibility.d.ts +2 -0
- package/dist/core/src/components/photoPostcard/core/engine.d.ts +6 -0
- package/dist/core/src/components/photoPostcard/core/index.d.ts +2 -0
- package/dist/core/src/components/photoPostcard/core/types.d.ts +7 -0
- package/dist/core/src/components/photoPostcard/element/index.d.ts +13 -0
- package/dist/core/src/components/photoPostcard/index.d.ts +3 -0
- package/dist/{src/components/photoPostcard → core/src/components/photoPostcard/react}/index.d.ts +4 -2
- package/dist/{src → core/src}/components/photoPostcard/types.d.ts +2 -2
- package/dist/{src → core/src}/vite-env.d.ts +6 -0
- package/dist/element/element.css +1 -0
- package/dist/element/index.d.ts +1 -0
- package/dist/element/index.js +254 -0
- package/dist/element/packages/photoPostcard/src/core.d.ts +1 -0
- package/dist/element/packages/photoPostcard/src/element.d.ts +1 -0
- package/dist/element/packages/photoPostcard/src/index.d.ts +3 -0
- package/dist/element/packages/photoPostcard/src/react.d.ts +3 -0
- package/dist/element/packages/photoPostcard/src/vue.d.ts +2 -0
- package/dist/element/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/element/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/element/packages/shared/src/index.d.ts +11 -0
- package/dist/element/packages/shared/src/math.d.ts +2 -0
- package/dist/element/packages/shared/src/photo.d.ts +15 -0
- package/dist/element/packages/shared/src/pointer.d.ts +14 -0
- package/dist/element/packages/shared/src/react/index.d.ts +30 -0
- package/dist/element/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/element/packages/shared/src/size.d.ts +8 -0
- package/dist/element/packages/shared/src/visibility.d.ts +2 -0
- package/dist/element/src/components/photoPostcard/core/engine.d.ts +6 -0
- package/dist/element/src/components/photoPostcard/core/index.d.ts +2 -0
- package/dist/element/src/components/photoPostcard/core/types.d.ts +7 -0
- package/dist/element/src/components/photoPostcard/element/index.d.ts +13 -0
- package/dist/element/src/components/photoPostcard/index.d.ts +3 -0
- package/dist/element/src/components/photoPostcard/react/index.d.ts +10 -0
- package/dist/element/src/components/photoPostcard/types.d.ts +45 -0
- package/dist/element/src/vite-env.d.ts +45 -0
- package/dist/react/index.cjs +1 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/{index.js → react/index.js} +35 -62
- package/dist/react/packages/photoPostcard/src/core.d.ts +1 -0
- package/dist/react/packages/photoPostcard/src/element.d.ts +1 -0
- package/dist/react/packages/photoPostcard/src/index.d.ts +3 -0
- package/dist/react/packages/photoPostcard/src/react.d.ts +3 -0
- package/dist/react/packages/photoPostcard/src/vue.d.ts +2 -0
- package/dist/react/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/react/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/react/packages/shared/src/index.d.ts +11 -0
- package/dist/react/packages/shared/src/math.d.ts +2 -0
- package/dist/react/packages/shared/src/photo.d.ts +15 -0
- package/dist/react/packages/shared/src/pointer.d.ts +14 -0
- package/dist/react/packages/shared/src/react/index.d.ts +30 -0
- package/dist/react/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/react/packages/shared/src/size.d.ts +8 -0
- package/dist/react/packages/shared/src/visibility.d.ts +2 -0
- package/dist/react/react.css +1 -0
- package/dist/react/src/components/photoPostcard/core/engine.d.ts +6 -0
- package/dist/react/src/components/photoPostcard/core/index.d.ts +2 -0
- package/dist/react/src/components/photoPostcard/core/types.d.ts +7 -0
- package/dist/react/src/components/photoPostcard/element/index.d.ts +13 -0
- package/dist/react/src/components/photoPostcard/index.d.ts +3 -0
- package/dist/react/src/components/photoPostcard/react/index.d.ts +10 -0
- package/dist/react/src/components/photoPostcard/types.d.ts +45 -0
- package/dist/react/src/vite-env.d.ts +45 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +226 -0
- package/dist/vue/packages/photoPostcard/src/core.d.ts +1 -0
- package/dist/vue/packages/photoPostcard/src/element.d.ts +1 -0
- package/dist/vue/packages/photoPostcard/src/index.d.ts +3 -0
- package/dist/vue/packages/photoPostcard/src/react.d.ts +3 -0
- package/dist/vue/packages/photoPostcard/src/vue.d.ts +2 -0
- package/dist/vue/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/vue/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/vue/packages/shared/src/index.d.ts +11 -0
- package/dist/vue/packages/shared/src/math.d.ts +2 -0
- package/dist/vue/packages/shared/src/photo.d.ts +15 -0
- package/dist/vue/packages/shared/src/pointer.d.ts +14 -0
- package/dist/vue/packages/shared/src/react/index.d.ts +30 -0
- package/dist/vue/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/vue/packages/shared/src/size.d.ts +8 -0
- package/dist/vue/packages/shared/src/visibility.d.ts +2 -0
- package/dist/vue/src/components/photoPostcard/core/engine.d.ts +6 -0
- package/dist/vue/src/components/photoPostcard/core/index.d.ts +2 -0
- package/dist/vue/src/components/photoPostcard/core/types.d.ts +7 -0
- package/dist/vue/src/components/photoPostcard/element/index.d.ts +13 -0
- package/dist/vue/src/components/photoPostcard/index.d.ts +3 -0
- package/dist/vue/src/components/photoPostcard/react/index.d.ts +10 -0
- package/dist/vue/src/components/photoPostcard/types.d.ts +45 -0
- package/dist/vue/src/vite-env.d.ts +45 -0
- package/dist/vue/vue.css +1 -0
- package/package.json +45 -10
- package/dist/index.cjs +0 -1
- package/dist/index.css +0 -1
- package/dist/index.d.ts +0 -3
- /package/dist/{packages → core/packages}/photoPostcard/src/index.d.ts +0 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { applyBlockHostBox as e } from "@cos-design/shared";
|
|
2
|
+
import './element.css';//#region src/components/photoPostcard/core/engine.ts
|
|
3
|
+
var t = "cos-photo-postcard", n = 6, r = 280, i = 320, a = (e, t) => t <= 0 ? 0 : (e % t + t) % t, o = (e, t) => t <= 0 ? 0 : Math.max(0, Math.min(t - 1, Math.floor(e))), s = (e) => {
|
|
4
|
+
let t = Math.sin(e * 127.1 + 31.7) * 43758.5453;
|
|
5
|
+
return t - Math.floor(t);
|
|
6
|
+
}, c = (e, t) => {
|
|
7
|
+
if (t) for (let [n, r] of Object.entries(t)) r != null && (n.startsWith("--") ? e.style.setProperty(n, String(r)) : e.style[n] = typeof r == "number" ? `${r}px` : String(r));
|
|
8
|
+
}, l = (e, n, r) => {
|
|
9
|
+
let i = r && (n.title || n.description), a = n.title ? n.title : "Greetings from the road";
|
|
10
|
+
e.replaceChildren();
|
|
11
|
+
let o = document.createElement("div");
|
|
12
|
+
o.className = `${t}__face ${t}__front`;
|
|
13
|
+
let s = document.createElement("div");
|
|
14
|
+
s.className = `${t}__photo-frame${i ? ` ${t}__photo-frame-with-caption` : ""}`;
|
|
15
|
+
let c = document.createElement("div");
|
|
16
|
+
c.className = `${t}__photo-wrap`;
|
|
17
|
+
let l = document.createElement("img");
|
|
18
|
+
l.className = `${t}__photo`, l.src = n.src, l.alt = n.alt ?? n.title ?? "", l.draggable = !1, c.appendChild(l), s.appendChild(c);
|
|
19
|
+
let u = document.createElement("div");
|
|
20
|
+
if (u.className = `${t}__corner-stamp`, u.setAttribute("aria-hidden", "true"), o.append(s, u), i) {
|
|
21
|
+
let e = document.createElement("div");
|
|
22
|
+
if (e.className = `${t}__front-caption`, n.title) {
|
|
23
|
+
let r = document.createElement("p");
|
|
24
|
+
r.className = `${t}__front-caption-title`, r.textContent = n.title, e.appendChild(r);
|
|
25
|
+
}
|
|
26
|
+
if (n.description) {
|
|
27
|
+
let r = document.createElement("p");
|
|
28
|
+
r.className = `${t}__front-caption-desc`, r.textContent = n.description, e.appendChild(r);
|
|
29
|
+
}
|
|
30
|
+
o.appendChild(e);
|
|
31
|
+
}
|
|
32
|
+
let d = document.createElement("div");
|
|
33
|
+
d.className = `${t}__face ${t}__back`;
|
|
34
|
+
let f = document.createElement("div");
|
|
35
|
+
f.className = `${t}__divider`, f.setAttribute("aria-hidden", "true");
|
|
36
|
+
let p = document.createElement("div");
|
|
37
|
+
p.className = `${t}__lined-paper`;
|
|
38
|
+
let m = document.createElement("p");
|
|
39
|
+
m.className = `${t}__greeting`, m.textContent = a, p.appendChild(m);
|
|
40
|
+
let h = document.createElement("p");
|
|
41
|
+
n.description ? (h.className = `${t}__body-text`, h.textContent = n.description) : (h.className = `${t}__body-placeholder`, h.textContent = "Wish you were here…"), p.appendChild(h);
|
|
42
|
+
let g = document.createElement("div");
|
|
43
|
+
g.className = `${t}__back-footer`;
|
|
44
|
+
let _ = document.createElement("div");
|
|
45
|
+
_.className = `${t}__postmark`, _.setAttribute("aria-hidden", "true");
|
|
46
|
+
let v = document.createElement("span");
|
|
47
|
+
v.className = `${t}__postmark-text`, v.innerHTML = "TRAVEL<br>POST", _.appendChild(v);
|
|
48
|
+
let y = document.createElement("div");
|
|
49
|
+
y.className = `${t}__stamp-square`, y.setAttribute("aria-hidden", "true"), g.append(_, y), d.append(f, p, g), e.append(o, d);
|
|
50
|
+
};
|
|
51
|
+
function u(u, d = { photos: [] }) {
|
|
52
|
+
let f = {
|
|
53
|
+
width: 360,
|
|
54
|
+
height: 420,
|
|
55
|
+
cardWidth: 260,
|
|
56
|
+
cardHeight: 170,
|
|
57
|
+
pullThreshold: 80,
|
|
58
|
+
showCaption: !0,
|
|
59
|
+
initialIndex: 0,
|
|
60
|
+
initialFlipped: !1,
|
|
61
|
+
ariaLabel: "明信片",
|
|
62
|
+
...d,
|
|
63
|
+
photos: Array.isArray(d.photos) ? d.photos : []
|
|
64
|
+
}, p = !1, m = o(f.initialIndex ?? 0, f.photos.length), h = !!f.initialFlipped, g = 0, _ = "idle", v = null, y = null, b = null, x = "", S = document.createElement("div"), C = document.createElement("div");
|
|
65
|
+
C.className = `${t}__stage`;
|
|
66
|
+
let w = document.createElement("div");
|
|
67
|
+
w.className = `${t}__empty`, w.textContent = "暂无明信片";
|
|
68
|
+
let T = document.createElement("div");
|
|
69
|
+
T.className = `${t}__stack`;
|
|
70
|
+
let E = document.createElement("div");
|
|
71
|
+
E.className = `${t}__card-slot`;
|
|
72
|
+
let D = document.createElement("div"), O = document.createElement("div");
|
|
73
|
+
O.className = `${t}__flip-inner`, D.appendChild(O), E.appendChild(D);
|
|
74
|
+
let k = document.createElement("div");
|
|
75
|
+
k.className = `${t}__hint`, k.textContent = "拖拽切换 · 点击查看背面", C.append(w, T, k), S.appendChild(C), u.appendChild(S);
|
|
76
|
+
let A = () => Array.isArray(f.photos) ? f.photos : [], j = () => A().length, M = (e, t) => e ? `${e.src}\0${e.title ?? ""}\0${e.description ?? ""}\0${e.alt ?? ""}\0${t}` : "", N = () => {
|
|
77
|
+
D.className = [
|
|
78
|
+
`${t}__card-active`,
|
|
79
|
+
h ? `${t}__flipped` : "",
|
|
80
|
+
_ === "exiting" ? `${t}__card-exiting` : ""
|
|
81
|
+
].filter(Boolean).join(" "), D.style.transform = `translateX(${g}px)`, D.style.transition = _ === "snapping" || _ === "exiting" ? `transform ${_ === "exiting" ? r : i}ms cubic-bezier(0.22, 1, 0.36, 1), opacity ${r}ms ease` : "none", D.style.opacity = _ === "exiting" ? "0.55" : "1", D.setAttribute("aria-pressed", String(h));
|
|
82
|
+
let e = A()[m];
|
|
83
|
+
D.setAttribute("aria-label", e ? `${h ? "背面" : "正面"}:${e.alt ?? e.title ?? `明信片 ${m + 1}`}` : "");
|
|
84
|
+
}, P = (e, n, r) => {
|
|
85
|
+
let i = new Set([E]);
|
|
86
|
+
for (let e of [...T.children]) i.has(e) || e.remove();
|
|
87
|
+
let a = e <= 1 ? [] : [1, 2].slice(0, Math.min(2, e - 1)).map((e) => {
|
|
88
|
+
let t = m * 13.7 + e * 5.3;
|
|
89
|
+
return {
|
|
90
|
+
depth: e,
|
|
91
|
+
rot: (s(t) * 2 - 1) * 5.5,
|
|
92
|
+
dx: e * 5 + s(t + 1.1) * 4,
|
|
93
|
+
dy: e * 3 + s(t + 2.4) * 3
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
for (let { depth: e, rot: i, dx: o, dy: s } of a) {
|
|
97
|
+
let a = document.createElement("div");
|
|
98
|
+
a.className = `${t}__stack-card`, a.style.width = `${n}px`, a.style.height = `${r}px`, a.style.transform = `translate(calc(-50% + ${o}px), calc(-50% + ${s}px)) rotate(${i}deg)`, a.style.opacity = e === 1 ? "0.92" : "0.78", a.setAttribute("aria-hidden", "true"), T.insertBefore(a, E);
|
|
99
|
+
}
|
|
100
|
+
}, F = () => {
|
|
101
|
+
let n = A(), r = n.length, i = f.cardWidth ?? 260, a = f.cardHeight ?? 170, o = f.showCaption !== !1;
|
|
102
|
+
if (S.className = [t, f.className].filter(Boolean).join(" "), e(u, S, {
|
|
103
|
+
width: f.width ?? 360,
|
|
104
|
+
height: f.height ?? 420
|
|
105
|
+
}), c(S, f.style), S.setAttribute("role", "region"), S.setAttribute("aria-label", f.ariaLabel ?? "明信片"), S.tabIndex = 0, w.hidden = r > 0, T.hidden = r === 0, k.hidden = r <= 1, r === 0) {
|
|
106
|
+
O.replaceChildren(), x = "";
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
T.style.width = `${i}px`, T.style.height = `${a}px`, (!E.isConnected || E.parentElement !== T) && T.appendChild(E), P(r, i, a), E.style.width = `${i}px`, E.style.height = `${a}px`, D.style.width = `${i}px`, D.style.height = `${a}px`, D.setAttribute("role", "button");
|
|
110
|
+
let s = n[m], d = M(s, o);
|
|
111
|
+
s && d !== x ? (l(O, s, o), x = d) : s || (O.replaceChildren(), x = ""), N();
|
|
112
|
+
}, I = (e) => {
|
|
113
|
+
let t = A(), n = o(e, t.length);
|
|
114
|
+
m = n, h = !1, f.onFlipChange?.(!1);
|
|
115
|
+
let r = t[n];
|
|
116
|
+
r && f.onIndexChange?.(n, r);
|
|
117
|
+
}, L = (e) => {
|
|
118
|
+
I(e), g = 0, _ = "idle", F();
|
|
119
|
+
}, R = (e) => {
|
|
120
|
+
let t = e * ((f.cardWidth ?? 260) * .55 + 48);
|
|
121
|
+
_ = "exiting", g = t, N(), y != null && window.clearTimeout(y), y = window.setTimeout(() => {
|
|
122
|
+
L(a(m + e, A().length));
|
|
123
|
+
}, r);
|
|
124
|
+
}, z = () => {
|
|
125
|
+
_ = "snapping", g = 0, N(), b != null && window.clearTimeout(b), b = window.setTimeout(() => {
|
|
126
|
+
_ = "idle", N();
|
|
127
|
+
}, i);
|
|
128
|
+
}, B = (e) => {
|
|
129
|
+
A().length <= 1 || R(e > 0 ? 1 : -1);
|
|
130
|
+
}, V = () => {
|
|
131
|
+
h = !h, f.onFlipChange?.(h), N();
|
|
132
|
+
}, H = (e) => {
|
|
133
|
+
_ === "exiting" || j() === 0 || (v = {
|
|
134
|
+
pointerId: e.pointerId,
|
|
135
|
+
startX: e.clientX,
|
|
136
|
+
moved: !1
|
|
137
|
+
}, _ = "dragging", D.setPointerCapture(e.pointerId));
|
|
138
|
+
}, U = (e) => {
|
|
139
|
+
if (!v || v.pointerId !== e.pointerId || _ === "exiting") return;
|
|
140
|
+
let t = e.clientX - v.startX;
|
|
141
|
+
Math.abs(t) > n && (v.moved = !0), g = j() <= 1 ? t * .22 : t, N();
|
|
142
|
+
}, W = (e) => {
|
|
143
|
+
if (!v || v.pointerId !== e.pointerId) return;
|
|
144
|
+
let t = v.startX, n = v.moved;
|
|
145
|
+
if (v = null, D.hasPointerCapture(e.pointerId) && D.releasePointerCapture(e.pointerId), _ === "exiting") return;
|
|
146
|
+
let r = e.clientX - t;
|
|
147
|
+
if (!n) {
|
|
148
|
+
_ = "idle", g = 0, V();
|
|
149
|
+
let e = A()[m];
|
|
150
|
+
e && f.onPhotoClick?.(m, e);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (Math.abs(r) >= (f.pullThreshold ?? 80) && j() > 1) {
|
|
154
|
+
R(r > 0 ? 1 : -1);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
z();
|
|
158
|
+
}, G = (e) => {
|
|
159
|
+
!v || v.pointerId !== e.pointerId || (v = null, D.hasPointerCapture(e.pointerId) && D.releasePointerCapture(e.pointerId), _ !== "exiting" && z());
|
|
160
|
+
}, K = (e) => {
|
|
161
|
+
e.key === "ArrowRight" ? (e.preventDefault(), B(1)) : e.key === "ArrowLeft" ? (e.preventDefault(), B(-1)) : (e.key === " " || e.key === "Enter") && (e.preventDefault(), V());
|
|
162
|
+
};
|
|
163
|
+
return D.addEventListener("pointerdown", H), D.addEventListener("pointermove", U), D.addEventListener("pointerup", W), D.addEventListener("pointercancel", G), S.addEventListener("keydown", K), F(), {
|
|
164
|
+
update(e) {
|
|
165
|
+
let t = Array.isArray(e.photos) ? e.photos : e.photos === void 0 ? f.photos : [];
|
|
166
|
+
f = {
|
|
167
|
+
...f,
|
|
168
|
+
...e,
|
|
169
|
+
photos: t
|
|
170
|
+
}, m = o(m, A().length), F();
|
|
171
|
+
},
|
|
172
|
+
destroy() {
|
|
173
|
+
p || (p = !0, y != null && window.clearTimeout(y), b != null && window.clearTimeout(b), D.removeEventListener("pointerdown", H), D.removeEventListener("pointermove", U), D.removeEventListener("pointerup", W), D.removeEventListener("pointercancel", G), S.removeEventListener("keydown", K), S.remove());
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/components/photoPostcard/element/index.ts
|
|
179
|
+
var d = "cos-photo-postcard";
|
|
180
|
+
function f(e) {
|
|
181
|
+
let t = {};
|
|
182
|
+
if (e.hasAttribute("width")) {
|
|
183
|
+
let n = e.getAttribute("width"), r = Number(n);
|
|
184
|
+
t.width = n != null && n !== "" && !Number.isNaN(r) ? r : n ?? void 0;
|
|
185
|
+
}
|
|
186
|
+
if (e.hasAttribute("height")) {
|
|
187
|
+
let n = e.getAttribute("height"), r = Number(n);
|
|
188
|
+
t.height = n != null && n !== "" && !Number.isNaN(r) ? r : n ?? void 0;
|
|
189
|
+
}
|
|
190
|
+
if (e.hasAttribute("aria-label") && (t.ariaLabel = e.getAttribute("aria-label") ?? void 0), e.hasAttribute("card-width") && (t.cardWidth = Number(e.getAttribute("card-width"))), e.hasAttribute("card-height") && (t.cardHeight = Number(e.getAttribute("card-height"))), e.hasAttribute("pull-threshold") && (t.pullThreshold = Number(e.getAttribute("pull-threshold"))), e.hasAttribute("initial-index") && (t.initialIndex = Number(e.getAttribute("initial-index"))), e.hasAttribute("show-caption")) {
|
|
191
|
+
let n = e.getAttribute("show-caption");
|
|
192
|
+
t.showCaption = n !== "false" && n !== "0";
|
|
193
|
+
}
|
|
194
|
+
if (e.hasAttribute("initial-flipped")) {
|
|
195
|
+
let n = e.getAttribute("initial-flipped");
|
|
196
|
+
t.initialFlipped = n !== "false" && n !== "0";
|
|
197
|
+
}
|
|
198
|
+
if (e.hasAttribute("photos")) try {
|
|
199
|
+
t.photos = JSON.parse(e.getAttribute("photos") ?? "null");
|
|
200
|
+
} catch {}
|
|
201
|
+
let n = e._photos;
|
|
202
|
+
return n !== void 0 && (t.photos = n), t.onPhotoClick = (...t) => {
|
|
203
|
+
e.dispatchEvent(new CustomEvent("photo-click", {
|
|
204
|
+
detail: t.length <= 1 ? t[0] : t,
|
|
205
|
+
bubbles: !0
|
|
206
|
+
}));
|
|
207
|
+
}, t.onIndexChange = (...t) => {
|
|
208
|
+
e.dispatchEvent(new CustomEvent("index-change", {
|
|
209
|
+
detail: t.length <= 1 ? t[0] : t,
|
|
210
|
+
bubbles: !0
|
|
211
|
+
}));
|
|
212
|
+
}, t.onFlipChange = (...t) => {
|
|
213
|
+
e.dispatchEvent(new CustomEvent("flip-change", {
|
|
214
|
+
detail: t.length <= 1 ? t[0] : t,
|
|
215
|
+
bubbles: !0
|
|
216
|
+
}));
|
|
217
|
+
}, t;
|
|
218
|
+
}
|
|
219
|
+
var p = class extends HTMLElement {
|
|
220
|
+
ctrl = null;
|
|
221
|
+
_photos;
|
|
222
|
+
get photos() {
|
|
223
|
+
return this._photos;
|
|
224
|
+
}
|
|
225
|
+
set photos(e) {
|
|
226
|
+
this._photos = e, this.ctrl?.update(f(this));
|
|
227
|
+
}
|
|
228
|
+
static get observedAttributes() {
|
|
229
|
+
return [
|
|
230
|
+
"photos",
|
|
231
|
+
"width",
|
|
232
|
+
"height",
|
|
233
|
+
"card-width",
|
|
234
|
+
"card-height",
|
|
235
|
+
"pull-threshold",
|
|
236
|
+
"show-caption",
|
|
237
|
+
"initial-index",
|
|
238
|
+
"initial-flipped",
|
|
239
|
+
"aria-label"
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
connectedCallback() {
|
|
243
|
+
this.ctrl = u(this, f(this));
|
|
244
|
+
}
|
|
245
|
+
disconnectedCallback() {
|
|
246
|
+
this.ctrl?.destroy(), this.ctrl = null;
|
|
247
|
+
}
|
|
248
|
+
attributeChangedCallback() {
|
|
249
|
+
this.ctrl?.update(f(this));
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
typeof customElements < "u" && !customElements.get("cos-photo-postcard") && customElements.define(d, p);
|
|
253
|
+
//#endregion
|
|
254
|
+
export { p as CosPhotoPostcardElement, d as TAG };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/components/photoPostcard/core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/components/photoPostcard/element';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ElementSize } from './size';
|
|
2
|
+
export interface CanvasBoxSizeInput {
|
|
3
|
+
/** 为 true 时跟随父容器尺寸(需父级有明确高度) */
|
|
4
|
+
fill?: boolean;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
defaultWidth: number;
|
|
8
|
+
defaultHeight: number;
|
|
9
|
+
measured: ElementSize;
|
|
10
|
+
}
|
|
11
|
+
export interface CanvasBoxSize {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
/** 是否处于 fill 模式且尚未量到有效尺寸 */
|
|
15
|
+
pending: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** 根据 fill / 显式宽高 / 测量结果解析画布逻辑尺寸 */
|
|
18
|
+
export declare const resolveCanvasBoxSize: ({ fill, width, height, defaultWidth, defaultHeight, measured, }: CanvasBoxSizeInput) => CanvasBoxSize;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Apply fill / explicit size to the adapter host and make the engine root fill it. */
|
|
2
|
+
export declare function applyCanvasHostBox(container: HTMLElement, root: HTMLElement, opts: {
|
|
3
|
+
fill: boolean;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}): void;
|
|
7
|
+
/**
|
|
8
|
+
* Size the adapter host (React/Vue div or custom element) so percentage widths
|
|
9
|
+
* don't collapse when the host is a shrink-wrapped flex child. Root fills the host
|
|
10
|
+
* unless `rootFillsHost` is false (e.g. PhotoAlbum sizes itself via CSS variables).
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyBlockHostBox(container: HTMLElement, root: HTMLElement, size: {
|
|
13
|
+
width?: number | string;
|
|
14
|
+
height?: number | string;
|
|
15
|
+
rootFillsHost?: boolean;
|
|
16
|
+
}): void;
|
|
17
|
+
/** Toggle empty-state nodes; author `display:` rules must not override `[hidden]`. */
|
|
18
|
+
export declare function setHidden(el: HTMLElement, hidden: boolean): void;
|
|
19
|
+
/** Stable JSON key for options, ignoring functions (callbacks). */
|
|
20
|
+
export declare function optionsFingerprint(value: unknown): string;
|
|
21
|
+
/** True when non-function fields differ (shallow). */
|
|
22
|
+
export declare function optionsVisualChanged(prev: Record<string, unknown>, next: Record<string, unknown>): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { clamp, lerp } from './math';
|
|
2
|
+
export { bindVisibilityPause } from './visibility';
|
|
3
|
+
export { prefersReducedMotion, bindPrefersReducedMotion } from './reduced-motion';
|
|
4
|
+
export { observeElementSize } from './size';
|
|
5
|
+
export type { ElementSize } from './size';
|
|
6
|
+
export { getRelativePointerPosition } from './pointer';
|
|
7
|
+
export type { PointerPosition } from './pointer';
|
|
8
|
+
export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from './photo';
|
|
9
|
+
export { resolveCanvasBoxSize } from './canvas-box';
|
|
10
|
+
export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
|
|
11
|
+
export { applyCanvasHostBox, applyBlockHostBox, setHidden, optionsFingerprint, optionsVisualChanged, } from './host-layout';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 图片预览组件通用照片项 */
|
|
2
|
+
export interface PhotoItem {
|
|
3
|
+
/** 图片地址 */
|
|
4
|
+
src: string;
|
|
5
|
+
/** 图片替代文本 */
|
|
6
|
+
alt?: string;
|
|
7
|
+
/** 照片标题 */
|
|
8
|
+
title?: string;
|
|
9
|
+
/** 照片说明 */
|
|
10
|
+
description?: string;
|
|
11
|
+
}
|
|
12
|
+
/** 线性浏览:当前索引变化(相册 / 胶卷 / 晾绳等) */
|
|
13
|
+
export type PhotoIndexChangeHandler<T = PhotoItem> = (index: number, photo: T) => void;
|
|
14
|
+
/** 环形浏览:正对镜头的面变化(走马灯 / 旋转木马等) */
|
|
15
|
+
export type PhotoFaceChangeHandler<T = PhotoItem> = (index: number, photo?: T) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PointerPosition {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
|
5
|
+
type PointLike = {
|
|
6
|
+
clientX: number;
|
|
7
|
+
clientY: number;
|
|
8
|
+
};
|
|
9
|
+
/** 相对元素左上角的指针坐标(兼容 mouse / touch / pointer) */
|
|
10
|
+
export declare const getRelativePointerPosition: (element: Element, event: PointLike | {
|
|
11
|
+
touches?: ArrayLike<PointLike>;
|
|
12
|
+
changedTouches?: ArrayLike<PointLike>;
|
|
13
|
+
}) => PointerPosition | null;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CSSProperties, RefObject } from 'react';
|
|
2
|
+
import { ElementSize } from '../size';
|
|
3
|
+
export type { CanvasBoxSize, CanvasBoxSizeInput } from '../canvas-box';
|
|
4
|
+
export { resolveCanvasBoxSize } from '../canvas-box';
|
|
5
|
+
export interface UseElementSizeOptions {
|
|
6
|
+
/** 为 false 时不观察 */
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** 观察元素尺寸(clientWidth / clientHeight) */
|
|
10
|
+
export declare const useElementSize: <T extends Element>(ref: RefObject<T | null>, options?: UseElementSizeOptions) => ElementSize;
|
|
11
|
+
export interface UseCanvasBoxOptions {
|
|
12
|
+
/** 为 true 时铺满父容器(父级需有明确高度) */
|
|
13
|
+
fill?: boolean;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
defaultWidth: number;
|
|
17
|
+
defaultHeight: number;
|
|
18
|
+
}
|
|
19
|
+
export interface UseCanvasBoxResult {
|
|
20
|
+
hostRef: RefObject<HTMLDivElement | null>;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
/** 挂到宿主容器的样式(fill 时为 100%×100%) */
|
|
24
|
+
hostStyle: CSSProperties;
|
|
25
|
+
fill: boolean;
|
|
26
|
+
/** 是否处于 fill 模式且尚未量到有效尺寸 */
|
|
27
|
+
pending: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** 画布/效果宿主尺寸:fill 时跟随父容器,否则用显式宽高或默认值 */
|
|
30
|
+
export declare const useCanvasBox: ({ fill, width: widthProp, height: heightProp, defaultWidth, defaultHeight, }: UseCanvasBoxOptions) => UseCanvasBoxResult;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PhotoPostcardController, PhotoPostcardOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Imperative port of the v3.8.x PhotoPostcard React behavior.
|
|
4
|
+
* Motion updates only touch transform/opacity/class — never detach the active card.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createPhotoPostcard(container: HTMLElement, initial?: PhotoPostcardOptions): PhotoPostcardController;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PhotoPostcardItem, PhotoPostcardProps } from '../types';
|
|
2
|
+
export type { PhotoPostcardItem, PhotoPostcardProps };
|
|
3
|
+
export type PhotoPostcardOptions = PhotoPostcardProps;
|
|
4
|
+
export interface PhotoPostcardController {
|
|
5
|
+
update(options: Partial<PhotoPostcardOptions>): void;
|
|
6
|
+
destroy(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PhotoPostcardOptions } from '../core';
|
|
2
|
+
declare const TAG = "cos-photo-postcard";
|
|
3
|
+
declare class CosPhotoPostcardElement extends HTMLElement {
|
|
4
|
+
private ctrl;
|
|
5
|
+
_photos?: PhotoPostcardOptions['photos'];
|
|
6
|
+
get photos(): PhotoPostcardOptions['photos'] | undefined;
|
|
7
|
+
set photos(value: PhotoPostcardOptions['photos']);
|
|
8
|
+
static get observedAttributes(): string[];
|
|
9
|
+
connectedCallback(): void;
|
|
10
|
+
disconnectedCallback(): void;
|
|
11
|
+
attributeChangedCallback(): void;
|
|
12
|
+
}
|
|
13
|
+
export { CosPhotoPostcardElement, TAG };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { PhotoPostcardProps } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* 旅行明信片堆叠:单张特色明信片可 3D 翻转,水平拖拽切换上一张/下一张。
|
|
5
|
+
* React 端保持 v3.8.x 声明式实现与交互逻辑。
|
|
6
|
+
*/
|
|
7
|
+
declare const PhotoPostcard: React.FC<PhotoPostcardProps>;
|
|
8
|
+
export default PhotoPostcard;
|
|
9
|
+
export type { PhotoPostcardItem, PhotoPostcardProps } from '../types';
|
|
10
|
+
export type { PhotoPostcardOptions } from '../core/types';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type StyleMap = Record<string, string | number | undefined>;
|
|
2
|
+
/** 单张旅行明信片数据 */
|
|
3
|
+
export interface PhotoPostcardItem {
|
|
4
|
+
/** 图片地址 */
|
|
5
|
+
src: string;
|
|
6
|
+
/** 图片替代文本 */
|
|
7
|
+
alt?: string;
|
|
8
|
+
/** 明信片标题(背面问候语 / 正面说明标题) */
|
|
9
|
+
title?: string;
|
|
10
|
+
/** 明信片正文(背面书写区 / 正面说明) */
|
|
11
|
+
description?: string;
|
|
12
|
+
}
|
|
13
|
+
/** PhotoPostcard 组件属性 */
|
|
14
|
+
export interface PhotoPostcardProps {
|
|
15
|
+
/** 明信片照片列表 */
|
|
16
|
+
photos: PhotoPostcardItem[];
|
|
17
|
+
/** 组件宽度 */
|
|
18
|
+
width?: number | string;
|
|
19
|
+
/** 组件高度 */
|
|
20
|
+
height?: number | string;
|
|
21
|
+
/** 单张明信片宽度(px) */
|
|
22
|
+
cardWidth?: number;
|
|
23
|
+
/** 单张明信片高度(px) */
|
|
24
|
+
cardHeight?: number;
|
|
25
|
+
/** 水平拖拽切换阈值(px) */
|
|
26
|
+
pullThreshold?: number;
|
|
27
|
+
/** 是否在正面底部显示标题与说明 */
|
|
28
|
+
showCaption?: boolean;
|
|
29
|
+
/** 初始展示索引 */
|
|
30
|
+
initialIndex?: number;
|
|
31
|
+
/** 初始是否背面朝上 */
|
|
32
|
+
initialFlipped?: boolean;
|
|
33
|
+
/** 点击当前明信片(几乎无位移时触发) */
|
|
34
|
+
onPhotoClick?: (index: number, photo: PhotoPostcardItem) => void;
|
|
35
|
+
/** 当前索引变化回调 */
|
|
36
|
+
onIndexChange?: (index: number, photo: PhotoPostcardItem) => void;
|
|
37
|
+
/** 正反面翻转状态变化回调 */
|
|
38
|
+
onFlipChange?: (flipped: boolean) => void;
|
|
39
|
+
/** 无障碍名称 */
|
|
40
|
+
ariaLabel?: string;
|
|
41
|
+
/** 自定义类名 */
|
|
42
|
+
className?: string;
|
|
43
|
+
/** 自定义样式 */
|
|
44
|
+
style?: StyleMap;
|
|
45
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
declare module '*.vue' {
|
|
4
|
+
import type { DefineComponent } from 'vue';
|
|
5
|
+
const component: DefineComponent<object, object, unknown>;
|
|
6
|
+
export default component;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '*.module.less' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.png' {
|
|
20
|
+
const src: string;
|
|
21
|
+
export default src;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.jpg' {
|
|
25
|
+
const src: string;
|
|
26
|
+
export default src;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.mp4' {
|
|
30
|
+
const src: string;
|
|
31
|
+
export default src;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.mp3' {
|
|
35
|
+
const src: string;
|
|
36
|
+
export default src;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.svg' {
|
|
40
|
+
import type { FC, SVGProps } from 'react';
|
|
41
|
+
|
|
42
|
+
export const ReactComponent: FC<SVGProps<SVGSVGElement>>;
|
|
43
|
+
const src: string;
|
|
44
|
+
export default src;
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./react.css');var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("react/jsx-runtime");var u=`cos-photo-postcard`,d=6,f=280,p=320,m=e=>typeof e==`number`?`${e}px`:e,h=(e,t)=>t<=0?0:(e%t+t)%t,g=(e,t)=>t<=0?0:Math.max(0,Math.min(t-1,Math.floor(e))),_=e=>{let t=Math.sin(e*127.1+31.7)*43758.5453;return t-Math.floor(t)},v=({photo:e,showCaption:t})=>{let n=t&&(e.title||e.description),r=e.title?e.title:`Greetings from the road`;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`${u}__face ${u}__front`,children:[(0,l.jsx)(`div`,{className:`${u}__photo-frame${n?` ${u}__photo-frame-with-caption`:``}`,children:(0,l.jsx)(`div`,{className:`${u}__photo-wrap`,children:(0,l.jsx)(`img`,{className:`${u}__photo`,src:e.src,alt:e.alt??e.title??``,draggable:!1})})}),(0,l.jsx)(`div`,{className:`${u}__corner-stamp`,"aria-hidden":`true`}),n?(0,l.jsxs)(`div`,{className:`${u}__front-caption`,children:[e.title?(0,l.jsx)(`p`,{className:`${u}__front-caption-title`,children:e.title}):null,e.description?(0,l.jsx)(`p`,{className:`${u}__front-caption-desc`,children:e.description}):null]}):null]}),(0,l.jsxs)(`div`,{className:`${u}__face ${u}__back`,children:[(0,l.jsx)(`div`,{className:`${u}__divider`,"aria-hidden":`true`}),(0,l.jsxs)(`div`,{className:`${u}__lined-paper`,children:[(0,l.jsx)(`p`,{className:`${u}__greeting`,children:r}),e.description?(0,l.jsx)(`p`,{className:`${u}__body-text`,children:e.description}):(0,l.jsx)(`p`,{className:`${u}__body-placeholder`,children:`Wish you were here…`})]}),(0,l.jsxs)(`div`,{className:`${u}__back-footer`,children:[(0,l.jsx)(`div`,{className:`${u}__postmark`,"aria-hidden":`true`,children:(0,l.jsxs)(`span`,{className:`${u}__postmark-text`,children:[`TRAVEL`,(0,l.jsx)(`br`,{}),`POST`]})}),(0,l.jsx)(`div`,{className:`${u}__stamp-square`,"aria-hidden":`true`})]})]})]})},y=({photos:e,width:t=360,height:n=420,cardWidth:r=260,cardHeight:i=170,pullThreshold:a=80,showCaption:o=!0,initialIndex:s=0,initialFlipped:y=!1,onPhotoClick:b,onIndexChange:x,onFlipChange:S,ariaLabel:C=`明信片`,className:w,style:T})=>{let E=(0,c.useRef)(null),D=(0,c.useRef)(null),O=(0,c.useRef)(g(s,e.length)),k=(0,c.useRef)(b),A=(0,c.useRef)(x),j=(0,c.useRef)(S),M=(0,c.useRef)(e),N=(0,c.useRef)(null),[P,F]=(0,c.useState)(()=>g(s,e.length)),[I,L]=(0,c.useState)(y),[R,z]=(0,c.useState)(0),[B,V]=(0,c.useState)(`idle`),H=e.length,U=e[P];(0,c.useEffect)(()=>{k.current=b,A.current=x,j.current=S,M.current=e},[b,x,S,e]),(0,c.useEffect)(()=>{O.current=P},[P]),(0,c.useEffect)(()=>()=>{N.current!=null&&window.clearTimeout(N.current)},[]);let W=(0,c.useMemo)(()=>H<=1?[]:[1,2].slice(0,Math.min(2,H-1)).map(e=>{let t=P*13.7+e*5.3;return{depth:e,rot:(_(t)*2-1)*5.5,dx:e*5+_(t+1.1)*4,dy:e*3+_(t+2.4)*3}}),[H,P]),G=(0,c.useCallback)(e=>{let t=M.current,n=g(e,t.length);F(n),O.current=n,L(!1),j.current?.(!1);let r=t[n];r&&A.current?.(n,r)},[]),K=(0,c.useCallback)(e=>{G(e),z(0),V(`idle`)},[G]),q=(0,c.useCallback)(e=>{let t=e*(r*.55+48);V(`exiting`),z(t),N.current!=null&&window.clearTimeout(N.current),N.current=window.setTimeout(()=>{let t=M.current;K(h(O.current+e,t.length))},f)},[r,K]),J=(0,c.useCallback)(()=>{V(`snapping`),z(0),window.setTimeout(()=>V(`idle`),p)},[]),Y=(0,c.useCallback)(e=>{M.current.length<=1||q(e>0?1:-1)},[q]),X=(0,c.useCallback)(()=>{L(e=>{let t=!e;return j.current?.(t),t})},[]),Z=(0,c.useCallback)(e=>{B===`exiting`||H===0||(D.current={pointerId:e.pointerId,startX:e.clientX,moved:!1},V(`dragging`),e.currentTarget.setPointerCapture(e.pointerId))},[H,B]),Q=(0,c.useCallback)(e=>{let t=D.current;if(!t||t.pointerId!==e.pointerId||B===`exiting`)return;let n=e.clientX-t.startX;Math.abs(n)>d&&(t.moved=!0),z(H<=1?n*.22:n)},[H,B]),$=(0,c.useCallback)(e=>{let t=D.current;if(!t||t.pointerId!==e.pointerId||(D.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),B===`exiting`))return;let n=e.clientX-t.startX;if(!t.moved){V(`idle`),z(0),X();let e=M.current[O.current];e&&k.current?.(O.current,e);return}if(Math.abs(n)>=a&&H>1){q(n>0?1:-1);return}J()},[q,H,B,a,J,X]),ee=(0,c.useCallback)(e=>{let t=D.current;!t||t.pointerId!==e.pointerId||(D.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),B!==`exiting`&&J())},[B,J]);(0,c.useEffect)(()=>{let e=E.current;if(!e)return;let t=e=>{e.key===`ArrowRight`?(e.preventDefault(),Y(1)):e.key===`ArrowLeft`?(e.preventDefault(),Y(-1)):(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),X())};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[Y,X]);let te=`translateX(${R}px)`,ne=B===`snapping`||B===`exiting`?`transform ${B===`exiting`?f:p}ms cubic-bezier(0.22, 1, 0.36, 1), opacity ${f}ms ease`:`none`,re=[u,`cos-photoPostcard-host`,w].filter(Boolean).join(` `),ie=[`${u}__card-active`,I?`${u}__flipped`:``,B===`exiting`?`${u}__card-exiting`:``].filter(Boolean).join(` `);return(0,l.jsx)(`div`,{ref:E,className:re,style:{width:m(t),height:m(n),...T},role:`region`,"aria-label":C,tabIndex:0,children:(0,l.jsx)(`div`,{className:`${u}__stage`,children:H===0?(0,l.jsx)(`div`,{className:`${u}__empty`,children:`暂无明信片`}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`${u}__stack`,style:{width:r,height:i},children:[W.map(({depth:e,rot:t,dx:n,dy:a})=>(0,l.jsx)(`div`,{className:`${u}__stack-card`,style:{width:r,height:i,transform:`translate(calc(-50% + ${n}px), calc(-50% + ${a}px)) rotate(${t}deg)`,opacity:e===1?.92:.78},"aria-hidden":`true`},e)),(0,l.jsx)(`div`,{className:`${u}__card-slot`,style:{width:r,height:i},children:(0,l.jsx)(`div`,{className:ie,style:{width:r,height:i,transform:te,transition:ne,opacity:B===`exiting`?.55:1},onPointerDown:Z,onPointerMove:Q,onPointerUp:$,onPointerCancel:ee,role:`button`,"aria-label":U?`${I?`背面`:`正面`}:${U.alt??U.title??`明信片 ${P+1}`}`:void 0,"aria-pressed":I,children:U?(0,l.jsx)(`div`,{className:`${u}__flip-inner`,children:(0,l.jsx)(v,{photo:U,showCaption:o})}):null})})]}),H>1?(0,l.jsx)(`div`,{className:`${u}__hint`,children:`拖拽切换 · 点击查看背面`}):null]})})})};exports.PhotoPostcard=y,exports.default=y;
|