@wix/interact 2.5.5 → 2.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/react.js +1 -1
  4. package/dist/cjs/web.js +1 -1
  5. package/dist/es/index.js +1 -1
  6. package/dist/es/react.js +2 -2
  7. package/dist/es/web.js +2 -2
  8. package/dist/index-Bt4pzwx1.js +21 -0
  9. package/dist/index-Bt4pzwx1.js.map +1 -0
  10. package/dist/index-C-q7gc5a.mjs +3565 -0
  11. package/dist/index-C-q7gc5a.mjs.map +1 -0
  12. package/dist/tsconfig.build.tsbuildinfo +1 -1
  13. package/dist/types/core/Interact.d.ts +10 -1
  14. package/dist/types/core/Interact.d.ts.map +1 -1
  15. package/dist/types/core/InteractionController.d.ts +3 -1
  16. package/dist/types/core/InteractionController.d.ts.map +1 -1
  17. package/dist/types/core/add.d.ts.map +1 -1
  18. package/dist/types/core/css.d.ts +12 -4
  19. package/dist/types/core/css.d.ts.map +1 -1
  20. package/dist/types/core/cssUtils.d.ts.map +1 -1
  21. package/dist/types/core/resolvers.d.ts +2 -2
  22. package/dist/types/core/resolvers.d.ts.map +1 -1
  23. package/dist/types/types/config.d.ts +3 -2
  24. package/dist/types/types/config.d.ts.map +1 -1
  25. package/dist/types/types/controller.d.ts +5 -0
  26. package/dist/types/types/controller.d.ts.map +1 -1
  27. package/dist/types/types/css.d.ts +15 -1
  28. package/dist/types/types/css.d.ts.map +1 -1
  29. package/dist/types/types/effects.d.ts +2 -1
  30. package/dist/types/types/effects.d.ts.map +1 -1
  31. package/dist/types/types/external.d.ts +2 -0
  32. package/dist/types/types/external.d.ts.map +1 -1
  33. package/dist/types/types/index.d.ts +1 -0
  34. package/dist/types/types/index.d.ts.map +1 -1
  35. package/dist/types/types/plugins.d.ts +81 -0
  36. package/dist/types/types/plugins.d.ts.map +1 -0
  37. package/dist/types/utils.d.ts +7 -4
  38. package/dist/types/utils.d.ts.map +1 -1
  39. package/docs/api/README.md +1 -1
  40. package/docs/api/functions.md +16 -8
  41. package/docs/api/interact-class.md +35 -0
  42. package/docs/api/types.md +95 -3
  43. package/docs/examples/list-patterns.md +4 -0
  44. package/docs/guides/README.md +4 -0
  45. package/docs/guides/configuration-structure.md +2 -0
  46. package/docs/guides/plugins.md +192 -0
  47. package/docs/guides/sequences.md +34 -1
  48. package/package.json +2 -2
  49. package/rules/click.md +2 -2
  50. package/rules/full-lean.md +79 -21
  51. package/rules/hover.md +2 -2
  52. package/rules/integration.md +20 -11
  53. package/rules/plugins.md +122 -0
  54. package/rules/pointermove.md +14 -22
  55. package/rules/validate.md +7 -4
  56. package/rules/viewenter.md +1 -1
  57. package/rules/viewprogress.md +4 -4
  58. package/dist/index-7fvAL10J.mjs +0 -3323
  59. package/dist/index-7fvAL10J.mjs.map +0 -1
  60. package/dist/index-C4A3nFix.js +0 -21
  61. package/dist/index-C4A3nFix.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../../src/types/plugins.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,MAAM,MAAM,qBAAqB,GAAG;IAClC,oEAAoE;IACpE,IAAI,EAAE,WAAW,CAAC;IAClB,kEAAkE;IAClE,GAAG,EAAE,MAAM,CAAC;IACZ,yEAAyE;IACzE,KAAK,EAAE,aAAa,GAAG,QAAQ,CAAC;IAChC,kFAAkF;IAClF,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,CAAC;AAEF,kGAAkG;AAClG,MAAM,MAAM,qBAAqB,GAAG,MAAM,IAAI,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,qBAAqB,KAC3B,IAAI,GAAG,qBAAqB,CAAC;AAElC;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,4EAA4E;IAC5E,GAAG,EAAE,MAAM,CAAC;IACZ,+EAA+E;IAC/E,KAAK,EAAE,aAAa,GAAG,QAAQ,CAAC;IAChC,kFAAkF;IAClF,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,4BAA4B,GAAG,CACzC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,0BAA0B,KAChC,IAAI,CAAC,WAAW,EAAE,cAAc,GAAG,gBAAgB,CAAC,EAAE,CAAC;AAE5D,2FAA2F;AAC3F,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,4BAA4B,CAAC,CAAC;AAEhF;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,uBAAuB;CAAG;AAE3C;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;KACxB,CAAC,IAAI,MAAM,uBAAuB,IAAI,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC;CACtF,GAAG;IACF,CAAC,WAAW,EAAE,IAAI,MAAM,EAAE,GAAG,OAAO,CAAC;CACtC,CAAC"}
