layershift 0.4.2 → 0.5.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/README.md CHANGED
@@ -52,7 +52,7 @@ npm install layershift
52
52
 
53
53
  ```js
54
54
  import 'layershift';
55
- // <layershift-effect> and <layershift-portal> are now registered
55
+ // <layershift-effect> is now registered
56
56
  ```
57
57
 
58
58
  ### TypeScript
@@ -135,7 +135,7 @@ Components follow atomic design (Atoms → Molecules → Organisms → Templates
135
135
 
136
136
  | Event | Detail | When |
137
137
  |-------|--------|------|
138
- | `layershift-effect:ready` | `{ videoWidth, videoHeight, duration }` | Initialization complete |
138
+ | `layershift-effect:ready` | `{ videoWidth, videoHeight, duration, motionConfig }` | Initialization complete |
139
139
  | `layershift-effect:play` | `{ currentTime }` | Video starts playing |
140
140
  | `layershift-effect:pause` | `{ currentTime }` | Video pauses |
141
141
  | `layershift-effect:loop` | `{ loopCount }` | Video loops back to start |
@@ -150,6 +150,84 @@ el.addEventListener('layershift-effect:ready', (e) => {
150
150
  });
151
151
  ```
152
152
 
153
+ ### Input
154
+
155
+ The component reads its position offset from the `input` property every frame. This decoupled design lets you use the built-in helpers or wire your own input source.
156
+
157
+ #### Quick Setup
158
+
159
+ Wire input on the ready event using the authored motion settings:
160
+
161
+ **ESM (npm)**
162
+ ```js
163
+ import { connectPointer } from 'layershift';
164
+
165
+ const el = document.querySelector('layershift-effect');
166
+ el.addEventListener('layershift-effect:ready', (e) => {
167
+ const { motionConfig } = e.detail;
168
+ const cleanup = connectPointer(el, motionConfig);
169
+ // Call cleanup() to stop input tracking
170
+ });
171
+ ```
172
+
173
+ **IIFE (script tag)**
174
+ ```js
175
+ const el = document.querySelector('layershift-effect');
176
+ el.addEventListener('layershift-effect:ready', (e) => {
177
+ const { motionConfig } = e.detail;
178
+ Layershift.connectPointer(el, motionConfig);
179
+ });
180
+ ```
181
+
182
+ #### Manual Input
183
+
184
+ Skip the helpers entirely and set `el.input` directly:
185
+
186
+ ```js
187
+ el.input = { x: 0.5, y: -0.3 }; // normalized -1 to 1
188
+ ```
189
+
190
+ This works with any input source — MIDI controllers, WebSocket streams, scroll position, animation timelines, or your own custom logic.
191
+
192
+ #### Helpers Reference
193
+
194
+ | Helper | Input Source | Best For |
195
+ |--------|-------------|----------|
196
+ | `connectPointer(el, opts?)` | Mouse + touch + gyro | Default — handles all devices |
197
+ | `connectMouse(el, opts?)` | Mouse only | Desktop-only experiences |
198
+ | `connectTouch(el, opts?)` | Touch drag | Touch-only experiences |
199
+ | `connectGyro(el, opts?)` | Device orientation | Mobile tilt control |
200
+
201
+ Each helper returns a cleanup function. Do not combine standalone helpers on the same element — use `connectPointer` instead.
202
+
203
+ #### InputOptions
204
+
205
+ | Option | Type | Default | Description |
206
+ |--------|------|---------|-------------|
207
+ | `sensitivityX` | number | 1 | Horizontal multiplier |
208
+ | `sensitivityY` | number | 1 | Vertical multiplier |
209
+ | `lerpFactor` | number | 0.08 | Smoothing factor (0–1, lower = smoother) |
210
+
211
+ ```js
212
+ connectPointer(el, {
213
+ sensitivityX: 0.4, // subtle horizontal movement
214
+ sensitivityY: 1.0, // full vertical movement
215
+ lerpFactor: 0.08, // smooth interpolation
216
+ });
217
+ ```
218
+
219
+ #### TypeScript
220
+
221
+ ```ts
222
+ import { connectPointer, connectMouse, type InputOptions } from 'layershift';
223
+ import type { EffectInput } from 'layershift';
224
+
225
+ const el = document.querySelector('layershift-effect')!;
226
+ const cleanup = connectPointer(el as HTMLElement & { input: EffectInput }, {
227
+ sensitivityX: 0.4,
228
+ });
229
+ ```
230
+
153
231
  ### Performance
154
232
 
155
233
  Each `<layershift-effect>` instance creates 1 WebGL renderer, 1 Web Worker, 1 hidden `<video>` element, and 2 GPU textures (1 draw call per frame). The bilateral filter runs entirely off the main thread.