@wix/interact 2.5.0 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/rules/validate.md CHANGED
@@ -55,7 +55,7 @@ if (!result.valid) {
55
55
  - `valid` is `true` when no remaining issue has severity `'error'`. **Warnings alone do not make `valid: false`.**
56
56
  - `errors` holds **all** surfaced issues — both `'error'` and `'warning'` severities. Filter on `severity` to separate them.
57
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.
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, 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
59
 
60
60
  ### assertValidInteractConfig
61
61
 
@@ -124,13 +124,23 @@ try {
124
124
  Severity is one of `'error' | 'warning'`. There are exactly two levers:
125
125
 
126
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 |
127
+ 2. **`severityOverrides`** — keyed by **rule category**, not by individual code. Only the following 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
+ | `SAME_ELEMENT_RETRIGGER` | `SAME_ELEMENT_RETRIGGER` | warning |
135
+ | `HIT_AREA_SHIFT` | `HIT_AREA_SHIFT` | warning |
136
+ | `SCROLL_RANGE` | `SCROLL_PRESET_MISSING_RANGE`, `SCROLL_PRESET_BAD_RANGE` | warning |
137
+ | `ANIMATION_END_GRAPH` | `ANIMATION_END_SELF_REFERENCE`, `ANIMATION_END_CYCLE` | warning |
138
+ | `ELEMENT_SELECTION` | `LIST_ITEM_SELECTOR_WITHOUT_CONTAINER`, `REDUNDANT_SELECTOR_WITH_LIST_ITEM` | warning |
139
+ | `STATE_EFFECT` | `EMPTY_STYLE_PROPERTIES`, `STATE_REMOVE_WITHOUT_EFFECT_ID` | warning |
140
+ | `RECOMMENDED_FILL` | `RECOMMENDED_FILL_BOTH` | info |
141
+ | `POINTER_AXIS` | `POINTER_AXIS_IGNORED` | warning |
142
+ | `KEYFRAME_STYLE` | `KEYFRAME_PROP_NOT_CAMEL_CASE` | warning |
143
+ | `VIEW_INSET` | `INVALID_INSET` | warning |
134
144
 
135
145
  For each category, set `'off'` to drop those issues entirely, `'warning'` / `'error'` to set their severity:
136
146
 
@@ -184,17 +194,17 @@ This is the authoritative list of every code the validator emits today. Codes no
184
194
 
185
195
  | Code | What it flags |
186
196
  | -------------------------------- | ------------------------------------------------------------------------------ |
187
- | `EFFECT_ID_NOT_FOUND` | An effect's `effectId` references a key absent from `config.effects`. |
188
197
  | `ANIMATION_END_EFFECT_NOT_FOUND` | An `animationEnd` interaction's `params.effectId` references a missing effect. |
189
198
  | `SEQUENCE_ID_NOT_FOUND` | A `sequenceId` references a key absent from `config.sequences`. |
190
199
  | `CONDITION_NOT_FOUND` | A `conditions[]` entry references a key absent from `config.conditions`. |
191
200
 
192
201
  ### Other structural errors (severity: error)
193
202
 
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. |
203
+ | Code | What it flags |
204
+ | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
205
+ | `INTERACTION_EMPTY` | An interaction has neither `effects` nor `sequences`. (`viewProgress`/`pointerMove` require a non-empty `effects` array and instead surface `SCHEMA_TOO_SMALL`.) |
206
+ | `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. |
207
+ | `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
208
 
199
209
  ### Best-practice warnings (severity: warning)
200
210
 
@@ -204,6 +214,27 @@ This is the authoritative list of every code the validator emits today. Codes no
204
214
  | `UNUSED_SEQUENCE` | A `config.sequences` entry is defined but never referenced. | `UNUSED_DEFINITION` |
205
215
  | `UNUSED_CONDITION` | A `config.conditions` entry is defined but never referenced. | `UNUSED_DEFINITION` |
206
216
  | `DUPLICATE_KEYFRAME_NAME` | A `keyframeEffect.name` is reused across effects in the same config. | `UNIQUE_DEFINITION_IDS` |
217
+ | `EFFECT_ID_NOT_FOUND` | An effect's `effectId` references a key absent from `config.effects`. | `ID_NOT_FOUND` |
218
+
219
+ ### Rule-derived semantic warnings (severity: warning)
220
+
221
+ 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`.
222
+
223
+ | Code | What it flags | Rule category |
224
+ | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
225
+ | `SAME_ELEMENT_RETRIGGER` | `viewEnter` with `triggerType` `repeat`/`alternate`/`state` on the same source+target element (re-trigger loop). | `SAME_ELEMENT_RETRIGGER` |
226
+ | `HIT_AREA_SHIFT` | `hover`/`click`/`interest`/`activate`/`pointerMove` `keyframeEffect` with a `translate`/`scale`/`matrix` transform on the same source+target element. | `HIT_AREA_SHIFT` |
227
+ | `SCROLL_PRESET_MISSING_RANGE` | A `*Scroll` `namedEffect` on `viewProgress` omits `range`. | `SCROLL_RANGE` |
228
+ | `SCROLL_PRESET_BAD_RANGE` | A scroll preset `range` is not `'in'`/`'out'`/`'continuous'`. | `SCROLL_RANGE` |
229
+ | `ANIMATION_END_SELF_REFERENCE` | An `animationEnd` interaction waits for an effect it also produces → it can never start. | `ANIMATION_END_GRAPH` |
230
+ | `LIST_ITEM_SELECTOR_WITHOUT_CONTAINER` | `listItemSelector` present without `listContainer` (inert) — on an interaction or an effect. | `ELEMENT_SELECTION` |
231
+ | `REDUNDANT_SELECTOR_WITH_LIST_ITEM` | `selector` is ignored when both `listContainer` and `listItemSelector` are present. | `ELEMENT_SELECTION` |
232
+ | `EMPTY_STYLE_PROPERTIES` | A state effect's `transition.styleProperties` / `transitionProperties` is `[]` (toggles nothing). | `STATE_EFFECT` |
233
+ | `STATE_REMOVE_WITHOUT_EFFECT_ID` | `stateAction: 'remove'` with no `effectId` to pair with a matching `'add'`. | `STATE_EFFECT` |
234
+ | `RECOMMENDED_FILL_BOTH` | A scrubbed (`viewProgress`/`pointerMove`) or toggling (`alternate`/`repeat`/`state`) effect omits `fill: 'both'`. | `RECOMMENDED_FILL` |
235
+ | `POINTER_AXIS_IGNORED` | `pointerMove` `params.axis` set on a `namedEffect`/`customEffect` (axis only applies to `keyframeEffect`). | `POINTER_AXIS` |
236
+ | `KEYFRAME_PROP_NOT_CAMEL_CASE` | A `keyframeEffect` property name is kebab-case (not WAAPI camelCase). | `KEYFRAME_STYLE` |
237
+ | `INVALID_INSET` | `viewEnter` `params.inset` is not 1–4 whitespace-separated CSS lengths/percentages. | `VIEW_INSET` |
207
238
 
208
239
  ---
209
240
 
@@ -263,9 +294,10 @@ The validator is **static**. It cannot see the DOM, the browser, or the preset r
263
294
  - **DOM-dependent issues** — element existence for a `key`/`selector`, `overflow: hidden` ancestors breaking `viewProgress`, `pointer-events: none` on a source, `:first-child` presence.
264
295
  - **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
296
  - **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).
297
+ - `overflow: hidden` ancestors breaking `viewProgress` → [viewprogress.md](https://wix.github.io/interact/rules/viewprogress.md).
298
+ - 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`.
299
+ - Reduced-motion alternatives, perspective usage, and other authoring guidance with no static signal.
300
+
301
+ > **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
302
 
271
303
  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.