@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.
@@ -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';
@@ -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 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) => {
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
- }, c = (e, t) => {
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
- }, l = (e, n, r) => {
9
- let i = r && (n.title || n.description), a = n.title ? n.title : "Greetings from the road";
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 = `${t}__face ${t}__front`;
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 = `${t}__photo-wrap`;
16
+ c.className = `${s}__photo-wrap`;
17
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);
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 = `${t}__corner-stamp`, u.setAttribute("aria-hidden", "true"), o.append(s, u), i) {
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 = `${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);
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 (n.description) {
27
- let r = document.createElement("p");
28
- r.className = `${t}__front-caption-desc`, r.textContent = n.description, e.appendChild(r);
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
- o.appendChild(e);
30
+ a.appendChild(e);
31
31
  }
32
32
  let d = document.createElement("div");
33
- d.className = `${t}__face ${t}__back`;
33
+ d.className = `${s}__face ${s}__back`;
34
34
  let f = document.createElement("div");
35
- f.className = `${t}__divider`, f.setAttribute("aria-hidden", "true");
35
+ f.className = `${s}__divider`, f.setAttribute("aria-hidden", "true");
36
36
  let p = document.createElement("div");
37
- p.className = `${t}__lined-paper`;
37
+ p.className = `${s}__lined-paper`;
38
38
  let m = document.createElement("p");
39
- m.className = `${t}__greeting`, m.textContent = a, p.appendChild(m);
39
+ m.className = `${s}__greeting`, m.textContent = i, p.appendChild(m);
40
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);
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 = `${t}__back-footer`;
43
+ g.className = `${s}__back-footer`;
44
44
  let _ = document.createElement("div");
45
- _.className = `${t}__postmark`, _.setAttribute("aria-hidden", "true");
45
+ _.className = `${s}__postmark`, _.setAttribute("aria-hidden", "true");
46
46
  let v = document.createElement("span");
47
- v.className = `${t}__postmark-text`, v.innerHTML = "TRAVEL<br>POST", _.appendChild(v);
47
+ v.className = `${s}__postmark-text`, v.innerHTML = "TRAVEL<br>POST", _.appendChild(v);
48
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);
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 u(u, d = { photos: [] }) {
52
- let f = {
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
- ...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`;
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 = `${t}__empty`, w.textContent = "暂无明信片";
67
+ w.className = `${s}__empty`, w.textContent = "暂无明信片";
68
68
  let T = document.createElement("div");
69
- T.className = `${t}__stack`;
69
+ T.className = `${s}__stack`;
70
70
  let E = document.createElement("div");
71
- E.className = `${t}__card-slot`;
71
+ E.className = `${s}__card-slot`;
72
72
  let D = document.createElement("div"), O = document.createElement("div");
73
- O.className = `${t}__flip-inner`, D.appendChild(O), E.appendChild(D);
73
+ O.className = `${s}__flip-inner`, D.appendChild(O), E.appendChild(D);
74
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 = () => {
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
- `${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;
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: (s(t) * 2 - 1) * 5.5,
92
- dx: e * 5 + s(t + 1.1) * 4,
93
- dy: e * 3 + s(t + 2.4) * 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: 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);
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(), 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) {
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 = `${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();
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 = o(e, t.length);
114
- m = n, h = !1, f.onFlipChange?.(!1);
115
- let r = t[n];
116
- r && f.onIndexChange?.(n, r);
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 * ((f.cardWidth ?? 260) * .55 + 48);
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(m + e, A().length));
123
- }, r);
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
- }, i);
127
+ }, u);
128
128
  }, B = (e) => {
129
129
  A().length <= 1 || R(e > 0 ? 1 : -1);
130
130
  }, V = () => {
131
- h = !h, f.onFlipChange?.(h), N();
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) > n && (v.moved = !0), g = j() <= 1 ? t * .22 : t, N();
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 r = e.clientX - t;
146
+ let i = e.clientX - t;
147
147
  if (!n) {
148
148
  _ = "idle", g = 0, V();
149
- let e = A()[m];
150
- e && f.onPhotoClick?.(m, e);
149
+ let e = A()[a];
150
+ e && r.onPhotoClick?.(a, e);
151
151
  return;
152
152
  }
