@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.
Files changed (179) hide show
  1. package/dist/cjs/index.js +2 -23
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/react.js +15 -0
  4. package/dist/cjs/react.js.map +1 -0
  5. package/dist/cjs/web.js +2 -0
  6. package/dist/cjs/web.js.map +1 -0
  7. package/dist/es/index.js +8 -0
  8. package/dist/es/index.js.map +1 -0
  9. package/dist/es/react.js +650 -0
  10. package/dist/es/react.js.map +1 -0
  11. package/dist/es/web.js +56 -0
  12. package/dist/es/web.js.map +1 -0
  13. package/dist/index-C8QxOkui.mjs +7940 -0
  14. package/dist/index-C8QxOkui.mjs.map +1 -0
  15. package/dist/index-DEPRHaUt.js +18 -0
  16. package/dist/index-DEPRHaUt.js.map +1 -0
  17. package/dist/tsconfig.build.tsbuildinfo +1 -0
  18. package/dist/types/core/Interact.d.ts +17 -7
  19. package/dist/types/core/Interact.d.ts.map +1 -0
  20. package/dist/types/core/InteractionController.d.ts +19 -0
  21. package/dist/types/core/InteractionController.d.ts.map +1 -0
  22. package/dist/types/core/add.d.ts +4 -3
  23. package/dist/types/core/add.d.ts.map +1 -0
  24. package/dist/types/core/css.d.ts +3 -0
  25. package/dist/types/core/css.d.ts.map +1 -0
  26. package/dist/types/core/remove.d.ts +3 -1
  27. package/dist/types/core/remove.d.ts.map +1 -0
  28. package/dist/types/core/utilities.d.ts +1 -0
  29. package/dist/types/core/utilities.d.ts.map +1 -0
  30. package/dist/types/dom/api.d.ts +3 -0
  31. package/dist/types/dom/api.d.ts.map +1 -0
  32. package/dist/types/handlers/animationEnd.d.ts +3 -2
  33. package/dist/types/handlers/animationEnd.d.ts.map +1 -0
  34. package/dist/types/handlers/click.d.ts +3 -2
  35. package/dist/types/handlers/click.d.ts.map +1 -0
  36. package/dist/types/handlers/hover.d.ts +3 -2
  37. package/dist/types/handlers/hover.d.ts.map +1 -0
  38. package/dist/types/handlers/index.d.ts +1 -0
  39. package/dist/types/handlers/index.d.ts.map +1 -0
  40. package/dist/types/handlers/pointerMove.d.ts +3 -2
  41. package/dist/types/handlers/pointerMove.d.ts.map +1 -0
  42. package/dist/types/handlers/utilities.d.ts +1 -0
  43. package/dist/types/handlers/utilities.d.ts.map +1 -0
  44. package/dist/types/handlers/viewEnter.d.ts +3 -2
  45. package/dist/types/handlers/viewEnter.d.ts.map +1 -0
  46. package/dist/types/handlers/viewProgress.d.ts +4 -3
  47. package/dist/types/handlers/viewProgress.d.ts.map +1 -0
  48. package/dist/types/index.d.ts +3 -2
  49. package/dist/types/index.d.ts.map +1 -0
  50. package/dist/types/react/Interaction.d.ts +10 -0
  51. package/dist/types/react/Interaction.d.ts.map +1 -0
  52. package/dist/types/react/index.d.ts +8 -0
  53. package/dist/types/react/index.d.ts.map +1 -0
  54. package/dist/types/react/interactRef.d.ts +3 -0
  55. package/dist/types/react/interactRef.d.ts.map +1 -0
  56. package/dist/types/types.d.ts +25 -10
  57. package/dist/types/types.d.ts.map +1 -0
  58. package/dist/types/utils.d.ts +4 -2
  59. package/dist/types/utils.d.ts.map +1 -0
  60. package/dist/types/{InteractElement.d.ts → web/InteractElement.d.ts} +115 -77
  61. package/dist/types/web/InteractElement.d.ts.map +1 -0
  62. package/dist/types/web/defineInteractElement.d.ts +2 -0
  63. package/dist/types/web/defineInteractElement.d.ts.map +1 -0
  64. package/dist/types/web/index.d.ts +6 -0
  65. package/dist/types/web/index.d.ts.map +1 -0
  66. package/docs/README.md +211 -0
  67. package/docs/advanced/README.md +164 -0
  68. package/docs/api/README.md +157 -0
  69. package/docs/api/element-selection.md +607 -0
  70. package/docs/api/functions.md +638 -0
  71. package/docs/api/interact-class.md +663 -0
  72. package/docs/api/interact-element.md +565 -0
  73. package/docs/api/interaction-controller.md +450 -0
  74. package/docs/api/types.md +957 -0
  75. package/docs/examples/README.md +212 -0
  76. package/docs/examples/click-interactions.md +977 -0
  77. package/docs/examples/entrance-animations.md +935 -0
  78. package/docs/examples/hover-effects.md +930 -0
  79. package/docs/examples/list-patterns.md +737 -0
  80. package/docs/guides/README.md +49 -0
  81. package/docs/guides/conditions-and-media-queries.md +1068 -0
  82. package/docs/guides/configuration-structure.md +726 -0
  83. package/docs/guides/custom-elements.md +327 -0
  84. package/docs/guides/effects-and-animations.md +634 -0
  85. package/docs/guides/getting-started.md +379 -0
  86. package/docs/guides/lists-and-dynamic-content.md +713 -0
  87. package/docs/guides/state-management.md +747 -0
  88. package/docs/guides/understanding-triggers.md +690 -0
  89. package/docs/integration/README.md +264 -0
  90. package/docs/integration/react.md +605 -0
  91. package/package.json +73 -56
  92. package/rules/Integration.md +255 -0
  93. package/rules/click-rules.md +533 -0
  94. package/rules/full-lean.md +346 -0
  95. package/rules/hover-rules.md +593 -0
  96. package/rules/pointermove-rules.md +1341 -0
  97. package/rules/scroll-list-rules.md +900 -0
  98. package/rules/viewenter-rules.md +1015 -0
  99. package/rules/viewprogress-rules.md +1044 -0
  100. package/dist/cjs/InteractElement.js +0 -162
  101. package/dist/cjs/InteractElement.js.map +0 -1
  102. package/dist/cjs/__tests__/interact.spec.js +0 -1930
  103. package/dist/cjs/__tests__/interact.spec.js.map +0 -1
  104. package/dist/cjs/__tests__/viewEnter.spec.js +0 -207
  105. package/dist/cjs/__tests__/viewEnter.spec.js.map +0 -1
  106. package/dist/cjs/core/Interact.js +0 -257
  107. package/dist/cjs/core/Interact.js.map +0 -1
  108. package/dist/cjs/core/add.js +0 -246
  109. package/dist/cjs/core/add.js.map +0 -1
  110. package/dist/cjs/core/remove.js +0 -35
  111. package/dist/cjs/core/remove.js.map +0 -1
  112. package/dist/cjs/core/utilities.js +0 -16
  113. package/dist/cjs/core/utilities.js.map +0 -1
  114. package/dist/cjs/external-types.d.js +0 -2
  115. package/dist/cjs/external-types.d.js.map +0 -1
  116. package/dist/cjs/handlers/animationEnd.js +0 -33
  117. package/dist/cjs/handlers/animationEnd.js.map +0 -1
  118. package/dist/cjs/handlers/click.js +0 -116
  119. package/dist/cjs/handlers/click.js.map +0 -1
  120. package/dist/cjs/handlers/hover.js +0 -141
  121. package/dist/cjs/handlers/hover.js.map +0 -1
  122. package/dist/cjs/handlers/index.js +0 -32
  123. package/dist/cjs/handlers/index.js.map +0 -1
  124. package/dist/cjs/handlers/pointerMove.js +0 -49
  125. package/dist/cjs/handlers/pointerMove.js.map +0 -1
  126. package/dist/cjs/handlers/utilities.js +0 -49
  127. package/dist/cjs/handlers/utilities.js.map +0 -1
  128. package/dist/cjs/handlers/viewEnter.js +0 -127
  129. package/dist/cjs/handlers/viewEnter.js.map +0 -1
  130. package/dist/cjs/handlers/viewProgress.js +0 -65
  131. package/dist/cjs/handlers/viewProgress.js.map +0 -1
  132. package/dist/cjs/test-types.d.js +0 -2
  133. package/dist/cjs/test-types.d.js.map +0 -1
  134. package/dist/cjs/types.js +0 -2
  135. package/dist/cjs/types.js.map +0 -1
  136. package/dist/cjs/utils.js +0 -68
  137. package/dist/cjs/utils.js.map +0 -1
  138. package/dist/esm/InteractElement.js +0 -156
  139. package/dist/esm/InteractElement.js.map +0 -1
  140. package/dist/esm/__tests__/interact.spec.js +0 -1937
  141. package/dist/esm/__tests__/interact.spec.js.map +0 -1
  142. package/dist/esm/__tests__/viewEnter.spec.js +0 -210
  143. package/dist/esm/__tests__/viewEnter.spec.js.map +0 -1
  144. package/dist/esm/core/Interact.js +0 -251
  145. package/dist/esm/core/Interact.js.map +0 -1
  146. package/dist/esm/core/add.js +0 -241
  147. package/dist/esm/core/add.js.map +0 -1
  148. package/dist/esm/core/remove.js +0 -30
  149. package/dist/esm/core/remove.js.map +0 -1
  150. package/dist/esm/core/utilities.js +0 -14
  151. package/dist/esm/core/utilities.js.map +0 -1
  152. package/dist/esm/external-types.d.js +0 -2
  153. package/dist/esm/external-types.d.js.map +0 -1
  154. package/dist/esm/handlers/animationEnd.js +0 -29
  155. package/dist/esm/handlers/animationEnd.js.map +0 -1
  156. package/dist/esm/handlers/click.js +0 -116
  157. package/dist/esm/handlers/click.js.map +0 -1
  158. package/dist/esm/handlers/hover.js +0 -141
  159. package/dist/esm/handlers/hover.js.map +0 -1
  160. package/dist/esm/handlers/index.js +0 -27
  161. package/dist/esm/handlers/index.js.map +0 -1
  162. package/dist/esm/handlers/pointerMove.js +0 -48
  163. package/dist/esm/handlers/pointerMove.js.map +0 -1
  164. package/dist/esm/handlers/utilities.js +0 -43
  165. package/dist/esm/handlers/utilities.js.map +0 -1
  166. package/dist/esm/handlers/viewEnter.js +0 -129
  167. package/dist/esm/handlers/viewEnter.js.map +0 -1
  168. package/dist/esm/handlers/viewProgress.js +0 -61
  169. package/dist/esm/handlers/viewProgress.js.map +0 -1
  170. package/dist/esm/index.js +0 -5
  171. package/dist/esm/index.js.map +0 -1
  172. package/dist/esm/test-types.d.js +0 -2
  173. package/dist/esm/test-types.d.js.map +0 -1
  174. package/dist/esm/types.js +0 -2
  175. package/dist/esm/types.js.map +0 -1
  176. package/dist/esm/utils.js +0 -63
  177. package/dist/esm/utils.js.map +0 -1
  178. package/dist/types/__tests__/interact.spec.d.ts +0 -1
  179. package/dist/types/__tests__/viewEnter.spec.d.ts +0 -0
