@supermousejs/utils 2.4.4-beta.3 → 2.4.4-beta.5
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 +100 -100
- package/dist/index.umd.js +2 -2
- package/dist/plugin.d.ts +8 -3
- package/dist/plugin.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
function y(e, t, n) {
|
|
2
2
|
return e + (t - e) * n;
|
|
3
3
|
}
|
|
4
|
-
function E(e, t, n,
|
|
5
|
-
return y(e, t, 1 - Math.exp(-n *
|
|
4
|
+
function E(e, t, n, o) {
|
|
5
|
+
return y(e, t, 1 - Math.exp(-n * o));
|
|
6
6
|
}
|
|
7
7
|
function $(e, t, n) {
|
|
8
|
-
const
|
|
9
|
-
return e +
|
|
8
|
+
const o = ((t - e) % 360 + 540) % 360 - 180;
|
|
9
|
+
return e + o * n;
|
|
10
10
|
}
|
|
11
11
|
function O(e, t) {
|
|
12
12
|
return Math.random() * (t - e) + e;
|
|
@@ -14,9 +14,9 @@ function O(e, t) {
|
|
|
14
14
|
function g(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, o = 0) {
|
|
18
|
+
const r = e - n, s = t - o;
|
|
19
|
+
return Math.sqrt(r * r + s * s);
|
|
20
20
|
}
|
|
21
21
|
function S(e, t) {
|
|
22
22
|
return Math.atan2(t, e) * (180 / Math.PI);
|
|
@@ -38,35 +38,35 @@ const se = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
38
38
|
if (typeof document > "u" || document.getElementById(e)) return;
|
|
39
39
|
const n = document.createElement("style");
|
|
40
40
|
n.id = e, n.innerHTML = t, document.head.appendChild(n);
|
|
41
|
-
},
|
|
41
|
+
}, h = /* @__PURE__ */ new WeakMap();
|
|
42
42
|
function C(e) {
|
|
43
43
|
return e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
44
44
|
}
|
|
45
45
|
function l(e, t) {
|
|
46
46
|
if (typeof document > "u" || !e) return;
|
|
47
|
-
let n =
|
|
48
|
-
n || (n = {},
|
|
49
|
-
for (const [
|
|
50
|
-
if (
|
|
51
|
-
const s = String(
|
|
47
|
+
let n = h.get(e);
|
|
48
|
+
n || (n = {}, h.set(e, n));
|
|
49
|
+
for (const [o, r] of Object.entries(t)) {
|
|
50
|
+
if (r === void 0) continue;
|
|
51
|
+
const s = String(r), c = C(o);
|
|
52
52
|
n[c] !== s && (e.style.setProperty(c, s), n[c] = s);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
function _(e, t, n) {
|
|
56
56
|
l(e, { [t]: n });
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function x(e, t) {
|
|
59
59
|
l(e, t);
|
|
60
60
|
}
|
|
61
|
-
function
|
|
62
|
-
const
|
|
63
|
-
l(e, { transform:
|
|
61
|
+
function P(e, t, n, o = 0, r = 1, s = 1, c = 0, i = 0) {
|
|
62
|
+
const d = `translate3d(${t}px, ${n}px, 0) translate(-50%, -50%) rotate(${o}deg) skew(${c}deg, ${i}deg) scale(${r}, ${s})`;
|
|
63
|
+
l(e, { transform: d });
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function R(e, t = document.body) {
|
|
66
66
|
const n = e.getBoundingClientRect();
|
|
67
67
|
if (t !== document.body) {
|
|
68
|
-
const
|
|
69
|
-
return new DOMRect(
|
|
68
|
+
const o = t.getBoundingClientRect(), r = n.left - o.left, s = n.top - o.top;
|
|
69
|
+
return new DOMRect(r, s, n.width, n.height);
|
|
70
70
|
}
|
|
71
71
|
return n;
|
|
72
72
|
}
|
|
@@ -82,7 +82,7 @@ function p(e = "div") {
|
|
|
82
82
|
willChange: "transform"
|
|
83
83
|
}), t;
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function T(e, t) {
|
|
86
86
|
const n = p("div");
|
|
87
87
|
return l(n, {
|
|
88
88
|
width: `${e}px`,
|
|
@@ -96,25 +96,25 @@ function A() {
|
|
|
96
96
|
}
|
|
97
97
|
const ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
98
98
|
__proto__: null,
|
|
99
|
-
applyStyles:
|
|
99
|
+
applyStyles: x,
|
|
100
100
|
createActor: p,
|
|
101
|
-
createCircle:
|
|
101
|
+
createCircle: T,
|
|
102
102
|
createDiv: A,
|
|
103
103
|
css: l,
|
|
104
104
|
injectStyles: M,
|
|
105
|
-
projectRect:
|
|
105
|
+
projectRect: R,
|
|
106
106
|
setStyle: _,
|
|
107
|
-
setTransform:
|
|
107
|
+
setTransform: P
|
|
108
108
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
109
|
-
function k(e, t, n = 4e-3,
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
109
|
+
function k(e, t, n = 4e-3, o = 0.5) {
|
|
110
|
+
const r = b(e, t);
|
|
111
|
+
if (r < 0.1)
|
|
112
112
|
return { rotation: 0, scaleX: 1, scaleY: 1 };
|
|
113
|
-
const s = S(e, t), c = g(
|
|
113
|
+
const s = S(e, t), c = g(r * n, 0, o), i = 1 + c, d = 1 - c * 0.5;
|
|
114
114
|
return {
|
|
115
115
|
rotation: s,
|
|
116
116
|
scaleX: i,
|
|
117
|
-
scaleY:
|
|
117
|
+
scaleY: d
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
const ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
@@ -126,14 +126,14 @@ function N(e, t) {
|
|
|
126
126
|
}
|
|
127
127
|
function ae(e, t) {
|
|
128
128
|
const n = {};
|
|
129
|
-
for (const
|
|
130
|
-
n[
|
|
131
|
-
e[
|
|
132
|
-
t[
|
|
129
|
+
for (const o of Object.keys(t))
|
|
130
|
+
n[o] = N(
|
|
131
|
+
e[o],
|
|
132
|
+
t[o]
|
|
133
133
|
);
|
|
134
134
|
return n;
|
|
135
135
|
}
|
|
136
|
-
const le = () => typeof window < "u" && window.matchMedia("(pointer: fine)").matches,
|
|
136
|
+
const le = () => typeof window < "u" && window.matchMedia("(pointer: fine)").matches, m = "[supermouse] doctor", a = {
|
|
137
137
|
brand: "color: #ffffff; background: #42b883; padding: 2px 4px; border-radius: 2px; font-weight: 700;",
|
|
138
138
|
error: "color: #ffffff; background: #f43f5e; padding: 2px 4px; border-radius: 2px; font-weight: 700;",
|
|
139
139
|
warn: "color: #1f2937; background: #f59e0b; padding: 2px 4px; border-radius: 2px; font-weight: 700;",
|
|
@@ -142,7 +142,7 @@ const le = () => typeof window < "u" && window.matchMedia("(pointer: fine)").mat
|
|
|
142
142
|
code: "color: #a1a1aa; font-weight: 500;",
|
|
143
143
|
hint: "color: #10b981; font-weight: 600;"
|
|
144
144
|
};
|
|
145
|
-
function
|
|
145
|
+
function de(e) {
|
|
146
146
|
const t = e ? D(e) : w();
|
|
147
147
|
H(t);
|
|
148
148
|
}
|
|
@@ -167,23 +167,23 @@ function L(e) {
|
|
|
167
167
|
function j(e) {
|
|
168
168
|
const t = [];
|
|
169
169
|
for (const n of e) {
|
|
170
|
-
const
|
|
171
|
-
L(n) &&
|
|
170
|
+
const o = n.name ?? "unknown", r = n.priority ?? 0;
|
|
171
|
+
L(n) && r >= 0 && t.push({
|
|
172
172
|
severity: "warn",
|
|
173
173
|
code: "PRIORITY_LOGIC",
|
|
174
|
-
message: `Plugin "${
|
|
175
|
-
hint: `Set priority to a negative value (e.g. -10) on "${
|
|
176
|
-
}), v(n) &&
|
|
174
|
+
message: `Plugin "${o}" has priority ${r} but appears to be a logic plugin (should run before physics).`,
|
|
175
|
+
hint: `Set priority to a negative value (e.g. -10) on "${o}"`
|
|
176
|
+
}), v(n) && r < 0 && t.push({
|
|
177
177
|
severity: "warn",
|
|
178
178
|
code: "PRIORITY_VISUAL",
|
|
179
|
-
message: `Plugin "${
|
|
179
|
+
message: `Plugin "${o}" has priority ${r} but appears to be a visual plugin (should run after physics).`,
|
|
180
180
|
hint: "Remove priority or use a positive value"
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
return t;
|
|
184
184
|
}
|
|
185
185
|
function z(e) {
|
|
186
|
-
const t = e.find((
|
|
186
|
+
const t = e.find((o) => o.name === "states");
|
|
187
187
|
if (!t) return [];
|
|
188
188
|
const n = t.priority ?? 0;
|
|
189
189
|
return n >= 0 ? [
|
|
@@ -198,11 +198,11 @@ function z(e) {
|
|
|
198
198
|
function V(e) {
|
|
199
199
|
const t = [];
|
|
200
200
|
for (const n of e) {
|
|
201
|
-
const
|
|
201
|
+
const o = n.name ?? "unknown";
|
|
202
202
|
v(n) && !n.element && t.push({
|
|
203
203
|
severity: "warn",
|
|
204
204
|
code: "MISSING_ELEMENT",
|
|
205
|
-
message: `Plugin "${
|
|
205
|
+
message: `Plugin "${o}" has no 'element' property — disablePlugin() will not hide its DOM.`,
|
|
206
206
|
hint: "Assign plugin.element = el in install(), or use definePlugin()"
|
|
207
207
|
});
|
|
208
208
|
}
|
|
@@ -233,13 +233,13 @@ function U(e) {
|
|
|
233
233
|
function G(e, t) {
|
|
234
234
|
const n = e.cursor;
|
|
235
235
|
if (n === void 0) return [];
|
|
236
|
-
const
|
|
237
|
-
return typeof n == "string" && !
|
|
236
|
+
const o = ["auto", "custom", "native", "both"];
|
|
237
|
+
return typeof n == "string" && !o.includes(n) ? [
|
|
238
238
|
{
|
|
239
239
|
severity: "error",
|
|
240
240
|
code: "INVALID_CURSOR_MODE",
|
|
241
|
-
message: `Invalid cursor mode "${n}". Expected one of: ${
|
|
242
|
-
hint: `Set cursor to one of: ${
|
|
241
|
+
message: `Invalid cursor mode "${n}". Expected one of: ${o.join(", ")}.`,
|
|
242
|
+
hint: `Set cursor to one of: ${o.join(", ")}`
|
|
243
243
|
}
|
|
244
244
|
] : n === "both" && e.container !== document.body && t?.cursorMode === "both" ? [
|
|
245
245
|
{
|
|
@@ -253,7 +253,7 @@ function G(e, t) {
|
|
|
253
253
|
function w(e) {
|
|
254
254
|
const t = [];
|
|
255
255
|
if (!Array.from(document.querySelectorAll("style")).some(
|
|
256
|
-
(
|
|
256
|
+
(r) => r.id.startsWith("supermouse-style-")
|
|
257
257
|
))
|
|
258
258
|
return [
|
|
259
259
|
{
|
|
@@ -263,8 +263,8 @@ function w(e) {
|
|
|
263
263
|
hint: "Call doctor() after new Supermouse() has run"
|
|
264
264
|
}
|
|
265
265
|
];
|
|
266
|
-
document.querySelectorAll('[style*="cursor"]').forEach((
|
|
267
|
-
const s =
|
|
266
|
+
document.querySelectorAll('[style*="cursor"]').forEach((r) => {
|
|
267
|
+
const s = r.getAttribute("style") ?? "";
|
|
268
268
|
s.includes("cursor: none") || s.includes("cursor") && t.push({
|
|
269
269
|
severity: "warn",
|
|
270
270
|
code: "INLINE_CURSOR",
|
|
@@ -272,10 +272,10 @@ function w(e) {
|
|
|
272
272
|
hint: "Remove inline cursor styles"
|
|
273
273
|
});
|
|
274
274
|
});
|
|
275
|
-
const
|
|
276
|
-
if (
|
|
277
|
-
const
|
|
278
|
-
s === "custom" && i && c && !
|
|
275
|
+
const o = document.querySelector(".supermouse-scope-0");
|
|
276
|
+
if (o) {
|
|
277
|
+
const r = o.classList.contains("supermouse-hide-0"), s = e?.state?.cursorMode ?? "auto", c = e?.state?.hasReceivedInput ?? !0, i = e?.input?.isEnabled ?? !0;
|
|
278
|
+
s === "custom" && i && c && !r && t.push({
|
|
279
279
|
severity: "warn",
|
|
280
280
|
code: "BODY_CURSOR_LEAK",
|
|
281
281
|
message: "Body instance has cursor: 'custom' but native cursor suppression class is not applied.",
|
|
@@ -286,21 +286,21 @@ function w(e) {
|
|
|
286
286
|
}
|
|
287
287
|
function H(e) {
|
|
288
288
|
if (e.length === 0) {
|
|
289
|
-
console.log(`%c${
|
|
289
|
+
console.log(`%c${m}%c No issues found`, a.brand, a.dim);
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
292
|
const t = [
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
293
|
+
f(e, "error", "error"),
|
|
294
|
+
f(e, "warn", "warning"),
|
|
295
|
+
f(e, "info", "note")
|
|
296
296
|
].filter((n) => n !== null).join(" · ");
|
|
297
|
-
console.log(`%c${
|
|
297
|
+
console.log(`%c${m}%c ${t}`, a.brand, a.dim);
|
|
298
298
|
for (const n of e)
|
|
299
299
|
Y(n);
|
|
300
300
|
}
|
|
301
|
-
function
|
|
302
|
-
const
|
|
303
|
-
return
|
|
301
|
+
function f(e, t, n) {
|
|
302
|
+
const o = e.filter((r) => r.severity === t).length;
|
|
303
|
+
return o > 0 ? `${o} ${n}${o > 1 ? "s" : ""}` : null;
|
|
304
304
|
}
|
|
305
305
|
function Y(e) {
|
|
306
306
|
console.log(
|
|
@@ -314,58 +314,58 @@ function Y(e) {
|
|
|
314
314
|
function q(e) {
|
|
315
315
|
return typeof e.create == "function";
|
|
316
316
|
}
|
|
317
|
-
function
|
|
318
|
-
const n = t.name ?? e.name,
|
|
317
|
+
function fe(e, t = {}) {
|
|
318
|
+
const n = t.name ?? e.name, o = t.isEnabled ?? !0;
|
|
319
319
|
if (!q(e))
|
|
320
320
|
return {
|
|
321
321
|
...e,
|
|
322
322
|
name: n,
|
|
323
|
-
isEnabled:
|
|
323
|
+
isEnabled: o
|
|
324
324
|
};
|
|
325
|
-
let
|
|
325
|
+
let r = null, s = !1;
|
|
326
326
|
const c = (i) => {
|
|
327
|
-
if (
|
|
328
|
-
return e.beforeDisable?.(i,
|
|
327
|
+
if (r)
|
|
328
|
+
return e.beforeDisable?.(i, r);
|
|
329
329
|
};
|
|
330
330
|
return {
|
|
331
331
|
name: n,
|
|
332
|
-
isEnabled:
|
|
332
|
+
isEnabled: o,
|
|
333
333
|
priority: e.priority,
|
|
334
334
|
install(i) {
|
|
335
|
-
if (
|
|
335
|
+
if (r = e.create(i), !(r instanceof HTMLElement) && !(r instanceof SVGElement)) {
|
|
336
336
|
console.warn(
|
|
337
337
|
`[supermouse] Plugin "${n}" create() did not return an HTMLElement or SVGElement.`
|
|
338
338
|
);
|
|
339
339
|
return;
|
|
340
340
|
}
|
|
341
|
-
this.element = i.stage.appendChild(
|
|
341
|
+
this.element = i.stage.appendChild(r), s = !0, e.hoverSelector && i.addHoverSelectors(e.hoverSelector), o || (r.style.display = "none"), e.install?.(i);
|
|
342
342
|
},
|
|
343
|
-
update(i,
|
|
344
|
-
!
|
|
343
|
+
update(i, d) {
|
|
344
|
+
!r || !s || e.update?.(i, r, d);
|
|
345
345
|
},
|
|
346
346
|
onEnable(i) {
|
|
347
|
-
|
|
347
|
+
r && (r.style.display = "", e.onEnable?.(i, r));
|
|
348
348
|
},
|
|
349
349
|
async onBeforeDisable(i) {
|
|
350
350
|
await c(i);
|
|
351
351
|
},
|
|
352
352
|
onDisable(i) {
|
|
353
|
-
|
|
353
|
+
r && e.onDisable?.(i, r);
|
|
354
354
|
},
|
|
355
355
|
destroy(i) {
|
|
356
|
-
|
|
356
|
+
r && (e.cleanup?.(i, r), r.remove(), r = null, s = !1), e.destroy?.(i);
|
|
357
357
|
}
|
|
358
358
|
};
|
|
359
359
|
}
|
|
360
360
|
function u(e, t = {}) {
|
|
361
361
|
const n = document.createElementNS("http://www.w3.org/2000/svg", e);
|
|
362
|
-
for (const [
|
|
363
|
-
n.setAttribute(
|
|
362
|
+
for (const [o, r] of Object.entries(t))
|
|
363
|
+
n.setAttribute(o, String(r));
|
|
364
364
|
return n;
|
|
365
365
|
}
|
|
366
366
|
function F(e, t) {
|
|
367
|
-
for (const [n,
|
|
368
|
-
e.setAttribute(n, String(
|
|
367
|
+
for (const [n, o] of Object.entries(t))
|
|
368
|
+
e.setAttribute(n, String(o));
|
|
369
369
|
}
|
|
370
370
|
function W(e = {}) {
|
|
371
371
|
return u("g", e);
|
|
@@ -389,8 +389,8 @@ function Q(e, t = {}) {
|
|
|
389
389
|
return n.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", e), n;
|
|
390
390
|
}
|
|
391
391
|
function ee(e, t = {}, n = []) {
|
|
392
|
-
const
|
|
393
|
-
return n.forEach((
|
|
392
|
+
const o = u("filter", { id: e, ...t });
|
|
393
|
+
return n.forEach((r) => o.appendChild(r)), o;
|
|
394
394
|
}
|
|
395
395
|
function te(e = 0, t = {}) {
|
|
396
396
|
return u("feGaussianBlur", {
|
|
@@ -404,10 +404,10 @@ function ne(e = 0.1, t = {}) {
|
|
|
404
404
|
...t
|
|
405
405
|
});
|
|
406
406
|
}
|
|
407
|
-
function
|
|
407
|
+
function oe(e) {
|
|
408
408
|
return u("feMergeNode", e ? { in: e } : {});
|
|
409
409
|
}
|
|
410
|
-
function
|
|
410
|
+
function re(e = []) {
|
|
411
411
|
const t = u("feMerge");
|
|
412
412
|
return e.forEach((n) => t.appendChild(n)), t;
|
|
413
413
|
}
|
|
@@ -427,22 +427,22 @@ const pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
427
427
|
filter: ee,
|
|
428
428
|
gaussianBlur: te,
|
|
429
429
|
group: W,
|
|
430
|
-
merge:
|
|
431
|
-
mergeNode:
|
|
430
|
+
merge: re,
|
|
431
|
+
mergeNode: oe,
|
|
432
432
|
path: Z,
|
|
433
433
|
rect: K,
|
|
434
434
|
setSVGAttrs: F,
|
|
435
435
|
text: J,
|
|
436
436
|
textPath: Q,
|
|
437
437
|
turbulence: ne
|
|
438
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
438
|
+
}, Symbol.toStringTag, { value: "Module" })), he = {
|
|
439
439
|
/** Good for entrance animations (starts fast, slows down) */
|
|
440
440
|
EASE_OUT_EXPO: "cubic-bezier(0.16, 1, 0.3, 1)",
|
|
441
441
|
/** Good for elastic/bouncy UI elements */
|
|
442
442
|
ELASTIC_OUT: "cubic-bezier(0.34, 1.56, 0.64, 1)",
|
|
443
443
|
/** Standard smooth movement */
|
|
444
444
|
SMOOTH: "ease-out"
|
|
445
|
-
},
|
|
445
|
+
}, me = {
|
|
446
446
|
/** The top-most layer. For text, tooltips, and crucial UI. */
|
|
447
447
|
OVERLAY: "400",
|
|
448
448
|
/** The main cursor layer. For the primary Dot/Pointer. */
|
|
@@ -453,23 +453,23 @@ const pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
453
453
|
TRACE: "100"
|
|
454
454
|
};
|
|
455
455
|
export {
|
|
456
|
-
|
|
457
|
-
|
|
456
|
+
he as Easings,
|
|
457
|
+
me as Layers,
|
|
458
458
|
S as angle,
|
|
459
|
-
|
|
459
|
+
x as applyStyles,
|
|
460
460
|
X as circle,
|
|
461
461
|
ie as circlePath,
|
|
462
462
|
I as circumference,
|
|
463
463
|
g as clamp,
|
|
464
464
|
p as createActor,
|
|
465
|
-
|
|
465
|
+
T as createCircle,
|
|
466
466
|
A as createDiv,
|
|
467
467
|
u as createSVGElement,
|
|
468
468
|
l as css,
|
|
469
469
|
E as damp,
|
|
470
|
-
|
|
470
|
+
fe as definePlugin,
|
|
471
471
|
b as dist,
|
|
472
|
-
|
|
472
|
+
de as doctor,
|
|
473
473
|
ce as dom,
|
|
474
474
|
ue as effects,
|
|
475
475
|
ee as filter,
|
|
@@ -481,17 +481,17 @@ export {
|
|
|
481
481
|
y as lerp,
|
|
482
482
|
$ as lerpAngle,
|
|
483
483
|
se as math,
|
|
484
|
-
|
|
485
|
-
|
|
484
|
+
re as merge,
|
|
485
|
+
oe as mergeNode,
|
|
486
486
|
N as normalize,
|
|
487
487
|
ae as normalizeAll,
|
|
488
488
|
Z as path,
|
|
489
|
-
|
|
489
|
+
R as projectRect,
|
|
490
490
|
O as random,
|
|
491
491
|
K as rect,
|
|
492
492
|
F as setSVGAttrs,
|
|
493
493
|
_ as setStyle,
|
|
494
|
-
|
|
494
|
+
P as setTransform,
|
|
495
495
|
pe as svg,
|
|
496
496
|
J as text,
|
|
497
497
|
Q as textPath,
|
package/dist/index.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
(function(r,
|
|
1
|
+
(function(r,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(r=typeof globalThis<"u"?globalThis:r||self,d(r.SupermouseUtils={}))})(this,(function(r){"use strict";function d(e,t,n){return e+(t-e)*n}function S(e,t,n,o){return d(e,t,1-Math.exp(-n*o))}function v(e,t,n){const o=((t-e)%360+540)%360-180;return e+o*n}function w(e,t){return Math.random()*(t-e)+e}function p(e,t,n){return Math.min(Math.max(e,t),n)}function y(e,t,n=0,o=0){const i=e-n,s=t-o;return Math.sqrt(i*i+s*s)}function g(e,t){return Math.atan2(t,e)*(180/Math.PI)}function E(e){return 2*Math.PI*e}const K=Object.freeze(Object.defineProperty({__proto__:null,angle:g,circumference:E,clamp:p,damp:S,dist:y,lerp:d,lerpAngle:v,random:w},Symbol.toStringTag,{value:"Module"})),$=(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)},O=new WeakMap;function Z(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function f(e,t){if(typeof document>"u"||!e)return;let n=O.get(e);n||(n={},O.set(e,n));for(const[o,i]of Object.entries(t)){if(i===void 0)continue;const s=String(i),a=Z(o);n[a]!==s&&(e.style.setProperty(a,s),n[a]=s)}}function M(e,t,n){f(e,{[t]:n})}function I(e,t){f(e,t)}function P(e,t,n,o=0,i=1,s=1,a=0,c=0){const m=`translate3d(${t}px, ${n}px, 0) translate(-50%, -50%) rotate(${o}deg) skew(${a}deg, ${c}deg) scale(${i}, ${s})`;f(e,{transform:m})}function C(e,t=document.body){const n=e.getBoundingClientRect();if(t!==document.body){const o=t.getBoundingClientRect(),i=n.left-o.left,s=n.top-o.top;return new DOMRect(i,s,n.width,n.height)}return n}function h(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 T(e,t){const n=h("div");return f(n,{width:`${e}px`,height:`${e}px`,borderRadius:"50%",backgroundColor:t}),n}function _(){return h("div")}const J=Object.freeze(Object.defineProperty({__proto__:null,applyStyles:I,createActor:h,createCircle:T,createDiv:_,css:f,injectStyles:$,projectRect:C,setStyle:M,setTransform:P},Symbol.toStringTag,{value:"Module"}));function A(e,t,n=.004,o=.5){const i=y(e,t);if(i<.1)return{rotation:0,scaleX:1,scaleY:1};const s=g(e,t),a=p(i*n,0,o),c=1+a,m=1-a*.5;return{rotation:s,scaleX:c,scaleY:m}}const Q=Object.freeze(Object.defineProperty({__proto__:null,getVelocityDistortion:A},Symbol.toStringTag,{value:"Module"}));function R(e,t){return e===void 0?()=>t:typeof e=="function"?e:()=>e}function x(e,t){const n={};for(const o of Object.keys(t))n[o]=R(e[o],t[o]);return n}const ee=()=>typeof window<"u"&&window.matchMedia("(pointer: fine)").matches,k="[supermouse] doctor",l={brand:"color: #ffffff; background: #42b883; padding: 2px 4px; border-radius: 2px; font-weight: 700;",error:"color: #ffffff; background: #f43f5e; padding: 2px 4px; border-radius: 2px; font-weight: 700;",warn:"color: #1f2937; background: #f59e0b; padding: 2px 4px; border-radius: 2px; font-weight: 700;",info:"color: #ffffff; background: #3b82f6; padding: 2px 4px; border-radius: 2px; font-weight: 700;",dim:"color: #6b7280;",code:"color: #a1a1aa; font-weight: 500;",hint:"color: #10b981; font-weight: 600;"};function te(e){const t=e?ne(e):D();le(t)}function ne(e){const t=e.plugins??[],n=e.options??{};return[...oe(t),...ie(t),...ce(t),...se(n),...ue(n),...ae(n,e.state),...D(e)]}function j(e){return e.element!==void 0||typeof e.update=="function"&&e.update.length>=3}function re(e){return e.element!==void 0?!1:typeof e.update=="function"&&e.update.length===2}function oe(e){const t=[];for(const n of e){const o=n.name??"unknown",i=n.priority??0;re(n)&&i>=0&&t.push({severity:"warn",code:"PRIORITY_LOGIC",message:`Plugin "${o}" has priority ${i} but appears to be a logic plugin (should run before physics).`,hint:`Set priority to a negative value (e.g. -10) on "${o}"`}),j(n)&&i<0&&t.push({severity:"warn",code:"PRIORITY_VISUAL",message:`Plugin "${o}" has priority ${i} but appears to be a visual plugin (should run after physics).`,hint:"Remove priority or use a positive value"})}return t}function ie(e){const t=e.find(o=>o.name==="states");if(!t)return[];const n=t.priority??0;return n>=0?[{severity:"error",code:"STATES_PRIORITY",message:`States plugin has priority ${n}. It must run before all visual plugins.`,hint:"Set priority: -999 on the States plugin"}]:[]}function ce(e){const t=[];for(const n of e){const o=n.name??"unknown";j(n)&&!n.element&&t.push({severity:"warn",code:"MISSING_ELEMENT",message:`Plugin "${o}" has no 'element' property — disablePlugin() will not hide its DOM.`,hint:"Assign plugin.element = el in install(), or use definePlugin()"})}return t}function se(e){const t=document.querySelectorAll('[class*="supermouse-scope-"]');return t.length<=1?[]:e.container!==document.body?[]:[{severity:"warn",code:"MULTI_INSTANCE",message:`Detected ${t.length} Supermouse instances. The body instance may conflict with scoped ones.`,hint:"Use suspend() / resume() or scope instances to different containers"}]}function ue(e){const t=e.container;return!t||t===document.body?[]:window.getComputedStyle(t).position!=="static"?[]:[{severity:"info",code:"CONTAINER_POSITION",message:"Container has position:static. Supermouse will mutate it to relative.",hint:"Set position: relative in your CSS to avoid the mutation"}]}function ae(e,t){const n=e.cursor;if(n===void 0)return[];const o=["auto","custom","native","both"];return typeof n=="string"&&!o.includes(n)?[{severity:"error",code:"INVALID_CURSOR_MODE",message:`Invalid cursor mode "${n}". Expected one of: ${o.join(", ")}.`,hint:`Set cursor to one of: ${o.join(", ")}`}]:n==="both"&&e.container!==document.body&&t?.cursorMode==="both"?[{severity:"warn",code:"NESTED_BOTH_MODE",message:"Scoped instance uses cursor: 'both'. In nested scopes, the native cursor may be hidden by the outer instance's cursor suppression.",hint:"Offset the custom cursor when cursorMode === 'both' or consider a single-instance scope architecture"}]:[]}function D(e){const t=[];if(!Array.from(document.querySelectorAll("style")).some(i=>i.id.startsWith("supermouse-style-")))return[{severity:"error",code:"NOT_INITIALIZED",message:"Supermouse has not been initialized yet.",hint:"Call doctor() after new Supermouse() has run"}];document.querySelectorAll('[style*="cursor"]').forEach(i=>{const s=i.getAttribute("style")??"";s.includes("cursor: none")||s.includes("cursor")&&t.push({severity:"warn",code:"INLINE_CURSOR",message:"Element has an inline cursor style that may override Supermouse.",hint:"Remove inline cursor styles"})});const o=document.querySelector(".supermouse-scope-0");if(o){const i=o.classList.contains("supermouse-hide-0"),s=e?.state?.cursorMode??"auto",a=e?.state?.hasReceivedInput??!0,c=e?.input?.isEnabled??!0;s==="custom"&&c&&a&&!i&&t.push({severity:"warn",code:"BODY_CURSOR_LEAK",message:"Body instance has cursor: 'custom' but native cursor suppression class is not applied.",hint:"Check that the animation loop is running and setCursor('custom') was called"})}return t}function le(e){if(e.length===0){console.log(`%c${k}%c No issues found`,l.brand,l.dim);return}const t=[b(e,"error","error"),b(e,"warn","warning"),b(e,"info","note")].filter(n=>n!==null).join(" · ");console.log(`%c${k}%c ${t}`,l.brand,l.dim);for(const n of e)de(n)}function b(e,t,n){const o=e.filter(i=>i.severity===t).length;return o>0?`${o} ${n}${o>1?"s":""}`:null}function de(e){console.log(`%c${e.severity.toUpperCase()}%c %c${e.code}%c ${e.message}`,l[e.severity],l.dim,l.code,"color: inherit;"),e.hint&&console.log(` %c→%c ${e.hint}`,l.hint,l.dim)}function fe(e){return typeof e.create=="function"}function me(e,t={}){const n=t.name??e.name,o=t.isEnabled??!0;if(!fe(e))return{...e,name:n,isEnabled:o};let i=null,s=!1;const a=c=>{if(i)return e.beforeDisable?.(c,i)};return{name:n,isEnabled:o,priority:e.priority,install(c){if(i=e.create(c),!(i instanceof HTMLElement)&&!(i instanceof SVGElement)){console.warn(`[supermouse] Plugin "${n}" create() did not return an HTMLElement or SVGElement.`);return}this.element=c.stage.appendChild(i),s=!0,e.hoverSelector&&c.addHoverSelectors(e.hoverSelector),o||(i.style.display="none"),e.install?.(c)},update(c,m){!i||!s||e.update?.(c,i,m)},onEnable(c){i&&(i.style.display="",e.onEnable?.(c,i))},async onBeforeDisable(c){await a(c)},onDisable(c){i&&e.onDisable?.(c,i)},destroy(c){i&&(e.cleanup?.(c,i),i.remove(),i=null,s=!1),e.destroy?.(c)}}}function u(e,t={}){const n=document.createElementNS("http://www.w3.org/2000/svg",e);for(const[o,i]of Object.entries(t))n.setAttribute(o,String(i));return n}function N(e,t){for(const[n,o]of Object.entries(t))e.setAttribute(n,String(o))}function L(e={}){return u("g",e)}function z(e={}){return u("circle",e)}function V(e={}){return u("rect",e)}function B(e,t={}){const n=u("path",t);return e!==void 0&&n.setAttribute("d",e),n}function U(e={},t){const n=u("text",e);return t!==void 0&&(n.textContent=t),n}function G(e,t={}){const n=u("textPath",{...t,href:e});return n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",e),n}function H(e,t={},n=[]){const o=u("filter",{id:e,...t});return n.forEach(i=>o.appendChild(i)),o}function Y(e=0,t={}){return u("feGaussianBlur",{stdDeviation:String(e),...t})}function q(e=.1,t={}){return u("feTurbulence",{baseFrequency:String(e),...t})}function F(e){return u("feMergeNode",e?{in:e}:{})}function W(e=[]){const t=u("feMerge");return e.forEach(n=>t.appendChild(n)),t}function X(e){const t=Math.round(e*100)/100;return`
|
|
2
2
|
M 0, -${t}
|
|
3
3
|
A ${t},${t} 0 1,1 0,${t}
|
|
4
4
|
A ${t},${t} 0 1,1 0,-${t}
|
|
5
|
-
`.replace(/\s+/g," ").trim()}const he=Object.freeze(Object.defineProperty({__proto__:null,circle:z,circlePath:X,createSVGElement:u,filter:H,gaussianBlur:Y,group:L,merge:W,mergeNode:F,path:B,rect:V,setSVGAttrs:N,text:U,textPath:G,turbulence:q},Symbol.toStringTag,{value:"Module"})),
|
|
5
|
+
`.replace(/\s+/g," ").trim()}const he=Object.freeze(Object.defineProperty({__proto__:null,circle:z,circlePath:X,createSVGElement:u,filter:H,gaussianBlur:Y,group:L,merge:W,mergeNode:F,path:B,rect:V,setSVGAttrs:N,text:U,textPath:G,turbulence:q},Symbol.toStringTag,{value:"Module"})),pe={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"},ye={OVERLAY:"400",CURSOR:"300",FOLLOWER:"200",TRACE:"100"};r.Easings=pe,r.Layers=ye,r.angle=g,r.applyStyles=I,r.circle=z,r.circlePath=X,r.circumference=E,r.clamp=p,r.createActor=h,r.createCircle=T,r.createDiv=_,r.createSVGElement=u,r.css=f,r.damp=S,r.definePlugin=me,r.dist=y,r.doctor=te,r.dom=J,r.effects=Q,r.filter=H,r.gaussianBlur=Y,r.getVelocityDistortion=A,r.group=L,r.hasFinePointer=ee,r.injectStyles=$,r.lerp=d,r.lerpAngle=v,r.math=K,r.merge=W,r.mergeNode=F,r.normalize=R,r.normalizeAll=x,r.path=B,r.projectRect=C,r.random=w,r.rect=V,r.setSVGAttrs=N,r.setStyle=M,r.setTransform=P,r.svg=he,r.text=U,r.textPath=G,r.turbulence=q,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/plugin.d.ts
CHANGED
|
@@ -78,10 +78,15 @@ export interface VisualConfig<E extends HTMLElement | SVGElement = HTMLElement |
|
|
|
78
78
|
/** General teardown hook, called after cleanup and element removal. */
|
|
79
79
|
destroy?(app: SupermouseInstance): void;
|
|
80
80
|
/**
|
|
81
|
-
* Auto-registers this selector
|
|
82
|
-
* Equivalent to `app.
|
|
81
|
+
* Auto-registers this selector in the owning scope's hover set on
|
|
82
|
+
* install. Equivalent to `app.addHoverSelectors(selector)` inside
|
|
83
|
+
* `install()`.
|
|
84
|
+
*
|
|
85
|
+
* The selector contributes to a shared set: all plugins in the same
|
|
86
|
+
* scope see the same `state.hoverTarget`, resolved as the innermost
|
|
87
|
+
* element matching any registered selector.
|
|
83
88
|
*/
|
|
84
|
-
|
|
89
|
+
hoverSelector?: string;
|
|
85
90
|
/**
|
|
86
91
|
* Called before the plugin is disabled. Can return a Promise to delay
|
|
87
92
|
* hiding until an exit animation finishes.
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE/E,wDAAwD;AACxD,MAAM,WAAW,iBAAiB;IAChC,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,UAAU,UAAU;IAClB,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iEAAiE;IACjE,OAAO,CAAC,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAY,SAAQ,UAAU;IAC7C;;;;OAIG;IACH,MAAM,CAAC,CAAC,GAAG,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1D,iEAAiE;IACjE,OAAO,CAAC,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,uDAAuD;IACvD,QAAQ,CAAC,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACzC,wDAAwD;IACxD,SAAS,CAAC,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC1C;;;;OAIG;IACH,aAAa,CAAC,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/D;AAED;;;;;;GAMG;AACH,MAAM,WAAW,YAAY,CAC3B,CAAC,SAAS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,CAAC;IAEvB;;;;OAIG;IACH,aAAa,CAAC,CAAC,GAAG,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3E;AAQD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,WAAW,GAAG,UAAU,EAC7D,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,WAAW,CAAC,EAAE,iBAAiB,GAC9B,gBAAgB,GAAG;IAAE,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAEtC;;;;;;GAMG;AACH,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.4.4-beta.
|
|
3
|
+
"version": "2.4.4-beta.5",
|
|
4
4
|
"main": "dist/index.umd.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@supermousejs/core": "2.5.0-beta.
|
|
36
|
+
"@supermousejs/core": "2.5.0-beta.5"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@supermousejs/core": "2.5.0-beta.
|
|
39
|
+
"@supermousejs/core": "2.5.0-beta.5"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "vite build"
|