@wix/interact 2.0.0-rc.8 → 2.0.1

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/rules/click.md CHANGED
@@ -61,8 +61,7 @@ These rules help generate click-based interactions using the `@wix/interact` lib
61
61
  key: 'mobile-nav',
62
62
  namedEffect: {
63
63
  type: 'SlideIn',
64
- direction: 'left',
65
- power: 'medium'
64
+ direction: 'left'
66
65
  },
67
66
  fill: 'both',
68
67
  reversed: true,
@@ -119,14 +118,14 @@ These rules help generate click-based interactions using the `@wix/interact` lib
119
118
 
120
119
  ```typescript
121
120
  {
122
- source: '[SOURCE_IDENTIFIER]',
121
+ key: '[SOURCE_IDENTIFIER]',
123
122
  trigger: 'click',
124
123
  params: {
125
124
  type: 'state'
126
125
  },
127
126
  effects: [
128
127
  {
129
- target: '[TARGET_IDENTIFIER]',
128
+ key: '[TARGET_IDENTIFIER]',
130
129
  [EFFECT_TYPE]: [EFFECT_DEFINITION],
131
130
  fill: 'both',
132
131
  reversed: [INITIAL_REVERSED_BOOL],
@@ -277,8 +276,7 @@ These rules help generate click-based interactions using the `@wix/interact` lib
277
276
  key: 'success-badge',
278
277
  namedEffect: {
279
278
  type: 'BounceIn',
280
- direction: 'center',
281
- power: 'medium'
279
+ direction: 'center'
282
280
  },
283
281
  duration: 600,
284
282
  easing: 'cubic-bezier(0.34, 1.56, 0.64, 1)',
@@ -309,7 +307,7 @@ These rules help generate click-based interactions using the `@wix/interact` lib
309
307
  key: '[SOURCE_IDENTIFIER]',
310
308
  trigger: 'click',
311
309
  params: {
312
- type: 'alternate'
310
+ method: 'toggle'
313
311
  },
314
312
  effects: [
315
313
  {
@@ -342,7 +340,7 @@ These rules help generate click-based interactions using the `@wix/interact` lib
342
340
  key: 'theme-switcher',
343
341
  trigger: 'click',
344
342
  params: {
345
- type: 'alternate'
343
+ method: 'toggle'
346
344
  },
347
345
  effects: [
348
346
  {
@@ -370,7 +368,7 @@ These rules help generate click-based interactions using the `@wix/interact` lib
370
368
  key: 'style-toggle',
371
369
  trigger: 'click',
372
370
  params: {
373
- type: 'alternate'
371
+ method: 'toggle'
374
372
  },
375
373
  effects: [
376
374
  {
@@ -397,7 +395,7 @@ These rules help generate click-based interactions using the `@wix/interact` lib
397
395
  key: 'interactive-card',
398
396
  trigger: 'click',
399
397
  params: {
400
- type: 'alternate'
398
+ method: 'toggle'
401
399
  },
402
400
  effects: [
403
401
  {
@@ -34,7 +34,7 @@ Interact.create(config);
34
34
 
35
35
  ```html
36
36
  <script type="module">
37
- import { Interact } from 'https://esm.sh/@wix/interact@2.0.0-rc.4';
37
+ import { Interact } from 'https://esm.sh/@wix/interact';
38
38
 
