m3-ripple 1.1.1 → 1.1.2
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 +8 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -41
- package/dist/ripple.css +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("react/jsx-runtime"),n=require("react"),U=.2,Z=12,J=75,K=.35,Q="forwards",V=({hoverOpacity:P,pressedOpacity:k,disabled:a=!1,className:w="",style:X,easing:E,duration:f=150,minimumPressDuration:C=225,touchDelay:g=150})=>{const[Y,A]=n.useState(!1),[D,I]=n.useState(!1),u=n.useRef(null),x=n.useRef(null),m=n.useRef(""),M=n.useRef(""),S=n.useRef(0),y=n.useRef(void 0),s=n.useRef(0),R=n.useRef(void 0),T=n.useRef(!1);n.useEffect(()=>{if(!x.current)return;const e=x.current.style;P!==void 0&&e.setProperty("--ripple-hover-opacity",P+""),k!==void 0&&e.setProperty("--ripple-pressed-opacity",k+""),f!==void 0&&f!==150&&e.setProperty("--ripple-duration",f+"ms")},[P,k,f]),n.useEffect(()=>{var c;const e=(c=u.current)==null?void 0:c.parentElement;if(!e)return;const t=(r,o)=>e.addEventListener(r,o,!0);return t("click",G),t("contextmenu",F),t("pointercancel",q),t("pointerdown",j),t("pointerenter",v),t("pointerleave",B),t("pointerup",L),()=>{const r=(o,d)=>e.removeEventListener(o,d,!0);r("click",G),r("contextmenu",F),r("pointercancel",q),r("pointerdown",j),r("pointerenter",v),r("pointerleave",B),r("pointerup",L)}},[a,E,f,C,g]);const h=n.useCallback(({pointerType:e})=>e==="touch",[]),i=n.useCallback(e=>{var c,r;if(a||(r=(c=u.current)==null?void 0:c.parentElement)!=null&&r.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]),$=n.useCallback(({x:e,y:t})=>{const c=u.current;if(!c)return!1;const r=c.getBoundingClientRect();return e>=r.left&&e<=r.right&&t>=r.top&&t<=r.bottom},[u]),v=n.useCallback(e=>{i(e)&&A(!0)},[i]),N=n.useCallback(()=>{const e=u.current;if(!e)return;const{height:t,width:c}=e.getBoundingClientRect(),r=Math.max(t,c),o=Math.max(K*r,J),d=Math.floor(r*U),H=Math.sqrt(c**2+t**2)+Z;S.current=d,M.current=(H+o)/d+"",m.current=d+"px"},[u]),_=n.useCallback(e=>{const t=u.current;if(!t)return{x:0,y:0};const c=t.getBoundingClientRect(),r=window.scrollX+c.left,o=window.scrollY+c.top;return{x:e.pageX-r,y:e.pageY-o}},[u]),z=n.useCallback(e=>{var o;const t=(o=u.current)==null?void 0:o.parentElement;if(!t)return{startPoint:{x:0,y:0},endPoint:{x:0,y:0}};const c=t.getBoundingClientRect(),r={x:(c.width-S.current)/2,y:(c.height-S.current)/2};return{startPoint:e?_(e):r,endPoint:r}},[u,_]),p=n.useCallback(e=>{var b;const t=x.current;if(!t)return;I(!0),(b=y.current)==null||b.cancel(),N();const{startPoint:c,endPoint:r}=z(e),o=`${c.x}px, ${c.y}px`,d=`${r.x}px, ${r.y}px`;y.current=t.animate({height:[m.current,m.current],width:[m.current,m.current],transform:[`translate(${o}) scale(1)`,`translate(${d}) scale(${M.current})`]},{pseudoElement:"::after",duration:f,easing:E,fill:Q})},[N,f,E,z]),l=n.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=n.useCallback(e=>{i(e)&&(A(!1),s.current!==0&&l())},[l,i]),L=n.useCallback(e=>{if(i(e)){if(s.current===2){s.current=3;return}if(s.current===1){s.current=3,p(R.current);return}}},[i,p]),j=n.useCallback(async e=>{if(i(e)){if(R.current=e,!h(e)){s.current=3,p(e);return}T.current&&!$(e)||(T.current=!1,s.current=1,await new Promise(t=>{setTimeout(t,g)}),s.current===1&&(s.current=2,p(e)))}},[i,h,$,p,g]),G=n.useCallback(()=>{if(!a){if(s.current===3){l();return}s.current===0&&(p(),l())}},[a,l,p]),q=n.useCallback(e=>{i(e)&&l()},[l,i]),F=n.useCallback(()=>{a||(T.current=!0,l())},[a,l]);return O.jsx("div",{ref:u,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":"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,
|
|
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,4CAwVb,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -4,14 +4,14 @@ const Q = 0.2, V = 12, W = 75, b = 0.35, ee = "forwards", ne = ({
|
|
|
4
4
|
hoverOpacity: I,
|
|
5
5
|
pressedOpacity: g,
|
|
6
6
|
disabled: a = !1,
|
|
7
|
-
className:
|
|
7
|
+
className: M = "",
|
|
8
8
|
style: U,
|
|
9
9
|
easing: T,
|
|
10
10
|
duration: p = 150,
|
|
11
11
|
minimumPressDuration: P = 225,
|
|
12
12
|
touchDelay: w = 150
|
|
13
13
|
}) => {
|
|
14
|
-
const [Z,
|
|
14
|
+
const [Z, N] = D(!1), [J, S] = D(!1), i = f(null), y = f(null), h = f(""), v = f(""), C = f(0), E = f(void 0), c = f(
|
|
15
15
|
0
|
|
16
16
|
/* INACTIVE */
|
|
17
17
|
), x = f(void 0), A = f(!1);
|
|
@@ -21,22 +21,22 @@ const Q = 0.2, V = 12, W = 75, b = 0.35, ee = "forwards", ne = ({
|
|
|
21
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
22
|
}, [I, g, p]), H(() => {
|
|
23
23
|
var n;
|
|
24
|
-
const e = (n =
|
|
24
|
+
const e = (n = i.current) == null ? void 0 : n.parentElement;
|
|
25
25
|
if (!e) return;
|
|
26
|
-
const t = (r,
|
|
26
|
+
const t = (r, s) => e.addEventListener(r, s, !0);
|
|
27
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 = (
|
|
28
|
+
const r = (s, m) => e.removeEventListener(s, m, !0);
|
|
29
29
|
r("click", Y), r("contextmenu", j), r("pointercancel", O), r("pointerdown", X), r("pointerenter", z), r("pointerleave", G), r("pointerup", F);
|
|
30
30
|
};
|
|
31
31
|
}, [a, T, p, P, w]);
|
|
32
32
|
const R = o(
|
|
33
33
|
({ pointerType: e }) => e === "touch",
|
|
34
34
|
[]
|
|
35
|
-
),
|
|
35
|
+
), u = o(
|
|
36
36
|
(e) => {
|
|
37
37
|
var n, r;
|
|
38
38
|
if (a || // @ts-ignore
|
|
39
|
-
(r = (n =
|
|
39
|
+
(r = (n = i.current) == null ? void 0 : n.parentElement) != null && r.disabled || !e.isPrimary || x.current && x.current.pointerId !== e.pointerId)
|
|
40
40
|
return !1;
|
|
41
41
|
if (e.type === "pointerenter" || e.type === "pointerleave")
|
|
42
42
|
return !R(e);
|
|
@@ -47,39 +47,40 @@ const Q = 0.2, V = 12, W = 75, b = 0.35, ee = "forwards", ne = ({
|
|
|
47
47
|
), _ = o(
|
|
48
48
|
// @ts-ignore
|
|
49
49
|
({ x: e, y: t }) => {
|
|
50
|
-
const n =
|
|
50
|
+
const n = i.current;
|
|
51
51
|
if (!n) return !1;
|
|
52
52
|
const r = n.getBoundingClientRect();
|
|
53
53
|
return e >= r.left && e <= r.right && t >= r.top && t <= r.bottom;
|
|
54
54
|
},
|
|
55
|
-
[
|
|
55
|
+
[i]
|
|
56
56
|
), z = o(
|
|
57
57
|
(e) => {
|
|
58
|
-
|
|
58
|
+
u(e) && N(!0);
|
|
59
59
|
},
|
|
60
|
-
[
|
|
60
|
+
[u]
|
|
61
61
|
), B = o(() => {
|
|
62
|
-
const e =
|
|
62
|
+
const e = i.current;
|
|
63
63
|
if (!e) return;
|
|
64
|
-
const { height: t, width: n } = e.getBoundingClientRect(), r = Math.max(t, n),
|
|
64
|
+
const { height: t, width: n } = e.getBoundingClientRect(), r = Math.max(t, n), s = Math.max(
|
|
65
65
|
b * r,
|
|
66
66
|
W
|
|
67
67
|
), m = Math.floor(r * Q), K = Math.sqrt(n ** 2 + t ** 2) + V;
|
|
68
|
-
C.current = m,
|
|
69
|
-
}, [
|
|
68
|
+
C.current = m, v.current = (K + s) / m + "", h.current = m + "px";
|
|
69
|
+
}, [i]), L = o(
|
|
70
70
|
(e) => {
|
|
71
|
-
const t =
|
|
71
|
+
const t = i.current;
|
|
72
72
|
if (!t) return { x: 0, y: 0 };
|
|
73
|
-
const n = t.getBoundingClientRect(), r = window.scrollX + n.left,
|
|
73
|
+
const n = t.getBoundingClientRect(), r = window.scrollX + n.left, s = window.scrollY + n.top;
|
|
74
74
|
return {
|
|
75
75
|
x: e.pageX - r,
|
|
76
|
-
y: e.pageY -
|
|
76
|
+
y: e.pageY - s
|
|
77
77
|
};
|
|
78
78
|
},
|
|
79
|
-
[
|
|
79
|
+
[i]
|
|
80
80
|
), k = o(
|
|
81
81
|
(e) => {
|
|
82
|
-
|
|
82
|
+
var s;
|
|
83
|
+
const t = (s = i.current) == null ? void 0 : s.parentElement;
|
|
83
84
|
if (!t)
|
|
84
85
|
return { startPoint: { x: 0, y: 0 }, endPoint: { x: 0, y: 0 } };
|
|
85
86
|
const n = t.getBoundingClientRect(), r = {
|
|
@@ -87,25 +88,26 @@ const Q = 0.2, V = 12, W = 75, b = 0.35, ee = "forwards", ne = ({
|
|
|
87
88
|
y: (n.height - C.current) / 2
|
|
88
89
|
};
|
|
89
90
|
return {
|
|
90
|
-
|
|
91
|
+
// If using keyboard, start in the center
|
|
92
|
+
startPoint: e ? L(e) : r,
|
|
91
93
|
endPoint: r
|
|
92
94
|
};
|
|
93
95
|
},
|
|
94
|
-
[
|
|
96
|
+
[i, L]
|
|
95
97
|
), d = o(
|
|
96
98
|
(e) => {
|
|
97
99
|
var $;
|
|
98
100
|
const t = y.current;
|
|
99
101
|
if (!t) return;
|
|
100
102
|
S(!0), ($ = E.current) == null || $.cancel(), B();
|
|
101
|
-
const { startPoint: n, endPoint: r } = k(e),
|
|
103
|
+
const { startPoint: n, endPoint: r } = k(e), s = `${n.x}px, ${n.y}px`, m = `${r.x}px, ${r.y}px`;
|
|
102
104
|
E.current = t.animate(
|
|
103
105
|
{
|
|
104
106
|
height: [h.current, h.current],
|
|
105
107
|
width: [h.current, h.current],
|
|
106
108
|
transform: [
|
|
107
|
-
`translate(${
|
|
108
|
-
`translate(${m}) scale(${
|
|
109
|
+
`translate(${s}) scale(1)`,
|
|
110
|
+
`translate(${m}) scale(${v.current})`
|
|
109
111
|
]
|
|
110
112
|
},
|
|
111
113
|
{
|
|
@@ -117,7 +119,7 @@ const Q = 0.2, V = 12, W = 75, b = 0.35, ee = "forwards", ne = ({
|
|
|
117
119
|
);
|
|
118
120
|
},
|
|
119
121
|
[B, p, T, k]
|
|
120
|
-
),
|
|
122
|
+
), l = o(() => {
|
|
121
123
|
x.current = void 0, c.current = 0;
|
|
122
124
|
const e = E.current;
|
|
123
125
|
let t = 1 / 0;
|
|
@@ -128,12 +130,12 @@ const Q = 0.2, V = 12, W = 75, b = 0.35, ee = "forwards", ne = ({
|
|
|
128
130
|
}, P - t);
|
|
129
131
|
}, [P]), G = o(
|
|
130
132
|
(e) => {
|
|
131
|
-
|
|
133
|
+
u(e) && (N(!1), c.current !== 0 && l());
|
|
132
134
|
},
|
|
133
|
-
[
|
|
135
|
+
[l, u]
|
|
134
136
|
), F = o(
|
|
135
137
|
(e) => {
|
|
136
|
-
if (
|
|
138
|
+
if (u(e)) {
|
|
137
139
|
if (c.current === 2) {
|
|
138
140
|
c.current = 3;
|
|
139
141
|
return;
|
|
@@ -144,10 +146,10 @@ const Q = 0.2, V = 12, W = 75, b = 0.35, ee = "forwards", ne = ({
|
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
},
|
|
147
|
-
[
|
|
149
|
+
[u, d]
|
|
148
150
|
), X = o(
|
|
149
151
|
async (e) => {
|
|
150
|
-
if (
|
|
152
|
+
if (u(e)) {
|
|
151
153
|
if (x.current = e, !R(e)) {
|
|
152
154
|
c.current = 3, d(e);
|
|
153
155
|
return;
|
|
@@ -157,28 +159,28 @@ const Q = 0.2, V = 12, W = 75, b = 0.35, ee = "forwards", ne = ({
|
|
|
157
159
|
}), c.current === 1 && (c.current = 2, d(e)));
|
|
158
160
|
}
|
|
159
161
|
},
|
|
160
|
-
[
|
|
162
|
+
[u, R, _, d, w]
|
|
161
163
|
), Y = o(() => {
|
|
162
164
|
if (!a) {
|
|
163
165
|
if (c.current === 3) {
|
|
164
|
-
|
|
166
|
+
l();
|
|
165
167
|
return;
|
|
166
168
|
}
|
|
167
|
-
c.current === 0 && (d(),
|
|
169
|
+
c.current === 0 && (d(), l());
|
|
168
170
|
}
|
|
169
|
-
}, [a,
|
|
171
|
+
}, [a, l, d]), O = o(
|
|
170
172
|
(e) => {
|
|
171
|
-
|
|
173
|
+
u(e) && l();
|
|
172
174
|
},
|
|
173
|
-
[
|
|
175
|
+
[l, u]
|
|
174
176
|
), j = o(() => {
|
|
175
|
-
a || (A.current = !0,
|
|
176
|
-
}, [a,
|
|
177
|
+
a || (A.current = !0, l());
|
|
178
|
+
}, [a, l]);
|
|
177
179
|
return /* @__PURE__ */ q(
|
|
178
180
|
"div",
|
|
179
181
|
{
|
|
180
|
-
ref:
|
|
181
|
-
className: `salty-ripple${
|
|
182
|
+
ref: i,
|
|
183
|
+
className: `salty-ripple${M ? ` ${M}` : ""}`,
|
|
182
184
|
style: U,
|
|
183
185
|
"aria-hidden": "true",
|
|
184
186
|
children: /* @__PURE__ */ q(
|
package/dist/ripple.css
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
.salty-ripple .salty-ripple-surface::before {
|
|
38
38
|
width: 100%;
|
|
39
39
|
height: 100%;
|
|
40
|
-
background-color: currentColor;
|
|
40
|
+
background-color: var(--ripple-color, currentColor);
|
|
41
41
|
inset: 0;
|
|
42
42
|
transition:
|
|
43
43
|
opacity var(--ripple-duration, 150ms),
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
inset: 0;
|
|
49
49
|
background: radial-gradient(
|
|
50
50
|
closest-side,
|
|
51
|
-
currentColor max(100% - 70px, 65%),
|
|
51
|
+
var(--ripple-color, currentColor) max(100% - 70px, 65%),
|
|
52
52
|
transparent 100%
|
|
53
53
|
);
|
|
54
54
|
transform-origin: center center;
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
.salty-ripple .salty-ripple-surface.--hover::before {
|
|
59
|
-
background-color: currentColor;
|
|
59
|
+
background-color: var(--ripple-color, currentColor);
|
|
60
60
|
opacity: var(--ripple-hover-opacity, 0.08);
|
|
61
61
|
}
|
|
62
62
|
|