cos-design 3.7.9 → 3.7.11

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/index.js CHANGED
@@ -275,24 +275,25 @@ import './index.css';var p = {
275
275
  "#60efff",
276
276
  "#7b2ff7",
277
277
  "#f107a3"
278
- ], A = ({ width: e, height: t, fill: n = !1, colors: r = k }) => {
279
- let { hostRef: i, hostStyle: a } = D({
278
+ ], A = ({ width: e, height: t, fill: n = !1, colors: i = k }) => {
279
+ let { hostRef: a, hostStyle: o } = D({
280
280
  fill: n,
281
281
  width: e,
282
282
  height: t,
283
283
  defaultWidth: 800,
284
284
  defaultHeight: 500
285
- }), o = r.length >= 2 ? r : k;
286
- return /* @__PURE__ */ u("div", {
287
- ref: i,
285
+ }), s = i.length >= 2 ? i : k, [l, d] = c(() => typeof document < "u" && document.hidden);
286
+ return r(() => b(d), []), /* @__PURE__ */ u("div", {
287
+ ref: a,
288
288
  className: O.aurora,
289
- style: a,
290
- children: o.map((e, t) => /* @__PURE__ */ u("div", {
289
+ style: o,
290
+ children: s.map((e, t) => /* @__PURE__ */ u("div", {
291
291
  className: O.band,
292
292
  style: {
293
293
  "--aurora-color": e,
294
294
  "--aurora-delay": `${t * -3}s`,
295
- "--aurora-duration": `${12 + t * 2}s`
295
+ "--aurora-duration": `${12 + t * 2}s`,
296
+ animationPlayState: l ? "paused" : "running"
296
297
  }
297
298
  }, e + t))
298
299
  });
@@ -599,6 +600,7 @@ import './index.css';var p = {
599
600
  }, U = {
600
601
  confetti: "cos-confetti-MeNtU",
601
602
  canvas: "cos-canvas-0T3Vs",
603
+ canvasPassthrough: "cos-canvasPassthrough-3xF83",
602
604
  hint: "cos-hint-sGHEi"
603
605
  }, W = [
604
606
  "#ff6b6b",
@@ -626,37 +628,37 @@ import './index.css';var p = {
626
628
  gravity: Math.random() * .15 + .12
627
629
  };
628
630
  });
629
- }, q = t(({ width: e, height: t, fill: i = !1, auto: o = !0, particleCount: c = 120, hint: l = "点击画布再次喷射", onComplete: f }, p) => {
630
- let m = s(null), { width: h, height: g } = E({
631
+ }, q = t(({ width: e, height: t, fill: i = !1, auto: o = !0, interactive: c, particleCount: l = 120, hint: f = "点击画布再次喷射", onComplete: p }, m) => {
632
+ let h = c ?? o, g = s(null), { width: _, height: v } = E({
631
633
  fill: i,
632
634
  width: e,
633
635
  height: t,
634
636
  defaultWidth: 800,
635
637
  defaultHeight: 400,
636
- measured: T(m, { enabled: i })
637
- }), _ = s(null), v = s([]), y = s(0), C = s(!1), w = s(f), D = s({
638
- width: h,
639
- height: g,
640
- particleCount: c
638
+ measured: T(g, { enabled: i })
639
+ }), y = s(null), C = s([]), w = s(0), D = s(!1), O = s(p), k = s({
640
+ width: _,
641
+ height: v,
642
+ particleCount: l
641
643
  });
642
- D.current = {
643
- width: h,
644
- height: g,
645
- particleCount: c
644
+ k.current = {
645
+ width: _,
646
+ height: v,
647
+ particleCount: l
646
648
  }, r(() => {
647
- w.current = f;
648
- }, [f]);
649
- let O = n(() => {
650
- let { width: e, height: t, particleCount: n } = D.current, r = x();
651
- v.current.push(...K(e, t, r ? Math.min(24, n) : n)), C.current = !0;
649
+ O.current = p;
650
+ }, [p]);
651
+ let A = n(() => {
652
+ let { width: e, height: t, particleCount: n } = k.current, r = x();
653
+ C.current.push(...K(e, t, r ? Math.min(24, n) : n)), D.current = !0;
652
654
  }, []);
653
- return a(p, () => ({ burst: O }), [O]), r(() => {
654
- o && O();
655
- }, [o, O]), r(() => {
656
- let e = _.current;
655
+ return a(m, () => ({ burst: A }), [A]), r(() => {
656
+ o && A();
657
+ }, [o, A]), r(() => {
658
+ let e = y.current;
657
659
  if (!e) return;
658
660
  let t = window.devicePixelRatio || 1;
659
- e.width = h * t, e.height = g * t;
661
+ e.width = _ * t, e.height = v * t;
660
662
  let n = e.getContext("2d");
661
663
  if (!n) return;
662
664
  n.setTransform(t, 0, 0, t, 0, 0);
@@ -665,37 +667,37 @@ import './index.css';var p = {
665
667
  }), o = S((e) => {
666
668
  i = e;
667
669
  }), s = () => {
668
- if (y.current = requestAnimationFrame(s), r) return;
669
- n.clearRect(0, 0, h, g);
670
+ if (w.current = requestAnimationFrame(s), r) return;
671
+ n.clearRect(0, 0, _, v);
670
672
  let e = i ? .03 : .008;
671
- v.current = v.current.filter((t) => (t.x += t.vx, t.y += t.vy, t.vy += t.gravity, t.vx *= .99, t.rotation += t.rotationSpeed, t.alpha -= e, t.alpha <= 0 || t.y > g + 20 ? !1 : (n.save(), n.translate(t.x, t.y), n.rotate(t.rotation * Math.PI / 180), n.globalAlpha = t.alpha, n.fillStyle = t.color, n.fillRect(-t.width / 2, -t.height / 2, t.width, t.height), n.restore(), !0))), C.current && v.current.length === 0 && (C.current = !1, w.current?.());
673
+ C.current = C.current.filter((t) => (t.x += t.vx, t.y += t.vy, t.vy += t.gravity, t.vx *= .99, t.rotation += t.rotationSpeed, t.alpha -= e, t.alpha <= 0 || t.y > v + 20 ? !1 : (n.save(), n.translate(t.x, t.y), n.rotate(t.rotation * Math.PI / 180), n.globalAlpha = t.alpha, n.fillStyle = t.color, n.fillRect(-t.width / 2, -t.height / 2, t.width, t.height), n.restore(), !0))), D.current && C.current.length === 0 && (D.current = !1, O.current?.());
672
674
  };
673
675
  return s(), () => {
674
- cancelAnimationFrame(y.current), a(), o();
676
+ cancelAnimationFrame(w.current), a(), o();
675
677
  };
676
- }, [g, h]), /* @__PURE__ */ d("div", {
677
- ref: m,
678
+ }, [v, _]), /* @__PURE__ */ d("div", {
679
+ ref: g,
678
680
  className: U.confetti,
679
681
  style: i ? {
680
682
  width: "100%",
681
683
  height: "100%"
682
684
  } : {
683
- width: h,
684
- height: g
685
+ width: _,
686
+ height: v
685
687
  },
686
688
  children: [/* @__PURE__ */ u("canvas", {
687
- ref: _,
688
- className: U.canvas,
689
+ ref: y,
690
+ className: `${U.canvas} ${h ? "" : U.canvasPassthrough}`,
689
691
  style: {
690
- width: h,
691
- height: g,
692
- touchAction: "none"
692
+ width: _,
693
+ height: v,
694
+ touchAction: h ? "none" : "auto"
693
695
  },
694
- onPointerDown: O
695
- }), /* @__PURE__ */ u("p", {
696
+ onPointerDown: h ? A : void 0
697
+ }), h && f ? /* @__PURE__ */ u("p", {
696
698
  className: U.hint,
697
- children: l
698
- })]
699
+ children: f
700
+ }) : null]
699
701
  });
700
702
  });
701
703
  q.displayName = "Confetti";
@@ -1326,6 +1328,7 @@ var J = {
1326
1328
  }, xe = {
1327
1329
  fireworks: "cos-fireworks-fsSqL",
1328
1330
  canvas: "cos-canvas-spL8G",
1331
+ canvasPassthrough: "cos-canvasPassthrough-jCNke",
1329
1332
  hint: "cos-hint-5XDRH"
1330
1333
  }, Se = [
1331
1334
  "#ff6b6b",
@@ -1349,35 +1352,35 @@ var J = {
1349
1352
  };
1350
1353
  });
1351
1354
  }, De = t((e, t) => {
1352
- let { width: i, height: o, fill: c = !1, auto: l = !0, hint: f = "点击画布燃放烟花", onComplete: p } = e, m = s(null), { width: h, height: g } = E({
1355
+ let { width: i, height: o, fill: c = !1, auto: l = !0, interactive: f, hint: p = "点击画布燃放烟花", onComplete: m } = e, h = f ?? l, g = s(null), { width: _, height: v } = E({
1353
1356
  fill: c,
1354
1357
  width: i,
1355
1358
  height: o,
1356
1359
  defaultWidth: 800,
1357
1360
  defaultHeight: 500,
1358
- measured: T(m, { enabled: c })
1359
- }), _ = s(null), v = s([]), y = s(0), C = s(!1), D = s(p);
1361
+ measured: T(g, { enabled: c })
1362
+ }), y = s(null), C = s([]), D = s(0), O = s(!1), k = s(m);
1360
1363
  r(() => {
1361
- D.current = p;
1362
- }, [p]);
1363
- let O = n((e) => {
1364
- let t = e ?? Math.random() * h * .6 + h * .2;
1365
- v.current.push({
1364
+ k.current = m;
1365
+ }, [m]);
1366
+ let A = n((e) => {
1367
+ let t = e ?? Math.random() * _ * .6 + _ * .2;
1368
+ C.current.push({
1366
1369
  x: t,
1367
- y: g,
1370
+ y: v,
1368
1371
  vy: -(Math.random() * 4 + 6),
1369
- targetY: Math.random() * g * .35 + g * .15,
1372
+ targetY: Math.random() * v * .35 + v * .15,
1370
1373
  color: Te(),
1371
1374
  exploded: !1,
1372
1375
  particles: [],
1373
1376
  age: 0
1374
- }), C.current = !0;
1375
- }, [g, h]);
1376
- return a(t, () => ({ launch: O }), [O]), r(() => {
1377
- let e = _.current;
1377
+ }), O.current = !0;
1378
+ }, [v, _]);
1379
+ return a(t, () => ({ launch: A }), [A]), r(() => {
1380
+ let e = y.current;
1378
1381
  if (!e) return;
1379
1382
  let t = window.devicePixelRatio || 1;
1380
- e.width = h * t, e.height = g * t;
1383
+ e.width = _ * t, e.height = v * t;
1381
1384
  let n = e.getContext("2d");
1382
1385
  if (!n) return;
1383
1386
  n.setTransform(t, 0, 0, t, 0, 0);
@@ -1386,55 +1389,55 @@ var J = {
1386
1389
  }), s = S((e) => {
1387
1390
  a = e;
1388
1391
  }), c = () => {
1389
- if (y.current = requestAnimationFrame(c), !i) {
1390
- if (n.fillStyle = "rgb(15 23 42 / 25%)", n.fillRect(0, 0, h, g), a) {
1391
- C.current && v.current.length === 0 && (C.current = !1, D.current?.());
1392
+ if (D.current = requestAnimationFrame(c), !i) {
1393
+ if (n.fillStyle = "rgb(15 23 42 / 25%)", n.fillRect(0, 0, _, v), a) {
1394
+ O.current && C.current.length === 0 && (O.current = !1, k.current?.());
1392
1395
  return;
1393
1396
  }
1394
- v.current = v.current.filter((e) => {
1397
+ C.current = C.current.filter((e) => {
1395
1398
  if (!e.exploded) {
1396
1399
  e.age += 1, e.y += e.vy, e.vy += Ce, n.beginPath(), n.arc(e.x, e.y, 2.5, 0, Math.PI * 2), n.fillStyle = e.color, n.fill();
1397
1400
  let t = e.vy >= 0, r = e.y <= e.targetY, i = e.y < 0, a = e.age >= we;
1398
1401
  return (t || r || i || a) && (e.exploded = !0, e.particles = Ee(e.x, e.y, e.color)), !0;
1399
1402
  }
1400
1403
  return e.particles = e.particles.filter((e) => (e.x += e.vx, e.y += e.vy, e.vy += .06, e.alpha -= e.decay, e.alpha <= 0 ? !1 : (n.beginPath(), n.arc(e.x, e.y, 2, 0, Math.PI * 2), n.fillStyle = e.color, n.globalAlpha = e.alpha, n.fill(), n.globalAlpha = 1, !0))), e.particles.length > 0;
1401
- }), C.current && v.current.length === 0 && (C.current = !1, D.current?.());
1404
+ }), O.current && C.current.length === 0 && (O.current = !1, k.current?.());
1402
1405
  }
1403
1406
  };
1404
- return c(), l && !a ? r = window.setInterval(() => O(), 1200) : l && a && O(), () => {
1405
- cancelAnimationFrame(y.current), clearInterval(r), o(), s();
1407
+ return c(), l && !a ? r = window.setInterval(() => A(), 1200) : l && a && A(), () => {
1408
+ cancelAnimationFrame(D.current), clearInterval(r), o(), s();
1406
1409
  };
1407
1410
  }, [
1408
1411
  l,
1409
- g,
1410
- O,
1411
- h
1412
+ v,
1413
+ A,
1414
+ _
1412
1415
  ]), /* @__PURE__ */ d("div", {
1413
- ref: m,
1416
+ ref: g,
1414
1417
  className: xe.fireworks,
1415
1418
  style: c ? {
1416
1419
  width: "100%",
1417
1420
  height: "100%"
1418
1421
  } : {
1419
- width: h,
1420
- height: g
1422
+ width: _,
1423
+ height: v
1421
1424
  },
1422
1425
  children: [/* @__PURE__ */ u("canvas", {
1423
- ref: _,
1424
- className: xe.canvas,
1426
+ ref: y,
1427
+ className: `${xe.canvas} ${h ? "" : xe.canvasPassthrough}`,
1425
1428
  style: {
1426
- width: h,
1427
- height: g,
1428
- touchAction: "none"
1429
+ width: _,
1430
+ height: v,
1431
+ touchAction: h ? "none" : "auto"
1429
1432
  },
1430
- onPointerDown: (e) => {
1433
+ onPointerDown: h ? (e) => {
1431
1434
  let t = w(e.currentTarget, e.nativeEvent);
1432
- t && O(t.x);
1433
- }
1434
- }), /* @__PURE__ */ u("p", {
1435
+ t && A(t.x);
1436
+ } : void 0
1437
+ }), h && p ? /* @__PURE__ */ u("p", {
1435
1438
  className: xe.hint,
1436
- children: f
1437
- })]
1439
+ children: p
1440
+ }) : null]
1438
1441
  });
1439
1442
  });
1440
1443
  De.displayName = "Fireworks";
@@ -2883,48 +2886,48 @@ var Ae = {
2883
2886
  let t = [...e?.length ? e : Dt];
2884
2887
  for (; t.length < 9;) t.push({ label: `奖品 ${t.length + 1}` });
2885
2888
  return t.slice(0, 9);
2886
- }, kt = t(({ items: e = Dt, targetIndex: t, buttonText: i = "开始抽奖", onDrawEnd: o, disabled: l = !1 }, f) => {
2887
- let p = Ot(e), [m, h] = c(null), [g, _] = c(null), [v, y] = c(!1), b = s([]), x = s(o), S = s(t);
2889
+ }, kt = t(({ items: e = Dt, targetIndex: t, buttonText: i = "开始抽奖", spinningText: o = "抽奖中…", onDrawEnd: l, disabled: f = !1 }, p) => {
2890
+ let m = Ot(e), [h, g] = c(null), [_, v] = c(null), [y, b] = c(!1), x = s([]), S = s(l), C = s(t);
2888
2891
  r(() => {
2889
- x.current = o;
2890
- }, [o]), r(() => {
2891
- S.current = t;
2892
+ S.current = l;
2893
+ }, [l]), r(() => {
2894
+ C.current = t;
2892
2895
  }, [t]);
2893
- let C = n(() => {
2894
- b.current.forEach((e) => window.clearTimeout(e)), b.current = [];
2895
- }, []);
2896
- r(() => C, [C]);
2897
2896
  let w = n(() => {
2898
- C(), y(!1), h(null), _(null);
2899
- }, [C]), T = n((e) => {
2900
- if (v || l) return;
2901
- C(), _(null), y(!0);
2902
- let t = ((typeof e == "number" ? e : typeof S.current == "number" ? S.current : Math.floor(Math.random() * 9)) % 9 + 9) % 9, n = 18 + t, r = 0, i = () => {
2903
- if (h(r % 9), r += 1, r > n) {
2904
- h(t), _(t), y(!1), x.current?.(p[t], t);
2897
+ x.current.forEach((e) => window.clearTimeout(e)), x.current = [];
2898
+ }, []);
2899
+ r(() => w, [w]);
2900
+ let T = n(() => {
2901
+ w(), b(!1), g(null), v(null);
2902
+ }, [w]), E = n((e) => {
2903
+ if (y || f) return;
2904
+ w(), v(null), b(!0);
2905
+ let t = ((typeof e == "number" ? e : typeof C.current == "number" ? C.current : Math.floor(Math.random() * 9)) % 9 + 9) % 9, n = 18 + t, r = 0, i = () => {
2906
+ if (g(r % 9), r += 1, r > n) {
2907
+ g(t), v(t), b(!1), S.current?.(m[t], t);
2905
2908
  return;
2906
2909
  }
2907
2910
  let e = 60 + Math.floor(r * 12);
2908
- b.current.push(window.setTimeout(i, e));
2911
+ x.current.push(window.setTimeout(i, e));
2909
2912
  };
2910
2913
  i();
2911
2914
  }, [
2912
- p,
2913
- C,
2914
- l,
2915
- v
2915
+ m,
2916
+ w,
2917
+ f,
2918
+ y
2916
2919
  ]);
2917
- return a(f, () => ({
2918
- draw: T,
2919
- reset: w
2920
- }), [T, w]), /* @__PURE__ */ d("div", {
2920
+ return a(p, () => ({
2921
+ draw: E,
2922
+ reset: T
2923
+ }), [E, T]), /* @__PURE__ */ d("div", {
2921
2924
  className: Et.nineGrid,
2922
2925
  children: [/* @__PURE__ */ u("div", {
2923
2926
  className: Et.board,
2924
2927
  role: "grid",
2925
2928
  "aria-label": "九宫格抽奖",
2926
- children: p.map((e, t) => {
2927
- let n = m === t, r = g === t;
2929
+ children: m.map((e, t) => {
2930
+ let n = h === t, r = _ === t;
2928
2931
  return /* @__PURE__ */ d("div", {
2929
2932
  role: "gridcell",
2930
2933
  className: `${Et.cell} ${n ? Et.active : ""} ${r ? Et.winner : ""}`,
@@ -2940,9 +2943,11 @@ var Ae = {
2940
2943
  }), /* @__PURE__ */ u("button", {
2941
2944
  type: "button",
2942
2945
  className: Et.button,
2943
- onClick: () => T(),
2944
- disabled: v || l,
2945
- children: v ? "抽奖中…" : i
2946
+ "data-testid": "nine-grid-draw",
2947
+ onClick: () => E(),
2948
+ disabled: y || f,
2949
+ "aria-busy": y,
2950
+ children: y ? o : i
2946
2951
  })]
2947
2952
  });
2948
2953
  });
@@ -9138,8 +9143,10 @@ var fs = {
9138
9143
  /* @__PURE__ */ u("button", {
9139
9144
  type: "button",
9140
9145
  className: fs.spinBtn,
9146
+ "data-testid": "slot-machine-spin",
9141
9147
  onClick: () => F(),
9142
9148
  disabled: v,
9149
+ "aria-busy": v,
9143
9150
  children: v ? p : _
9144
9151
  }),
9145
9152
  S.length > 0 && !v && /* @__PURE__ */ u("p", {
@@ -9675,8 +9682,10 @@ var bs = {
9675
9682
  /* @__PURE__ */ u("button", {
9676
9683
  type: "button",
9677
9684
  className: Ps.spinBtn,
9685
+ "data-testid": "turntable-spin",
9678
9686
  onClick: () => N(),
9679
9687
  disabled: S,
9688
+ "aria-busy": S,
9680
9689
  children: S ? p : f
9681
9690
  })
9682
9691
  ]
@@ -6,9 +6,13 @@ export interface ConfettiProps {
6
6
  fill?: boolean;
7
7
  /** 挂载后自动播放,默认 true */
8
8
  auto?: boolean;
9
+ /**
10
+ * 是否响应点击再次喷射;默认跟随 auto(auto=false 时不拦截指针,避免挡住抽奖按钮)
11
+ */
12
+ interactive?: boolean;
9
13
  /** 每次喷射粒子数,默认 120 */
10
14
  particleCount?: number;
11
- /** 画布操作提示 */
15
+ /** 画布操作提示;非 interactive 时不展示 */
12
16
  hint?: string;
13
17
  /** 粒子全部消散后回调 */
14
18
  onComplete?: () => void;
@@ -6,7 +6,11 @@ export interface FireworksProps {
6
6
  fill?: boolean;
7
7
  /** 是否自动燃放,默认 true */
8
8
  auto?: boolean;
9
- /** 画布操作提示 */
9
+ /**
10
+ * 是否响应点击燃放;默认跟随 auto(auto=false 时不拦截指针)
11
+ */
12
+ interactive?: boolean;
13
+ /** 画布操作提示;非 interactive 时不展示 */
10
14
  hint?: string;
11
15
  /** 画面空闲(无火箭/粒子)时回调 */
12
16
  onComplete?: () => void;
@@ -18,6 +18,8 @@ export interface NineGridProps {
18
18
  targetIndex?: number;
19
19
  /** 抽奖按钮文案 */
20
20
  buttonText?: string;
21
+ /** 抽奖进行中的按钮文案 */
22
+ spinningText?: string;
21
23
  /** 抽奖结束回调 */
22
24
  onDrawEnd?: (item: NineGridItem, index: number) => void;
23
25
  /** 禁用交互 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cos-design",
3
- "version": "3.7.9",
3
+ "version": "3.7.11",
4
4
  "description": "React visual-effect components for marketing pages, campaigns, canvas backgrounds, and creative showcases",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",