@wix/interact 2.0.3 → 2.0.4

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 (38) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/react.js +1 -1
  3. package/dist/cjs/web.js +1 -1
  4. package/dist/es/index.js +1 -1
  5. package/dist/es/react.js +2 -2
  6. package/dist/es/web.js +2 -2
  7. package/dist/index-BZL18ynN.mjs +2750 -0
  8. package/dist/index-BZL18ynN.mjs.map +1 -0
  9. package/dist/index-IaOsZpFD.js +18 -0
  10. package/dist/index-IaOsZpFD.js.map +1 -0
  11. package/dist/tsconfig.build.tsbuildinfo +1 -1
  12. package/dist/types/core/Interact.d.ts +9 -1
  13. package/dist/types/core/Interact.d.ts.map +1 -1
  14. package/dist/types/core/add.d.ts.map +1 -1
  15. package/dist/types/handlers/animationEnd.d.ts +1 -1
  16. package/dist/types/handlers/animationEnd.d.ts.map +1 -1
  17. package/dist/types/handlers/effectHandlers.d.ts +2 -1
  18. package/dist/types/handlers/effectHandlers.d.ts.map +1 -1
  19. package/dist/types/handlers/eventTrigger.d.ts +1 -1
  20. package/dist/types/handlers/eventTrigger.d.ts.map +1 -1
  21. package/dist/types/handlers/viewEnter.d.ts +1 -1
  22. package/dist/types/handlers/viewEnter.d.ts.map +1 -1
  23. package/dist/types/types.d.ts +29 -2
  24. package/dist/types/types.d.ts.map +1 -1
  25. package/package.json +2 -2
  26. package/rules/MASTER-CLEANUP-PLAN.md +286 -0
  27. package/rules/click.md +12 -31
  28. package/rules/full-lean.md +26 -4
  29. package/rules/hover.md +68 -153
  30. package/rules/integration.md +17 -85
  31. package/rules/pointermove.md +32 -57
  32. package/rules/scroll-list.md +82 -280
  33. package/rules/viewenter.md +65 -90
  34. package/rules/viewprogress.md +139 -845
  35. package/dist/index-BfcN_rkn.mjs +0 -2338
  36. package/dist/index-BfcN_rkn.mjs.map +0 -1
  37. package/dist/index-HXLBEIjG.js +0 -18
  38. package/dist/index-HXLBEIjG.js.map +0 -1
@@ -499,21 +499,27 @@ Same as Rule 2
499
499
 
500
500
  ```typescript
501
501
  {
502
- key: 'responsive-element',
503
- trigger: 'viewEnter',
504
- params: {
505
- type: 'once',
506
- threshold: 0.3, // Good for mobile
507
- inset: '-100px' // Extra space for desktop
502
+ conditions: {
503
+ // Condition IDs are user-defined strings matched against these media predicates
504
+ 'desktop-only': { type: 'media', predicate: '(min-width: 768px)' },
508
505
  },
509
- conditions: ['desktop-only'],
510
- effects: [
506
+ interactions: [
511
507
  {
512
508
  key: 'responsive-element',
513
- namedEffect: {
514
- type: 'FadeIn'
509
+ trigger: 'viewEnter',
510
+ params: {
511
+ type: 'once',
512
+ threshold: 0.3,
513
+ inset: '-100px'
515
514
  },
516
- duration: 800
515
+ conditions: ['desktop-only'],
516
+ effects: [
517
+ {
518
+ key: 'responsive-element',
519
+ namedEffect: { type: 'FadeIn' },
520
+ duration: 800
521
+ }
522
+ ]
517
523
  }
518
524
  ]
519
525
  }
@@ -836,43 +842,42 @@ Animating multiple targets from single viewport trigger:
836
842
 
837
843
  ### Conditional ViewEnter Animations
838
844
 
839
- Combining with conditions for responsive behavior:
845
+ Use the `conditions` config map to guard interactions by device or motion preference. Condition IDs are user-defined strings — they must be declared in the top-level `conditions` map before being referenced in an interaction.
840
846
 
841
847
  ```typescript
