@cos-design/photo-postcard 4.0.0 → 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/packages/shared/src/element-options.d.ts +19 -0
- package/dist/core/packages/shared/src/index.d.ts +2 -0
- package/dist/element/index.js +94 -129
- package/dist/element/packages/shared/src/element-options.d.ts +19 -0
- package/dist/element/packages/shared/src/index.d.ts +2 -0
- package/dist/react/packages/shared/src/element-options.d.ts +19 -0
- package/dist/react/packages/shared/src/index.d.ts +2 -0
- package/dist/vue/index.js +71 -71
- package/dist/vue/packages/shared/src/element-options.d.ts +19 -0
- package/dist/vue/packages/shared/src/index.d.ts +2 -0
- package/package.json +3 -3
|
@@ -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;
|
|
@@ -9,3 +9,5 @@ export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from
|
|
|
9
9
|
export { resolveCanvasBoxSize } from './canvas-box';
|
|
10
10
|
export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
|
|
11
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';
|
package/dist/element/index.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { applyBlockHostBox as e } from "@cos-design/shared";
|
|
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
2
|
import './element.css';//#region src/components/photoPostcard/core/engine.ts
|
|
3
|
-
var
|
|
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
4
|
let t = Math.sin(e * 127.1 + 31.7) * 43758.5453;
|
|
5
5
|
return t - Math.floor(t);
|
|
6
|
-
},
|
|
6
|
+
}, m = (e, t) => {
|
|
7
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
|
-
},
|
|
9
|
-
let
|
|
8
|
+
}, h = (e, t, n) => {
|
|
9
|
+
let r = n && (t.title || t.description), i = t.title ? t.title : "Greetings from the road";
|
|
10
10
|
e.replaceChildren();
|
|
11
|
+
let a = document.createElement("div");
|
|
12
|
+
a.className = `${s}__face ${s}__front`;
|
|
11
13
|
let o = document.createElement("div");
|
|
12
|
-
o.className = `${
|
|
13
|
-
let s = document.createElement("div");
|
|
14
|
-
s.className = `${t}__photo-frame${i ? ` ${t}__photo-frame-with-caption` : ""}`;
|
|
14
|
+
o.className = `${s}__photo-frame${r ? ` ${s}__photo-frame-with-caption` : ""}`;
|
|
15
15
|
let c = document.createElement("div");
|
|
16
|
-
c.className = `${
|
|
16
|
+
c.className = `${s}__photo-wrap`;
|
|
17
17
|
let l = document.createElement("img");
|
|
18
|
-
l.className = `${
|
|
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
19
|
let u = document.createElement("div");
|
|
20
|
-
if (u.className = `${
|
|
20
|
+
if (u.className = `${s}__corner-stamp`, u.setAttribute("aria-hidden", "true"), a.append(o, u), r) {
|
|
21
21
|
let e = document.createElement("div");
|
|
22
|
-
if (e.className = `${
|
|
23
|
-
let
|
|
24
|
-
|
|
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
25
|
}
|
|
26
|
-
if (
|
|
27
|
-
let
|
|
28
|
-
|
|
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
29
|
}
|
|
30
|
-
|
|
30
|
+
a.appendChild(e);
|
|
31
31
|
}
|
|
32
32
|
let d = document.createElement("div");
|
|
33
|
-
d.className = `${
|
|
33
|
+
d.className = `${s}__face ${s}__back`;
|
|
34
34
|
let f = document.createElement("div");
|
|
35
|
-
f.className = `${
|
|
35
|
+
f.className = `${s}__divider`, f.setAttribute("aria-hidden", "true");
|
|
36
36
|
let p = document.createElement("div");
|
|
37
|
-
p.className = `${
|
|
37
|
+
p.className = `${s}__lined-paper`;
|
|
38
38
|
let m = document.createElement("p");
|
|
39
|
-
m.className = `${
|
|
39
|
+
m.className = `${s}__greeting`, m.textContent = i, p.appendChild(m);
|
|
40
40
|
let h = document.createElement("p");
|
|
41
|
-
|
|
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
42
|
let g = document.createElement("div");
|
|
43
|
-
g.className = `${
|
|
43
|
+
g.className = `${s}__back-footer`;
|
|
44
44
|
let _ = document.createElement("div");
|
|
45
|
-
_.className = `${
|
|
45
|
+
_.className = `${s}__postmark`, _.setAttribute("aria-hidden", "true");
|
|
46
46
|
let v = document.createElement("span");
|
|
47
|
-
v.className = `${
|
|
47
|
+
v.className = `${s}__postmark-text`, v.innerHTML = "TRAVEL<br>POST", _.appendChild(v);
|
|
48
48
|
let y = document.createElement("div");
|
|
49
|
-
y.className = `${
|
|
49
|
+
y.className = `${s}__stamp-square`, y.setAttribute("aria-hidden", "true"), g.append(_, y), d.append(f, p, g), e.append(a, d);
|
|
50
50
|
};
|
|
51
|
-
function
|
|
52
|
-
let
|
|
51
|
+
function g(t, n = { photos: [] }) {
|
|
52
|
+
let r = {
|
|
53
53
|
width: 360,
|
|
54
54
|
height: 420,
|
|
55
55
|
cardWidth: 260,
|
|
@@ -59,76 +59,76 @@ function u(u, d = { photos: [] }) {
|
|
|
59
59
|
initialIndex: 0,
|
|
60
60
|
initialFlipped: !1,
|
|
61
61
|
ariaLabel: "明信片",
|
|
62
|
-
...
|
|
63
|
-
photos: Array.isArray(
|
|
64
|
-
},
|
|
65
|
-
C.className = `${
|
|
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
66
|
let w = document.createElement("div");
|
|
67
|
-
w.className = `${
|
|
67
|
+
w.className = `${s}__empty`, w.textContent = "暂无明信片";
|
|
68
68
|
let T = document.createElement("div");
|
|
69
|
-
T.className = `${
|
|
69
|
+
T.className = `${s}__stack`;
|
|
70
70
|
let E = document.createElement("div");
|
|
71
|
-
E.className = `${
|
|
71
|
+
E.className = `${s}__card-slot`;
|
|
72
72
|
let D = document.createElement("div"), O = document.createElement("div");
|
|
73
|
-
O.className = `${
|
|
73
|
+
O.className = `${s}__flip-inner`, D.appendChild(O), E.appendChild(D);
|
|
74
74
|
let k = document.createElement("div");
|
|
75
|
-
k.className = `${
|
|
76
|
-
let A = () => Array.isArray(
|
|
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
77
|
D.className = [
|
|
78
|
-
`${
|
|
79
|
-
|
|
80
|
-
_ === "exiting" ? `${
|
|
81
|
-
].filter(Boolean).join(" "), D.style.transform = `translateX(${g}px)`, D.style.transition = _ === "snapping" || _ === "exiting" ? `transform ${_ === "exiting" ?
|
|
82
|
-
let e = A()[
|
|
83
|
-
D.setAttribute("aria-label", e ? `${
|
|
84
|
-
}, P = (e,
|
|
85
|
-
let
|
|
86
|
-
for (let e of [...T.children])
|
|
87
|
-
let
|
|
88
|
-
let t =
|
|
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
89
|
return {
|
|
90
90
|
depth: e,
|
|
91
|
-
rot: (
|
|
92
|
-
dx: e * 5 +
|
|
93
|
-
dy: e * 3 +
|
|
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
94
|
};
|
|
95
95
|
});
|
|
96
|
-
for (let { depth: e, rot:
|
|
97
|
-
let
|
|
98
|
-
|
|
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
99
|
}
|
|
100
100
|
}, F = () => {
|
|
101
|
-
let n = A(),
|
|
102
|
-
if (S.className = [
|
|
103
|
-
width:
|
|
104
|
-
height:
|
|
105
|
-
}),
|
|
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
106
|
O.replaceChildren(), x = "";
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
|
-
T.style.width = `${
|
|
110
|
-
let
|
|
111
|
-
|
|
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
112
|
}, I = (e) => {
|
|
113
|
-
let t = A(), n =
|
|
114
|
-
|
|
115
|
-
let
|
|
116
|
-
|
|
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
117
|
}, L = (e) => {
|
|
118
118
|
I(e), g = 0, _ = "idle", F();
|
|
119
119
|
}, R = (e) => {
|
|
120
|
-
let t = e * ((
|
|
120
|
+
let t = e * ((r.cardWidth ?? 260) * .55 + 48);
|
|
121
121
|
_ = "exiting", g = t, N(), y != null && window.clearTimeout(y), y = window.setTimeout(() => {
|
|
122
|
-
L(a
|
|
123
|
-
},
|
|
122
|
+
L(d(a + e, A().length));
|
|
123
|
+
}, l);
|
|
124
124
|
}, z = () => {
|
|
125
125
|
_ = "snapping", g = 0, N(), b != null && window.clearTimeout(b), b = window.setTimeout(() => {
|
|
126
126
|
_ = "idle", N();
|
|
127
|
-
},
|
|
127
|
+
}, u);
|
|
128
128
|
}, B = (e) => {
|
|
129
129
|
A().length <= 1 || R(e > 0 ? 1 : -1);
|
|
130
130
|
}, V = () => {
|
|
131
|
-
|
|
131
|
+
o = !o, r.onFlipChange?.(o), N();
|
|
132
132
|
}, H = (e) => {
|
|
133
133
|
_ === "exiting" || j() === 0 || (v = {
|
|
134
134
|
pointerId: e.pointerId,
|
|
@@ -138,20 +138,20 @@ function u(u, d = { photos: [] }) {
|
|
|
138
138
|
}, U = (e) => {
|
|
139
139
|
if (!v || v.pointerId !== e.pointerId || _ === "exiting") return;
|
|
140
140
|
let t = e.clientX - v.startX;
|
|
141
|
-
Math.abs(t) >
|
|
141
|
+
Math.abs(t) > c && (v.moved = !0), g = j() <= 1 ? t * .22 : t, N();
|
|
142
142
|
}, W = (e) => {
|
|
143
143
|
if (!v || v.pointerId !== e.pointerId) return;
|
|
144
144
|
let t = v.startX, n = v.moved;
|
|
145
145
|
if (v = null, D.hasPointerCapture(e.pointerId) && D.releasePointerCapture(e.pointerId), _ === "exiting") return;
|
|
146
|
-
let
|
|
146
|
+
let i = e.clientX - t;
|
|
147
147
|
if (!n) {
|
|
148
148
|
_ = "idle", g = 0, V();
|
|
149
|
-
let e = A()[
|
|
150
|
-
e &&
|
|
149
|
+
let e = A()[a];
|
|
150
|
+
e && r.onPhotoClick?.(a, e);
|
|
151
151
|
return;
|
|
152
152
|
}
|
|
153
|
-
if (Math.abs(
|
|
154
|
-
R(
|
|
153
|
+
if (Math.abs(i) >= (r.pullThreshold ?? 80) && j() > 1) {
|
|
154
|
+
R(i > 0 ? 1 : -1);
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
157
|
z();
|
|
@@ -162,68 +162,33 @@ function u(u, d = { photos: [] }) {
|
|
|
162
162
|
};
|
|
163
163
|
return D.addEventListener("pointerdown", H), D.addEventListener("pointermove", U), D.addEventListener("pointerup", W), D.addEventListener("pointercancel", G), S.addEventListener("keydown", K), F(), {
|
|
164
164
|
update(e) {
|
|
165
|
-
let t = Array.isArray(e.photos) ? e.photos : e.photos === void 0 ?
|
|
166
|
-
|
|
167
|
-
...
|
|
165
|
+
let t = Array.isArray(e.photos) ? e.photos : e.photos === void 0 ? r.photos : [];
|
|
166
|
+
r = {
|
|
167
|
+
...r,
|
|
168
168
|
...e,
|
|
169
169
|
photos: t
|
|
170
|
-
},
|
|
170
|
+
}, a = f(a, A().length), F();
|
|
171
171
|
},
|
|
172
172
|
destroy() {
|
|
173
|
-
|
|
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
174
|
}
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
177
|
//#endregion
|
|
178
178
|
//#region src/components/photoPostcard/element/index.ts
|
|
179
|
-
var
|
|
180
|
-
function
|
|
181
|
-
let
|
|
182
|
-
|
|
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;
|
|
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;
|
|
218
183
|
}
|
|
219
|
-
var
|
|
184
|
+
var y = class extends HTMLElement {
|
|
220
185
|
ctrl = null;
|
|
221
186
|
_photos;
|
|
222
187
|
get photos() {
|
|
223
188
|
return this._photos;
|
|
224
189
|
}
|
|
225
190
|
set photos(e) {
|
|
226
|
-
this._photos = e, this.ctrl?.update(
|
|
191
|
+
this._photos = e, this.ctrl?.update(v(this));
|
|
227
192
|
}
|
|
228
193
|
static get observedAttributes() {
|
|
229
194
|
return [
|
|
@@ -240,15 +205,15 @@ var p = class extends HTMLElement {
|
|
|
240
205
|
];
|
|
241
206
|
}
|
|
242
207
|
connectedCallback() {
|
|
243
|
-
this.ctrl =
|
|
208
|
+
this.ctrl = g(this, v(this));
|
|
244
209
|
}
|
|
245
210
|
disconnectedCallback() {
|
|
246
211
|
this.ctrl?.destroy(), this.ctrl = null;
|
|
247
212
|
}
|
|
248
213
|
attributeChangedCallback() {
|
|
249
|
-
this.ctrl?.update(
|
|
214
|
+
this.ctrl?.update(v(this));
|
|
250
215
|
}
|
|
251
216
|
};
|
|
252
|
-
typeof customElements < "u" && !customElements.get("cos-photo-postcard") && customElements.define(
|
|
217
|
+
typeof customElements < "u" && !customElements.get("cos-photo-postcard") && customElements.define(_, y);
|
|
253
218
|
//#endregion
|
|
254
|
-
export {
|
|
219
|
+
export { y as CosPhotoPostcardElement, _ as TAG };
|
|
@@ -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;
|
|
@@ -9,3 +9,5 @@ export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from
|
|
|
9
9
|
export { resolveCanvasBoxSize } from './canvas-box';
|
|
10
10
|
export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
|
|
11
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,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;
|
|
@@ -9,3 +9,5 @@ export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from
|
|
|
9
9
|
export { resolveCanvasBoxSize } from './canvas-box';
|
|
10
10
|
export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
|
|
11
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';
|
package/dist/vue/index.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
import { createElementBlock as e, defineComponent as t, onMounted as n, onUnmounted as r, openBlock as i, ref as a, watch as o } from "vue";
|
|
2
|
-
import { applyBlockHostBox as s
|
|
2
|
+
import { applyBlockHostBox as s } from "@cos-design/shared";
|
|
3
3
|
import './vue.css';//#region src/components/photoPostcard/core/engine.ts
|
|
4
|
-
var
|
|
4
|
+
var c = "cos-photo-postcard", l = 6, u = 280, d = 320, f = (e, t) => t <= 0 ? 0 : (e % t + t) % t, p = (e, t) => t <= 0 ? 0 : Math.max(0, Math.min(t - 1, Math.floor(e))), m = (e) => {
|
|
5
5
|
let t = Math.sin(e * 127.1 + 31.7) * 43758.5453;
|
|
6
6
|
return t - Math.floor(t);
|
|
7
|
-
},
|
|
7
|
+
}, h = (e, t) => {
|
|
8
8
|
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));
|
|
9
|
-
},
|
|
9
|
+
}, g = (e, t, n) => {
|
|
10
10
|
let r = n && (t.title || t.description), i = t.title ? t.title : "Greetings from the road";
|
|
11
11
|
e.replaceChildren();
|
|
12
12
|
let a = document.createElement("div");
|
|
13
|
-
a.className = `${
|
|
13
|
+
a.className = `${c}__face ${c}__front`;
|
|
14
14
|
let o = document.createElement("div");
|
|
15
|
-
o.className = `${
|
|
15
|
+
o.className = `${c}__photo-frame${r ? ` ${c}__photo-frame-with-caption` : ""}`;
|
|
16
16
|
let s = document.createElement("div");
|
|
17
|
-
s.className = `${
|
|
18
|
-
let
|
|
19
|
-
|
|
17
|
+
s.className = `${c}__photo-wrap`;
|
|
18
|
+
let l = document.createElement("img");
|
|
19
|
+
l.className = `${c}__photo`, l.src = t.src, l.alt = t.alt ?? t.title ?? "", l.draggable = !1, s.appendChild(l), o.appendChild(s);
|
|
20
20
|
let u = document.createElement("div");
|
|
21
|
-
if (u.className = `${
|
|
21
|
+
if (u.className = `${c}__corner-stamp`, u.setAttribute("aria-hidden", "true"), a.append(o, u), r) {
|
|
22
22
|
let e = document.createElement("div");
|
|
23
|
-
if (e.className = `${
|
|
23
|
+
if (e.className = `${c}__front-caption`, t.title) {
|
|
24
24
|
let n = document.createElement("p");
|
|
25
|
-
n.className = `${
|
|
25
|
+
n.className = `${c}__front-caption-title`, n.textContent = t.title, e.appendChild(n);
|
|
26
26
|
}
|
|
27
27
|
if (t.description) {
|
|
28
28
|
let n = document.createElement("p");
|
|
29
|
-
n.className = `${
|
|
29
|
+
n.className = `${c}__front-caption-desc`, n.textContent = t.description, e.appendChild(n);
|
|
30
30
|
}
|
|
31
31
|
a.appendChild(e);
|
|
32
32
|
}
|
|
33
33
|
let d = document.createElement("div");
|
|
34
|
-
d.className = `${
|
|
34
|
+
d.className = `${c}__face ${c}__back`;
|
|
35
35
|
let f = document.createElement("div");
|
|
36
|
-
f.className = `${
|
|
36
|
+
f.className = `${c}__divider`, f.setAttribute("aria-hidden", "true");
|
|
37
37
|
let p = document.createElement("div");
|
|
38
|
-
p.className = `${
|
|
38
|
+
p.className = `${c}__lined-paper`;
|
|
39
39
|
let m = document.createElement("p");
|
|
40
|
-
m.className = `${
|
|
40
|
+
m.className = `${c}__greeting`, m.textContent = i, p.appendChild(m);
|
|
41
41
|
let h = document.createElement("p");
|
|
42
|
-
t.description ? (h.className = `${
|
|
42
|
+
t.description ? (h.className = `${c}__body-text`, h.textContent = t.description) : (h.className = `${c}__body-placeholder`, h.textContent = "Wish you were here…"), p.appendChild(h);
|
|
43
43
|
let g = document.createElement("div");
|
|
44
|
-
g.className = `${
|
|
44
|
+
g.className = `${c}__back-footer`;
|
|
45
45
|
let _ = document.createElement("div");
|
|
46
|
-
_.className = `${
|
|
46
|
+
_.className = `${c}__postmark`, _.setAttribute("aria-hidden", "true");
|
|
47
47
|
let v = document.createElement("span");
|
|
48
|
-
v.className = `${
|
|
48
|
+
v.className = `${c}__postmark-text`, v.innerHTML = "TRAVEL<br>POST", _.appendChild(v);
|
|
49
49
|
let y = document.createElement("div");
|
|
50
|
-
y.className = `${
|
|
50
|
+
y.className = `${c}__stamp-square`, y.setAttribute("aria-hidden", "true"), g.append(_, y), d.append(f, p, g), e.append(a, d);
|
|
51
51
|
};
|
|
52
|
-
function
|
|
52
|
+
function _(e, t = { photos: [] }) {
|
|
53
53
|
let n = {
|
|
54
54
|
width: 360,
|
|
55
55
|
height: 420,
|
|
@@ -62,24 +62,24 @@ function v(e, t = { photos: [] }) {
|
|
|
62
62
|
ariaLabel: "明信片",
|
|
63
63
|
...t,
|
|
64
64
|
photos: Array.isArray(t.photos) ? t.photos : []
|
|
65
|
-
}, r = !1, i =
|
|
66
|
-
C.className = `${
|
|
65
|
+
}, r = !1, i = p(n.initialIndex ?? 0, n.photos.length), a = !!n.initialFlipped, o = 0, _ = "idle", v = null, y = null, b = null, x = "", S = document.createElement("div"), C = document.createElement("div");
|
|
66
|
+
C.className = `${c}__stage`;
|
|
67
67
|
let w = document.createElement("div");
|
|
68
|
-
w.className = `${
|
|
68
|
+
w.className = `${c}__empty`, w.textContent = "暂无明信片";
|
|
69
69
|
let T = document.createElement("div");
|
|
70
|
-
T.className = `${
|
|
70
|
+
T.className = `${c}__stack`;
|
|
71
71
|
let E = document.createElement("div");
|
|
72
|
-
E.className = `${
|
|
72
|
+
E.className = `${c}__card-slot`;
|
|
73
73
|
let D = document.createElement("div"), O = document.createElement("div");
|
|
74
|
-
O.className = `${
|
|
74
|
+
O.className = `${c}__flip-inner`, D.appendChild(O), E.appendChild(D);
|
|
75
75
|
let k = document.createElement("div");
|
|
76
|
-
k.className = `${
|
|
76
|
+
k.className = `${c}__hint`, k.textContent = "拖拽切换 · 点击查看背面", C.append(w, T, k), S.appendChild(C), e.appendChild(S);
|
|
77
77
|
let A = () => Array.isArray(n.photos) ? n.photos : [], j = () => A().length, M = (e, t) => e ? `${e.src}\0${e.title ?? ""}\0${e.description ?? ""}\0${e.alt ?? ""}\0${t}` : "", N = () => {
|
|
78
78
|
D.className = [
|
|
79
|
-
`${
|
|
80
|
-
a ? `${
|
|
81
|
-
|
|
82
|
-
].filter(Boolean).join(" "), D.style.transform = `translateX(${o}px)`, D.style.transition =
|
|
79
|
+
`${c}__card-active`,
|
|
80
|
+
a ? `${c}__flipped` : "",
|
|
81
|
+
_ === "exiting" ? `${c}__card-exiting` : ""
|
|
82
|
+
].filter(Boolean).join(" "), D.style.transform = `translateX(${o}px)`, D.style.transition = _ === "snapping" || _ === "exiting" ? `transform ${_ === "exiting" ? u : d}ms cubic-bezier(0.22, 1, 0.36, 1), opacity ${u}ms ease` : "none", D.style.opacity = _ === "exiting" ? "0.55" : "1", D.setAttribute("aria-pressed", String(a));
|
|
83
83
|
let e = A()[i];
|
|
84
84
|
D.setAttribute("aria-label", e ? `${a ? "背面" : "正面"}:${e.alt ?? e.title ?? `明信片 ${i + 1}`}` : "");
|
|
85
85
|
}, P = (e, t, n) => {
|
|
@@ -89,64 +89,64 @@ function v(e, t = { photos: [] }) {
|
|
|
89
89
|
let t = i * 13.7 + e * 5.3;
|
|
90
90
|
return {
|
|
91
91
|
depth: e,
|
|
92
|
-
rot: (
|
|
93
|
-
dx: e * 5 +
|
|
94
|
-
dy: e * 3 +
|
|
92
|
+
rot: (m(t) * 2 - 1) * 5.5,
|
|
93
|
+
dx: e * 5 + m(t + 1.1) * 4,
|
|
94
|
+
dy: e * 3 + m(t + 2.4) * 3
|
|
95
95
|
};
|
|
96
96
|
});
|
|
97
97
|
for (let { depth: e, rot: r, dx: i, dy: o } of a) {
|
|
98
98
|
let a = document.createElement("div");
|
|
99
|
-
a.className = `${
|
|
99
|
+
a.className = `${c}__stack-card`, a.style.width = `${t}px`, a.style.height = `${n}px`, a.style.transform = `translate(calc(-50% + ${i}px), calc(-50% + ${o}px)) rotate(${r}deg)`, a.style.opacity = e === 1 ? "0.92" : "0.78", a.setAttribute("aria-hidden", "true"), T.insertBefore(a, E);
|
|
100
100
|
}
|
|
101
101
|
}, F = () => {
|
|
102
|
-
let t = A(), r = t.length, a = n.cardWidth ?? 260, o = n.cardHeight ?? 170,
|
|
103
|
-
if (S.className = [
|
|
102
|
+
let t = A(), r = t.length, a = n.cardWidth ?? 260, o = n.cardHeight ?? 170, l = n.showCaption !== !1;
|
|
103
|
+
if (S.className = [c, n.className].filter(Boolean).join(" "), s(e, S, {
|
|
104
104
|
width: n.width ?? 360,
|
|
105
105
|
height: n.height ?? 420
|
|
106
|
-
}),
|
|
106
|
+
}), h(S, n.style), S.setAttribute("role", "region"), S.setAttribute("aria-label", n.ariaLabel ?? "明信片"), S.tabIndex = 0, w.hidden = r > 0, T.hidden = r === 0, k.hidden = r <= 1, r === 0) {
|
|
107
107
|
O.replaceChildren(), x = "";
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
110
|
T.style.width = `${a}px`, T.style.height = `${o}px`, (!E.isConnected || E.parentElement !== T) && T.appendChild(E), P(r, a, o), E.style.width = `${a}px`, E.style.height = `${o}px`, D.style.width = `${a}px`, D.style.height = `${o}px`, D.setAttribute("role", "button");
|
|
111
|
-
let u = t[i], d = M(u,
|
|
112
|
-
u && d !== x ? (
|
|
111
|
+
let u = t[i], d = M(u, l);
|
|
112
|
+
u && d !== x ? (g(O, u, l), x = d) : u || (O.replaceChildren(), x = ""), N();
|
|
113
113
|
}, I = (e) => {
|
|
114
|
-
let t = A(), r =
|
|
114
|
+
let t = A(), r = p(e, t.length);
|
|
115
115
|
i = r, a = !1, n.onFlipChange?.(!1);
|
|
116
116
|
let o = t[r];
|
|
117
117
|
o && n.onIndexChange?.(r, o);
|
|
118
118
|
}, L = (e) => {
|
|
119
|
-
I(e), o = 0,
|
|
119
|
+
I(e), o = 0, _ = "idle", F();
|
|
120
120
|
}, R = (e) => {
|
|
121
121
|
let t = e * ((n.cardWidth ?? 260) * .55 + 48);
|
|
122
|
-
|
|
123
|
-
L(
|
|
124
|
-
},
|
|
122
|
+
_ = "exiting", o = t, N(), y != null && window.clearTimeout(y), y = window.setTimeout(() => {
|
|
123
|
+
L(f(i + e, A().length));
|
|
124
|
+
}, u);
|
|
125
125
|
}, z = () => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
},
|
|
126
|
+
_ = "snapping", o = 0, N(), b != null && window.clearTimeout(b), b = window.setTimeout(() => {
|
|
127
|
+
_ = "idle", N();
|
|
128
|
+
}, d);
|
|
129
129
|
}, B = (e) => {
|
|
130
130
|
A().length <= 1 || R(e > 0 ? 1 : -1);
|
|
131
131
|
}, V = () => {
|
|
132
132
|
a = !a, n.onFlipChange?.(a), N();
|
|
133
133
|
}, H = (e) => {
|
|
134
|
-
|
|
134
|
+
_ === "exiting" || j() === 0 || (v = {
|
|
135
135
|
pointerId: e.pointerId,
|
|
136
136
|
startX: e.clientX,
|
|
137
137
|
moved: !1
|
|
138
|
-
},
|
|
138
|
+
}, _ = "dragging", D.setPointerCapture(e.pointerId));
|
|
139
139
|
}, U = (e) => {
|
|
140
|
-
if (!v || v.pointerId !== e.pointerId ||
|
|
140
|
+
if (!v || v.pointerId !== e.pointerId || _ === "exiting") return;
|
|
141
141
|
let t = e.clientX - v.startX;
|
|
142
|
-
Math.abs(t) >
|
|
142
|
+
Math.abs(t) > l && (v.moved = !0), o = j() <= 1 ? t * .22 : t, N();
|
|
143
143
|
}, W = (e) => {
|
|
144
144
|
if (!v || v.pointerId !== e.pointerId) return;
|
|
145
145
|
let t = v.startX, r = v.moved;
|
|
146
|
-
if (v = null, D.hasPointerCapture(e.pointerId) && D.releasePointerCapture(e.pointerId),
|
|
146
|
+
if (v = null, D.hasPointerCapture(e.pointerId) && D.releasePointerCapture(e.pointerId), _ === "exiting") return;
|
|
147
147
|
let a = e.clientX - t;
|
|
148
148
|
if (!r) {
|
|
149
|
-
|
|
149
|
+
_ = "idle", o = 0, V();
|
|
150
150
|
let e = A()[i];
|
|
151
151
|
e && n.onPhotoClick?.(i, e);
|
|
152
152
|
return;
|
|
@@ -157,7 +157,7 @@ function v(e, t = { photos: [] }) {
|
|
|
157
157
|
}
|
|
158
158
|
z();
|
|
159
159
|
}, G = (e) => {
|
|
160
|
-
!v || v.pointerId !== e.pointerId || (v = null, D.hasPointerCapture(e.pointerId) && D.releasePointerCapture(e.pointerId),
|
|
160
|
+
!v || v.pointerId !== e.pointerId || (v = null, D.hasPointerCapture(e.pointerId) && D.releasePointerCapture(e.pointerId), _ !== "exiting" && z());
|
|
161
161
|
}, K = (e) => {
|
|
162
162
|
e.key === "ArrowRight" ? (e.preventDefault(), B(1)) : e.key === "ArrowLeft" ? (e.preventDefault(), B(-1)) : (e.key === " " || e.key === "Enter") && (e.preventDefault(), V());
|
|
163
163
|
};
|
|
@@ -168,7 +168,7 @@ function v(e, t = { photos: [] }) {
|
|
|
168
168
|
...n,
|
|
169
169
|
...e,
|
|
170
170
|
photos: t
|
|
171
|
-
}, i =
|
|
171
|
+
}, i = p(i, A().length), F();
|
|
172
172
|
},
|
|
173
173
|
destroy() {
|
|
174
174
|
r || (r = !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());
|
|
@@ -177,7 +177,7 @@ function v(e, t = { photos: [] }) {
|
|
|
177
177
|
}
|
|
178
178
|
//#endregion
|
|
179
179
|
//#region src/components/photoPostcard/vue/PhotoPostcard.vue
|
|
180
|
-
var
|
|
180
|
+
var v = /* @__PURE__ */ t({
|
|
181
181
|
__name: "PhotoPostcard",
|
|
182
182
|
props: {
|
|
183
183
|
photos: {},
|
|
@@ -204,23 +204,23 @@ var y = /* @__PURE__ */ t({
|
|
|
204
204
|
"index-change",
|
|
205
205
|
"flip-change"
|
|
206
206
|
],
|
|
207
|
-
setup(t, { expose: s, emit:
|
|
208
|
-
let
|
|
209
|
-
...
|
|
210
|
-
onPhotoClick: (...e) =>
|
|
211
|
-
onIndexChange: (...e) =>
|
|
212
|
-
onFlipChange: (...e) =>
|
|
207
|
+
setup(t, { expose: s, emit: c }) {
|
|
208
|
+
let l = t, u = c, d = a(), f = null, p = () => ({
|
|
209
|
+
...l,
|
|
210
|
+
onPhotoClick: (...e) => u("photo-click", ...e),
|
|
211
|
+
onIndexChange: (...e) => u("index-change", ...e),
|
|
212
|
+
onFlipChange: (...e) => u("flip-change", ...e)
|
|
213
213
|
});
|
|
214
214
|
return n(() => {
|
|
215
|
-
|
|
216
|
-
}), o(() =>
|
|
217
|
-
|
|
215
|
+
d.value && (f = _(d.value, p()));
|
|
216
|
+
}), o(() => ({ ...l }), () => f?.update(p()), { deep: !0 }), r(() => {
|
|
217
|
+
f?.destroy(), f = null;
|
|
218
218
|
}), s({}), (t, n) => (i(), e("div", {
|
|
219
219
|
ref_key: "hostRef",
|
|
220
|
-
ref:
|
|
220
|
+
ref: d,
|
|
221
221
|
class: "cos-photoPostcard-host"
|
|
222
222
|
}, null, 512));
|
|
223
223
|
}
|
|
224
224
|
});
|
|
225
225
|
//#endregion
|
|
226
|
-
export {
|
|
226
|
+
export { v as PhotoPostcard };
|
|
@@ -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;
|
|
@@ -9,3 +9,5 @@ export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from
|
|
|
9
9
|
export { resolveCanvasBoxSize } from './canvas-box';
|
|
10
10
|
export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
|
|
11
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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cos-design/photo-postcard",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "PhotoPostcard component from cos-design",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/react/index.cjs",
|
|
@@ -84,6 +84,6 @@
|
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@cos-design/shared": "4.
|
|
87
|
+
"@cos-design/shared": "4.1.0"
|
|
88
88
|
}
|
|
89
|
-
}
|
|
89
|
+
}
|