@@ -1,11 +1,8 @@
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;
5
5
  export declare function camelToKebabCase(property: string): string;
6
- export declare function calculateSequenceEffectsOffsets(effects: ((any & {
7
- delay?: number;
8
- }) | null)[], delay: number, offset: number, offsetEasing: (p: number) => number): void;
9
6
  /**
10
7
  * Applies a selector condition predicate to a base selector.
11
8
  * - If `&` is in the predicate, replace `&` with the base selector
@@ -13,6 +10,12 @@ export declare function calculateSequenceEffectsOffsets(effects: ((any & {
13
10
  */
14
11
  export declare function applySelectorCondition(baseSelector: string, predicate: string): string;
15
12
  export declare function generateId(): string;
13
+ /**
14
+ * Resolves the style properties of a state effect - `transition.styleProperties` wins
15
+ * when both are set - with property names normalized to the kebab-case form CSS expects.
16
+ * Property names may be authored in either camelCase or kebab-case.
17
+ */
18
+ export declare function getStateStyleProperties(transitionEffect: Pick<StateEffect, 'transition' | 'transitionProperties'>): StyleProperty[];
16
19
  export declare function transitionEffectToTransitionsList(transitionEffect: StateEffect): string[];
17
20
  export declare function createTransitionCSS({ key, effectId, transition, transitionProperties, childSelector, selectorCondition, }: CreateTransitionCSSParams): string[];
18
21
  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;AAEjF,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,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,CA0CtC;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"}
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;;;;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"}
@@ -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, useFirstChild?)**](functions.md#generate) - Generate complete CSS for all animations, transitions, scroll-driven effects, and FOUC prevention
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
@@ -12,11 +12,11 @@ import { add, remove, generate } from '@wix/interact';
12
12
 
13
13
  ## Functions Overview
14
14
 
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?` | `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, useFirstChild?)`
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, useFirstChild?: boolean): string;
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
- **`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>`).
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
 
@@ -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.
@@ -770,8 +772,8 @@ type SequenceOptionsConfig = {
770
772
 
771
773
  - `delay` - Base delay (ms) applied to all effects in the sequence. Default: `0`.
772
774
  - `offset` - Stagger interval (ms) between consecutive effects. Default: `0`.
773
- - `offsetEasing` - Easing function or named string for offset distribution (`'linear'`, `'quadIn'`, `'sineOut'`, etc.). Default: `linear`.
774
- - `sequenceId` - Optional ID for referencing a reusable sequence from `InteractConfig.sequences`.
775
+ - `offsetEasing` - Easing function or named string for offset distribution (`'linear'`, `'quadIn'`, `'sineOut'`, etc.). Default: `linear`. Only string easings can be compiled into generated CSS — a function excludes the sequence from `generate()`'s output. See [Stagger in Generated CSS](../guides/sequences.md#stagger-in-generated-css).
776
+ - `sequenceId` - Optional ID for referencing a reusable sequence from `InteractConfig.sequences`. Also names the `--motion-<sequenceId>-index` custom properties that carry the stagger in generated CSS. Defaults to `seq-<interactionIndex>-<sequenceIndex>`, derived from the config position so CSS generation and the runtime agree.
775
777
  - `conditions` - Optional array of condition IDs. When set, the sequence is only active when all conditions match.
776
778
  - `triggerType` - Controls play behavior for event trigger sequences (`hover`, `click`, `activate`, `interest`, `viewEnter`). Same values as `TimeEffect.triggerType`: `'once'` (default for viewEnter), `'alternate'` (default for hover/click), `'repeat'`, `'state'`.
777
779
 
@@ -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
@@ -904,6 +904,10 @@ Different `offsetEasing` values produce distinct stagger patterns:
904
904
  { offset: 80, offsetEasing: 'sineOut' }
905
905
  ```