153
- if (Math.abs(r) >= (f.pullThreshold ?? 80) && j() > 1) {
154
- R(r > 0 ? 1 : -1);
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 ? f.photos : [];
166
- f = {
167
- ...f,
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
- }, m = o(m, A().length), F();
170
+ }, a = f(a, A().length), F();
171
171
  },
172
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());
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 d = "cos-photo-postcard";
180
- function f(e) {
181
- let t = {};
182
- if (e.hasAttribute("width")) {
183
- let n = e.getAttribute("width"), r = Number(n);
184
- t.width = n != null && n !== "" && !Number.isNaN(r) ? r : n ?? void 0;
185
- }
186
- if (e.hasAttribute("height")) {
187
- let n = e.getAttribute("height"), r = Number(n);
188
- t.height = n != null && n !== "" && !Number.isNaN(r) ? r : n ?? void 0;
189
- }
190
- if (e.hasAttribute("aria-label") && (t.ariaLabel = e.getAttribute("aria-label") ?? void 0), e.hasAttribute("card-width") && (t.cardWidth = Number(e.getAttribute("card-width"))), e.hasAttribute("card-height") && (t.cardHeight = Number(e.getAttribute("card-height"))), e.hasAttribute("pull-threshold") && (t.pullThreshold = Number(e.getAttribute("pull-threshold"))), e.hasAttribute("initial-index") && (t.initialIndex = Number(e.getAttribute("initial-index"))), e.hasAttribute("show-caption")) {
191
- let n = e.getAttribute("show-caption");
192
- t.showCaption = n !== "false" && n !== "0";
193
- }
194
- if (e.hasAttribute("initial-flipped")) {
195
- let n = e.getAttribute("initial-flipped");
196
- t.initialFlipped = n !== "false" && n !== "0";
197
- }
198
- if (e.hasAttribute("photos")) try {
199
- t.photos = JSON.parse(e.getAttribute("photos") ?? "null");
200
- } catch {}
201
- let n = e._photos;
202
- return n !== void 0 && (t.photos = n), t.onPhotoClick = (...t) => {
203
- e.dispatchEvent(new CustomEvent("photo-click", {
204
- detail: t.length <= 1 ? t[0] : t,
205
- bubbles: !0
206
- }));
207
- }, t.onIndexChange = (...t) => {
208
- e.dispatchEvent(new CustomEvent("index-change", {
209
- detail: t.length <= 1 ? t[0] : t,
210
- bubbles: !0
211
- }));
212
- }, t.onFlipChange = (...t) => {
213
- e.dispatchEvent(new CustomEvent("flip-change", {
214
- detail: t.length <= 1 ? t[0] : t,
215
- bubbles: !0
216
- }));
217
- }, t;
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 p = class extends HTMLElement {
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(f(this));
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 = u(this, f(this));
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(f(this));
214
+ this.ctrl?.update(v(this));
250
215
  }
251
216
  };
252
- typeof customElements < "u" && !customElements.get("cos-photo-postcard") && customElements.define(d, p);
217
+ typeof customElements < "u" && !customElements.get("cos-photo-postcard") && customElements.define(_, y);
253
218
  //#endregion
254
- export { p as CosPhotoPostcardElement, d as TAG };
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, optionsFingerprint as c } from "@cos-design/shared";
2
+ import { applyBlockHostBox as s } from "@cos-design/shared";
3
3
  import './vue.css';//#region src/components/photoPostcard/core/engine.ts
