cos-design 3.7.10 → 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
@@ -600,6 +600,7 @@ import './index.css';var p = {
600
600
  }, U = {
601
601
  confetti: "cos-confetti-MeNtU",
602
602
  canvas: "cos-canvas-0T3Vs",
603
+ canvasPassthrough: "cos-canvasPassthrough-3xF83",
603
604
  hint: "cos-hint-sGHEi"
604
605
  }, W = [
605
606
  "#ff6b6b",
@@ -627,37 +628,37 @@ import './index.css';var p = {
627
628
  gravity: Math.random() * .15 + .12
628
629
  };
629
630
  });
630
- }, q = t(({ width: e, height: t, fill: i = !1, auto: o = !0, particleCount: c = 120, hint: l = "点击画布再次喷射", onComplete: f }, p) => {
631
- 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({
632
633
  fill: i,
633
634
  width: e,
634
635
  height: t,
635
636
  defaultWidth: 800,
636
637
  defaultHeight: 400,
637
- measured: T(m, { enabled: i })
638
- }), _ = s(null), v = s([]), y = s(0), C = s(!1), w = s(f), D = s({
639
- width: h,
640
- height: g,
641
- 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
642
643
  });
643
- D.current = {
644
- width: h,
645
- height: g,
646
- particleCount: c
644
+ k.current = {
645
+ width: _,
646
+ height: v,
647
+ particleCount: l
647
648
  }, r(() => {
648
- w.current = f;
649
- }, [f]);
650
- let O = n(() => {
651
- let { width: e, height: t, particleCount: n } = D.current, r = x();
652
- 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;
653
654
  }, []);
654
- return a(p, () => ({ burst: O }), [O]), r(() => {
655
- o && O();
656
- }, [o, O]), r(() => {
657
- let e = _.current;
655
+ return a(m, () => ({ burst: A }), [A]), r(() => {
656
+ o && A();
657
+ }, [o, A]), r(() => {
658
+ let e = y.current;
658
659
  if (!e) return;
659
660
  let t = window.devicePixelRatio || 1;
660
- e.width = h * t, e.height = g * t;
661
+ e.width = _ * t, e.height = v * t;
661
662
  let n = e.getContext("2d");
662
663
  if (!n) return;
663
664
  n.setTransform(t, 0, 0, t, 0, 0);
@@ -666,37 +667,37 @@ import './index.css';var p = {
666
667
  }), o = S((e) => {
667
668
  i = e;
668
669
  }), s = () => {
669
- if (y.current = requestAnimationFrame(s), r) return;
670
- n.clearRect(0, 0, h, g);
670
+ if (w.current = requestAnimationFrame(s), r) return;
671
+ n.clearRect(0, 0, _, v);
671
672
  let e = i ? .03 : .008;
672
- 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?.());
673
674
  };
674
675
  return s(), () => {
675
- cancelAnimationFrame(y.current), a(), o();
676
+ cancelAnimationFrame(w.current), a(), o();
676
677
  };
677
- }, [g, h]), /* @__PURE__ */ d("div", {
678
- ref: m,
678
+ }, [v, _]), /* @__PURE__ */ d("div", {
679
+ ref: g,
679
680
  className: U.confetti,
680
681
  style: i ? {
681
682
  width: "100%",
682
683
  height: "100%"
683
684
  } : {
684
- width: h,
685
- height: g
685
+ width: _,
686
+ height: v
686
687
  },
687
688
  children: [/* @__PURE__ */ u("canvas", {
688
- ref: _,
689
- className: U.canvas,
689
+ ref: y,
690
+ className: `${U.canvas} ${h ? "" : U.canvasPassthrough}`,
690
691
  style: {
691
- width: h,
692
- height: g,
693
- touchAction: "none"
692
+ width: _,
693
+ height: v,
694
+ touchAction: h ? "none" : "auto"
694
695
  },
695
- onPointerDown: O
696
- }), /* @__PURE__ */ u("p", {
696
+ onPointerDown: h ? A : void 0
697
+ }), h && f ? /* @__PURE__ */ u("p", {
697
698
  className: U.hint,
698
- children: l
699
- })]
699
+ children: f
700
+ }) : null]
700
701
  });
701
702
  });
702
703
  q.displayName = "Confetti";
@@ -1327,6 +1328,7 @@ var J = {
1327
1328
  }, xe = {
1328
1329
  fireworks: "cos-fireworks-fsSqL",
1329
1330
  canvas: "cos-canvas-spL8G",
1331
+ canvasPassthrough: "cos-canvasPassthrough-jCNke",
1330
1332
  hint: "cos-hint-5XDRH"
1331
1333
  }, Se = [
1332
1334
  "#ff6b6b",
@@ -1350,35 +1352,35 @@ var J = {
1350
1352
  };
1351
1353
  });