906
906
 
907
+ Any string easing works — named keys, `cubic-bezier(...)`, or `linear(...)`. Keep it a string rather than a
908
+ function if the list should also be staggered by generated CSS; see
909
+ [Stagger in Generated CSS](../guides/sequences.md#stagger-in-generated-css).
910
+
907
911
  ### 20. Reusable Sequences with `sequenceId`
908
912
 
909
913
  Define a sequence once, reference it from multiple interactions:
@@ -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.
@@ -18,6 +18,35 @@ For example, with 5 effects and `offset: 200`:
18
18
  | `quadIn` | 0, 50, 200, 450, 800 | Slow start, then rapid |
19
19
  | `sineOut` | 0, 306, 565, 739, 800 | Fast start, then gradual |
20
20
 
21
+ ## Stagger in Generated CSS
22
+
23
+ `generate()` emits **one** animation rule per sequence effect, not one per list item — the item count
24
+ isn't known when the CSS is produced. The per-item delay is therefore expressed as a `calc()` over two
25
+ custom properties naming the element's position in the sequence:
26
+
27
+ ```css
28
+ animation: card-entrance 600ms
29
+ calc((0 + <offsetEasing(index / last) > * 80 * var(--motion-card-stagger-last, 1)) * 1ms) …;
30
+ ```
31
+
32
+ At runtime the `Sequence` writes `--motion-<sequenceId>-index` and `--motion-<sequenceId>-last` onto each
33
+ target element, and the shared rule resolves to a different delay per item. Before that — during SSR and
34
+ until Interact initializes — the `var()` fallbacks resolve `index` to `0`, so every element sits at the
35
+ base delay and the CSS stays valid and FOUC-free.
36
+
37
+ This is why sequences need a stable `sequenceId`: it names the custom properties, and the CSS half and the
38
+ runtime half must agree on it. When you don't provide one, Interact derives it from the sequence's position
39
+ in the config (`seq-<interactionIndex>-<sequenceIndex>`) so both halves compute the same value from the same
40
+ config.
41
+
42
+ > **`offsetEasing` must be a string for CSS generation.** A `(p: number) => number` function has no CSS
43
+ > equivalent, so `generate()` skips the entire sequence — the animations still run once Interact
44
+ > initializes, but nothing is rendered ahead of time and entrance animations may flash. Use a named easing,
45
+ > `cubic-bezier(...)`, or `linear(...)` for anything that needs generated CSS.
46
+ >
47
+ > [`@wix/interact-validate`](https://github.com/wix/interact/blob/master/packages/interact-validate/README.md)
48
+ > reports this statically as the `FUNCTION_OFFSET_EASING` warning.
49
+
21
50
  ## Config Structure
22
51
 
23
52
  Sequences can be defined at two levels:
@@ -124,11 +153,15 @@ type SequenceOptionsConfig = {
124
153
  delay?: number; // Base delay (ms). Default: 0
125
154
  offset?: number; // Stagger interval (ms). Default: 0
126
155
  offsetEasing?: string | ((p: number) => number); // Easing for offset distribution
127
- sequenceId?: string; // ID for reusable sequence reference
156
+ sequenceId?: string; // ID for reusable sequence reference, and for the CSS stagger custom properties
128
157
  conditions?: string[]; // Media query condition IDs
129
158
  };
130
159
  ```
131
160
 
161
+ A function `offsetEasing` works at runtime but excludes the sequence from
162
+ [generated CSS](#stagger-in-generated-css). Auto-generated `sequenceId`s are derived from the config
163
+ position, so `generate()` and the runtime agree on them.
164
+
132
165
  ### `SequenceConfig`
133
166
 
134
167
  Inline sequence definition (extends `SequenceOptionsConfig`):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/interact",
3
- "version": "2.5.5",
3
+ "version": "2.5.7",
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.8",
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 in camelCase.
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 camelCase format (e.g. `'backgroundColor'`, `'borderRadius'`, `'opacity'`).
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.