4
- var l = "cos-photo-postcard", u = 6, d = 280, f = 320, p = (e, t) => t <= 0 ? 0 : (e % t + t) % t, m = (e, t) => t <= 0 ? 0 : Math.max(0, Math.min(t - 1, Math.floor(e))), h = (e) => {
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
- }, g = (e, t) => {
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
- }, _ = (e, t, n) => {
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 = `${l}__face ${l}__front`;
13
+ a.className = `${c}__face ${c}__front`;
14
14
  let o = document.createElement("div");
15
- o.className = `${l}__photo-frame${r ? ` ${l}__photo-frame-with-caption` : ""}`;
15
+ o.className = `${c}__photo-frame${r ? ` ${c}__photo-frame-with-caption` : ""}`;
16
16
  let s = document.createElement("div");
17
- s.className = `${l}__photo-wrap`;
18
- let c = document.createElement("img");
19
- c.className = `${l}__photo`, c.src = t.src, c.alt = t.alt ?? t.title ?? "", c.draggable = !1, s.appendChild(c), o.appendChild(s);
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 = `${l}__corner-stamp`, u.setAttribute("aria-hidden", "true"), a.append(o, u), r) {
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 = `${l}__front-caption`, t.title) {
23
+ if (e.className = `${c}__front-caption`, t.title) {
24
24
  let n = document.createElement("p");
25
- n.className = `${l}__front-caption-title`, n.textContent = t.title, e.appendChild(n);
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 = `${l}__front-caption-desc`, n.textContent = t.description, e.appendChild(n);
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 = `${l}__face ${l}__back`;
34
+ d.className = `${c}__face ${c}__back`;
35
35
  let f = document.createElement("div");
36
- f.className = `${l}__divider`, f.setAttribute("aria-hidden", "true");
36
+ f.className = `${c}__divider`, f.setAttribute("aria-hidden", "true");
37
37
  let p = document.createElement("div");
38
- p.className = `${l}__lined-paper`;
38
+ p.className = `${c}__lined-paper`;
39
39
  let m = document.createElement("p");
40
- m.className = `${l}__greeting`, m.textContent = i, p.appendChild(m);
40
+ m.className = `${c}__greeting`, m.textContent = i, p.appendChild(m);
41
41
  let h = document.createElement("p");
42
- t.description ? (h.className = `${l}__body-text`, h.textContent = t.description) : (h.className = `${l}__body-placeholder`, h.textContent = "Wish you were here…"), p.appendChild(h);
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 = `${l}__back-footer`;
44
+ g.className = `${c}__back-footer`;
45
45
  let _ = document.createElement("div");
46
- _.className = `${l}__postmark`, _.setAttribute("aria-hidden", "true");
46
+ _.className = `${c}__postmark`, _.setAttribute("aria-hidden", "true");
47
47
  let v = document.createElement("span");
48
- v.className = `${l}__postmark-text`, v.innerHTML = "TRAVEL<br>POST", _.appendChild(v);
48
+ v.className = `${c}__postmark-text`, v.innerHTML = "TRAVEL<br>POST", _.appendChild(v);
49
49
  let y = document.createElement("div");
50
- y.className = `${l}__stamp-square`, y.setAttribute("aria-hidden", "true"), g.append(_, y), d.append(f, p, g), e.append(a, d);
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 v(e, t = { photos: [] }) {
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 = m(n.initialIndex ?? 0, n.photos.length), a = !!n.initialFlipped, o = 0, c = "idle", v = null, y = null, b = null, x = "", S = document.createElement("div"), C = document.createElement("div");
66
- C.className = `${l}__stage`;
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 = `${l}__empty`, w.textContent = "暂无明信片";
68
+ w.className = `${c}__empty`, w.textContent = "暂无明信片";
69
69
  let T = document.createElement("div");
70
- T.className = `${l}__stack`;
70
+ T.className = `${c}__stack`;
71
71
  let E = document.createElement("div");
72
- E.className = `${l}__card-slot`;
72
+ E.className = `${c}__card-slot`;
73
73
  let D = document.createElement("div"), O = document.createElement("div");
74
- O.className = `${l}__flip-inner`, D.appendChild(O), E.appendChild(D);
74
+ O.className = `${c}__flip-inner`, D.appendChild(O), E.appendChild(D);
75
75
  let k = document.createElement("div");
76
- k.className = `${l}__hint`, k.textContent = "拖拽切换 · 点击查看背面", C.append(w, T, k), S.appendChild(C), e.appendChild(S);
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
- `${l}__card-active`,
80
- a ? `${l}__flipped` : "",
81
- c === "exiting" ? `${l}__card-exiting` : ""
82
- ].filter(Boolean).join(" "), D.style.transform = `translateX(${o}px)`, D.style.transition = c === "snapping" || c === "exiting" ? `transform ${c === "exiting" ? d : f}ms cubic-bezier(0.22, 1, 0.36, 1), opacity ${d}ms ease` : "none", D.style.opacity = c === "exiting" ? "0.55" : "1", D.setAttribute("aria-pressed", String(a));
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: (h(t) * 2 - 1) * 5.5,
93
- dx: e * 5 + h(t + 1.1) * 4,
94
- dy: e * 3 + h(t + 2.4) * 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 = `${l}__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);
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, c = n.showCaption !== !1;
103
- if (S.className = [l, n.className].filter(Boolean).join(" "), s(e, S, {
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
- }), g(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) {
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, c);
112
- u && d !== x ? (_(O, u, c), x = d) : u || (O.replaceChildren(), x = ""), N();
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 = m(e, t.length);
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, c = "idle", F();
119
+ I(e), o = 0, _ = "idle", F();
120
120
  }, R = (e) => {
121
121
  let t = e * ((n.cardWidth ?? 260) * .55 + 48);
122
- c = "exiting", o = t, N(), y != null && window.clearTimeout(y), y = window.setTimeout(() => {
123
- L(p(i + e, A().length));
124
- }, d);
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
- c = "snapping", o = 0, N(), b != null && window.clearTimeout(b), b = window.setTimeout(() => {
127
- c = "idle", N();
128
- }, f);
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
- c === "exiting" || j() === 0 || (v = {
134
+ _ === "exiting" || j() === 0 || (v = {
135
135
  pointerId: e.pointerId,
136
136
  startX: e.clientX,
137
137
  moved: !1
138
- }, c = "dragging", D.setPointerCapture(e.pointerId));
138
+ }, _ = "dragging", D.setPointerCapture(e.pointerId));
139
139
  }, U = (e) => {
140
- if (!v || v.pointerId !== e.pointerId || c === "exiting") return;
140
+ if (!v || v.pointerId !== e.pointerId || _ === "exiting") return;
141
141
  let t = e.clientX - v.startX;
142
- Math.abs(t) > u && (v.moved = !0), o = j() <= 1 ? t * .22 : t, N();
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), c === "exiting") return;
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
- c = "idle", o = 0, V();
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), c !== "exiting" && z());
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 = m(i, A().length), F();
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 y = /* @__PURE__ */ t({
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: l }) {
208
- let u = t, d = l, f = a(), p = null, m = () => ({
209
- ...u,
210
- onPhotoClick: (...e) => d("photo-click", ...e),
211
- onIndexChange: (...e) => d("index-change", ...e),
212
- onFlipChange: (...e) => d("flip-change", ...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
- f.value && (p = v(f.value, m()));
216
- }), o(() => c(u), () => p?.update(m())), r(() => {
217
- p?.destroy(), p = null;
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: f,
220
+ ref: d,
221
221
  class: "cos-photoPostcard-host"
222
222
  }, null, 512));
223
223
  }
224
224
  });
225
225
  //#endregion
226
- export { y as PhotoPostcard };
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.0.0",
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.0.0"
87
+ "@cos-design/shared": "4.1.0"
88
88
  }
89
- }
89
+ }