@cos-design/slot-machine 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,151 +1,138 @@
1
- import { prefersReducedMotion as e } from "@cos-design/shared";
1
+ import { optionCallbackDispatcher as e, prefersReducedMotion as t, readJsonAttr as n, readNumberAttr as r, readPropertyOverride as i, readStringAttr as a } from "@cos-design/shared";
2
2
  import './element.css';//#region src/components/slotMachine/core/engine.ts
3
- var t = "cos-slot-machine", n = [
3
+ var o = "cos-slot-machine", s = [
4
4
  "🍒",
5
5
  "🍋",
6
6
  "🍊",
7
7
  "🍇",
8
8
  "⭐",
9
9
  "7️⃣"
10
- ], r = 30, i = 8, a = [
10
+ ], c = 30, l = 8, u = [
11
11
  0,
12
12
  350,
13
13
  700
14
- ], o = 80, s = 3, c = (e) => 1 - (1 - e) ** 3, l = (e, t) => {
14
+ ], d = 80, f = 3, p = (e) => 1 - (1 - e) ** 3, m = (e, t) => {
15
15
  if (t === void 0) return Math.floor(Math.random() * e.length);
16
16
  let n = e.indexOf(t);
17
17
  return n >= 0 ? n : Math.floor(Math.random() * e.length);
18
18
  };
19
- function u(u, d = {}) {
20
- let f = {
21
- symbols: n,
19
+ function h(e, n = {}) {
20
+ let r = {
21
+ symbols: s,
22
22
  spinDuration: 3e3,
23
23
  spinningText: "旋转中...",
24
24
  jackpotText: "🎰 大奖!",
25
25
  resultPrefix: "结果:",
26
- ...d
27
- }, p = !1, m = !1, h = [
26
+ ...n
27
+ }, i = !1, a = !1, h = [
28
28
  0,
29
29
  0,
30
30
  0
31
31
  ], g = [], _ = 0, v = null, y = document.createElement("div"), b = document.createElement("div");
32
- b.className = `${t}__machine`;
32
+ b.className = `${o}__machine`;
33
33
  let x = [], S = [];
34
34
  for (let e = 0; e < 3; e++) {
35
35
  let e = document.createElement("div");
36
- e.className = `${t}__reel`;
36
+ e.className = `${o}__reel`;
37
+ let t = document.createElement("div");
38
+ t.className = `${o}__strip`;
37
39
  let n = document.createElement("div");
38
- n.className = `${t}__strip`;
39
- let r = document.createElement("div");
40
- r.className = `${t}__mask`, e.append(n, r), b.appendChild(e), x.push(e), S.push(n);
40
+ n.className = `${o}__mask`, e.append(t, n), b.appendChild(e), x.push(e), S.push(t);
41
41
  }
42
42
  let C = document.createElement("button");
43
- C.type = "button", C.className = `${t}__spin-btn`, C.dataset.testid = "slot-machine-spin";
43
+ C.type = "button", C.className = `${o}__spin-btn`, C.dataset.testid = "slot-machine-spin";
44
44
  let w = document.createElement("p");
45
- w.className = `${t}__result`, w.hidden = !0, y.append(b, C, w), u.appendChild(y);
46
- let T = () => f.symbols?.length ? f.symbols : n, E = () => T().length * o, D = () => Math.floor(r / 2) * E(), O = (e, t) => -(e - 1 + t * T().length) * o, k = () => f.buttonText ?? f.startText ?? "开始", A = () => {
47
- let e = T(), n = [];
48
- for (let t = 0; t < r; t++) n.push(...e);
45
+ w.className = `${o}__result`, w.hidden = !0, y.append(b, C, w), e.appendChild(y);
46
+ let T = () => r.symbols?.length ? r.symbols : s, E = () => T().length * d, D = () => Math.floor(c / 2) * E(), O = (e, t) => -(e - 1 + t * T().length) * d, k = () => r.buttonText ?? r.startText ?? "开始", A = () => {
47
+ let e = T(), t = [];
48
+ for (let n = 0; n < c; n++) t.push(...e);
49
49
  for (let e of S) {
50
50
  e.replaceChildren();
51
- for (let r of n) {
52
- let n = document.createElement("div");
53
- n.className = `${t}__item`, n.style.height = `${o}px`, n.textContent = r, e.appendChild(n);
51
+ for (let n of t) {
52
+ let t = document.createElement("div");
53
+ t.className = `${o}__item`, t.style.height = `${d}px`, t.textContent = n, e.appendChild(t);
54
54
  }
55
55
  }
56
- let i = o * s;
57
- for (let e of x) e.style.height = `${i}px`;
56
+ let n = d * f;
57
+ for (let e of x) e.style.height = `${n}px`;
58
58
  }, j = () => {
59
59
  S.forEach((e, t) => {
60
60
  e.style.transform = `translateY(${h[t]}px)`;
61
61
  });
62
62
  }, M = () => {
63
- y.className = t, C.disabled = m, C.setAttribute("aria-busy", String(m)), C.textContent = m ? f.spinningText ?? "旋转中..." : k(), g.length > 0 && !m ? (w.hidden = !1, w.textContent = g[0] === g[1] && g[1] === g[2] ? f.jackpotText ?? "🎰 大奖!" : `${f.resultPrefix ?? "结果:"} ${g.join(" ")}`) : (w.hidden = !0, w.textContent = "");
64
- }, N = (t) => {
63
+ y.className = o, C.disabled = a, C.setAttribute("aria-busy", String(a)), C.textContent = a ? r.spinningText ?? "旋转中..." : k(), g.length > 0 && !a ? (w.hidden = !1, w.textContent = g[0] === g[1] && g[1] === g[2] ? r.jackpotText ?? "🎰 大奖!" : `${r.resultPrefix ?? "结果:"} ${g.join(" ")}`) : (w.hidden = !0, w.textContent = "");
64
+ }, N = (e) => {
65
65
  let n = T();
66
- if (m || n.length === 0 || p) return;
67
- m = !0, g = [], M();
68
- let r = t ?? f.targetResults, s = [
66
+ if (a || n.length === 0 || i) return;
67
+ a = !0, g = [], M();
68
+ let o = e ?? r.targetResults, s = [
69
69
  0,
70
70
  1,
71
71
  2
72
- ].map((e) => l(n, r?.[e])), u = [...h], d = n.length * o, y = s.map((e, t) => {
73
- let n = u[t], r = i * d, a = Math.ceil((-n + r) / d) + 1, o = O(e, a);
74
- for (; n - o < r;) a += 1, o = O(e, a);
75
- return o;
76
- }), b = Math.max(f.spinDuration ?? 3e3, 16), x = performance.now(), S = { cancelled: !1 };
72
+ ].map((e) => m(n, o?.[e])), c = [...h], f = n.length * d, y = s.map((e, t) => {
73
+ let n = c[t], r = l * f, i = Math.ceil((-n + r) / f) + 1, a = O(e, i);
74
+ for (; n - a < r;) i += 1, a = O(e, i);
75
+ return a;
76
+ }), b = Math.max(r.spinDuration ?? 3e3, 16), x = performance.now(), S = { cancelled: !1 };
77
77
  v = S;
78
78
  let C = () => {
79
- if (S.cancelled || p) return;
79
+ if (S.cancelled || i) return;
80
80
  let e = s.map((e) => n[e]);
81
- h = s.map((e) => O(e, Math.round(D() / d))), g = e, m = !1, j(), M(), f.onSpinEnd?.(e);
81
+ h = s.map((e) => O(e, Math.round(D() / f))), g = e, a = !1, j(), M(), r.onSpinEnd?.(e);
82
82
  };
83
- if (e()) {
83
+ if (t()) {
84
84
  C();
85
85
  return;
86
86
  }
87
87
  let w = (e) => {
88
- S.cancelled || p || (h = u.map((t, n) => {
89
- let r = e - x - a[n];
88
+ S.cancelled || i || (h = c.map((t, n) => {
89
+ let r = e - x - u[n];
90
90
  if (r < 0) return t;
91
91
  let i = Math.min(r / b, 1);
92
- return t + (y[n] - t) * c(i);
93
- }), j(), a.every((t) => e - x - t >= b) ? C() : _ = requestAnimationFrame(w));
92
+ return t + (y[n] - t) * p(i);
93
+ }), j(), u.every((t) => e - x - t >= b) ? C() : _ = requestAnimationFrame(w));
94
94
  };
95
95
  _ = requestAnimationFrame(w);
96
96
  };
97
97
  return C.addEventListener("click", () => N()), A(), j(), M(), {
98
98
  update(e) {
99
99
  let t = T().join("\0");
100
- f = {
101
- ...f,
100
+ r = {
101
+ ...r,
102
102
  ...e
103
103
  }, T().join("\0") !== t && A(), M();
104
104
  },
105
105
  spin: N,
106
106
  reset: () => {
107
- m || (g = [], M());
107
+ a || (g = [], M());
108
108
  },
109
109
  destroy() {
110
- p || (p = !0, v && (v.cancelled = !0), cancelAnimationFrame(_), y.remove());
110
+ i || (i = !0, v && (v.cancelled = !0), cancelAnimationFrame(_), y.remove());
111
111
  }
112
112
  };
113
113
  }
114
114
  //#endregion
115
115
  //#region src/components/slotMachine/element/index.ts
116
- var d = "cos-slot-machine";
117
- function f(e) {
118
- let t = {};
119
- if (e.hasAttribute("start-text") && (t.startText = e.getAttribute("start-text") ?? void 0), e.hasAttribute("button-text") && (t.buttonText = e.getAttribute("button-text") ?? void 0), e.hasAttribute("spinning-text") && (t.spinningText = e.getAttribute("spinning-text") ?? void 0), e.hasAttribute("jackpot-text") && (t.jackpotText = e.getAttribute("jackpot-text") ?? void 0), e.hasAttribute("result-prefix") && (t.resultPrefix = e.getAttribute("result-prefix") ?? void 0), e.hasAttribute("spin-duration") && (t.spinDuration = Number(e.getAttribute("spin-duration"))), e.hasAttribute("symbols")) try {
120
- t.symbols = JSON.parse(e.getAttribute("symbols") ?? "null");
121
- } catch {}
122
- let n = e._symbols;
123
- if (n !== void 0 && (t.symbols = n), e.hasAttribute("target-results")) try {
124
- t.targetResults = JSON.parse(e.getAttribute("target-results") ?? "null");
125
- } catch {}
126
- let r = e._targetResults;
127
- return r !== void 0 && (t.targetResults = r), t.onSpinEnd = (...t) => {
128
- e.dispatchEvent(new CustomEvent("spin-end", {
129
- detail: t.length <= 1 ? t[0] : t,
130
- bubbles: !0
131
- }));
132
- }, t;
116
+ var g = "cos-slot-machine";
117
+ function _(t) {
118
+ let o = {};
119
+ return a(o, t, "startText", "start-text"), a(o, t, "buttonText", "button-text"), a(o, t, "spinningText", "spinning-text"), a(o, t, "jackpotText", "jackpot-text"), a(o, t, "resultPrefix", "result-prefix"), r(o, t, "spinDuration", "spin-duration"), n(o, t, "symbols", "symbols"), i(o, t, "symbols", "_symbols"), n(o, t, "targetResults", "target-results"), i(o, t, "targetResults", "_targetResults"), o.onSpinEnd = e(t, "spin-end"), o;
133
120
  }
134
- var p = class extends HTMLElement {
121
+ var v = class extends HTMLElement {
135
122
  ctrl = null;
136
123
  _symbols;
137
124
  get symbols() {
138
125
  return this._symbols;
139
126
  }
140
127
  set symbols(e) {
141
- this._symbols = e, this.ctrl?.update(f(this));
128
+ this._symbols = e, this.ctrl?.update(_(this));
142
129
  }
143
130
  _targetResults;
144
131
  get targetResults() {
145
132
  return this._targetResults;
146
133
  }
147
134
  set targetResults(e) {
148
- this._targetResults = e, this.ctrl?.update(f(this));
135
+ this._targetResults = e, this.ctrl?.update(_(this));
149
136
  }
150
137
  static get observedAttributes() {
151
138
  return [
@@ -160,13 +147,13 @@ var p = class extends HTMLElement {
160
147
  ];
161
148
  }
162
149
  connectedCallback() {
163
- this.ctrl = u(this, f(this));
150
+ this.ctrl = h(this, _(this));
164
151
  }
165
152
  disconnectedCallback() {
166
153
  this.ctrl?.destroy(), this.ctrl = null;
167
154
  }
168
155
  attributeChangedCallback() {
169
- this.ctrl?.update(f(this));
156
+ this.ctrl?.update(_(this));
170
157
  }
171
158
  spin(e) {
172
159
  return this.ctrl?.spin(e);
@@ -175,6 +162,6 @@ var p = class extends HTMLElement {
175
162
  return this.ctrl?.reset();
176
163
  }
177
164
  };
178
- typeof customElements < "u" && !customElements.get("cos-slot-machine") && customElements.define(d, p);
165
+ typeof customElements < "u" && !customElements.get("cos-slot-machine") && customElements.define(g, v);
179
166
  //#endregion
180
- export { p as CosSlotMachineElement, d as TAG };
167
+ export { v as CosSlotMachineElement, g 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,25 +1,25 @@
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 { optionsFingerprint as s, prefersReducedMotion as c } from "@cos-design/shared";
2
+ import { prefersReducedMotion as s } from "@cos-design/shared";
3
3
  import './vue.css';//#region src/components/slotMachine/core/engine.ts
4
- var l = "cos-slot-machine", u = [
4
+ var c = "cos-slot-machine", l = [
5
5
  "🍒",
6
6
  "🍋",
7
7
  "🍊",
8
8
  "🍇",
9
9
  "⭐",
10
10
  "7️⃣"
11
- ], d = 30, f = 8, p = [
11
+ ], u = 30, d = 8, f = [
12
12
  0,
13
13
  350,
14
14
  700
15
- ], m = 80, h = 3, g = (e) => 1 - (1 - e) ** 3, _ = (e, t) => {
15
+ ], p = 80, m = 3, h = (e) => 1 - (1 - e) ** 3, g = (e, t) => {
16
16
  if (t === void 0) return Math.floor(Math.random() * e.length);
17
17
  let n = e.indexOf(t);
18
18
  return n >= 0 ? n : Math.floor(Math.random() * e.length);
19
19
  };
20
- function v(e, t = {}) {
20
+ function _(e, t = {}) {
21
21
  let n = {
22
- symbols: u,
22
+ symbols: l,
23
23
  spinDuration: 3e3,
24
24
  spinningText: "旋转中...",
25
25
  jackpotText: "🎰 大奖!",
@@ -29,71 +29,71 @@ function v(e, t = {}) {
29
29
  0,
30
30
  0,
31
31
  0
32
- ], o = [], s = 0, v = null, y = document.createElement("div"), b = document.createElement("div");
33
- b.className = `${l}__machine`;
32
+ ], o = [], _ = 0, v = null, y = document.createElement("div"), b = document.createElement("div");
33
+ b.className = `${c}__machine`;
34
34
  let x = [], S = [];
35
35
  for (let e = 0; e < 3; e++) {
36
36
  let e = document.createElement("div");
37
- e.className = `${l}__reel`;
37
+ e.className = `${c}__reel`;
38
38
  let t = document.createElement("div");
39
- t.className = `${l}__strip`;
39
+ t.className = `${c}__strip`;
40
40
  let n = document.createElement("div");
41
- n.className = `${l}__mask`, e.append(t, n), b.appendChild(e), x.push(e), S.push(t);
41
+ n.className = `${c}__mask`, e.append(t, n), b.appendChild(e), x.push(e), S.push(t);
42
42
  }
43
43
  let C = document.createElement("button");
44
- C.type = "button", C.className = `${l}__spin-btn`, C.dataset.testid = "slot-machine-spin";
44
+ C.type = "button", C.className = `${c}__spin-btn`, C.dataset.testid = "slot-machine-spin";
45
45
  let w = document.createElement("p");
46
- w.className = `${l}__result`, w.hidden = !0, y.append(b, C, w), e.appendChild(y);
47
- let T = () => n.symbols?.length ? n.symbols : u, E = () => T().length * m, D = () => Math.floor(d / 2) * E(), O = (e, t) => -(e - 1 + t * T().length) * m, k = () => n.buttonText ?? n.startText ?? "开始", A = () => {
46
+ w.className = `${c}__result`, w.hidden = !0, y.append(b, C, w), e.appendChild(y);
47
+ let T = () => n.symbols?.length ? n.symbols : l, E = () => T().length * p, D = () => Math.floor(u / 2) * E(), O = (e, t) => -(e - 1 + t * T().length) * p, k = () => n.buttonText ?? n.startText ?? "开始", A = () => {
48
48
  let e = T(), t = [];
49
- for (let n = 0; n < d; n++) t.push(...e);
49
+ for (let n = 0; n < u; n++) t.push(...e);
50
50
  for (let e of S) {
51
51
  e.replaceChildren();
52
52
  for (let n of t) {
53
53
  let t = document.createElement("div");
54
- t.className = `${l}__item`, t.style.height = `${m}px`, t.textContent = n, e.appendChild(t);
54
+ t.className = `${c}__item`, t.style.height = `${p}px`, t.textContent = n, e.appendChild(t);
55
55
  }
56
56
  }
57
- let n = m * h;
57
+ let n = p * m;
58
58
  for (let e of x) e.style.height = `${n}px`;
59
59
  }, j = () => {
60
60
  S.forEach((e, t) => {
61
61
  e.style.transform = `translateY(${a[t]}px)`;
62
62
  });
63
63
  }, M = () => {
64
- y.className = l, C.disabled = i, C.setAttribute("aria-busy", String(i)), C.textContent = i ? n.spinningText ?? "旋转中..." : k(), o.length > 0 && !i ? (w.hidden = !1, w.textContent = o[0] === o[1] && o[1] === o[2] ? n.jackpotText ?? "🎰 大奖!" : `${n.resultPrefix ?? "结果:"} ${o.join(" ")}`) : (w.hidden = !0, w.textContent = "");
64
+ y.className = c, C.disabled = i, C.setAttribute("aria-busy", String(i)), C.textContent = i ? n.spinningText ?? "旋转中..." : k(), o.length > 0 && !i ? (w.hidden = !1, w.textContent = o[0] === o[1] && o[1] === o[2] ? n.jackpotText ?? "🎰 大奖!" : `${n.resultPrefix ?? "结果:"} ${o.join(" ")}`) : (w.hidden = !0, w.textContent = "");
65
65
  }, N = (e) => {
66
66
  let t = T();
67
67
  if (i || t.length === 0 || r) return;
68
68
  i = !0, o = [], M();
69
- let l = e ?? n.targetResults, u = [
69
+ let c = e ?? n.targetResults, l = [
70
70
  0,
71
71
  1,
72
72
  2
73
- ].map((e) => _(t, l?.[e])), d = [...a], h = t.length * m, y = u.map((e, t) => {
74
- let n = d[t], r = f * h, i = Math.ceil((-n + r) / h) + 1, a = O(e, i);
73
+ ].map((e) => g(t, c?.[e])), u = [...a], m = t.length * p, y = l.map((e, t) => {
74
+ let n = u[t], r = d * m, i = Math.ceil((-n + r) / m) + 1, a = O(e, i);
75
75
  for (; n - a < r;) i += 1, a = O(e, i);
76
76
  return a;
77
77
  }), b = Math.max(n.spinDuration ?? 3e3, 16), x = performance.now(), S = { cancelled: !1 };
78
78
  v = S;
79
79
  let C = () => {
80
80
  if (S.cancelled || r) return;
81
- let e = u.map((e) => t[e]);
82
- a = u.map((e) => O(e, Math.round(D() / h))), o = e, i = !1, j(), M(), n.onSpinEnd?.(e);
81
+ let e = l.map((e) => t[e]);
82
+ a = l.map((e) => O(e, Math.round(D() / m))), o = e, i = !1, j(), M(), n.onSpinEnd?.(e);
83
83
  };
84
- if (c()) {
84
+ if (s()) {
85
85
  C();
86
86
  return;
87
87
  }
88
88
  let w = (e) => {
89
- S.cancelled || r || (a = d.map((t, n) => {
90
- let r = e - x - p[n];
89
+ S.cancelled || r || (a = u.map((t, n) => {
90
+ let r = e - x - f[n];
91
91
  if (r < 0) return t;
92
92
  let i = Math.min(r / b, 1);
93
- return t + (y[n] - t) * g(i);
94
- }), j(), p.every((t) => e - x - t >= b) ? C() : s = requestAnimationFrame(w));
93
+ return t + (y[n] - t) * h(i);
94
+ }), j(), f.every((t) => e - x - t >= b) ? C() : _ = requestAnimationFrame(w));
95
95
  };
96
- s = requestAnimationFrame(w);
96
+ _ = requestAnimationFrame(w);
97
97
  };
98
98
  return C.addEventListener("click", () => N()), A(), j(), M(), {
99
99
  update(e) {
@@ -108,13 +108,13 @@ function v(e, t = {}) {
108
108
  i || (o = [], M());
109
109
  },
110
110
  destroy() {
111
- r || (r = !0, v && (v.cancelled = !0), cancelAnimationFrame(s), y.remove());
111
+ r || (r = !0, v && (v.cancelled = !0), cancelAnimationFrame(_), y.remove());
112
112
  }
113
113
  };
114
114
  }
115
115
  //#endregion
116
116
  //#region src/components/slotMachine/vue/SlotMachine.vue
117
- var y = /* @__PURE__ */ t({
117
+ var v = /* @__PURE__ */ t({
118
118
  __name: "SlotMachine",
119
119
  props: {
120
120
  symbols: {},
@@ -128,24 +128,24 @@ var y = /* @__PURE__ */ t({
128
128
  resultPrefix: {}
129
129
  },
130
130
  emits: ["spin-end"],
131
- setup(t, { expose: c, emit: l }) {
132
- let u = t, d = l, f = a(), p = null, m = () => ({
133
- ...u,
134
- onSpinEnd: (...e) => d("spin-end", ...e)
131
+ setup(t, { expose: s, emit: c }) {
132
+ let l = t, u = c, d = a(), f = null, p = () => ({
133
+ ...l,
134
+ onSpinEnd: (...e) => u("spin-end", ...e)
135
135
  });
136
136
  return n(() => {
137
- f.value && (p = v(f.value, m()));
138
- }), o(() => s(u), () => p?.update(m())), r(() => {
139
- p?.destroy(), p = null;
140
- }), c({
141
- spin: (e) => p?.spin(e),
142
- reset: () => p?.reset()
137
+ d.value && (f = _(d.value, p()));
138
+ }), o(() => ({ ...l }), () => f?.update(p()), { deep: !0 }), r(() => {
139
+ f?.destroy(), f = null;
140
+ }), s({
141
+ spin: (e) => f?.spin(e),
142
+ reset: () => f?.reset()
143
143
  }), (t, n) => (i(), e("div", {
144
144
  ref_key: "hostRef",
145
- ref: f,
145
+ ref: d,
146
146
  class: "cos-slotMachine-host"
147
147
  }, null, 512));
148
148
  }
149
149
  });
150
150
  //#endregion
151
- export { y as SlotMachine };
151
+ export { v as SlotMachine };
@@ -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/slot-machine",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "SlotMachine 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
+ }