@wix/interact 1.84.0 → 1.86.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 +7 -7
- package/dist/cjs/{WixInteractElement.js → InteractElement.js} +19 -16
- package/dist/cjs/InteractElement.js.map +1 -0
- package/dist/cjs/__tests__/interact.spec.js +55 -55
- package/dist/cjs/__tests__/interact.spec.js.map +1 -1
- package/dist/cjs/core/Interact.js +28 -15
- package/dist/cjs/core/Interact.js.map +1 -1
- package/dist/cjs/core/add.js +38 -31
- package/dist/cjs/core/add.js.map +1 -1
- package/dist/cjs/core/remove.js +9 -10
- package/dist/cjs/core/remove.js.map +1 -1
- package/dist/cjs/core/utilities.js +16 -0
- package/dist/cjs/core/utilities.js.map +1 -0
- package/dist/cjs/handlers/click.js +11 -4
- package/dist/cjs/handlers/click.js.map +1 -1
- package/dist/cjs/handlers/hover.js +12 -5
- package/dist/cjs/handlers/hover.js.map +1 -1
- package/dist/cjs/handlers/utilities.js +0 -2
- package/dist/cjs/handlers/utilities.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils.js +2 -2
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/{WixInteractElement.js → InteractElement.js} +17 -14
- package/dist/esm/InteractElement.js.map +1 -0
- package/dist/esm/__tests__/interact.spec.js +55 -55
- package/dist/esm/__tests__/interact.spec.js.map +1 -1
- package/dist/esm/core/Interact.js +29 -18
- package/dist/esm/core/Interact.js.map +1 -1
- package/dist/esm/core/add.js +38 -31
- package/dist/esm/core/add.js.map +1 -1
- package/dist/esm/core/remove.js +9 -10
- package/dist/esm/core/remove.js.map +1 -1
- package/dist/esm/core/utilities.js +14 -0
- package/dist/esm/core/utilities.js.map +1 -0
- package/dist/esm/handlers/click.js +11 -4
- package/dist/esm/handlers/click.js.map +1 -1
- package/dist/esm/handlers/hover.js +12 -5
- package/dist/esm/handlers/hover.js.map +1 -1
- package/dist/esm/handlers/utilities.js +0 -2
- package/dist/esm/handlers/utilities.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.js +2 -2
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/{WixInteractElement.d.ts → InteractElement.d.ts} +3 -3
- package/dist/types/core/Interact.d.ts +11 -7
- package/dist/types/core/add.d.ts +3 -3
- package/dist/types/core/utilities.d.ts +2 -0
- package/dist/types/handlers/click.d.ts +2 -2
- package/dist/types/handlers/hover.d.ts +2 -2
- package/dist/types/types.d.ts +12 -14
- package/package.json +3 -3
- package/dist/cjs/WixInteractElement.js.map +0 -1
- package/dist/esm/WixInteractElement.js.map +0 -1
|
@@ -49,20 +49,27 @@ function createTimeEffectHandler(element, effect, options, reducedMotion = false
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
function createTransitionHandler(element, {
|
|
52
|
-
effectId
|
|
52
|
+
effectId,
|
|
53
|
+
listContainer,
|
|
54
|
+
listItemSelector
|
|
53
55
|
}, options) {
|
|
54
56
|
const method = options.method || 'toggle';
|
|
55
57
|
const isToggle = method === 'toggle';
|
|
58
|
+
const shouldSetStateOnElement = !!listContainer;
|
|
56
59
|
return event => {
|
|
57
|
-
const
|
|
58
|
-
if (!
|
|
60
|
+
const interactElement = element.closest('interact-element');
|
|
61
|
+
if (!interactElement) {
|
|
59
62
|
return;
|
|
60
63
|
}
|
|
64
|
+
let item;
|
|
65
|
+
if (shouldSetStateOnElement) {
|
|
66
|
+
item = element.closest(`${listContainer} > ${listItemSelector || ''}:has(:scope)`);
|
|
67
|
+
}
|
|
61
68
|
if (event.type === 'mouseenter') {
|
|
62
69
|
const method_ = isToggle ? 'add' : method;
|
|
63
|
-
|
|
70
|
+
interactElement.toggleEffect(effectId, method_, item);
|
|
64
71
|
} else if (event.type === 'mouseleave' && isToggle) {
|
|
65
|
-
|
|
72
|
+
interactElement.toggleEffect(effectId, 'remove', item);
|
|
66
73
|
}
|
|
67
74
|
};
|
|
68
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_motion","require","_utilities","handlerMap","WeakMap","createTimeEffectHandler","element","effect","options","reducedMotion","animation","getAnimation","effectToAnimationOptions","undefined","type","initialPlay","event","play","reverse","playState","progress","isCSS","onFinish","dataset","motionEnter","cancel","pause","createTransitionHandler","effectId","method","isToggle","
|
|
1
|
+
{"version":3,"names":["_motion","require","_utilities","handlerMap","WeakMap","createTimeEffectHandler","element","effect","options","reducedMotion","animation","getAnimation","effectToAnimationOptions","undefined","type","initialPlay","event","play","reverse","playState","progress","isCSS","onFinish","dataset","motionEnter","cancel","pause","createTransitionHandler","effectId","listContainer","listItemSelector","method","isToggle","shouldSetStateOnElement","interactElement","closest","item","method_","toggleEffect","addHoverHandler","source","target","handler","isStateTrigger","once","transition","transitionProperties","cleanup","removeEventListener","handlerObj","addHandlerToMap","addEventListener","passive","addLeave","removeHoverHandler","removeElementFromHandlerMap","_default","exports","default","add","remove"],"sources":["../../../src/handlers/hover.ts"],"sourcesContent":["import type { AnimationGroup } from '@wix/motion';\nimport { getAnimation } from '@wix/motion';\nimport type {\n TimeEffect,\n TransitionEffect,\n StateParams,\n HandlerObjectMap,\n IInteractElement,\n PointerTriggerParams,\n EffectBase,\n} from '../types';\nimport {\n effectToAnimationOptions,\n addHandlerToMap,\n removeElementFromHandlerMap,\n} from './utilities';\n\nconst handlerMap = new WeakMap() as HandlerObjectMap;\n\nfunction createTimeEffectHandler(\n element: HTMLElement,\n effect: TimeEffect & EffectBase,\n options: PointerTriggerParams,\n reducedMotion: boolean = false,\n) {\n const animation = getAnimation(\n element,\n effectToAnimationOptions(effect),\n undefined,\n reducedMotion,\n ) as AnimationGroup;\n const type = options.type || 'alternate';\n let initialPlay = true;\n\n return (event: MouseEvent) => {\n if (event.type === 'mouseenter') {\n if (type === 'alternate') {\n if (initialPlay) {\n initialPlay = false;\n animation.play();\n } else {\n animation.reverse();\n }\n } else if (type === 'state') {\n if (animation.playState !== 'finished') {\n // 'idle' OR 'paused'\n animation.play();\n }\n } else {\n // type === 'repeat'\n // type === 'once'\n animation.progress(0);\n\n if (animation.isCSS) {\n animation.onFinish(() => {\n element.dataset.motionEnter = 'done';\n });\n }\n\n animation.play();\n }\n } else if (event.type === 'mouseleave') {\n if (type === 'alternate') {\n animation.reverse();\n } else if (type === 'repeat') {\n animation.cancel();\n delete element.dataset.motionEnter;\n } else if (type === 'state') {\n if (animation.playState === 'running') {\n animation.pause();\n }\n }\n }\n };\n}\n\nfunction createTransitionHandler(\n element: HTMLElement,\n {\n effectId,\n listContainer,\n listItemSelector,\n }: TransitionEffect & EffectBase & { effectId: string },\n options: StateParams,\n) {\n const method = options.method || 'toggle';\n const isToggle = method === 'toggle';\n const shouldSetStateOnElement = !!listContainer;\n\n return (event: MouseEvent) => {\n const interactElement = element.closest(\n 'interact-element',\n ) as IInteractElement;\n if (!interactElement) {\n return;\n }\n\n let item;\n if (shouldSetStateOnElement) {\n item = element.closest(\n `${listContainer} > ${listItemSelector || ''}:has(:scope)`,\n ) as HTMLElement | null;\n }\n\n if (event.type === 'mouseenter') {\n const method_ = isToggle ? 'add' : method;\n interactElement.toggleEffect(effectId, method_, item);\n } else if (event.type === 'mouseleave' && isToggle) {\n interactElement.toggleEffect(effectId, 'remove', item);\n }\n };\n}\n\nfunction addHoverHandler(\n source: HTMLElement,\n target: HTMLElement,\n effect: (TransitionEffect | TimeEffect) & EffectBase,\n options: StateParams | PointerTriggerParams = {},\n reducedMotion: boolean = false,\n) {\n let handler: (event: MouseEvent) => void;\n let isStateTrigger = false;\n let once = false;\n\n if (\n (effect as TransitionEffect).transition ||\n (effect as TransitionEffect).transitionProperties\n ) {\n handler = createTransitionHandler(\n target,\n effect as TransitionEffect & EffectBase & { effectId: string },\n options as StateParams,\n );\n isStateTrigger = true;\n } else {\n handler = createTimeEffectHandler(\n target,\n effect as TimeEffect & EffectBase,\n options as PointerTriggerParams,\n reducedMotion,\n );\n once = (options as PointerTriggerParams).type === 'once';\n }\n\n const cleanup = () => {\n source.removeEventListener('mouseenter', handler);\n source.removeEventListener('mouseleave', handler);\n };\n\n const handlerObj = { source, target, cleanup };\n\n addHandlerToMap(handlerMap, source, handlerObj);\n addHandlerToMap(handlerMap, target, handlerObj);\n\n source.addEventListener('mouseenter', handler, { passive: true, once });\n\n const addLeave = isStateTrigger\n ? ((options as StateParams).method || 'toggle') === 'toggle'\n : (options as PointerTriggerParams).type !== 'once';\n if (addLeave) {\n source.addEventListener('mouseleave', handler, { passive: true });\n }\n}\n\nfunction removeHoverHandler(element: HTMLElement) {\n removeElementFromHandlerMap(handlerMap, element);\n}\n\nexport default {\n add: addHoverHandler,\n remove: removeHoverHandler,\n};\n"],"mappings":";;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAUA,IAAAC,UAAA,GAAAD,OAAA;AAMA,MAAME,UAAU,GAAG,IAAIC,OAAO,CAAC,CAAqB;AAEpD,SAASC,uBAAuBA,CAC9BC,OAAoB,EACpBC,MAA+B,EAC/BC,OAA6B,EAC7BC,aAAsB,GAAG,KAAK,EAC9B;EACA,MAAMC,SAAS,GAAG,IAAAC,oBAAY,EAC5BL,OAAO,EACP,IAAAM,mCAAwB,EAACL,MAAM,CAAC,EAChCM,SAAS,EACTJ,aACF,CAAmB;EACnB,MAAMK,IAAI,GAAGN,OAAO,CAACM,IAAI,IAAI,WAAW;EACxC,IAAIC,WAAW,GAAG,IAAI;EAEtB,OAAQC,KAAiB,IAAK;IAC5B,IAAIA,KAAK,CAACF,IAAI,KAAK,YAAY,EAAE;MAC/B,IAAIA,IAAI,KAAK,WAAW,EAAE;QACxB,IAAIC,WAAW,EAAE;UACfA,WAAW,GAAG,KAAK;UACnBL,SAAS,CAACO,IAAI,CAAC,CAAC;QAClB,CAAC,MAAM;UACLP,SAAS,CAACQ,OAAO,CAAC,CAAC;QACrB;MACF,CAAC,MAAM,IAAIJ,IAAI,KAAK,OAAO,EAAE;QAC3B,IAAIJ,SAAS,CAACS,SAAS,KAAK,UAAU,EAAE;UACtC;UACAT,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0BAAe,EAAC/C,UAAU,EAAEqC,MAAM,EAAES,UAAU,CAAC;EAC/C,IAAAC,0BAAe,EAAC/C,UAAU,EAAEsC,MAAM,EAAEQ,UAAU,CAAC;EAE/CT,MAAM,CAACW,gBAAgB,CAAC,YAAY,EAAET,OAAO,EAAE;IAAEU,OAAO,EAAE,IAAI;IAAER;EAAK,CAAC,CAAC;EAEvE,MAAMS,QAAQ,GAAGV,cAAc,GAC3B,CAAEnC,OAAO,CAAiBuB,MAAM,IAAI,QAAQ,MAAM,QAAQ,GACzDvB,OAAO,CAA0BM,IAAI,KAAK,MAAM;EACrD,IAAIuC,QAAQ,EAAE;IACZb,MAAM,CAACW,gBAAgB,CAAC,YAAY,EAAET,OAAO,EAAE;MAAEU,OAAO,EAAE;IAAK,CAAC,CAAC;EACnE;AACF;AAEA,SAASE,kBAAkBA,CAAChD,OAAoB,EAAE;EAChD,IAAAiD,sCAA2B,EAACpD,UAAU,EAAEG,OAAO,CAAC;AAClD;AAAC,IAAAkD,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc;EACbC,GAAG,EAAEpB,eAAe;EACpBqB,MAAM,EAAEN;AACV,CAAC","ignoreList":[]}
|
|
@@ -7,7 +7,6 @@ exports.removeElementFromHandlerMap = removeElementFromHandlerMap;
|
|
|
7
7
|
function effectToAnimationOptions(effect) {
|
|
8
8
|
if (effect.duration) {
|
|
9
9
|
return {
|
|
10
|
-
type: 'TimeAnimationOptions',
|
|
11
10
|
id: '',
|
|
12
11
|
...effect
|
|
13
12
|
};
|
|
@@ -18,7 +17,6 @@ function effectToAnimationOptions(effect) {
|
|
|
18
17
|
...rest
|
|
19
18
|
} = effect;
|
|
20
19
|
return {
|
|
21
|
-
type: 'ScrubAnimationOptions',
|
|
22
20
|
id: '',
|
|
23
21
|
startOffset: rangeStart,
|
|
24
22
|
endOffset: rangeEnd,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["effectToAnimationOptions","effect","duration","
|
|
1
|
+
{"version":3,"names":["effectToAnimationOptions","effect","duration","id","rangeStart","rangeEnd","rest","startOffset","endOffset","addHandlerToMap","handlersMap","element","handlerObj","handlers","get","Set","set","add","removeElementFromHandlerMap","handlerMap","forEach","source","target","cleanup","otherKey","otherHandlers","delete"],"sources":["../../../src/handlers/utilities.ts"],"sourcesContent":["import type {\n TimeEffect,\n ScrubEffect,\n HandlerObject,\n HandlerObjectMap,\n AnimationOptions,\n} from '../types';\n\nexport function effectToAnimationOptions(effect: TimeEffect | ScrubEffect) {\n if ((effect as TimeEffect).duration) {\n return {\n id: '',\n ...effect,\n } as AnimationOptions<'time'>;\n }\n\n const { rangeStart, rangeEnd, ...rest } = effect as ScrubEffect;\n return {\n id: '',\n startOffset: rangeStart,\n endOffset: rangeEnd,\n ...rest,\n } as AnimationOptions<'scrub'>;\n}\n\nexport function addHandlerToMap(\n handlersMap: HandlerObjectMap,\n element: HTMLElement,\n handlerObj: HandlerObject,\n) {\n let handlers = handlersMap.get(element);\n\n if (!handlers) {\n handlers = new Set();\n handlersMap.set(element, handlers);\n }\n\n handlers.add(handlerObj);\n}\n\nexport function removeElementFromHandlerMap(\n handlerMap: HandlerObjectMap,\n element: HTMLElement,\n) {\n const handlers = handlerMap.get(element);\n\n handlers?.forEach((handlerObj) => {\n const { source, target, cleanup } = handlerObj;\n cleanup();\n\n const otherKey = source === element ? target : source;\n const otherHandlers = handlerMap.get(otherKey);\n otherHandlers?.delete(handlerObj);\n });\n\n handlerMap.delete(element);\n}\n"],"mappings":";;;;;;AAQO,SAASA,wBAAwBA,CAACC,MAAgC,EAAE;EACzE,IAAKA,MAAM,CAAgBC,QAAQ,EAAE;IACnC,OAAO;MACLC,EAAE,EAAE,EAAE;MACN,GAAGF;IACL,CAAC;EACH;EAEA,MAAM;IAAEG,UAAU;IAAEC,QAAQ;IAAE,GAAGC;EAAK,CAAC,GAAGL,MAAqB;EAC/D,OAAO;IACLE,EAAE,EAAE,EAAE;IACNI,WAAW,EAAEH,UAAU;IACvBI,SAAS,EAAEH,QAAQ;IACnB,GAAGC;EACL,CAAC;AACH;AAEO,SAASG,eAAeA,CAC7BC,WAA6B,EAC7BC,OAAoB,EACpBC,UAAyB,EACzB;EACA,IAAIC,QAAQ,GAAGH,WAAW,CAACI,GAAG,CAACH,OAAO,CAAC;EAEvC,IAAI,CAACE,QAAQ,EAAE;IACbA,QAAQ,GAAG,IAAIE,GAAG,CAAC,CAAC;IACpBL,WAAW,CAACM,GAAG,CAACL,OAAO,EAAEE,QAAQ,CAAC;EACpC;EAEAA,QAAQ,CAACI,GAAG,CAACL,UAAU,CAAC;AAC1B;AAEO,SAASM,2BAA2BA,CACzCC,UAA4B,EAC5BR,OAAoB,EACpB;EACA,MAAME,QAAQ,GAAGM,UAAU,CAACL,GAAG,CAACH,OAAO,CAAC;EAExCE,QAAQ,YAARA,QAAQ,CAAEO,OAAO,CAAER,UAAU,IAAK;IAChC,MAAM;MAAES,MAAM;MAAEC,MAAM;MAAEC;IAAQ,CAAC,GAAGX,UAAU;IAC9CW,OAAO,CAAC,CAAC;IAET,MAAMC,QAAQ,GAAGH,MAAM,KAAKV,OAAO,GAAGW,MAAM,GAAGD,MAAM;IACrD,MAAMI,aAAa,GAAGN,UAAU,CAACL,GAAG,CAACU,QAAQ,CAAC;IAC9CC,aAAa,YAAbA,aAAa,CAAEC,MAAM,CAACd,UAAU,CAAC;EACnC,CAAC,CAAC;EAEFO,UAAU,CAACO,MAAM,CAACf,OAAO,CAAC;AAC5B","ignoreList":[]}
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/types.ts"],"sourcesContent":["import type {\n NamedEffect,\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 '
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/types.ts"],"sourcesContent":["import type {\n NamedEffect,\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 'interact-element': React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLElement>,\n HTMLElement\n > & {\n 'data-interact-key'?: 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: (element: Element, progress: any) => void;\n };\n\nexport type TimeEffect = {\n duration: number;\n easing?: string;\n iterations?: number;\n alternate?: boolean;\n fill?: Fill;\n reversed?: boolean;\n delay?: number;\n} & EffectEffectProperty;\n\nexport type ScrubEffect = {\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 EffectBase = {\n key?: string;\n listContainer?: string;\n listItemSelector?: string;\n conditions?: string[];\n selector?: string;\n effectId?: string;\n};\n\nexport type EffectRef = EffectBase & { effectId: string };\n\nexport type Effect = EffectBase & (TimeEffect | ScrubEffect | TransitionEffect);\n\nexport type Condition = {\n type: 'media' | 'container';\n predicate?: string;\n};\n\nexport type InteractionTrigger = {\n key: string;\n listContainer?: string;\n listItemSelector?: 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 IInteractElement 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 disconnect(): void;\n renderStyle(cssRules: string[]): void;\n toggleEffect(\n effectId: string,\n method: StateParams['method'],\n item?: HTMLElement | null,\n ): 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
|
@@ -41,12 +41,12 @@ function createTransitionCSS({
|
|
|
41
41
|
const styleProperties = ((_properties2 = properties) == null ? void 0 : _properties2.map(property => `${property.name}: ${property.value};`)) || [];
|
|
42
42
|
const escapedKey = key.replace(/"/g, "'");
|
|
43
43
|
const result = [`:is(:state(${effectId}), :--${effectId}) ${childSelector},
|
|
44
|
-
[data-
|
|
44
|
+
[data-interact-effect~="${effectId}"] ${childSelector} {
|
|
45
45
|
${styleProperties.join(`
|
|
46
46
|
`)}
|
|
47
47
|
}`];
|
|
48
48
|
if (transitions.length) {
|
|
49
|
-
result.push(`@media (prefers-reduced-motion: no-preference) { [data-
|
|
49
|
+
result.push(`@media (prefers-reduced-motion: no-preference) { [data-interact-key="${escapedKey}"] ${childSelector} {
|
|
50
50
|
transition: ${transitions.join(', ')};
|
|
51
51
|
} }`);
|
|
52
52
|
}
|
package/dist/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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-
|
|
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-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-interact-key=\"${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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;EAErD,IAAIC,GAAG,EAAE;IACP,OAAOA,GAAG;EACZ;AACF","ignoreList":[]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { add, addListItems } from './core/add';
|
|
3
3
|
import { remove, removeListItems } from './core/remove';
|
|
4
|
-
export const
|
|
5
|
-
export function
|
|
4
|
+
export const INTERACT_EFFECT_DATA_ATTR = 'interactEffect';
|
|
5
|
+
export function getInteractElement() {
|
|
6
6
|
let checkedForLegacyStateSyntax = false;
|
|
7
7
|
let isLegacyStateSyntax = false;
|
|
8
|
-
return class
|
|
8
|
+
return class InteractElement extends HTMLElement {
|
|
9
9
|
constructor() {
|
|
10
10
|
super();
|
|
11
11
|
_defineProperty(this, "_internals", void 0);
|
|
@@ -38,7 +38,7 @@ export function getWixInteractElement() {
|
|
|
38
38
|
this.disconnect();
|
|
39
39
|
}
|
|
40
40
|
disconnect() {
|
|
41
|
-
const key = this.dataset.
|
|
41
|
+
const key = this.dataset.interactKey;
|
|
42
42
|
if (key) {
|
|
43
43
|
remove(key);
|
|
44
44
|
}
|
|
@@ -53,9 +53,9 @@ export function getWixInteractElement() {
|
|
|
53
53
|
if (this.connected) {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
key = key || this.dataset.
|
|
56
|
+
key = key || this.dataset.interactKey;
|
|
57
57
|
if (!key) {
|
|
58
|
-
console.warn('
|
|
58
|
+
console.warn('InteractElement: No key provided');
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
this.connected = add(this, key);
|
|
@@ -77,11 +77,14 @@ export function getWixInteractElement() {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
toggleEffect(effectId, method) {
|
|
80
|
+
toggleEffect(effectId, method, item) {
|
|
81
|
+
if (item === null) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
81
84
|
if (isLegacyStateSyntax) {
|
|
82
85
|
effectId = `--${effectId}`;
|
|
83
86
|
}
|
|
84
|
-
if (this._internals) {
|
|
87
|
+
if (this._internals && !item) {
|
|
85
88
|
if (method === 'toggle') {
|
|
86
89
|
this._internals.states.has(effectId) ? this._internals.states.delete(effectId) : this._internals.states.add(effectId);
|
|
87
90
|
} else if (method === 'add') {
|
|
@@ -92,8 +95,8 @@ export function getWixInteractElement() {
|
|
|
92
95
|
this._internals.states.clear();
|
|
93
96
|
}
|
|
94
97
|
} else {
|
|
95
|
-
var _this$dataset$
|
|
96
|
-
const currentEffects = new Set(((_this$dataset$
|
|
98
|
+
var _this$dataset$INTERAC;
|
|
99
|
+
const currentEffects = new Set(((_this$dataset$INTERAC = this.dataset[INTERACT_EFFECT_DATA_ATTR]) == null ? void 0 : _this$dataset$INTERAC.split(' ')) || []);
|
|
97
100
|
if (method === 'toggle') {
|
|
98
101
|
currentEffects.has(effectId) ? currentEffects.delete(effectId) : currentEffects.add(effectId);
|
|
99
102
|
} else if (method === 'add') {
|
|
@@ -103,7 +106,7 @@ export function getWixInteractElement() {
|
|
|
103
106
|
} else if (method === 'clear') {
|
|
104
107
|
currentEffects.clear();
|
|
105
108
|
}
|
|
106
|
-
this.dataset[
|
|
109
|
+
(item || this).dataset[INTERACT_EFFECT_DATA_ATTR] = Array.from(currentEffects).join(' ');
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
getActiveEffects() {
|
|
@@ -111,7 +114,7 @@ export function getWixInteractElement() {
|
|
|
111
114
|
const effects = Array.from(this._internals.states);
|
|
112
115
|
return isLegacyStateSyntax ? effects.map(effect => effect.replace(/^--/g, '')) : effects;
|
|
113
116
|
}
|
|
114
|
-
const raw = this.dataset[
|
|
117
|
+
const raw = this.dataset[INTERACT_EFFECT_DATA_ATTR] || '';
|
|
115
118
|
const trimmed = raw.trim();
|
|
116
119
|
return trimmed ? trimmed.split(/\s+/) : [];
|
|
117
120
|
}
|
|
@@ -130,7 +133,7 @@ export function getWixInteractElement() {
|
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
_childListChangeHandler(listContainer, entries) {
|
|
133
|
-
const key = this.dataset.
|
|
136
|
+
const key = this.dataset.interactKey;
|
|
134
137
|
const removedElements = [];
|
|
135
138
|
const addedElements = [];
|
|
136
139
|
entries.forEach(entry => {
|
|
@@ -150,4 +153,4 @@ export function getWixInteractElement() {
|
|
|
150
153
|
}
|
|
151
154
|
};
|
|
152
155
|
}
|
|
153
|
-
//# sourceMappingURL=
|
|
156
|
+
//# sourceMappingURL=InteractElement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["add","addListItems","remove","removeListItems","INTERACT_EFFECT_DATA_ATTR","getInteractElement","checkedForLegacyStateSyntax","isLegacyStateSyntax","InteractElement","HTMLElement","constructor","_defineProperty","connected","sheet","_observers","WeakMap","attachInternals","_internals","states","delete","e","connectedCallback","connect","disconnectedCallback","disconnect","key","dataset","interactKey","index","document","adoptedStyleSheets","indexOf","splice","console","warn","renderStyle","cssRules","CSSStyleSheet","replace","join","push","position","length","cssRule","insertRule","error","toggleEffect","effectId","method","item","has","clear","_this$dataset$INTERAC","currentEffects","Set","split","Array","from","getActiveEffects","effects","map","effect","raw","trimmed","trim","watchChildList","listContainer","list","querySelector","observer","get","MutationObserver","_childListChangeHandler","bind","set","observe","childList","entries","removedElements","addedElements","forEach","entry","removedNodes","el","addedNodes"],"sources":["../../src/InteractElement.ts"],"sourcesContent":["import type { StateParams } from './types';\nimport { add, addListItems } from './core/add';\nimport { remove, removeListItems } from './core/remove';\n\nexport const INTERACT_EFFECT_DATA_ATTR = 'interactEffect';\n\nexport function getInteractElement() {\n let checkedForLegacyStateSyntax = false;\n let isLegacyStateSyntax = false;\n\n return class InteractElement 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 this.disconnect();\n }\n\n disconnect() {\n const key = this.dataset.interactKey;\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.interactKey;\n\n if (!key) {\n console.warn('InteractElement: 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(\n effectId: string,\n method: StateParams['method'],\n item?: HTMLElement | null,\n ) {\n if (item === null) {\n return;\n }\n if (isLegacyStateSyntax) {\n effectId = `--${effectId}`;\n }\n\n if (this._internals && !item) {\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[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 (item || this).dataset[INTERACT_EFFECT_DATA_ATTR] =\n Array.from(currentEffects).join(' ');\n }\n }\n\n getActiveEffects(): string[] {\n if (this._internals) {\n const effects = Array.from(this._internals.states);\n return isLegacyStateSyntax\n ? effects.map((effect) => effect.replace(/^--/g, ''))\n : effects;\n }\n\n const raw = this.dataset[INTERACT_EFFECT_DATA_ATTR] || '';\n const trimmed = raw.trim();\n return trimmed ? trimmed.split(/\\s+/) : [];\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.interactKey;\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,yBAAyB,GAAG,gBAAgB;AAEzD,OAAO,SAASC,kBAAkBA,CAAA,EAAG;EACnC,IAAIC,2BAA2B,GAA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