39
39
  const config = {
40
40
  // config-props
@@ -48,7 +48,7 @@ Interact.create(config);
48
48
 
49
49
  - Use `generate(config)` to create critical CSS that hides elements until their `viewEnter` entrance animation plays.
50
50
  - Add `data-interact-initial="true"` to the `<interact-element>` that should have its first child hidden initially.
51
- - Only use `data-interact-initial="true"` for `<interact-element>` with `viewEnter` trigger.
51
+ - Only use `data-interact-initial="true"` for `<interact-element>` with `viewEnter` trigger and `type: 'once'`, where the source and target elements are the same.
52
52
  - Do NOT use for `hover` or `click` interactions.
53
53
 
54
54
  **Usage:**
@@ -115,9 +115,10 @@ This configuration declares what user/system triggers occur on which source elem
115
115
  - **Purpose**: Named predicates that gate interactions/effects by runtime context.
116
116
  - **Key (string)**: The condition id. MUST be unique across the registry.
117
117
  - **Value (Condition)**:
118
- - **type**: `'media' | 'container'`
118
+ - **type**: `'media' | 'container' | 'selector'`
119
119
  - `'media'`: The predicate MUST be a valid CSS media query expression without the outer `@media` keyword (e.g., `'(min-width: 768px)'`).
120
120
  - `'container'`: The predicate SHOULD be a valid CSS container query condition string relative to the relevant container context.
121
+ - `'selector'`: The predicate is a CSS selector pattern. If it contains `&`, the `&` is replaced with the base element selector; otherwise the predicate is appended to the base selector. Used for conditional styling (e.g., `:nth-of-type(odd)`, `.active`).
121
122
  - **predicate?**: OPTIONAL textual predicate for the given type. If omitted, the condition is treated as always-true (i.e., a no-op guard).
122
123
 
123
124
  - **interactions: Interaction[]**
@@ -131,13 +132,13 @@ This configuration declares what user/system triggers occur on which source elem
131
132
  - OPTIONAL. A CSS selector used to select items within `listContainer`.
132
133
  - **trigger: TriggerType**
133
134
  - REQUIRED. One of:
134
- - `'hover' | 'click'`: Pointer interactions.
135
+ - `'hover' | 'click' | 'activate' | 'interest'`: Pointer interactions (`activate` = click with keyboard Space/Enter; `interest` = hover with focus).
135
136
  - `'viewEnter' | 'pageVisible' | 'viewProgress'`: Viewport visibility/progress triggers.
136
137
  - `'animationEnd'`: Fires when a specific effect completes on the source element.
137
138
  - `'pointerMove'`: Continuous pointer motion over an area.
138
139
  - **params?: TriggerParams**
139
140
  - OPTIONAL. Parameter object that MUST match the trigger:
140
- - hover/click: `StateParams | PointerTriggerParams`
141
+ - hover/click/activate/interest: `StateParams | PointerTriggerParams` (activate uses same params as click; interest uses same params as hover).
141
142
  - `StateParams.method`: `'add' | 'remove' | 'toggle' | 'clear'`
142
143
  - `PointerTriggerParams.type?`: `'once' | 'repeat' | 'alternate' | 'state'`
143
144
  - Usage:
@@ -153,13 +154,14 @@ This configuration declares what user/system triggers occur on which source elem
153
154
  - `'once'`: Play once and remove the listener (hover attaches only the enter listener; no leave).
154
155
  - `'state'`: Hover — play on enter if idle/paused, pause on leave if running. Click — toggle play/pause on successive clicks until finished.
155
156
  - viewEnter/pageVisible/viewProgress: `ViewEnterParams`
156
- - `type?`: `'once' | 'repeat' | 'alternate'`
157
+ - `type?`: `'once' | 'repeat' | 'alternate' | 'state'`
157
158
  - `threshold?`: number in [0,1] describing intersection threshold
158
159
  - `inset?`: string CSS-style inset for rootMargin/observer geometry
159
160
  - Usage:
160
161
  - `'once'`: Play on first visibility and unobserve the element.
161
162
  - `'repeat'`: Play each time the element re‑enters visibility according to `threshold`/`inset`.
162
163
  - `'alternate'`: Triggers on re‑entries; if you need alternating direction, set it on the effect (e.g., `alternate: true`) rather than relying on the trigger.
164
+ - `'state'`: Play on entry, pause on exit (for looping/continuous animations).
163
165
  - `threshold`: Passed to `IntersectionObserver.threshold` — typical values are 0.1–0.6 for entrances.
164
166
  - `inset`: Applied as vertical `rootMargin` (`top/bottom`), e.g., `'-100px'` to trigger earlier/later; left/right remain 0.
165
167
  - Note: For `viewProgress`, `threshold` and `inset` are ignored; progress is driven by ViewTimeline/scroll scenes. Control the range via `ScrubEffect.rangeStart/rangeEnd` and `namedEffect.range`.
@@ -168,10 +170,11 @@ This configuration declares what user/system triggers occur on which source elem
168
170
  - Usage: Fire when the specified effect (by `effectId`) on the source element finishes, useful for chaining sequences.
169
171
  - pointerMove: `PointerMoveParams`
170
172
  - `hitArea?`: `'root' | 'self'` (default `'self'`)
173
+ - `axis?`: `'x' | 'y'` - when using `keyframeEffect` with `pointerMove`, selects which pointer coordinate maps to linear 0-1 progress; defaults to `'y'`. Ignored for `namedEffect` and `customEffect`.
171
174
  - Usage:
172
175
  - `'self'`: Track pointer within the source element’s bounds.
173
176
  - `'root'`: Track pointer anywhere in the viewport (document root).
174
- - Only use with `ScrubEffect` mouse presets (`namedEffect`) or `customEffect` that consumes pointer progress; avoid `keyframeEffect` with `pointerMove`.
177
+ - Only use with `ScrubEffect` mouse presets (`namedEffect`) or `customEffect` that consumes pointer progress; avoid `keyframeEffect` with `pointerMove` unless mapping a single axis via `axis`.
175
178
  - When using `customEffect` with `pointerMove`, the progress parameter is an object:
176
179
  - ```typescript
177
180
  type Progress = {
@@ -343,7 +346,7 @@ The config remains the same for both integrations—only the HTML/JSX setup diff
343
346
  - `delay?`: number (ms)
344
347
  - One of:
345
348
  - `keyframeEffect`: `{ name: string; keyframes: Keyframe[] }`
346
- - `namedEffect`: `NamedEffect` (from `@wix/motion`)
349
+ - `namedEffect`: `NamedEffect` (from `@wix/motion-presets`)
347
350
  - `customEffect`: `(element: Element, progress: any) => void`
348
351
 
349
352
  2. **ScrubEffect** (animation driven by scroll/progress)
@@ -373,12 +376,12 @@ The config remains the same for both integrations—only the HTML/JSX setup diff
373
376
  - 'exit-crossing': The moment the target's center crosses the exit boundary.
374
377
  - If omitted, the runtime chooses a context-appropriate anchor; specify explicitly for deterministic behavior.
375
378
  - offset: A `LengthPercentage` that shifts the anchor boundary.
376
- - Explicit format: `{ value: number; type: 'percentage' | 'px' | 'em' | 'rem' | 'vh' | 'vw' | 'vmin' | 'vmax' }`
379
+ - Explicit format: `{ value: number; unit: 'percentage' | 'px' | 'em' | 'rem' | 'vh' | 'vw' | 'vmin' | 'vmax' }`
377
380
  - Percentages are interpreted along the relevant scroll axis relative to the observation area (e.g., viewport or container size).
378
381
  - Positive values move the anchor "forward" along the scroll direction; negative values move it "backward".
379
382
  - Examples:
380
- - Start when the element is 20% inside the viewport: `rangeStart: { name: 'entry', offset: { value: 20, type: 'percentage' } }`
381
- - End when the element is leaving: `rangeEnd: { name: 'exit', offset: { value: 0, type: 'percentage' } }`
383
+ - Start when the element is 20% inside the viewport: `rangeStart: { name: 'entry', offset: { value: 20, unit: 'percentage' } }`
384
+ - End when the element is leaving: `rangeEnd: { name: 'exit', offset: { value: 0, unit: 'percentage' } }`
382
385
 
383
386
  3. **TransitionEffect** (CSS transition-style state toggles)
384
387
  - `key?`: string (target override; see TARGET CASCADE)
@@ -391,15 +394,10 @@ The config remains the same for both integrations—only the HTML/JSX setup diff
391
394
 
392
395
  ### Authoring rules for animation payloads (`namedEffect`, `keyframeEffect`, `customEffect`):
393
396
 
394
- - **namedEffect (Preferred)**: Use first for best performance. These are pre-built presets from `@wix/motion` that are GPU-friendly and tuned.
395
- - Structure: `namedEffect: { type: '<PresetName>', /* optional preset options like direction (bottom|top|left|right), power ('soft'|'medium'|'hard'), etc. do not use those without having proper documentation of which options exist and of what types. */ }`
396
- - Short list of common preset names:
397
- - Entrance: `FadeIn`, `BounceIn`, `SlideIn`, `FlipIn`, `ArcIn`
398
- - Ongoing: `Pulse`, `Spin`, `Wiggle`, `Bounce`
399
- - Scroll: `ParallaxScroll`, `FadeScroll`, `RevealScroll`, `TiltScroll`
400
- - For scroll-effects used with the `viewProgress` trigger, the `namedEffect` options MUST include `range: 'in' | 'out' | 'continuous'`. Prefer `range: 'continuous'` for simplicity.
401
- - Mouse: For `pointerMove` (mouse-effects), prefer `namedEffect` presets (e.g., `TrackMouse`, `Tilt3DMouse`, `ScaleMouse`, `BlurMouse`); avoid `keyframeEffect` with `pointerMove` since progress is two‑dimensional.
402
- - Mouse: `TrackMouse`, `Tilt3DMouse`, `ScaleMouse`, `BlurMouse`
397
+ - **namedEffect (Preferred)**: Use first for best performance. These are pre-built presets from `@wix/motion-presets` that are GPU-friendly and tuned.
398
+ - Structure: `namedEffect: { type: '<PresetName>', /* optional preset options like direction (bottom|top|left|right), etc. do not use those without having proper documentation of which options exist and of what types. */ }`
399
+ - Short list of common preset names: - Entrance: `FadeIn`, `BounceIn`, `SlideIn`, `F
400
+ lipIn`, `ArcIn` - Ongoing: `Pulse`, `Spin`, `Wiggle`, `Bounce` - Scroll: `ParallaxScroll`, `FadeScroll`, `RevealScroll`, `TiltScroll` - For scroll-effects used with the `viewProgress` trigger, the `namedEffect` options MUST include `range: 'in' | 'out' | 'continuous'`. Prefer `range: 'continuous'` for simplicity. - Mouse: For `pointerMove` (mouse-effects), prefer `namedEffect` presets (e.g., `TrackMouse`, `Tilt3DMouse`, `ScaleMouse`, `BlurMouse`); avoid `keyframeEffect` with `pointerMove` since progress is two‑dimensional. - Mouse: `TrackMouse`, `Tilt3DMouse`, `ScaleMouse`, `BlurMouse`
403
401
  - **keyframeEffect (Default for custom animations)**: Prefer this when you need a custom-made animation.
404
402
  - Structure: `keyframeEffect: { name: string; keyframes: Keyframe[] }` (keyframes use standard CSS/WAAPI properties).
405
403
  - Not compatible with `pointerMove` (mouse-effects) because pointer progress is two‑dimensional; use `customEffect` for custom pointer‑driven animations.
package/rules/hover.md CHANGED
@@ -95,7 +95,7 @@ This document contains rules for generating hover trigger interactions in `@wix/
95
95
 
96
96
  ## Rule 2: Hover Enter/Leave Animations with Named Effects
97
97
 
98
- **Purpose**: Generate hover interactions using pre-built named effects from @wix/motion
98
+ **Purpose**: Generate hover interactions using pre-built named effects from @wix/motion-presets
99
99
 
100
100
  **Pattern**:
101
101
 
@@ -125,7 +125,7 @@ This document contains rules for generating hover trigger interactions in `@wix/
125
125
  **Variables**:
126
126
 
127
127
  - `[REVERSED_BOOL]`: Optional boolean value indicating whether the mouse enter animation is reversed (and mouse leave is forwards).
128
- - `[NAMED_EFFECT_TYPE]`: Name of the pre-built named effect from @wix/motion to use.
128
+ - `[NAMED_EFFECT_TYPE]`: Name of the pre-built named effect from @wix/motion-presets to use.
129
129
  - `[EFFECT_PROPERTIES]`: Named effect specific properties (distance, angle, perspective, etc.)
130
130
  - Other variables same as Rule 1
131
131
 
@@ -159,8 +159,7 @@ This document contains rules for generating hover trigger interactions in `@wix/
159
159
  {
160
160
  key: 'feature-card',
161
161
  namedEffect: {
162
- type: 'Pulse',
163
- power: 'soft'
162
+ type: 'Pulse'
164
163
  },
165
164
  fill: 'both',
166
165
  duration: 250,
@@ -181,8 +180,7 @@ This document contains rules for generating hover trigger interactions in `@wix/
181
180
  key: 'button-icon',
182
181
  namedEffect: {
183
182
  type: 'SpinIn',
184
- direction: 'clockwise',
185
- power: 'soft'
183
+ direction: 'clockwise'
186
184
  },
187
185
  fill: 'both',
188
186
  duration: 200,
@@ -169,20 +169,22 @@ const html = `
169
169
 
170
170
  **When to Use:**
171
171
 
172
- - For elements with an entrance efffect that is triggered a with `viewEnter`
172
+ - For elements with an entrance effect that is triggered with `viewEnter`
173
173
  - To prevent elements from being visible before their entrance animation plays
174
174
  - For server-side rendering (SSR) or static site generation (SSG) scenarios
175
175
 
176
176
  ## 5. Triggers & Behaviors
177
177
 
178
- | Trigger | Description | Key Parameters | Rules File |
179
- | :------------- | :------------------------------- | :------------------------------------------------------------------------------------------------------------------------ | :------------------ |
180
- | `hover` | Mouse enter/leave | `type`: 'once', 'alternate', 'repeat', 'state' for animations, or `method`: 'add', 'remove', 'toggle', 'clear' for states | `./hover.md` |
181
- | `click` | Mouse click | `type`: 'once', 'alternate', 'repeat', 'state' for animations, or `method`: 'add', 'remove', 'toggle', 'clear' for states | `./click.md` |
182
- | `viewEnter` | Element enters viewport | `type`: 'once', 'alternate', 'repeat', 'state'; `threshold` (0-1) | `./viewEnter.md` |
183
- | `viewProgress` | Scroll-driven using ViewTimeline | (No specific params, uses effect ranges) | `./viewprogress.md` |
184
- | `pointerMove` | Mouse movement | `hitArea`: 'self' (default) or 'root' | `./pointermove.md` |
185
- | `animationEnd` | Chaining animations | `effectId`: ID of the previous effect | -- |
178
+ | Trigger | Description | Key Parameters | Rules File |
179
+ | :------------- | :---------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------ | :------------------ |
180
+ | `hover` | Mouse enter/leave | `type`: 'once', 'alternate', 'repeat', 'state' for animations, or `method`: 'add', 'remove', 'toggle', 'clear' for states | `./hover.md` |
181
+ | `click` | Mouse click | `type`: 'once', 'alternate', 'repeat', 'state' for animations, or `method`: 'add', 'remove', 'toggle', 'clear' for states | `./click.md` |
182
+ | `activate` | Accessible click (click + keyboard Space/Enter) | Same as `click` with keyboard support | `./click.md` |
183
+ | `interest` | Accessible hover (hover + focus) | Same as `hover` with focus support | `./hover.md` |
184
+ | `viewEnter` | Element enters viewport | `type`: 'once', 'alternate', 'repeat', 'state'; `threshold` (0-1) | `./viewenter.md` |
185
+ | `viewProgress` | Scroll-driven using ViewTimeline | (No specific params, uses effect ranges) | `./viewprogress.md` |
186
+ | `pointerMove` | Mouse movement | `hitArea`: 'self' (default) or 'root'; `axis`: 'x' or 'y' for keyframeEffect | `./pointermove.md` |
187
+ | `animationEnd` | Chaining animations | `effectId`: ID of the previous effect | -- |
186
188
 
187
189
  ## 6. Effects & Animations
188
190
 
@@ -190,9 +192,33 @@ Effects define _what_ happens. They can be inline or referenced by ID.
190
192
 
191
193
  ### Effect Types
192
194
 
193
- #### 1. Named Effects (Pre-built)
195
+ #### 1. Named Effects (Pre-built effect library)>
194
196
 
195
- Use Motion effect presets for consistency.
197
+ Use the @wix/motion-presets library for consistency.
198
+
199
+ **Install:**
200
+
201
+ ```bash
202
+ > npm install @wix/motion-presets
203
+ ```
204
+
205
+ **Import and register:**
206
+
207
+ ```typescript
208
+ import { Interact } from '@wix/interact/web';
209
+ import * as presets from '@wix/motion-presets';
210
+
211
+ Interact.registerEffects(presets);
212
+ ```
213
+
214
+ **Or register only required presets:**
215
+
216
+ ```typescript
217
+ import { Interact } from '@wix/interact/web';
218
+ import { FadeIn, ParallaxScroll } from '@wix/motion-presets';
219
+
220
+ Interact.registerEffects({ FadeIn, ParallaxScroll });
221
+ ```
196
222
 
197
223
  ```typescript
198
224
  {
@@ -239,8 +265,8 @@ Used with `viewProgress`, linked to scroll progress while element is inside view
239
265
  ```typescript
240
266
  {
241
267
  keyframeEffect: { ... },
242
- rangeStart: { name: 'cover', offset: { value: 0, type: 'percentage' } },
243
- rangeEnd: { name: 'cover', offset: { value: 100, type: 'percentage' } },
268
+ rangeStart: { name: 'cover', offset: { value: 0, unit: 'percentage' } },
269
+ rangeEnd: { name: 'cover', offset: { value: 100, unit: 'percentage' } },
244
270
  fill: 'both'
245
271
  }
246
272
  ```