@supermousejs/utils 2.1.1 → 2.2.0
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 +74 -57
- package/LICENSE.md +21 -21
- package/README.md +14 -15
- package/dist/css.d.ts +12 -0
- package/dist/css.d.ts.map +1 -0
- package/dist/doctor.d.ts +5 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/dom.d.ts +58 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/effects.d.ts +14 -0
- package/dist/effects.d.ts.map +1 -0
- package/dist/index.d.ts +10 -227
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +92 -92
- package/dist/index.umd.js +1 -7
- package/dist/layers.d.ts +15 -0
- package/dist/layers.d.ts.map +1 -0
- package/dist/math.d.ts +38 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/options.d.ts +11 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/plugin.d.ts +34 -0
- package/dist/plugin.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/css.ts +11 -11
- package/src/doctor.ts +47 -49
- package/src/dom.ts +64 -50
- package/src/effects.ts +5 -6
- package/src/index.ts +10 -10
- package/src/layers.ts +17 -17
- package/src/math.ts +1 -1
- package/src/options.ts +22 -22
- package/src/plugin.ts +16 -16
- package/tsconfig.json +9 -13
- package/tsconfig.tsbuildinfo +1 -0
- package/vite.config.ts +22 -22
package/dist/index.mjs
CHANGED
|
@@ -1,68 +1,61 @@
|
|
|
1
1
|
function y(e, t, n) {
|
|
2
2
|
return e + (t - e) * n;
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
return y(e, t, 1 - Math.exp(-n *
|
|
4
|
+
function v(e, t, n, r) {
|
|
5
|
+
return y(e, t, 1 - Math.exp(-n * r));
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
return e +
|
|
7
|
+
function C(e, t, n) {
|
|
8
|
+
const r = ((t - e) % 360 + 540) % 360 - 180;
|
|
9
|
+
return e + r * n;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function O(e, t) {
|
|
12
12
|
return Math.random() * (t - e) + e;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function m(e, t, n) {
|
|
15
15
|
return Math.min(Math.max(e, t), n);
|
|
16
16
|
}
|
|
17
|
-
function b(e, t, n = 0,
|
|
18
|
-
const
|
|
19
|
-
return Math.sqrt(
|
|
17
|
+
function b(e, t, n = 0, r = 0) {
|
|
18
|
+
const o = e - n, c = t - r;
|
|
19
|
+
return Math.sqrt(o * o + c * c);
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function h(e, t) {
|
|
22
22
|
return Math.atan2(t, e) * (180 / Math.PI);
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const j = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
25
25
|
__proto__: null,
|
|
26
|
-
angle:
|
|
27
|
-
clamp:
|
|
28
|
-
damp:
|
|
26
|
+
angle: h,
|
|
27
|
+
clamp: m,
|
|
28
|
+
damp: v,
|
|
29
29
|
dist: b,
|
|
30
30
|
lerp: y,
|
|
31
|
-
lerpAngle:
|
|
32
|
-
random:
|
|
33
|
-
}, Symbol.toStringTag, { value: "Module" }))
|
|
31
|
+
lerpAngle: C,
|
|
32
|
+
random: O
|
|
33
|
+
}, Symbol.toStringTag, { value: "Module" })), _ = (e, t) => {
|
|
34
|
+
if (typeof document > "u" || document.getElementById(e)) return;
|
|
35
|
+
const n = document.createElement("style");
|
|
36
|
+
n.id = e, n.innerHTML = t, document.head.appendChild(n);
|
|
37
|
+
}, p = /* @__PURE__ */ new WeakMap();
|
|
34
38
|
function a(e, t) {
|
|
35
|
-
|
|
39
|
+
if (typeof document > "u" || !e) return;
|
|
40
|
+
let n = p.get(e);
|
|
41
|
+
n || (n = {}, p.set(e, n));
|
|
42
|
+
for (const r in t) {
|
|
43
|
+
const o = t[r];
|
|
44
|
+
n[r] !== o && (e.style[r] = o, n[r] = o);
|
|
45
|
+
}
|
|
36
46
|
}
|
|
37
|
-
const p = /* @__PURE__ */ new WeakMap();
|
|
38
47
|
function u(e, t, n) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
e
|
|
44
|
-
translate3d(${t}px, ${n}px, 0)
|
|
45
|
-
translate(-50%, -50%)
|
|
46
|
-
rotate(${o}deg)
|
|
47
|
-
skew(${s}deg, ${l}deg)
|
|
48
|
-
scale(${r}, ${i})
|
|
49
|
-
`;
|
|
48
|
+
a(e, { [t]: n });
|
|
49
|
+
}
|
|
50
|
+
function M(e, t, n, r = 0, o = 1, c = 1, s = 0, l = 0) {
|
|
51
|
+
const i = `translate3d(${t}px, ${n}px, 0) translate(-50%, -50%) rotate(${r}deg) skew(${s}deg, ${l}deg) scale(${o}, ${c})`;
|
|
52
|
+
u(e, "transform", i);
|
|
50
53
|
}
|
|
51
54
|
function w(e, t = document.body) {
|
|
52
55
|
const n = e.getBoundingClientRect();
|
|
53
56
|
if (t !== document.body) {
|
|
54
|
-
const
|
|
55
|
-
return
|
|
56
|
-
x: r,
|
|
57
|
-
y: i,
|
|
58
|
-
width: n.width,
|
|
59
|
-
height: n.height,
|
|
60
|
-
top: i,
|
|
61
|
-
left: r,
|
|
62
|
-
right: r + n.width,
|
|
63
|
-
bottom: i + n.height,
|
|
64
|
-
toJSON: () => ({})
|
|
65
|
-
};
|
|
57
|
+
const r = t.getBoundingClientRect(), o = n.left - r.left, c = n.top - r.top;
|
|
58
|
+
return new DOMRect(o, c, n.width, n.height);
|
|
66
59
|
}
|
|
67
60
|
return n;
|
|
68
61
|
}
|
|
@@ -78,7 +71,7 @@ function d(e = "div") {
|
|
|
78
71
|
willChange: "transform"
|
|
79
72
|
}), t;
|
|
80
73
|
}
|
|
81
|
-
function
|
|
74
|
+
function R(e, t) {
|
|
82
75
|
const n = d("div");
|
|
83
76
|
return a(n, {
|
|
84
77
|
width: `${e}px`,
|
|
@@ -87,34 +80,35 @@ function A(e, t) {
|
|
|
87
80
|
backgroundColor: t
|
|
88
81
|
}), n;
|
|
89
82
|
}
|
|
90
|
-
function
|
|
83
|
+
function T() {
|
|
91
84
|
return d("div");
|
|
92
85
|
}
|
|
93
|
-
const
|
|
86
|
+
const z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
94
87
|
__proto__: null,
|
|
95
88
|
applyStyles: a,
|
|
96
89
|
createActor: d,
|
|
97
|
-
createCircle:
|
|
98
|
-
createDiv:
|
|
90
|
+
createCircle: R,
|
|
91
|
+
createDiv: T,
|
|
92
|
+
injectStyles: _,
|
|
99
93
|
projectRect: w,
|
|
100
94
|
setStyle: u,
|
|
101
|
-
setTransform:
|
|
95
|
+
setTransform: M
|
|
102
96
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
103
|
-
function
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
97
|
+
function x(e, t, n = 4e-3, r = 0.5) {
|
|
98
|
+
const o = b(e, t);
|
|
99
|
+
if (o < 0.1)
|
|
106
100
|
return { rotation: 0, scaleX: 1, scaleY: 1 };
|
|
107
|
-
const
|
|
101
|
+
const c = h(e, t), s = m(o * n, 0, r), l = 1 + s, i = 1 - s * 0.5;
|
|
108
102
|
return {
|
|
109
|
-
rotation:
|
|
103
|
+
rotation: c,
|
|
110
104
|
scaleX: l,
|
|
111
|
-
scaleY:
|
|
105
|
+
scaleY: i
|
|
112
106
|
};
|
|
113
107
|
}
|
|
114
|
-
const
|
|
108
|
+
const P = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
115
109
|
__proto__: null,
|
|
116
|
-
getVelocityDistortion:
|
|
117
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
110
|
+
getVelocityDistortion: x
|
|
111
|
+
}, Symbol.toStringTag, { value: "Module" })), D = {
|
|
118
112
|
/** The top-most layer. For text, tooltips, and crucial UI. */
|
|
119
113
|
OVERLAY: "400",
|
|
120
114
|
/** The main cursor layer. For the primary Dot/Pointer. */
|
|
@@ -123,7 +117,7 @@ const z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
123
117
|
FOLLOWER: "200",
|
|
124
118
|
/** The background layer. For trails, sparkles, and particles. */
|
|
125
119
|
TRACE: "100"
|
|
126
|
-
},
|
|
120
|
+
}, L = {
|
|
127
121
|
/** Good for entrance animations (starts fast, slows down) */
|
|
128
122
|
EASE_OUT_EXPO: "cubic-bezier(0.16, 1, 0.3, 1)",
|
|
129
123
|
/** Good for elastic/bouncy UI elements */
|
|
@@ -131,75 +125,81 @@ const z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
131
125
|
/** Standard smooth movement */
|
|
132
126
|
SMOOTH: "ease-out"
|
|
133
127
|
};
|
|
134
|
-
function
|
|
128
|
+
function A(e, t) {
|
|
135
129
|
return e === void 0 ? () => t : typeof e == "function" ? e : () => e;
|
|
136
130
|
}
|
|
137
131
|
function $(e) {
|
|
138
132
|
return "create" in e && typeof e.create == "function";
|
|
139
133
|
}
|
|
140
|
-
function
|
|
141
|
-
const n = t.name || e.name,
|
|
134
|
+
function k(e, t = {}) {
|
|
135
|
+
const n = t.name || e.name, r = t.isEnabled ?? !0;
|
|
142
136
|
if ($(e)) {
|
|
143
|
-
let
|
|
144
|
-
const
|
|
137
|
+
let o;
|
|
138
|
+
const c = [];
|
|
145
139
|
if (e.styles)
|
|
146
140
|
for (const [s, l] of Object.entries(e.styles)) {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
const f =
|
|
141
|
+
const i = A(t[s], void 0), g = l;
|
|
142
|
+
c.push((E, S) => {
|
|
143
|
+
const f = i(E.state);
|
|
150
144
|
f !== void 0 && u(S, g, f);
|
|
151
145
|
});
|
|
152
146
|
}
|
|
153
147
|
return {
|
|
154
148
|
name: n,
|
|
155
|
-
isEnabled:
|
|
149
|
+
isEnabled: r,
|
|
156
150
|
install(s) {
|
|
157
|
-
|
|
151
|
+
o = e.create(s), e.selector && s.registerHoverTarget(e.selector), this.isEnabled === !1 && (o.style.opacity = "0"), s.container.appendChild(o);
|
|
158
152
|
},
|
|
159
153
|
update(s, l) {
|
|
160
|
-
if (
|
|
161
|
-
for (let
|
|
162
|
-
i
|
|
163
|
-
e.update?.(s,
|
|
154
|
+
if (o) {
|
|
155
|
+
for (let i = 0; i < c.length; i++)
|
|
156
|
+
c[i](s, o);
|
|
157
|
+
e.update?.(s, o, l);
|
|
164
158
|
}
|
|
165
159
|
},
|
|
166
160
|
onDisable(s) {
|
|
167
|
-
|
|
161
|
+
o && (u(o, "opacity", 0), e.onDisable?.(s, o));
|
|
168
162
|
},
|
|
169
163
|
onEnable(s) {
|
|
170
|
-
|
|
164
|
+
o && (u(o, "opacity", 1), e.onEnable?.(s, o));
|
|
171
165
|
},
|
|
172
166
|
destroy() {
|
|
173
|
-
|
|
167
|
+
o && (e.cleanup?.(o), o.remove());
|
|
174
168
|
}
|
|
175
169
|
};
|
|
176
170
|
} else
|
|
177
171
|
return {
|
|
178
172
|
...e,
|
|
179
173
|
name: n,
|
|
180
|
-
isEnabled:
|
|
174
|
+
isEnabled: r
|
|
181
175
|
};
|
|
182
176
|
}
|
|
183
|
-
function
|
|
184
|
-
if (console.group("🐭 Supermouse Doctor"), !Array.from(document.querySelectorAll("style")).some(
|
|
185
|
-
|
|
177
|
+
function I() {
|
|
178
|
+
if (console.group("🐭 Supermouse Doctor"), !Array.from(document.querySelectorAll("style")).some(
|
|
179
|
+
(r) => r.id.startsWith("supermouse-style-")
|
|
180
|
+
)) {
|
|
181
|
+
console.warn("[x] Supermouse has not been initialized yet."), console.warn(" Please call doctor() after `new Supermouse()` has run."), console.groupEnd();
|
|
186
182
|
return;
|
|
187
183
|
}
|
|
188
184
|
const t = [];
|
|
189
|
-
document.querySelectorAll('[style*="cursor"]').forEach((
|
|
190
|
-
|
|
191
|
-
el:
|
|
185
|
+
document.querySelectorAll('[style*="cursor"]').forEach((r) => {
|
|
186
|
+
r.getAttribute("style")?.includes("cursor: none") || t.push({
|
|
187
|
+
el: r,
|
|
192
188
|
reason: 'Element has inline "cursor" style. Remove it and let Supermouse handle state.'
|
|
193
189
|
});
|
|
194
|
-
}), document.body.style.cursor !== "none" && console.warn(
|
|
190
|
+
}), document.body.style.cursor !== "none" && console.warn(
|
|
191
|
+
'[Global] document.body.style.cursor is not "none". Ensure { hideCursor: true } is passed to Supermouse.'
|
|
192
|
+
), t.length > 0 ? (console.warn(`Found ${t.length} potential conflicts:`), t.forEach((r) => console.warn(`[${r.reason}]`, r.el)), console.info(
|
|
193
|
+
'Tip: Avoid setting "cursor: pointer" manually. Use plugins or `rules` config instead.'
|
|
194
|
+
)) : console.log("[ok] No obvious inline-style conflicts found."), console.groupEnd();
|
|
195
195
|
}
|
|
196
196
|
export {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
197
|
+
L as Easings,
|
|
198
|
+
D as Layers,
|
|
199
|
+
k as definePlugin,
|
|
200
|
+
I as doctor,
|
|
201
|
+
z as dom,
|
|
202
|
+
P as effects,
|
|
203
|
+
j as math,
|
|
204
|
+
A as normalize
|
|
205
205
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
translate3d(${t}px, ${n}px, 0)
|
|
3
|
-
translate(-50%, -50%)
|
|
4
|
-
rotate(${o}deg)
|
|
5
|
-
skew(${s}deg, ${c}deg)
|
|
6
|
-
scale(${r}, ${i})
|
|
7
|
-
`}function C(e,t=document.body){const n=e.getBoundingClientRect();if(t!==document.body){const o=t.getBoundingClientRect(),r=n.left-o.left,i=n.top-o.top;return{x:r,y:i,width:n.width,height:n.height,top:i,left:r,right:r+n.width,bottom:i+n.height,toJSON:()=>({})}}return n}function y(e="div"){const t=document.createElement(e);return f(t,{position:"absolute",top:"0",left:"0",pointerEvents:"none",boxSizing:"border-box",display:"block",willChange:"transform"}),t}function w(e,t){const n=y("div");return f(n,{width:`${e}px`,height:`${e}px`,borderRadius:"50%",backgroundColor:t}),n}function M(){return y("div")}const A=Object.freeze(Object.defineProperty({__proto__:null,applyStyles:f,createActor:y,createCircle:w,createDiv:M,projectRect:C,setStyle:d,setTransform:v},Symbol.toStringTag,{value:"Module"}));function R(e,t,n=.004,o=.5){const r=m(e,t);if(r<.1)return{rotation:0,scaleX:1,scaleY:1};const i=b(e,t),s=h(r*n,0,o),c=1+s,u=1-s*.5;return{rotation:i,scaleX:c,scaleY:u}}const j=Object.freeze(Object.defineProperty({__proto__:null,getVelocityDistortion:R},Symbol.toStringTag,{value:"Module"})),$={OVERLAY:"400",CURSOR:"300",FOLLOWER:"200",TRACE:"100"},z={EASE_OUT_EXPO:"cubic-bezier(0.16, 1, 0.3, 1)",ELASTIC_OUT:"cubic-bezier(0.34, 1.56, 0.64, 1)",SMOOTH:"ease-out"};function g(e,t){return e===void 0?()=>t:typeof e=="function"?e:()=>e}function P(e){return"create"in e&&typeof e.create=="function"}function L(e,t={}){const n=t.name||e.name,o=t.isEnabled??!0;if(P(e)){let r;const i=[];if(e.styles)for(const[s,c]of Object.entries(e.styles)){const u=g(t[s],void 0),U=c;i.push((k,x)=>{const E=u(k.state);E!==void 0&&d(x,U,E)})}return{name:n,isEnabled:o,install(s){r=e.create(s),e.selector&&s.registerHoverTarget(e.selector),this.isEnabled===!1&&(r.style.opacity="0"),s.container.appendChild(r)},update(s,c){if(r){for(let u=0;u<i.length;u++)i[u](s,r);e.update?.(s,r,c)}},onDisable(s){r&&(d(r,"opacity",0),e.onDisable?.(s,r))},onEnable(s){r&&(d(r,"opacity",1),e.onEnable?.(s,r))},destroy(){r&&(e.cleanup?.(r),r.remove())}}}else return{...e,name:n,isEnabled:o}}function D(){if(console.group("🐭 Supermouse Doctor"),!Array.from(document.querySelectorAll("style")).some(o=>o.id.startsWith("supermouse-style-"))){console.warn("❌ Supermouse has not been initialized yet."),console.warn(' Please call doctor() AFTER "new Supermouse()" has run.'),console.groupEnd();return}const t=[];document.querySelectorAll('[style*="cursor"]').forEach(o=>{o.getAttribute("style")?.includes("cursor: none")||t.push({el:o,reason:'Element has inline "cursor" style. Remove it and let Supermouse handle state.'})}),document.body.style.cursor!=="none"&&console.warn('[Global] document.body.style.cursor is not "none". Ensure { hideCursor: true } is passed to Supermouse.'),t.length>0?(console.warn(`Found ${t.length} potential conflicts:`),t.forEach(o=>console.warn(`[${o.reason}]`,o.el)),console.info('Tip: Avoid setting "cursor: pointer" manually. Use plugins or "rules" config instead.')):console.log("✅ No obvious inline-style conflicts found."),console.groupEnd()}l.Easings=z,l.Layers=$,l.definePlugin=L,l.doctor=D,l.dom=A,l.effects=j,l.math=_,l.normalize=g,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(i,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(i=typeof globalThis<"u"?globalThis:i||self,a(i.SupermouseUtils={}))})(this,(function(i){"use strict";function a(e,t,n){return e+(t-e)*n}function S(e,t,n,r){return a(e,t,1-Math.exp(-n*r))}function v(e,t,n){const r=((t-e)%360+540)%360-180;return e+r*n}function O(e,t){return Math.random()*(t-e)+e}function y(e,t,n){return Math.min(Math.max(e,t),n)}function p(e,t,n=0,r=0){const o=e-n,c=t-r;return Math.sqrt(o*o+c*c)}function b(e,t){return Math.atan2(t,e)*(180/Math.PI)}const C=Object.freeze(Object.defineProperty({__proto__:null,angle:b,clamp:y,damp:S,dist:p,lerp:a,lerpAngle:v,random:O},Symbol.toStringTag,{value:"Module"})),M=(e,t)=>{if(typeof document>"u"||document.getElementById(e))return;const n=document.createElement("style");n.id=e,n.innerHTML=t,document.head.appendChild(n)},h=new WeakMap;function f(e,t){if(typeof document>"u"||!e)return;let n=h.get(e);n||(n={},h.set(e,n));for(const r in t){const o=t[r];n[r]!==o&&(e.style[r]=o,n[r]=o)}}function d(e,t,n){f(e,{[t]:n})}function T(e,t,n,r=0,o=1,c=1,s=0,u=0){const l=`translate3d(${t}px, ${n}px, 0) translate(-50%, -50%) rotate(${r}deg) skew(${s}deg, ${u}deg) scale(${o}, ${c})`;d(e,"transform",l)}function _(e,t=document.body){const n=e.getBoundingClientRect();if(t!==document.body){const r=t.getBoundingClientRect(),o=n.left-r.left,c=n.top-r.top;return new DOMRect(o,c,n.width,n.height)}return n}function m(e="div"){const t=document.createElement(e);return f(t,{position:"absolute",top:"0",left:"0",pointerEvents:"none",boxSizing:"border-box",display:"block",willChange:"transform"}),t}function w(e,t){const n=m("div");return f(n,{width:`${e}px`,height:`${e}px`,borderRadius:"50%",backgroundColor:t}),n}function R(){return m("div")}const j=Object.freeze(Object.defineProperty({__proto__:null,applyStyles:f,createActor:m,createCircle:w,createDiv:R,injectStyles:M,projectRect:_,setStyle:d,setTransform:T},Symbol.toStringTag,{value:"Module"}));function A(e,t,n=.004,r=.5){const o=p(e,t);if(o<.1)return{rotation:0,scaleX:1,scaleY:1};const c=b(e,t),s=y(o*n,0,r),u=1+s,l=1-s*.5;return{rotation:c,scaleX:u,scaleY:l}}const $=Object.freeze(Object.defineProperty({__proto__:null,getVelocityDistortion:A},Symbol.toStringTag,{value:"Module"})),z={OVERLAY:"400",CURSOR:"300",FOLLOWER:"200",TRACE:"100"},P={EASE_OUT_EXPO:"cubic-bezier(0.16, 1, 0.3, 1)",ELASTIC_OUT:"cubic-bezier(0.34, 1.56, 0.64, 1)",SMOOTH:"ease-out"};function g(e,t){return e===void 0?()=>t:typeof e=="function"?e:()=>e}function L(e){return"create"in e&&typeof e.create=="function"}function D(e,t={}){const n=t.name||e.name,r=t.isEnabled??!0;if(L(e)){let o;const c=[];if(e.styles)for(const[s,u]of Object.entries(e.styles)){const l=g(t[s],void 0),x=u;c.push((I,U)=>{const E=l(I.state);E!==void 0&&d(U,x,E)})}return{name:n,isEnabled:r,install(s){o=e.create(s),e.selector&&s.registerHoverTarget(e.selector),this.isEnabled===!1&&(o.style.opacity="0"),s.container.appendChild(o)},update(s,u){if(o){for(let l=0;l<c.length;l++)c[l](s,o);e.update?.(s,o,u)}},onDisable(s){o&&(d(o,"opacity",0),e.onDisable?.(s,o))},onEnable(s){o&&(d(o,"opacity",1),e.onEnable?.(s,o))},destroy(){o&&(e.cleanup?.(o),o.remove())}}}else return{...e,name:n,isEnabled:r}}function k(){if(console.group("🐭 Supermouse Doctor"),!Array.from(document.querySelectorAll("style")).some(r=>r.id.startsWith("supermouse-style-"))){console.warn("[x] Supermouse has not been initialized yet."),console.warn(" Please call doctor() after `new Supermouse()` has run."),console.groupEnd();return}const t=[];document.querySelectorAll('[style*="cursor"]').forEach(r=>{r.getAttribute("style")?.includes("cursor: none")||t.push({el:r,reason:'Element has inline "cursor" style. Remove it and let Supermouse handle state.'})}),document.body.style.cursor!=="none"&&console.warn('[Global] document.body.style.cursor is not "none". Ensure { hideCursor: true } is passed to Supermouse.'),t.length>0?(console.warn(`Found ${t.length} potential conflicts:`),t.forEach(r=>console.warn(`[${r.reason}]`,r.el)),console.info('Tip: Avoid setting "cursor: pointer" manually. Use plugins or `rules` config instead.')):console.log("[ok] No obvious inline-style conflicts found."),console.groupEnd()}i.Easings=P,i.Layers=z,i.definePlugin=D,i.doctor=k,i.dom=j,i.effects=$,i.math=C,i.normalize=g,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/layers.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard Z-Index layers for the Supermouse ecosystem.
|
|
3
|
+
* Relative to the Supermouse Container.
|
|
4
|
+
*/
|
|
5
|
+
export declare const Layers: {
|
|
6
|
+
/** The top-most layer. For text, tooltips, and crucial UI. */
|
|
7
|
+
readonly OVERLAY: "400";
|
|
8
|
+
/** The main cursor layer. For the primary Dot/Pointer. */
|
|
9
|
+
readonly CURSOR: "300";
|
|
10
|
+
/** The secondary layer. For Rings, brackets, or followers. */
|
|
11
|
+
readonly FOLLOWER: "200";
|
|
12
|
+
/** The background layer. For trails, sparkles, and particles. */
|
|
13
|
+
readonly TRACE: "100";
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=layers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layers.d.ts","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,MAAM;IACjB,8DAA8D;;IAG9D,0DAA0D;;IAG1D,8DAA8D;;IAG9D,iEAAiE;;CAEzD,CAAC"}
|
package/dist/math.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linear Interpolation between two values.
|
|
3
|
+
*/
|
|
4
|
+
export declare function lerp(start: number, end: number, factor: number): number;
|
|
5
|
+
/**
|
|
6
|
+
* Frame-rate independent damping (Time-based Lerp).
|
|
7
|
+
* Ensures smooth animation consistent across 60hz, 120hz, etc.
|
|
8
|
+
*
|
|
9
|
+
* @param a Current value
|
|
10
|
+
* @param b Target value
|
|
11
|
+
* @param lambda Smoothing factor (approx 1-20). Higher is faster.
|
|
12
|
+
* @param dt Delta time in seconds (not milliseconds)
|
|
13
|
+
*/
|
|
14
|
+
export declare function damp(a: number, b: number, lambda: number, dt: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* Linear Interpolation between two angles in degrees, taking the shortest path.
|
|
17
|
+
* Handles wrap-around at 360 degrees.
|
|
18
|
+
*/
|
|
19
|
+
export declare function lerpAngle(start: number, end: number, factor: number): number;
|
|
20
|
+
/**
|
|
21
|
+
* Returns a random number between min and max.
|
|
22
|
+
* Usage: math.random(10, 20) -> 14.5
|
|
23
|
+
*/
|
|
24
|
+
export declare function random(min: number, max: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Constrains a value between a minimum and maximum.
|
|
27
|
+
*/
|
|
28
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
29
|
+
/**
|
|
30
|
+
* Calculates the distance (hypotenuse) between two points (or magnitude of a vector).
|
|
31
|
+
* If x2/y2 are omitted, calculates magnitude of vector x1/y1.
|
|
32
|
+
*/
|
|
33
|
+
export declare function dist(x1: number, y1: number, x2?: number, y2?: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* Calculates the angle in degrees between two points (or vector direction).
|
|
36
|
+
*/
|
|
37
|
+
export declare function angle(x: number, y: number): number;
|
|
38
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAE7E;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,GAAE,MAAU,EAAE,EAAE,GAAE,MAAU,GAAG,MAAM,CAInF;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAElD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MouseState, ValueOrGetter } from '../../core/src';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a function that always resolves the option value.
|
|
4
|
+
* Eliminates 'typeof' checks inside the render loop by normalizing
|
|
5
|
+
* static values into getter functions during initialization.
|
|
6
|
+
*
|
|
7
|
+
* @param option The option passed by the user
|
|
8
|
+
* @param defaultValue Fallback value
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalize<T>(option: ValueOrGetter<T> | undefined, defaultValue: T): (state: MouseState) => T;
|
|
11
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEpE;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,SAAS,EACpC,YAAY,EAAE,CAAC,GACd,CAAC,KAAK,EAAE,UAAU,KAAK,CAAC,CAQ1B"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Supermouse, SupermousePlugin } from '../../core/src';
|
|
2
|
+
export interface BasePluginOptions {
|
|
3
|
+
name?: string;
|
|
4
|
+
isEnabled?: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface LogicConfig {
|
|
7
|
+
name: string;
|
|
8
|
+
priority?: number;
|
|
9
|
+
install?: (app: Supermouse) => void;
|
|
10
|
+
update?: (app: Supermouse, deltaTime: number) => void;
|
|
11
|
+
destroy?: (app: Supermouse) => void;
|
|
12
|
+
onEnable?: (app: Supermouse) => void;
|
|
13
|
+
onDisable?: (app: Supermouse) => void;
|
|
14
|
+
create?: never;
|
|
15
|
+
}
|
|
16
|
+
interface VisualConfig<E extends HTMLElement, O extends object> {
|
|
17
|
+
name: string;
|
|
18
|
+
/** Automatically register this attribute selector */
|
|
19
|
+
selector?: string;
|
|
20
|
+
/** Create and return the DOM Element */
|
|
21
|
+
create: (app: Supermouse) => E;
|
|
22
|
+
/** Map option keys to CSS properties */
|
|
23
|
+
styles?: Partial<Record<keyof O, keyof CSSStyleDeclaration>>;
|
|
24
|
+
/** Update loop with access to the element */
|
|
25
|
+
update?: (app: Supermouse, element: E, deltaTime: number) => void;
|
|
26
|
+
onEnable?: (app: Supermouse, element: E) => void;
|
|
27
|
+
onDisable?: (app: Supermouse, element: E) => void;
|
|
28
|
+
cleanup?: (element: E) => void;
|
|
29
|
+
destroy?: never;
|
|
30
|
+
}
|
|
31
|
+
export declare function definePlugin<E extends HTMLElement, O extends BasePluginOptions>(config: VisualConfig<E, O>, userOptions?: O): SupermousePlugin;
|
|
32
|
+
export declare function definePlugin(config: LogicConfig, userOptions?: BasePluginOptions): SupermousePlugin;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAIvE,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,IAAI,CAAC;IACpC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACtD,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,IAAI,CAAC;IACpC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,IAAI,CAAC;IACrC,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,IAAI,CAAC;IAEtC,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB;AAGD,UAAU,YAAY,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,MAAM;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,MAAM,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,CAAC,CAAC;IAC/B,wCAAwC;IACxC,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,mBAAmB,CAAC,CAAC,CAAC;IAC7D,6CAA6C;IAC7C,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAClE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IACjD,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IAClD,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,KAAK,CAAC;CACjB;AAYD,wBAAgB,YAAY,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,iBAAiB,EAC7E,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,WAAW,CAAC,EAAE,CAAC,GACd,gBAAgB,CAAC;AAGpB,wBAAgB,YAAY,CAC1B,MAAM,EAAE,WAAW,EACnB,WAAW,CAAC,EAAE,iBAAiB,GAC9B,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supermousejs/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"main": "dist/index.umd.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@supermousejs/core": "2.0
|
|
30
|
+
"@supermousejs/core": "2.1.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@supermousejs/core": "2.0
|
|
33
|
+
"@supermousejs/core": "2.1.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "vite build"
|
package/src/css.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Common cubic-bezier easing strings for CSS transitions.
|
|
3
|
-
*/
|
|
4
|
-
export const Easings = {
|
|
5
|
-
/** Good for entrance animations (starts fast, slows down) */
|
|
6
|
-
EASE_OUT_EXPO:
|
|
7
|
-
/** Good for elastic/bouncy UI elements */
|
|
8
|
-
ELASTIC_OUT:
|
|
9
|
-
/** Standard smooth movement */
|
|
10
|
-
SMOOTH:
|
|
11
|
-
} as const;
|
|
1
|
+
/**
|
|
2
|
+
* Common cubic-bezier easing strings for CSS transitions.
|
|
3
|
+
*/
|
|
4
|
+
export const Easings = {
|
|
5
|
+
/** Good for entrance animations (starts fast, slows down) */
|
|
6
|
+
EASE_OUT_EXPO: "cubic-bezier(0.16, 1, 0.3, 1)",
|
|
7
|
+
/** Good for elastic/bouncy UI elements */
|
|
8
|
+
ELASTIC_OUT: "cubic-bezier(0.34, 1.56, 0.64, 1)",
|
|
9
|
+
/** Standard smooth movement */
|
|
10
|
+
SMOOTH: "ease-out"
|
|
11
|
+
} as const;
|
package/src/doctor.ts
CHANGED
|
@@ -1,49 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
console.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
console.
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
console.groupEnd();
|
|
49
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* A diagnostic utility to find common CSS conflicts that cause cursor glitches.
|
|
3
|
+
*/
|
|
4
|
+
export function doctor() {
|
|
5
|
+
console.group("🐭 Supermouse Doctor");
|
|
6
|
+
|
|
7
|
+
const hasInitialized = Array.from(document.querySelectorAll("style")).some((s) =>
|
|
8
|
+
s.id.startsWith("supermouse-style-")
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
if (!hasInitialized) {
|
|
12
|
+
console.warn("[x] Supermouse has not been initialized yet.");
|
|
13
|
+
console.warn(" Please call doctor() after `new Supermouse()` has run.");
|
|
14
|
+
console.groupEnd();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const issues: { el: Element; reason: string }[] = [];
|
|
19
|
+
|
|
20
|
+
const inlineCursor = document.querySelectorAll('[style*="cursor"]');
|
|
21
|
+
inlineCursor.forEach((el) => {
|
|
22
|
+
if (el.getAttribute("style")?.includes("cursor: none")) return;
|
|
23
|
+
|
|
24
|
+
issues.push({
|
|
25
|
+
el,
|
|
26
|
+
reason: 'Element has inline "cursor" style. Remove it and let Supermouse handle state.'
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (document.body.style.cursor !== "none") {
|
|
31
|
+
console.warn(
|
|
32
|
+
'[Global] document.body.style.cursor is not "none". Ensure { hideCursor: true } is passed to Supermouse.'
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (issues.length > 0) {
|
|
37
|
+
console.warn(`Found ${issues.length} potential conflicts:`);
|
|
38
|
+
issues.forEach((i) => console.warn(`[${i.reason}]`, i.el));
|
|
39
|
+
console.info(
|
|
40
|
+
'Tip: Avoid setting "cursor: pointer" manually. Use plugins or `rules` config instead.'
|
|
41
|
+
);
|
|
42
|
+
} else {
|
|
43
|
+
console.log("[ok] No obvious inline-style conflicts found.");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
console.groupEnd();
|
|
47
|
+
}
|