@exegia/specular 0.1.0 → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Emmanuel De Freitas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,10 +1,32 @@
1
+ <div align="center">
2
+
3
+ <img src="assets/logo.svg" alt="" width="132" height="132">
4
+
1
5
  # @exegia/specular
2
6
 
3
- Specular lighting for Tailwind v4 + React: a highlight that tracks the pointer.
4
- Declare a surface, get a utility
5
- family that draws a two-layer inset "bezel" one axis at a time, a
6
- tailwind-merge config that keeps those utilities alive in `cn()`, and React
7
- primitives that light the surface with the pointer.
7
+ **✨ Specular lighting for Tailwind v4 + React — a two-layer inset bezel as
8
+ utilities, a `cn()` that keeps them alive, and a rim highlight that tracks the
9
+ pointer.**
10
+
11
+ [![npm](https://img.shields.io/npm/v/@exegia/specular?color=6366f1&labelColor=1c1917)](https://www.npmjs.com/package/@exegia/specular) [![types](https://img.shields.io/npm/types/@exegia/specular?color=38bdf8&labelColor=1c1917)](https://www.npmjs.com/package/@exegia/specular) [![provenance](https://img.shields.io/badge/npm-provenance-a855f7?labelColor=1c1917)](https://www.npmjs.com/package/@exegia/specular#provenance) [![runtime deps](https://img.shields.io/badge/runtime%20deps-0-f43f5e?labelColor=1c1917)](#install) [![license](https://img.shields.io/npm/l/@exegia/specular?color=fbbf24&labelColor=1c1917)](LICENSE)
12
+
13
+ <img src="assets/demo.gif" alt="Six avatars whose rim highlights turn to follow the pointer as it moves across them" width="100%">
14
+
15
+ <sub>Six discs, one window listener. Recorded from <a href="examples/vite-react"><code>examples/vite-react</code></a>.</sub>
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ Declare a surface, get a utility family that draws a two-layer inset "bezel"
22
+ one axis at a time, a tailwind-merge config that keeps those utilities alive
23
+ in `cn()`, and React primitives that light the surface with the pointer.
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ npm i @exegia/specular # or: bun add / pnpm add / yarn add
29
+ ```
8
30
 
9
31
  | export | contents |
10
32
  |---|---|
@@ -97,8 +119,8 @@ For a surface `S` and a layer `L`. Every utility also emits the base
97
119
  | utility | writes |
98
120
  |---|---|
99
121
  | `S-base` (or `baseClass`) | `box-shadow: var(--tw-S-shadow)` |
100
- | `S-L` | `--tw-S-L-alpha: 100` |
101
- | `S-L/40`, `S-L/[0.4]` | `--tw-S-L-alpha: 40` (fractions are scaled; `/80` ≡ `/[0.8]`) |
122
+ | `S-L` | the base `box-shadow` only: layer `L` at its configured alpha, so the `dark` preset applies |
123
+ | `S-L/40`, `S-L/[0.4]` | `--tw-S-L-alpha: 40` (fractions are scaled; `/80` ≡ `/[0.8]`); `/100` is explicit full strength |
102
124
  | `S-L-t-N` | `--tw-S-L-y: calc(N * 1px)` — light enters from the top, pushes the layer down |
103
125
  | `S-L-b-N` | `--tw-S-L-y: calc(N * -1px)` |
104
126
  | `S-L-l-N` / `S-L-r-N` | `--tw-S-L-x` |
@@ -221,6 +243,13 @@ make example-dev # build the library, install the example, start Vite
221
243
  make example-build # production build, what CI runs
222
244
  ```
223
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
+
224
253
  See [`examples/vite-react/README.md`](examples/vite-react/README.md) for what
225
254
  each section shows.
226
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/plugin.js CHANGED
@@ -20,6 +20,9 @@ export function normalizeAlpha(raw) {
20
20
  return String(Math.round(parseFloat(v) * 10000) / 100);
21
21
  return v;
22
22
  }
23
+ /** The `DEFAULT` value handed to the bare layer class. A sentinel, not a
24
+ * number, so `S-L-[100]` (an arbitrary value) still writes the alpha. */
25
+ const CONFIGURED = "configured";
23
26
  const instanceVar = (s, l, p) => `--tw-${s}-${l}-${p}`;
24
27
  const presetVar = (s, l, p) => `--${s}-${l}-${p}`;
25
28
  function chain(s, l, p) {
@@ -75,8 +78,14 @@ export function createPlugin(surfaces, options = {}) {
75
78
  const n = `${s.name}-${l.name}`;
76
79
  const v = (p) => instanceVar(s.name, l.name, p);
77
80
  const set = (p, f = (x) => x) => (value) => ({ ...base, [v(p)]: f(value) });
78
- // Bare = full alpha; `/40` and `/[0.4]` = 40.
79
- matchUtilities({ [n]: (value, { modifier }) => ({ ...base, [v("alpha")]: normalizeAlpha(modifier ?? value) }) }, { values: { DEFAULT: "100" }, modifiers: "any" });
81
+ // Bare = the configured alpha: the class emits only the composed
82
+ // box-shadow, so the alpha chain falls through to the preset (the
83
+ // `dark` block) and then the config. Writing 100 here would make the
84
+ // canonical `bezel-lit bezel-dim` ignore both. `/40` and `/[0.4]` = 40;
85
+ // `/100` is the explicit full-strength form.
86
+ matchUtilities({
87
+ [n]: (value, { modifier }) => modifier === null && value === CONFIGURED ? base : { ...base, [v("alpha")]: normalizeAlpha(modifier ?? value) },
88
+ }, { values: { DEFAULT: CONFIGURED }, modifiers: "any" });
80
89
  // The letter names the edge the light enters from.
81
90
  matchUtilities({ [`${n}-t`]: set("y"), [`${n}-l`]: set("x"), [`${n}-blur`]: set("blur"), [`${n}-spread`]: set("spread") }, lengths(false));
82
91
  matchUtilities({ [`${n}-b`]: set("y", negate), [`${n}-r`]: set("x", negate) }, lengths(true));
@@ -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;
@@ -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 next = unwrap(s.last, bearingFrom(rect.left + rect.width / 2, rect.top + rect.height / 2, pointer.x, pointer.y));
50
- if (next === null)
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
- s.last = next;
53
- s.emit(next);
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 150ms cubic-bezier(0.22, 1, 0.36, 1)";
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 150ms cubic-bezier(0.22, 1, 0.36, 1)";
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 = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exegia/specular",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/emmanuel-defreitas/specular.git"