1352
1354
  }, De = t((e, t) => {
1353
- 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({
1354
1356
  fill: c,
1355
1357
  width: i,
1356
1358
  height: o,
1357
1359
  defaultWidth: 800,
1358
1360
  defaultHeight: 500,
1359
- measured: T(m, { enabled: c })
1360
- }), _ = 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);
1361
1363
  r(() => {
1362
- D.current = p;
1363
- }, [p]);
1364
- let O = n((e) => {
1365
- let t = e ?? Math.random() * h * .6 + h * .2;
1366
- 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({
1367
1369
  x: t,
1368
- y: g,
1370
+ y: v,
1369
1371
  vy: -(Math.random() * 4 + 6),
1370
- targetY: Math.random() * g * .35 + g * .15,
1372
+ targetY: Math.random() * v * .35 + v * .15,
1371
1373
  color: Te(),
1372
1374
  exploded: !1,
1373
1375
  particles: [],
1374
1376
  age: 0
1375
- }), C.current = !0;
1376
- }, [g, h]);
1377
- return a(t, () => ({ launch: O }), [O]), r(() => {
1378
- let e = _.current;
1377
+ }), O.current = !0;
1378
+ }, [v, _]);
1379
+ return a(t, () => ({ launch: A }), [A]), r(() => {
1380
+ let e = y.current;
1379
1381
  if (!e) return;
1380
1382
  let t = window.devicePixelRatio || 1;
1381
- e.width = h * t, e.height = g * t;
1383
+ e.width = _ * t, e.height = v * t;
1382
1384
  let n = e.getContext("2d");
1383
1385
  if (!n) return;
1384
1386
  n.setTransform(t, 0, 0, t, 0, 0);
@@ -1387,55 +1389,55 @@ var J = {
1387
1389
  }), s = S((e) => {
1388
1390
  a = e;
1389
1391
  }), c = () => {
1390
- if (y.current = requestAnimationFrame(c), !i) {
1391
- if (n.fillStyle = "rgb(15 23 42 / 25%)", n.fillRect(0, 0, h, g), a) {
1392
- 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?.());
1393
1395
  return;
1394
1396
  }
1395
- v.current = v.current.filter((e) => {
1397
+ C.current = C.current.filter((e) => {
1396
1398
  if (!e.exploded) {
1397
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();
1398
1400
  let t = e.vy >= 0, r = e.y <= e.targetY, i = e.y < 0, a = e.age >= we;
1399
1401
  return (t || r || i || a) && (e.exploded = !0, e.particles = Ee(e.x, e.y, e.color)), !0;
1400
1402
  }
1401
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;
1402
- }), C.current && v.current.length === 0 && (C.current = !1, D.current?.());
1404
+ }), O.current && C.current.length === 0 && (O.current = !1, k.current?.());
1403
1405
  }
1404
1406
  };
1405
- return c(), l && !a ? r = window.setInterval(() => O(), 1200) : l && a && O(), () => {
1406
- 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();
1407
1409
  };
1408
1410
  }, [
1409
1411
  l,
1410
- g,
1411
- O,
1412
- h
1412
+ v,
1413
+ A,
1414
+ _
1413
1415
  ]), /* @__PURE__ */ d("div", {
1414
- ref: m,
1416
+ ref: g,
1415
1417
  className: xe.fireworks,
1416
1418
  style: c ? {
1417
1419
  width: "100%",
1418
1420
  height: "100%"
1419
1421
  } : {
1420
- width: h,
1421
- height: g
1422
+ width: _,
1423
+ height: v
1422
1424
  },
1423
1425
  children: [/* @__PURE__ */ u("canvas", {
1424
- ref: _,
1425
- className: xe.canvas,
1426
+ ref: y,
1427
+ className: `${xe.canvas} ${h ? "" : xe.canvasPassthrough}`,
1426
1428
  style: {
1427
- width: h,
1428
- height: g,
1429
- touchAction: "none"
1429
+ width: _,
1430
+ height: v,
1431
+ touchAction: h ? "none" : "auto"
1430
1432
  },
1431
- onPointerDown: (e) => {
1433
+ onPointerDown: h ? (e) => {
1432
1434
  let t = w(e.currentTarget, e.nativeEvent);
1433
- t && O(t.x);
1434
- }
1435
- }), /* @__PURE__ */ u("p", {
1435
+ t && A(t.x);
1436
+ } : void 0
1437
+ }), h && p ? /* @__PURE__ */ u("p", {
1436
1438
  className: xe.hint,
1437
- children: f
1438
- })]
1439
+ children: p
1440
+ }) : null]
1439
1441
  });
1440
1442
  });
1441
1443
  De.displayName = "Fireworks";
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cos-design",
3
- "version": "3.7.10",
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",