@wix/interact 2.4.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +3 -0
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/react.js +6 -6
  4. package/dist/cjs/react.js.map +1 -1
  5. package/dist/cjs/web.js +1 -1
  6. package/dist/es/index.js +1 -1
  7. package/dist/es/react.js +117 -126
  8. package/dist/es/react.js.map +1 -1
  9. package/dist/es/web.js +2 -2
  10. package/dist/{index-C6u4q815.mjs → index-C2yYG3we.mjs} +232 -219
  11. package/dist/index-C2yYG3we.mjs.map +1 -0
  12. package/dist/{index-Qg46rn0Y.js → index-D84f3ylM.js} +8 -8
  13. package/dist/index-D84f3ylM.js.map +1 -0
  14. package/dist/tsconfig.build.tsbuildinfo +1 -1
  15. package/dist/types/core/css.d.ts.map +1 -1
  16. package/dist/types/core/cssUtils.d.ts.map +1 -1
  17. package/dist/types/core/resolvers.d.ts.map +1 -1
  18. package/dist/types/handlers/index.d.ts.map +1 -1
  19. package/dist/types/react/Interaction.d.ts +0 -1
  20. package/dist/types/react/Interaction.d.ts.map +1 -1
  21. package/dist/types/types/config.d.ts +1 -1
  22. package/dist/types/types/config.d.ts.map +1 -1
  23. package/dist/types/types/css.d.ts +1 -1
  24. package/dist/types/types/css.d.ts.map +1 -1
  25. package/dist/types/types/external.d.ts +1 -1
  26. package/dist/types/types/external.d.ts.map +1 -1
  27. package/dist/types/types/handlers.d.ts +0 -1
  28. package/dist/types/types/handlers.d.ts.map +1 -1
  29. package/dist/types/types/triggers.d.ts +1 -1
  30. package/dist/types/types/triggers.d.ts.map +1 -1
  31. package/docs/README.md +1 -0
  32. package/docs/api/README.md +7 -0
  33. package/docs/api/functions.md +3 -8
  34. package/docs/api/types.md +2 -3
  35. package/docs/examples/entrance-animations.md +3 -3
  36. package/docs/guides/README.md +1 -1
  37. package/docs/guides/configuration-structure.md +1 -1
  38. package/docs/guides/state-management.md +0 -41
  39. package/docs/integration/react.md +7 -8
  40. package/package.json +1 -1
  41. package/rules/full-lean.md +7 -36
  42. package/rules/integration.md +4 -31
  43. package/rules/validate.md +271 -0
  44. package/rules/viewenter.md +6 -35
  45. package/rules/viewprogress.md +1 -1
  46. package/dist/index-C6u4q815.mjs.map +0 -1
  47. package/dist/index-Qg46rn0Y.js.map +0 -1
