@wix/interact 2.5.4 → 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-CfagoYAR.mjs → index-CEt49C5d.mjs} +1246 -1112
- 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 +19 -6
- 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 +16 -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 +23 -13
- package/docs/api/interact-class.md +35 -0
- package/docs/api/types.md +93 -1
- package/docs/examples/entrance-animations.md +1 -0
- 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 +58 -12
- package/rules/hover.md +2 -2
- package/rules/integration.md +11 -11
- package/rules/plugins.md +122 -0
- package/rules/validate.md +5 -3
- package/rules/viewenter.md +5 -2
- package/rules/viewprogress.md +1 -1
- package/dist/index-CfagoYAR.mjs.map +0 -1
- package/dist/index-DdqUOFMC.js +0 -21
- package/dist/index-DdqUOFMC.js.map +0 -1
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Condition, CreateTransitionCSSParams, StateEffect } from './types';
|
|
1
|
+
import type { Condition, CreateTransitionCSSParams, StateEffect, StyleProperty } from './types';
|
|
2
2
|
export declare function roundNumber(num: number, precision?: number): number;
|
|
3
3
|
export declare function isTemplatedKey(key: string): boolean;
|
|
4
4
|
export declare function kebabCustomProp(args: (string | number)[]): string;
|
|
@@ -13,6 +13,12 @@ export declare function calculateSequenceEffectsOffsets(effects: ((any & {
|
|
|
13
13
|
*/
|
|
14
14
|
export declare function applySelectorCondition(baseSelector: string, predicate: string): string;
|
|
15
15
|
export declare function generateId(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the style properties of a state effect - `transition.styleProperties` wins
|
|
18
|
+
* when both are set - with property names normalized to the kebab-case form CSS expects.
|
|
19
|
+
* Property names may be authored in either camelCase or kebab-case.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getStateStyleProperties(transitionEffect: Pick<StateEffect, 'transition' | 'transitionProperties'>): StyleProperty[];
|
|
16
22
|
export declare function transitionEffectToTransitionsList(transitionEffect: StateEffect): string[];
|
|
17
23
|
export declare function createTransitionCSS({ key, effectId, transition, transitionProperties, childSelector, selectorCondition, }: CreateTransitionCSSParams): string[];
|
|
18
24
|
export declare function getFullPredicateByType(conditionNames: string[] | undefined, conditions: Record<string, Condition>, type: 'media' | 'container'): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAyB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEhG,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,MAAM,CAE9D;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,WAEzC;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,UAExD;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,CAAC,CAAC,GAAG,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAC9C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAClC,IAAI,CASN;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAKtF;AAED,wBAAgB,UAAU,WAQzB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,gBAAgB,EAAE,IAAI,CAAC,WAAW,EAAE,YAAY,GAAG,sBAAsB,CAAC,GACzE,aAAa,EAAE,CAQjB;AAED,wBAAgB,iCAAiC,CAAC,gBAAgB,EAAE,WAAW,YAwC9E;AAID,wBAAgB,mBAAmB,CAAC,EAClC,GAAG,EACH,QAAQ,EACR,UAAU,EACV,oBAAoB,EACpB,aAAgC,EAChC,iBAAiB,GAClB,EAAE,yBAAyB,GAAG,MAAM,EAAE,CAyCtC;AAED,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,MAAM,EAAE,GAAG,SAAS,EACpC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EACrC,IAAI,EAAE,OAAO,GAAG,WAAW,UAY5B;AAED,wBAAgB,aAAa,CAC3B,cAAc,EAAE,MAAM,EAAE,GAAG,SAAS,EACpC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,uBAMtC;AAED,wBAAgB,oBAAoB,CAClC,cAAc,EAAE,MAAM,EAAE,GAAG,SAAS,EACpC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GACpC,MAAM,GAAG,SAAS,CASpB"}
|
package/docs/api/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Complete reference documentation for all public APIs in `@wix/interact`.
|
|
|
18
18
|
- [Error handling](functions.md#error-handling) and [performance considerations](functions.md#performance-considerations)
|
|
19
19
|
- [**remove(path)**](functions.md#remove) - Remove interactions from an element
|
|
20
20
|
- [Cleanup behavior](functions.md#behavior-details) and [advanced usage](functions.md#advanced-usage)
|
|
21
|
-
- [**generate(config,
|
|
21
|
+
- [**generate(config, options?)**](functions.md#generate) - Generate complete CSS for all animations, transitions, scroll-driven effects, and FOUC prevention
|
|
22
22
|
- [What it generates](functions.md#what-it-generates), [benefits](functions.md#benefits), and [use cases](functions.md#use-cases)
|
|
23
23
|
- [FOUC prevention](functions.md#fouc-prevention-viewenter), [scroll-driven CSS](functions.md#scroll-driven-css-viewprogress), and [SSR](functions.md#server-side-rendering-ssr)
|
|
24
24
|
- [**addListItems(root, key, listContainer, elements)**](functions.md#addlistitems) - Add interactions to new list items
|
package/docs/api/functions.md
CHANGED
|
@@ -12,11 +12,11 @@ import { add, remove, generate } from '@wix/interact';
|
|
|
12
12
|
|
|
13
13
|
## Functions Overview
|
|
14
14
|
|
|
15
|
-
| Function | Purpose | Parameters
|
|
16
|
-
| ------------ | -------------------------------------------------------------------------------- |
|
|
17
|
-
| `add()` | Add interactions to an element | `element`, `key?`
|
|
18
|
-
| `remove()` | Remove interactions from an element | `key`
|
|
19
|
-
| `generate()` | Generate complete CSS for all animations, transitions, and scroll-driven effects | `config`, `useFirstChild?` | `string` |
|
|
15
|
+
| Function | Purpose | Parameters | Returns |
|
|
16
|
+
| ------------ | -------------------------------------------------------------------------------- | -------------------------------------- | -------- |
|
|
17
|
+
| `add()` | Add interactions to an element | `element`, `key?` | `void` |
|
|
18
|
+
| `remove()` | Remove interactions from an element | `key` | `void` |
|
|
19
|
+
| `generate()` | Generate complete CSS for all animations, transitions, and scroll-driven effects | `config`, `useFirstChild?`, `plugins?` | `string` |
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
@@ -196,21 +196,29 @@ console.log('Interactions removed for hero');
|
|
|
196
196
|
|
|
197
197
|
---
|
|
198
198
|
|
|
199
|
-
## `generate(config,
|
|
199
|
+
## `generate(config, options?)`
|
|
200
200
|
|
|
201
201
|
Generates a complete CSS string from an `InteractConfig`. The output includes `@keyframes`, animation and transition custom properties, view-timeline declarations, state-selector rules, coordinated-list aggregation, and FOUC-prevention initial rules — everything the browser needs to run the configured animations and transitions natively, without waiting for JavaScript.
|
|
202
202
|
|
|
203
203
|
### Signature
|
|
204
204
|
|
|
205
205
|
```typescript
|
|
206
|
-
function generate(config: InteractConfig,
|
|
206
|
+
function generate(config: InteractConfig, options?: boolean | GenerateOptions): string;
|
|
207
|
+
|
|
208
|
+
type GenerateOptions = {
|
|
209
|
+
useFirstChild?: boolean;
|
|
210
|
+
plugins?: InteractPluginStyles;
|
|
211
|
+
};
|
|
207
212
|
```
|
|
208
213
|
|
|
209
214
|
### Parameters
|
|
210
215
|
|
|
211
216
|
**`config: InteractConfig`** - The full interaction configuration. Every interaction in the config is processed — not just `viewEnter`.
|
|
212
217
|
|
|
213
|
-
**`
|
|
218
|
+
**`options?: boolean | GenerateOptions`** - Either an options object or — for backwards compatibility — a bare boolean used as `useFirstChild` (`generate(config, false)` ≡ `generate(config, { useFirstChild: false })`).
|
|
219
|
+
|
|
220
|
+
- **`useFirstChild?: boolean`** - When `true` (the default), generated selectors target the first child of each keyed element (e.g. `[data-interact-key="hero"] > :first-child`). This is the correct mode for `<interact-element>` custom elements. Pass `false` when the keyed element itself is the animation target (vanilla JS or React `<Interaction>`).
|
|
221
|
+
- **`plugins?: InteractPluginStyles`** - Optional map of plugin name → SSR style generator. For every `$<name>` field in the config, the matching generator is called with the field's (opaque) value and a context, and its returned CSS data is appended to the output. Used to emit build-time styling on a plugin's behalf — e.g. hiding pre-split text for FOUC prevention. Like `create()`/`use()`, `generate()` never inspects the field value. See [Plugins → SSR styling](../guides/plugins.md#ssr-styling-foouc-prevention).
|
|
214
222
|
|
|
215
223
|
### Returns
|
|
216
224
|
|
|
@@ -247,7 +255,9 @@ The output covers every CSS-expressible aspect of the configuration:
|
|
|
247
255
|
|
|
248
256
|
For entrance animations where the source and target are the same element, `generate()` emits an initial rule that hides the element until its animation starts. Inject the generated CSS into `<head>` (preferred) or the beginning of `<body>`.
|
|
249
257
|
|
|
250
|
-
The initial rule uses `:not([data-interact-enter])` so the element becomes visible once the animation begins. This only applies to `viewEnter` interactions with `triggerType: 'once'` (the default for `viewEnter`)
|
|
258
|
+
The initial rule uses `:not([data-interact-enter])` so the element becomes visible once the animation begins. This only applies to `viewEnter` interactions with `triggerType: 'once'` (the default for `viewEnter`)
|
|
259
|
+
|
|
260
|
+
For any entrance animation, use `fill: 'backwards'` (or `'both'` when the final keyframe must persist). Entrance presets default to `backwards`.
|
|
251
261
|
|
|
252
262
|
For `triggerType: 'repeat'`/`'alternate'`/`'state'`, manually apply the starting keyframe as inline styles on the target element and use `fill: 'both'`.
|
|
253
263
|
|
|
@@ -256,10 +266,10 @@ For `triggerType: 'repeat'`/`'alternate'`/`'state'`, manually apply the starting
|
|
|
256
266
|
```css
|
|
257
267
|
[data-interact-key='hero']:not([data-interact-enter]) {
|
|
258
268
|
visibility: hidden;
|
|
259
|
-
transform: none;
|
|
260
|
-
translate: none;
|
|
261
|
-
scale: none;
|
|
262
|
-
rotate: none;
|
|
269
|
+
transform: none !important;
|
|
270
|
+
translate: none !important;
|
|
271
|
+
scale: none !important;
|
|
272
|
+
rotate: none !important;
|
|
263
273
|
}
|
|
264
274
|
```
|
|
265
275
|
|
|
@@ -31,6 +31,9 @@ class Interact {
|
|
|
31
31
|
}): void;
|
|
32
32
|
static registerEffects(effects: Record<string, NamedEffect>): void;
|
|
33
33
|
static getController(key: string | undefined): IInteractionController | undefined;
|
|
34
|
+
static use(name: string, plugin: InteractPlugin): void;
|
|
35
|
+
static getPlugin(name: string): InteractPlugin | undefined;
|
|
36
|
+
static getPluginNames(): Set<string>;
|
|
34
37
|
|
|
35
38
|
// Instance methods
|
|
36
39
|
init(config: InteractConfig, options?: { useCustomElement?: boolean }): void;
|
|
@@ -230,6 +233,38 @@ Interact.registerEffects({
|
|
|
230
233
|
- Effects must be registered before calling `Interact.create()` with configurations that reference them
|
|
231
234
|
- Registration is global — once registered, effects are available to all Interact instances
|
|
232
235
|
|
|
236
|
+
### `Interact.use(name, plugin)`
|
|
237
|
+
|
|
238
|
+
Registers a plugin under a name. When an interaction or effect carries a `$<name>` field, Interact invokes the plugin with that field's value and a context. Interact is agnostic to what the plugin does — see the [Plugins guide](../guides/plugins.md).
|
|
239
|
+
|
|
240
|
+
**Parameters:**
|
|
241
|
+
|
|
242
|
+
- `name: string` - The plugin name, matched against `$<name>` config fields
|
|
243
|
+
- `plugin: InteractPlugin` - `(value, context) => void | (() => void)`; the returned cleanup runs on disconnect/teardown
|
|
244
|
+
|
|
245
|
+
**Example:**
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
import { Interact } from '@wix/interact';
|
|
249
|
+
import { splitTextPlugin } from '@wix/splittext/plugin';
|
|
250
|
+
|
|
251
|
+
Interact.use('splitText', splitTextPlugin);
|
|
252
|
+
Interact.create(config); // configs may now use a `$splitText: { ... }` field
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**Notes:**
|
|
256
|
+
|
|
257
|
+
- Register plugins **before** `Interact.create()`.
|
|
258
|
+
- Registration is global. A `$<name>` field naming an unregistered plugin is ignored.
|
|
259
|
+
|
|
260
|
+
### `Interact.getPlugin(name)`
|
|
261
|
+
|
|
262
|
+
Returns the plugin registered under `name`, or `undefined`.
|
|
263
|
+
|
|
264
|
+
### `Interact.getPluginsNames()`
|
|
265
|
+
|
|
266
|
+
Returns the set of registered plugins names (non-prefixed).
|
|
267
|
+
|
|
233
268
|
### `Interact.getController(key)`
|
|
234
269
|
|
|
235
270
|
Retrieves a cached `InteractionController` by its key.
|
package/docs/api/types.md
CHANGED
|
@@ -117,7 +117,7 @@ type Interaction = {
|
|
|
117
117
|
params?: TriggerParams;
|
|
118
118
|
conditions?: string[];
|
|
119
119
|
effects: ((Effect | EffectRef) & { interactionId?: string })[];
|
|
120
|
-
};
|
|
120
|
+
} & PluginFields; // `$<name>` plugin fields, e.g. `$splitText`
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
**Properties:**
|
|
@@ -128,6 +128,7 @@ type Interaction = {
|
|
|
128
128
|
- `listContainer` - Optional selector for list container when targeting list items
|
|
129
129
|
- `params` - Optional parameters for the trigger
|
|
130
130
|
- `conditions` - Optional array of condition IDs to evaluate
|
|
131
|
+
- `$<name>` - Optional `$`-prefixed plugin fields (see [Plugin Types](#plugin-types)). Also available on effects.
|
|
131
132
|
- `effects` - Array of effects to apply when triggered
|
|
132
133
|
|
|
133
134
|
**Example:**
|
|
@@ -615,6 +616,7 @@ type TransitionProperty = StyleProperty & TransitionOptions;
|
|
|
615
616
|
|
|
616
617
|
**Properties:**
|
|
617
618
|
|
|
619
|
+
- `name` - CSS property name, in kebab-case (`'background-color'`) or camelCase (`'backgroundColor'`). Both are accepted and normalized to kebab-case in the generated CSS; custom properties (`--*`) are used verbatim and are case-sensitive.
|
|
618
620
|
- `stateAction` - How to modify the element's CSS state on event triggers (`hover`, `click`, `activate`, `interest`):
|
|
619
621
|
- `'toggle'` (default) - Hover: adds on enter, removes on leave. Click: toggles on each click.
|
|
620
622
|
- `'add'` - Add the effect state; hover leave will NOT auto-remove.
|
|
@@ -937,6 +939,96 @@ Union type of all trigger parameter types.
|
|
|
937
939
|
type TriggerParams = ViewEnterParams | PointerMoveParams | AnimationEndParams;
|
|
938
940
|
```
|
|
939
941
|
|
|
942
|
+
## Plugin Types
|
|
943
|
+
|
|
944
|
+
See the [Plugins guide](../guides/plugins.md) for the full picture.
|
|
945
|
+
|
|
946
|
+
### `InteractPlugin`
|
|
947
|
+
|
|
948
|
+
A plugin callback registered via `Interact.use()`.
|
|
949
|
+
|
|
950
|
+
```typescript
|
|
951
|
+
type InteractPlugin = (
|
|
952
|
+
value: unknown,
|
|
953
|
+
context: InteractPluginContext,
|
|
954
|
+
) => void | InteractPluginCleanup;
|
|
955
|
+
```
|
|
956
|
+
|
|
957
|
+
### `InteractPluginContext`
|
|
958
|
+
|
|
959
|
+
```typescript
|
|
960
|
+
type InteractPluginContext = {
|
|
961
|
+
root: HTMLElement; // the interaction's (or effect target's) root element
|
|
962
|
+
key: string; // the interaction/effect key
|
|
963
|
+
scope: 'interaction' | 'effect';
|
|
964
|
+
config: Record<string, unknown>; // the interaction/effect object the plugin field was on
|
|
965
|
+
};
|
|
966
|
+
```
|
|
967
|
+
|
|
968
|
+
### `InteractPluginCleanup`
|
|
969
|
+
|
|
970
|
+
```typescript
|
|
971
|
+
type InteractPluginCleanup = () => void; // runs on disconnect/teardown
|
|
972
|
+
```
|
|
973
|
+
|
|
974
|
+
### `InteractPluginConfigMap`
|
|
975
|
+
|
|
976
|
+
Augmentable interface for typing plugin fields, keyed by the **unprefixed** plugin name. Empty by default; consumers merge into it:
|
|
977
|
+
|
|
978
|
+
```typescript
|
|
979
|
+
import type { SplitTextPluginConfig } from '@wix/splittext/plugin';
|
|
980
|
+
|
|
981
|
+
declare module '@wix/interact' {
|
|
982
|
+
interface InteractPluginConfigMap {
|
|
983
|
+
splitText: SplitTextPluginConfig;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
// types the `$splitText` field on interactions and effects
|
|
987
|
+
```
|
|
988
|
+
|
|
989
|
+
Prefer the config type exported by the plugin package over re-declaring its shape by hand.
|
|
990
|
+
|
|
991
|
+
### `PluginFields`
|
|
992
|
+
|
|
993
|
+
The `$`-prefixed plugin fields allowed on interactions and effects. Augmented plugins keep their value types (as `$<name>`); any other `$`-prefixed field is still allowed with an `unknown` value.
|
|
994
|
+
|
|
995
|
+
```typescript
|
|
996
|
+
type PluginFields = {
|
|
997
|
+
[K in keyof InteractPluginConfigMap as `$${K & string}`]?: InteractPluginConfigMap[K];
|
|
998
|
+
} & {
|
|
999
|
+
[pluginField: `$${string}`]: unknown;
|
|
1000
|
+
};
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
### `InteractPluginStyleGenerator`
|
|
1004
|
+
|
|
1005
|
+
A plugin's **build-time** styling callback, passed in the `plugins` argument of `generate()` (distinct from the runtime callback given to `Interact.use()`). Returns initial CSS declarations for the element — e.g. hiding pre-plugin content for FOUC prevention.
|
|
1006
|
+
|
|
1007
|
+
```typescript
|
|
1008
|
+
type InteractPluginStyleGenerator = (
|
|
1009
|
+
value: unknown,
|
|
1010
|
+
context: InteractPluginStyleContext,
|
|
1011
|
+
) => { declarations: { name: string; value: string | number }[]; selectorSuffix?: string }[];
|
|
1012
|
+
```
|
|
1013
|
+
|
|
1014
|
+
### `InteractPluginStyleContext`
|
|
1015
|
+
|
|
1016
|
+
```typescript
|
|
1017
|
+
type InteractPluginStyleContext = {
|
|
1018
|
+
key: string; // the interaction (or effect target) key the field is on
|
|
1019
|
+
scope: 'interaction' | 'effect';
|
|
1020
|
+
config: Record<string, unknown>; // the interaction/effect object the field is on
|
|
1021
|
+
};
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
### `InteractPluginStyles`
|
|
1025
|
+
|
|
1026
|
+
Map of plugin name → SSR style generator, passed as the `plugins` argument to `generate()`.
|
|
1027
|
+
|
|
1028
|
+
```typescript
|
|
1029
|
+
type InteractPluginStyles = Record<string, InteractPluginStyleGenerator>;
|
|
1030
|
+
```
|
|
1031
|
+
|
|
940
1032
|
## See Also
|
|
941
1033
|
|
|
942
1034
|
- [Sequences & Staggering Guide](../guides/sequences.md) - Comprehensive sequences guide
|
package/docs/guides/README.md
CHANGED
|
@@ -40,6 +40,10 @@ Working with dynamic lists, list containers, staggered animations, and automatic
|
|
|
40
40
|
|
|
41
41
|
Coordinate multiple effects with staggered timing using easing-driven delay offsets. Covers inline and reusable sequences, cross-element orchestration, `listContainer` integration, dynamic add/remove, and conditional sequences.
|
|
42
42
|
|
|
43
|
+
### 🔌 [Plugins](./plugins.md)
|
|
44
|
+
|
|
45
|
+
Extend Interact with external code via `Interact.use()` and `$`-prefixed config fields. Covers the generic bridge, the plugin contract and cleanup lifecycle, type-safe config, and using `@wix/splittext` to split text for staggered reveals.
|
|
46
|
+
|
|
43
47
|
## Learning Path
|
|
44
48
|
|
|
45
49
|
If you're new to `@wix/interact`, we recommend following the guides in this order:
|
|
@@ -43,6 +43,8 @@ Each interaction defines a complete cause-and-effect relationship:
|
|
|
43
43
|
|
|
44
44
|
Time-based playback (`once`, `repeat`, `alternate`, `state`) is set with `triggerType` on each time effect, or with `triggerType` on a sequence object when using `sequences`. Optional `params` on the interaction are for observer options (`viewEnter`), pointer/`animationEnd` settings, and other non-playback trigger configuration.
|
|
45
45
|
|
|
46
|
+
An interaction (or effect) may also carry `$`-prefixed fields (e.g. `$splitText`) — config routed to external plugins registered via `Interact.use()`. See the [Plugins guide](./plugins.md).
|
|
47
|
+
|
|
46
48
|
## Element Selection with Selectors
|
|
47
49
|
|
|
48
50
|
The `selector` property allows you to specify exactly which element should be used for interactions, instead of being limited to the first child element.
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Plugins
|
|
2
|
+
|
|
3
|
+
`@wix/interact` can route parts of your config to **plugins** — external code registered at runtime. Interact acts purely as a bridge: it knows a plugin's _name_, and when an interaction or effect carries a field named `$<name>` it hands that field's value to the plugin. Interact never knows what the plugin does.
|
|
4
|
+
|
|
5
|
+
This keeps Interact free of any plugin-specific code, and keeps plugins (like [`@wix/splittext`](https://www.npmjs.com/package/@wix/splittext)) free of any dependency on Interact. A plugin package can still ship its own adapter — `@wix/splittext/plugin` does — by typing it _structurally_ against the contract below rather than importing `@wix/interact`. Your app then only supplies the type glue.
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
1. Register a plugin by name, before `Interact.create()`:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { Interact } from '@wix/interact';
|
|
13
|
+
|
|
14
|
+
Interact.use('myPlugin', (value, context) => {
|
|
15
|
+
// `value` is whatever the config put in the `$myPlugin` field
|
|
16
|
+
// `context` describes where it was found (see below)
|
|
17
|
+
// return an optional cleanup function
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
2. Reference it with a `$`-prefixed field on an **interaction** or an **effect**:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
Interact.create({
|
|
25
|
+
interactions: [
|
|
26
|
+
{
|
|
27
|
+
key: 'hero',
|
|
28
|
+
trigger: 'viewEnter',
|
|
29
|
+
$myPlugin: { any: 'value' },
|
|
30
|
+
effects: [{ effectId: 'fade-in' }],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
When the `hero` element connects, Interact sees the `$myPlugin` field, looks up the `myPlugin` plugin, and calls it with `{ any: 'value' }`. Plugins run **before** target resolution, so any DOM a plugin creates is visible to the `selector` / `listContainer` queries that follow.
|
|
37
|
+
|
|
38
|
+
If a `$`-prefixed field names a plugin that was never registered, Interact ignores it.
|
|
39
|
+
|
|
40
|
+
> **Why the `$` prefix?** It marks a field as plugin config unambiguously (no clash with real config fields), it's a valid unquoted key in JS/TS and valid JSON, and it lets `@wix/interact-validate` accept plugin fields (via `catchall`) while still flagging genuinely-unknown keys.
|
|
41
|
+
|
|
42
|
+
## The plugin contract
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
type InteractPlugin = (
|
|
46
|
+
value: unknown,
|
|
47
|
+
context: {
|
|
48
|
+
root: HTMLElement; // the interaction's (or effect target's) root element
|
|
49
|
+
key: string; // the interaction/effect key
|
|
50
|
+
scope: 'interaction' | 'effect';
|
|
51
|
+
config: Record<string, unknown>; // the interaction/effect object the field was on
|
|
52
|
+
},
|
|
53
|
+
) => void | (() => void); // optionally return a cleanup function
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- Plugins run at **connect** time (when the element enters the DOM / is added).
|
|
57
|
+
- A returned **cleanup** runs on disconnect, on teardown (`Interact.destroy()`), and when an interaction re-connects after a media-query change — so plugins can fully undo their work.
|
|
58
|
+
- Each distinct plugin value is applied **once per connect**, even if referenced by multiple triggers on the same element.
|
|
59
|
+
|
|
60
|
+
### Type-safe config (optional)
|
|
61
|
+
|
|
62
|
+
Augment `InteractPluginConfigMap` — keyed by the **unprefixed** plugin name — so the `$<name>` field is type-checked:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
declare module '@wix/interact' {
|
|
66
|
+
interface InteractPluginConfigMap {
|
|
67
|
+
myPlugin: { any: string };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// now `$myPlugin` is typed as `{ any: string }` on interactions and effects
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Example: `@wix/splittext`
|
|
74
|
+
|
|
75
|
+
`@wix/splittext` splits an element's text into `<span>` wrappers (`.split-c` for chars, `.split-w` for words, `.split-l` for lines, `.split-s` for sentences). You don't need to write the adapter — it ships from the `@wix/splittext/plugin` entry point, written against the contract above _structurally_ so `@wix/splittext` keeps no dependency on `@wix/interact`. Register it, then target the generated spans with a normal `selector`:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// splitTextTypes.ts — the ONLY module that needs both packages, and only for types
|
|
79
|
+
import type { SplitTextPluginConfig } from '@wix/splittext/plugin';
|
|
80
|
+
|
|
81
|
+
declare module '@wix/interact' {
|
|
82
|
+
interface InteractPluginConfigMap {
|
|
83
|
+
splitText: SplitTextPluginConfig;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { Interact } from '@wix/interact';
|
|
90
|
+
import { splitTextPlugin } from '@wix/splittext/plugin';
|
|
91
|
+
|
|
92
|
+
Interact.use('splitText', splitTextPlugin);
|
|
93
|
+
|
|
94
|
+
Interact.create({
|
|
95
|
+
effects: {
|
|
96
|
+
'char-fade-up': { namedEffect: { type: 'FadeIn' }, duration: 400 },
|
|
97
|
+
},
|
|
98
|
+
interactions: [
|
|
99
|
+
{
|
|
100
|
+
key: 'hero',
|
|
101
|
+
trigger: 'viewEnter',
|
|
102
|
+
// split `.title` into characters before the sequence resolves
|
|
103
|
+
$splitText: { container: '.title', type: 'chars' },
|
|
104
|
+
sequences: [
|
|
105
|
+
{
|
|
106
|
+
offset: 30,
|
|
107
|
+
offsetEasing: 'quadIn',
|
|
108
|
+
// stagger the generated char spans
|
|
109
|
+
effects: [{ effectId: 'char-fade-up', selector: '.split-c' }],
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Effect-level (cross-element) splitting
|
|
118
|
+
|
|
119
|
+
A `$`-prefixed field can also sit on an individual effect, using that effect's **target** element as the root — useful for splitting a different element inside a multi-effect sequence:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
{
|
|
123
|
+
key: 'cta',
|
|
124
|
+
trigger: 'click',
|
|
125
|
+
sequences: [
|
|
126
|
+
{
|
|
127
|
+
offset: 60,
|
|
128
|
+
effects: [
|
|
129
|
+
{
|
|
130
|
+
key: 'heading',
|
|
131
|
+
$splitText: { container: '.heading-text', type: 'chars' },
|
|
132
|
+
selector: '.split-c',
|
|
133
|
+
effectId: 'scatter',
|
|
134
|
+
},
|
|
135
|
+
{ key: 'subtitle', effectId: 'fade-out' },
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## SSR styling (FOUC prevention)
|
|
143
|
+
|
|
144
|
+
A plugin often needs initial CSS _before_ it runs — e.g. hiding the un-split text so an entrance animation doesn't flash the raw content. That's a build-time concern, so it lives in [`generate()`](../api/functions.md#generateconfig-options), not in the runtime `use()` callback.
|
|
145
|
+
|
|
146
|
+
Pass a **second, separate callback per plugin** in the `plugins` option of `generate()`'s options bag — `generate(config, { useFirstChild, plugins })`. For every `$<name>` field, `generate()` calls the matching generator with the field's (opaque) value and a context, and appends the returned CSS. Like `create()`, `generate()` never looks inside the value — the plugin decides what to emit (and defines its own selectors under `selectorSuffix`).
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
type InteractPluginStyleGenerator = (
|
|
150
|
+
value: unknown,
|
|
151
|
+
context: {
|
|
152
|
+
key: string;
|
|
153
|
+
scope: 'interaction' | 'effect';
|
|
154
|
+
config: Record<string, unknown>;
|
|
155
|
+
},
|
|
156
|
+
) => { declarations: { name: string; value: string | number }[]; selectorSuffix?: string }[];
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`selectorSuffix` is concatenated to the base selector (`[data-interact-key="<key>"]`), to refine the target for the styling.
|
|
160
|
+
|
|
161
|
+
### SplitText example — hide until split
|
|
162
|
+
|
|
163
|
+
`@wix/splittext/plugin` ships this pairing ready-made: `splitTextStyle` is the SSR counterpart to `splitTextPlugin`, and the two agree on a `data-splittext-ready` marker. Opt in per-field with `hideUntilReady`:
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import { generate } from '@wix/interact';
|
|
167
|
+
import { splitTextStyle } from '@wix/splittext/plugin';
|
|
168
|
+
|
|
169
|
+
const config = {
|
|
170
|
+
effects: { 'char-fade-up': { namedEffect: { type: 'FadeIn' }, duration: 400 } },
|
|
171
|
+
interactions: [
|
|
172
|
+
{
|
|
173
|
+
key: 'hero',
|
|
174
|
+
trigger: 'viewEnter',
|
|
175
|
+
$splitText: { container: '.title', type: 'chars', hideUntilReady: true },
|
|
176
|
+
sequences: [{ offset: 30, effects: [{ effectId: 'char-fade-up', selector: '.split-c' }] }],
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// Embed this CSS in <head> at build/SSR time.
|
|
182
|
+
const css = generate(config, { plugins: { splitText: splitTextStyle } });
|
|
183
|
+
// → `[data-interact-key="hero"] .title:not([data-splittext-ready]) { visibility: hidden; }`
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
On first paint the container is hidden; once the runtime plugin splits it and sets `data-splittext-ready`, the hide rule stops matching and the (individually-hidden) spans take over their entrance animation — no flash of un-split text. Without `hideUntilReady`, `splitTextStyle` emits nothing.
|
|
187
|
+
|
|
188
|
+
> Plugin styles are emitted verbatim and unconditionally. If a rule should be scoped to a media query or condition, have the generator build that itself (it receives the interaction/effect `config`).
|
|
189
|
+
|
|
190
|
+
## Validation
|
|
191
|
+
|
|
192
|
+
`@wix/interact-validate` accepts any `$`-prefixed field as opaque plugin config (via zod's `catchall`) — it does not inspect plugin-specific shapes (it has no knowledge of any plugin). Non-prefixed unknown keys are still rejected, so a typo like `slector` (or forgetting the `$` on a plugin field) is caught.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/interact",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.6",
|
|
4
4
|
"description": "Declarative, configuration-driven interaction library — web-native, AI-ready, and framework-agnostic.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"url": "https://github.com/wix/interact/issues"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@wix/motion": "^2.1.
|
|
71
|
+
"@wix/motion": "^2.1.9",
|
|
72
72
|
"fastdom": "^1.0.12",
|
|
73
73
|
"fizban": "^0.7.2",
|
|
74
74
|
"kuliso": "^0.4.13"
|
package/rules/click.md
CHANGED
|
@@ -67,7 +67,7 @@ Use `keyframeEffect` or `namedEffect` when the click should play an animation (C
|
|
|
67
67
|
- `'repeat'` — restarts the animation from the beginning on each click.
|
|
68
68
|
- `'once'` — plays once on the first click and never again.
|
|
69
69
|
- `'state'` — resumes/pauses the animation on each click. Useful for continuous loops (`iterations: Infinity`).
|
|
70
|
-
- `[KEYFRAMES]` — array of keyframe objects (e.g. `[{ opacity: 0 }, { opacity: 1 }]`). Property names
|
|
70
|
+
- `[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.
|
|
71
71
|
- `[EFFECT_NAME]` — unique string identifier for a `keyframeEffect`.
|
|
72
72
|
- `[NAMED_EFFECT_DEFINITION]` — object with properties of pre-built, time-based animation effect from `@wix/motion-presets`. Refer to motion-presets rules for available presets and their options.
|
|
73
73
|
- `[FILL_MODE]` - optional. Always `'both'` with `triggerType: 'alternate'` or `'repeat'`, otherwise depends on the effect.
|
|
@@ -130,7 +130,7 @@ Use `transition` when all properties share timing. Use `transitionProperties` wh
|
|
|
130
130
|
- `'add'` — applies the style state. Does not remove on subsequent clicks.
|
|
131
131
|
- `'remove'` — removes a previously applied style state.
|
|
132
132
|
- `'clear'` — clears all previously applied style states. Useful for resetting multiple stacked style states at once.
|
|
133
|
-
- `[CSS_PROP]` — CSS property name as a string in
|
|
133
|
+
- `[CSS_PROP]` — CSS property name as a string, in kebab-case (`'background-color'`) or camelCase (`'backgroundColor'`) — both accepted; prefer kebab-case, since these are written into CSS. Custom properties (`--*`) are used verbatim.
|
|
134
134
|
- `[VALUE]` — target CSS value for the property.
|
|
135
135
|
- `[DURATION_MS]` — transition duration in milliseconds.
|
|
136
136
|
- `[DELAY_MS]` — optional transition delay in milliseconds.
|