@exegia/specular 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/pointer-light.d.ts +5 -1
- package/dist/pointer-light.js +37 -8
- package/dist/rim.d.ts +1 -1
- package/dist/rim.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -243,6 +243,13 @@ make example-dev # build the library, install the example, start Vite
|
|
|
243
243
|
make example-build # production build, what CI runs
|
|
244
244
|
```
|
|
245
245
|
|
|
246
|
+
A focused `demo/` app shows just the apply steps and the hover behaviour
|
|
247
|
+
(cards lift, glow buttons, press sink, pointer-following light and rims):
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
make demo-dev # build the library, install the demo, start Vite
|
|
251
|
+
```
|
|
252
|
+
|
|
246
253
|
See [`examples/vite-react/README.md`](examples/vite-react/README.md) for what
|
|
247
254
|
each section shows.
|
|
248
255
|
|
package/dist/index.d.ts
CHANGED
|
@@ -43,6 +43,22 @@ export type SurfaceConfig = {
|
|
|
43
43
|
};
|
|
44
44
|
export type Surfaces = Record<string, SurfaceConfig>;
|
|
45
45
|
export declare function defineSurfaces<const T extends Surfaces>(surfaces: T): T;
|
|
46
|
+
/** Instance-tier custom properties `litVars()` writes: `--tw-{surface}-lit-x/y`. */
|
|
47
|
+
export type LitVars = {
|
|
48
|
+
[k: `--tw-${string}-lit-x`]: string;
|
|
49
|
+
} & {
|
|
50
|
+
[k: `--tw-${string}-lit-y`]: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Instance-tier vars that turn a surface's lit edge toward a pointer bearing.
|
|
54
|
+
*
|
|
55
|
+
* Bearing 0 = 12 o'clock, clockwise. The offset is (-sin, +cos) · depth: an
|
|
56
|
+
* inset layer offset exposes the band OPPOSITE the offset, so a bearing of 0
|
|
57
|
+
* (cursor above) writes (−0, +depth) — the top edge lights up. Pair with
|
|
58
|
+
* `usePointerLight(ref)` and spread into `style`. `surface` must match the
|
|
59
|
+
* surface name in your `defineSurfaces` config.
|
|
60
|
+
*/
|
|
61
|
+
export declare function litVars(angle: number, depth?: number, surface?: string): LitVars;
|
|
46
62
|
export type ResolvedLayer = {
|
|
47
63
|
name: string;
|
|
48
64
|
inset: boolean;
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,22 @@ export function defineSurfaces(surfaces) {
|
|
|
40
40
|
}
|
|
41
41
|
return surfaces;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Instance-tier vars that turn a surface's lit edge toward a pointer bearing.
|
|
45
|
+
*
|
|
46
|
+
* Bearing 0 = 12 o'clock, clockwise. The offset is (-sin, +cos) · depth: an
|
|
47
|
+
* inset layer offset exposes the band OPPOSITE the offset, so a bearing of 0
|
|
48
|
+
* (cursor above) writes (−0, +depth) — the top edge lights up. Pair with
|
|
49
|
+
* `usePointerLight(ref)` and spread into `style`. `surface` must match the
|
|
50
|
+
* surface name in your `defineSurfaces` config.
|
|
51
|
+
*/
|
|
52
|
+
export function litVars(angle, depth = 2.5, surface = "card") {
|
|
53
|
+
const rad = (angle * Math.PI) / 180;
|
|
54
|
+
return {
|
|
55
|
+
[`--tw-${surface}-lit-x`]: `${(-Math.sin(rad) * depth).toFixed(2)}px`,
|
|
56
|
+
[`--tw-${surface}-lit-y`]: `${(Math.cos(rad) * depth).toFixed(2)}px`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
43
59
|
export const LAYER_PROPS = ["x", "y", "blur", "spread", "color", "alpha"];
|
|
44
60
|
export function length(v, fallback = "0") {
|
|
45
61
|
if (v === undefined)
|
package/dist/pointer-light.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare function bearingFrom(cx: number, cy: number, x: number, y: number
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function unwrap(last: number, bearing: number): number | null;
|
|
20
20
|
/** Register a target; the listener exists only while the set is non-empty. */
|
|
21
|
-
export declare function subscribe(target: () => Element | null, emit: (angle: number) => void): () => void;
|
|
21
|
+
export declare function subscribe(target: () => Element | null, emit: (angle: number) => void, damping?: number): () => void;
|
|
22
22
|
/** For tests. */
|
|
23
23
|
export declare const subscriberCount: () => number;
|
|
24
24
|
/** `false` on the server and on first render; tracks the media query after. */
|
|
@@ -26,10 +26,12 @@ export declare function useReducedMotion(): boolean;
|
|
|
26
26
|
export type PointerLightOptions = {
|
|
27
27
|
mode?: "state";
|
|
28
28
|
enabled?: boolean;
|
|
29
|
+
damping?: number;
|
|
29
30
|
} | {
|
|
30
31
|
mode: "var";
|
|
31
32
|
property?: string;
|
|
32
33
|
enabled?: boolean;
|
|
34
|
+
damping?: number;
|
|
33
35
|
};
|
|
34
36
|
/**
|
|
35
37
|
* `mode: "state"` (default) returns the raw bearing and re-renders on change.
|
|
@@ -41,9 +43,11 @@ export type PointerLightOptions = {
|
|
|
41
43
|
export declare function usePointerLight(ref: RefObject<Element | null>, options?: {
|
|
42
44
|
mode?: "state";
|
|
43
45
|
enabled?: boolean;
|
|
46
|
+
damping?: number;
|
|
44
47
|
}): number;
|
|
45
48
|
export declare function usePointerLight(ref: RefObject<Element | null>, options: {
|
|
46
49
|
mode: "var";
|
|
47
50
|
property?: string;
|
|
48
51
|
enabled?: boolean;
|
|
52
|
+
damping?: number;
|
|
49
53
|
}): void;
|
package/dist/pointer-light.js
CHANGED
|
@@ -39,6 +39,7 @@ function flush() {
|
|
|
39
39
|
frame = 0;
|
|
40
40
|
if (!pointer)
|
|
41
41
|
return;
|
|
42
|
+
let unsettled = false;
|
|
42
43
|
for (const s of subscribers) {
|
|
43
44
|
const el = s.target();
|
|
44
45
|
if (!el)
|
|
@@ -46,12 +47,39 @@ function flush() {
|
|
|
46
47
|
const rect = el.getBoundingClientRect();
|
|
47
48
|
if (rect.width === 0)
|
|
48
49
|
continue;
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
50
|
+
const bearing = bearingFrom(rect.left + rect.width / 2, rect.top + rect.height / 2, pointer.x, pointer.y);
|
|
51
|
+
if (s.damping >= 1) {
|
|
52
|
+
const next = unwrap(s.last, bearing);
|
|
53
|
+
if (next === null)
|
|
54
|
+
continue;
|
|
55
|
+
s.last = next;
|
|
56
|
+
s.emit(next);
|
|
51
57
|
continue;
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
}
|
|
59
|
+
// Damped: ease along the shortest arc each frame, self-scheduling until
|
|
60
|
+
// the residual is under a degree. `last` stays continuous.
|
|
61
|
+
if (Number.isNaN(s.last)) {
|
|
62
|
+
s.last = bearing;
|
|
63
|
+
s.emit(bearing);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
let d = bearing - (((s.last % 360) + 360) % 360);
|
|
67
|
+
if (d > 180)
|
|
68
|
+
d -= 360;
|
|
69
|
+
if (d < -180)
|
|
70
|
+
d += 360;
|
|
71
|
+
if (Math.abs(d) <= ANGLE_EPSILON) {
|
|
72
|
+
s.last = bearing;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const moved = s.last + d * s.damping;
|
|
76
|
+
s.last = moved;
|
|
77
|
+
s.emit(moved);
|
|
78
|
+
if (Math.abs(d) * (1 - s.damping) > 0.5)
|
|
79
|
+
unsettled = true;
|
|
54
80
|
}
|
|
81
|
+
if (unsettled && frame === 0)
|
|
82
|
+
frame = requestAnimationFrame(flush);
|
|
55
83
|
}
|
|
56
84
|
function onMove(event) {
|
|
57
85
|
pointer = { x: event.clientX, y: event.clientY };
|
|
@@ -59,8 +87,8 @@ function onMove(event) {
|
|
|
59
87
|
frame = requestAnimationFrame(flush);
|
|
60
88
|
}
|
|
61
89
|
/** Register a target; the listener exists only while the set is non-empty. */
|
|
62
|
-
export function subscribe(target, emit) {
|
|
63
|
-
const sub = { target, last: Number.NaN, emit };
|
|
90
|
+
export function subscribe(target, emit, damping = 1) {
|
|
91
|
+
const sub = { target, last: Number.NaN, emit, damping };
|
|
64
92
|
if (subscribers.size === 0)
|
|
65
93
|
window.addEventListener("pointermove", onMove, { passive: true });
|
|
66
94
|
subscribers.add(sub);
|
|
@@ -96,6 +124,7 @@ export function usePointerLight(ref, options = {}) {
|
|
|
96
124
|
const reduce = useReducedMotion();
|
|
97
125
|
const enabled = options.enabled ?? true;
|
|
98
126
|
const mode = options.mode ?? "state";
|
|
127
|
+
const damping = options.damping ?? 1;
|
|
99
128
|
const property = options.mode === "var" ? (options.property ?? "--light-angle") : null;
|
|
100
129
|
useEffect(() => {
|
|
101
130
|
if (!enabled || reduce)
|
|
@@ -103,7 +132,7 @@ export function usePointerLight(ref, options = {}) {
|
|
|
103
132
|
const emit = property === null
|
|
104
133
|
? setAngle
|
|
105
134
|
: (a) => ref.current?.style.setProperty(property, `${a}deg`);
|
|
106
|
-
return subscribe(() => ref.current, emit);
|
|
107
|
-
}, [enabled, reduce, property, ref]);
|
|
135
|
+
return subscribe(() => ref.current, emit, damping);
|
|
136
|
+
}, [enabled, reduce, property, ref, damping]);
|
|
108
137
|
return mode === "state" ? angle : undefined;
|
|
109
138
|
}
|
package/dist/rim.d.ts
CHANGED
|
@@ -22,5 +22,5 @@ export type RimProps = Omit<HTMLAttributes<HTMLSpanElement>, "children"> & {
|
|
|
22
22
|
lo?: number;
|
|
23
23
|
};
|
|
24
24
|
/** transitions.dev `--duration-quick` / `--ease-smooth-out`. */
|
|
25
|
-
export declare const RIM_TRANSITION = "transform
|
|
25
|
+
export declare const RIM_TRANSITION = "transform 350ms cubic-bezier(0.22, 1, 0.36, 1)";
|
|
26
26
|
export declare function Rim({ angle, hi, lo, style, ...rest }: RimProps): import("react").JSX.Element;
|
package/dist/rim.js
CHANGED
|
@@ -4,7 +4,7 @@ import { useReducedMotion } from "./pointer-light.js";
|
|
|
4
4
|
const GRADIENT = "conic-gradient(from 180deg, var(--rim-lo) 0%, transparent 24%, transparent 28%, var(--rim-hi) 50%, transparent 72%, transparent 76%, var(--rim-lo) 100%)";
|
|
5
5
|
const MASK = "radial-gradient(farthest-side, transparent 78%, #000 92%)";
|
|
6
6
|
/** transitions.dev `--duration-quick` / `--ease-smooth-out`. */
|
|
7
|
-
export const RIM_TRANSITION = "transform
|
|
7
|
+
export const RIM_TRANSITION = "transform 350ms cubic-bezier(0.22, 1, 0.36, 1)";
|
|
8
8
|
export function Rim({ angle = 0, hi, lo, style, ...rest }) {
|
|
9
9
|
const reduce = useReducedMotion();
|
|
10
10
|
const vars = {
|