@wix/interact 2.4.0 → 2.5.0
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 +3 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/react.js +1 -1
- package/dist/cjs/web.js +1 -1
- package/dist/es/index.js +1 -1
- package/dist/es/react.js +2 -2
- package/dist/es/web.js +2 -2
- package/dist/{index-C6u4q815.mjs → index-C79XXItl.mjs} +231 -218
- package/dist/index-C79XXItl.mjs.map +1 -0
- package/dist/{index-Qg46rn0Y.js → index-CVJ6Iq9s.js} +8 -8
- package/dist/index-CVJ6Iq9s.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/core/css.d.ts.map +1 -1
- package/dist/types/core/cssUtils.d.ts.map +1 -1
- package/dist/types/core/resolvers.d.ts.map +1 -1
- package/dist/types/handlers/index.d.ts.map +1 -1
- package/dist/types/types/config.d.ts +1 -1
- package/dist/types/types/config.d.ts.map +1 -1
- package/dist/types/types/css.d.ts +1 -1
- package/dist/types/types/css.d.ts.map +1 -1
- package/dist/types/types/external.d.ts +1 -1
- package/dist/types/types/external.d.ts.map +1 -1
- package/dist/types/types/handlers.d.ts +0 -1
- package/dist/types/types/handlers.d.ts.map +1 -1
- package/dist/types/types/triggers.d.ts +1 -1
- package/dist/types/types/triggers.d.ts.map +1 -1
- package/docs/README.md +1 -0
- package/docs/api/README.md +7 -0
- package/docs/api/types.md +2 -3
- package/docs/guides/README.md +1 -1
- package/docs/guides/configuration-structure.md +1 -1
- package/docs/guides/state-management.md +0 -41
- package/package.json +1 -1
- package/rules/full-lean.md +3 -3
- package/rules/integration.md +2 -2
- package/rules/validate.md +271 -0
- package/dist/index-C6u4q815.mjs.map +0 -1
- package/dist/index-Qg46rn0Y.js.map +0 -1
|
@@ -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).
|