@wix/interact 2.5.5 → 2.5.6
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 +1 -1
- 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-7fvAL10J.mjs → index-CEt49C5d.mjs} +1241 -1107
- package/dist/index-CEt49C5d.mjs.map +1 -0
- package/dist/index-CxaQDD-U.js +21 -0
- package/dist/index-CxaQDD-U.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/core/Interact.d.ts +10 -1
- package/dist/types/core/Interact.d.ts.map +1 -1
- package/dist/types/core/InteractionController.d.ts +3 -1
- package/dist/types/core/InteractionController.d.ts.map +1 -1
- package/dist/types/core/add.d.ts.map +1 -1
- package/dist/types/core/css.d.ts +12 -4
- package/dist/types/core/css.d.ts.map +1 -1
- package/dist/types/core/cssUtils.d.ts.map +1 -1
- package/dist/types/types/config.d.ts +2 -1
- package/dist/types/types/config.d.ts.map +1 -1
- package/dist/types/types/controller.d.ts +5 -0
- package/dist/types/types/controller.d.ts.map +1 -1
- package/dist/types/types/css.d.ts +15 -1
- package/dist/types/types/css.d.ts.map +1 -1
- package/dist/types/types/effects.d.ts +2 -1
- package/dist/types/types/effects.d.ts.map +1 -1
- package/dist/types/types/external.d.ts +2 -0
- package/dist/types/types/external.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/plugins.d.ts +81 -0
- package/dist/types/types/plugins.d.ts.map +1 -0
- package/dist/types/utils.d.ts +7 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/docs/api/README.md +1 -1
- package/docs/api/functions.md +16 -8
- package/docs/api/interact-class.md +35 -0
- package/docs/api/types.md +93 -1
- package/docs/guides/README.md +4 -0
- package/docs/guides/configuration-structure.md +2 -0
- package/docs/guides/plugins.md +192 -0
- package/package.json +2 -2
- package/rules/click.md +2 -2
- package/rules/full-lean.md +57 -11
- package/rules/hover.md +2 -2
- package/rules/integration.md +11 -11
- package/rules/plugins.md +122 -0
- package/rules/validate.md +4 -3
- package/rules/viewenter.md +1 -1
- package/rules/viewprogress.md +1 -1
- package/dist/index-7fvAL10J.mjs.map +0 -1
- package/dist/index-C4A3nFix.js +0 -21
- package/dist/index-C4A3nFix.js.map +0 -1
package/rules/integration.md
CHANGED
|
@@ -273,7 +273,7 @@ Define reusable sequences in `InteractConfig.sequences` and reference by `sequen
|
|
|
273
273
|
|
|
274
274
|
## CSS Generation & FOUC Prevention
|
|
275
275
|
|
|
276
|
-
`generate(config,
|
|
276
|
+
`generate(config, options?)` 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
277
|
|
|
278
278
|
**Static site policy:** For static or pre-rendered HTML (agent-generated pages,
|
|
279
279
|
SSG, static export), prefer calling `generate()` for the complete config at
|
|
@@ -284,7 +284,7 @@ browser before its `Interact.create()` call. If splitting is impractical,
|
|
|
284
284
|
generating the complete CSS at runtime is an acceptable fallback. Call
|
|
285
285
|
`registerEffects()` before each `generate()` when using `namedEffect`.
|
|
286
286
|
|
|
287
|
-
The `useFirstChild`
|
|
287
|
+
The `useFirstChild` option tells Interact whether to render `:first-child` selectors for custom-element (`web`) integration: `true` for **web**, `false` for **react** and **vanilla**. Pass it either as a bare boolean (`generate(config, true)`) or in the options bag (`generate(config, { useFirstChild: true })`) — the bag is also where `plugins` goes.
|
|
288
288
|
|
|
289
289
|
```javascript
|
|
290
290
|
import { generate } from '@wix/interact/web';
|
|
@@ -344,12 +344,12 @@ See [viewenter.md](./viewenter.md) for full details.
|
|
|
344
344
|
|
|
345
345
|
Each `Interact.create(config)` call returns an instance. Keep a reference if you need to add/remove elements dynamically (vanilla JS) or to destroy a specific instance. Call `Interact.destroy()` to tear down all instances at once (e.g. on page navigation).
|
|
346
346
|
|
|
347
|
-
| Method / Property | Description
|
|
348
|
-
| :---------------------------------- |
|
|
349
|
-
| `generate(config,
|
|
350
|
-
| `Interact.create(config)` | Initialize with a config. Returns the instance. Multiple configs create separate instances.
|
|
351
|
-
| `Interact.registerEffects(presets)` | Register named effect presets before `generate()` and `create`. Required for `namedEffect`.
|
|
352
|
-
| `Interact.destroy()` | Tear down all instances.
|
|
353
|
-
| `Interact.forceReducedMotion` | `boolean` — force reduced-motion behavior regardless of OS setting. Default: `false`.
|
|
354
|
-
| `Interact.allowA11yTriggers` | `boolean` — enable accessibility triggers (`interest`, `activate`). Default: `false`.
|
|
355
|
-
| `Interact.setup(options)` | Configure global defaults for scroll/pointer/viewEnter trigger params. Call before `create`.
|
|
347
|
+
| Method / Property | Description |
|
|
348
|
+
| :---------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
349
|
+
| `generate(config, options?)` | Produce complete CSS for all interactions. Call at build/generation time; embed in HTML. `options` = `{ useFirstChild?, plugins? }`, or a bare boolean for legacy `useFirstChild`. |
|
|
350
|
+
| `Interact.create(config)` | Initialize with a config. Returns the instance. Multiple configs create separate instances. |
|
|
351
|
+
| `Interact.registerEffects(presets)` | Register named effect presets before `generate()` and `create`. Required for `namedEffect`. |
|
|
352
|
+
| `Interact.destroy()` | Tear down all instances. |
|
|
353
|
+
| `Interact.forceReducedMotion` | `boolean` — force reduced-motion behavior regardless of OS setting. Default: `false`. |
|
|
354
|
+
| `Interact.allowA11yTriggers` | `boolean` — enable accessibility triggers (`interest`, `activate`). Default: `false`. |
|
|
355
|
+
| `Interact.setup(options)` | Configure global defaults for scroll/pointer/viewEnter trigger params. Call before `create`. |
|
package/rules/plugins.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# @wix/interact Plugin Rules
|
|
2
|
+
|
|
3
|
+
Rules for extending `@wix/interact` with external plugins via `Interact.use()` and `$`-prefixed config fields.
|
|
4
|
+
|
|
5
|
+
## Model
|
|
6
|
+
|
|
7
|
+
Interact is a **generic bridge**. It knows a plugin only by the name it was registered under. When an interaction or effect carries a field named `$<name>`, Interact passes that field's value to the matching plugin and (optionally) stores a cleanup. Interact never inspects what the plugin does.
|
|
8
|
+
|
|
9
|
+
- `@wix/interact` has **no** plugin-specific code and does **not** depend on any plugin package.
|
|
10
|
+
- A plugin package (e.g. `@wix/splittext`) does **not** depend on `@wix/interact`.
|
|
11
|
+
- A plugin package MAY still ship a ready-made adapter (e.g. `@wix/splittext/plugin`), typed _structurally_ against the contract below so it stays assignable to `InteractPlugin` without importing Interact. Prefer the shipped adapter over hand-rolling one.
|
|
12
|
+
- Only the **typing** glue lives in your app — the declaration merge on `InteractPluginConfigMap` (see [Config placement](#config-placement)).
|
|
13
|
+
|
|
14
|
+
## Registration
|
|
15
|
+
|
|
16
|
+
Register before `Interact.create()`:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
Interact.use('<plugin-name>', (value, context) => {
|
|
20
|
+
// value: the value of the `$<plugin-name>` field
|
|
21
|
+
// context: { root, key, scope: 'interaction' | 'effect', config }
|
|
22
|
+
// return: optional cleanup () => void, run on disconnect/teardown
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
- `Interact.getPlugin(name) / Interact.getPluginsNames()` inspect the registry.
|
|
27
|
+
|
|
28
|
+
## Config placement
|
|
29
|
+
|
|
30
|
+
Add a `$<plugin-name>` field on an **interaction** or an **effect**:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
{
|
|
34
|
+
key: 'hero',
|
|
35
|
+
trigger: 'viewEnter',
|
|
36
|
+
$splitText: { /* any value */ },
|
|
37
|
+
effects: [ /* ... */ ],
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Rules
|
|
42
|
+
|
|
43
|
+
- **MUST** register the plugin (`Interact.use`) before `Interact.create()`. A `$<name>` field with no registered plugin is ignored.
|
|
44
|
+
- **MUST** prefix plugin fields with `$` (e.g. `$splitText`). A non-prefixed unknown key on an interaction/effect is rejected by `@wix/interact-validate` (via `catchall` + key check). Only `$`-prefixed fields are treated as opaque, un-inspected plugin config.
|
|
45
|
+
- Use a bare, unquoted `$<name>` key — no quotes needed since `$` is a valid identifier start (e.g. `$splitText:`, not `'plugin:splitText':`).
|
|
46
|
+
- Plugins run at **connect time, before target resolution** — DOM a plugin creates is visible to the `selector` / `listContainer` queries that follow.
|
|
47
|
+
- A returned cleanup runs on disconnect, on `Interact.destroy()`, and on media-query reconnect. Use it to fully undo the plugin's work.
|
|
48
|
+
- Each distinct plugin value is applied **once per connect**, even across multiple triggers on the same element.
|
|
49
|
+
- Interaction-level fields use the interaction's element as `root`; effect-level fields use the effect's target element as `root`.
|
|
50
|
+
|
|
51
|
+
## SSR styling (FOUC prevention)
|
|
52
|
+
|
|
53
|
+
Runtime plugins mutate the DOM only after JS loads. To style the element _before_ that (e.g. hide un-split text so an entrance animation doesn't flash), pass a **separate** per-plugin callback in the `plugins` option of `generate()`'s options bag:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
const css = generate(config, {
|
|
57
|
+
useFirstChild: true,
|
|
58
|
+
plugins: {
|
|
59
|
+
myPlugin: (value, _context) => {
|
|
60
|
+
// value: the opaque `$myPlugin` value;
|
|
61
|
+
// context: { key, scope: 'interaction' | 'effect', config }
|
|
62
|
+
// return: { declarations: { name: string; value: number | string }[]; selectorSuffix?: string }[]
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
declarations: [{ name: 'visibility', value: 'hidden' }],
|
|
66
|
+
selectorSuffix: ` ${value.container ?? ''}:not([data-myplugin-ready])`,
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- If the plugin package ships its own generator, pass that instead of writing one — e.g. `splitTextStyle` from `@wix/splittext/plugin` (see the example below).
|
|
75
|
+
- This is **NOT** the callback registered via `Interact.use()` — it's a build-time styling generator.
|
|
76
|
+
- `generate()` does **not** inspect the `$<name>` value (same as `create()`); it just routes it to the generator, which returns partial CSS rule(s) data.
|
|
77
|
+
- `declarations` is an array of names and values of CSS properties to set; `selectorSuffix` is used to refine the target of the CSS rule - the resulting selector for the rule is `[data-interact-key=${key}]${selectorSuffix}`
|
|
78
|
+
- Context: `{ key, scope: 'interaction' | 'effect', config }`.
|
|
79
|
+
- Typical pattern: the runtime plugin sets a marker attribute after applying (e.g. `data-splittext-ready`), and the SSR rule hides until that marker is present.
|
|
80
|
+
|
|
81
|
+
## Example: `@wix/splittext`
|
|
82
|
+
|
|
83
|
+
Split text into `<span>`s, then target the generated spans with a normal `selector`. Default classes: `.split-c` (chars), `.split-w` (words), `.split-l` (lines), `.split-s` (sentences).
|
|
84
|
+
|
|
85
|
+
**Do NOT hand-roll this adapter.** `@wix/splittext/plugin` ships both callbacks — `splitTextPlugin` (runtime) and `splitTextStyle` (SSR) — already paired on the `data-splittext-ready` marker:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import { Interact, generate } from '@wix/interact';
|
|
89
|
+
import { splitTextPlugin, splitTextStyle } from '@wix/splittext/plugin';
|
|
90
|
+
|
|
91
|
+
const config = {
|
|
92
|
+
effects: { 'char-fade-up': { namedEffect: { type: 'FadeIn' }, duration: 400 } },
|
|
93
|
+
interactions: [
|
|
94
|
+
{
|
|
95
|
+
key: 'hero',
|
|
96
|
+
trigger: 'viewEnter',
|
|
97
|
+
// `hideUntilReady` opts into the SSR hide rule emitted by splitTextStyle
|
|
98
|
+
$splitText: { container: '.title', type: 'chars', hideUntilReady: true },
|
|
99
|
+
sequences: [{ offset: 30, effects: [{ effectId: 'char-fade-up', selector: '.split-c' }] }],
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
Interact.use('splitText', splitTextPlugin);
|
|
105
|
+
|
|
106
|
+
const css = generate(config, { useFirstChild: true, plugins: { splitText: splitTextStyle } });
|
|
107
|
+
// Embed css in HTML — see CSS Generation & FOUC Prevention
|
|
108
|
+
|
|
109
|
+
Interact.create(config);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
To type the `$splitText` field, declaration-merge in your app (the only place importing both packages):
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import type { SplitTextPluginConfig } from '@wix/splittext/plugin';
|
|
116
|
+
|
|
117
|
+
declare module '@wix/interact' {
|
|
118
|
+
interface InteractPluginConfigMap {
|
|
119
|
+
splitText: SplitTextPluginConfig;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
package/rules/validate.md
CHANGED
|
@@ -56,7 +56,7 @@ if (!result.valid) {
|
|
|
56
56
|
- `valid` is `true` when no remaining issue has severity `'error'`. **Warnings alone do not make `valid: false`.**
|
|
57
57
|
- `errors` holds **all** surfaced issues — both `'error'` and `'warning'` severities. Filter on `severity` to separate them.
|
|
58
58
|
- Issues are sorted lexicographically by `path`.
|
|
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
|
|
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` nudges, CSS property names that are neither camelCase nor kebab-case). If the structural parse fails, the semantic layer is skipped.
|
|
60
60
|
|
|
61
61
|
### assertValidInteractConfig
|
|
62
62
|
|
|
@@ -140,7 +140,7 @@ Severity is one of `'error' | 'warning'`. There are exactly two levers:
|
|
|
140
140
|
| `STATE_EFFECT` | `EMPTY_STYLE_PROPERTIES`, `STATE_REMOVE_WITHOUT_EFFECT_ID` | warning |
|
|
141
141
|
| `RECOMMENDED_FILL` | `RECOMMENDED_FILL_BOTH` | info |
|
|
142
142
|
| `POINTER_AXIS` | `POINTER_AXIS_IGNORED` | warning |
|
|
143
|
-
| `
|
|
143
|
+
| `CSS_PROPERTY_NAME` | `INVALID_CSS_PROPERTY_NAME` | warning |
|
|
144
144
|
| `VIEW_INSET` | `INVALID_INSET` | warning |
|
|
145
145
|
|
|
146
146
|
For each category, set `'off'` to drop those issues entirely, `'warning'` / `'error'` to set their severity:
|
|
@@ -235,7 +235,7 @@ Statically-detectable authoring pitfalls lifted from the trigger rule files. Eac
|
|
|
235
235
|
| `RECOMMENDED_FILL_BOTH` | A scrubbed (`viewProgress`/`pointerMove`) or toggling (`alternate`/`repeat`/`state`) effect omits `fill: 'both'`. | `RECOMMENDED_FILL` |
|
|
236
236
|
| `RECOMMENDED_FILL_BACKWARDS` | A `viewEnter` + `once` named/keyframe effect targeting another element or using a same-element delay omits `fill: 'backwards'` or `'both'`. | `RECOMMENDED_FILL` |
|
|
237
237
|
| `POINTER_AXIS_IGNORED` | `pointerMove` `params.axis` set on a `namedEffect`/`customEffect` (axis only applies to `keyframeEffect`). | `POINTER_AXIS` |
|
|
238
|
-
| `
|
|
238
|
+
| `INVALID_CSS_PROPERTY_NAME` | A keyframe or state-effect property name is neither camelCase nor kebab-case (both casings are accepted; this one cannot be normalized). | `CSS_PROPERTY_NAME` |
|
|
239
239
|
| `INVALID_INSET` | `viewEnter` `params.inset` is not 1–4 whitespace-separated CSS lengths/percentages. | `VIEW_INSET` |
|
|
240
240
|
|
|
241
241
|
---
|
|
@@ -278,6 +278,7 @@ const ExperienceSchema = z.object({
|
|
|
278
278
|
- `InteractConfigSchema` is `.strict()` — unrecognized top-level keys produce `SCHEMA_UNRECOGNIZED_KEYS`.
|
|
279
279
|
- `InteractConfigSchema` carries a `.transform()`, so a successful `.parse()` returns the config augmented with an internal `warnings` array; `validateInteractConfig` consumes that for you.
|
|
280
280
|
- `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.
|
|
281
|
+
- Interactions and effects accept `$`-prefixed plugin fields (e.g. `$splitText`) — config routed to plugins registered via `Interact.use()`. Interaction/effect schemas use `.catchall(z.unknown())` + a key check instead of `.strict()`: `$`-prefixed fields are accepted with opaque values (validate has no knowledge of any plugin's shape), while any non-prefixed unknown key is still reported as `SCHEMA_UNRECOGNIZED_KEYS` (typo detection preserved). The top-level `InteractConfigSchema` stays `.strict()`.
|
|
281
282
|
|
|
282
283
|
---
|
|
283
284
|
|
package/rules/viewenter.md
CHANGED
|
@@ -152,7 +152,7 @@ Use `keyframeEffect` or `namedEffect` when the viewEnter should play an animatio
|
|
|
152
152
|
- `'state'` — resumes on enter, pauses on leave. Useful for continuous loops (`iterations: Infinity`). Use separate source and target.
|
|
153
153
|
- `[VISIBILITY_THRESHOLD]` — optional. Number between 0–1 indicating how much of the source element must be visible to trigger (e.g. `0.3` = 30%).
|
|
154
154
|
- `[VIEWPORT_INSETS]` — optional. String adjusting the viewport detection area (e.g. `'-100px'` extends it, `'50px'` shrinks it).
|
|
155
|
-
- `[KEYFRAMES]` — array of keyframe objects (e.g. `[{ opacity: 0 }, { opacity: 1 }]`). Property names
|
|
155
|
+
- `[KEYFRAMES]` — array of keyframe objects (e.g. `[{ opacity: 0 }, { opacity: 1 }]`). Property names may be camelCase or kebab-case (both accepted); prefer camelCase, which is what WAAPI uses.
|
|
156
156
|
- `[EFFECT_NAME]` — unique string identifier for a `keyframeEffect`.
|
|
157
157
|
- `[NAMED_EFFECT_DEFINITION]` — object with properties of pre-built effect from `@wix/motion-presets`. Refer to motion-presets rules for available presets and their options.
|
|
158
158
|
- `[FILL_MODE]` — `'both'` for `triggerType: 'alternate'`, `'repeat'`, or `'state'`. For `triggerType: 'once'`: use `'backwards'` for entrance, so the first keyframe applies during any `delay` (use `'both'` when the final keyframe must persist after the animation).
|
package/rules/viewprogress.md
CHANGED
|
@@ -55,7 +55,7 @@ For static sites, pre-render CSS via `generate()` at build time — see
|
|
|
55
55
|
- `[TARGET_KEY]` — identifier matching the element's key (`data-interact-key` for web, `interactKey` for React) on the element to animate (can be same as source or different).
|
|
56
56
|
- `[NAMED_EFFECT_DEFINITION]` — object with properties of pre-built effect from `@wix/motion-presets`. **CRITICAL:** Scroll presets (`*Scroll`) MUST include `range: 'in' | 'out' | 'continuous'` in their options. `'in'` ends at the idle state, `'out'` starts from the idle state, `'continuous'` passes through it.
|
|
57
57
|
- `[EFFECT_NAME]` — unique name for custom keyframe effect.
|
|
58
|
-
- `[EFFECT_KEYFRAMES]` — array of keyframe objects defining CSS property values (e.g. `[{ opacity: 0 }, { opacity: 1 }]`). Property names
|
|
58
|
+
- `[EFFECT_KEYFRAMES]` — array of keyframe objects defining CSS property values (e.g. `[{ opacity: 0 }, { opacity: 1 }]`). Property names may be camelCase or kebab-case (both accepted); prefer camelCase, which is what WAAPI uses.
|
|
59
59
|
- `[RANGE_NAME]` — scroll range name:
|
|
60
60
|
- `'cover'` — full visibility span from first pixel entering to last pixel leaving.
|
|
61
61
|
- `'entry'` — the phase while the element is entering the viewport.
|