@wix/interact 1.92.0 → 2.0.0-rc.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/dist/cjs/index.js +2 -23
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react.js +15 -0
- package/dist/cjs/react.js.map +1 -0
- package/dist/cjs/web.js +2 -0
- package/dist/cjs/web.js.map +1 -0
- package/dist/es/index.js +8 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/react.js +650 -0
- package/dist/es/react.js.map +1 -0
- package/dist/es/web.js +56 -0
- package/dist/es/web.js.map +1 -0
- package/dist/index-C8QxOkui.mjs +7940 -0
- package/dist/index-C8QxOkui.mjs.map +1 -0
- package/dist/index-DEPRHaUt.js +18 -0
- package/dist/index-DEPRHaUt.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/core/Interact.d.ts +17 -7
- package/dist/types/core/Interact.d.ts.map +1 -0
- package/dist/types/core/InteractionController.d.ts +19 -0
- package/dist/types/core/InteractionController.d.ts.map +1 -0
- package/dist/types/core/add.d.ts +4 -3
- package/dist/types/core/add.d.ts.map +1 -0
- package/dist/types/core/css.d.ts +3 -0
- package/dist/types/core/css.d.ts.map +1 -0
- package/dist/types/core/remove.d.ts +3 -1
- package/dist/types/core/remove.d.ts.map +1 -0
- package/dist/types/core/utilities.d.ts +1 -0
- package/dist/types/core/utilities.d.ts.map +1 -0
- package/dist/types/dom/api.d.ts +3 -0
- package/dist/types/dom/api.d.ts.map +1 -0
- package/dist/types/handlers/animationEnd.d.ts +3 -2
- package/dist/types/handlers/animationEnd.d.ts.map +1 -0
- package/dist/types/handlers/click.d.ts +3 -2
- package/dist/types/handlers/click.d.ts.map +1 -0
- package/dist/types/handlers/hover.d.ts +3 -2
- package/dist/types/handlers/hover.d.ts.map +1 -0
- package/dist/types/handlers/index.d.ts +1 -0
- package/dist/types/handlers/index.d.ts.map +1 -0
- package/dist/types/handlers/pointerMove.d.ts +3 -2
- package/dist/types/handlers/pointerMove.d.ts.map +1 -0
- package/dist/types/handlers/utilities.d.ts +1 -0
- package/dist/types/handlers/utilities.d.ts.map +1 -0
- package/dist/types/handlers/viewEnter.d.ts +3 -2
- package/dist/types/handlers/viewEnter.d.ts.map +1 -0
- package/dist/types/handlers/viewProgress.d.ts +4 -3
- package/dist/types/handlers/viewProgress.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/react/Interaction.d.ts +10 -0
- package/dist/types/react/Interaction.d.ts.map +1 -0
- package/dist/types/react/index.d.ts +8 -0
- package/dist/types/react/index.d.ts.map +1 -0
- package/dist/types/react/interactRef.d.ts +3 -0
- package/dist/types/react/interactRef.d.ts.map +1 -0
- package/dist/types/types.d.ts +25 -10
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +4 -2
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/{InteractElement.d.ts → web/InteractElement.d.ts} +115 -77
- package/dist/types/web/InteractElement.d.ts.map +1 -0
- package/dist/types/web/defineInteractElement.d.ts +2 -0
- package/dist/types/web/defineInteractElement.d.ts.map +1 -0
- package/dist/types/web/index.d.ts +6 -0
- package/dist/types/web/index.d.ts.map +1 -0
- package/docs/README.md +211 -0
- package/docs/advanced/README.md +164 -0
- package/docs/api/README.md +157 -0
- package/docs/api/element-selection.md +607 -0
- package/docs/api/functions.md +638 -0
- package/docs/api/interact-class.md +663 -0
- package/docs/api/interact-element.md +565 -0
- package/docs/api/interaction-controller.md +450 -0
- package/docs/api/types.md +957 -0
- package/docs/examples/README.md +212 -0
- package/docs/examples/click-interactions.md +977 -0
- package/docs/examples/entrance-animations.md +935 -0
- package/docs/examples/hover-effects.md +930 -0
- package/docs/examples/list-patterns.md +737 -0
- package/docs/guides/README.md +49 -0
- package/docs/guides/conditions-and-media-queries.md +1068 -0
- package/docs/guides/configuration-structure.md +726 -0
- package/docs/guides/custom-elements.md +327 -0
- package/docs/guides/effects-and-animations.md +634 -0
- package/docs/guides/getting-started.md +379 -0
- package/docs/guides/lists-and-dynamic-content.md +713 -0
- package/docs/guides/state-management.md +747 -0
- package/docs/guides/understanding-triggers.md +690 -0
- package/docs/integration/README.md +264 -0
- package/docs/integration/react.md +605 -0
- package/package.json +73 -56
- package/rules/Integration.md +255 -0
- package/rules/click-rules.md +533 -0
- package/rules/full-lean.md +346 -0
- package/rules/hover-rules.md +593 -0
- package/rules/pointermove-rules.md +1341 -0
- package/rules/scroll-list-rules.md +900 -0
- package/rules/viewenter-rules.md +1015 -0
- package/rules/viewprogress-rules.md +1044 -0
- package/dist/cjs/InteractElement.js +0 -162
- package/dist/cjs/InteractElement.js.map +0 -1
- package/dist/cjs/__tests__/interact.spec.js +0 -1930
- package/dist/cjs/__tests__/interact.spec.js.map +0 -1
- package/dist/cjs/__tests__/viewEnter.spec.js +0 -207
- package/dist/cjs/__tests__/viewEnter.spec.js.map +0 -1
- package/dist/cjs/core/Interact.js +0 -257
- package/dist/cjs/core/Interact.js.map +0 -1
- package/dist/cjs/core/add.js +0 -246
- package/dist/cjs/core/add.js.map +0 -1
- package/dist/cjs/core/remove.js +0 -35
- package/dist/cjs/core/remove.js.map +0 -1
- package/dist/cjs/core/utilities.js +0 -16
- package/dist/cjs/core/utilities.js.map +0 -1
- package/dist/cjs/external-types.d.js +0 -2
- package/dist/cjs/external-types.d.js.map +0 -1
- package/dist/cjs/handlers/animationEnd.js +0 -33
- package/dist/cjs/handlers/animationEnd.js.map +0 -1
- package/dist/cjs/handlers/click.js +0 -116
- package/dist/cjs/handlers/click.js.map +0 -1
- package/dist/cjs/handlers/hover.js +0 -141
- package/dist/cjs/handlers/hover.js.map +0 -1
- package/dist/cjs/handlers/index.js +0 -32
- package/dist/cjs/handlers/index.js.map +0 -1
- package/dist/cjs/handlers/pointerMove.js +0 -49
- package/dist/cjs/handlers/pointerMove.js.map +0 -1
- package/dist/cjs/handlers/utilities.js +0 -49
- package/dist/cjs/handlers/utilities.js.map +0 -1
- package/dist/cjs/handlers/viewEnter.js +0 -127
- package/dist/cjs/handlers/viewEnter.js.map +0 -1
- package/dist/cjs/handlers/viewProgress.js +0 -65
- package/dist/cjs/handlers/viewProgress.js.map +0 -1
- package/dist/cjs/test-types.d.js +0 -2
- package/dist/cjs/test-types.d.js.map +0 -1
- package/dist/cjs/types.js +0 -2
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/utils.js +0 -68
- package/dist/cjs/utils.js.map +0 -1
- package/dist/esm/InteractElement.js +0 -156
- package/dist/esm/InteractElement.js.map +0 -1
- package/dist/esm/__tests__/interact.spec.js +0 -1937
- package/dist/esm/__tests__/interact.spec.js.map +0 -1
- package/dist/esm/__tests__/viewEnter.spec.js +0 -210
- package/dist/esm/__tests__/viewEnter.spec.js.map +0 -1
- package/dist/esm/core/Interact.js +0 -251
- package/dist/esm/core/Interact.js.map +0 -1
- package/dist/esm/core/add.js +0 -241
- package/dist/esm/core/add.js.map +0 -1
- package/dist/esm/core/remove.js +0 -30
- package/dist/esm/core/remove.js.map +0 -1
- package/dist/esm/core/utilities.js +0 -14
- package/dist/esm/core/utilities.js.map +0 -1
- package/dist/esm/external-types.d.js +0 -2
- package/dist/esm/external-types.d.js.map +0 -1
- package/dist/esm/handlers/animationEnd.js +0 -29
- package/dist/esm/handlers/animationEnd.js.map +0 -1
- package/dist/esm/handlers/click.js +0 -116
- package/dist/esm/handlers/click.js.map +0 -1
- package/dist/esm/handlers/hover.js +0 -141
- package/dist/esm/handlers/hover.js.map +0 -1
- package/dist/esm/handlers/index.js +0 -27
- package/dist/esm/handlers/index.js.map +0 -1
- package/dist/esm/handlers/pointerMove.js +0 -48
- package/dist/esm/handlers/pointerMove.js.map +0 -1
- package/dist/esm/handlers/utilities.js +0 -43
- package/dist/esm/handlers/utilities.js.map +0 -1
- package/dist/esm/handlers/viewEnter.js +0 -129
- package/dist/esm/handlers/viewEnter.js.map +0 -1
- package/dist/esm/handlers/viewProgress.js +0 -61
- package/dist/esm/handlers/viewProgress.js.map +0 -1
- package/dist/esm/index.js +0 -5
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/test-types.d.js +0 -2
- package/dist/esm/test-types.d.js.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utils.js +0 -63
- package/dist/esm/utils.js.map +0 -1
- package/dist/types/__tests__/interact.spec.d.ts +0 -1
- package/dist/types/__tests__/viewEnter.spec.d.ts +0 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
### Basic usage (quick start)
|
|
2
|
+
|
|
3
|
+
- Import the runtime and create it with a config defining the interactions.
|
|
4
|
+
- Call `Interact.create(config)` once to initialize.
|
|
5
|
+
- Create the full configuration up‑front and pass it in a single `create` call to avoid unintended overrides; subsequent calls replace the previous config.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Interact } from '@wix/interact';
|
|
9
|
+
import type { InteractConfig } from '@wix/interact';
|
|
10
|
+
|
|
11
|
+
const config: InteractConfig = {
|
|
12
|
+
// config-props
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
Interact.create(config);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- Without Node/build tools: add a `<script type="module">` and import from the CDN.
|
|
19
|
+
|
|
20
|
+
```html
|
|
21
|
+
<script type="module">
|
|
22
|
+
import { Interact } from 'https://esm.sh/@wix/interact@1.86.0';
|
|
23
|
+
|
|
24
|
+
const config = {
|
|
25
|
+
// config-props
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
Interact.create(config);
|
|
29
|
+
</script>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Preventing FOUC for entrance animations
|
|
33
|
+
|
|
34
|
+
- Use `generate(config)` to create critical CSS that hides elements until their `viewEnter` entrance animation plays.
|
|
35
|
+
- Add `data-interact-initial="true"` to the `<interact-element>` that should have its first child hidden initially.
|
|
36
|
+
- Only use `data-interact-initial="true"` for `<interact-element>` with `viewEnter` trigger.
|
|
37
|
+
- Do NOT use for `hover` or `click` interactions.
|
|
38
|
+
|
|
39
|
+
**Usage:**
|
|
40
|
+
```javascript
|
|
41
|
+
import { generate } from '@wix/interact';
|
|
42
|
+
|
|
43
|
+
const config = {/*...*/};
|
|
44
|
+
|
|
45
|
+
// Generate CSS at build time or on server
|
|
46
|
+
const css = generate(config);
|
|
47
|
+
|
|
48
|
+
// Include in your HTML template
|
|
49
|
+
const html = `
|
|
50
|
+
<!DOCTYPE html>
|
|
51
|
+
<html>
|
|
52
|
+
<head>
|
|
53
|
+
<style>${css}</style>
|
|
54
|
+
</head>
|
|
55
|
+
<body>
|
|
56
|
+
<interact-element data-interact-key="hero" data-interact-initial="true">
|
|
57
|
+
<section class="hero">
|
|
58
|
+
<h1>Welcome to Our Site</h1>
|
|
59
|
+
<p>This content fades in smoothly without flash</p>
|
|
60
|
+
</section>
|
|
61
|
+
</interact-element>
|
|
62
|
+
<script type="module" src="./main.js"></script>
|
|
63
|
+
</body>
|
|
64
|
+
</html>
|
|
65
|
+
`;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### General guidelines (avoiding common pitfalls)
|
|
69
|
+
- Missing required fields or invalid references SHOULD be treated as no-ops for the offending interaction/effect while leaving the rest of the config functional.
|
|
70
|
+
- Params with incorrect types or shapes (especially for `namedEffect` preset options) can produce console errors. If you do not know the expected type/structure for a param, omit it and rely on defaults rather than guessing.
|
|
71
|
+
- Using `overflow: hidden` or `overflow: auto` can break viewProgress animations. Prefer `overflow: clip` for clipping semantics while preserving normal ViewTimeline.
|
|
72
|
+
- When animating with perspective, prefer `transform: perspective(...)` inside keyframes/presets. Reserve the static CSS `perspective` property for the specific case where multiple children of the same container must share the same viewpoint (`perspective-origin`).
|
|
73
|
+
- Stacking contexts and `viewProgress` (ViewTimeline): Creating a new stacking context on the target or any of its ancestors can prevent or freeze ViewTimeline sampling in some engines and setups. Avoid stacking‑context‑creating styles on the observed subtree (target and ancestors), including `transform`, `filter`, `perspective`, `opacity < 1`, `mix-blend-mode`, `isolation: isolate`, aggressive `will-change`, and `contain: paint/layout/size`. If needed for visuals, wrap the content and apply these styles to an inner child so the element that owns the timeline remains “flat”. Also avoid turning the scroll container into a stacking context; if you need clipping, prefer `overflow: clip` and avoid `transform` on the container. Typical symptoms are `viewProgress` not running, jumping 0→1, or never reaching anchors—remove or relocate the offending styles.
|
|
74
|
+
|
|
75
|
+
### InteractConfig – Rules for authoring interactions (AI-agent oriented)
|
|
76
|
+
|
|
77
|
+
This configuration declares what user/system triggers occur on which source element(s), and which visual effects should be applied to which target element(s). It is composed of three top-level sections: `effects`, `conditions`, and `interactions`.
|
|
78
|
+
|
|
79
|
+
### Global rules
|
|
80
|
+
- **Required/Optional**: You MUST provide an `interactions` array. You SHOULD provide an `effects` registry when you want to reference reusable effects by id. `conditions` are OPTIONAL.
|
|
81
|
+
- **Cross-references**: All cross-references (by id) MUST point to existing entries (e.g., an `EffectRef.effectId` MUST exist in `effects`).
|
|
82
|
+
- **Element keys**: All element keys (`key` fields) refer to the element path string (e.g., the value used in `data-interact-key`) and MUST be stable for the lifetime of the configuration.
|
|
83
|
+
- **List context**: Where both a list container and list item selector are provided, they MUST describe the same list context across an interaction and its effects. Mismatched list contexts will be ignored by the system.
|
|
84
|
+
- **Conditions**: Conditions act as guards. If any condition on an interaction or effect evaluates to false, the corresponding trigger/effect WILL NOT be applied.
|
|
85
|
+
- **Custom element usage**: Do NOT add observers/listeners manually. Wrap the DOM subtree with `<interact-element>` and set `data-interact-key` to the element key; use that same key in your config (`Interaction.key`/`Effect.key`). The runtime binds triggers/effects via this attribute.
|
|
86
|
+
|
|
87
|
+
### Structure
|
|
88
|
+
- **effects: Record<string, Effect>**
|
|
89
|
+
- **Purpose**: A registry of reusable, named effect definitions that can be referenced from interactions via `EffectRef`.
|
|
90
|
+
- **Key (string)**: The effect id. MUST be unique across the registry.
|
|
91
|
+
- **Value (Effect)**: A full effect definition. See Effect rules below.
|
|
92
|
+
|
|
93
|
+
- **conditions?: Record<string, Condition>**
|
|
94
|
+
- **Purpose**: Named predicates that gate interactions/effects by runtime context.
|
|
95
|
+
- **Key (string)**: The condition id. MUST be unique across the registry.
|
|
96
|
+
- **Value (Condition)**:
|
|
97
|
+
- **type**: `'media' | 'container'`
|
|
98
|
+
- `'media'`: The predicate MUST be a valid CSS media query expression without the outer `@media` keyword (e.g., `'(min-width: 768px)'`).
|
|
99
|
+
- `'container'`: The predicate SHOULD be a valid CSS container query condition string relative to the relevant container context.
|
|
100
|
+
- **predicate?**: OPTIONAL textual predicate for the given type. If omitted, the condition is treated as always-true (i.e., a no-op guard).
|
|
101
|
+
|
|
102
|
+
- **interactions: Interaction[]**
|
|
103
|
+
- **Purpose**: Declarative mapping from a source element and trigger to one or more target effects.
|
|
104
|
+
- Each `Interaction` contains:
|
|
105
|
+
- **key: string**
|
|
106
|
+
- REQUIRED. The source element path. The trigger attaches to this element.
|
|
107
|
+
- **listContainer?: string**
|
|
108
|
+
- OPTIONAL. A CSS selector for a list container context. When present, the trigger is scoped to items within this list.
|
|
109
|
+
- **listItemSelector?: string**
|
|
110
|
+
- OPTIONAL. A CSS selector used to select items within `listContainer`.
|
|
111
|
+
- **trigger: TriggerType**
|
|
112
|
+
- REQUIRED. One of:
|
|
113
|
+
- `'hover' | 'click'`: Pointer interactions.
|
|
114
|
+
- `'viewEnter' | 'pageVisible' | 'viewProgress'`: Viewport visibility/progress triggers.
|
|
115
|
+
- `'animationEnd'`: Fires when a specific effect completes on the source element.
|
|
116
|
+
- `'pointerMove'`: Continuous pointer motion over an area.
|
|
117
|
+
- **params?: TriggerParams**
|
|
118
|
+
- OPTIONAL. Parameter object that MUST match the trigger:
|
|
119
|
+
- hover/click: `StateParams | PointerTriggerParams`
|
|
120
|
+
- `StateParams.method`: `'add' | 'remove' | 'toggle' | 'clear'`
|
|
121
|
+
- `PointerTriggerParams.type?`: `'once' | 'repeat' | 'alternate' | 'state'`
|
|
122
|
+
- Usage:
|
|
123
|
+
- When the effect is a `TransitionEffect`, use `StateParams.method` to control the state toggle invoked on interaction:
|
|
124
|
+
- `'toggle'` (default): Hover — adds on enter and removes on leave. Click — toggles on each click.
|
|
125
|
+
- `'add'`: Apply the state on the event; hover leave will NOT auto‑remove.
|
|
126
|
+
- `'remove'`: Remove the state on the event.
|
|
127
|
+
- `'clear'`: Clear/reset the effect’s state for the element (or list item when list context is used).
|
|
128
|
+
- With lists (`listContainer`/`listItemSelector`), the state is set on the matching item only.
|
|
129
|
+
- When the effect is a time animation (`namedEffect`/`keyframeEffect`), use `PointerTriggerParams.type`:
|
|
130
|
+
- `'alternate'` (default): Hover — play on enter, reverse on leave. Click — alternate play/reverse on successive clicks.
|
|
131
|
+
- `'repeat'`: Restart from progress 0 on each event; on hover leave the animation is canceled.
|
|
132
|
+
- `'once'`: Play once and remove the listener (hover attaches only the enter listener; no leave).
|
|
133
|
+
- `'state'`: Hover — play on enter if idle/paused, pause on leave if running. Click — toggle play/pause on successive clicks until finished.
|
|
134
|
+
- viewEnter/pageVisible/viewProgress: `ViewEnterParams`
|
|
135
|
+
- `type?`: `'once' | 'repeat' | 'alternate'`
|
|
136
|
+
- `threshold?`: number in [0,1] describing intersection threshold
|
|
137
|
+
- `inset?`: string CSS-style inset for rootMargin/observer geometry
|
|
138
|
+
- Usage:
|
|
139
|
+
- `'once'`: Play on first visibility and unobserve the element.
|
|
140
|
+
- `'repeat'`: Play each time the element re‑enters visibility according to `threshold`/`inset`.
|
|
141
|
+
- `'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.
|
|
142
|
+
- `threshold`: Passed to `IntersectionObserver.threshold` — typical values are 0.1–0.6 for entrances.
|
|
143
|
+
- `inset`: Applied as vertical `rootMargin` (`top/bottom`), e.g., `'-100px'` to trigger earlier/later; left/right remain 0.
|
|
144
|
+
- 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`.
|
|
145
|
+
- animationEnd: `AnimationEndParams`
|
|
146
|
+
- `effectId`: string of the effect to wait for completion
|
|
147
|
+
- Usage: Fire when the specified effect (by `effectId`) on the source element finishes, useful for chaining sequences.
|
|
148
|
+
- pointerMove: `PointerMoveParams`
|
|
149
|
+
- `hitArea?`: `'root' | 'self'` (default `'self'`)
|
|
150
|
+
- Usage:
|
|
151
|
+
- `'self'`: Track pointer within the source element’s bounds.
|
|
152
|
+
- `'root'`: Track pointer anywhere in the viewport (document root).
|
|
153
|
+
- Only use with `ScrubEffect` mouse presets (`namedEffect`) or `customEffect` that consumes pointer progress; avoid `keyframeEffect` with `pointerMove`.
|
|
154
|
+
- When using `customEffect` with `pointerMove`, the progress parameter is an object:
|
|
155
|
+
- ```typescript
|
|
156
|
+
type Progress = {
|
|
157
|
+
x: number; // 0-1: horizontal position (0 = left edge, 1 = right edge)
|
|
158
|
+
y: number; // 0-1: vertical position (0 = top edge, 1 = bottom edge)
|
|
159
|
+
v?: { // Velocity (optional)
|
|
160
|
+
x: number; // Horizontal velocity
|
|
161
|
+
y: number; // Vertical velocity
|
|
162
|
+
};
|
|
163
|
+
active?: boolean; // Whether mouse is currently in the hit area
|
|
164
|
+
};
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
- **conditions?: string[]**
|
|
168
|
+
- OPTIONAL. Array of condition ids that MUST all pass for this trigger to be active.
|
|
169
|
+
- **selector?: string**
|
|
170
|
+
- OPTIONAL. Additional CSS selector to refine the source element's descendants when attaching/observing the trigger (e.g., delegate a click to a child button).
|
|
171
|
+
- **effects: Array<Effect | EffectRef>**
|
|
172
|
+
- REQUIRED. The effects to apply when the trigger fires. Ordering is significant: the first array entry is applied first. The system may reverse internal storage to preserve this application order.
|
|
173
|
+
|
|
174
|
+
### Working with `<interact-element>`
|
|
175
|
+
- Wrap the interactive DOM subtree with the custom element and set `data-interact-key` to a stable key. Reference that same key from your config via `Interaction.key` (and optionally `Effect.key`). No observers/listeners or manual DOM querying are needed—the runtime binds triggers and effects by this attribute.
|
|
176
|
+
- If an effect targets an element that is not the interaction’s source, you MUST also wrap that target element’s subtree with its own `<interact-element>` and set `data-interact-key` to the target’s key (the value used in `Effect.key` or the referenced registry Effect’s `key`). This is required so the runtime can locate and apply effects to non-source targets.
|
|
177
|
+
|
|
178
|
+
```html
|
|
179
|
+
<interact-element data-interact-key="my-button">
|
|
180
|
+
<button id="my-button">Click me</button>
|
|
181
|
+
</interact-element>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
import type { InteractConfig } from '@wix/interact';
|
|
186
|
+
|
|
187
|
+
const config: InteractConfig = {
|
|
188
|
+
interactions: [
|
|
189
|
+
{
|
|
190
|
+
key: 'my-button', // matches data-interact-key
|
|
191
|
+
trigger: 'hover',
|
|
192
|
+
effects: [
|
|
193
|
+
{
|
|
194
|
+
// key omitted -> targets the source element ('my-button')
|
|
195
|
+
// effect props go here (e.g., transition | keyframeEffect | namedEffect | customEffect)
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
For a different target element:
|
|
204
|
+
|
|
205
|
+
```html
|
|
206
|
+
<interact-element data-interact-key="my-button">
|
|
207
|
+
<button id="my-button">Click me</button>
|
|
208
|
+
</interact-element>
|
|
209
|
+
|
|
210
|
+
<interact-element data-interact-key="my-badge">
|
|
211
|
+
<span id="my-badge">Badge</span>
|
|
212
|
+
</interact-element>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
const config: InteractConfig = {
|
|
217
|
+
interactions: [
|
|
218
|
+
{
|
|
219
|
+
key: 'my-button',
|
|
220
|
+
trigger: 'click',
|
|
221
|
+
effects: [
|
|
222
|
+
{
|
|
223
|
+
key: 'my-badge', // target is different than source
|
|
224
|
+
// effect props (e.g., transition | keyframeEffect | namedEffect)
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
};
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Effect rules (applies to both registry-defined Effect and inline Effect within interactions)
|
|
233
|
+
- Common fields (`EffectBase`):
|
|
234
|
+
- **key?: string**
|
|
235
|
+
- OPTIONAL. Target element path. If omitted, resolution follows TARGET CASCADE:
|
|
236
|
+
1) `Effect.key` (if provided)
|
|
237
|
+
2) If Effect is an `EffectRef`: lookup registry by `effectId` and use that registry Effect’s `key`
|
|
238
|
+
3) Fallback to the `Interaction.key` (i.e., source acts as target)
|
|
239
|
+
- **listContainer?: string, listItemSelector?: string**
|
|
240
|
+
- OPTIONAL. If provided, MUST match the interaction's list context when both exist.
|
|
241
|
+
- **conditions?: string[]**
|
|
242
|
+
- OPTIONAL. All conditions MUST pass for the effect to run (in addition to interaction conditions).
|
|
243
|
+
- **selector?: string**
|
|
244
|
+
- OPTIONAL. Additional CSS selector to refine the target element's descendants.
|
|
245
|
+
- **effectId?: string**
|
|
246
|
+
- For `EffectRef` this field is REQUIRED and MUST reference an entry in `effects`.
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
- Composition and fill usage
|
|
250
|
+
- **composite** (similar to CSS `animation-composition` / WAAPI `composite`):
|
|
251
|
+
- Controls how this effect combines with other effects targeting the same element/property.
|
|
252
|
+
- `'replace'` (default): this effect fully replaces prior values for overlapping properties.
|
|
253
|
+
- `'add'`: this effect adds to the underlying value where the property supports additive composition (e.g., transforms, filters, opacity).
|
|
254
|
+
- `'accumulate'`: values build up across iterations/repeats where supported.
|
|
255
|
+
- Note: If a property is not additive, the runtime will treat `'add'`/`'accumulate'` like `'replace'`.
|
|
256
|
+
- **fill** (like CSS `animation-fill-mode`):
|
|
257
|
+
- `'none'`: styles are only applied while the effect is actively running/in-range.
|
|
258
|
+
- `'forwards'`: the effect’s end state is retained after completion (or last sampled value for scrub).
|
|
259
|
+
- `'backwards'`: the start state applies before the effect begins (or before `rangeStart` for scrub/during `delay` for time effects).
|
|
260
|
+
- `'both'`: combines `'backwards'` and `'forwards'`.
|
|
261
|
+
- For scroll-driven animations (`viewProgress`), prefer `fill: 'both'` to preserve start/end states around the active range and avoid flicker on rapid scroll.
|
|
262
|
+
|
|
263
|
+
- Types of `Effect` (exactly one MUST be provided via discriminated fields):
|
|
264
|
+
1) **TimeEffect** (discrete animation over time)
|
|
265
|
+
- `duration`: number (REQUIRED)
|
|
266
|
+
- `easing?`: string (CSS/WAAPI easing)
|
|
267
|
+
- `iterations?`: number (>=1 or Infinity)
|
|
268
|
+
- `alternate?`: boolean (direction alternation)
|
|
269
|
+
- `fill?`: `'none' | 'forwards' | 'backwards' | 'both'`
|
|
270
|
+
- `composite?`: `'replace' | 'add' | 'accumulate'`
|
|
271
|
+
- `reversed?`: boolean
|
|
272
|
+
- `delay?`: number (ms)
|
|
273
|
+
- One of:
|
|
274
|
+
- `keyframeEffect`: `{ name: string; keyframes: Keyframe[] }`
|
|
275
|
+
- `namedEffect`: `NamedEffect` (from `@wix/motion`)
|
|
276
|
+
- `customEffect`: `(element: Element, progress: any) => void`
|
|
277
|
+
|
|
278
|
+
2) **ScrubEffect** (animation driven by scroll/progress)
|
|
279
|
+
- `easing?`: string
|
|
280
|
+
- `iterations?`: number (NOT Infinity)
|
|
281
|
+
- `alternate?`: boolean
|
|
282
|
+
- `fill?`: `'none' | 'forwards' | 'backwards' | 'both'`
|
|
283
|
+
- `composite?`: `'replace' | 'add' | 'accumulate'`
|
|
284
|
+
- `reversed?`: boolean
|
|
285
|
+
- `rangeStart`: `RangeOffset`
|
|
286
|
+
- `rangeEnd`: `RangeOffset`
|
|
287
|
+
- `centeredToTarget?`: boolean // If `true` centers the coordinate range at the target element, otherwise uses source element
|
|
288
|
+
- `transitionDuration?`: number (ms for smoothing on progress jumps)
|
|
289
|
+
- `transitionDelay?`: number
|
|
290
|
+
- `transitionEasing?`: `ScrubTransitionEasing`
|
|
291
|
+
- One of `keyframeEffect | namedEffect | customEffect` (see above)
|
|
292
|
+
- For mouse-effects driven by the `pointerMove` trigger, do NOT use `keyframeEffect` (pointer progress is two‑dimensional and cannot be mapped to linear keyframes). Use `namedEffect` mouse presets instead, or `customEffect` for custom‑made animations.
|
|
293
|
+
- For scroll `namedEffect` presets (e.g., `*Scroll`) used with a `viewProgress` trigger, include `range: 'in' | 'out' | 'continuous'` in the `namedEffect` options; prefer `'continuous'` for simplicity.
|
|
294
|
+
- RangeOffset (used by `rangeStart`/`rangeEnd`):
|
|
295
|
+
- Type: `{ name: 'entry' | 'exit' | 'contain' | 'cover' | 'entry-crossing' | 'exit-crossing'; offset: LengthPercentage }`
|
|
296
|
+
- name?: Optional logical anchor derived from ViewTimeline concepts.
|
|
297
|
+
- 'entry': Leading edge of the target crosses into the view/container.
|
|
298
|
+
- 'exit': Trailing edge of the target crosses out of the view/container.
|
|
299
|
+
- 'contain': Interval where the target is fully within the view/container.
|
|
300
|
+
- 'cover': Interval where the view/container is fully covered by the target.
|
|
301
|
+
- 'entry-crossing': The moment the target's center crosses the entry boundary.
|
|
302
|
+
- 'exit-crossing': The moment the target's center crosses the exit boundary.
|
|
303
|
+
- If omitted, the runtime chooses a context-appropriate anchor; specify explicitly for deterministic behavior.
|
|
304
|
+
- offset: A `LengthPercentage` that shifts the anchor boundary.
|
|
305
|
+
- Explicit format: `{ value: number; type: 'percentage' | 'px' | 'em' | 'rem' | 'vh' | 'vw' | 'vmin' | 'vmax' }`
|
|
306
|
+
- Percentages are interpreted along the relevant scroll axis relative to the observation area (e.g., viewport or container size).
|
|
307
|
+
- Positive values move the anchor "forward" along the scroll direction; negative values move it "backward".
|
|
308
|
+
- Examples:
|
|
309
|
+
- Start when the element is 20% inside the viewport: `rangeStart: { name: 'entry', offset: { value: 20, type: 'percentage' } }`
|
|
310
|
+
- End when the element is leaving: `rangeEnd: { name: 'exit', offset: { value: 0, type: 'percentage' } }`
|
|
311
|
+
|
|
312
|
+
3) **TransitionEffect** (CSS transition-style state toggles)
|
|
313
|
+
- `key?`: string (target override; see TARGET CASCADE)
|
|
314
|
+
- `effectId?`: string (when used as a reference identity)
|
|
315
|
+
- One of:
|
|
316
|
+
- `transition?`: `{ duration?: number; delay?: number; easing?: string; styleProperties: { name: string; value: string }[] }`
|
|
317
|
+
- Applies a single transition options block to all listed style properties.
|
|
318
|
+
- `transitionProperties?`: `Array<{ name: string; value: string; duration?: number; delay?: number; easing?: string }>`
|
|
319
|
+
- Allows per-property transition options. If both `transition` and `transitionProperties` are provided, the system SHOULD apply both with per-property entries taking precedence for overlapping properties.
|
|
320
|
+
|
|
321
|
+
### Authoring rules for animation payloads (`namedEffect`, `keyframeEffect`, `customEffect`):
|
|
322
|
+
- **namedEffect (Preferred)**: Use first for best performance. These are pre-built presets from `@wix/motion` that are GPU-friendly and tuned.
|
|
323
|
+
- 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. */ }`
|
|
324
|
+
- Short list of common preset names:
|
|
325
|
+
- Entrance: `FadeIn`, `BounceIn`, `SlideIn`, `FlipIn`, `ArcIn`
|
|
326
|
+
- Ongoing: `Pulse`, `Spin`, `Wiggle`, `Bounce`
|
|
327
|
+
- Scroll: `ParallaxScroll`, `FadeScroll`, `RevealScroll`, `TiltScroll`
|
|
328
|
+
- For scroll-effects used with the `viewProgress` trigger, the `namedEffect` options MUST include `range: 'in' | 'out' | 'continuous'`. Prefer `range: 'continuous'` for simplicity.
|
|
329
|
+
- Mouse: For `pointerMove` (mouse-effects), prefer `namedEffect` presets (e.g., `TrackMouse`, `Tilt3DMouse`, `ScaleMouse`, `BlurMouse`); avoid `keyframeEffect` with `pointerMove` since progress is two‑dimensional.
|
|
330
|
+
- Mouse: `TrackMouse`, `Tilt3DMouse`, `ScaleMouse`, `BlurMouse`
|
|
331
|
+
- **keyframeEffect (Default for custom animations)**: Prefer this when you need a custom-made animation.
|
|
332
|
+
- Structure: `keyframeEffect: { name: string; keyframes: Keyframe[] }` (keyframes use standard CSS/WAAPI properties).
|
|
333
|
+
- Not compatible with `pointerMove` (mouse-effects) because pointer progress is two‑dimensional; use `customEffect` for custom pointer‑driven animations.
|
|
334
|
+
- **customEffect (Last resort)**: Use only when you must perform DOM manipulation or produce randomized/non-deterministic visuals that cannot be expressed as keyframes or presets.
|
|
335
|
+
- Structure: `customEffect: (element: Element, progress: any) => void`
|
|
336
|
+
|
|
337
|
+
### Target resolution and list context
|
|
338
|
+
- When applying an effect, the system resolves the final target as:
|
|
339
|
+
`Effect.key -> registry Effect.key (for EffectRef) -> Interaction.key`.
|
|
340
|
+
- If a `listContainer` is present on the interaction, the selector resolution may be widened to include list items (optionally filtered by `listItemSelector`), and then further refined by any provided `selector`.
|
|
341
|
+
|
|
342
|
+
### Reduced motion
|
|
343
|
+
- The runtime MAY force reduced motion globally. Authors SHOULD keep effects resilient to reduced motion by avoiding reliance on specific durations or continuous motion.
|
|
344
|
+
- Use `conditions` to provide responsive and accessible behavior:
|
|
345
|
+
- Define media conditions such as `'(prefers-reduced-motion: reduce)'` and breakpoint queries, and attach them to interactions/effects to disable, simplify, or swap animations when appropriate.
|
|
346
|
+
- Provide alternative reduced‑motion variants (e.g., shorter durations, fewer transforms, no perpetual motion/parallax/3D), and select them via `conditions` or effect references so that users who prefer reduced motion get a gentler experience.
|