@wix/interact 1.74.0 → 1.76.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.
Files changed (52) hide show
  1. package/README.md +33 -21
  2. package/dist/cjs/WixInteractElement.js +61 -17
  3. package/dist/cjs/WixInteractElement.js.map +1 -1
  4. package/dist/cjs/__tests__/interact.spec.js +761 -109
  5. package/dist/cjs/__tests__/interact.spec.js.map +1 -1
  6. package/dist/cjs/core/Interact.js +190 -0
  7. package/dist/cjs/core/Interact.js.map +1 -0
  8. package/dist/cjs/core/add.js +231 -0
  9. package/dist/cjs/core/add.js.map +1 -0
  10. package/dist/cjs/core/remove.js +37 -0
  11. package/dist/cjs/core/remove.js.map +1 -0
  12. package/dist/cjs/handlers/click.js +1 -1
  13. package/dist/cjs/handlers/click.js.map +1 -1
  14. package/dist/cjs/handlers/hover.js +1 -1
  15. package/dist/cjs/handlers/hover.js.map +1 -1
  16. package/dist/cjs/index.js +6 -4
  17. package/dist/cjs/index.js.map +1 -1
  18. package/dist/cjs/types.js.map +1 -1
  19. package/dist/cjs/utils.js +12 -10
  20. package/dist/cjs/utils.js.map +1 -1
  21. package/dist/esm/WixInteractElement.js +61 -17
  22. package/dist/esm/WixInteractElement.js.map +1 -1
  23. package/dist/esm/__tests__/interact.spec.js +743 -91
  24. package/dist/esm/__tests__/interact.spec.js.map +1 -1
  25. package/dist/esm/core/Interact.js +186 -0
  26. package/dist/esm/core/Interact.js.map +1 -0
  27. package/dist/esm/core/add.js +226 -0
  28. package/dist/esm/core/add.js.map +1 -0
  29. package/dist/esm/core/remove.js +32 -0
  30. package/dist/esm/core/remove.js.map +1 -0
  31. package/dist/esm/handlers/click.js +1 -1
  32. package/dist/esm/handlers/click.js.map +1 -1
  33. package/dist/esm/handlers/hover.js +1 -1
  34. package/dist/esm/handlers/hover.js.map +1 -1
  35. package/dist/esm/index.js +3 -1
  36. package/dist/esm/index.js.map +1 -1
  37. package/dist/esm/types.js.map +1 -1
  38. package/dist/esm/utils.js +12 -10
  39. package/dist/esm/utils.js.map +1 -1
  40. package/dist/types/WixInteractElement.d.ts +5 -2
  41. package/dist/types/core/Interact.d.ts +24 -0
  42. package/dist/types/core/add.d.ts +6 -0
  43. package/dist/types/core/remove.d.ts +5 -0
  44. package/dist/types/index.d.ts +3 -1
  45. package/dist/types/types.d.ts +22 -9
  46. package/dist/types/utils.d.ts +1 -1
  47. package/package.json +7 -6
  48. package/dist/cjs/interact.js +0 -308
  49. package/dist/cjs/interact.js.map +0 -1
  50. package/dist/esm/interact.js +0 -301
  51. package/dist/esm/interact.js.map +0 -1
  52. package/dist/types/interact.d.ts +0 -26
package/dist/cjs/index.js CHANGED
@@ -7,10 +7,12 @@ var _exportNames = {
7
7
  remove: true
8
8
  };
9
9
  exports.remove = exports.add = exports.Interact = void 0;
10
- var _interact = require("./interact");
11
- exports.Interact = _interact.Interact;
12
- exports.add = _interact.add;
13
- exports.remove = _interact.remove;
10
+ var _Interact = require("./core/Interact");
11
+ exports.Interact = _Interact.Interact;
12
+ var _add = require("./core/add");
13
+ exports.add = _add.add;
14
+ var _remove = require("./core/remove");
15
+ exports.remove = _remove.remove;
14
16
  var _types = require("./types");
