@wix/interact 1.74.0 → 1.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -21
- package/dist/cjs/WixInteractElement.js +61 -17
- package/dist/cjs/WixInteractElement.js.map +1 -1
- package/dist/cjs/__tests__/interact.spec.js +761 -109
- package/dist/cjs/__tests__/interact.spec.js.map +1 -1
- package/dist/cjs/core/Interact.js +190 -0
- package/dist/cjs/core/Interact.js.map +1 -0
- package/dist/cjs/core/add.js +226 -0
- package/dist/cjs/core/add.js.map +1 -0
- package/dist/cjs/core/remove.js +37 -0
- package/dist/cjs/core/remove.js.map +1 -0
- package/dist/cjs/handlers/click.js +1 -1
- package/dist/cjs/handlers/click.js.map +1 -1
- package/dist/cjs/handlers/hover.js +1 -1
- package/dist/cjs/handlers/hover.js.map +1 -1
- package/dist/cjs/index.js +6 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils.js +12 -10
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/WixInteractElement.js +61 -17
- package/dist/esm/WixInteractElement.js.map +1 -1
- package/dist/esm/__tests__/interact.spec.js +743 -91
- package/dist/esm/__tests__/interact.spec.js.map +1 -1
- package/dist/esm/core/Interact.js +186 -0
- package/dist/esm/core/Interact.js.map +1 -0
- package/dist/esm/core/add.js +221 -0
- package/dist/esm/core/add.js.map +1 -0
- package/dist/esm/core/remove.js +32 -0
- package/dist/esm/core/remove.js.map +1 -0
- package/dist/esm/handlers/click.js +1 -1
- package/dist/esm/handlers/click.js.map +1 -1
- package/dist/esm/handlers/hover.js +1 -1
- package/dist/esm/handlers/hover.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.js +12 -10
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/WixInteractElement.d.ts +5 -2
- package/dist/types/core/Interact.d.ts +24 -0
- package/dist/types/core/add.d.ts +6 -0
- package/dist/types/core/remove.d.ts +5 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/types.d.ts +22 -9
- package/dist/types/utils.d.ts +1 -1
- package/package.json +7 -6
- package/dist/cjs/interact.js +0 -308
- package/dist/cjs/interact.js.map +0 -1
- package/dist/esm/interact.js +0 -301
- package/dist/esm/interact.js.map +0 -1
- package/dist/types/interact.d.ts +0 -26
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ const config = {
|
|
|
30
30
|
interactions: [
|
|
31
31
|
{
|
|
32
32
|
trigger: 'viewEnter',
|
|
33
|
-
|
|
33
|
+
key: '#my-element',
|
|
34
34
|
effects: [
|
|
35
35
|
{
|
|
36
36
|
effectId: 'fade-in',
|
|
@@ -42,7 +42,8 @@ const config = {
|
|
|
42
42
|
'fade-in': {
|
|
43
43
|
duration: 1000,
|
|
44
44
|
keyframeEffect: {
|
|
45
|
-
|
|
45
|
+
name: 'fade',
|
|
46
|
+
keyframes: {opacity: [0, 1]}
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
}
|
|
@@ -56,7 +57,7 @@ const interact = Interact.create(config);
|
|
|
56
57
|
|
|
57
58
|
```html
|
|
58
59
|
<!-- Wrap your target element with wix-interact-element -->
|
|
59
|
-
<wix-interact-element data-wix-path="
|
|
60
|
+
<wix-interact-element data-wix-path="my-element">
|
|
60
61
|
<div>This will fade in when it enters the viewport!</div>
|
|
61
62
|
</wix-interact-element>
|
|
62
63
|
```
|
|
@@ -69,7 +70,7 @@ import React from 'react';
|
|
|
69
70
|
|
|
70
71
|
function MyComponent() {
|
|
71
72
|
return (
|
|
72
|
-
<wix-interact-element data-wix-path="
|
|
73
|
+
<wix-interact-element data-wix-path="my-element">
|
|
73
74
|
<div className="animated-content">
|
|
74
75
|
Hello, animated world!
|
|
75
76
|
</div>
|
|
@@ -94,7 +95,7 @@ Define when interactions should occur:
|
|
|
94
95
|
Define what should happen:
|
|
95
96
|
- **Time-based animations** - Duration-based effects with easing
|
|
96
97
|
- **Scroll-driven animations** - Progress-based effects tied to scroll
|
|
97
|
-
- **Pointer-driven animations** - Progress-based effects linked to pointer
|
|
98
|
+
- **Pointer-driven animations** - Progress-based effects linked to pointer position
|
|
98
99
|
- **CSS transitions** - Style property transitions
|
|
99
100
|
- **Custom effects** - Integration with `@wix/motion`
|
|
100
101
|
|
|
@@ -104,14 +105,17 @@ Define what should happen:
|
|
|
104
105
|
interactions: [ // Define trigger → effect relationships
|
|
105
106
|
{
|
|
106
107
|
trigger: 'viewEnter',
|
|
107
|
-
|
|
108
|
+
key: 'source-element',
|
|
108
109
|
effects: [{ effectId: 'my-effect' }]
|
|
109
110
|
}
|
|
110
111
|
],
|
|
111
112
|
effects: { // Define reusable effect definitions
|
|
112
113
|
'my-effect': {
|
|
113
114
|
duration: 1000,
|
|
114
|
-
keyframeEffect: {
|
|
115
|
+
keyframeEffect: {
|
|
116
|
+
name: 'fade',
|
|
117
|
+
keyframes: { opacity: [0, 1] }
|
|
118
|
+
}
|
|
115
119
|
}
|
|
116
120
|
},
|
|
117
121
|
conditions: { // Define conditional logic
|
|
@@ -132,20 +136,20 @@ Define what should happen:
|
|
|
132
136
|
// Create a new instance with configuration
|
|
133
137
|
Interact.create(config: InteractConfig): Interact
|
|
134
138
|
|
|
135
|
-
// Get instance that handles a specific
|
|
136
|
-
Interact.getInstance(
|
|
139
|
+
// Get instance that handles a specific key
|
|
140
|
+
Interact.getInstance(key: string): Interact | undefined
|
|
137
141
|
|
|
138
|
-
// Get cached element by
|
|
139
|
-
Interact.getElement(
|
|
142
|
+
// Get cached element by key
|
|
143
|
+
Interact.getElement(key: string): IWixInteractElement | undefined
|
|
140
144
|
```
|
|
141
145
|
|
|
142
146
|
### Standalone Functions
|
|
143
147
|
```typescript
|
|
144
148
|
// Add interactions to an element
|
|
145
|
-
add(element: IWixInteractElement,
|
|
149
|
+
add(element: IWixInteractElement, key: string): boolean
|
|
146
150
|
|
|
147
151
|
// Remove all interactions from an element
|
|
148
|
-
remove(
|
|
152
|
+
remove(key: string): void
|
|
149
153
|
```
|
|
150
154
|
|
|
151
155
|
## Examples
|
|
@@ -155,7 +159,7 @@ remove(path: string): void
|
|
|
155
159
|
{
|
|
156
160
|
interactions: [{
|
|
157
161
|
trigger: 'viewEnter',
|
|
158
|
-
|
|
162
|
+
key: 'hero',
|
|
159
163
|
effects: [{ effectId: 'slide-up' }]
|
|
160
164
|
}],
|
|
161
165
|
effects: {
|
|
@@ -163,8 +167,11 @@ remove(path: string): void
|
|
|
163
167
|
duration: 800,
|
|
164
168
|
easing: 'ease-out',
|
|
165
169
|
keyframeEffect: {
|
|
166
|
-
|
|
167
|
-
|
|
170
|
+
name: 'slide-up',
|
|
171
|
+
keyframes: {
|
|
172
|
+
transform: ['translateY(20px)', 'translateY(0)'],
|
|
173
|
+
opacity: [0, 1]
|
|
174
|
+
}
|
|
168
175
|
}
|
|
169
176
|
}
|
|
170
177
|
}
|
|
@@ -176,13 +183,15 @@ remove(path: string): void
|
|
|
176
183
|
{
|
|
177
184
|
interactions: [{
|
|
178
185
|
trigger: 'click',
|
|
179
|
-
|
|
186
|
+
key: 'button',
|
|
180
187
|
effects: [{ effectId: 'bounce' }]
|
|
181
188
|
}],
|
|
182
189
|
effects: {
|
|
183
190
|
'bounce': {
|
|
184
191
|
duration: 600,
|
|
185
|
-
namedEffect:
|
|
192
|
+
namedEffect: {
|
|
193
|
+
type: 'Bounce'
|
|
194
|
+
}
|
|
186
195
|
}
|
|
187
196
|
}
|
|
188
197
|
}
|
|
@@ -193,7 +202,7 @@ remove(path: string): void
|
|
|
193
202
|
{
|
|
194
203
|
interactions: [{
|
|
195
204
|
trigger: 'hover',
|
|
196
|
-
|
|
205
|
+
key: 'card',
|
|
197
206
|
conditions: ['desktop-only'],
|
|
198
207
|
effects: [{ effectId: 'lift' }]
|
|
199
208
|
}],
|
|
@@ -207,8 +216,11 @@ remove(path: string): void
|
|
|
207
216
|
'lift': {
|
|
208
217
|
duration: 200,
|
|
209
218
|
keyframeEffect: {
|
|
210
|
-
|
|
211
|
-
|
|
219
|
+
name: 'lift',
|
|
220
|
+
keyframes: {
|
|
221
|
+
transform: ['translateY(0)', 'translateY(-8px)'],
|
|
222
|
+
boxShadow: ['0 2px 4px rgb(0 0 0 / 0.1)', '0 8px 16px rgb(0 0 0 / 0.15)']
|
|
223
|
+
}
|
|
212
224
|
}
|
|
213
225
|
}
|
|
214
226
|
}
|
|
@@ -5,7 +5,8 @@ exports.__esModule = true;
|
|
|
5
5
|
exports.WIX_INTERACT_EFFECT_DATA_ATTR = void 0;
|
|
6
6
|
exports.getWixInteractElement = getWixInteractElement;
|
|
7
7
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
|
-
var
|
|
8
|
+
var _add = require("./core/add");
|
|
9
|
+
var _remove = require("./core/remove");
|
|
9
10
|
const WIX_INTERACT_EFFECT_DATA_ATTR = exports.WIX_INTERACT_EFFECT_DATA_ATTR = 'wixInteractEffect';
|
|
10
11
|
function getWixInteractElement() {
|
|
11
12
|
let checkedForLegacyStateSyntax = false;
|
|
@@ -16,8 +17,10 @@ function getWixInteractElement() {
|
|
|
16
17
|
(0, _defineProperty2.default)(this, "_internals", void 0);
|
|
17
18
|
(0, _defineProperty2.default)(this, "connected", void 0);
|
|
18
19
|
(0, _defineProperty2.default)(this, "sheet", void 0);
|
|
20
|
+
(0, _defineProperty2.default)(this, "_observers", void 0);
|
|
19
21
|
this.connected = false;
|
|
20
22
|
this.sheet = null;
|
|
23
|
+
this._observers = new WeakMap();
|
|
21
24
|
if (this.attachInternals) {
|
|
22
25
|
this._internals = this.attachInternals();
|
|
23
26
|
if (!checkedForLegacyStateSyntax) {
|
|
@@ -38,37 +41,45 @@ function getWixInteractElement() {
|
|
|
38
41
|
this.connect();
|
|
39
42
|
}
|
|
40
43
|
disconnectedCallback() {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
(0,
|
|
44
|
+
const key = this.dataset.wixPath;
|
|
45
|
+
if (key) {
|
|
46
|
+
(0, _remove.remove)(key);
|
|
44
47
|
}
|
|
45
48
|
if (this.sheet) {
|
|
46
49
|
const index = document.adoptedStyleSheets.indexOf(this.sheet);
|
|
47
50
|
document.adoptedStyleSheets.splice(index, 1);
|
|
48
51
|
}
|
|
52
|
+
this._observers = new WeakMap();
|
|
49
53
|
this.connected = false;
|
|
50
54
|
}
|
|
51
|
-
connect(
|
|
55
|
+
connect(key) {
|
|
52
56
|
if (this.connected) {
|
|
53
57
|
return;
|
|
54
58
|
}
|
|
55
|
-
|
|
56
|
-
if (!
|
|
57
|
-
console.warn('WixInteractElement: No
|
|
59
|
+
key = key || this.dataset.wixPath;
|
|
60
|
+
if (!key) {
|
|
61
|
+
console.warn('WixInteractElement: No key provided');
|
|
58
62
|
return;
|
|
59
63
|
}
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
this.connected = (0, _add.add)(this, key);
|
|
65
|
+
}
|
|
66
|
+
renderStyle(cssRules) {
|
|
67
|
+
if (!this.sheet) {
|
|
68
|
+
this.sheet = new CSSStyleSheet();
|
|
69
|
+
void this.sheet.replace(cssRules.join('\n'));
|
|
70
|
+
document.adoptedStyleSheets.push(this.sheet);
|
|
62
71
|
} else {
|
|
63
|
-
|
|
72
|
+
let position = this.sheet.cssRules.length;
|
|
73
|
+
for (const cssRule of cssRules) {
|
|
74
|
+
try {
|
|
75
|
+
this.sheet.insertRule(cssRule, position);
|
|
76
|
+
position++;
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.error(e);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
64
81
|
}
|
|
65
82
|
}
|
|
66
|
-
renderStyle(cssText) {
|
|
67
|
-
const sheet = new CSSStyleSheet();
|
|
68
|
-
this.sheet = sheet;
|
|
69
|
-
sheet.replace(cssText);
|
|
70
|
-
document.adoptedStyleSheets.push(sheet);
|
|
71
|
-
}
|
|
72
83
|
toggleEffect(effectId, method) {
|
|
73
84
|
if (isLegacyStateSyntax) {
|
|
74
85
|
effectId = `--${effectId}`;
|
|
@@ -98,6 +109,39 @@ function getWixInteractElement() {
|
|
|
98
109
|
this.dataset[WIX_INTERACT_EFFECT_DATA_ATTR] = Array.from(currentEffects).join(' ');
|
|
99
110
|
}
|
|
100
111
|
}
|
|
112
|
+
watchChildList(listContainer) {
|
|
113
|
+
const list = this.querySelector(listContainer);
|
|
114
|
+
if (list) {
|
|
115
|
+
// TODO: we can probably improve this and use less observers, this impl. uses one per container element
|
|
116
|
+
let observer = this._observers.get(list);
|
|
117
|
+
if (!observer) {
|
|
118
|
+
observer = new MutationObserver(this._childListChangeHandler.bind(this, listContainer));
|
|
119
|
+
this._observers.set(list, observer);
|
|
120
|
+
observer.observe(list, {
|
|
121
|
+
childList: true
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
_childListChangeHandler(listContainer, entries) {
|
|
127
|
+
const key = this.dataset.wixPath;
|
|
128
|
+
const removedElements = [];
|
|
129
|
+
const addedElements = [];
|
|
130
|
+
entries.forEach(entry => {
|
|
131
|
+
entry.removedNodes.forEach(el => {
|
|
132
|
+
if (el instanceof HTMLElement) {
|
|
133
|
+
removedElements.push(el);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
entry.addedNodes.forEach(el => {
|
|
137
|
+
if (el instanceof HTMLElement) {
|
|
138
|
+
addedElements.push(el);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
(0, _remove.removeListItems)(removedElements);
|
|
143
|
+
key && (0, _add.addListItems)(this, key, listContainer, addedElements);
|
|
144
|
+
}
|
|
101
145
|
};
|
|
102
146
|
}
|
|
103
147
|
//# sourceMappingURL=WixInteractElement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_interact","require","WIX_INTERACT_EFFECT_DATA_ATTR","exports","getWixInteractElement","checkedForLegacyStateSyntax","isLegacyStateSyntax","WixInteractElement","HTMLElement","constructor","_defineProperty2","default","connected","sheet","attachInternals","_internals","states","add","delete","e","connectedCallback","connect","disconnectedCallback","path","dataset","wixPath","remove","index","document","adoptedStyleSheets","indexOf","splice","console","warn","firstElementChild","renderStyle","cssText","CSSStyleSheet","replace","push","toggleEffect","effectId","method","has","clear","_this$dataset$WIX_INT","currentEffects","Set","split","Array","from","join"],"sources":["../../src/WixInteractElement.ts"],"sourcesContent":["import type { StateParams } from './types';\nimport { add, remove } from './interact';\n\nexport const WIX_INTERACT_EFFECT_DATA_ATTR = 'wixInteractEffect';\n\nexport function getWixInteractElement() {\n let checkedForLegacyStateSyntax = false;\n let isLegacyStateSyntax = false;\n\n return class WixInteractElement extends HTMLElement {\n _internals: (ElementInternals & { states: Set<string> }) | null;\n connected: boolean;\n sheet: CSSStyleSheet | null;\n\n constructor() {\n super();\n\n this.connected = false;\n this.sheet = null;\n\n if (this.attachInternals) {\n this._internals = this.attachInternals() as ElementInternals & {\n states: Set<string>;\n };\n\n if (!checkedForLegacyStateSyntax) {\n checkedForLegacyStateSyntax = true;\n\n try {\n this._internals.states.add('test');\n this._internals.states.delete('test');\n } catch (e) {\n isLegacyStateSyntax = true;\n }\n }\n } else {\n checkedForLegacyStateSyntax = true; // custom states not supported - skip syntax check\n this._internals = null;\n }\n }\n connectedCallback() {\n this.connect();\n }\n\n disconnectedCallback() {\n const path = this.dataset.wixPath;\n\n if (path) {\n remove(path);\n }\n\n if (this.sheet) {\n const index = document.adoptedStyleSheets.indexOf(this.sheet);\n document.adoptedStyleSheets.splice(index, 1);\n }\n\n this.connected = false;\n }\n\n connect(path?: string) {\n if (this.connected) {\n return;\n }\n\n path = path || this.dataset.wixPath;\n\n if (!path) {\n console.warn('WixInteractElement: No path provided');\n return;\n }\n\n if (this.firstElementChild) {\n this.connected = add(this, path);\n } else {\n console.warn('WixInteractElement: No child element found');\n }\n }\n\n renderStyle(cssText: string) {\n const sheet = new CSSStyleSheet();\n this.sheet = sheet;\n\n sheet.replace(cssText);\n\n document.adoptedStyleSheets.push(sheet);\n }\n\n toggleEffect(effectId: string, method: StateParams['method']) {\n if (isLegacyStateSyntax) {\n effectId = `--${effectId}`;\n }\n\n if (this._internals) {\n if (method === 'toggle') {\n this._internals.states.has(effectId)\n ? this._internals.states.delete(effectId)\n : this._internals.states.add(effectId);\n } else if (method === 'add') {\n this._internals.states.add(effectId);\n } else if (method === 'remove') {\n this._internals.states.delete(effectId);\n } else if (method === 'clear') {\n this._internals.states.clear();\n }\n } else {\n const currentEffects = new Set(\n this.dataset[WIX_INTERACT_EFFECT_DATA_ATTR]?.split(' ') || [],\n );\n\n if (method === 'toggle') {\n currentEffects.has(effectId)\n ? currentEffects.delete(effectId)\n : currentEffects.add(effectId);\n } else if (method === 'add') {\n currentEffects.add(effectId);\n } else if (method === 'remove') {\n currentEffects.delete(effectId);\n } else if (method === 'clear') {\n currentEffects.clear();\n }\n\n this.dataset[WIX_INTERACT_EFFECT_DATA_ATTR] =\n Array.from(currentEffects).join(' ');\n }\n }\n };\n}\n"],"mappings":";;;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AAEO,MAAMC,6BAA6B,GAAAC,OAAA,CAAAD,6BAAA,GAAG,mBAAmB;AAEzD,SAASE,qBAAqBA,CAAA,EAAG;EACtC,IAAIC,2BAA2B,GAAG,KAAK;EACvC,IAAIC,mBAAmB,GAAG,KAAK;EAE/B,OAAO,MAAMC,kBAAkB,SAASC,WAAW,CAAC;IAKlDC,WAAWA,CAAA,EAAG;MACZ,KAAK,CAAC,CAAC;MAAC,IAAAC,gBAAA,CAAAC,OAAA;MAAA,IAAAD,gBAAA,CAAAC,OAAA;MAAA,IAAAD,gBAAA,CAAAC,OAAA;MAER,IAAI,CAACC,SAAS,GAAG,KAAK;MACtB,IAAI,CAACC,KAAK,GAAG,IAAI;MAEjB,IAAI,IAAI,CAACC,eAAe,EAAE;QACxB,IAAI,CAACC,UAAU,GAAG,IAAI,CAACD,eAAe,CAAC,CAEtC;QAED,IA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GAAG,CAAC,KAAI,EAC7D,CAAC;QAED,IAAIN,MAAM,KAAK,QAAQ,EAAE;UACvBI,cAAc,CAACH,GAAG,CAACF,QAAQ,CAAC,GACxBK,cAAc,CAAC5B,MAAM,CAACuB,QAAQ,CAAC,GAC/BK,cAAc,CAAC7B,GAAG,CAACwB,QAAQ,CAAC;QAClC,CAAC,MAAM,IAAIC,MAAM,KAAK,KAAK,EAAE;UAC3BI,cAAc,CAAC7B,GAAG,CAACwB,QAAQ,CAAC;QAC9B,CAAC,MAAM,IAAIC,MAAM,KAAK,QAAQ,EAAE;UAC9BI,cAAc,CAAC5B,MAAM,CAACuB,QAAQ,CAAC;QACjC,CAAC,MAAM,IAAIC,MAAM,KAAK,OAAO,EAAE;UAC7BI,cAAc,CAACF,KAAK,CAAC,CAAC;QACxB;QAEA,IAAI,CAACpB,OAAO,CAACtB,6BAA6B,CAAC,GACzC+C,KAAK,CAACC,IAAI,CAACJ,cAAc,CAAC,CAACK,IAAI,CAAC,GAAG,CAAC;MACxC;IACF;EACF,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_add","require","_remove","WIX_INTERACT_EFFECT_DATA_ATTR","exports","getWixInteractElement","checkedForLegacyStateSyntax","isLegacyStateSyntax","WixInteractElement","HTMLElement","constructor","_defineProperty2","default","connected","sheet","_observers","WeakMap","attachInternals","_internals","states","add","delete","e","connectedCallback","connect","disconnectedCallback","key","dataset","wixPath","remove","index","document","adoptedStyleSheets","indexOf","splice","console","warn","renderStyle","cssRules","CSSStyleSheet","replace","join","push","position","length","cssRule","insertRule","error","toggleEffect","effectId","method","has","clear","_this$dataset$WIX_INT","currentEffects","Set","split","Array","from","watchChildList","listContainer","list","querySelector","observer","get","MutationObserver","_childListChangeHandler","bind","set","observe","childList","entries","removedElements","addedElements","forEach","entry","removedNodes","el","addedNodes","removeListItems","addListItems"],"sources":["../../src/WixInteractElement.ts"],"sourcesContent":["import type { StateParams } from './types';\nimport { add, addListItems } from './core/add';\nimport { remove, removeListItems } from './core/remove';\n\nexport const WIX_INTERACT_EFFECT_DATA_ATTR = 'wixInteractEffect';\n\nexport function getWixInteractElement() {\n let checkedForLegacyStateSyntax = false;\n let isLegacyStateSyntax = false;\n\n return class WixInteractElement extends HTMLElement {\n _internals: (ElementInternals & { states: Set<string> }) | null;\n connected: boolean;\n sheet: CSSStyleSheet | null;\n _observers: WeakMap<HTMLElement, MutationObserver>;\n\n constructor() {\n super();\n\n this.connected = false;\n this.sheet = null;\n this._observers = new WeakMap();\n\n if (this.attachInternals) {\n this._internals = this.attachInternals() as ElementInternals & {\n states: Set<string>;\n };\n\n if (!checkedForLegacyStateSyntax) {\n checkedForLegacyStateSyntax = true;\n\n try {\n this._internals.states.add('test');\n this._internals.states.delete('test');\n } catch (e) {\n isLegacyStateSyntax = true;\n }\n }\n } else {\n checkedForLegacyStateSyntax = true; // custom states not supported - skip syntax check\n this._internals = null;\n }\n }\n connectedCallback() {\n this.connect();\n }\n\n disconnectedCallback() {\n const key = this.dataset.wixPath;\n\n if (key) {\n remove(key);\n }\n\n if (this.sheet) {\n const index = document.adoptedStyleSheets.indexOf(this.sheet);\n document.adoptedStyleSheets.splice(index, 1);\n }\n\n this._observers = new WeakMap();\n\n this.connected = false;\n }\n\n connect(key?: string) {\n if (this.connected) {\n return;\n }\n\n key = key || this.dataset.wixPath;\n\n if (!key) {\n console.warn('WixInteractElement: No key provided');\n return;\n }\n\n this.connected = add(this, key);\n }\n\n renderStyle(cssRules: string[]) {\n if (!this.sheet) {\n this.sheet = new CSSStyleSheet();\n void this.sheet.replace(cssRules.join('\\n'));\n\n document.adoptedStyleSheets.push(this.sheet);\n } else {\n let position = this.sheet.cssRules.length;\n\n for (const cssRule of cssRules) {\n try {\n this.sheet.insertRule(cssRule, position);\n position++;\n } catch (e) {\n console.error(e);\n }\n }\n }\n }\n\n toggleEffect(effectId: string, method: StateParams['method']) {\n if (isLegacyStateSyntax) {\n effectId = `--${effectId}`;\n }\n\n if (this._internals) {\n if (method === 'toggle') {\n this._internals.states.has(effectId)\n ? this._internals.states.delete(effectId)\n : this._internals.states.add(effectId);\n } else if (method === 'add') {\n this._internals.states.add(effectId);\n } else if (method === 'remove') {\n this._internals.states.delete(effectId);\n } else if (method === 'clear') {\n this._internals.states.clear();\n }\n } else {\n const currentEffects = new Set(\n this.dataset[WIX_INTERACT_EFFECT_DATA_ATTR]?.split(' ') || [],\n );\n\n if (method === 'toggle') {\n currentEffects.has(effectId)\n ? currentEffects.delete(effectId)\n : currentEffects.add(effectId);\n } else if (method === 'add') {\n currentEffects.add(effectId);\n } else if (method === 'remove') {\n currentEffects.delete(effectId);\n } else if (method === 'clear') {\n currentEffects.clear();\n }\n\n this.dataset[WIX_INTERACT_EFFECT_DATA_ATTR] =\n Array.from(currentEffects).join(' ');\n }\n }\n\n watchChildList(listContainer: string): void {\n const list = this.querySelector(listContainer);\n\n if (list) {\n // TODO: we can probably improve this and use less observers, this impl. uses one per container element\n let observer = this._observers.get(list as HTMLElement);\n\n if (!observer) {\n observer = new MutationObserver(\n this._childListChangeHandler.bind(this, listContainer),\n );\n\n this._observers.set(list as HTMLElement, observer);\n\n observer.observe(list as HTMLElement, { childList: true });\n }\n }\n }\n\n _childListChangeHandler(listContainer: string, entries: MutationRecord[]) {\n const key = this.dataset.wixPath;\n const removedElements: HTMLElement[] = [];\n const addedElements: HTMLElement[] = [];\n\n entries.forEach((entry) => {\n entry.removedNodes.forEach((el) => {\n if (el instanceof HTMLElement) {\n removedElements.push(el);\n }\n });\n\n entry.addedNodes.forEach((el) => {\n if (el instanceof HTMLElement) {\n addedElements.push(el);\n }\n });\n });\n\n removeListItems(removedElements);\n key && addListItems(this, key, listContainer, addedElements);\n }\n };\n}\n"],"mappings":";;;;;;;AACA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEO,MAAME,6BAA6B,GAAAC,OAAA,CAAAD,6BAAA,GAAG,mBAAmB;AAEzD,SAASE,qBAAqBA,CAA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