@@ -81,10 +81,10 @@ useEffect(() => {
81
81
  **Vanilla JS:**
82
82
 
83
83
  ```ts
84
- import { Interact } from '@wix/interact';
84
+ import { Interact, add, remove } from '@wix/interact';
85
85
  const instance = Interact.create(config);
86
- instance.add(element, 'hero'); // bind after element exists in DOM
87
- instance.remove('hero'); // unregister
86
+ add(element, 'hero'); // bind after element exists in DOM
87
+ remove('hero'); // unregister
88
88
  ```
89
89
 
90
90
  **CDN (no build tools):**
@@ -606,47 +606,18 @@ Inject the result into the `<head>` (preferred), or beginning of `<body>`, so it
606
606
 
607
607
  **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
608
 
609
- **Solution:** Two things are required — both MUST be present:
610
-
611
- 1. **Generate CSS** using `generate(config, useFirstChild)` — among all the rules it produces, it includes initial rules that hide entrance-animated elements from the moment the page renders.
612
- 2. **Mark elements with `initial`** — tells the runtime which elements have critical CSS applied so it can coordinate with the generated styles.
613
-
614
- **Step 1: Generate CSS** — see above.
615
-
616
- **Step 2: Mark elements**
617
-
618
- **Web (Custom Elements):**
619
-
620
- ```html
621
- <interact-element data-interact-key="hero" data-interact-initial="true">
622
- <section class="hero">...</section>
623
- </interact-element>
624
- ```
625
-
626
- **React:**
627
-
628
- ```tsx
629
- <Interaction tagName="section" interactKey="hero" initial={true} className="hero">
630
- ...
631
- </Interaction>
632
- ```
633
-
634
- **Vanilla:**
635
-
636
- ```html
637
- <section data-interact-key="hero" data-interact-initial="true" class="hero">...</section>
638
- ```
609
+ **Solution:** Call `generate(config, useFirstChild)` server-side or at build time and inject the resulting CSS into `<head>`. The generated initial rules hide entrance-animated elements from the moment the page renders.
639
610
 
640
611
  ### Scroll-driven CSS (viewProgress)
641
612
 
642
613
  For `viewProgress` interactions, `generate()` emits `view-timeline` declarations and `animation-timeline`/`animation-range` properties.
643
- No `initial` attribute is needed for scroll-driven animations.
614
+ Scroll-driven animations do not need separate FOUC prevention — the animation is continuously driven by scroll position.
644
615
 
645
616
  ### Rules
646
617
 
647
618
  - `generate()` should be called server-side or at build time. Can also be called on client-side if page content is initially hidden (e.g. behind a loader/splash screen).
648
- - `initial` is only valid for `viewEnter` + `triggerType: 'once'` where source and target are the same element.
649
- - For `repeat`/`alternate`/`state`, do NOT use `initial`. Instead, manually apply the initial keyframe as inline styles on the target element and use `fill: 'both'`.
619
+ - FOUC initial rules apply only to `viewEnter` + `triggerType: 'once'` where source and target are the same element.
620
+ - For `repeat`/`alternate`/`state`, manually apply the starting keyframe as inline styles on the target element and use `fill: 'both'`.
650
621
 
651
622
  ---
652
623
 
@@ -87,10 +87,10 @@ import { Interaction } from '@wix/interact/react';
87
87
  ### Vanilla JS
88
88
 
89
89
  ```typescript
90
- import { Interact } from '@wix/interact';
90
+ import { Interact, add } from '@wix/interact';
91
91
 
92
92
  const interact = Interact.create(config);
93
- interact.add(element, 'hero');
93
+ add(element, 'hero');
94
94
  ```
95
95
 
96
96
  **Rules:**
@@ -281,12 +281,7 @@ const css = generate(config);
281
281
 
282
282
  **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
283
 
284
- **Solution:** Two things are required — both MUST be present:
285
-
286
- 1. **Generate CSS** with `generate(config, useFirstChild)` — among all the rules it produces, it includes initial rules that hide entrance-animated elements until the animation starts.
287
- 2. **Mark elements with `initial`** — `data-interact-initial="true"` on `<interact-element>`, or `initial={true}` on `<Interaction>` in React.
288
-
289
- Using only one of these has no effect — both are required.
284
+ **Solution:** Call `generate(config, useFirstChild)` server-side or at build time and inject the resulting CSS into `<head>`. The generated initial rules hide entrance-animated elements until the animation starts.
290
285
 
291
286
  See [viewenter.md](./viewenter.md) for full details.
292
287
 
@@ -294,29 +289,7 @@ See [viewenter.md](./viewenter.md) for full details.
294
289
 
295
290
  - `generate()` should be called server-side or at build time. Can also be called on the client if page content is initially hidden (e.g. behind a loader).
296
291
  - `generate()` processes all interactions, not just `viewEnter`.
297
- - `initial` is only valid for `viewEnter` + `triggerType: 'once'` (or no `triggerType`, which defaults to `'once'`) where source and target are the same element.
298
-
299
- **Web:**
300
-
301
- ```html
302
- <interact-element data-interact-key="hero" data-interact-initial="true">
303
- <section id="hero">...</section>
304
- </interact-element>
305
- ```
306
-
307
- **React:**
308
-
309
- ```tsx
310
- <Interaction tagName="section" interactKey="hero" initial={true} className="hero">
311
- ...
312
- </Interaction>
313
- ```
314
-
315
- **Vanilla:**
316
-
317
- ```html
318
- <section data-interact-key="hero" data-interact-initial="true" class="hero">...</section>
319
- ```
292
+ - FOUC initial rules apply only to `viewEnter` + `triggerType: 'once'` (or no `triggerType`, which defaults to `'once'`) where source and target are the same element.
320
293
 
321
294
  ---
322
295
 
@@ -0,0 +1,271 @@
1
+ # Validation Rules for @wix/interact-validate
2
+
3
+ Rules for using `@wix/interact-validate` — validate an `InteractConfig` before it reaches the runtime.
4
+
5
+ `@wix/interact-validate` is a standalone, zod-powered validator for the `@wix/interact` `InteractConfig` shape. It runs **statically** (no DOM, no browser, no runtime), so it is safe in build tools, CI, and server-side code. It is a separate package from `@wix/interact` and declares `@wix/interact` as a peer dependency — its config types come from there, so the two never drift.
6
+
7
+ ## Table of Contents
8
+
9
+ - [When to validate](#when-to-validate)
10
+ - [API](#api)
11
+ - [validateInteractConfig](#validateinteractconfig)
12
+ - [assertValidInteractConfig](#assertvalidinteractconfig)
13
+ - [ValidateOptions](#validateoptions)
14
+ - [ValidationError shape](#validationerror-shape)
15
+ - [InteractValidationError](#interactvalidationerror)
16
+ - [Severity, strict, and overrides](#severity-strict-and-overrides)
17
+ - [Error-code catalogue](#error-code-catalogue)
18
+ - [Zod schema exports](#zod-schema-exports)
19
+ - [Generation guidance for agents](#generation-guidance-for-agents)
20
+ - [Limitations — what is NOT checked](#limitations--what-is-not-checked)
21
+
22
+ ---
23
+
24
+ ## When to validate
25
+
26
+ - **In CI / at build time** — gate a build on a clean config.
27
+ - **Before `Interact.create()` / `generate()`** — fail fast on a malformed config instead of debugging at runtime.
28
+ - **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
+ ---
31
+
32
+ ## API
33
+
34
+ Two functions cover most use. Import from the package root — there is no subpath:
35
+
36
+ ```ts
37
+ import { validateInteractConfig, assertValidInteractConfig } from '@wix/interact-validate';
38
+ ```
39
+
40
+ ### validateInteractConfig
41
+
42
+ ```ts
43
+ const result = validateInteractConfig(config, options?);
44
+ // → { valid: boolean; errors: ValidationError[] }
45
+
46
+ if (!result.valid) {
47
+ for (const e of result.errors) {
48
+ console.warn(`[${e.severity}] ${e.code}: ${e.message} (at ${e.path.join('.')})`);
49
+ }
50
+ }
51
+ ```
52
+
53
+ **Rules:**
54
+
55
+ - `valid` is `true` when no remaining issue has severity `'error'`. **Warnings alone do not make `valid: false`.**
56
+ - `errors` holds **all** surfaced issues — both `'error'` and `'warning'` severities. Filter on `severity` to separate them.
57
+ - 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
+
60
+ ### assertValidInteractConfig
61
+
62
+ ```ts
63
+ assertValidInteractConfig(config); // asserts: input is InteractConfig — throws on failure
64
+ ```
65
+
66
+ **Rules:**
67
+
68
+ - Throws `InteractValidationError` when `valid` is `false` (i.e. at least one `'error'`). Warnings alone do not throw.
69
+ - After it returns, TypeScript narrows the argument to `InteractConfig`.
70
+ - It calls `validateInteractConfig` with default options (no `strict`/`max`/overrides). For custom options, call `validateInteractConfig` directly and inspect `result.valid`.
71
+
72
+ ### ValidateOptions
73
+
74
+ ```ts
75
+ type ValidateOptions = {
76
+ strict?: boolean;
77
+ max?: number;
78
+ severityOverrides?: Record<string, 'error' | 'warning' | 'off'>;
79
+ };
80
+ ```
81
+
82
+ | Option | Effect |
83
+ | ------------------- | -------------------------------------------------------------------------------------------------------- |
84
+ | `strict` | Promotes every remaining issue to `'error'`. Use in CI to fail on warnings too. |
85
+ | `max` | Truncates the returned list to the first N issues (after sorting). Useful for inline diagnostics. |
86
+ | `severityOverrides` | Per-**rule-category** severity override. Keys are rule-category codes (see below), not individual codes. |
87
+
88
+ ### ValidationError shape
89
+
90
+ ```ts
91
+ type ValidationError = {
92
+ code: string; // domain code — see catalogue below
93
+ message: string; // human-readable description
94
+ path: (string | number)[]; // path to the offending value, e.g. ['interactions', 0, 'effects', 0]
95
+ severity: 'error' | 'warning';
96
+ hint?: string; // optional remediation hint (reserved; not currently populated)
97
+ };
98
+ ```
99
+
100
+ ### InteractValidationError
101
+
102
+ ```ts
103
+ import { InteractValidationError } from '@wix/interact-validate';
104
+
105
+ try {
106
+ assertValidInteractConfig(untrusted);
107
+ } catch (err) {
108
+ if (err instanceof InteractValidationError) {
109
+ console.error(err.errors); // ValidationError[]
110
+ }
111
+ }
112
+ ```
113
+
114
+ **Rules:**
115
+
116
+ - `.name` is `'InteractValidationError'`.
117
+ - `.message` is `'Interact config validation failed with N issue(s).'`
118
+ - `.errors` is the same array `validateInteractConfig` would return.
119
+
120
+ ---
121
+
122
+ ## Severity, strict, and overrides
123
+
124
+ Severity is one of `'error' | 'warning'`. There are exactly two levers:
125
+
126
+ 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 three categories are registered and overridable:
128
+
129
+ | Rule category | Covers codes | Default severity |
130
+ | ----------------------- | ------------------------------------------------------ | ---------------- |
131
+ | `UNUSED_DEFINITION` | `UNUSED_EFFECT`, `UNUSED_SEQUENCE`, `UNUSED_CONDITION` | warning |
132
+ | `UNIQUE_DEFINITION_IDS` | `DUPLICATE_KEYFRAME_NAME` | warning |
133
+ | `VALID_MEDIA_QUERIES` | `INVALID_MEDIA_QUERY` | error |
134
+
135
+ For each category, set `'off'` to drop those issues entirely, `'warning'` / `'error'` to set their severity:
136
+
137
+ ```ts
138
+ validateInteractConfig(config, {
139
+ severityOverrides: {
140
+ UNUSED_DEFINITION: 'off', // silence dead-config hygiene warnings
141
+ VALID_MEDIA_QUERIES: 'warning', // demote bad media-query syntax from error to warning
142
+ },
143
+ });
144
+ ```
145
+
146
+ **Important:** all other codes (every `SCHEMA_*`, numeric, effect-source, and referential code) are **not** in a rule category and therefore **cannot** be silenced or re-leveled via `severityOverrides`. They are always emitted at their built-in severity (and promoted by `strict`). Precedence: `'off'` is applied first (the issue is dropped), then any `'warning'`/`'error'` override, then `strict` (which forces everything that remains to `'error'`).
147
+
148
+ ---
149
+
150
+ ## Error-code catalogue
151
+
152
+ This is the authoritative list of every code the validator emits today. Codes not listed here are not produced.
153
+
154
+ ### Structural / schema errors (severity: error)
155
+
156
+ | Code | What it flags |
157
+ | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
158
+ | `SCHEMA_INVALID_TYPE` | A field has the wrong type (e.g. `interactions` missing or not an array). |
159
+ | `SCHEMA_UNRECOGNIZED_KEYS` | Unknown keys are present — every object is `.strict()`. |
160
+ | `SCHEMA_INVALID_UNION` | A value matches no variant of a union. Covers a bad `trigger`, a trigger/effect mismatch, an effect defining more than one source inline, and an effect mixing `triggerType` with `stateAction`. |
161
+ | `SCHEMA_INVALID_LITERAL` | An invalid enum/literal value (e.g. an unknown `fill`, `composite`, `stateAction`, `triggerType`, or `RangeOffset.name`). |
162
+ | `SCHEMA_TOO_SMALL` | Below a minimum bound (e.g. empty `key`, empty `predicate`, empty `keyframes`/`effects` array). |
163
+ | `SCHEMA_INVALID` | Catch-all for any other unclassified zod issue. |
164
+
165
+ ### Numeric-bound errors (severity: error)
166
+
167
+ | Code | What it flags |
168
+ | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
169
+ | `NEGATIVE_DURATION` | `duration` is negative. |
170
+ | `NEGATIVE_DELAY` | `delay` is negative. |
171
+ | `NEGATIVE_ITERATIONS` | `iterations` is negative (or, on scroll/pointer effects, `0` / non-integer). |
172
+ | `NEGATIVE_OFFSET` | A sequence `offset` is negative. |
173
+ | `THRESHOLD_OUT_OF_RANGE` | `viewEnter` `params.threshold` is outside `[0, 1]`. |
174
+ | `ITERATIONS_INFINITY_ON_SCRUB` | `iterations: Infinity` on a `viewProgress` / `pointerMove` effect. Scrubbed effects are progress-driven, so an infinite count is invalid. (Time-based effects DO allow `Infinity`, and `0` is treated as `Infinity`.) |
175
+
176
+ ### Effect-source errors (severity: error)
177
+
178
+ | Code | What it flags |
179
+ | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
180
+ | `MULTIPLE_EFFECT_SOURCES` | An effect does not define **exactly one** of `namedEffect` / `keyframeEffect` / `customEffect` (or, after merging an `effectId` reference with its registry effect, ends up with zero or more than one source). Inline effects that violate this surface as `SCHEMA_INVALID_UNION`; this code surfaces specifically when resolving an `effectId` reference. |
181
+ | `MULTIPLE_TRANSITION_SOURCES` | A state effect does not define **exactly one** of `transition` / `transitionProperties`. Primarily surfaces when using the exported `StateEffect` schemas directly in host composition. |
182
+
183
+ ### Referential errors (severity: error)
184
+
185
+ | Code | What it flags |
186
+ | -------------------------------- | ------------------------------------------------------------------------------ |
187
+ | `EFFECT_ID_NOT_FOUND` | An effect's `effectId` references a key absent from `config.effects`. |
188
+ | `ANIMATION_END_EFFECT_NOT_FOUND` | An `animationEnd` interaction's `params.effectId` references a missing effect. |
189
+ | `SEQUENCE_ID_NOT_FOUND` | A `sequenceId` references a key absent from `config.sequences`. |
190
+ | `CONDITION_NOT_FOUND` | A `conditions[]` entry references a key absent from `config.conditions`. |
191
+
192
+ ### Other structural errors (severity: error)
193
+
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. |
198
+
199
+ ### Best-practice warnings (severity: warning)
200
+
201
+ | Code | What it flags | Rule category |
202
+ | ------------------------- | ---------------------------------------------------------------------------- | ----------------------- |
203
+ | `UNUSED_EFFECT` | A `config.effects` entry is defined but never referenced by any interaction. | `UNUSED_DEFINITION` |
204
+ | `UNUSED_SEQUENCE` | A `config.sequences` entry is defined but never referenced. | `UNUSED_DEFINITION` |
205
+ | `UNUSED_CONDITION` | A `config.conditions` entry is defined but never referenced. | `UNUSED_DEFINITION` |
206
+ | `DUPLICATE_KEYFRAME_NAME` | A `keyframeEffect.name` is reused across effects in the same config. | `UNIQUE_DEFINITION_IDS` |
207
+
208
+ ---
209
+
210
+ ## Zod schema exports
211
+
212
+ The package re-exports its zod schemas so host projects can compose their own schemas:
213
+
214
+ ```ts
215
+ import {
216
+ InteractConfigSchema,
217
+ Interaction,
218
+ TriggerType,
219
+ ViewEnterParams,
220
+ PointerMoveParams,
221
+ AnimationEndParams,
222
+ TriggerParams,
223
+ Effect,
224
+ EffectRef,
225
+ EffectSource,
226
+ TimeEffect,
227
+ NamedEffect,
228
+ SequenceConfig,
229
+ SequenceConfigRef,
230
+ Keyframe,
231
+ LengthPercentage,
232
+ RangeOffset,
233
+ Condition,
234
+ } from '@wix/interact-validate';
235
+ import { z } from 'zod';
236
+
237
+ const ExperienceSchema = z.object({
238
+ version: z.string(),
239
+ interact: InteractConfigSchema,
240
+ });
241
+ ```
242
+
243
+ **Rules:**
244
+
245
+ - `InteractConfigSchema` is `.strict()` — unrecognized top-level keys produce `SCHEMA_UNRECOGNIZED_KEYS`.
246
+ - `InteractConfigSchema` carries a `.transform()`, so a successful `.parse()` returns the config augmented with an internal `warnings` array; `validateInteractConfig` consumes that for you.
247
+ - `customEffect` and function-valued `offsetEasing` are accepted as opaque functions (`z.custom<Function>`) — they are not deep-validated, so JS-authored configs with function fields validate correctly.
248
+
249
+ ---
250
+
251
+ ## Generation guidance for agents
252
+
253
+ - After generating a config, run `validateInteractConfig(config)` and **fix every `error`** before emitting. Prefer to fix `warning`s too.
254
+ - For a hard gate, use `assertValidInteractConfig(config)` or `validateInteractConfig(config, { strict: true })`.
255
+ - 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, and pre-render CSS with `generate(config)`. See [full-lean.md](https://wix.github.io/interact/rules/full-lean.md).
256
+
257
+ ---
258
+
259
+ ## Limitations — what is NOT checked
260
+
261
+ The validator is **static**. It cannot see the DOM, the browser, or the preset registry, so the following are out of scope — keep applying the trigger rule files for these:
262
+
263
+ - **DOM-dependent issues** — element existence for a `key`/`selector`, `overflow: hidden` ancestors breaking `viewProgress`, `pointer-events: none` on a source, `:first-child` presence.
264
+ - **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
+ - **Documented authoring pitfalls with no static signal**, which the trigger rule files cover instead:
266
+ - Same source+target on `viewEnter` with a non-`once` `triggerType` → [viewenter.md](https://wix.github.io/interact/rules/viewenter.md).
267
+ - Hit-area shift from animating size/position on `hover` / `pointerMove` → [hover.md](https://wix.github.io/interact/rules/hover.md), [pointermove.md](https://wix.github.io/interact/rules/pointermove.md).
268
+ - Scroll presets needing a `range` / `rangeStart` / `rangeEnd` → [viewprogress.md](https://wix.github.io/interact/rules/viewprogress.md).
269
+ - `fill: 'both'` recommendations for `alternate` / `repeat` / `state` → [full-lean.md](https://wix.github.io/interact/rules/full-lean.md).
270
+
271
+ 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).
@@ -21,14 +21,9 @@ 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:** Two things are required — **both** MUST be present for FOUC prevention to work:
24
+ **Solution:** Call `generate(config, useFirstChild)` server-side or at build time and inject the resulting CSS into the document `<head>` (or at the beginning of `<body>`) so it loads before the page content is painted. Among all the CSS it produces, `generate()` includes initial rules that hide entrance-animated elements from the moment the page renders, before JavaScript runs. The rules use `:not([data-interact-enter])` so elements become visible once the animation starts.
25
25
 
26
- 1. **Generate CSS** using `generate(config)` — among all the CSS it produces, it includes initial rules that hide entrance-animated elements from the moment the page renders, before JavaScript runs.
27
- 2. **Mark elements with `initial`** — set `data-interact-initial="true"` on `<interact-element>`, or `initial={true}` on the `<Interaction>` React component. This tells the runtime which elements have critical CSS applied.
28
-
29
- If only one of these is present, FOUC prevention will **not** work. Both the CSS and the `initial` attribute are required.
30
-
31
- ### Step 1: Generate CSS and inject into `<head>` (preferred), or beginning of `<body>`
26
+ ### Generate CSS and inject into `<head>` (preferred), or beginning of `<body>`
32
27
 
33
28
  Call `generate(config)` server-side or at build time. Inject the resulting CSS into the document `<head>` (or in `<body>` before your content) so it loads before the page content is painted:
34
29
 
@@ -51,7 +46,7 @@ const config: InteractConfig = {
51
46
  ],
52
47
  };
53
48
 
54
- const css = generate(config);
49
+ const css = generate(config, useFirstChild);
55
50
  ```
56
51
 
57
52
  **Append to `<head>` or beginning of `<body>`:**
@@ -62,36 +57,12 @@ const css = generate(config);
62
57
  </style>
63
58
  ```
64
59
 
65
- ### Step 2: Mark elements with `initial`
66
-
67
- **Web (Custom Elements):**
68
-
69
- ```html
70
- <interact-element data-interact-key="[SOURCE_KEY]" data-interact-initial="true">
71
- <section>...</section>
72
- </interact-element>
73
- ```
74
-
75
- **React:**
76
-
77
- ```tsx
78
- <Interaction tagName="section" interactKey="[SOURCE_KEY]" initial={true}>
79
- ...
80
- </Interaction>
81
- ```
82
-
83
- **Vanilla:**
84
-
85
- ```html
86
- <section data-interact-key="[SOURCE_KEY]" data-interact-initial="true">...</section>
87
- ```
88
-
89
60
  ### Rules
90
61
 
91
62
  - `generate()` should be called server-side or at build time. Can also be called on the client if the page content is initially hidden (e.g. behind a loader/splash screen).
92
- - `initial` is only valid for `viewEnter` + `triggerType: 'once'` (or no `triggerType`, which defaults to `'once'`) where source and target are the same element.
93
- - Do NOT use `initial` for `viewEnter` with `triggerType: 'repeat'`/`'alternate'`/`'state'`. For those, manually apply the initial keyframe as inline styles on the target element and use `fill: 'both'`.
94
- - `generate(config)` processes all interactions in the config, not just `viewEnter`. Set `initial` only on the relevant `viewEnter` + `triggerType: 'once'` elements.
63
+ - 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
+ - For `viewEnter` with `triggerType: 'repeat'`/`'alternate'`/`'state'`, manually apply the starting keyframe as inline styles on the target element and use `fill: 'both'`.
65
+ - `generate(config)` processes all interactions in the config, not just `viewEnter`.
95
66
 
96
67
  ## Rule 1: keyframeEffect / namedEffect (TimeEffect)
97
68
 
@@ -191,6 +191,6 @@ Inject the resulting CSS into `<head>` so scroll-driven animations are ready bef
191
191
  - **No DOM references needed.** CSS attribute selectors (`[data-interact-key]`) bind to elements reactively as they appear in the DOM. No `querySelector`, no cached references, no lifecycle management.
192
192
  - **Instant first paint.** Animations work as soon as CSS is parsed, before JS loads or hydrates.
193
193
 
194
- No `initial` attribute is needed for scroll-driven animations — unlike `viewEnter` FOUC prevention, there is no flash-of-content concern since the animation is continuously driven by scroll position.
194
+ Scroll-driven animations do not need separate FOUC prevention — unlike `viewEnter` entrances, there is no flash-of-content concern since the animation is continuously driven by scroll position.
195
195
 
196
196
  > **Note:** `generate()` processes all interactions in the config, not just `viewProgress`. If your config also includes `viewEnter`, `hover`, `click`, or other triggers, CSS for those is generated too.