15
17
  Object.keys(_types).forEach(function (key) {
16
18
  if (key === "default" || key === "__esModule") return;
@@ -1 +1 @@
1
- {"version":3,"names":["_interact","require","exports","Interact","add","remove","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames"],"sources":["../../src/index.ts"],"sourcesContent":["export { Interact, add, remove } from './interact';\n\nexport * from './types';\n"],"mappings":";;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAAmDC,OAAA,CAAAC,QAAA,GAAAH,SAAA,CAAAG,QAAA;AAAAD,OAAA,CAAAE,GAAA,GAAAJ,SAAA,CAAAI,GAAA;AAAAF,OAAA,CAAAG,MAAA,GAAAL,SAAA,CAAAK,MAAA;AAEnD,IAAAC,MAAA,GAAAL,OAAA;AAAAM,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAR,OAAA,IAAAA,OAAA,CAAAQ,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAR,OAAA,CAAAQ,GAAA,IAAAJ,MAAA,CAAAI,GAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["_Interact","require","exports","Interact","_add","add","_remove","remove","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames"],"sources":["../../src/index.ts"],"sourcesContent":["export { Interact } from './core/Interact';\nexport { add } from './core/add';\nexport { remove } from './core/remove';\n\nexport * from './types';\n"],"mappings":";;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAA2CC,OAAA,CAAAC,QAAA,GAAAH,SAAA,CAAAG,QAAA;AAC3C,IAAAC,IAAA,GAAAH,OAAA;AAAiCC,OAAA,CAAAG,GAAA,GAAAD,IAAA,CAAAC,GAAA;AACjC,IAAAC,OAAA,GAAAL,OAAA;AAAuCC,OAAA,CAAAK,MAAA,GAAAD,OAAA,CAAAC,MAAA;AAEvC,IAAAC,MAAA,GAAAP,OAAA;AAAAQ,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAV,OAAA,IAAAA,OAAA,CAAAU,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAV,OAAA,CAAAU,GAAA,IAAAJ,MAAA,CAAAI,GAAA;AAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../src/types.ts"],"sourcesContent":["import type {\n NamedEffect,\n MotionKeyframeEffect,\n CustomEffect,\n RangeOffset,\n ScrubTransitionEasing,\n MotionAnimationOptions,\n} from '@wix/motion';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n 'wix-interact-element': React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLElement>,\n HTMLElement\n > & {\n 'data-wix-path'?: string;\n };\n }\n }\n}\n\nexport type TriggerType =\n | 'hover'\n | 'click'\n | 'viewEnter'\n | 'pageVisible'\n | 'animationEnd'\n | 'viewProgress'\n | 'pointerMove';\n\nexport type ViewEnterType = 'once' | 'repeat' | 'alternate';\n\nexport type TransitionMethod = 'add' | 'remove' | 'toggle' | 'clear';\n\nexport type StateParams = {\n method: TransitionMethod;\n};\n\nexport type PointerTriggerParams = {\n type?: ViewEnterType | 'state';\n};\n\nexport type ViewEnterParams = {\n type?: ViewEnterType;\n threshold?: number;\n inset?: string;\n};\n\nexport type PointerMoveParams = {\n hitArea?: 'root' | 'self';\n};\n\nexport type AnimationEndParams = {\n effectId: string;\n};\n\nexport type TriggerParams =\n | StateParams\n | PointerTriggerParams\n | ViewEnterParams\n | PointerMoveParams\n | AnimationEndParams;\n\ntype Fill = 'none' | 'forwards' | 'backwards' | 'both';\n\ntype EffectEffectProperty =\n | {\n keyframeEffect: MotionKeyframeEffect;\n }\n | {\n namedEffect: NamedEffect;\n }\n | {\n customEffect: CustomEffect;\n };\n\nexport type TimeEffect = {\n target?: string;\n duration: number;\n easing?: string;\n iterations?: number;\n alternate?: boolean;\n fill?: Fill;\n reversed?: boolean;\n delay?: number;\n effectId?: string;\n} & EffectEffectProperty;\n\nexport type ScrubEffect = {\n target?: string;\n easing?: string;\n iterations?: number;\n alternate?: boolean;\n fill?: Fill;\n reversed?: boolean;\n rangeStart?: RangeOffset;\n rangeEnd?: RangeOffset;\n centeredToTarget?: boolean;\n transitionDuration?: number;\n transitionDelay?: number;\n transitionEasing?: ScrubTransitionEasing;\n} & EffectEffectProperty;\n\nexport type TransitionOptions = {\n duration?: number;\n delay?: number;\n easing?: string;\n};\n\nexport type StyleProperty = {\n name: string;\n value: string;\n};\n\nexport type TransitionProperty = StyleProperty & TransitionOptions;\n\nexport type TransitionEffect = {\n target?: string;\n effectId?: string;\n} & {\n transition?: TransitionOptions & {\n styleProperties: StyleProperty[];\n };\n transitionProperties?: TransitionProperty[];\n};\n\nexport type EffectRef = {\n target?: string;\n effectId: string;\n conditions?: string[];\n};\n\nexport type Effect = (TimeEffect | ScrubEffect | TransitionEffect) & {\n conditions?: string[];\n};\n\nexport type Condition = {\n type: 'media' | 'container';\n predicate?: string;\n};\n\ntype InteractionTrigger = {\n source: string;\n trigger: TriggerType;\n params?: TriggerParams;\n conditions?: string[];\n};\n\nexport type Interaction = InteractionTrigger & {\n effects: ((Effect | EffectRef) & { interactionId?: string })[];\n};\n\nexport type InteractConfig = {\n effects: Record<string, Effect>;\n conditions?: Record<string, Condition>;\n interactions: Interaction[];\n};\n\nexport type AnimationOptions<T extends 'time' | 'scrub'> =\n MotionAnimationOptions<T> & EffectEffectProperty;\n\n/// ////////////////////////////////////////////////////////\n/// ////////////////////////////////////////////////////////\n/// ////////////////////////////////////////////////////////\n\nexport interface IWixInteractElement extends HTMLElement {\n _internals: (ElementInternals & { states: Set<string> }) | null;\n connected: boolean;\n sheet: CSSStyleSheet | null;\n connectedCallback(): void;\n disconnectedCallback(): void;\n connect(path?: string): void;\n renderStyle(cssText: string): void;\n toggleEffect(effectId: string, method: StateParams['method']): void;\n}\n\nexport type InteractionParamsTypes = {\n hover: StateParams | PointerTriggerParams;\n click: StateParams | PointerTriggerParams;\n viewEnter: ViewEnterParams;\n pageVisible: ViewEnterParams;\n animationEnd: AnimationEndParams;\n viewProgress: ViewEnterParams;\n pointerMove: PointerMoveParams;\n};\n\nexport type InteractionHandlerModule<T extends TriggerType> = {\n add: (\n source: HTMLElement,\n target: HTMLElement,\n effect: Effect,\n options: InteractionParamsTypes[T],\n reducedMotion?: boolean,\n ) => void;\n remove: (element: HTMLElement) => void;\n};\n\nexport type TriggerHandlerMap<T extends TriggerType> = {\n [K in T]: InteractionHandlerModule<K>;\n};\n\nexport type HandlerObject = {\n source: HTMLElement;\n target: HTMLElement;\n cleanup: () => void;\n handler?: () => void;\n};\n\nexport type HandlerObjectMap = WeakMap<HTMLElement, Set<HandlerObject>>;\n\nexport type InteractCache = {\n effects: {\n [effectId: string]: Effect;\n };\n conditions: {\n [conditionId: string]: Condition;\n };\n interactions: {\n [path: string]: {\n triggers: Interaction[];\n effects: Record<\n string,\n (InteractionTrigger & { effect: Effect | EffectRef })[]\n >;\n interactionIds: Set<string>;\n };\n };\n};\n\nexport type CreateTransitionCSSParams = {\n path: string;\n effectId: string;\n transition?: TransitionEffect['transition'];\n properties?: TransitionProperty[];\n childSelector?: string;\n};\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["../../src/types.ts"],"sourcesContent":["import type {\n NamedEffect,\n CustomEffect,\n RangeOffset,\n ScrubTransitionEasing,\n MotionAnimationOptions,\n} from '@wix/motion';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n 'wix-interact-element': React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLElement>,\n HTMLElement\n > & {\n 'data-wix-path'?: string;\n };\n }\n }\n}\n\nexport type TriggerType =\n | 'hover'\n | 'click'\n | 'viewEnter'\n | 'pageVisible'\n | 'animationEnd'\n | 'viewProgress'\n | 'pointerMove';\n\nexport type ViewEnterType = 'once' | 'repeat' | 'alternate';\n\nexport type TransitionMethod = 'add' | 'remove' | 'toggle' | 'clear';\n\nexport type StateParams = {\n method: TransitionMethod;\n};\n\nexport type PointerTriggerParams = {\n type?: ViewEnterType | 'state';\n};\n\nexport type ViewEnterParams = {\n type?: ViewEnterType;\n threshold?: number;\n inset?: string;\n};\n\nexport type PointerMoveParams = {\n hitArea?: 'root' | 'self';\n};\n\nexport type AnimationEndParams = {\n effectId: string;\n};\n\nexport type TriggerParams =\n | StateParams\n | PointerTriggerParams\n | ViewEnterParams\n | PointerMoveParams\n | AnimationEndParams;\n\ntype Fill = 'none' | 'forwards' | 'backwards' | 'both';\n\ntype MotionKeyframeEffect = {\n name: string;\n keyframes: Keyframe[];\n};\n\ntype EffectEffectProperty =\n | {\n keyframeEffect: MotionKeyframeEffect;\n }\n | {\n namedEffect: NamedEffect;\n }\n | {\n customEffect: CustomEffect;\n };\n\nexport type TimeEffect = {\n key?: string;\n duration: number;\n easing?: string;\n iterations?: number;\n alternate?: boolean;\n fill?: Fill;\n reversed?: boolean;\n delay?: number;\n effectId?: string;\n} & EffectEffectProperty;\n\nexport type ScrubEffect = {\n key?: string;\n easing?: string;\n iterations?: number;\n alternate?: boolean;\n fill?: Fill;\n reversed?: boolean;\n rangeStart?: RangeOffset;\n rangeEnd?: RangeOffset;\n centeredToTarget?: boolean;\n transitionDuration?: number;\n transitionDelay?: number;\n transitionEasing?: ScrubTransitionEasing;\n} & EffectEffectProperty;\n\nexport type TransitionOptions = {\n duration?: number;\n delay?: number;\n easing?: string;\n};\n\nexport type StyleProperty = {\n name: string;\n value: string;\n};\n\nexport type TransitionProperty = StyleProperty & TransitionOptions;\n\nexport type TransitionEffect = {\n key?: string;\n effectId?: string;\n} & {\n transition?: TransitionOptions & {\n styleProperties: StyleProperty[];\n };\n transitionProperties?: TransitionProperty[];\n};\n\nexport type EffectRef = {\n key?: string;\n effectId: string;\n listContainer?: string;\n conditions?: string[];\n selector?: string;\n};\n\nexport type Effect = (TimeEffect | ScrubEffect | TransitionEffect) & {\n listContainer?: string;\n conditions?: string[];\n selector?: string;\n};\n\nexport type Condition = {\n type: 'media' | 'container';\n predicate?: string;\n};\n\nexport type InteractionTrigger = {\n key: string;\n listContainer?: string;\n trigger: TriggerType;\n params?: TriggerParams;\n conditions?: string[];\n selector?: string;\n};\n\nexport type Interaction = InteractionTrigger & {\n effects: ((Effect | EffectRef) & { interactionId?: string })[];\n};\n\nexport type InteractConfig = {\n effects: Record<string, Effect>;\n conditions?: Record<string, Condition>;\n interactions: Interaction[];\n};\n\nexport type AnimationOptions<T extends 'time' | 'scrub'> =\n MotionAnimationOptions<T> & EffectEffectProperty;\n\n/// ////////////////////////////////////////////////////////\n/// ////////////////////////////////////////////////////////\n/// ////////////////////////////////////////////////////////\n\nexport interface IWixInteractElement extends HTMLElement {\n _internals: (ElementInternals & { states: Set<string> }) | null;\n connected: boolean;\n sheet: CSSStyleSheet | null;\n _observers: WeakMap<HTMLElement, MutationObserver>;\n connectedCallback(): void;\n disconnectedCallback(): void;\n connect(path?: string): void;\n renderStyle(cssRules: string[]): void;\n toggleEffect(effectId: string, method: StateParams['method']): void;\n watchChildList(listContainer: string): void;\n}\n\nexport type InteractionParamsTypes = {\n hover: StateParams | PointerTriggerParams;\n click: StateParams | PointerTriggerParams;\n viewEnter: ViewEnterParams;\n pageVisible: ViewEnterParams;\n animationEnd: AnimationEndParams;\n viewProgress: ViewEnterParams;\n pointerMove: PointerMoveParams;\n};\n\nexport type InteractionHandlerModule<T extends TriggerType> = {\n add: (\n source: HTMLElement,\n target: HTMLElement,\n effect: Effect,\n options: InteractionParamsTypes[T],\n reducedMotion?: boolean,\n ) => void;\n remove: (element: HTMLElement) => void;\n};\n\nexport type TriggerHandlerMap<T extends TriggerType> = {\n [K in T]: InteractionHandlerModule<K>;\n};\n\nexport type HandlerObject = {\n source: HTMLElement;\n target: HTMLElement;\n cleanup: () => void;\n handler?: () => void;\n};\n\nexport type HandlerObjectMap = WeakMap<HTMLElement, Set<HandlerObject>>;\n\nexport type InteractCache = {\n effects: {\n [effectId: string]: Effect;\n };\n conditions: {\n [conditionId: string]: Condition;\n };\n interactions: {\n [path: string]: {\n triggers: Interaction[];\n effects: Record<\n string,\n (InteractionTrigger & { effect: Effect | EffectRef })[]\n >;\n interactionIds: Set<string>;\n selectors: Set<string>;\n };\n };\n};\n\nexport type CreateTransitionCSSParams = {\n key: string;\n effectId: string;\n transition?: TransitionEffect['transition'];\n properties?: TransitionProperty[];\n childSelector?: string;\n};\n"],"mappings":"","ignoreList":[]}
package/dist/cjs/utils.js CHANGED
@@ -10,11 +10,11 @@ function generateId() {
10
10
  );
