@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/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 O(e, t, n, o) {
5
- return y(e, t, 1 - Math.exp(-n * o));
4
+ function v(e, t, n, r) {
5
+ return y(e, t, 1 - Math.exp(-n * r));
6
6
  }
7
- function _(e, t, n) {
8
- const o = ((t - e) % 360 + 540) % 360 - 180;
9
- return e + o * n;
7
+ function C(e, t, n) {
8
+ const r = ((t - e) % 360 + 540) % 360 - 180;
9
+ return e + r * n;
10
10
  }
11
- function C(e, t) {
11
+ function O(e, t) {
12
12
  return Math.random() * (t - e) + e;
13
13
  }
14
- function h(e, t, n) {
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, o = 0) {
18
- const r = e - n, i = t - o;
19
- return Math.sqrt(r * r + i * i);
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 m(e, t) {
21
+ function h(e, t) {
22
22
  return Math.atan2(t, e) * (180 / Math.PI);
23
23
  }
24
- const x = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
24
+ const j = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
25
25
  __proto__: null,
26
- angle: m,
27
- clamp: h,
28
- damp: O,
26
+ angle: h,
27
+ clamp: m,
28
+ damp: v,
29
29
  dist: b,
30
30
  lerp: y,
31
- lerpAngle: _,
32
- random: C
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
- Object.assign(e.style, t);
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
- let o = p.get(e);
40
- o || (o = {}, p.set(e, o)), o[t] !== n && (e.style[t] = n, o[t] = n);
41
- }
42
- function v(e, t, n, o = 0, r = 1, i = 1, s = 0, l = 0) {
43
- e.style.transform = `
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 o = t.getBoundingClientRect(), r = n.left - o.left, i = n.top - o.top;
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 A(e, t) {
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 M() {
83
+ function T() {
91
84
  return d("div");
92
85
  }
93
- const j = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
86
+ const z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
94
87
  __proto__: null,
95
88
  applyStyles: a,
96
89
  createActor: d,
97
- createCircle: A,
98
- createDiv: M,
90
+ createCircle: R,
91
+ createDiv: T,
92
+ injectStyles: _,
99
93
  projectRect: w,
100
94
  setStyle: u,
101
- setTransform: v
95
+ setTransform: M
102
96
  }, Symbol.toStringTag, { value: "Module" }));
103
- function R(e, t, n = 4e-3, o = 0.5) {
104
- const r = b(e, t);
105
- if (r < 0.1)
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 i = m(e, t), s = h(r * n, 0, o), l = 1 + s, c = 1 - s * 0.5;
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: i,
103
+ rotation: c,
110
104
  scaleX: l,
111
- scaleY: c
105
+ scaleY: i
112
106
  };
113
107
  }
114
- const z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
108
+ const P = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
115
109
  __proto__: null,
116
- getVelocityDistortion: R
117
- }, Symbol.toStringTag, { value: "Module" })), P = {
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
- }, D = {
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 T(e, t) {
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 L(e, t = {}) {
141
- const n = t.name || e.name, o = t.isEnabled ?? !0;
134
+ function k(e, t = {}) {
135
+ const n = t.name || e.name, r = t.isEnabled ?? !0;
142
136
  if ($(e)) {
143
- let r;
144
- const i = [];
137
+ let o;
138
+ const c = [];
145
139
  if (e.styles)
146
140
  for (const [s, l] of Object.entries(e.styles)) {
147
- const c = T(t[s], void 0), g = l;
148
- i.push((E, S) => {
149
- const f = c(E.state);
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: o,
149
+ isEnabled: r,
156
150
  install(s) {
157
- r = e.create(s), e.selector && s.registerHoverTarget(e.selector), this.isEnabled === !1 && (r.style.opacity = "0"), s.container.appendChild(r);
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 (r) {
161
- for (let c = 0; c < i.length; c++)
162
- i[c](s, r);
163
- e.update?.(s, r, l);
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
- r && (u(r, "opacity", 0), e.onDisable?.(s, r));
161
+ o && (u(o, "opacity", 0), e.onDisable?.(s, o));
168
162
  },
169
163
  onEnable(s) {
170
- r && (u(r, "opacity", 1), e.onEnable?.(s, r));
164
+ o && (u(o, "opacity", 1), e.onEnable?.(s, o));
171
165
  },
172
166
  destroy() {
173
- r && (e.cleanup?.(r), r.remove());
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: o
174
+ isEnabled: r
181
175
  };
182
176
  }
183
- function k() {
184
- if (console.group("🐭 Supermouse Doctor"), !Array.from(document.querySelectorAll("style")).some((o) => o.id.startsWith("supermouse-style-"))) {
185
- console.warn("❌ Supermouse has not been initialized yet."), console.warn(' Please call doctor() AFTER "new Supermouse()" has run.'), console.groupEnd();
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((o) => {
190
- o.getAttribute("style")?.includes("cursor: none") || t.push({
191
- el: o,
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('[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();
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
- D as Easings,
198
- P as Layers,
199
- L as definePlugin,
200
- k as doctor,
201
- j as dom,
202
- z as effects,
203
- x as math,
204
- T as normalize
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(l,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l.SupermouseUtils={}))})(this,(function(l){"use strict";function a(e,t,n){return e+(t-e)*n}function S(e,t,n,o){return a(e,t,1-Math.exp(-n*o))}function O(e,t,n){const o=((t-e)%360+540)%360-180;return e+o*n}function T(e,t){return Math.random()*(t-e)+e}function h(e,t,n){return Math.min(Math.max(e,t),n)}function m(e,t,n=0,o=0){const r=e-n,i=t-o;return Math.sqrt(r*r+i*i)}function b(e,t){return Math.atan2(t,e)*(180/Math.PI)}const _=Object.freeze(Object.defineProperty({__proto__:null,angle:b,clamp:h,damp:S,dist:m,lerp:a,lerpAngle:O,random:T},Symbol.toStringTag,{value:"Module"}));function f(e,t){Object.assign(e.style,t)}const p=new WeakMap;function d(e,t,n){let o=p.get(e);o||(o={},p.set(e,o)),o[t]!==n&&(e.style[t]=n,o[t]=n)}function v(e,t,n,o=0,r=1,i=1,s=0,c=0){e.style.transform=`
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"})}));
@@ -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"}
@@ -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.1.1",
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.5"
30
+ "@supermousejs/core": "2.1.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@supermousejs/core": "2.0.5"
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: '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;
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
- * Supermouse Doctor
4
- * A diagnostic utility to find common CSS conflicts that cause "Double Cursor" glitches.
5
- */
6
- export function doctor() {
7
- console.group('🐭 Supermouse Doctor');
8
-
9
- // 0. Check Initialization
10
- // Supermouse injects a style tag with an ID starting with 'supermouse-style-'
11
- const hasInitialized = Array.from(document.querySelectorAll('style')).some(s => s.id.startsWith('supermouse-style-'));
12
-
13
- if (!hasInitialized) {
14
- console.warn('❌ Supermouse has not been initialized yet.');
15
- console.warn(' Please call doctor() AFTER "new Supermouse()" has run.');
16
- console.groupEnd();
17
- return;
18
- }
19
-
20
- const issues: { el: Element, reason: string }[] = [];
21
-
22
- // 1. Check for Inline Styles (Hard Overrides)
23
- const inlineCursor = document.querySelectorAll('[style*="cursor"]');
24
- inlineCursor.forEach(el => {
25
- // Ignore the supermouse container itself (usually has cursor: none)
26
- if (el.getAttribute('style')?.includes('cursor: none')) return;
27
-
28
- issues.push({
29
- el,
30
- reason: 'Element has inline "cursor" style. Remove it and let Supermouse handle state.'
31
- });
32
- });
33
-
34
- // 2. Check Global Body State
35
- if (document.body.style.cursor !== 'none') {
36
- console.warn('[Global] document.body.style.cursor is not "none". Ensure { hideCursor: true } is passed to Supermouse.');
37
- }
38
-
39
- // 3. Report
40
- if (issues.length > 0) {
41
- console.warn(`Found ${issues.length} potential conflicts:`);
42
- issues.forEach(i => console.warn(`[${i.reason}]`, i.el));
43
- console.info('Tip: Avoid setting "cursor: pointer" manually. Use plugins or "rules" config instead.');
44
- } else {
45
- console.log('✅ No obvious inline-style conflicts found.');
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
+ }