@supermousejs/utils 2.3.1 โ 2.4.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 +26 -0
- package/README.md +613 -8
- package/dist/css.d.ts +14 -0
- package/dist/css.d.ts.map +1 -1
- package/dist/doctor.d.ts +7 -4
- package/dist/doctor.d.ts.map +1 -1
- package/dist/dom.d.ts +24 -14
- package/dist/dom.d.ts.map +1 -1
- package/dist/index.d.ts +10 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +425 -131
- package/dist/index.umd.js +5 -1
- package/dist/math.d.ts +1 -0
- package/dist/math.d.ts.map +1 -1
- package/dist/options.d.ts +30 -0
- package/dist/options.d.ts.map +1 -1
- package/dist/plugin.d.ts +99 -22
- package/dist/plugin.d.ts.map +1 -1
- package/dist/svg.d.ts +36 -0
- package/dist/svg.d.ts.map +1 -0
- package/package.json +5 -3
- package/src/css.ts +18 -0
- package/src/doctor.ts +285 -32
- package/src/dom.ts +53 -31
- package/src/index.ts +15 -11
- package/src/math.ts +4 -0
- package/src/options.ts +65 -22
- package/src/plugin.ts +183 -119
- package/src/svg.ts +119 -0
- package/dist/layers.d.ts +0 -15
- package/dist/layers.d.ts.map +0 -1
- package/src/layers.ts +0 -17
package/dist/index.umd.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(r=typeof globalThis<"u"?globalThis:r||self,f(r.SupermouseUtils={}))})(this,(function(r){"use strict";function f(e,t,n){return e+(t-e)*n}function S(e,t,n,o){return f(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 g(e,t,n){return Math.min(Math.max(e,t),n)}function p(e,t,n=0,o=0){const i=e-n,c=t-o;return Math.sqrt(i*i+c*c)}function y(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:y,circumference:E,clamp:g,damp:S,dist:p,lerp:f,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 d(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 c=String(i),a=Z(o);n[a]!==c&&(e.style.setProperty(a,c),n[a]=c)}}function M(e,t,n){d(e,{[t]:n})}function I(e,t){d(e,t)}function P(e,t,n,o=0,i=1,c=1,a=0,s=0){const m=`translate3d(${t}px, ${n}px, 0) translate(-50%, -50%) rotate(${o}deg) skew(${a}deg, ${s}deg) scale(${i}, ${c})`;d(e,{transform:m})}function T(e,t=document.body){const n=e.getBoundingClientRect();if(t!==document.body){const o=t.getBoundingClientRect(),i=n.left-o.left,c=n.top-o.top;return new DOMRect(i,c,n.width,n.height)}return n}function h(e="div"){const t=document.createElement(e);return d(t,{position:"absolute",top:"0",left:"0",pointerEvents:"none",boxSizing:"border-box",display:"block",willChange:"transform"}),t}function C(e,t){const n=h("div");return d(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:C,createDiv:_,css:d,injectStyles:$,projectRect:T,setStyle:M,setTransform:P},Symbol.toStringTag,{value:"Module"}));function A(e,t,n=.004,o=.5){const i=p(e,t);if(i<.1)return{rotation:0,scaleX:1,scaleY:1};const c=y(e,t),a=g(i*n,0,o),s=1+a,m=1-a*.5;return{rotation:c,scaleX:s,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),...se(t),...ce(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 se(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 ce(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 c=i.getAttribute("style")??"";c.includes("cursor: none")||c.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"),c=e?.state?.cursorMode??"auto",a=e?.state?.hasReceivedInput??!0,s=e?.input?.isEnabled??!0;c==="custom"&&s&&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)fe(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 fe(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 de(e){return typeof e.create=="function"}function me(e,t={}){const n=t.name??e.name,o=t.isEnabled??!0;if(!de(e))return{...e,name:n,isEnabled:o};let i=null,c=!1;const a=s=>{if(i)return e.beforeDisable?.(s,i)};return{name:n,isEnabled:o,priority:e.priority,install(s){if(i=e.create(s),!(i instanceof HTMLElement)&&!(i instanceof SVGElement)){console.warn(`[supermouse] Plugin "${n}" create() did not return an HTMLElement or SVGElement.`);return}this.element=s.stage.appendChild(i),c=!0,e.selector&&s.registerHoverTarget(e.selector),o||(i.style.display="none"),e.install?.(s)},update(s,m){!i||!c||e.update?.(s,i,m)},onEnable(s){i&&(i.style.display="",e.onEnable?.(s,i))},async onBeforeDisable(s){await a(s)},onDisable(s){i&&e.onDisable?.(s,i)},destroy(s){i&&(e.cleanup?.(s,i),i.remove(),i=null,c=!1),e.destroy?.(s)}}}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
|
+
M 0, -${t}
|
|
3
|
+
A ${t},${t} 0 1,1 0,${t}
|
|
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"})),ge={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"},pe={OVERLAY:"400",CURSOR:"300",FOLLOWER:"200",TRACE:"100"};r.Easings=ge,r.Layers=pe,r.angle=y,r.applyStyles=I,r.circle=z,r.circlePath=X,r.circumference=E,r.clamp=g,r.createActor=h,r.createCircle=C,r.createDiv=_,r.createSVGElement=u,r.css=d,r.damp=S,r.definePlugin=me,r.dist=p,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=f,r.lerpAngle=v,r.math=K,r.merge=W,r.mergeNode=F,r.normalize=R,r.normalizeAll=x,r.path=B,r.projectRect=T,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/math.d.ts
CHANGED
|
@@ -35,4 +35,5 @@ export declare function dist(x1: number, y1: number, x2?: number, y2?: number):
|
|
|
35
35
|
* Calculates the angle in degrees between two points (or vector direction).
|
|
36
36
|
*/
|
|
37
37
|
export declare function angle(x: number, y: number): number;
|
|
38
|
+
export declare function circumference(r: number): number;
|
|
38
39
|
//# sourceMappingURL=math.d.ts.map
|
package/dist/math.d.ts.map
CHANGED
|
@@ -1 +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"}
|
|
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;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
package/dist/options.d.ts
CHANGED
|
@@ -6,6 +6,36 @@ import { MouseState, ValueOrGetter } from '../packages/core/src';
|
|
|
6
6
|
*
|
|
7
7
|
* @param option The option passed by the user
|
|
8
8
|
* @param defaultValue Fallback value
|
|
9
|
+
* @returns A function that returns the resolved value of the option
|
|
9
10
|
*/
|
|
10
11
|
export declare function normalize<T>(option: ValueOrGetter<T> | undefined, defaultValue: T): (state: MouseState) => T;
|
|
12
|
+
/**
|
|
13
|
+
* Normalizes multiple options in one call.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const cfg = normalizeAll(options, {
|
|
17
|
+
* size: 20,
|
|
18
|
+
* color: "#fff",
|
|
19
|
+
* opacity: 1,
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // In update():
|
|
23
|
+
* const size = cfg.size(app.state);
|
|
24
|
+
*
|
|
25
|
+
* @param defaults Default values for the options
|
|
26
|
+
* @param options User-provided options to normalize
|
|
27
|
+
* @returns An object with normalized getter functions for each option
|
|
28
|
+
*/
|
|
29
|
+
export declare function normalizeAll<T extends Record<string, unknown>>(options: Partial<{
|
|
30
|
+
[K in keyof T]: ValueOrGetter<T[K]>;
|
|
31
|
+
}>, defaults: T): {
|
|
32
|
+
[K in keyof T]: (state: MouseState) => T[K];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Checks if the current device has a fine pointer (e.g., mouse) or a coarse pointer (e.g., touch).
|
|
36
|
+
* This is useful for conditionally enabling or disabling cursor effects based on the input device.
|
|
37
|
+
*
|
|
38
|
+
* @returns True if the device has a fine pointer, false otherwise.
|
|
39
|
+
*/
|
|
40
|
+
export declare const hasFinePointer: () => boolean;
|
|
11
41
|
//# sourceMappingURL=options.d.ts.map
|
package/dist/options.d.ts.map
CHANGED
|
@@ -1 +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
|
|
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;;;;;;;;GAQG;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;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,OAAO,EAAE,OAAO,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,EACzD,QAAQ,EAAE,CAAC,GACV;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC;CAAE,CAWjD;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,QAAO,OAC6C,CAAC"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,34 +1,111 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SupermouseInstance, SupermousePlugin } from '../packages/core/src';
|
|
2
|
+
/** Options that can be passed to any plugin factory. */
|
|
2
3
|
export interface BasePluginOptions {
|
|
4
|
+
/** Overrides the plugin's internal name. */
|
|
3
5
|
name?: string;
|
|
6
|
+
/** Whether the plugin starts enabled. Defaults to `true`. */
|
|
4
7
|
isEnabled?: boolean;
|
|
5
8
|
}
|
|
6
|
-
interface
|
|
9
|
+
interface CoreConfig {
|
|
10
|
+
/** Unique identifier. Used by `getPlugin()`, `enablePlugin()`, etc. */
|
|
7
11
|
name: string;
|
|
12
|
+
/** Execution order in the frame loop. Lower values are executed earlier */
|
|
8
13
|
priority?: number;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
onDisable?: (app: Supermouse) => void;
|
|
14
|
-
create?: never;
|
|
14
|
+
/** Whether the plugin starts enabled. Defaults to `true`. */
|
|
15
|
+
isEnabled?: boolean;
|
|
16
|
+
/** Called once when the plugin is registered via `app.use()`. */
|
|
17
|
+
install?(app: SupermouseInstance): void;
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Declarative config for a logic plugin.
|
|
21
|
+
*
|
|
22
|
+
* Logic plugins modify cursor intent (e.g. magnetism, snapping, gravity).
|
|
23
|
+
*/
|
|
24
|
+
export interface LogicConfig extends CoreConfig {
|
|
25
|
+
/**
|
|
26
|
+
* Called every frame while the plugin is enabled.
|
|
27
|
+
* @param app The Supermouse instance.
|
|
28
|
+
* @param deltaTime Elapsed time since last frame, in milliseconds.
|
|
29
|
+
*/
|
|
30
|
+
update?(app: SupermouseInstance, deltaTime: number): void;
|
|
31
|
+
/** Called when the plugin is removed or the app is destroyed. */
|
|
32
|
+
destroy?(app: SupermouseInstance): void;
|
|
33
|
+
/** Called when `app.enablePlugin(name)` is invoked. */
|
|
34
|
+
onEnable?(app: SupermouseInstance): void;
|
|
35
|
+
/** Called when `app.disablePlugin(name)` is invoked. */
|
|
36
|
+
onDisable?(app: SupermouseInstance): void;
|
|
37
|
+
/**
|
|
38
|
+
* Called before the plugin is disabled. Can return a Promise to delay
|
|
39
|
+
* hiding until an exit animation finishes. This is the declarative
|
|
40
|
+
* equivalent of `SupermousePlugin.onBeforeDisable`.
|
|
41
|
+
*/
|
|
42
|
+
beforeDisable?(app: SupermouseInstance): void | Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Declarative config for a visual plugin.
|
|
46
|
+
*
|
|
47
|
+
* @typeParam E - The specific element subtype returned by `create`.
|
|
48
|
+
* Can be an `HTMLElement` (e.g. `HTMLDivElement`) or an `SVGElement`
|
|
49
|
+
* (e.g. `SVGSVGElement`).
|
|
50
|
+
*/
|
|
51
|
+
export interface VisualConfig<E extends HTMLElement | SVGElement = HTMLElement | SVGElement> extends CoreConfig {
|
|
52
|
+
/**
|
|
53
|
+
* Factory that creates the plugin's root DOM element.
|
|
54
|
+
* Called once during `install()`. The returned element is automatically
|
|
55
|
+
* appended to the **stage** (not `app.container`).
|
|
56
|
+
*/
|
|
57
|
+
create: (app: SupermouseInstance) => E;
|
|
58
|
+
/**
|
|
59
|
+
* Called every frame while the plugin is enabled.
|
|
60
|
+
* Use `css()` from `@supermousejs/utils` for style writes,
|
|
61
|
+
* and `setTransform()` for positioning.
|
|
62
|
+
*/
|
|
63
|
+
update?(app: SupermouseInstance, element: E, deltaTime: number): void;
|
|
64
|
+
/** Called when the plugin is enabled. The element is already visible. */
|
|
65
|
+
onEnable?(app: SupermouseInstance, element: E): void;
|
|
66
|
+
/**
|
|
67
|
+
* Called when the plugin is disabled.
|
|
68
|
+
* The element is still in the DOM when this runs, so you can start
|
|
69
|
+
* CSS transitions. If `beforeDisable` is defined and returns a Promise,
|
|
70
|
+
* the core will wait for it to resolve before hiding the element.
|
|
71
|
+
*/
|
|
72
|
+
onDisable?(app: SupermouseInstance, element: E): void;
|
|
73
|
+
/**
|
|
74
|
+
* Called during `destroy()`, before the element is removed from the DOM.
|
|
75
|
+
* Use this to tear down external listeners or GSAP timelines.
|
|
76
|
+
*/
|
|
77
|
+
cleanup?(app: SupermouseInstance, element: E): void;
|
|
78
|
+
/** General teardown hook, called after cleanup and element removal. */
|
|
79
|
+
destroy?(app: SupermouseInstance): void;
|
|
80
|
+
/**
|
|
81
|
+
* Auto-registers this selector as a hover target on install.
|
|
82
|
+
* Equivalent to `app.registerHoverTarget(selector)` inside `install()`.
|
|
83
|
+
*/
|
|
19
84
|
selector?: string;
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
onEnable?: (app: Supermouse, element: E) => void;
|
|
27
|
-
onDisable?: (app: Supermouse, element: E) => void;
|
|
28
|
-
cleanup?: (element: E) => void;
|
|
29
|
-
destroy?: never;
|
|
85
|
+
/**
|
|
86
|
+
* Called before the plugin is disabled. Can return a Promise to delay
|
|
87
|
+
* hiding until an exit animation finishes.
|
|
88
|
+
* Receives the element as the second argument.
|
|
89
|
+
*/
|
|
90
|
+
beforeDisable?(app: SupermouseInstance, element: E): void | Promise<void>;
|
|
30
91
|
}
|
|
31
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Creates a visual plugin with automatic DOM mounting and lifecycle management.
|
|
94
|
+
*
|
|
95
|
+
* @param config Visual plugin definition.
|
|
96
|
+
* @param userOptions Optional overrides for `name` and `isEnabled`.
|
|
97
|
+
* @returns A `SupermousePlugin` whose `element` property is typed as `E`.
|
|
98
|
+
*/
|
|
99
|
+
export declare function definePlugin<E extends HTMLElement | SVGElement>(config: VisualConfig<E>, userOptions?: BasePluginOptions): SupermousePlugin & {
|
|
100
|
+
element?: E;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Creates a logic plugin that is passed through directly.
|
|
104
|
+
*
|
|
105
|
+
* @param config Logic plugin definition.
|
|
106
|
+
* @param userOptions Optional overrides for `name` and `isEnabled`.
|
|
107
|
+
* @returns A `SupermousePlugin`.
|
|
108
|
+
*/
|
|
32
109
|
export declare function definePlugin(config: LogicConfig, userOptions?: BasePluginOptions): SupermousePlugin;
|
|
33
110
|
export {};
|
|
34
111
|
//# sourceMappingURL=plugin.d.ts.map
|
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,
|
|
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,EA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GAAG,IAAI,CAAC;IACrD;;;;;OAKG;IACH,SAAS,CAAC,CAAC,GAAG,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IAEtD;;;OAGG;IACH,OAAO,CAAC,CAAC,GAAG,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IACpD,uEAAuE;IACvE,OAAO,CAAC,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAExC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;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/dist/svg.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type SVGAttrs = Record<string, string | number | boolean>;
|
|
2
|
+
/** Create any SVG element by tag name with attributes. */
|
|
3
|
+
export declare function createSVGElement<K extends keyof SVGElementTagNameMap>(tag: K, attrs?: SVGAttrs): SVGElementTagNameMap[K];
|
|
4
|
+
/** Set multiple attributes on an SVG element. */
|
|
5
|
+
export declare function setSVGAttrs(el: SVGElement, attrs: SVGAttrs): void;
|
|
6
|
+
/** Create a `<g>` group. */
|
|
7
|
+
export declare function group(attrs?: SVGAttrs): SVGGElement;
|
|
8
|
+
/** Create a `<circle>`. */
|
|
9
|
+
export declare function circle(attrs?: SVGAttrs): SVGCircleElement;
|
|
10
|
+
/** Create a `<rect>`. */
|
|
11
|
+
export declare function rect(attrs?: SVGAttrs): SVGRectElement;
|
|
12
|
+
/** Create a `<path>` with optional `d` attribute. */
|
|
13
|
+
export declare function path(d?: string, attrs?: SVGAttrs): SVGPathElement;
|
|
14
|
+
/** Create a `<text>` element. */
|
|
15
|
+
export declare function text(attrs?: SVGAttrs, content?: string): SVGTextElement;
|
|
16
|
+
/** Create a `<textPath>` with proper `href` and `xlink:href`. */
|
|
17
|
+
export declare function textPath(href: string, attrs?: SVGAttrs): SVGTextPathElement;
|
|
18
|
+
/** Create a `<filter>` with region attributes and children. */
|
|
19
|
+
export declare function filter(id: string, attrs?: SVGAttrs, children?: SVGElement[]): SVGFilterElement;
|
|
20
|
+
/** Create a `<feGaussianBlur>` primitive. */
|
|
21
|
+
export declare function gaussianBlur(stdDeviation?: string | number, attrs?: SVGAttrs): SVGFEGaussianBlurElement;
|
|
22
|
+
/** Create a `<feTurbulence>` primitive. */
|
|
23
|
+
export declare function turbulence(baseFrequency?: string | number, attrs?: SVGAttrs): SVGFETurbulenceElement;
|
|
24
|
+
/** Create a `<feMergeNode>` primitive. */
|
|
25
|
+
export declare function mergeNode(inAttr?: string): SVGFEMergeNodeElement;
|
|
26
|
+
/** Create a `<feMerge>` container with merge node children. */
|
|
27
|
+
export declare function merge(nodes?: SVGFEMergeNodeElement[]): SVGFEMergeElement;
|
|
28
|
+
/**
|
|
29
|
+
* Calculates the SVG Path data for a perfect circle starting at the top center (12 o'clock).
|
|
30
|
+
*
|
|
31
|
+
* Path moves to (0, -r), then draws two semi-circles.
|
|
32
|
+
* @param r Radius in pixels
|
|
33
|
+
*/
|
|
34
|
+
export declare function circlePath(r: number): string;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=svg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.d.ts","sourceRoot":"","sources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Aa,GAAE,MAAM,GAAG,MAAY,EACpC,KAAK,GAAE,QAAa,GACnB,sBAAsB,CAKxB;AAED,0CAA0C;AAC1C,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAEhE;AAED,+DAA+D;AAC/D,wBAAgB,KAAK,CAAC,KAAK,GAAE,qBAAqB,EAAO,GAAG,iBAAiB,CAI5E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAU5C"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supermousejs/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"main": "dist/index.umd.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"author": "O.S David",
|
|
8
|
+
"description": "Shared utilities and helpers for writing Supermouse plugins",
|
|
8
9
|
"url": "https://github.com/Whitestar14/supermouse-js",
|
|
10
|
+
"sideEffects": false,
|
|
9
11
|
"license": "MIT",
|
|
10
12
|
"exports": {
|
|
11
13
|
".": {
|
|
@@ -27,10 +29,10 @@
|
|
|
27
29
|
"access": "public"
|
|
28
30
|
},
|
|
29
31
|
"peerDependencies": {
|
|
30
|
-
"@supermousejs/core": "2.
|
|
32
|
+
"@supermousejs/core": "2.4.0"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
|
-
"@supermousejs/core": "2.
|
|
35
|
+
"@supermousejs/core": "2.4.0"
|
|
34
36
|
},
|
|
35
37
|
"scripts": {
|
|
36
38
|
"build": "vite build"
|
package/src/css.ts
CHANGED
|
@@ -9,3 +9,21 @@ export const Easings = {
|
|
|
9
9
|
/** Standard smooth movement */
|
|
10
10
|
SMOOTH: "ease-out"
|
|
11
11
|
} as const;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Standard Z-Index layers for the Supermouse ecosystem.
|
|
15
|
+
* Relative to the Supermouse Container.
|
|
16
|
+
*/
|
|
17
|
+
export const Layers = {
|
|
18
|
+
/** The top-most layer. For text, tooltips, and crucial UI. */
|
|
19
|
+
OVERLAY: "400",
|
|
20
|
+
|
|
21
|
+
/** The main cursor layer. For the primary Dot/Pointer. */
|
|
22
|
+
CURSOR: "300",
|
|
23
|
+
|
|
24
|
+
/** The secondary layer. For Rings, brackets, or followers. */
|
|
25
|
+
FOLLOWER: "200",
|
|
26
|
+
|
|
27
|
+
/** The background layer. For trails, sparkles, and particles. */
|
|
28
|
+
TRACE: "100"
|
|
29
|
+
} as const;
|