@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 @@
|
|
|
1
|
+
export * from './src/components/photoPostcard/core';
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { applyBlockHostBox as e } from "@cos-design/shared";
|
|
2
|
+
//#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
|
+
export { u as createPhotoPostcard };
|
|
@@ -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 };
|
package/dist/{src/components/photoPostcard → core/src/components/photoPostcard/react}/index.d.ts
RENAMED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { PhotoPostcardProps } from '
|
|
2
|
+
import { PhotoPostcardProps } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* 旅行明信片堆叠:单张特色明信片可 3D 翻转,水平拖拽切换上一张/下一张。
|
|
5
|
+
* React 端保持 v3.8.x 声明式实现与交互逻辑。
|
|
5
6
|
*/
|
|
6
7
|
declare const PhotoPostcard: React.FC<PhotoPostcardProps>;
|
|
7
8
|
export default PhotoPostcard;
|
|
8
|
-
export type { PhotoPostcardItem, PhotoPostcardProps } from '
|
|
9
|
+
export type { PhotoPostcardItem, PhotoPostcardProps } from '../types';
|
|
10
|
+
export type { PhotoPostcardOptions } from '../core/types';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export type StyleMap = Record<string, string | number | undefined>;
|
|
2
2
|
/** 单张旅行明信片数据 */
|
|
3
3
|
export interface PhotoPostcardItem {
|
|
4
4
|
/** 图片地址 */
|
|
@@ -41,5 +41,5 @@ export interface PhotoPostcardProps {
|
|
|
41
41
|
/** 自定义类名 */
|
|
42
42
|
className?: string;
|
|
43
43
|
/** 自定义样式 */
|
|
44
|
-
style?:
|
|
44
|
+
style?: StyleMap;
|
|
45
45
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/// <reference types="vite/client" />
|
|
2
2
|
|
|
3
|
+
declare module '*.vue' {
|
|
4
|
+
import type { DefineComponent } from 'vue';
|
|
5
|
+
const component: DefineComponent<object, object, unknown>;
|
|
6
|
+
export default component;
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
declare module '*.module.less' {
|
|
4
10
|
const classes: { readonly [key: string]: string };
|
|
5
11
|
export default classes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.cos-photoPostcard-host,cos-photo-postcard{box-sizing:border-box;width:100%;max-width:100%;display:block}.cos-photo-postcard__empty[hidden]{display:none!important}.cos-photo-postcard{--card-stock:#f4f0e8;--card-edge:#e8e2d6;--ink:#3d4a4f;--ink-muted:#6b787d;--stamp-teal:#2a5f6f;--stamp-coral:#c97b6a;--line-color:#2a5f6f24;--shadow-soft:#23373e24;--shadow-deep:#1928301a;-webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;background:radial-gradient(120% 90% at 50% 108%,#2a5f6f1a 0%,#0000 58%),radial-gradient(70% 55% at 14% 8%,#ffffff6b 0%,#0000 62%),linear-gradient(168deg,#ece7de 0%,#e4dfd4 48%,#d9d3c8 100%);border-radius:14px;position:relative;overflow:hidden}.cos-photo-postcard:before{content:"";pointer-events:none;background:repeating-linear-gradient(92deg,#ffffff0d 0 1px,#0000 1px 9px),repeating-linear-gradient(8deg,#3c464b0a 0 2px,#0000 2px 16px);position:absolute;inset:0}.cos-photo-postcard__stage{justify-content:center;align-items:center;width:100%;height:100%;display:flex;position:relative}.cos-photo-postcard__stack{touch-action:none;position:relative}.cos-photo-postcard__stack-card{background:var(--card-stock);box-shadow:0 1px 0 #ffffff8c inset, 0 2px 4px var(--shadow-soft), 0 10px 24px var(--shadow-deep);pointer-events:none;will-change:transform;border-radius:3px;position:absolute;top:50%;left:50%}.cos-photo-postcard__stack-card:first-child{z-index:1}.cos-photo-postcard__stack-card:nth-child(2){z-index:2}.cos-photo-postcard__card-slot{z-index:3;perspective:900px;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}.cos-photo-postcard__card-active{cursor:grab;will-change:transform;filter:drop-shadow(0 8px 18px var(--shadow-soft)) drop-shadow(0 2px 6px var(--shadow-deep));position:relative}.cos-photo-postcard__card-active:active{cursor:grabbing}.cos-photo-postcard__card-exiting{pointer-events:none}.cos-photo-postcard__flip-inner{width:100%;height:100%;transform-style:preserve-3d;transition:transform .58s cubic-bezier(.4,.12,.18,1);position:relative}.cos-photo-postcard__flipped .cos-photo-postcard__flip-inner{transform:rotateY(180deg)}.cos-photo-postcard__face{backface-visibility:hidden;transform-style:preserve-3d;background:var(--card-stock);border:1px solid var(--card-edge);border-radius:3px;position:absolute;inset:0;overflow:hidden}.cos-photo-postcard__front{transform:rotateY(0)}.cos-photo-postcard__back{flex-direction:column;display:flex;transform:rotateY(180deg)}.cos-photo-postcard__photo-frame{background:#fff;border:2px solid #fff;flex-direction:column;display:flex;position:absolute;inset:10px;box-shadow:0 0 0 1px #0000000d}.cos-photo-postcard__photo-frame-with-caption{bottom:52px}.cos-photo-postcard__photo-wrap{background:#dfe5e8;flex:1;min-height:0;position:relative;overflow:hidden}.cos-photo-postcard__photo{object-fit:cover;pointer-events:none;width:100%;height:100%;display:block}.cos-photo-postcard__corner-stamp{z-index:2;border:1.5px solid var(--stamp-teal);background:repeating-linear-gradient(0deg, var(--stamp-teal) 0 2px, transparent 2px 4px), linear-gradient(145deg, #2a5f6f2e 0%, #2a5f6f14 100%);opacity:.88;width:28px;height:34px;position:absolute;top:8px;right:8px;box-shadow:0 1px 2px #00000014;-webkit-mask-image:radial-gradient(circle at 0 0,#0000 2px,#000 2.5px),linear-gradient(#000 0 0);mask-image:radial-gradient(circle at 0 0,#0000 2px,#000 2.5px),linear-gradient(#000 0 0);-webkit-mask-position:0 0,0 0;mask-position:0 0,0 0;-webkit-mask-size:4px 4px,auto;mask-size:4px 4px,auto;-webkit-mask-repeat:repeat,repeat;mask-repeat:repeat,repeat;-webkit-mask-clip:border-box,border-box;mask-clip:border-box,border-box;-webkit-mask-origin:border-box,border-box;mask-origin:border-box,border-box;-webkit-mask-composite:xor;mask-composite:exclude;-webkit-mask-source-type:auto,auto;mask-mode:match-source,match-source}.cos-photo-postcard__corner-stamp:after{content:"";border:1px dashed #ffffff8c;position:absolute;inset:5px 4px}.cos-photo-postcard__front-caption{color:var(--ink);letter-spacing:.02em;border-top:1px solid #2a5f6f1f;padding:6px 8px;font-size:10px;line-height:1.35;position:absolute;bottom:8px;left:10px;right:10px}.cos-photo-postcard__front-caption-title{margin:0;font-size:11px;font-weight:600}.cos-photo-postcard__front-caption-desc{color:var(--ink-muted);margin:2px 0 0;font-size:9px}.cos-photo-postcard__lined-paper{background:repeating-linear-gradient(180deg, transparent 0, transparent 17px, var(--line-color) 17px, var(--line-color) 18px), linear-gradient(180deg, #ffffff59 0%, transparent 24%);border-radius:1px;flex:1;margin:14px 16px 10px;padding:12px 14px 8px;position:relative}.cos-photo-postcard__greeting{color:var(--stamp-teal);letter-spacing:.03em;margin:0 0 10px;font-family:Georgia,Times New Roman,serif;font-size:13px;font-style:italic;font-weight:600}.cos-photo-postcard__body-text{color:var(--ink);letter-spacing:.01em;white-space:pre-wrap;margin:0;font-family:Georgia,Times New Roman,serif;font-size:11px;line-height:18px}.cos-photo-postcard__body-placeholder{color:var(--ink-muted);opacity:.72;margin:0;font-family:Georgia,Times New Roman,serif;font-size:11px;font-style:italic;line-height:18px}.cos-photo-postcard__back-footer{flex-shrink:0;height:58px;margin:0 14px 12px;position:relative}.cos-photo-postcard__stamp-square{border:2px solid var(--stamp-teal);background:repeating-linear-gradient(-38deg,#2a5f6f38 0 3px,#c97b6a29 3px 6px),linear-gradient(160deg,#2a5f6f1f 0%,#c97b6a1a 100%);width:44px;height:52px;position:absolute;bottom:0;right:0;box-shadow:inset 0 0 0 3px #f4f0e8d9,0 1px 3px #0000001a}.cos-photo-postcard__stamp-square:before{content:"";border:1px dashed #2a5f6f73;position:absolute;inset:6px}.cos-photo-postcard__postmark{border:2px solid var(--stamp-coral);width:52px;height:52px;color:var(--stamp-coral);letter-spacing:.08em;text-transform:uppercase;opacity:.82;border-radius:50%;justify-content:center;align-items:center;font-size:7px;font-weight:700;display:flex;position:absolute;bottom:6px;left:4px;transform:rotate(-12deg)}.cos-photo-postcard__postmark:before{content:"";border:1px solid #c97b6a73;border-radius:50%;position:absolute;inset:5px}.cos-photo-postcard__postmark-text{z-index:1;text-align:center;line-height:1.2;position:relative}.cos-photo-postcard__divider{pointer-events:none;background:linear-gradient(#0000,#2a5f6f2e 18% 82%,#0000);width:1px;position:absolute;top:14px;bottom:14px;left:58%}.cos-photo-postcard__empty{color:#3d4a4f94;letter-spacing:.06em;justify-content:center;align-items:center;width:100%;height:100%;font-size:13px;display:flex}.cos-photo-postcard__hint{color:#3d4a4f6b;letter-spacing:.12em;text-transform:uppercase;pointer-events:none;white-space:nowrap;font-size:10px;position:absolute;bottom:12px;left:50%;transform:translate(-50%)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/components/photoPostcard/element';
|