m3-ripple 1.0.2 → 1.1.1
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/.github/workflows/publish.yml +3 -5
- package/CHANGELOG.md +10 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +130 -126
- package/dist/ripple.css +3 -0
- package/package.json +1 -1
|
@@ -29,9 +29,9 @@ jobs:
|
|
|
29
29
|
bun-version: latest
|
|
30
30
|
registry-url: "https://registry.npmjs.org"
|
|
31
31
|
|
|
32
|
-
- uses: actions/setup-node@
|
|
32
|
+
- uses: actions/setup-node@v5
|
|
33
33
|
with:
|
|
34
|
-
node-version: '
|
|
34
|
+
node-version: '24.x'
|
|
35
35
|
registry-url: 'https://registry.npmjs.org'
|
|
36
36
|
|
|
37
37
|
- name: Install packages
|
|
@@ -41,7 +41,5 @@ jobs:
|
|
|
41
41
|
run: bun run build
|
|
42
42
|
|
|
43
43
|
- name: 'Publish'
|
|
44
|
-
env:
|
|
45
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
46
44
|
run: |
|
|
47
|
-
npm publish --provenance --access=public
|
|
45
|
+
NPM_AUTH_TOKEN="" npm publish --provenance --access=public
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
# 1.1.1 - 30 Dec
|
|
2
|
+
Fix:
|
|
3
|
+
- ripple sharing element
|
|
4
|
+
|
|
5
|
+
# 1.1.0 - 30 Dec 2025
|
|
6
|
+
Improvement:
|
|
7
|
+
- add `pointer-events: none` to ripple element to prevent blocking pointer events on parent elements
|
|
8
|
+
- automatic disable ripple effect based on parent element
|
|
9
|
+
- add `overflow: hidden`, `border-radius: inherit` to ripple container
|
|
10
|
+
|
|
1
11
|
# 1.0.2 - 22 Jun 2025
|
|
2
12
|
Fix:
|
|
3
13
|
- Unexpected semi-colon in CSS
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("react/jsx-runtime"),r=require("react"),U=.2,Z=12,J=75,K=.35,Q="forwards",V=({hoverOpacity:P,pressedOpacity:E,disabled:a=!1,className:w="",style:X,easing:k,duration:f=150,minimumPressDuration:C=225,touchDelay:g=150})=>{const[Y,A]=r.useState(!1),[D,I]=r.useState(!1),o=r.useRef(null),x=r.useRef(null),m=r.useRef(""),v=r.useRef(""),S=r.useRef(0),y=r.useRef(void 0),s=r.useRef(0),R=r.useRef(void 0),T=r.useRef(!1);r.useEffect(()=>{if(!x.current)return;const e=x.current.style;P!==void 0&&e.setProperty("--ripple-hover-opacity",P+""),E!==void 0&&e.setProperty("--ripple-pressed-opacity",E+""),f!==void 0&&f!==150&&e.setProperty("--ripple-duration",f+"ms")},[P,E,f]),r.useEffect(()=>{var c;const e=(c=o.current)==null?void 0:c.parentElement;if(!e)return;const t=(n,l)=>e.addEventListener(n,l,!0);return t("click",G),t("contextmenu",F),t("pointercancel",q),t("pointerdown",j),t("pointerenter",$),t("pointerleave",B),t("pointerup",L),()=>{const n=(l,d)=>e.removeEventListener(l,d,!0);n("click",G),n("contextmenu",F),n("pointercancel",q),n("pointerdown",j),n("pointerenter",$),n("pointerleave",B),n("pointerup",L)}},[a,k,f,C,g]);const h=r.useCallback(({pointerType:e})=>e==="touch",[]),u=r.useCallback(e=>{var c,n;if(a||(n=(c=o.current)==null?void 0:c.parentElement)!=null&&n.disabled||!e.isPrimary||R.current&&R.current.pointerId!==e.pointerId)return!1;if(e.type==="pointerenter"||e.type==="pointerleave")return!h(e);const t=e.buttons===1;return h(e)||t},[a,h]),M=r.useCallback(({x:e,y:t})=>{const c=o.current;if(!c)return!1;const n=c.getBoundingClientRect();return e>=n.left&&e<=n.right&&t>=n.top&&t<=n.bottom},[o]),$=r.useCallback(e=>{u(e)&&A(!0)},[u]),N=r.useCallback(()=>{const e=o.current;if(!e)return;const{height:t,width:c}=e.getBoundingClientRect(),n=Math.max(t,c),l=Math.max(K*n,J),d=Math.floor(n*U),H=Math.sqrt(c**2+t**2)+Z;S.current=d,v.current=(H+l)/d+"",m.current=d+"px"},[o]),_=r.useCallback(e=>{const t=o.current;if(!t)return{x:0,y:0};const c=t.getBoundingClientRect(),n=window.scrollX+c.left,l=window.scrollY+c.top;return{x:e.pageX-n,y:e.pageY-l}},[o]),z=r.useCallback(e=>{const t=o.current.parentElement;if(!t)return{startPoint:{x:0,y:0},endPoint:{x:0,y:0}};const c=t.getBoundingClientRect(),n={x:(c.width-S.current)/2,y:(c.height-S.current)/2};return{startPoint:_(e),endPoint:n}},[o,_]),p=r.useCallback(e=>{var b;const t=x.current;if(!t)return;I(!0),(b=y.current)==null||b.cancel(),N();const{startPoint:c,endPoint:n}=z(e),l=`${c.x}px, ${c.y}px`,d=`${n.x}px, ${n.y}px`;y.current=t.animate({height:[m.current,m.current],width:[m.current,m.current],transform:[`translate(${l}) scale(1)`,`translate(${d}) scale(${v.current})`]},{pseudoElement:"::after",duration:f,easing:k,fill:Q})},[N,f,k,z]),i=r.useCallback(()=>{R.current=void 0,s.current=0;const e=y.current;let t=1/0;if(typeof(e==null?void 0:e.currentTime)=="number"?t=e.currentTime:e!=null&&e.currentTime&&(t=e.currentTime.to("ms").value),t>=C)return void I(!1);setTimeout(()=>{y.current===e&&I(!1)},C-t)},[C]),B=r.useCallback(e=>{u(e)&&(A(!1),s.current!==0&&i())},[i,u]),L=r.useCallback(e=>{if(u(e)){if(s.current===2){s.current=3;return}if(s.current===1){s.current=3,p(R.current);return}}},[u,p]),j=r.useCallback(async e=>{if(u(e)){if(R.current=e,!h(e)){s.current=3,p(e);return}T.current&&!M(e)||(T.current=!1,s.current=1,await new Promise(t=>{setTimeout(t,g)}),s.current===1&&(s.current=2,p(e)))}},[u,h,M,p,g]),G=r.useCallback(()=>{if(!a){if(s.current===3){i();return}s.current===0&&(p(),i())}},[a,i,p]),q=r.useCallback(e=>{u(e)&&i()},[i,u]),F=r.useCallback(()=>{a||(T.current=!0,i())},[a,i]);return O.jsx("div",{ref:o,className:`salty-ripple${w?` ${w}`:""}`,style:X,"aria-hidden":"true",children:O.jsx("div",{ref:x,className:`salty-ripple-surface${Y?" --hover":""}${D?" --press":""}`})})};exports.Ripple=V;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAQA,MAAM,WAAW,WAAW;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAE3B;;OAEG;IACH,MAAM,CAAC,EAAE,4BAA4B,CAAA;IAErC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAE7B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB;AA+CD;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,kHAUpB,WAAW,4CAqVb,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,192 +1,196 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as D, useRef as
|
|
3
|
-
const Q = 0.2, V = 12, W = 75, b = 0.35,
|
|
4
|
-
hoverOpacity:
|
|
5
|
-
pressedOpacity:
|
|
1
|
+
import { jsx as q } from "react/jsx-runtime";
|
|
2
|
+
import { useState as D, useRef as f, useEffect as H, useCallback as o } from "react";
|
|
3
|
+
const Q = 0.2, V = 12, W = 75, b = 0.35, ee = "forwards", ne = ({
|
|
4
|
+
hoverOpacity: I,
|
|
5
|
+
pressedOpacity: g,
|
|
6
6
|
disabled: a = !1,
|
|
7
|
-
className:
|
|
8
|
-
style:
|
|
9
|
-
easing:
|
|
7
|
+
className: v = "",
|
|
8
|
+
style: U,
|
|
9
|
+
easing: T,
|
|
10
10
|
duration: p = 150,
|
|
11
|
-
minimumPressDuration:
|
|
12
|
-
touchDelay:
|
|
11
|
+
minimumPressDuration: P = 225,
|
|
12
|
+
touchDelay: w = 150
|
|
13
13
|
}) => {
|
|
14
|
-
const [
|
|
14
|
+
const [Z, M] = D(!1), [J, S] = D(!1), s = f(null), y = f(null), h = f(""), N = f(""), C = f(0), E = f(void 0), c = f(
|
|
15
15
|
0
|
|
16
16
|
/* INACTIVE */
|
|
17
|
-
),
|
|
18
|
-
|
|
19
|
-
if (!
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
}, [
|
|
23
|
-
|
|
24
|
-
(
|
|
17
|
+
), x = f(void 0), A = f(!1);
|
|
18
|
+
H(() => {
|
|
19
|
+
if (!y.current) return;
|
|
20
|
+
const e = y.current.style;
|
|
21
|
+
I !== void 0 && e.setProperty("--ripple-hover-opacity", I + ""), g !== void 0 && e.setProperty("--ripple-pressed-opacity", g + ""), p !== void 0 && p !== 150 && e.setProperty("--ripple-duration", p + "ms");
|
|
22
|
+
}, [I, g, p]), H(() => {
|
|
23
|
+
var n;
|
|
24
|
+
const e = (n = s.current) == null ? void 0 : n.parentElement;
|
|
25
|
+
if (!e) return;
|
|
26
|
+
const t = (r, l) => e.addEventListener(r, l, !0);
|
|
27
|
+
return t("click", Y), t("contextmenu", j), t("pointercancel", O), t("pointerdown", X), t("pointerenter", z), t("pointerleave", G), t("pointerup", F), () => {
|
|
28
|
+
const r = (l, m) => e.removeEventListener(l, m, !0);
|
|
29
|
+
r("click", Y), r("contextmenu", j), r("pointercancel", O), r("pointerdown", X), r("pointerenter", z), r("pointerleave", G), r("pointerup", F);
|
|
30
|
+
};
|
|
31
|
+
}, [a, T, p, P, w]);
|
|
32
|
+
const R = o(
|
|
33
|
+
({ pointerType: e }) => e === "touch",
|
|
25
34
|
[]
|
|
26
|
-
),
|
|
27
|
-
(
|
|
28
|
-
|
|
35
|
+
), i = o(
|
|
36
|
+
(e) => {
|
|
37
|
+
var n, r;
|
|
38
|
+
if (a || // @ts-ignore
|
|
39
|
+
(r = (n = s.current) == null ? void 0 : n.parentElement) != null && r.disabled || !e.isPrimary || x.current && x.current.pointerId !== e.pointerId)
|
|
29
40
|
return !1;
|
|
30
|
-
if (
|
|
31
|
-
return !
|
|
32
|
-
const
|
|
33
|
-
return
|
|
41
|
+
if (e.type === "pointerenter" || e.type === "pointerleave")
|
|
42
|
+
return !R(e);
|
|
43
|
+
const t = e.buttons === 1;
|
|
44
|
+
return R(e) || t;
|
|
34
45
|
},
|
|
35
|
-
[a,
|
|
36
|
-
),
|
|
46
|
+
[a, R]
|
|
47
|
+
), _ = o(
|
|
37
48
|
// @ts-ignore
|
|
38
|
-
({ x:
|
|
39
|
-
const n =
|
|
49
|
+
({ x: e, y: t }) => {
|
|
50
|
+
const n = s.current;
|
|
40
51
|
if (!n) return !1;
|
|
41
|
-
const
|
|
42
|
-
return
|
|
43
|
-
},
|
|
44
|
-
[i]
|
|
45
|
-
), Y = r(
|
|
46
|
-
(t) => {
|
|
47
|
-
s(t) && N(!0);
|
|
52
|
+
const r = n.getBoundingClientRect();
|
|
53
|
+
return e >= r.left && e <= r.right && t >= r.top && t <= r.bottom;
|
|
48
54
|
},
|
|
49
55
|
[s]
|
|
50
|
-
),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
), z = o(
|
|
57
|
+
(e) => {
|
|
58
|
+
i(e) && M(!0);
|
|
59
|
+
},
|
|
60
|
+
[i]
|
|
61
|
+
), B = o(() => {
|
|
62
|
+
const e = s.current;
|
|
63
|
+
if (!e) return;
|
|
64
|
+
const { height: t, width: n } = e.getBoundingClientRect(), r = Math.max(t, n), l = Math.max(
|
|
65
|
+
b * r,
|
|
55
66
|
W
|
|
56
|
-
),
|
|
57
|
-
|
|
58
|
-
}, [
|
|
59
|
-
(
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
62
|
-
const n =
|
|
67
|
+
), m = Math.floor(r * Q), K = Math.sqrt(n ** 2 + t ** 2) + V;
|
|
68
|
+
C.current = m, N.current = (K + l) / m + "", h.current = m + "px";
|
|
69
|
+
}, [s]), L = o(
|
|
70
|
+
(e) => {
|
|
71
|
+
const t = s.current;
|
|
72
|
+
if (!t) return { x: 0, y: 0 };
|
|
73
|
+
const n = t.getBoundingClientRect(), r = window.scrollX + n.left, l = window.scrollY + n.top;
|
|
63
74
|
return {
|
|
64
|
-
x:
|
|
65
|
-
y:
|
|
75
|
+
x: e.pageX - r,
|
|
76
|
+
y: e.pageY - l
|
|
66
77
|
};
|
|
67
78
|
},
|
|
68
|
-
[
|
|
69
|
-
),
|
|
70
|
-
(
|
|
71
|
-
const
|
|
72
|
-
if (!
|
|
79
|
+
[s]
|
|
80
|
+
), k = o(
|
|
81
|
+
(e) => {
|
|
82
|
+
const t = s.current.parentElement;
|
|
83
|
+
if (!t)
|
|
73
84
|
return { startPoint: { x: 0, y: 0 }, endPoint: { x: 0, y: 0 } };
|
|
74
|
-
const n =
|
|
75
|
-
x: (n.width -
|
|
76
|
-
y: (n.height -
|
|
85
|
+
const n = t.getBoundingClientRect(), r = {
|
|
86
|
+
x: (n.width - C.current) / 2,
|
|
87
|
+
y: (n.height - C.current) / 2
|
|
77
88
|
};
|
|
78
89
|
return {
|
|
79
|
-
startPoint:
|
|
80
|
-
endPoint:
|
|
90
|
+
startPoint: L(e),
|
|
91
|
+
endPoint: r
|
|
81
92
|
};
|
|
82
93
|
},
|
|
83
|
-
[
|
|
84
|
-
),
|
|
85
|
-
(
|
|
86
|
-
var
|
|
87
|
-
const
|
|
88
|
-
if (!
|
|
89
|
-
|
|
90
|
-
const { startPoint: n, endPoint:
|
|
91
|
-
|
|
94
|
+
[s, L]
|
|
95
|
+
), d = o(
|
|
96
|
+
(e) => {
|
|
97
|
+
var $;
|
|
98
|
+
const t = y.current;
|
|
99
|
+
if (!t) return;
|
|
100
|
+
S(!0), ($ = E.current) == null || $.cancel(), B();
|
|
101
|
+
const { startPoint: n, endPoint: r } = k(e), l = `${n.x}px, ${n.y}px`, m = `${r.x}px, ${r.y}px`;
|
|
102
|
+
E.current = t.animate(
|
|
92
103
|
{
|
|
93
|
-
height: [
|
|
94
|
-
width: [
|
|
104
|
+
height: [h.current, h.current],
|
|
105
|
+
width: [h.current, h.current],
|
|
95
106
|
transform: [
|
|
96
|
-
`translate(${
|
|
97
|
-
`translate(${
|
|
107
|
+
`translate(${l}) scale(1)`,
|
|
108
|
+
`translate(${m}) scale(${N.current})`
|
|
98
109
|
]
|
|
99
110
|
},
|
|
100
111
|
{
|
|
101
112
|
pseudoElement: "::after",
|
|
102
113
|
duration: p,
|
|
103
|
-
easing:
|
|
104
|
-
fill:
|
|
114
|
+
easing: T,
|
|
115
|
+
fill: ee
|
|
105
116
|
}
|
|
106
117
|
);
|
|
107
118
|
},
|
|
108
|
-
[B, p,
|
|
109
|
-
), u =
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
let
|
|
113
|
-
if (typeof (
|
|
114
|
-
return void
|
|
119
|
+
[B, p, T, k]
|
|
120
|
+
), u = o(() => {
|
|
121
|
+
x.current = void 0, c.current = 0;
|
|
122
|
+
const e = E.current;
|
|
123
|
+
let t = 1 / 0;
|
|
124
|
+
if (typeof (e == null ? void 0 : e.currentTime) == "number" ? t = e.currentTime : e != null && e.currentTime && (t = e.currentTime.to("ms").value), t >= P)
|
|
125
|
+
return void S(!1);
|
|
115
126
|
setTimeout(() => {
|
|
116
|
-
|
|
117
|
-
},
|
|
118
|
-
}, [
|
|
119
|
-
(
|
|
120
|
-
|
|
127
|
+
E.current === e && S(!1);
|
|
128
|
+
}, P - t);
|
|
129
|
+
}, [P]), G = o(
|
|
130
|
+
(e) => {
|
|
131
|
+
i(e) && (M(!1), c.current !== 0 && u());
|
|
121
132
|
},
|
|
122
|
-
[u,
|
|
123
|
-
),
|
|
124
|
-
(
|
|
125
|
-
if (
|
|
133
|
+
[u, i]
|
|
134
|
+
), F = o(
|
|
135
|
+
(e) => {
|
|
136
|
+
if (i(e)) {
|
|
126
137
|
if (c.current === 2) {
|
|
127
138
|
c.current = 3;
|
|
128
139
|
return;
|
|
129
140
|
}
|
|
130
141
|
if (c.current === 1) {
|
|
131
|
-
c.current = 3,
|
|
142
|
+
c.current = 3, d(x.current);
|
|
132
143
|
return;
|
|
133
144
|
}
|
|
134
145
|
}
|
|
135
146
|
},
|
|
136
|
-
[
|
|
137
|
-
),
|
|
138
|
-
async (
|
|
139
|
-
if (
|
|
140
|
-
if (
|
|
141
|
-
c.current = 3,
|
|
147
|
+
[i, d]
|
|
148
|
+
), X = o(
|
|
149
|
+
async (e) => {
|
|
150
|
+
if (i(e)) {
|
|
151
|
+
if (x.current = e, !R(e)) {
|
|
152
|
+
c.current = 3, d(e);
|
|
142
153
|
return;
|
|
143
154
|
}
|
|
144
|
-
|
|
145
|
-
setTimeout(
|
|
146
|
-
}), c.current === 1 && (c.current = 2,
|
|
155
|
+
A.current && !_(e) || (A.current = !1, c.current = 1, await new Promise((t) => {
|
|
156
|
+
setTimeout(t, w);
|
|
157
|
+
}), c.current === 1 && (c.current = 2, d(e)));
|
|
147
158
|
}
|
|
148
159
|
},
|
|
149
|
-
[
|
|
150
|
-
),
|
|
160
|
+
[i, R, _, d, w]
|
|
161
|
+
), Y = o(() => {
|
|
151
162
|
if (!a) {
|
|
152
163
|
if (c.current === 3) {
|
|
153
164
|
u();
|
|
154
165
|
return;
|
|
155
166
|
}
|
|
156
|
-
c.current === 0 && (
|
|
167
|
+
c.current === 0 && (d(), u());
|
|
157
168
|
}
|
|
158
|
-
}, [a, u,
|
|
159
|
-
(
|
|
160
|
-
|
|
169
|
+
}, [a, u, d]), O = o(
|
|
170
|
+
(e) => {
|
|
171
|
+
i(e) && u();
|
|
161
172
|
},
|
|
162
|
-
[u,
|
|
163
|
-
),
|
|
164
|
-
a || (
|
|
173
|
+
[u, i]
|
|
174
|
+
), j = o(() => {
|
|
175
|
+
a || (A.current = !0, u());
|
|
165
176
|
}, [a, u]);
|
|
166
|
-
return /* @__PURE__ */
|
|
177
|
+
return /* @__PURE__ */ q(
|
|
167
178
|
"div",
|
|
168
179
|
{
|
|
169
|
-
ref:
|
|
170
|
-
className: `salty-ripple${
|
|
171
|
-
style:
|
|
180
|
+
ref: s,
|
|
181
|
+
className: `salty-ripple${v ? ` ${v}` : ""}`,
|
|
182
|
+
style: U,
|
|
172
183
|
"aria-hidden": "true",
|
|
173
|
-
|
|
174
|
-
onContextMenu: Z,
|
|
175
|
-
onPointerCancel: H,
|
|
176
|
-
onPointerDown: j,
|
|
177
|
-
onPointerEnter: Y,
|
|
178
|
-
onPointerLeave: O,
|
|
179
|
-
onPointerUp: U,
|
|
180
|
-
children: /* @__PURE__ */ k(
|
|
184
|
+
children: /* @__PURE__ */ q(
|
|
181
185
|
"div",
|
|
182
186
|
{
|
|
183
|
-
ref:
|
|
184
|
-
className: `salty-ripple-surface${
|
|
187
|
+
ref: y,
|
|
188
|
+
className: `salty-ripple-surface${Z ? " --hover" : ""}${J ? " --press" : ""}`
|
|
185
189
|
}
|
|
186
190
|
)
|
|
187
191
|
}
|
|
188
192
|
);
|
|
189
193
|
};
|
|
190
194
|
export {
|
|
191
|
-
|
|
195
|
+
ne as Ripple
|
|
192
196
|
};
|
package/dist/ripple.css
CHANGED