842
848
  {
843
- key: 'responsive-section',
844
- trigger: 'viewEnter',
845
- params: {
846
- type: 'once',
847
- threshold: 0.5
849
+ conditions: {
850
+ 'desktop-only': { type: 'media', predicate: '(min-width: 768px)' },
851
+ 'prefers-motion': { type: 'media', predicate: '(prefers-reduced-motion: no-preference)' },
852
+ 'mobile-only': { type: 'media', predicate: '(max-width: 767px)' },
848
853
  },
849
- conditions: ['desktop-only', 'prefers-motion'],
850
- effects: [
854
+ interactions: [
851
855
  {
852
856
  key: 'responsive-section',
853
- namedEffect: {
854
- type: 'ComplexEntrance'
855
- },
856
- duration: 1000
857
- }
858
- ]
859
- },
860
- // Simplified version for mobile/reduced motion
861
- {
862
- key: 'responsive-section',
863
- trigger: 'viewEnter',
864
- params: {
865
- type: 'once',
866
- threshold: 0.7
867
- },
868
- conditions: ['mobile-only'],
869
- effects: [
857
+ trigger: 'viewEnter',
858
+ params: { type: 'once', threshold: 0.5 },
859
+ conditions: ['desktop-only', 'prefers-motion'],
860
+ effects: [
861
+ {
862
+ key: 'responsive-section',
863
+ namedEffect: { type: 'SlideIn' },
864
+ duration: 1000
865
+ }
866
+ ]
867
+ },
868
+ // Simplified fallback for mobile or reduced-motion users
870
869
  {
871
870
  key: 'responsive-section',
872
- namedEffect: {
873
- type: 'FadeIn'
874
- },
875
- duration: 400
871
+ trigger: 'viewEnter',
872
+ params: { type: 'once', threshold: 0.7 },
873
+ conditions: ['mobile-only'],
874
+ effects: [
875
+ {
876
+ key: 'responsive-section',
877
+ namedEffect: { type: 'FadeIn' },
878
+ duration: 400
879
+ }
880
+ ]
876
881
  }
877
882
  ]
878
883
  }
@@ -882,11 +887,14 @@ Combining with conditions for responsive behavior:
882
887
 
883
888
  ## Preventing Flash of Unstyled Content (FOUC)
884
889
 
885
- When using `viewEnter` for entrance animations, elements may briefly appear in their final state before the animation plays. Use the `generate` function to create critical CSS that prevents this.
890
+ Use `generate(config)` from `@wix/interact/web` server-side or at build time to produce critical CSS that hides entrance elements until their animation plays.
886
891
 
887
- ### Using the `generate` Function
892
+ **Constraints:**
888
893
 
889
- **Import and generate CSS:**
894
+ - MUST be called server-side or at build time — not client-side
895
+ - MUST set `data-interact-initial="true"` on the `<interact-element>` whose first child should be hidden
896
+ - Only valid for `viewEnter` + `params.type: 'once'` where source and target are the same element
897
+ - Do NOT use for `hover`, `click`, or `viewEnter` with `repeat`/`alternate`/`state` types
890
898
 
891
899
  ```typescript
892
900
  import { generate } from '@wix/interact/web';
@@ -894,56 +902,35 @@ import { generate } from '@wix/interact/web';
894
902
  const config: InteractConfig = {
895
903
  interactions: [
896
904
  {
897
- key: 'hero-section',
905
+ key: 'hero',
898
906
  trigger: 'viewEnter',
899
- params: { type: 'once', threshold: 0.3 },
900
- effects: [
901
- {
902
- namedEffect: { type: 'FadeIn' },
903
- duration: 800,
904
- fill: 'backwards',
905
- },
906
- ],
907
+ params: { type: 'once', threshold: 0.2 },
908
+ effects: [{ namedEffect: { type: 'FadeIn' }, duration: 800 }],
907
909
  },
908
910
  ],
909
911
  };
910
912
 
911
- // Generate CSS at build time or on server
913
+ // Called at build time or on the server
912
914
  const css = generate(config);
913
915
 
914
- // Include in your HTML template
916
+ // Inject into <head> before the page renders
915
917
  const html = `
916
- <!DOCTYPE html>
917
- <html>
918
918
  <head>
919
- <style>${css}</style>
919
+ <style>${css}</style>
920
920
  </head>
921
921
  <body>
922
- <interact-element data-interact-key="hero" data-interact-initial="true">
923
- <section class="hero">
924
- <h1>Welcome to Our Site</h1>
925
- <p>This content fades in smoothly without flash</p>
926
- </section>
927
- </interact-element>
928
- <script type="module" src="./main.js"></script>
922
+ <interact-element data-interact-key="hero" data-interact-initial="true">
923
+ <section class="hero">...</section>
924
+ </interact-element>
929
925
  </body>
930
- </html>
931
926
  `;
932
927
  ```
933
928
 
934
- ### Generated CSS Behavior
935
-
936
- The `generate` function produces CSS that:
937
-
938
- 1. **Hides marked elements** until their entrance animation completes
939
- 2. **Resets transforms** to allow `IntersectionObserver` to trigger entrance using the element's original layout and position
940
- 3. **Respects reduced motion preferences** - users with `prefers-reduced-motion: reduce` see elements immediately
941
-
942
929
  ---
943
930
 
944
931
  ## Best Practices for ViewEnter Interactions
945
932
 
946
- ### Behavior Guildelines
933
+ ### Behavior Guidelines
947
934
 
948
935
  1. **Use `alternate` and `repeat` types only with a separate source `key` and target `key`** to avoid re-triggering when animation starts or not triggering at all if animated target is out of viewport or clipped
949
936
 
@@ -953,23 +940,15 @@ The `generate` function produces CSS that:
953
940
  2. **Be careful with separate source/target patterns** - ensure source doesn't get clipped
954
941
  3. **Use appropriate thresholds** - avoid triggering too early or too late
955
942
 
956
- ### User Experience Guidelines
943
+ ### Threshold and Timing Guidelines
957
944
 
958
945
  1. **Use realistic thresholds** (0.1-0.5) for natural timing
959
- 2. **Use tiny thresholds for huge elements** 0.01-0.05 for elements much larger than viewport
946
+ 2. **Use tiny thresholds for huge elements** (0.01-0.05) for elements much larger than viewport
960
947
  3. **Provide adequate inset margins** for mobile viewports
961
948
  4. **Keep entrance animations moderate** (500-1200ms)
962
949
  5. **Use staggered delays thoughtfully** (50-200ms intervals)
963
- 6. **Ensure content is readable** during animations
964
950
 
965
- ### Accessibility Considerations
966
-
967
- 1. **Respect `prefers-reduced-motion`** for all entrance animations
968
- 2. **Don't rely solely on animations** to convey important information
969
- 3. **Ensure sufficient contrast** during fade-in effects
970
- 4. **Provide alternative content loading** for users who disable animations
971
-
972
- ### Threshold and Timing Guidelines
951
+ ### Threshold and Timing Reference
973
952
 
974
953
  **Recommended Thresholds by Content Type**:
975
954
 
@@ -977,7 +956,7 @@ The `generate` function produces CSS that:
977
956
  - **Content blocks**: 0.3-0.5 (balanced trigger)
978
957
  - **Small elements**: 0.5-0.8 (late trigger)
979
958
  - **Tall sections**: 0.1-0.2 (early trigger)
980
- - **HUge sections**: 0.01-0.05 (ensure trigger)
959
+ - **Huge sections**: 0.01-0.05 (ensure trigger)
981
960
 
982
961
  **Recommended Insets by Device**:
983
962
 
@@ -1048,7 +1027,3 @@ The `generate` function produces CSS that:
1048
1027
  - Use hardware-accelerated properties
1049
1028
  - Avoid animating layout properties
1050
1029
  - Consider using `will-change` for complex animations
1051
-
1052
- ---
1053
-
1054
- These rules provide comprehensive coverage for ViewEnter trigger interactions in `@wix/interact`, supporting all four behavior types and various intersection observer configurations as outlined in the development plan.