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/CHANGELOG.md +23 -7
- package/README.md +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +79 -77
- package/dist/src/components/confetti/index.d.ts +5 -1
- package/dist/src/components/fireworks/index.d.ts +5 -1
- package/package.json +1 -1
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,
|
|
631
|
-
let
|
|
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(
|
|
638
|
-
}),
|
|
639
|
-
width:
|
|
640
|
-
height:
|
|
641
|
-
particleCount:
|
|
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
|
-
|
|
644
|
-
width:
|
|
645
|
-
height:
|
|
646
|
-
particleCount:
|
|
644
|
+
k.current = {
|
|
645
|
+
width: _,
|
|
646
|
+
height: v,
|
|
647
|
+
particleCount: l
|
|
647
648
|
}, r(() => {
|
|
648
|
-
|
|
649
|
-
}, [
|
|
650
|
-
let
|
|
651
|
-
let { width: e, height: t, particleCount: n } =
|
|
652
|
-
|
|
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(
|
|
655
|
-
o &&
|
|
656
|
-
}, [o,
|
|
657
|
-
let e =
|
|
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 =
|
|
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 (
|
|
670
|
-
n.clearRect(0, 0,
|
|
670
|
+
if (w.current = requestAnimationFrame(s), r) return;
|
|
671
|
+
n.clearRect(0, 0, _, v);
|
|
671
672
|
let e = i ? .03 : .008;
|
|
672
|
-
|
|
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(
|
|
676
|
+
cancelAnimationFrame(w.current), a(), o();
|
|
676
677
|
};
|
|
677
|
-
}, [
|
|
678
|
-
ref:
|
|
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:
|
|
685
|
-
height:
|
|
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:
|
|
692
|
-
height:
|
|
693
|
-
touchAction: "none"
|
|
692
|
+
width: _,
|
|
693
|
+
height: v,
|
|
694
|
+
touchAction: h ? "none" : "auto"
|
|
694
695
|
},
|
|
695
|
-
onPointerDown:
|
|
696
|
-
}), /* @__PURE__ */ u("p", {
|
|
696
|
+
onPointerDown: h ? A : void 0
|
|
697
|
+
}), h && f ? /* @__PURE__ */ u("p", {
|
|
697
698
|
className: U.hint,
|
|
698
|
-
children:
|
|
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,
|
|
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(
|
|
1360
|
-
}),
|
|
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
|
-
|
|
1363
|
-
}, [
|
|
1364
|
-
let
|
|
1365
|
-
let t = e ?? Math.random() *
|
|
1366
|
-
|
|
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:
|
|
1370
|
+
y: v,
|
|
1369
1371
|
vy: -(Math.random() * 4 + 6),
|
|
1370
|
-
targetY: Math.random() *
|
|
1372
|
+
targetY: Math.random() * v * .35 + v * .15,
|
|
1371
1373
|
color: Te(),
|
|
1372
1374
|
exploded: !1,
|
|
1373
1375
|
particles: [],
|
|
1374
1376
|
age: 0
|
|
1375
|
-
}),
|
|
1376
|
-
}, [
|
|
1377
|
-
return a(t, () => ({ launch:
|
|
1378
|
-
let e =
|
|
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 =
|
|
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 (
|
|
1391
|
-
if (n.fillStyle = "rgb(15 23 42 / 25%)", n.fillRect(0, 0,
|
|
1392
|
-
|
|
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
|
-
|
|
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
|
-
}),
|
|
1404
|
+
}), O.current && C.current.length === 0 && (O.current = !1, k.current?.());
|
|
1403
1405
|
}
|
|
1404
1406
|
};
|
|
1405
|
-
return c(), l && !a ? r = window.setInterval(() =>
|
|
1406
|
-
cancelAnimationFrame(
|
|
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
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1412
|
+
v,
|
|
1413
|
+
A,
|
|
1414
|
+
_
|
|
1413
1415
|
]), /* @__PURE__ */ d("div", {
|
|
1414
|
-
ref:
|
|
1416
|
+
ref: g,
|
|
1415
1417
|
className: xe.fireworks,
|
|
1416
1418
|
style: c ? {
|
|
1417
1419
|
width: "100%",
|
|
1418
1420
|
height: "100%"
|
|
1419
1421
|
} : {
|
|
1420
|
-
width:
|
|
1421
|
-
height:
|
|
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:
|
|
1428
|
-
height:
|
|
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 &&
|
|
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:
|
|
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