@@ -0,0 +1,379 @@
1
+ # Getting Started
2
+
3
+ Welcome to `@wix/interact`! This guide will help you create your first interaction in under 4 minutes.
4
+
5
+ ## What is @wix/interact?
6
+
7
+ `@wix/interact` is a powerful library that lets you create interactive animations and effects triggered by user actions like clicking, hovering, or scrolling. It integrates seamlessly with `@wix/motion` to provide smooth, performant animations.
8
+
9
+ ## Core Concepts
10
+
11
+ Before we dive in, let's understand the three main concepts:
12
+
13
+ 1. **Triggers** - User actions that start an interaction (click, hover, scroll, etc.)
14
+ 2. **Effects** - The visual changes that happen (animations, transitions, style changes)
15
+ 3. **Elements** - The HTML elements that participate in the interaction
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @wix/interact
21
+ ```
22
+
23
+ ## Package Entry Points
24
+
25
+ `@wix/interact` provides three entry points for different use cases:
26
+
27
+ | Entry Point | Use Case | Key Exports |
28
+ |-------------|----------|-------------|
29
+ | `@wix/interact/react` | React applications | `Interaction`, `createInteractRef`, `Interact` |
30
+ | `@wix/interact/web` | Web Components | `Interact`, `defineInteractElement`, `add`, `remove` |
31
+ | `@wix/interact` | Vanilla JS | `Interact`, `add`, `remove` |
32
+
33
+ Choose the entry point that matches your framework:
34
+
35
+ ```typescript
36
+ // For React applications
37
+ import { Interact, Interaction } from '@wix/interact/react';
38
+
39
+ // For native Web Components
40
+ import { Interact } from '@wix/interact/web';
41
+
42
+ // For vaniall JavaScript
43
+ import { Interact, add, remove } from '@wix/interact';
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Your First Interaction (React)
49
+
50
+ If you're using React, here's the quickest way to get started using the `Interaction` component:
51
+
52
+ ### Step 1: Create the Configuration
53
+
54
+ ```tsx
55
+ import React, { useEffect } from 'react';
56
+ import { Interact, Interaction, InteractConfig } from '@wix/interact/react';
57
+
58
+ const config: InteractConfig = {
59
+ interactions: [
60
+ {
61
+ key: 'my-image', // What element triggers the interaction
62
+ trigger: 'hover', // What user action starts it
63
+ effects: [
64
+ {
65
+ keyframeEffect: {
66
+ name: 'scale',
67
+ keyframes: [
68
+ { scale: 2 }
69
+ ]
70
+ },
71
+ duration: 300, // Animation duration in milliseconds
72
+ easing: 'ease-out' // Animation timing
73
+ }
74
+ ]
75
+ }
76
+ ],
77
+ effects: {}
78
+ };
79
+ ```
80
+
81
+ ### Step 2: Create the Component
82
+
83
+ ```tsx
84
+ function App() {
85
+ useEffect(() => {
86
+ const instance = Interact.create(config);
87
+ return () => instance.destroy();
88
+ }, []);
89
+
90
+ return (
91
+ <Interaction tagName="div" interactKey="my-image" className="image-container">
92
+ <img src="logo.png" alt="Logo" />
93
+ </Interaction>
94
+ );
95
+ }
96
+
97
+ export default App;
98
+ ```
99
+
100
+ That's it! The image will now scale up when you hover over it.
101
+
102
+ ---
103
+
104
+ ## Your First Interaction (Vanilla JavaScript)
105
+
106
+ For vanilla JavaScript or non-React frameworks, use the `interact-element` custom element:
107
+
108
+ ### Step 1: Basic HTML Structure
109
+
110
+ ```html
111
+ <!DOCTYPE html>
112
+ <html>
113
+ <head>
114
+ <title>My First Interaction</title>
115
+ </head>
116
+ <body>
117
+ <interact-element data-interact-key="my-image">
118
+ <img id="my-image" src="logo.png" alt="Logo" />
119
+ </interact-element>
120
+
121
+ <script type="module" src="./main.js"></script>
122
+ </body>
123
+ </html>
124
+ ```
125
+
126
+ **Key points:**
127
+ - Wrap your element in `<interact-element>`
128
+ - Use `data-interact-key` to identify the element (must be unique)
129
+ - The key in your interaction config should be a unique string that matches the value of `data-interact-key` for that element
130
+
131
+ ### Step 2: Configure the Interaction
132
+
133
+ ```javascript
134
+ // main.js
135
+ import { Interact } from '@wix/interact/web';
136
+
137
+ // Create the interaction configuration
138
+ const config = {
139
+ interactions: [
140
+ {
141
+ key: 'my-image', // What element triggers the interaction
142
+ trigger: 'hover', // What user action starts it
143
+ effects: [
144
+ {
145
+ keyframeEffect: {
146
+ name: 'scale',
147
+ keyframes: [
148
+ { scale: 2 }
149
+ ]
150
+ },
151
+ duration: 300, // Animation duration in milliseconds
152
+ easing: 'ease-out' // Animation timing
153
+ }
154
+ ]
155
+ }
156
+ ],
157
+ effects: {}
158
+ };
159
+
160
+ // Initialize the interaction
161
+ Interact.create(config);
162
+ ```
163
+
164
+ ---
165
+
166
+ ## Understanding the Configuration
167
+
168
+ Let's break down what each part does:
169
+
170
+ ### The `interactions` Array
171
+ This contains all your interactions. Each interaction defines:
172
+ - **key**: Which element triggers the interaction
173
+ - **trigger**: What user action starts it
174
+ - **effects**: What animations happen
175
+
176
+ ### The `effects` Object
177
+ Define reusable effects that can be referenced by `effectId`:
178
+
179
+ ```typescript
180
+ const config = {
181
+ effects: {
182
+ 'fade-in': {
183
+ duration: 1000,
184
+ keyframeEffect: {
185
+ name: 'fade-in',
186
+ keyframes: [
187
+ { opacity: 0 },
188
+ { opacity: 1 }
189
+ ]
190
+ }
191
+ }
192
+ },
193
+ interactions: [
194
+ {
195
+ key: 'hero',
196
+ trigger: 'viewEnter',
197
+ effects: [{ effectId: 'fade-in' }] // Reference the effect
198
+ }
199
+ ]
200
+ };
201
+ ```
202
+
203
+ ### Effect Properties
204
+ Each effect defines:
205
+ - **key**: Which element gets animated (if missing it defaults to source)
206
+ - **keyframeEffect**: An object containing a `keyframes` property that maps to an array of keyframe objects, and a `name` containing a unique name for that effect
207
+ - **duration**: How long the animation takes
208
+ - **easing**: The animation timing curve
209
+
210
+ ---
211
+
212
+ ## Common Patterns
213
+
214
+ ### Hover with Scale and Rotation
215
+ ```javascript
216
+ {
217
+ key: 'my-element',
218
+ trigger: 'hover',
219
+ effects: [
220
+ {
221
+ key: 'my-element',
222
+ keyframeEffect: {
223
+ name: 'twist',
224
+ keyframes: [
225
+ { transform: 'scale(1) rotate(0deg)' },
226
+ { transform: 'scale(1.1) rotate(5deg)' }
227
+ ]
228
+ },
229
+ duration: 200,
230
+ easing: 'ease-out'
231
+ }
232
+ ]
233
+ }
234
+ ```
235
+
236
+ ### Click to Toggle State
237
+ ```javascript
238
+ {
239
+ key: 'my-button',
240
+ trigger: 'click',
241
+ params: { method: 'toggle' },
242
+ effects: [
243
+ {
244
+ key: 'my-content',
245
+ effectId: 'expand',
246
+ }
247
+ ]
248
+ }
249
+ ```
250
+
251
+ ### Entrance Animation on Viewport Entry
252
+ ```javascript
253
+ {
254
+ key: 'my-element',
255
+ trigger: 'viewEnter',
256
+ effects: [
257
+ {
258
+ key: 'my-element',
259
+ namedEffect: 'FadeIn',
260
+ duration: 800,
261
+ easing: 'ease-out'
262
+ }
263
+ ]
264
+ }
265
+ ```
266
+
267
+ > **Tip**: To prevent a flash of content before entrance animations start, use the `generate()` function to create CSS that hides elements until their animation triggers. See [Entrance Animations](../examples/entrance-animations.md#preventing-flash-of-unstyled-content-fouc) for details.
268
+
269
+ ---
270
+
271
+ ## React vs Web Components
272
+
273
+ | Approach | When to Use |
274
+ |----------|-------------|
275
+ | **React (`Interaction` component)** | React applications, automatic cleanup |
276
+ | **Web Components (`interact-element`)** | Framework-agnostic projects, declerative creation and automatic DOM-changes handling |
277
+ | **Mini** | Framework-agnostic projects, if no need for dynamic DOM changes or integrating with other frameworks |
278
+
279
+ ### React Example (Recommended for React)
280
+
281
+ ```tsx
282
+ import { Interact, Interaction } from '@wix/interact/react';
283
+
284
+ function Card() {
285
+ useEffect(() => {
286
+ Interact.create(config);
287
+ return () => Interact.destroy();
288
+ }, []);
289
+
290
+ return (
291
+ <Interaction tagName="article" interactKey="card" className="card">
292
+ <h2>Card Title</h2>
293
+ <p>Card content here</p>
294
+ </Interaction>
295
+ );
296
+ }
297
+ ```
298
+
299
+ ### Web Component Example (Framework-agnostic)
300
+
301
+ ```html
302
+ <interact-element data-interact-key="card">
303
+ <article class="card">
304
+ <h2>Card Title</h2>
305
+ <p>Card content here</p>
306
+ </article>
307
+ </interact-element>
308
+ ```
309
+
310
+ ```typescript
311
+ import { Interact } from '@wix/interact/web';
312
+ Interact.create(config);
313
+ ```
314
+
315
+ ---
316
+
317
+ ## TypeScript Support
318
+
319
+ Both entry points provide full TypeScript support:
320
+
321
+ ```typescript
322
+ import { Interact, InteractConfig, Interaction } from '@wix/interact/react';
323
+
324
+ const config: InteractConfig = {
325
+ interactions: [
326
+ {
327
+ key: 'hero',
328
+ trigger: 'viewEnter', // TypeScript validates trigger types
329
+ effects: [
330
+ {
331
+ duration: 1000,
332
+ keyframeEffect: {
333
+ name: 'fade',
334
+ keyframes: [{ opacity: 0 }, { opacity: 1 }]
335
+ }
336
+ }
337
+ ]
338
+ }
339
+ ],
340
+ effects: {}
341
+ };
342
+
343
+ // Full type inference
344
+ const instance = Interact.create(config);
345
+ ```
346
+
347
+ ---
348
+
349
+ ## Cleanup
350
+
351
+ Always clean up interactions when components unmount or pages change:
352
+
353
+ ### React
354
+ ```tsx
355
+ useEffect(() => {
356
+ const instance = Interact.create(config);
357
+ return () => instance.destroy();
358
+ }, []);
359
+ ```
360
+
361
+ ### Vanilla JavaScript
362
+ ```javascript
363
+ // On page unload or SPA navigation
364
+ window.addEventListener('beforeunload', () => {
365
+ Interact.destroy();
366
+ });
367
+ ```
368
+
369
+ ---
370
+
371
+ ## Next Steps
372
+
373
+ Congratulations! You've created your first interaction. Here's what to explore next:
374
+
375
+ 1. **[Understanding Triggers](./understanding-triggers.md)** - Learn about all 7 trigger types
376
+ 2. **[Effects and Animations](./effects-and-animations.md)** - Discover more animation options
377
+ 3. **[Custom Elements](./custom-elements.md)** - Understand how `<interact-element>` works
378
+ 4. **[React Integration](../integration/react.md)** - Deep dive into React components and hooks
379
+ 5. **[Configuration Structure](./configuration-structure.md)** - Organize complex interactions