@cos-design/photo-postcard 3.7.3 → 4.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/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/element-options.d.ts +19 -0
- package/dist/core/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/core/packages/shared/src/index.d.ts +13 -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 +219 -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/element-options.d.ts +19 -0
- package/dist/element/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/element/packages/shared/src/index.d.ts +13 -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/element-options.d.ts +19 -0
- package/dist/react/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/react/packages/shared/src/index.d.ts +13 -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/element-options.d.ts +19 -0
- package/dist/vue/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/vue/packages/shared/src/index.d.ts +13 -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 +46 -11
- 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,219 @@
|
|
|
1
|
+
import { applyBlockHostBox as e, optionCallbackDispatcher as t, readBooleanAttr as n, readJsonAttr as r, readNumberAttr as i, readPropertyOverride as a, readStringAttr as o } from "@cos-design/shared";
|
|
2
|
+
import './element.css';//#region src/components/photoPostcard/core/engine.ts
|
|
3
|
+
var s = "cos-photo-postcard", c = 6, l = 280, u = 320, d = (e, t) => t <= 0 ? 0 : (e % t + t) % t, f = (e, t) => t <= 0 ? 0 : Math.max(0, Math.min(t - 1, Math.floor(e))), p = (e) => {
|
|
4
|
+
let t = Math.sin(e * 127.1 + 31.7) * 43758.5453;
|
|
5
|
+
return t - Math.floor(t);
|
|
6
|
+
}, m = (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
|
+
}, h = (e, t, n) => {
|
|
9
|
+
let r = n && (t.title || t.description), i = t.title ? t.title : "Greetings from the road";
|
|
10
|
+
e.replaceChildren();
|
|
11
|
+
let a = document.createElement("div");
|
|
12
|
+
a.className = `${s}__face ${s}__front`;
|
|
13
|
+
let o = document.createElement("div");
|
|
14
|
+
o.className = `${s}__photo-frame${r ? ` ${s}__photo-frame-with-caption` : ""}`;
|
|
15
|
+
let c = document.createElement("div");
|
|
16
|
+
c.className = `${s}__photo-wrap`;
|
|
17
|
+
let l = document.createElement("img");
|
|
18
|
+
l.className = `${s}__photo`, l.src = t.src, l.alt = t.alt ?? t.title ?? "", l.draggable = !1, c.appendChild(l), o.appendChild(c);
|
|
19
|
+
let u = document.createElement("div");
|
|
20
|
+
if (u.className = `${s}__corner-stamp`, u.setAttribute("aria-hidden", "true"), a.append(o, u), r) {
|
|
21
|
+
let e = document.createElement("div");
|
|
22
|
+
if (e.className = `${s}__front-caption`, t.title) {
|
|
23
|
+
let n = document.createElement("p");
|
|
24
|
+
n.className = `${s}__front-caption-title`, n.textContent = t.title, e.appendChild(n);
|
|
25
|
+
}
|
|
26
|
+
if (t.description) {
|
|
27
|
+
let n = document.createElement("p");
|
|
28
|
+
n.className = `${s}__front-caption-desc`, n.textContent = t.description, e.appendChild(n);
|
|
29
|
+
}
|
|
30
|
+
a.appendChild(e);
|
|
31
|
+
}
|
|
32
|
+
let d = document.createElement("div");
|
|
33
|
+
d.className = `${s}__face ${s}__back`;
|
|
34
|
+
let f = document.createElement("div");
|
|
35
|
+
f.className = `${s}__divider`, f.setAttribute("aria-hidden", "true");
|
|
36
|
+
let p = document.createElement("div");
|
|
37
|
+
p.className = `${s}__lined-paper`;
|
|
38
|
+
let m = document.createElement("p");
|
|
39
|
+
m.className = `${s}__greeting`, m.textContent = i, p.appendChild(m);
|
|
40
|
+
let h = document.createElement("p");
|
|
41
|
+
t.description ? (h.className = `${s}__body-text`, h.textContent = t.description) : (h.className = `${s}__body-placeholder`, h.textContent = "Wish you were here…"), p.appendChild(h);
|
|
42
|
+
let g = document.createElement("div");
|
|
43
|
+
g.className = `${s}__back-footer`;
|
|
44
|
+
let _ = document.createElement("div");
|
|
45
|
+
_.className = `${s}__postmark`, _.setAttribute("aria-hidden", "true");
|
|
46
|
+
let v = document.createElement("span");
|
|
47
|
+
v.className = `${s}__postmark-text`, v.innerHTML = "TRAVEL<br>POST", _.appendChild(v);
|
|
48
|
+
let y = document.createElement("div");
|
|
49
|
+
y.className = `${s}__stamp-square`, y.setAttribute("aria-hidden", "true"), g.append(_, y), d.append(f, p, g), e.append(a, d);
|
|
50
|
+
};
|
|
51
|
+
function g(t, n = { photos: [] }) {
|
|
52
|
+
let r = {
|
|
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
|
+
...n,
|
|
63
|
+
photos: Array.isArray(n.photos) ? n.photos : []
|
|
64
|
+
}, i = !1, a = f(r.initialIndex ?? 0, r.photos.length), o = !!r.initialFlipped, g = 0, _ = "idle", v = null, y = null, b = null, x = "", S = document.createElement("div"), C = document.createElement("div");
|
|
65
|
+
C.className = `${s}__stage`;
|
|
66
|
+
let w = document.createElement("div");
|
|
67
|
+
w.className = `${s}__empty`, w.textContent = "暂无明信片";
|
|
68
|
+
let T = document.createElement("div");
|
|
69
|
+
T.className = `${s}__stack`;
|
|
70
|
+
let E = document.createElement("div");
|
|
71
|
+
E.className = `${s}__card-slot`;
|
|
72
|
+
let D = document.createElement("div"), O = document.createElement("div");
|
|
73
|
+
O.className = `${s}__flip-inner`, D.appendChild(O), E.appendChild(D);
|
|
74
|
+
let k = document.createElement("div");
|
|
75
|
+
k.className = `${s}__hint`, k.textContent = "拖拽切换 · 点击查看背面", C.append(w, T, k), S.appendChild(C), t.appendChild(S);
|
|
76
|
+
let A = () => Array.isArray(r.photos) ? r.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
|
+
`${s}__card-active`,
|
|
79
|
+
o ? `${s}__flipped` : "",
|
|
80
|
+
_ === "exiting" ? `${s}__card-exiting` : ""
|
|
81
|
+
].filter(Boolean).join(" "), D.style.transform = `translateX(${g}px)`, D.style.transition = _ === "snapping" || _ === "exiting" ? `transform ${_ === "exiting" ? l : u}ms cubic-bezier(0.22, 1, 0.36, 1), opacity ${l}ms ease` : "none", D.style.opacity = _ === "exiting" ? "0.55" : "1", D.setAttribute("aria-pressed", String(o));
|
|
82
|
+
let e = A()[a];
|
|
83
|
+
D.setAttribute("aria-label", e ? `${o ? "背面" : "正面"}:${e.alt ?? e.title ?? `明信片 ${a + 1}`}` : "");
|
|
84
|
+
}, P = (e, t, n) => {
|
|
85
|
+
let r = new Set([E]);
|
|
86
|
+
for (let e of [...T.children]) r.has(e) || e.remove();
|
|
87
|
+
let i = e <= 1 ? [] : [1, 2].slice(0, Math.min(2, e - 1)).map((e) => {
|
|
88
|
+
let t = a * 13.7 + e * 5.3;
|
|
89
|
+
return {
|
|
90
|
+
depth: e,
|
|
91
|
+
rot: (p(t) * 2 - 1) * 5.5,
|
|
92
|
+
dx: e * 5 + p(t + 1.1) * 4,
|
|
93
|
+
dy: e * 3 + p(t + 2.4) * 3
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
for (let { depth: e, rot: r, dx: a, dy: o } of i) {
|
|
97
|
+
let i = document.createElement("div");
|
|
98
|
+
i.className = `${s}__stack-card`, i.style.width = `${t}px`, i.style.height = `${n}px`, i.style.transform = `translate(calc(-50% + ${a}px), calc(-50% + ${o}px)) rotate(${r}deg)`, i.style.opacity = e === 1 ? "0.92" : "0.78", i.setAttribute("aria-hidden", "true"), T.insertBefore(i, E);
|
|
99
|
+
}
|
|
100
|
+
}, F = () => {
|
|
101
|
+
let n = A(), i = n.length, o = r.cardWidth ?? 260, c = r.cardHeight ?? 170, l = r.showCaption !== !1;
|
|
102
|
+
if (S.className = [s, r.className].filter(Boolean).join(" "), e(t, S, {
|
|
103
|
+
width: r.width ?? 360,
|
|
104
|
+
height: r.height ?? 420
|
|
105
|
+
}), m(S, r.style), S.setAttribute("role", "region"), S.setAttribute("aria-label", r.ariaLabel ?? "明信片"), S.tabIndex = 0, w.hidden = i > 0, T.hidden = i === 0, k.hidden = i <= 1, i === 0) {
|
|
106
|
+
O.replaceChildren(), x = "";
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
T.style.width = `${o}px`, T.style.height = `${c}px`, (!E.isConnected || E.parentElement !== T) && T.appendChild(E), P(i, o, c), E.style.width = `${o}px`, E.style.height = `${c}px`, D.style.width = `${o}px`, D.style.height = `${c}px`, D.setAttribute("role", "button");
|
|
110
|
+
let u = n[a], d = M(u, l);
|
|
111
|
+
u && d !== x ? (h(O, u, l), x = d) : u || (O.replaceChildren(), x = ""), N();
|
|
112
|
+
}, I = (e) => {
|
|
113
|
+
let t = A(), n = f(e, t.length);
|
|
114
|
+
a = n, o = !1, r.onFlipChange?.(!1);
|
|
115
|
+
let i = t[n];
|
|
116
|
+
i && r.onIndexChange?.(n, i);
|
|
117
|
+
}, L = (e) => {
|
|
118
|
+
I(e), g = 0, _ = "idle", F();
|
|
119
|
+
}, R = (e) => {
|
|
120
|
+
let t = e * ((r.cardWidth ?? 260) * .55 + 48);
|
|
121
|
+
_ = "exiting", g = t, N(), y != null && window.clearTimeout(y), y = window.setTimeout(() => {
|
|
122
|
+
L(d(a + e, A().length));
|
|
123
|
+
}, l);
|
|
124
|
+
}, z = () => {
|
|
125
|
+
_ = "snapping", g = 0, N(), b != null && window.clearTimeout(b), b = window.setTimeout(() => {
|
|
126
|
+
_ = "idle", N();
|
|
127
|
+
}, u);
|
|
128
|
+
}, B = (e) => {
|
|
129
|
+
A().length <= 1 || R(e > 0 ? 1 : -1);
|
|
130
|
+
}, V = () => {
|
|
131
|
+
o = !o, r.onFlipChange?.(o), 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) > c && (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 i = e.clientX - t;
|
|
147
|
+
if (!n) {
|
|
148
|
+
_ = "idle", g = 0, V();
|
|
149
|
+
let e = A()[a];
|
|
150
|
+
e && r.onPhotoClick?.(a, e);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (Math.abs(i) >= (r.pullThreshold ?? 80) && j() > 1) {
|
|
154
|
+
R(i > 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 ? r.photos : [];
|
|
166
|
+
r = {
|
|
167
|
+
...r,
|
|
168
|
+
...e,
|
|
169
|
+
photos: t
|
|
170
|
+
}, a = f(a, A().length), F();
|
|
171
|
+
},
|
|
172
|
+
destroy() {
|
|
173
|
+
i || (i = !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 _ = "cos-photo-postcard";
|
|
180
|
+
function v(e) {
|
|
181
|
+
let s = {};
|
|
182
|
+
return o(s, e, "width", "width"), o(s, e, "height", "height"), o(s, e, "ariaLabel", "aria-label"), i(s, e, "cardWidth", "card-width"), i(s, e, "cardHeight", "card-height"), i(s, e, "pullThreshold", "pull-threshold"), i(s, e, "initialIndex", "initial-index"), n(s, e, "showCaption", "show-caption", "optional-true"), n(s, e, "initialFlipped", "initial-flipped", "presence"), r(s, e, "photos", "photos"), a(s, e, "photos", "_photos"), s.onPhotoClick = t(e, "photo-click"), s.onIndexChange = t(e, "index-change"), s.onFlipChange = t(e, "flip-change"), s;
|
|
183
|
+
}
|
|
184
|
+
var y = class extends HTMLElement {
|
|
185
|
+
ctrl = null;
|
|
186
|
+
_photos;
|
|
187
|
+
get photos() {
|
|
188
|
+
return this._photos;
|
|
189
|
+
}
|
|
190
|
+
set photos(e) {
|
|
191
|
+
this._photos = e, this.ctrl?.update(v(this));
|
|
192
|
+
}
|
|
193
|
+
static get observedAttributes() {
|
|
194
|
+
return [
|
|
195
|
+
"photos",
|
|
196
|
+
"width",
|
|
197
|
+
"height",
|
|
198
|
+
"card-width",
|
|
199
|
+
"card-height",
|
|
200
|
+
"pull-threshold",
|
|
201
|
+
"show-caption",
|
|
202
|
+
"initial-index",
|
|
203
|
+
"initial-flipped",
|
|
204
|
+
"aria-label"
|
|
205
|
+
];
|
|
206
|
+
}
|
|
207
|
+
connectedCallback() {
|
|
208
|
+
this.ctrl = g(this, v(this));
|
|
209
|
+
}
|
|
210
|
+
disconnectedCallback() {
|
|
211
|
+
this.ctrl?.destroy(), this.ctrl = null;
|
|
212
|
+
}
|
|
213
|
+
attributeChangedCallback() {
|
|
214
|
+
this.ctrl?.update(v(this));
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
typeof customElements < "u" && !customElements.get("cos-photo-postcard") && customElements.define(_, y);
|
|
218
|
+
//#endregion
|
|
219
|
+
export { y as CosPhotoPostcardElement, _ 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,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Component attribute → Core options parsing (v4 Element adapters).
|
|
3
|
+
* Keeps behavior consistent across 91 components.
|
|
4
|
+
*/
|
|
5
|
+
export type BooleanAttrMode =
|
|
6
|
+
/** `options.key = el.hasAttribute(attr)` — always written */
|
|
7
|
+
'presence'
|
|
8
|
+
/** Only when attribute present: `raw !== 'false' && raw !== '0'` (omit when absent) */
|
|
9
|
+
| 'optional-true'
|
|
10
|
+
/** Only when attribute present; when absent leave `undefined` (controlled props like `flipped`) */
|
|
11
|
+
| 'optional-undefined';
|
|
12
|
+
export declare const camelToKebabAttr: (name: string) => string;
|
|
13
|
+
export declare function readStringAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
|
|
14
|
+
export declare function readNumberAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
|
|
15
|
+
export declare function readBooleanAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string, mode?: BooleanAttrMode): void;
|
|
16
|
+
export declare function readJsonAttr<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, attr?: string): void;
|
|
17
|
+
/** Property setters on the custom element class (`_prizes`, `_items`, …) override attributes. */
|
|
18
|
+
export declare function readPropertyOverride<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, backingKey: string): void;
|
|
19
|
+
export declare function optionCallbackDispatcher(el: HTMLElement, eventName: string): (...args: unknown[]) => void;
|
|
@@ -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,13 @@
|
|
|
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';
|
|
12
|
+
export type { BooleanAttrMode } from './element-options';
|
|
13
|
+
export { camelToKebabAttr, optionCallbackDispatcher, readBooleanAttr, readJsonAttr, readNumberAttr, readPropertyOverride, readStringAttr, } from './element-options';
|
|
@@ -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;
|