@wix/interact 2.5.1 → 2.5.3
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 +27 -0
- package/docs/api/interact-class.md +1 -1
- package/docs/guides/custom-elements.md +10 -10
- package/docs/integration/react.md +17 -13
- package/package.json +1 -1
- package/rules/click.md +8 -0
- package/rules/full-lean.md +76 -16
- package/rules/hover.md +8 -0
- package/rules/integration.md +63 -15
- package/rules/validate.md +58 -18
- package/rules/viewenter.md +41 -9
- package/rules/viewprogress.md +43 -6
package/README.md
CHANGED
|
@@ -19,6 +19,33 @@ Declarative, configuration-driven interaction library — web-native, AI-ready,
|
|
|
19
19
|
- **Preset ecosystem** — Plug in [`@wix/motion-presets`](https://github.com/wix/interact/tree/master/packages/motion-presets) for 75+ ready-made effects.
|
|
20
20
|
- **Accessible** — Built-in `activate` (click + keyboard) and `interest` (hover + focus) trigger variants
|
|
21
21
|
|
|
22
|
+
## Coding-agent skill: Interactor
|
|
23
|
+
|
|
24
|
+
Working with an AI coding agent (Claude Code, Cursor, and others)? Install the **Interactor** skill so your agent can install, wire up, and configure `@wix/interact` for you — creating beautiful interactions and validating them before shipping.
|
|
25
|
+
|
|
26
|
+
### Install
|
|
27
|
+
|
|
28
|
+
Install it via the [`skills`](https://www.npmjs.com/package/skills) CLI (runs through `npx`, nothing to install globally):
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx skills add wix/interact # add to the current project
|
|
32
|
+
npx skills add wix/interact --global # or install for every project
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Run interactively, the CLI prompts for the agent and scope; pass `-a cursor` (also `claude-code`, `opencode`, or `-a '*'` for all) to pick up-front.
|
|
36
|
+
|
|
37
|
+
### Use it
|
|
38
|
+
|
|
39
|
+
In **Cursor** or **Claude Code**, invoke the skill from chat with `/interactor` and describe what you want:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
/interactor fade the hero in when it scrolls into view
|
|
43
|
+
/interactor stagger these cards in on entrance
|
|
44
|
+
/interactor add a subtle 3D tilt toward the cursor on the product cards
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The agent follows the skill workflow: detects your stack (React, Web Components, or vanilla JS), installs packages if needed, generates an `InteractConfig`, validates it with `@wix/interact-validate`, and injects `generate()` CSS.
|
|
48
|
+
|
|
22
49
|
## Install
|
|
23
50
|
|
|
24
51
|
```bash
|
|
@@ -103,9 +103,9 @@ interact-element.--hover-active .my-element {
|
|
|
103
103
|
}
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
### State Toggle
|
|
106
|
+
### State Toggle Actions
|
|
107
107
|
|
|
108
|
-
The element provides
|
|
108
|
+
The element provides actions to manage states:
|
|
109
109
|
|
|
110
110
|
1. `add`: adds a state named by `effectId`
|
|
111
111
|
2. `remove`: removes a state named by `effectId`
|
|
@@ -164,16 +164,16 @@ export default {
|
|
|
164
164
|
```javascript
|
|
165
165
|
// Create element programmatically
|
|
166
166
|
function createInteractiveElement(id, content) {
|
|
167
|
-
const
|
|
168
|
-
|
|
167
|
+
const interactElement = document.createElement('interact-element');
|
|
168
|
+
interactElement.dataset.interactKey = id;
|
|
169
169
|
|
|
170
170
|
const childElement = document.createElement('div');
|
|
171
171
|
childElement.id = id;
|
|
172
172
|
childElement.innerHTML = content;
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
interactElement.appendChild(childElement);
|
|
175
175
|
|
|
176
|
-
return
|
|
176
|
+
return interactElement;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
// Usage
|
|
@@ -218,12 +218,12 @@ You can change the key dynamically:
|
|
|
218
218
|
const element = document.querySelector('interact-element');
|
|
219
219
|
|
|
220
220
|
// Remove old interactions
|
|
221
|
-
if (element.dataset.
|
|
222
|
-
remove(element.dataset.
|
|
221
|
+
if (element.dataset.interactKey) {
|
|
222
|
+
remove(element.dataset.interactKey);
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
// Update key
|
|
226
|
-
element.dataset.
|
|
226
|
+
element.dataset.interactKey = 'new-target';
|
|
227
227
|
|
|
228
228
|
// Reconnect with new key
|
|
229
229
|
element.connect('new-target');
|
|
@@ -303,7 +303,7 @@ console.log('interact-element registered:', customElements.get('interact-element
|
|
|
303
303
|
```javascript
|
|
304
304
|
const element = document.querySelector('interact-element');
|
|
305
305
|
console.log('Connected:', element.connected);
|
|
306
|
-
console.log('Key:', element.dataset.
|
|
306
|
+
console.log('Key:', element.dataset.interactKey);
|
|
307
307
|
console.log('Has child:', element.firstElementChild !== null);
|
|
308
308
|
```
|
|
309
309
|
|
|
@@ -400,7 +400,7 @@ const config: InteractConfig = {
|
|
|
400
400
|
key: 'accordion',
|
|
401
401
|
trigger: 'click',
|
|
402
402
|
selector: '.accordion-header',
|
|
403
|
-
effects: [{ effectId: 'expanded',
|
|
403
|
+
effects: [{ effectId: 'expanded', stateAction: 'toggle' }],
|
|
404
404
|
},
|
|
405
405
|
],
|
|
406
406
|
};
|
|
@@ -460,20 +460,24 @@ import { Interact, Interaction, InteractConfig } from '@wix/interact/react';
|
|
|
460
460
|
const config: InteractConfig = {
|
|
461
461
|
interactions: [
|
|
462
462
|
{
|
|
463
|
-
key: 'product-list',
|
|
463
|
+
key: 'product-list', // single triggering parent
|
|
464
464
|
trigger: 'viewEnter',
|
|
465
|
-
|
|
466
|
-
effects: [
|
|
465
|
+
sequences: [
|
|
467
466
|
{
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
467
|
+
offset: 100, // Stagger animation for list items
|
|
468
|
+
effects: [
|
|
469
|
+
{
|
|
470
|
+
listContainer: '.products', //multiple target elements
|
|
471
|
+
keyframeEffect: {
|
|
472
|
+
name: 'slide-up',
|
|
473
|
+
keyframes: [
|
|
474
|
+
{ opacity: 0, transform: 'translateY(30px)' },
|
|
475
|
+
{ opacity: 1, transform: 'translateY(0)' },
|
|
476
|
+
],
|
|
477
|
+
},
|
|
478
|
+
duration: 400,
|
|
479
|
+
},
|
|
480
|
+
],
|
|
477
481
|
},
|
|
478
482
|
],
|
|
479
483
|
},
|
package/package.json
CHANGED
package/rules/click.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
This document contains rules for generating click-triggered interactions in `@wix/interact`.
|
|
4
4
|
|
|
5
|
+
**Static site CSS:** For static or pre-rendered sites, prefer including all click
|
|
6
|
+
interactions in `generate(config, useFirstChild)` at build/generation time and
|
|
7
|
+
embedding the CSS in the HTML output (`<style>` or linked `.css` in `<head>`, or
|
|
8
|
+
`blocking="render"` at the start of `<body>`). Split runtime-dependent click
|
|
9
|
+
interactions into a separate config where practical; otherwise generate the
|
|
10
|
+
complete CSS at runtime before `Interact.create()`.
|
|
11
|
+
See [full-lean.md](./full-lean.md#css-generation--fouc-prevention).
|
|
12
|
+
|
|
5
13
|
**CRITICAL — Accessible click**: Use `trigger: 'activate'` instead of `trigger: 'click'` to also respond to keyboard activation (Enter / Space).
|
|
6
14
|
|
|
7
15
|
## Table of Contents
|
package/rules/full-lean.md
CHANGED
|
@@ -54,7 +54,12 @@ Create the full config up-front and pass it in a single `create` call. Subsequen
|
|
|
54
54
|
**Web (Custom Elements):**
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
|
-
import { Interact } from '@wix/interact/web';
|
|
57
|
+
import { Interact, generate } from '@wix/interact/web';
|
|
58
|
+
import { FadeIn } from '@wix/motion-presets';
|
|
59
|
+
|
|
60
|
+
Interact.registerEffects({ FadeIn });
|
|
61
|
+
const css = generate(config, true); // useFirstChild = true for web
|
|
62
|
+
// Embed css in HTML — see CSS Generation & FOUC Prevention
|
|
58
63
|
const instance = Interact.create(config);
|
|
59
64
|
```
|
|
60
65
|
|
|
@@ -62,12 +67,15 @@ The `config` object is an `InteractConfig` containing `interactions` (required),
|
|
|
62
67
|
|
|
63
68
|
**React:**
|
|
64
69
|
|
|
70
|
+
- Call `generate(config, false)` during SSR/build and embed the CSS in document `<head>` (`<style>` or a linked `.css` file).
|
|
65
71
|
- Wrap the `Interact.create()` call in a `useEffect` hook to prevent it from running on server-side.
|
|
66
72
|
- Store the returned instance, and call its `.destroy()` method on the effect's cleanup function.
|
|
67
73
|
|
|
68
74
|
```ts
|
|
69
75
|
import { useEffect } from 'react';
|
|
70
|
-
import { Interact } from '@wix/interact/react';
|
|
76
|
+
import { Interact, generate } from '@wix/interact/react';
|
|
77
|
+
|
|
78
|
+
const css = generate(config, false); // useFirstChild = false for React
|
|
71
79
|
|
|
72
80
|
useEffect(() => {
|
|
73
81
|
const instance = Interact.create(config);
|
|
@@ -81,7 +89,12 @@ useEffect(() => {
|
|
|
81
89
|
**Vanilla JS:**
|
|
82
90
|
|
|
83
91
|
```ts
|
|
84
|
-
import { Interact, add, remove } from '@wix/interact';
|
|
92
|
+
import { Interact, add, remove, generate } from '@wix/interact';
|
|
93
|
+
import { FadeIn } from '@wix/motion-presets';
|
|
94
|
+
|
|
95
|
+
Interact.registerEffects({ FadeIn });
|
|
96
|
+
const css = generate(config, false); // useFirstChild = false for vanilla
|
|
97
|
+
// Embed css in HTML — see CSS Generation & FOUC Prevention
|
|
85
98
|
const instance = Interact.create(config);
|
|
86
99
|
add(element, 'hero'); // bind after element exists in DOM
|
|
87
100
|
remove('hero'); // unregister
|
|
@@ -89,14 +102,25 @@ remove('hero'); // unregister
|
|
|
89
102
|
|
|
90
103
|
**CDN (no build tools):**
|
|
91
104
|
|
|
105
|
+
For agent-generated static HTML, prefer running `generate()` in a Node/build
|
|
106
|
+
script and embedding all CSS in the output. If some interactions need runtime
|
|
107
|
+
data, split them into a browser-generated config where practical; otherwise
|
|
108
|
+
generate the complete CSS at runtime. This example shows the fully pre-generated
|
|
109
|
+
case, so its CDN script only needs `Interact` for runtime `create()`:
|
|
110
|
+
|
|
92
111
|
```html
|
|
112
|
+
<head>
|
|
113
|
+
<style>
|
|
114
|
+
…pre-generated css from generate()…
|
|
115
|
+
</style>
|
|
116
|
+
</head>
|
|
93
117
|
<script type="module">
|
|
94
|
-
import { Interact } from 'https://esm.sh/@wix/interact';
|
|
118
|
+
import { Interact } from 'https://esm.sh/@wix/interact/web';
|
|
95
119
|
Interact.create(config);
|
|
96
120
|
</script>
|
|
97
121
|
```
|
|
98
122
|
|
|
99
|
-
**Registering presets** — MUST be called before calling `Interact.create()` with usage of `namedEffect`:
|
|
123
|
+
**Registering presets** — MUST be called before calling `generate()` or `Interact.create()` with usage of `namedEffect`:
|
|
100
124
|
|
|
101
125
|
```ts
|
|
102
126
|
import * as presets from '@wix/motion-presets';
|
|
@@ -586,27 +610,58 @@ conditions: {
|
|
|
586
610
|
|
|
587
611
|
### Generating CSS
|
|
588
612
|
|
|
589
|
-
Call `generate(config, useFirstChild)`
|
|
590
|
-
|
|
613
|
+
Call `generate(config, useFirstChild)` at build/generation time to produce complete CSS for **all** interactions in the config — including initial state for entrance effects triggered by `viewEnter`. The output includes `@keyframes`, animation/transition custom properties, `view-timeline` declarations, state-selector rules, coordinated-list aggregation, and FOUC-prevention initial rules.
|
|
614
|
+
|
|
615
|
+
**Static site policy:** For static or pre-rendered HTML, prefer calling
|
|
616
|
+
`generate()` for the complete config at build/generation time and embedding the
|
|
617
|
+
CSS in the shipped HTML. If some interactions depend on runtime-only data, split
|
|
618
|
+
them into a separate config: pre-generate the static config and generate/inject
|
|
619
|
+
the runtime config in the browser before its `Interact.create()` call. If
|
|
620
|
+
splitting is impractical, generating the complete CSS at runtime is an acceptable
|
|
621
|
+
fallback. Call `registerEffects()` before each `generate()` when using
|
|
622
|
+
`namedEffect`.
|
|
623
|
+
|
|
624
|
+
The `useFirstChild` argument tells Interact whether to render `:first-child` selectors for custom-element (`web`) integration: `true` for **web**, `false` for **react** and **vanilla**.
|
|
591
625
|
|
|
592
626
|
```ts
|
|
593
627
|
import { generate } from '@wix/interact/web';
|
|
594
|
-
|
|
628
|
+
import { FadeIn } from '@wix/motion-presets';
|
|
629
|
+
|
|
630
|
+
Interact.registerEffects({ FadeIn });
|
|
631
|
+
const css = generate(config, true); // true for web; false for react/vanilla
|
|
595
632
|
```
|
|
596
633
|
|
|
597
|
-
|
|
634
|
+
**Embed the CSS** in the HTML output using one of:
|
|
598
635
|
|
|
599
636
|
```html
|
|
600
|
-
<
|
|
601
|
-
|
|
602
|
-
|
|
637
|
+
<!-- Option 1: inline in <head> (preferred) -->
|
|
638
|
+
<head>
|
|
639
|
+
<style>
|
|
640
|
+
…generated css…
|
|
641
|
+
</style>
|
|
642
|
+
</head>
|
|
643
|
+
|
|
644
|
+
<!-- Option 2: linked stylesheet in <head> -->
|
|
645
|
+
<head>
|
|
646
|
+
<link rel="stylesheet" href="interact.css" />
|
|
647
|
+
</head>
|
|
648
|
+
|
|
649
|
+
<!-- Option 3: render-blocking at start of <body> (prevents FOUC) -->
|
|
650
|
+
<body>
|
|
651
|
+
<style blocking="render">
|
|
652
|
+
…generated css…
|
|
653
|
+
</style>
|
|
654
|
+
<!-- or -->
|
|
655
|
+
<link rel="stylesheet" href="interact.css" blocking="render" />
|
|
656
|
+
…
|
|
657
|
+
</body>
|
|
603
658
|
```
|
|
604
659
|
|
|
605
660
|
### FOUC Prevention (viewEnter + once)
|
|
606
661
|
|
|
607
662
|
**Problem:** Elements with entrance animations (e.g. `viewEnter` + `triggerType: 'once'` with `FadeIn`) start in their final visible state. Before the animation framework initializes and applies the starting keyframe (e.g. `opacity: 0`), the element is briefly visible at full opacity — causing a flash of unstyled/un-animated content (FOUC).
|
|
608
663
|
|
|
609
|
-
**Solution:** Call `generate(config, useFirstChild)`
|
|
664
|
+
**Solution:** Call `generate(config, useFirstChild)` at build/generation time and embed the resulting CSS before first paint. The generated initial rules hide entrance-animated elements from the moment the page renders.
|
|
610
665
|
|
|
611
666
|
### Scroll-driven CSS (viewProgress)
|
|
612
667
|
|
|
@@ -615,7 +670,11 @@ Scroll-driven animations do not need separate FOUC prevention — the animation
|
|
|
615
670
|
|
|
616
671
|
### Rules
|
|
617
672
|
|
|
618
|
-
-
|
|
673
|
+
- For static/pre-rendered sites, prefer generating all possible CSS at
|
|
674
|
+
build/generation time. Split runtime-dependent interactions into a separate
|
|
675
|
+
config where practical, or fall back to generating the full config at runtime.
|
|
676
|
+
- Inject runtime-generated CSS before the corresponding `Interact.create()` call
|
|
677
|
+
and before revealing initially hidden content to minimize FOUC.
|
|
619
678
|
- FOUC initial rules apply only to `viewEnter` + `triggerType: 'once'` where source and target are the same element.
|
|
620
679
|
- For `repeat`/`alternate`/`state`, manually apply the starting keyframe as inline styles on the target element and use `fill: 'both'`.
|
|
621
680
|
|
|
@@ -650,11 +709,12 @@ The target element is what the effect animates. Resolved in priority order:
|
|
|
650
709
|
|
|
651
710
|
| Method / Property | Description |
|
|
652
711
|
| :---------------------------------- | :------------------------------------------------------------------------------------------------------------ |
|
|
712
|
+
| `generate(config, useFirstChild?)` | Produce complete CSS for all interactions. Call at build/generation time; embed in HTML. |
|
|
653
713
|
| `Interact.create(config)` | Initialize with a config. Returns the instance. Store the instance to manage its lifecycle. |
|
|
654
|
-
| `Interact.registerEffects(presets)` | Register named effect presets. MUST be called before `create`.
|
|
714
|
+
| `Interact.registerEffects(presets)` | Register named effect presets. MUST be called before `generate()` and `create`. |
|
|
655
715
|
| `Interact.destroy()` | Tear down all instances. Call on unmount or route change to prevent memory leaks. |
|
|
656
716
|
| `Interact.forceReducedMotion` | `boolean` (default: `false`) — force reduced-motion behavior regardless of OS setting. |
|
|
657
|
-
| `Interact.allowA11yTriggers` | `boolean` (default: `
|
|
717
|
+
| `Interact.allowA11yTriggers` | `boolean` (default: `true`) — enable accessibility trigger variants (`interest`, `activate`). |
|
|
658
718
|
| `Interact.setup(options)` | Configure global options for scroll, pointer, and viewEnter systems. Call before `create`. See options below. |
|
|
659
719
|
|
|
660
720
|
**`Interact.setup(options)`** — optional configuration object:
|
package/rules/hover.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
This document contains rules for generating hover-triggered interactions in `@wix/interact`.
|
|
4
4
|
|
|
5
|
+
**Static site CSS:** For static or pre-rendered sites, prefer including all hover
|
|
6
|
+
interactions in `generate(config, useFirstChild)` at build/generation time and
|
|
7
|
+
embedding the CSS in the HTML output (`<style>` or linked `.css` in `<head>`, or
|
|
8
|
+
`blocking="render"` at the start of `<body>`). Split runtime-dependent hover
|
|
9
|
+
interactions into a separate config where practical; otherwise generate the
|
|
10
|
+
complete CSS at runtime before `Interact.create()`.
|
|
11
|
+
See [full-lean.md](./full-lean.md#css-generation--fouc-prevention).
|
|
12
|
+
|
|
5
13
|
**CRITICAL — Accessible hover**: Use `trigger: 'interest'` instead of `trigger: 'hover'` to also respond to keyboard focus.
|
|
6
14
|
|
|
7
15
|
- **CRITICAL**: MUST AVOID using the same element as both trigger source and effect target with effects that change size or position (e.g. `transform: translate(…)`, `scale(…)`). The transform shifts the hit area, causing jittery re-entry cycles. Instead, use `selector` to target a child element for the animation.
|
package/rules/integration.md
CHANGED
|
@@ -31,8 +31,12 @@ npm install @wix/interact @wix/motion-presets
|
|
|
31
31
|
### Web (Custom Elements)
|
|
32
32
|
|
|
33
33
|
```typescript
|
|
34
|
-
import { Interact } from '@wix/interact/web';
|
|
34
|
+
import { Interact, generate } from '@wix/interact/web';
|
|
35
|
+
import { FadeIn } from '@wix/motion-presets';
|
|
35
36
|
|
|
37
|
+
Interact.registerEffects({ FadeIn });
|
|
38
|
+
const css = generate(config, true); // useFirstChild = true for web
|
|
39
|
+
// Embed css in HTML — see CSS Generation & FOUC Prevention
|
|
36
40
|
Interact.create(config);
|
|
37
41
|
```
|
|
38
42
|
|
|
@@ -53,12 +57,16 @@ Wrap target elements with `<interact-element>`:
|
|
|
53
57
|
|
|
54
58
|
### React
|
|
55
59
|
|
|
60
|
+
- Call `generate(config, false)` during SSR/build and embed the CSS in document `<head>` (`<style>` or a linked `.css` file).
|
|
56
61
|
- Wrap the `Interact.create()` call in a `useEffect` hook to prevent it from running on server-side.
|
|
57
62
|
- Store the returned instance, and call its `.destroy()` method on the effect's cleanup function.
|
|
58
63
|
|
|
59
64
|
```typescript
|
|
60
65
|
import { useEffect } from 'react';
|
|
61
|
-
import { Interact } from '@wix/interact/react';
|
|
66
|
+
import { Interact, generate } from '@wix/interact/react';
|
|
67
|
+
|
|
68
|
+
const css = generate(config, false); // useFirstChild = false for React
|
|
69
|
+
// Embed css in <head> during SSR/build
|
|
62
70
|
|
|
63
71
|
useEffect(() => {
|
|
64
72
|
const instance = Interact.create(config);
|
|
@@ -87,9 +95,13 @@ import { Interaction } from '@wix/interact/react';
|
|
|
87
95
|
### Vanilla JS
|
|
88
96
|
|
|
89
97
|
```typescript
|
|
90
|
-
import { Interact, add } from '@wix/interact';
|
|
98
|
+
import { Interact, add, generate } from '@wix/interact';
|
|
99
|
+
import { FadeIn } from '@wix/motion-presets';
|
|
91
100
|
|
|
92
|
-
|
|
101
|
+
Interact.registerEffects({ FadeIn });
|
|
102
|
+
const css = generate(config, false); // useFirstChild = false for vanilla
|
|
103
|
+
// Embed css in HTML — see CSS Generation & FOUC Prevention
|
|
104
|
+
Interact.create(config);
|
|
93
105
|
add(element, 'hero');
|
|
94
106
|
```
|
|
95
107
|
|
|
@@ -102,7 +114,7 @@ add(element, 'hero');
|
|
|
102
114
|
|
|
103
115
|
## Named Effects & registerEffects
|
|
104
116
|
|
|
105
|
-
To use `namedEffect` presets from `@wix/motion-presets`, register them before calling `Interact.create`. For full effect type syntax (`keyframeEffect`, `customEffect`, `StateEffect`, `ScrubEffect`), see `full-lean.md`.
|
|
117
|
+
To use `namedEffect` presets from `@wix/motion-presets`, register them before calling `generate()` or `Interact.create()`. For full effect type syntax (`keyframeEffect`, `customEffect`, `StateEffect`, `ScrubEffect`), see `full-lean.md`.
|
|
106
118
|
|
|
107
119
|
**Install:**
|
|
108
120
|
|
|
@@ -261,33 +273,68 @@ Define reusable sequences in `InteractConfig.sequences` and reference by `sequen
|
|
|
261
273
|
|
|
262
274
|
## CSS Generation & FOUC Prevention
|
|
263
275
|
|
|
264
|
-
`generate(config, useFirstChild)` produces complete CSS for **all** interactions in the config — `@keyframes`, animation/transition custom properties, `view-timeline` declarations, state-selector rules, coordinated-list aggregation, and FOUC-prevention initial rules.
|
|
265
|
-
|
|
276
|
+
`generate(config, useFirstChild)` produces complete CSS for **all** interactions in the config — `@keyframes`, animation/transition custom properties, `view-timeline` declarations, state-selector rules, coordinated-list aggregation, and FOUC-prevention initial rules.
|
|
277
|
+
|
|
278
|
+
**Static site policy:** For static or pre-rendered HTML (agent-generated pages,
|
|
279
|
+
SSG, static export), prefer calling `generate()` for the complete config at
|
|
280
|
+
build/generation time and embedding the CSS in the shipped HTML. If some
|
|
281
|
+
interactions depend on runtime-only data, split them into a separate config:
|
|
282
|
+
pre-generate the static config and generate/inject the runtime config in the
|
|
283
|
+
browser before its `Interact.create()` call. If splitting is impractical,
|
|
284
|
+
generating the complete CSS at runtime is an acceptable fallback. Call
|
|
285
|
+
`registerEffects()` before each `generate()` when using `namedEffect`.
|
|
286
|
+
|
|
287
|
+
The `useFirstChild` argument tells Interact whether to render `:first-child` selectors for custom-element (`web`) integration: `true` for **web**, `false` for **react** and **vanilla**.
|
|
266
288
|
|
|
267
289
|
```javascript
|
|
268
290
|
import { generate } from '@wix/interact/web';
|
|
269
|
-
|
|
291
|
+
import { FadeIn } from '@wix/motion-presets';
|
|
292
|
+
|
|
293
|
+
Interact.registerEffects({ FadeIn });
|
|
294
|
+
const css = generate(config, true); // true for web; false for react/vanilla
|
|
270
295
|
```
|
|
271
296
|
|
|
272
|
-
**
|
|
297
|
+
**Embed the CSS** in the HTML output using one of:
|
|
273
298
|
|
|
274
299
|
```html
|
|
275
|
-
<
|
|
276
|
-
|
|
277
|
-
|
|
300
|
+
<!-- Option 1: inline in <head> (preferred) -->
|
|
301
|
+
<head>
|
|
302
|
+
<style>
|
|
303
|
+
…generated css…
|
|
304
|
+
</style>
|
|
305
|
+
</head>
|
|
306
|
+
|
|
307
|
+
<!-- Option 2: linked stylesheet in <head> -->
|
|
308
|
+
<head>
|
|
309
|
+
<link rel="stylesheet" href="interact.css" />
|
|
310
|
+
</head>
|
|
311
|
+
|
|
312
|
+
<!-- Option 3: render-blocking at start of <body> (prevents FOUC) -->
|
|
313
|
+
<body>
|
|
314
|
+
<style blocking="render">
|
|
315
|
+
…generated css…
|
|
316
|
+
</style>
|
|
317
|
+
<!-- or -->
|
|
318
|
+
<link rel="stylesheet" href="interact.css" blocking="render" />
|
|
319
|
+
…
|
|
320
|
+
</body>
|
|
278
321
|
```
|
|
279
322
|
|
|
280
323
|
### FOUC Prevention (viewEnter + once)
|
|
281
324
|
|
|
282
325
|
**Problem:** Elements with entrance animations (e.g. `FadeIn` on `viewEnter`) are initially visible in their final state. Before the animation framework applies the starting keyframe, the content flashes visibly — a flash of un-animated content (FOUC).
|
|
283
326
|
|
|
284
|
-
**Solution:** Call `generate(config, useFirstChild)`
|
|
327
|
+
**Solution:** Call `generate(config, useFirstChild)` at build/generation time and embed the resulting CSS before first paint. The generated initial rules hide entrance-animated elements until the animation starts.
|
|
285
328
|
|
|
286
329
|
See [viewenter.md](./viewenter.md) for full details.
|
|
287
330
|
|
|
288
331
|
**Rules:**
|
|
289
332
|
|
|
290
|
-
-
|
|
333
|
+
- For static/pre-rendered sites, prefer generating all possible CSS at
|
|
334
|
+
build/generation time. Split runtime-dependent interactions into a separate
|
|
335
|
+
config where practical, or fall back to generating the full config at runtime.
|
|
336
|
+
- Inject runtime-generated CSS before the corresponding `Interact.create()` call
|
|
337
|
+
and before revealing initially hidden content to minimize FOUC.
|
|
291
338
|
- `generate()` processes all interactions, not just `viewEnter`.
|
|
292
339
|
- FOUC initial rules apply only to `viewEnter` + `triggerType: 'once'` (or no `triggerType`, which defaults to `'once'`) where source and target are the same element.
|
|
293
340
|
|
|
@@ -299,8 +346,9 @@ Each `Interact.create(config)` call returns an instance. Keep a reference if you
|
|
|
299
346
|
|
|
300
347
|
| Method / Property | Description |
|
|
301
348
|
| :---------------------------------- | :------------------------------------------------------------------------------------------- |
|
|
349
|
+
| `generate(config, useFirstChild?)` | Produce complete CSS for all interactions. Call at build/generation time; embed in HTML. |
|
|
302
350
|
| `Interact.create(config)` | Initialize with a config. Returns the instance. Multiple configs create separate instances. |
|
|
303
|
-
| `Interact.registerEffects(presets)` | Register named effect presets before `create`. Required for `namedEffect
|
|
351
|
+
| `Interact.registerEffects(presets)` | Register named effect presets before `generate()` and `create`. Required for `namedEffect`. |
|
|
304
352
|
| `Interact.destroy()` | Tear down all instances. |
|
|
305
353
|
| `Interact.forceReducedMotion` | `boolean` — force reduced-motion behavior regardless of OS setting. Default: `false`. |
|
|
306
354
|
| `Interact.allowA11yTriggers` | `boolean` — enable accessibility triggers (`interest`, `activate`). Default: `false`. |
|
package/rules/validate.md
CHANGED
|
@@ -25,6 +25,7 @@ Rules for using `@wix/interact-validate` — validate an `InteractConfig` before
|
|
|
25
25
|
|
|
26
26
|
- **In CI / at build time** — gate a build on a clean config.
|
|
27
27
|
- **Before `Interact.create()` / `generate()`** — fail fast on a malformed config instead of debugging at runtime.
|
|
28
|
+
- **After validation, for static site output** — run `generate(config, useFirstChild)` in the build step and embed the CSS in the HTML (`<style>` or linked `.css` in `<head>`, or `blocking="render"` at start of `<body>`). Validation alone does not produce styles.
|
|
28
29
|
- **On LLM-generated configs** — run the validator on any config an agent produces and fix every `error` (ideally every `warning`) before emitting it.
|
|
29
30
|
|
|
30
31
|
---
|
|
@@ -55,7 +56,7 @@ if (!result.valid) {
|
|
|
55
56
|
- `valid` is `true` when no remaining issue has severity `'error'`. **Warnings alone do not make `valid: false`.**
|
|
56
57
|
- `errors` holds **all** surfaced issues — both `'error'` and `'warning'` severities. Filter on `severity` to separate them.
|
|
57
58
|
- Issues are sorted lexicographically by `path`.
|
|
58
|
-
- Validation runs in two layers: a **structural** zod parse first (produces `SCHEMA_*` and numeric/threshold codes); if that succeeds, **referential + semantic** checks run (dangling references, unused definitions, duplicate keyframe names, media-query syntax). If the structural parse fails, the semantic layer is skipped.
|
|
59
|
+
- Validation runs in two layers: a **structural** zod parse first (produces `SCHEMA_*` and numeric/threshold codes); if that succeeds, **referential + semantic** checks run (dangling references, unused definitions, duplicate keyframe names, media-query syntax, and the rule-derived semantic warnings — same-element re-trigger, hit-area shift, scroll-preset `range`, `animationEnd` graph cycles, element-selection coherence, `fill`/`inset`/keyframe-camelCase nudges). If the structural parse fails, the semantic layer is skipped.
|
|
59
60
|
|
|
60
61
|
### assertValidInteractConfig
|
|
61
62
|
|
|
@@ -124,13 +125,23 @@ try {
|
|
|
124
125
|
Severity is one of `'error' | 'warning'`. There are exactly two levers:
|
|
125
126
|
|
|
126
127
|
1. **`strict: true`** — promotes all remaining issues to `'error'`, so any warning fails the config.
|
|
127
|
-
2. **`severityOverrides`** — keyed by **rule category**, not by individual code. Only the following
|
|
128
|
-
|
|
129
|
-
| Rule category
|
|
130
|
-
|
|
|
131
|
-
| `UNUSED_DEFINITION`
|
|
132
|
-
| `UNIQUE_DEFINITION_IDS`
|
|
133
|
-
| `VALID_MEDIA_QUERIES`
|
|
128
|
+
2. **`severityOverrides`** — keyed by **rule category**, not by individual code. Only the following categories are registered and overridable:
|
|
129
|
+
|
|
130
|
+
| Rule category | Covers codes | Default severity |
|
|
131
|
+
| ------------------------ | --------------------------------------------------------------------------- | ---------------- |
|
|
132
|
+
| `UNUSED_DEFINITION` | `UNUSED_EFFECT`, `UNUSED_SEQUENCE`, `UNUSED_CONDITION` | warning |
|
|
133
|
+
| `UNIQUE_DEFINITION_IDS` | `DUPLICATE_KEYFRAME_NAME` | warning |
|
|
134
|
+
| `VALID_MEDIA_QUERIES` | `INVALID_MEDIA_QUERY` | error |
|
|
135
|
+
| `SAME_ELEMENT_RETRIGGER` | `SAME_ELEMENT_RETRIGGER` | warning |
|
|
136
|
+
| `HIT_AREA_SHIFT` | `HIT_AREA_SHIFT` | warning |
|
|
137
|
+
| `SCROLL_RANGE` | `SCROLL_PRESET_MISSING_RANGE`, `SCROLL_PRESET_BAD_RANGE` | warning |
|
|
138
|
+
| `ANIMATION_END_GRAPH` | `ANIMATION_END_SELF_REFERENCE`, `ANIMATION_END_CYCLE` | warning |
|
|
139
|
+
| `ELEMENT_SELECTION` | `LIST_ITEM_SELECTOR_WITHOUT_CONTAINER`, `REDUNDANT_SELECTOR_WITH_LIST_ITEM` | warning |
|
|
140
|
+
| `STATE_EFFECT` | `EMPTY_STYLE_PROPERTIES`, `STATE_REMOVE_WITHOUT_EFFECT_ID` | warning |
|
|
141
|
+
| `RECOMMENDED_FILL` | `RECOMMENDED_FILL_BOTH` | info |
|
|
142
|
+
| `POINTER_AXIS` | `POINTER_AXIS_IGNORED` | warning |
|
|
143
|
+
| `KEYFRAME_STYLE` | `KEYFRAME_PROP_NOT_CAMEL_CASE` | warning |
|
|
144
|
+
| `VIEW_INSET` | `INVALID_INSET` | warning |
|
|
134
145
|
|
|
135
146
|
For each category, set `'off'` to drop those issues entirely, `'warning'` / `'error'` to set their severity:
|
|
136
147
|
|
|
@@ -184,17 +195,17 @@ This is the authoritative list of every code the validator emits today. Codes no
|
|
|
184
195
|
|
|
185
196
|
| Code | What it flags |
|
|
186
197
|
| -------------------------------- | ------------------------------------------------------------------------------ |
|
|
187
|
-
| `EFFECT_ID_NOT_FOUND` | An effect's `effectId` references a key absent from `config.effects`. |
|
|
188
198
|
| `ANIMATION_END_EFFECT_NOT_FOUND` | An `animationEnd` interaction's `params.effectId` references a missing effect. |
|
|
189
199
|
| `SEQUENCE_ID_NOT_FOUND` | A `sequenceId` references a key absent from `config.sequences`. |
|
|
190
200
|
| `CONDITION_NOT_FOUND` | A `conditions[]` entry references a key absent from `config.conditions`. |
|
|
191
201
|
|
|
192
202
|
### Other structural errors (severity: error)
|
|
193
203
|
|
|
194
|
-
| Code | What it flags
|
|
195
|
-
| --------------------- |
|
|
196
|
-
| `INTERACTION_EMPTY` | An interaction has neither `effects` nor `sequences`. (`viewProgress`/`pointerMove` require a non-empty `effects` array and instead surface `SCHEMA_TOO_SMALL`.)
|
|
197
|
-
| `INVALID_MEDIA_QUERY` | A `media` condition's `predicate` fails static media-query syntax validation (balanced parentheses + allowed characters). Belongs to the `VALID_MEDIA_QUERIES` rule category.
|
|
204
|
+
| Code | What it flags |
|
|
205
|
+
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
206
|
+
| `INTERACTION_EMPTY` | An interaction has neither `effects` nor `sequences`. (`viewProgress`/`pointerMove` require a non-empty `effects` array and instead surface `SCHEMA_TOO_SMALL`.) |
|
|
207
|
+
| `INVALID_MEDIA_QUERY` | A `media` condition's `predicate` fails static media-query syntax validation (balanced parentheses + allowed characters). Belongs to the `VALID_MEDIA_QUERIES` rule category. |
|
|
208
|
+
| `ANIMATION_END_CYCLE` | A cycle of `animationEnd` interactions wait on each other's effects → deadlock; none can start. Belongs to the `ANIMATION_END_GRAPH` rule category (so it can be demoted/silenced). |
|
|
198
209
|
|
|
199
210
|
### Best-practice warnings (severity: warning)
|
|
200
211
|
|
|
@@ -204,6 +215,27 @@ This is the authoritative list of every code the validator emits today. Codes no
|
|
|
204
215
|
| `UNUSED_SEQUENCE` | A `config.sequences` entry is defined but never referenced. | `UNUSED_DEFINITION` |
|
|
205
216
|
| `UNUSED_CONDITION` | A `config.conditions` entry is defined but never referenced. | `UNUSED_DEFINITION` |
|
|
206
217
|
| `DUPLICATE_KEYFRAME_NAME` | A `keyframeEffect.name` is reused across effects in the same config. | `UNIQUE_DEFINITION_IDS` |
|
|
218
|
+
| `EFFECT_ID_NOT_FOUND` | An effect's `effectId` references a key absent from `config.effects`. | `ID_NOT_FOUND` |
|
|
219
|
+
|
|
220
|
+
### Rule-derived semantic warnings (severity: warning)
|
|
221
|
+
|
|
222
|
+
Statically-detectable authoring pitfalls lifted from the trigger rule files. Each belongs to its own rule category, so `severityOverrides` can silence (`'off'`) or escalate (`'error'`) it. `strict: true` promotes all of these to `error`.
|
|
223
|
+
|
|
224
|
+
| Code | What it flags | Rule category |
|
|
225
|
+
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
|
|
226
|
+
| `SAME_ELEMENT_RETRIGGER` | `viewEnter` with `triggerType` `repeat`/`alternate`/`state` on the same source+target element (re-trigger loop). | `SAME_ELEMENT_RETRIGGER` |
|
|
227
|
+
| `HIT_AREA_SHIFT` | `hover`/`click`/`interest`/`activate`/`pointerMove` `keyframeEffect` with a `translate`/`scale`/`matrix` transform on the same source+target element. | `HIT_AREA_SHIFT` |
|
|
228
|
+
| `SCROLL_PRESET_MISSING_RANGE` | A `*Scroll` `namedEffect` on `viewProgress` omits `range`. | `SCROLL_RANGE` |
|
|
229
|
+
| `SCROLL_PRESET_BAD_RANGE` | A scroll preset `range` is not `'in'`/`'out'`/`'continuous'`. | `SCROLL_RANGE` |
|
|
230
|
+
| `ANIMATION_END_SELF_REFERENCE` | An `animationEnd` interaction waits for an effect it also produces → it can never start. | `ANIMATION_END_GRAPH` |
|
|
231
|
+
| `LIST_ITEM_SELECTOR_WITHOUT_CONTAINER` | `listItemSelector` present without `listContainer` (inert) — on an interaction or an effect. | `ELEMENT_SELECTION` |
|
|
232
|
+
| `REDUNDANT_SELECTOR_WITH_LIST_ITEM` | `selector` is ignored when both `listContainer` and `listItemSelector` are present. | `ELEMENT_SELECTION` |
|
|
233
|
+
| `EMPTY_STYLE_PROPERTIES` | A state effect's `transition.styleProperties` / `transitionProperties` is `[]` (toggles nothing). | `STATE_EFFECT` |
|
|
234
|
+
| `STATE_REMOVE_WITHOUT_EFFECT_ID` | `stateAction: 'remove'` with no `effectId` to pair with a matching `'add'`. | `STATE_EFFECT` |
|
|
235
|
+
| `RECOMMENDED_FILL_BOTH` | A scrubbed (`viewProgress`/`pointerMove`) or toggling (`alternate`/`repeat`/`state`) effect omits `fill: 'both'`. | `RECOMMENDED_FILL` |
|
|
236
|
+
| `POINTER_AXIS_IGNORED` | `pointerMove` `params.axis` set on a `namedEffect`/`customEffect` (axis only applies to `keyframeEffect`). | `POINTER_AXIS` |
|
|
237
|
+
| `KEYFRAME_PROP_NOT_CAMEL_CASE` | A `keyframeEffect` property name is kebab-case (not WAAPI camelCase). | `KEYFRAME_STYLE` |
|
|
238
|
+
| `INVALID_INSET` | `viewEnter` `params.inset` is not 1–4 whitespace-separated CSS lengths/percentages. | `VIEW_INSET` |
|
|
207
239
|
|
|
208
240
|
---
|
|
209
241
|
|
|
@@ -252,7 +284,14 @@ const ExperienceSchema = z.object({
|
|
|
252
284
|
|
|
253
285
|
- After generating a config, run `validateInteractConfig(config)` and **fix every `error`** before emitting. Prefer to fix `warning`s too.
|
|
254
286
|
- For a hard gate, use `assertValidInteractConfig(config)` or `validateInteractConfig(config, { strict: true })`.
|
|
255
|
-
-
|
|
287
|
+
- For static/pre-rendered site output, prefer: validate → `registerEffects()` →
|
|
288
|
+
`generate(config, useFirstChild)` at build/generation time → embed CSS in
|
|
289
|
+
`<head>` (`<style>` or linked `.css`) or at the start of `<body>` with
|
|
290
|
+
`blocking="render"`. If only part of the config is available then, validate and
|
|
291
|
+
generate the static and runtime-dependent configs separately. If splitting is
|
|
292
|
+
impractical, validate and generate the complete config at runtime before
|
|
293
|
+
`Interact.create()`.
|
|
294
|
+
- Mirror the core generation rules: do not invent `namedEffect` types, do not attach DOM listeners manually, use `overflow: clip` (not `hidden`) on scroll-tracked ancestors. See [full-lean.md](https://wix.github.io/interact/rules/full-lean.md).
|
|
256
295
|
|
|
257
296
|
---
|
|
258
297
|
|
|
@@ -263,9 +302,10 @@ The validator is **static**. It cannot see the DOM, the browser, or the preset r
|
|
|
263
302
|
- **DOM-dependent issues** — element existence for a `key`/`selector`, `overflow: hidden` ancestors breaking `viewProgress`, `pointer-events: none` on a source, `:first-child` presence.
|
|
264
303
|
- **Preset correctness** — only the config shape is checked, never whether a `namedEffect.type` is a registered preset or whether its options are valid. See [scroll-presets and other preset rules](https://github.com/wix/interact/blob/master/packages/motion-presets/rules/presets/presets-main.md).
|
|
265
304
|
- **Documented authoring pitfalls with no static signal**, which the trigger rule files cover instead:
|
|
266
|
-
-
|
|
267
|
-
-
|
|
268
|
-
-
|
|
269
|
-
|
|
305
|
+
- `overflow: hidden` ancestors breaking `viewProgress` → [viewprogress.md](https://wix.github.io/interact/rules/viewprogress.md).
|
|
306
|
+
- Whether a `keyframeEffect`/`namedEffect` actually changes size/position when it cannot be introspected (e.g. `namedEffect` options) — only inline `keyframeEffect` transforms are scanned for `HIT_AREA_SHIFT`.
|
|
307
|
+
- Reduced-motion alternatives, perspective usage, and other authoring guidance with no static signal.
|
|
308
|
+
|
|
309
|
+
> **Note:** Several pitfalls that previously had "no static signal" are now flagged as **warnings** (see the rule-derived semantic warnings above): same source+target on `viewEnter` with a non-`once` `triggerType` (`SAME_ELEMENT_RETRIGGER`), hit-area shift from inline `keyframeEffect` transforms on `hover`/`pointerMove` (`HIT_AREA_SHIFT`), scroll presets missing/invalid `range` (`SCROLL_PRESET_*`), and missing `fill: 'both'` (`RECOMMENDED_FILL_BOTH`). These are heuristic and conservative (they skip ambiguous cases to avoid false positives), so the trigger rule files remain the authoritative guidance.
|
|
270
310
|
|
|
271
311
|
For the full API, usage recipes, and the same catalogue in package form, see the [`@wix/interact-validate` README](https://github.com/wix/interact/blob/master/packages/interact-validate/README.md).
|
package/rules/viewenter.md
CHANGED
|
@@ -21,14 +21,21 @@ This document contains rules for generating interactions that respond to element
|
|
|
21
21
|
|
|
22
22
|
**Problem:** Elements with entrance animations (e.g. `FadeIn`) start in their final visible state (e.g. `opacity: 1`). Before the animation framework initializes and applies the starting keyframe (e.g. `opacity: 0`), the element is briefly visible at full opacity — a flash of un-animated content.
|
|
23
23
|
|
|
24
|
-
**Solution:** Call `generate(config, useFirstChild)`
|
|
24
|
+
**Solution:** Call `generate(config, useFirstChild)` at build/generation time and embed the resulting CSS before first paint. Among all the CSS it produces, `generate()` includes initial rules that hide entrance-animated elements from the moment the page renders, before JS runs. The rules use `:not([data-interact-enter])` so elements become visible once the animation starts.
|
|
25
25
|
|
|
26
|
-
### Generate CSS
|
|
26
|
+
### Generate CSS at build time and embed in HTML
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Prefer running this for the complete config in a **build/generation script**
|
|
29
|
+
(Node, SSG, agent scratch) and embedding the resulting CSS in the HTML output.
|
|
30
|
+
If some entrances depend on runtime-only data, split them into a separate config
|
|
31
|
+
and generate/inject that CSS in the browser before its `Interact.create()` call.
|
|
32
|
+
If splitting is impractical, generate the complete CSS at runtime as a fallback:
|
|
29
33
|
|
|
30
34
|
```typescript
|
|
31
35
|
import { generate } from '@wix/interact';
|
|
36
|
+
import { FadeIn } from '@wix/motion-presets';
|
|
37
|
+
|
|
38
|
+
Interact.registerEffects({ FadeIn });
|
|
32
39
|
|
|
33
40
|
const config: InteractConfig = {
|
|
34
41
|
interactions: [
|
|
@@ -46,26 +53,51 @@ const config: InteractConfig = {
|
|
|
46
53
|
],
|
|
47
54
|
};
|
|
48
55
|
|
|
49
|
-
const css = generate(config, useFirstChild);
|
|
56
|
+
const css = generate(config, useFirstChild); // true for web; false for react/vanilla
|
|
50
57
|
```
|
|
51
58
|
|
|
52
|
-
**
|
|
59
|
+
**Embed the CSS** using one of:
|
|
53
60
|
|
|
54
61
|
```html
|
|
55
|
-
<
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
<!-- Option 1: inline in <head> (preferred) -->
|
|
63
|
+
<head>
|
|
64
|
+
<style>
|
|
65
|
+
…generated css…
|
|
66
|
+
</style>
|
|
67
|
+
</head>
|
|
68
|
+
|
|
69
|
+
<!-- Option 2: linked stylesheet in <head> -->
|
|
70
|
+
<head>
|
|
71
|
+
<link rel="stylesheet" href="interact.css" />
|
|
72
|
+
</head>
|
|
73
|
+
|
|
74
|
+
<!-- Option 3: render-blocking at start of <body> (prevents FOUC) -->
|
|
75
|
+
<body>
|
|
76
|
+
<style blocking="render">
|
|
77
|
+
…generated css…
|
|
78
|
+
</style>
|
|
79
|
+
<!-- or -->
|
|
80
|
+
<link rel="stylesheet" href="interact.css" blocking="render" />
|
|
81
|
+
…
|
|
82
|
+
</body>
|
|
58
83
|
```
|
|
59
84
|
|
|
60
85
|
### Rules
|
|
61
86
|
|
|
62
|
-
-
|
|
87
|
+
- For static/pre-rendered sites, prefer generating all possible CSS at
|
|
88
|
+
build/generation time. Split runtime-dependent interactions into a separate
|
|
89
|
+
config where practical, or fall back to generating the full config at runtime.
|
|
90
|
+
- Inject runtime-generated CSS before the corresponding `Interact.create()` call
|
|
91
|
+
and before revealing initially hidden content to minimize FOUC.
|
|
63
92
|
- FOUC initial rules apply only to `viewEnter` + `triggerType: 'once'` (or no `triggerType`, which defaults to `'once'`) where source and target are the same element.
|
|
64
93
|
- For `viewEnter` with `triggerType: 'repeat'`/`'alternate'`/`'state'`, manually apply the starting keyframe as inline styles on the target element and use `fill: 'both'`.
|
|
65
94
|
- `generate(config)` processes all interactions in the config, not just `viewEnter`.
|
|
66
95
|
|
|
67
96
|
## Rule 1: keyframeEffect / namedEffect (TimeEffect)
|
|
68
97
|
|
|
98
|
+
For static sites, include this interaction in the config passed to `generate()` at
|
|
99
|
+
build time (see [FOUC section](#preventing-flash-of-unstyled-content-fouc)).
|
|
100
|
+
|
|
69
101
|
Use `keyframeEffect` or `namedEffect` when the viewEnter should play an animation (CSS or WAAPI). Set `triggerType` on each effect to control playback behavior. Use `params` only for observer configuration (`threshold`, `inset`).
|
|
70
102
|
|
|
71
103
|
**Multiple effects:** The `effects` array can contain multiple effects — all share the same viewEnter trigger and fire together when the element enters the viewport. Each effect can have its own `triggerType`. Use this to animate different targets from a single viewport entry event.
|
package/rules/viewprogress.md
CHANGED
|
@@ -19,6 +19,9 @@ These rules help generate scroll-driven interactions using `@wix/interact`. View
|
|
|
19
19
|
|
|
20
20
|
**Use Case**: Scroll-driven CSS-based effects.
|
|
21
21
|
|
|
22
|
+
For static sites, pre-render CSS via `generate()` at build time — see
|
|
23
|
+
[Pre-rendering Scroll-driven CSS with generate()](#pre-rendering-scroll-driven-css-with-generate).
|
|
24
|
+
|
|
22
25
|
**Multiple effects:** The `effects` array can contain multiple effects — all are driven by the same scroll progress. Use this to animate different targets or properties in sync with the same scroll position.
|
|
23
26
|
|
|
24
27
|
### Template
|
|
@@ -148,10 +151,26 @@ These rules help generate scroll-driven interactions using `@wix/interact`. View
|
|
|
148
151
|
|
|
149
152
|
## Pre-rendering Scroll-driven CSS with generate()
|
|
150
153
|
|
|
151
|
-
|
|
154
|
+
**Static site policy:** For static or pre-rendered HTML, prefer calling
|
|
155
|
+
`generate()` for the complete config at build/generation time and embedding the
|
|
156
|
+
CSS in the shipped HTML. If some interactions depend on runtime-only data, split
|
|
157
|
+
them into a separate config: pre-generate the static config and generate/inject
|
|
158
|
+
the runtime config in the browser before its `Interact.create()` call. If
|
|
159
|
+
splitting is impractical, generating the complete CSS at runtime is an acceptable
|
|
160
|
+
fallback. Call `registerEffects()` before each `generate()` when using
|
|
161
|
+
`namedEffect` scroll presets.
|
|
162
|
+
|
|
163
|
+
Call `generate(config, useFirstChild)` at build/generation time to produce native
|
|
164
|
+
scroll-driven CSS for `viewProgress` interactions. The generated output includes
|
|
165
|
+
`view-timeline` declarations, `animation-timeline`/`animation-range` custom
|
|
166
|
+
properties, and `@keyframes` — everything the browser needs to run scroll-driven
|
|
167
|
+
animations without any JS.
|
|
152
168
|
|
|
153
169
|
```typescript
|
|
154
170
|
import { generate } from '@wix/interact';
|
|
171
|
+
import { ParallaxScroll } from '@wix/motion-presets';
|
|
172
|
+
|
|
173
|
+
Interact.registerEffects({ ParallaxScroll });
|
|
155
174
|
|
|
156
175
|
const config = {
|
|
157
176
|
interactions: [
|
|
@@ -174,15 +193,33 @@ const config = {
|
|
|
174
193
|
effects: {},
|
|
175
194
|
};
|
|
176
195
|
|
|
177
|
-
const css = generate(config, false);
|
|
196
|
+
const css = generate(config, false); // false for react/vanilla; true for web
|
|
178
197
|
```
|
|
179
198
|
|
|
180
|
-
|
|
199
|
+
**Embed the CSS** using one of:
|
|
181
200
|
|
|
182
201
|
```html
|
|
183
|
-
<
|
|
184
|
-
|
|
185
|
-
|
|
202
|
+
<!-- Option 1: inline in <head> (preferred) -->
|
|
203
|
+
<head>
|
|
204
|
+
<style>
|
|
205
|
+
…generated css…
|
|
206
|
+
</style>
|
|
207
|
+
</head>
|
|
208
|
+
|
|
209
|
+
<!-- Option 2: linked stylesheet in <head> -->
|
|
210
|
+
<head>
|
|
211
|
+
<link rel="stylesheet" href="interact.css" />
|
|
212
|
+
</head>
|
|
213
|
+
|
|
214
|
+
<!-- Option 3: render-blocking at start of <body> -->
|
|
215
|
+
<body>
|
|
216
|
+
<style blocking="render">
|
|
217
|
+
…generated css…
|
|
218
|
+
</style>
|
|
219
|
+
<!-- or -->
|
|
220
|
+
<link rel="stylesheet" href="interact.css" blocking="render" />
|
|
221
|
+
…
|
|
222
|
+
</body>
|
|
186
223
|
```
|
|
187
224
|
|
|
188
225
|
**Benefits:**
|