11
11
  }
12
12
  function createTransitionCSS({
13
- path,
13
+ key,
14
14
  effectId,
15
15
  transition,
16
16
  properties,
17
- childSelector = ':first-child'
17
+ childSelector = '> :first-child'
18
18
  }) {
19
19
  var _properties2;
20
20
  let transitions = [];
@@ -39,16 +39,18 @@ function createTransitionCSS({
39
39
  transitions = ((_properties = properties) == null ? void 0 : _properties.filter(property => property.duration).map(property => `${property.name} ${property.duration}ms ${(0, _motion.getEasing)(property.easing) || 'ease'}${property.delay ? ` ${property.delay}ms` : ''}`)) || [];
40
40
  }
41
41
  const styleProperties = ((_properties2 = properties) == null ? void 0 : _properties2.map(property => `${property.name}: ${property.value};`)) || [];
42
- const escapedPath = path.replace(/"/g, "'");
43
- return `
44
- ${transitions.length ? `@media (prefers-reduced-motion: no-preference) { [data-wix-path="${escapedPath}"] > ${childSelector} {
45
- transition: ${transitions.join(', ')};
46
- } }` : ''}
47
- :is(:state(${effectId}), :--${effectId}) > ${childSelector},
48
- [data-wix-interact-effect~="${effectId}"] > ${childSelector} {
42
+ const escapedKey = key.replace(/"/g, "'");
43
+ const result = [`:is(:state(${effectId}), :--${effectId}) ${childSelector},
44
+ [data-wix-interact-effect~="${effectId}"] ${childSelector} {
49
45
  ${styleProperties.join(`
50
46
  `)}
51
- }`;
47
+ }`];
48
+ if (transitions.length) {
49
+ result.push(`@media (prefers-reduced-motion: no-preference) { [data-wix-path="${escapedKey}"] ${childSelector} {
50
+ transition: ${transitions.join(', ')};
51
+ } }`);
52
+ }
53
+ return result;
52
54
  }
53
55
  function getMediaQuery(conditionNames, conditions) {
54
56
  const conditionContent = (conditionNames || []).filter(conditionName => {
@@ -1 +1 @@
1
- {"version":3,"names":["_motion","require","generateId","replace","c","String","fromCharCode","crypto","getRandomValues","Uint8Array","createTransitionCSS","path","effectId","transition","properties","childSelector","_properties2","transitions","styleProperties","duration","easing","delay","hasCustomPropertiesTransition","some","styleProperty","name","startsWith","getEasing","map","_properties","filter","property","value","escapedPath","length","join","getMediaQuery","conditionNames","conditions","conditionContent","conditionName","_conditions$condition","type","predicate","condition","mql","window","matchMedia"],"sources":["../../src/utils.ts"],"sourcesContent":["import { getEasing } from '@wix/motion';\nimport type { Condition, CreateTransitionCSSParams } from './types';\n\nexport function generateId() {\n return 'wi-12343210'.replace(\n /\\d/g,\n (c) =>\n String.fromCharCode(\n (+c ^\n (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (+c / 4)))) +\n 97,\n ), // 97 for \"a\"\n );\n}\n\nexport function createTransitionCSS({\n path,\n effectId,\n transition,\n properties,\n childSelector = ':first-child',\n}: CreateTransitionCSSParams): string {\n let transitions: string[] = [];\n\n if (transition?.styleProperties) {\n const { duration, easing, delay } = transition;\n\n if (duration) {\n const hasCustomPropertiesTransition = transition.styleProperties.some(\n (styleProperty) => styleProperty.name.startsWith('--'),\n );\n\n if (hasCustomPropertiesTransition) {\n // If there are custom properties in the transition, we need to fall back to Viewer's legacy implementation\n transitions = [\n `all ${duration}ms ${getEasing(easing || 'ease')}${\n delay ? ` ${delay}ms` : ''\n }`,\n 'visibility 0s',\n ];\n } else {\n transitions = transition.styleProperties.map(\n (styleProperty) =>\n `${styleProperty.name} ${duration}ms ${getEasing(\n easing || 'ease',\n )}${delay ? ` ${delay}ms` : ''}`,\n );\n }\n }\n\n properties = transition.styleProperties;\n } else {\n transitions =\n properties\n ?.filter((property) => property.duration)\n .map(\n (property) =>\n `${property.name} ${property.duration}ms ${\n getEasing(property.easing) || 'ease'\n }${property.delay ? ` ${property.delay}ms` : ''}`,\n ) || [];\n }\n\n const styleProperties =\n properties?.map((property) => `${property.name}: ${property.value};`) || [];\n const escapedPath = path.replace(/\"/g, \"'\");\n\n return `\n ${\n transitions.length\n ? `@media (prefers-reduced-motion: no-preference) { [data-wix-path=\"${escapedPath}\"] > ${childSelector} {\n transition: ${transitions.join(', ')};\n } }`\n : ''\n }\n :is(:state(${effectId}), :--${effectId}) > ${childSelector},\n [data-wix-interact-effect~=\"${effectId}\"] > ${childSelector} {\n ${styleProperties.join(`\n `)}\n }`;\n}\n\nexport function getMediaQuery(\n conditionNames: string[] | undefined,\n conditions: Record<string, Condition>,\n) {\n const conditionContent = (conditionNames || [])\n .filter((conditionName) => {\n return (\n conditions[conditionName]?.type === 'media' &&\n conditions[conditionName].predicate\n );\n })\n .map((conditionName) => {\n return conditions[conditionName].predicate;\n })\n .join(') and (');\n\n const condition = conditionContent && `(${conditionContent})`;\n const mql = condition && window.matchMedia(condition);\n\n if (mql) {\n return mql;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAGO,SAASC,UAAUA,CAAA,EAAG;EAC3B,OAAO,aAAa,CAACC,OAAO,CAC1B,KAAK,EACJC,CAAC,IACAC,MAAM,CAACC,YAAY,CACjB,CAAC,CAACF,CAAC,GACAG,MAAM,CAACC,eAAe,CAAC,IAAIC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAI,EAAE,IAAK,CAACL,CAAC,GAAG,CAAI,IACjE,EACJ,CAAC,CAAE;EACP,CAAC;AACH;AAEO,SAASM,mBAAmBA,CAAC;EAClCC,IAAI;EACJC,QAAQ;EACRC,UAAU;EACVC,UAAU;EACVC,aAAa,GAAG;AACS,CAAC,EAAU;EAAA,IAAAC,YAAA;EACpC,IAAIC,WAAqB,GAAG,EAAE;EAE9B,IAAIJ,UAAU,YAAVA,UAAU,CAAEK,eAAe,EAAE;IAC/B,MAAM;MAAEC,QAAQ;MAAEC,MAAM;MAAEC;IAAM,CAAC,GAAGR,UAAU;IAE9C,IAAIM,QAAQ,EAAE;MACZ,MAAMG,6BAA6B,GAAGT,UAAU,CAACK,eAAe,CAACK,IAAI,CAClEC,aAAa,IAAKA,aAAa,CAACC,IAAI,CAAC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MAAM,GACd,oEAAoED,WAAW,QAAQlB,aAAa;AAC9G,oBAAoBE,WAAW,CAACkB,IAAI,CAAC,IAAI,CAAC;AAC1C,QAAQ,GACE,EAAE;AACZ,iBACiBvB,QAAQ,SAASA,QAAQ,OAAOG,aAAa;AAC9D,kCAAkCH,QAAQ,QAAQG,aAAa;AAC/D,QAAQG,eAAe,CAACiB,IAAI,CAAC;AAC7B,OAAO,CAAC;AACR,MAAM;AACN;AAEO,SAASC,aAAaA,CAC3BC,cAAoC,EACpCC,UAAqC,EACrC;EACA,MAAMC,gBAAgB,GAAG,CAACF,cAAc,IAAI,EAAE,EAC3CP,MAAM,CAAEU,aAAa,IAAK;IAAA,IAAAC,qBAAA;IACzB,OACE,EAAAA,qBAAA,GAAAH,UAAU,CAACE,aAAa,CAAC,qBAAzBC,qBAAA,CAA2BC,IAAI,MAAK,OAAO,IAC3CJ,UAAU,CAACE,aAAa,CAAC,CAACG,SAAS;EAEvC,CAAC,CAAC,CACDf,GAAG,CAAEY,aAAa,IAAK;IACtB,OAAOF,UAAU,CAACE,aAAa,CAAC,CAACG,SAAS;EAC5C,CAAC,CAAC,CACDR,IAAI,CAAC,SAAS,CAAC;EAElB,MAAMS,SAAS,GAAGL,gBAAgB,IAAI,IAAIA,gBAAgB,GAAG;EAC7D,MAAMM,GAAG,GAAGD,SAAS,IAAIE,MAAM,CAACC,UAAU,CAACH,SAAS,CAAC;EAErD,IAAIC,GAAG,EAAE;IACP,OAAOA,GAAG;EACZ;AACF","ignoreList":[]}
1
+ {"version":3,"names":["_motion","require","generateId","replace","c","String","fromCharCode","crypto","getRandomValues","Uint8Array","createTransitionCSS","key","effectId","transition","properties","childSelector","_properties2","transitions","styleProperties","duration","easing","delay","hasCustomPropertiesTransition","some","styleProperty","name","startsWith","getEasing","map","_properties","filter","property","value","escapedKey","result","join","length","push","getMediaQuery","conditionNames","conditions","conditionContent","conditionName","_conditions$condition","type","predicate","condition","mql","window","matchMedia"],"sources":["../../src/utils.ts"],"sourcesContent":["import { getEasing } from '@wix/motion';\nimport type { Condition, CreateTransitionCSSParams } from './types';\n\nexport function generateId() {\n return 'wi-12343210'.replace(\n /\\d/g,\n (c) =>\n String.fromCharCode(\n (+c ^\n (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (+c / 4)))) +\n 97,\n ), // 97 for \"a\"\n );\n}\n\nexport function createTransitionCSS({\n key,\n effectId,\n transition,\n properties,\n childSelector = '> :first-child',\n}: CreateTransitionCSSParams): string[] {\n let transitions: string[] = [];\n\n if (transition?.styleProperties) {\n const { duration, easing, delay } = transition;\n\n if (duration) {\n const hasCustomPropertiesTransition = transition.styleProperties.some(\n (styleProperty) => styleProperty.name.startsWith('--'),\n );\n\n if (hasCustomPropertiesTransition) {\n // If there are custom properties in the transition, we need to fall back to Viewer's legacy implementation\n transitions = [\n `all ${duration}ms ${getEasing(easing || 'ease')}${\n delay ? ` ${delay}ms` : ''\n }`,\n 'visibility 0s',\n ];\n } else {\n transitions = transition.styleProperties.map(\n (styleProperty) =>\n `${styleProperty.name} ${duration}ms ${getEasing(\n easing || 'ease',\n )}${delay ? ` ${delay}ms` : ''}`,\n );\n }\n }\n\n properties = transition.styleProperties;\n } else {\n transitions =\n properties\n ?.filter((property) => property.duration)\n .map(\n (property) =>\n `${property.name} ${property.duration}ms ${\n getEasing(property.easing) || 'ease'\n }${property.delay ? ` ${property.delay}ms` : ''}`,\n ) || [];\n }\n\n const styleProperties =\n properties?.map((property) => `${property.name}: ${property.value};`) || [];\n const escapedKey = key.replace(/\"/g, \"'\");\n\n const result = [\n `:is(:state(${effectId}), :--${effectId}) ${childSelector},\n [data-wix-interact-effect~=\"${effectId}\"] ${childSelector} {\n ${styleProperties.join(`\n `)}\n }`,\n ];\n\n if (transitions.length) {\n result.push(`@media (prefers-reduced-motion: no-preference) { [data-wix-path=\"${escapedKey}\"] ${childSelector} {\n transition: ${transitions.join(', ')};\n } }`);\n }\n return result;\n}\n\nexport function getMediaQuery(\n conditionNames: string[] | undefined,\n conditions: Record<string, Condition>,\n) {\n const conditionContent = (conditionNames || [])\n .filter((conditionName) => {\n return (\n conditions[conditionName]?.type === 'media' &&\n conditions[conditionName].predicate\n );\n })\n .map((conditionName) => {\n return conditions[conditionName].predicate;\n })\n .join(') and (');\n\n const condition = conditionContent && `(${conditionContent})`;\n const mql = condition && window.matchMedia(condition);\n\n if (mql) {\n return mql;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAGO,SAASC,UAAUA,CAAA,EAAG;EAC3B,OAAO,aAAa,CAACC,OAAO,CAC1B,KAAK,EACJC,CAAC,IACAC,MAAM,CAACC,YAAY,CACjB,CAAC,CAACF,CAAC,GACAG,MAAM,CAACC,eAAe,CAAC,IAAIC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAI,EAAE,IAAK,CAACL,CAAC,GAAG,CAAI,IACjE,EACJ,CAAC,CAAE;EACP,CAAC;AACH;AAEO,SAASM,mBAAmBA,CAAC;EAClCC,GAAG;EACHC,QAAQ;EACRC,UAAU;EACVC,UAAU;EACVC,aAAa,GAAG;AACS,CAAC,EAAY;EAAA,IAAAC,YAAA;EACtC,IAAIC,WAAqB,GAAG,EAAE;EAE9B,IAAIJ,UAAU,YAAVA,UAAU,CAAEK,eAAe,EAAE;IAC/B,MAAM;MAAEC,QAAQ;MAAEC,MAAM;MAAEC;IAAM,CAAC,GAAGR,UAAU;IAE9C,IAAIM,QAAQ,EAAE;MACZ,MAAMG,6BAA6B,GAAGT,UAAU,CAACK,eAAe,CAACK,IAAI,CAClEC,aAAa,IAAKA,aAAa,CAACC,IAAI,CAACC,UAAU,CAAC,IAAI,CACvD,CAAC;MAED,IAAIJ,6BAA6B,EAAE;QACjC;QACAL,WAAW,GAAG,CACZ,OAAOE,QAAQ,MAAM,IAAAQ,iBAAS,EAACP,MAAM,IAAI,MAAM,CAAC,GAC9CC,KAAK,GAAG,IAAIA,KAAK,IAAI,GAAG,EAAE,E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,CAAC,oEAAoEJ,UAAU,MAAMlB,aAAa;AACjH,oBAAoBE,WAAW,CAACkB,IAAI,CAAC,IAAI,CAAC;AAC1C,QAAQ,CAAC;EACP;EACA,OAAOD,MAAM;AACf;AAEO,SAASI,aAAaA,CAC3BC,cAAoC,EACpCC,UAAqC,EACrC;EACA,MAAMC,gBAAgB,GAAG,CAACF,cAAc,IAAI,EAAE,EAC3CT,MAAM,CAAEY,aAAa,IAAK;IAAA,IAAAC,qBAAA;IACzB,OACE,EAAAA,qBAAA,GAAAH,UAAU,CAACE,aAAa,CAAC,qBAAzBC,qBAAA,CAA2BC,IAAI,MAAK,OAAO,IAC3CJ,UAAU,CAACE,aAAa,CAAC,CAACG,SAAS;EAEvC,CAAC,CAAC,CACDjB,GAAG,CAAEc,aAAa,IAAK;IACtB,OAAOF,UAAU,CAACE,aAAa,CAAC,CAACG,SAAS;EAC5C,CAAC,CAAC,CACDV,IAAI,CAAC,SAAS,CAAC;EAElB,MAAMW,SAAS,GAAGL,gBAAgB,IAAI,IAAIA,gBAAgB,GAAG;EAC7D,MAAMM,GAAG,GAAGD,SAAS,IAAIE,MAAM,CAACC,UAAU,CAACH,SAAS,CAAC;EAErD,IAAIC,GAAG,EAAE;IACP,OAAOA,GAAG;EACZ;AACF","ignoreList":[]}
@@ -1,5 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import { add, remove } from './interact';
2
+ import { add, addListItems } from './core/add';
3
+ import { remove, removeListItems } from './core/remove';
3
4
  export const WIX_INTERACT_EFFECT_DATA_ATTR = 'wixInteractEffect';
4
5
  export function getWixInteractElement() {
5
6
  let checkedForLegacyStateSyntax = false;
@@ -10,8 +11,10 @@ export function getWixInteractElement() {
10
11
  _defineProperty(this, "_internals", void 0);
11
12
  _defineProperty(this, "connected", void 0);
12
13
  _defineProperty(this, "sheet", void 0);
14
+ _defineProperty(this, "_observers", void 0);
13
15
  this.connected = false;
14
16
  this.sheet = null;
17
+ this._observers = new WeakMap();
15
18
  if (this.attachInternals) {
16
19
  this._internals = this.attachInternals();
17
20
  if (!checkedForLegacyStateSyntax) {
@@ -32,37 +35,45 @@ export function getWixInteractElement() {
32
35
  this.connect();
33
36
  }
34
37
  disconnectedCallback() {
35
- const path = this.dataset.wixPath;
36
- if (path) {
37
- remove(path);
38
+ const key = this.dataset.wixPath;
39
+ if (key) {
40
+ remove(key);
38
41
  }
39
42
  if (this.sheet) {
40
43
  const index = document.adoptedStyleSheets.indexOf(this.sheet);
41
44
  document.adoptedStyleSheets.splice(index, 1);
42
45
  }
46
+ this._observers = new WeakMap();
43
47
  this.connected = false;
44
48
  }
45
- connect(path) {
49
+ connect(key) {
46
50
  if (this.connected) {
47
51
  return;
48
52
  }
49
- path = path || this.dataset.wixPath;
50
- if (!path) {
51
- console.warn('WixInteractElement: No path provided');
53
+ key = key || this.dataset.wixPath;
54
+ if (!key) {
55
+ console.warn('WixInteractElement: No key provided');
52
56
  return;
53
57
  }
54
- if (this.firstElementChild) {
55
- this.connected = add(this, path);
58
+ this.connected = add(this, key);
59
+ }
60
+ renderStyle(cssRules) {
61
+ if (!this.sheet) {
62
+ this.sheet = new CSSStyleSheet();
63
+ void this.sheet.replace(cssRules.join('\n'));
64
+ document.adoptedStyleSheets.push(this.sheet);
56
65
  } else {
57
- console.warn('WixInteractElement: No child element found');
66
+ let position = this.sheet.cssRules.length;
67
+ for (const cssRule of cssRules) {
68
+ try {
69
+ this.sheet.insertRule(cssRule, position);
70
+ position++;
71
+ } catch (e) {
72
+ console.error(e);
73
+ }
74
+ }
58
75
  }
59
76
  }
60
- renderStyle(cssText) {
61
- const sheet = new CSSStyleSheet();
62
- this.sheet = sheet;
63
- sheet.replace(cssText);
64
- document.adoptedStyleSheets.push(sheet);
65
- }
66
77
  toggleEffect(effectId, method) {
67
78
  if (isLegacyStateSyntax) {
68
79
  effectId = `--${effectId}`;
@@ -92,6 +103,39 @@ export function getWixInteractElement() {
92
103
  this.dataset[WIX_INTERACT_EFFECT_DATA_ATTR] = Array.from(currentEffects).join(' ');
93
104
  }
94
105
  }
106
+ watchChildList(listContainer) {
107
+ const list = this.querySelector(listContainer);
108
+ if (list) {
109
+ // TODO: we can probably improve this and use less observers, this impl. uses one per container element
110
+ let observer = this._observers.get(list);
111
+ if (!observer) {
112
+ observer = new MutationObserver(this._childListChangeHandler.bind(this, listContainer));
113
+ this._observers.set(list, observer);
114
+ observer.observe(list, {
115
+ childList: true
116
+ });
117
+ }
118
+ }
119
+ }
120
+ _childListChangeHandler(listContainer, entries) {
121
+ const key = this.dataset.wixPath;
122
+ const removedElements = [];
123
+ const addedElements = [];
124
+ entries.forEach(entry => {
125
+ entry.removedNodes.forEach(el => {
126
+ if (el instanceof HTMLElement) {
127
+ removedElements.push(el);
128
+ }
129
+ });
130
+ entry.addedNodes.forEach(el => {
131
+ if (el instanceof HTMLElement) {
132
+ addedElements.push(el);
133
+ }
134
+ });
135
+ });
136
+ removeListItems(removedElements);
137
+ key && addListItems(this, key, listContainer, addedElements);
138
+ }
95
139
  };
96
140
  }
97
141
  //# sourceMappingURL=WixInteractElement.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["add","remove","WIX_INTERACT_EFFECT_DATA_ATTR","getWixInteractElement","checkedForLegacyStateSyntax","isLegacyStateSyntax","WixInteractElement","HTMLElement","constructor","_defineProperty","connected","sheet","attachInternals","_internals","states","delete","e","connectedCallback","connect","disconnectedCallback","path","dataset","wixPath","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,SAASA,GAAG,EAAEC,MAAM,QAAQ,YAAY;AAExC,OAAO,MAAMC,6BAA6B,GAAG,mBAAmB;AAEhE,OAAO,SAASC,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;MAACC,eAAA;MAAAA,eAAA;MAAAA,eAAA;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,IAAI,CAACR,2BAA2B,EAAE;UAChCA,2BAA2B,GAAG,IAAI;UAElC,IAAI;YACF,IAAI,CAACS,UAAU,CAACC,MAAM,CAACd,GAAG,CAAC,MAAM,CAAC;YAClC,IAAI,CAACa,UAAU,CAACC,MAAM,CAACC,MAAM,CAAC,MAAM,CAAC;UACvC,CAAC,CAAC,OAAOC,CAAC,EAAE;YACVX,mBAAmB,GAAG,IAAI;UAC5B;QACF;MACF,CAAC,MAAM;QACLD,2BAA2B,GAAG,IAAI,CAAC,CAAC;QACpC,IAAI,CAACS,UAAU,GAAG,IAAI;MACxB;IACF;IACAI,iBAAiBA,CAAA,EAAG;MAClB,IAAI,CAACC,OAAO,CAAC,CAAC;IAChB;IAEAC,oBAAoBA,CAAA,EAAG;MACrB,MAAMC,IAAI,GAAG,IAAI,CAACC,OAAO,CAACC,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BAA6B,CAAC,GACzC2C,KAAK,CAACC,IAAI,CAACJ,cAAc,CAAC,CAACK,IAAI,CAAC,GAAG,CAAC;MACxC;IACF;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["add","addListItems","remove","removeListItems","WIX_INTERACT_EFFECT_DATA_ATTR","getWixInteractElement","checkedForLegacyStateSyntax","isLegacyStateSyntax","WixInteractElement","HTMLElement","constructor","_defineProperty","connected","sheet","_observers","WeakMap","attachInternals","_internals","states","delete","e","connectedCallback","connect","disconnectedCallback","key","dataset","wixPath","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"],"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,SAASA,GAAG,EAAEC,YAAY,QAAQ,YAAY;AAC9C,SAASC,MAAM,EAAEC,eAAe,QAAQ,eAAe;AAEvD,OAAO,MAAMC,6BAA6B,GAAG,mBAAmB;AAEhE,OAAO,SAASC,qBAAqBA,CAAA,EAAG;EACtC,IAAIC,2BAA2B,GAAG,KAAK;EACvC,IAAIC,mBAAmB,GAAG,KAAK;EAE/B,OAAO,MAAMC,kBAAkB,SAASC,WAAW,CAAC;IAMlDC,WAAWA,CAAA,EAAG;MACZ,KAAK,CAAC,CAAC;MAACC,eAAA;MAAAA,eAAA;MAAAA,eAAA;MAAAA,eAAA;MAER,IAAI,CAACC,SAAS,GAAG,KAAK;MACtB,IAAI,CAACC,KAAK,GAAG,IAAI;MACjB,IAAI,CAACC,UAAU,GAAG,IAAIC,OAAO,CAAC,CAAC;MAE/B,IAAI,IAAI,CAACC,eAAe,EAAE;QACxB,IAAI,CAACC,UAAU,GAAG,IAAI,CAACD,eAAe,CAAC,CAEtC;QAED,IAAI,CAACV,2BAA2B,EAAE;UAChCA,2BAA2B,GAAG,IAAI;UAElC,IAAI;YACF,IAAI,CAACW,UAAU,CAACC,MAAM,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