@wix/interact 1.92.0 → 1.94.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/dist/cjs/InteractElement.js +1 -0
- package/dist/cjs/InteractElement.js.map +1 -1
- package/dist/cjs/__tests__/interact.spec.js +334 -0
- package/dist/cjs/__tests__/interact.spec.js.map +1 -1
- package/dist/cjs/__tests__/viewEnter.spec.js +23 -6
- package/dist/cjs/__tests__/viewEnter.spec.js.map +1 -1
- package/dist/cjs/core/add.js +12 -8
- package/dist/cjs/core/add.js.map +1 -1
- package/dist/cjs/handlers/animationEnd.js +9 -0
- package/dist/cjs/handlers/animationEnd.js.map +1 -1
- package/dist/cjs/handlers/click.js +19 -3
- package/dist/cjs/handlers/click.js.map +1 -1
- package/dist/cjs/handlers/hover.js +19 -3
- package/dist/cjs/handlers/hover.js.map +1 -1
- package/dist/cjs/handlers/viewEnter.js +10 -1
- package/dist/cjs/handlers/viewEnter.js.map +1 -1
- package/dist/cjs/handlers/viewProgress.js +24 -8
- package/dist/cjs/handlers/viewProgress.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils.js +34 -4
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/InteractElement.js +1 -0
- package/dist/esm/InteractElement.js.map +1 -1
- package/dist/esm/__tests__/interact.spec.js +335 -0
- package/dist/esm/__tests__/interact.spec.js.map +1 -1
- package/dist/esm/__tests__/viewEnter.spec.js +23 -6
- package/dist/esm/__tests__/viewEnter.spec.js.map +1 -1
- package/dist/esm/core/add.js +13 -9
- package/dist/esm/core/add.js.map +1 -1
- package/dist/esm/handlers/animationEnd.js +9 -0
- package/dist/esm/handlers/animationEnd.js.map +1 -1
- package/dist/esm/handlers/click.js +19 -3
- package/dist/esm/handlers/click.js.map +1 -1
- package/dist/esm/handlers/hover.js +19 -3
- package/dist/esm/handlers/hover.js.map +1 -1
- package/dist/esm/handlers/viewEnter.js +10 -1
- package/dist/esm/handlers/viewEnter.js.map +1 -1
- package/dist/esm/handlers/viewProgress.js +24 -8
- package/dist/esm/handlers/viewProgress.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.js +33 -4
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/__tests__/viewEnter.spec.d.ts +7 -0
- package/dist/types/types.d.ts +3 -1
- package/dist/types/utils.d.ts +2 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getAnimation","effectToAnimationOptions","addHandlerToMap","removeElementFromHandlerMap","fastdom","SAFE_OBSERVER_CONFIG","root","rootMargin","threshold","observers","handlerMap","WeakMap","elementFirstRun","WeakSet","elementObserverMap","viewEnterOptions","setOptions","options","getObserver","isSafeMode","key","JSON","stringify","config","inset","observer","IntersectionObserver","entries","forEach","entry","target","isFirstRun","has","add","useSafeViewEnter","isIntersecting","measure","_entry$rootBounds","sourceHeight","boundingClientRect","height","rootHeight","rootBounds","Array","isArray","Math","min","needsSafeObserver","mutate","unobserve","safeObserver","set","observe","handlers","get","_ref","source","handler","type","delete","addViewEnterHandler","effect","globalOptions","animation","undefined","reducedMotion","isCSS","onFinish","dataset","motionEnter","play","cleanup","currentObserver","cancel","handlerObj","removeViewEnterHandler","element","remove"],"sources":["../../../src/handlers/viewEnter.ts"],"sourcesContent":["import type { AnimationGroup } from '@wix/motion';\nimport { getAnimation } from '@wix/motion';\nimport type {\n TimeEffect,\n HandlerObjectMap,\n ViewEnterParams,\n InteractionGlobalOptions,\n} from '../types';\nimport {\n effectToAnimationOptions,\n addHandlerToMap,\n removeElementFromHandlerMap,\n} from './utilities';\nimport fastdom from 'fastdom';\n\nconst SAFE_OBSERVER_CONFIG: IntersectionObserverInit = {\n root: null,\n rootMargin: '0px 0px -10% 0px',\n threshold: [0],\n};\n\nconst observers: Record<string, IntersectionObserver> = {};\nconst handlerMap = new WeakMap() as HandlerObjectMap;\nconst elementFirstRun = new WeakSet<HTMLElement>();\nconst elementObserverMap = new WeakMap<HTMLElement, IntersectionObserver>();\nlet viewEnterOptions: Partial<ViewEnterParams> = {};\n\nfunction setOptions(options: Partial<ViewEnterParams>) {\n viewEnterOptions = options;\n}\n\nfunction getObserver(options: ViewEnterParams, isSafeMode: boolean = false) {\n const key = JSON.stringify({ ...options, isSafeMode });\n\n if (observers[key]) {\n return observers[key];\n }\n\n const config: IntersectionObserverInit = isSafeMode\n ? SAFE_OBSERVER_CONFIG\n : {\n root: null,\n rootMargin: options.inset\n ? `${options.inset} 0px ${options.inset}`\n : '0px',\n threshold: options.threshold,\n };\n\n const observer = new IntersectionObserver((entries) => {\n entries.forEach((entry) => {\n const target = entry.target as HTMLElement;\n const isFirstRun = !elementFirstRun.has(target);\n\n if (isFirstRun) {\n elementFirstRun.add(target);\n\n if (options.useSafeViewEnter && !entry.isIntersecting) {\n fastdom.measure(() => {\n const sourceHeight = entry.boundingClientRect.height;\n const rootHeight = entry.rootBounds?.height;\n\n if (!rootHeight) {\n return;\n }\n\n const threshold = Array.isArray(options.threshold)\n ? Math.min(...options.threshold)\n : options.threshold;\n\n const needsSafeObserver =\n threshold && sourceHeight * threshold > rootHeight;\n\n if (needsSafeObserver) {\n fastdom.mutate(() => {\n observer.unobserve(target);\n const safeObserver = getObserver(options, true);\n elementObserverMap.set(target, safeObserver);\n safeObserver.observe(target);\n });\n }\n });\n return;\n }\n }\n\n if (entry.isIntersecting) {\n const handlers = handlerMap.get(target);\n\n handlers?.forEach(({ source, handler }) => {\n if (source === entry.target) {\n handler!();\n }\n });\n\n if (options.type === 'once') {\n observer.unobserve(entry.target);\n elementFirstRun.delete(target);\n }\n }\n });\n }, config);\n\n observers[key] = observer;\n\n return observer;\n}\n\nfunction addViewEnterHandler(\n source: HTMLElement,\n target: HTMLElement,\n effect: TimeEffect,\n options: ViewEnterParams = {},\n globalOptions?: InteractionGlobalOptions,\n) {\n const
|
|
1
|
+
{"version":3,"names":["getAnimation","effectToAnimationOptions","addHandlerToMap","removeElementFromHandlerMap","fastdom","SAFE_OBSERVER_CONFIG","root","rootMargin","threshold","observers","handlerMap","WeakMap","elementFirstRun","WeakSet","elementObserverMap","viewEnterOptions","setOptions","options","getObserver","isSafeMode","key","JSON","stringify","config","inset","observer","IntersectionObserver","entries","forEach","entry","target","isFirstRun","has","add","useSafeViewEnter","isIntersecting","measure","_entry$rootBounds","sourceHeight","boundingClientRect","height","rootHeight","rootBounds","Array","isArray","Math","min","needsSafeObserver","mutate","unobserve","safeObserver","set","observe","handlers","get","_ref","source","handler","type","delete","addViewEnterHandler","effect","globalOptions","animation","undefined","reducedMotion","isCSS","onFinish","dataset","motionEnter","selectorCondition","matches","play","cleanup","currentObserver","cancel","handlerObj","removeViewEnterHandler","element","remove"],"sources":["../../../src/handlers/viewEnter.ts"],"sourcesContent":["import type { AnimationGroup } from '@wix/motion';\nimport { getAnimation } from '@wix/motion';\nimport type {\n TimeEffect,\n HandlerObjectMap,\n ViewEnterParams,\n InteractionGlobalOptions,\n} from '../types';\nimport {\n effectToAnimationOptions,\n addHandlerToMap,\n removeElementFromHandlerMap,\n} from './utilities';\nimport fastdom from 'fastdom';\n\nconst SAFE_OBSERVER_CONFIG: IntersectionObserverInit = {\n root: null,\n rootMargin: '0px 0px -10% 0px',\n threshold: [0],\n};\n\nconst observers: Record<string, IntersectionObserver> = {};\nconst handlerMap = new WeakMap() as HandlerObjectMap;\nconst elementFirstRun = new WeakSet<HTMLElement>();\nconst elementObserverMap = new WeakMap<HTMLElement, IntersectionObserver>();\nlet viewEnterOptions: Partial<ViewEnterParams> = {};\n\nfunction setOptions(options: Partial<ViewEnterParams>) {\n viewEnterOptions = options;\n}\n\nfunction getObserver(options: ViewEnterParams, isSafeMode: boolean = false) {\n const key = JSON.stringify({ ...options, isSafeMode });\n\n if (observers[key]) {\n return observers[key];\n }\n\n const config: IntersectionObserverInit = isSafeMode\n ? SAFE_OBSERVER_CONFIG\n : {\n root: null,\n rootMargin: options.inset\n ? `${options.inset} 0px ${options.inset}`\n : '0px',\n threshold: options.threshold,\n };\n\n const observer = new IntersectionObserver((entries) => {\n entries.forEach((entry) => {\n const target = entry.target as HTMLElement;\n const isFirstRun = !elementFirstRun.has(target);\n\n if (isFirstRun) {\n elementFirstRun.add(target);\n\n if (options.useSafeViewEnter && !entry.isIntersecting) {\n fastdom.measure(() => {\n const sourceHeight = entry.boundingClientRect.height;\n const rootHeight = entry.rootBounds?.height;\n\n if (!rootHeight) {\n return;\n }\n\n const threshold = Array.isArray(options.threshold)\n ? Math.min(...options.threshold)\n : options.threshold;\n\n const needsSafeObserver =\n threshold && sourceHeight * threshold > rootHeight;\n\n if (needsSafeObserver) {\n fastdom.mutate(() => {\n observer.unobserve(target);\n const safeObserver = getObserver(options, true);\n elementObserverMap.set(target, safeObserver);\n safeObserver.observe(target);\n });\n }\n });\n return;\n }\n }\n\n if (entry.isIntersecting) {\n const handlers = handlerMap.get(target);\n\n handlers?.forEach(({ source, handler }) => {\n if (source === entry.target) {\n handler!();\n }\n });\n\n if (options.type === 'once') {\n observer.unobserve(entry.target);\n elementFirstRun.delete(target);\n }\n }\n });\n }, config);\n\n observers[key] = observer;\n\n return observer;\n}\n\nfunction addViewEnterHandler(\n source: HTMLElement,\n target: HTMLElement,\n effect: TimeEffect,\n options: ViewEnterParams = {},\n globalOptions?: InteractionGlobalOptions,\n) {\n const animation = getAnimation(\n target,\n effectToAnimationOptions(effect),\n undefined,\n globalOptions?.reducedMotion,\n ) as AnimationGroup;\n\n if (!animation) {\n return;\n }\n\n const observer = getObserver({ ...viewEnterOptions, ...options });\n\n if (animation?.isCSS && options.type === 'once') {\n animation.onFinish(() => {\n target.dataset.motionEnter = 'done';\n });\n }\n const { selectorCondition } = globalOptions || {};\n const handler = () => {\n if (selectorCondition && !target.matches(selectorCondition)) {\n return;\n }\n animation.play(() => {\n if (!animation.isCSS) {\n target.dataset.motionEnter = 'done';\n }\n });\n };\n\n const cleanup = () => {\n const currentObserver = elementObserverMap.get(source) || observer;\n currentObserver.unobserve(source);\n animation.cancel();\n elementFirstRun.delete(source);\n elementObserverMap.delete(source);\n };\n const handlerObj = { source, target, handler, cleanup };\n\n addHandlerToMap(handlerMap, source, handlerObj);\n addHandlerToMap(handlerMap, target, handlerObj);\n\n elementObserverMap.set(source, observer);\n observer.observe(source);\n}\n\nfunction removeViewEnterHandler(element: HTMLElement) {\n removeElementFromHandlerMap(handlerMap, element);\n}\n\nexport default {\n add: addViewEnterHandler,\n remove: removeViewEnterHandler,\n setOptions,\n};\n"],"mappings":"AACA,SAASA,YAAY,QAAQ,aAAa;AAO1C,SACEC,wBAAwB,EACxBC,eAAe,EACfC,2BAA2B,QACtB,aAAa;AACpB,OAAOC,OAAO,MAAM,SAAS;AAE7B,MAAMC,oBAA8C,GAAG;EACrDC,IAAI,EAAE,IAAI;EACVC,UAAU,EAAE,kBAAkB;EAC9BC,SAAS,EAAE,CAAC,CAAC;AACf,CAAC;AAED,MAAMC,SAA+C,GAAG,CAAC,CAAC;AAC1D,MAAMC,UAAU,GAAG,IAAIC,OAAO,CAAC,CAAqB;AACpD,MAAMC,eAAe,GAAG,IAAIC,OAAO,CAAc,CAAC;AAClD,MAAMC,kBAAkB,GAAG,IAAIH,OAAO,CAAoC,CAAC;AAC3E,IAAII,gBAA0C,GAAG,CAAC,CAAC;AAEnD,SAASC,UAAUA,CAACC,OAAiC,EAAE;EACrDF,gBAAgB,GAAGE,OAAO;AAC5B;AAEA,SAASC,WAAWA,CAACD,OAAwB,EAAEE,UAAmB,EAAU;EAAA,IAA7BA,UAAmB;IAAnBA,UAAmB,GAAG,KAAK;EAAA;EACxE,MAAMC,GAAG,GAAGC,IAAI,CAACC,SAAS,CAAC;IAAE,GAAGL,OAAO;IAAEE;EAAW,CAAC,CAAC;EAEtD,IAAIV,SAAS,CAACW,GAAG,CAAC,EAAE;IAClB,OAAOX,SAAS,CAACW,GAAG,CAAC;EACvB;EAEA,MAAMG,MAAgC,GAAGJ,UAAU,GAC/Cd,oBAAoB,GACpB;IACEC,IAAI,EAAE,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sBAAsBA,CAACC,OAAoB,EAAE;EACpD3E,2BAA2B,CAACO,UAAU,EAAEoE,OAAO,CAAC;AAClD;AAEA,eAAe;EACb7C,GAAG,EAAE2B,mBAAmB;EACxBmB,MAAM,EAAEF,sBAAsB;EAC9B7D;AACF,CAAC","ignoreList":[]}
|
|
@@ -15,11 +15,24 @@ function addViewProgressHandler(source, target, effect, __, globalOptions) {
|
|
|
15
15
|
element: source
|
|
16
16
|
};
|
|
17
17
|
const effectOptions = effectToAnimationOptions(effect);
|
|
18
|
+
let cleanup;
|
|
18
19
|
if ('ViewTimeline' in window) {
|
|
19
20
|
// Use ViewTimeline for modern browsers
|
|
20
21
|
const animationGroup = getWebAnimation(target, effectOptions, triggerParams);
|
|
21
22
|
if (animationGroup) {
|
|
22
23
|
animationGroup.play();
|
|
24
|
+
cleanup = () => {
|
|
25
|
+
animationGroup.ready.then(() => {
|
|
26
|
+
animationGroup.cancel();
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const handlerObj = {
|
|
30
|
+
source,
|
|
31
|
+
target,
|
|
32
|
+
cleanup
|
|
33
|
+
};
|
|
34
|
+
addHandlerToMap(scrollManagerMap, source, handlerObj);
|
|
35
|
+
addHandlerToMap(scrollManagerMap, target, handlerObj);
|
|
23
36
|
}
|
|
24
37
|
} else {
|
|
25
38
|
const scene = getScrubScene(target, effectOptions, triggerParams);
|
|
@@ -34,21 +47,24 @@ function addViewProgressHandler(source, target, effect, __, globalOptions) {
|
|
|
34
47
|
root: document.body,
|
|
35
48
|
...scrollOptionsGetter()
|
|
36
49
|
});
|
|
37
|
-
|
|
50
|
+
cleanup = () => {
|
|
38
51
|
scroll.destroy();
|
|
39
52
|
};
|
|
40
|
-
const handlerObj = {
|
|
41
|
-
source,
|
|
42
|
-
target,
|
|
43
|
-
cleanup
|
|
44
|
-
};
|
|
45
|
-
addHandlerToMap(scrollManagerMap, source, handlerObj);
|
|
46
|
-
addHandlerToMap(scrollManagerMap, target, handlerObj);
|
|
47
53
|
Promise.all(scenes.map(s => s.ready || Promise.resolve())).then(() => {
|
|
48
54
|
scroll.start();
|
|
49
55
|
});
|
|
50
56
|
}
|
|
51
57
|
}
|
|
58
|
+
if (!cleanup) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const handlerObj = {
|
|
62
|
+
source,
|
|
63
|
+
target,
|
|
64
|
+
cleanup
|
|
65
|
+
};
|
|
66
|
+
addHandlerToMap(scrollManagerMap, source, handlerObj);
|
|
67
|
+
addHandlerToMap(scrollManagerMap, target, handlerObj);
|
|
52
68
|
}
|
|
53
69
|
function removeViewProgressHandler(element) {
|
|
54
70
|
removeElementFromHandlerMap(scrollManagerMap, element);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getWebAnimation","getScrubScene","Scroll","effectToAnimationOptions","addHandlerToMap","removeElementFromHandlerMap","scrollManagerMap","WeakMap","scrollOptionsGetter","registerOptionsGetter","getter","addViewProgressHandler","source","target","effect","__","globalOptions","reducedMotion","triggerParams","trigger","element","effectOptions","window","animationGroup","play","scene","scenes","Array","isArray","scroll","viewSource","observeViewportEntry","observeViewportResize","observeSourcesResize","root","document","body","
|
|
1
|
+
{"version":3,"names":["getWebAnimation","getScrubScene","Scroll","effectToAnimationOptions","addHandlerToMap","removeElementFromHandlerMap","scrollManagerMap","WeakMap","scrollOptionsGetter","registerOptionsGetter","getter","addViewProgressHandler","source","target","effect","__","globalOptions","reducedMotion","triggerParams","trigger","element","effectOptions","cleanup","window","animationGroup","play","ready","then","cancel","handlerObj","scene","scenes","Array","isArray","scroll","viewSource","observeViewportEntry","observeViewportResize","observeSourcesResize","root","document","body","destroy","Promise","all","map","s","resolve","start","removeViewProgressHandler","add","remove"],"sources":["../../../src/handlers/viewProgress.ts"],"sourcesContent":["import type { AnimationGroup, ScrubScrollScene } from '@wix/motion';\nimport { getWebAnimation, getScrubScene } from '@wix/motion';\nimport { Scroll, scrollConfig } from 'fizban';\nimport type {\n ViewEnterParams,\n ScrubEffect,\n HandlerObjectMap,\n InteractionGlobalOptions,\n} from '../types';\nimport {\n effectToAnimationOptions,\n addHandlerToMap,\n removeElementFromHandlerMap,\n} from './utilities';\n\nconst scrollManagerMap = new WeakMap() as HandlerObjectMap;\nlet scrollOptionsGetter: () => Partial<scrollConfig> = () => ({});\n\nfunction registerOptionsGetter(getter: () => scrollConfig) {\n scrollOptionsGetter = getter;\n}\n\nfunction addViewProgressHandler(\n source: HTMLElement,\n target: HTMLElement,\n effect: ScrubEffect,\n __: ViewEnterParams,\n globalOptions?: InteractionGlobalOptions,\n): void {\n if (globalOptions?.reducedMotion) {\n return;\n }\n\n const triggerParams = {\n trigger: 'view-progress' as const,\n element: source,\n };\n\n const effectOptions = effectToAnimationOptions(effect);\n let cleanup;\n if ('ViewTimeline' in window) {\n // Use ViewTimeline for modern browsers\n const animationGroup = getWebAnimation(\n target,\n effectOptions,\n triggerParams,\n );\n\n if (animationGroup) {\n animationGroup.play();\n\n cleanup = () => {\n (animationGroup as AnimationGroup).ready.then(() => {\n (animationGroup as AnimationGroup).cancel();\n });\n };\n\n const handlerObj = { source, target, cleanup };\n addHandlerToMap(scrollManagerMap, source, handlerObj);\n addHandlerToMap(scrollManagerMap, target, handlerObj);\n }\n } else {\n const scene = getScrubScene(target, effectOptions, triggerParams);\n\n if (scene) {\n const scenes = Array.isArray(scene) ? scene : [scene];\n const scroll = new Scroll({\n viewSource: source,\n scenes,\n observeViewportEntry: false,\n observeViewportResize: false,\n observeSourcesResize: true,\n root: document.body,\n ...scrollOptionsGetter(),\n });\n\n cleanup = () => {\n scroll.destroy();\n };\n\n Promise.all(\n (scenes as ScrubScrollScene[]).map((s) => s.ready || Promise.resolve()),\n ).then(() => {\n scroll.start();\n });\n }\n }\n if (!cleanup) {\n return;\n }\n\n const handlerObj = { source, target, cleanup };\n\n addHandlerToMap(scrollManagerMap, source, handlerObj);\n addHandlerToMap(scrollManagerMap, target, handlerObj);\n}\n\nfunction removeViewProgressHandler(element: HTMLElement): void {\n removeElementFromHandlerMap(scrollManagerMap, element);\n}\n\nexport default {\n add: addViewProgressHandler,\n remove: removeViewProgressHandler,\n registerOptionsGetter,\n};\n"],"mappings":"AACA,SAASA,eAAe,EAAEC,aAAa,QAAQ,aAAa;AAC5D,SAASC,MAAM,QAAsB,QAAQ;AAO7C,SACEC,wBAAwB,EACxBC,eAAe,EACfC,2BAA2B,QACtB,aAAa;AAEpB,MAAMC,gBAAgB,GAAG,IAAIC,OAAO,CAAC,CAAqB;AAC1D,IAAIC,mBAAgD,GAAGA,CAAA,MAAO,CAAC,CAAC,CAAC;AAEjE,SAASC,qBAAqBA,CAACC,MAA0B,EAAE;EACzDF,mBAAmB,GAAGE,MAAM;AAC9B;AAEA,SAASC,sBAAsBA,CAC7BC,MAAmB,EACnBC,MAAmB,EACnBC,MAAmB,EACnBC,EAAmB,EACnBC,aAAwC,EAClC;EACN,IAAIA,aAAa,YAAbA,aAAa,CAAEC,aAAa,EAAE;IAChC;EACF;EAEA,MAAMC,aAAa,GAAG;IACpBC,OAAO,EAAE,eAAwB;IACjCC,OAAO,EAAER;EACX,CAAC;EAED,MAAMS,aAAa,GAAGlB,wBAAwB,CAACW,MAAM,CAAC;EACtD,IAAIQ,OAAO;EACX,IAAI,cAAc,IAAIC,MAAM,EAAE;IAC5B;IACA,MAAMC,cAAc,GAAGxB,eAAe,CACpCa,MAAM,EACNQ,aAAa,EACbH,aACF,CAAC;IAED,IAAIM,cAAc,EAAE;MAClBA,cAAc,CAACC,IAAI,CAAC,CAAC;MAErBH,OAAO,GAAGA,CAAA,KAAM;QACbE,cAAc,CAAoBE,KAAK,CAACC,IAAI,CAAC,MAAM;UACjDH,cAAc,CAAoBI,MAAM,CAAC,CAAC;QAC7C,CAAC,CAAC;MACJ,CAAC;MAED,MAAMC,UAAU,GAAG;QAAEjB,MAAM;QAAEC,MAAM;QAAES;MAAQ,CAAC;MAC9ClB,eAAe,CAACE,gBAAgB,EAAEM,MAAM,EAAEiB,UAAU,CAAC;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GAAG,EAAEvC,sBAAsB;EAC3BwC,MAAM,EAAEF,yBAAyB;EACjCxC;AACF,CAAC","ignoreList":[]}
|
package/dist/esm/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 '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 | 'activate'\n | 'interest';\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 useSafeViewEnter?: boolean;\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 activate: StateParams | PointerTriggerParams;\n interest: StateParams | PointerTriggerParams;\n};\n\nexport type InteractionGlobalOptions = {\n reducedMotion?: boolean;\n allowA11yTriggers?: boolean;\n};\n\nexport type InteractionHandlerModule<T extends TriggerType> = {\n registerOptionsGetter?: (getter: () => any) => void;\n add: (\n source: HTMLElement,\n target: HTMLElement,\n effect: Effect,\n options: InteractionParamsTypes[T],\n globalOptions?: InteractionGlobalOptions,\n ) => void;\n remove: (element: HTMLElement) => void;\n};\n\nexport type ViewEnterHandlerModule = InteractionHandlerModule<'viewEnter'> & {\n setOptions: (options: Partial<ViewEnterParams>) => 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":[]}
|
|
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 | 'activate'\n | 'interest';\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 useSafeViewEnter?: boolean;\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' | 'selector';\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 activate: StateParams | PointerTriggerParams;\n interest: StateParams | PointerTriggerParams;\n};\n\nexport type InteractionGlobalOptions = {\n reducedMotion?: boolean;\n allowA11yTriggers?: boolean;\n selectorCondition?: string;\n};\n\nexport type InteractionHandlerModule<T extends TriggerType> = {\n registerOptionsGetter?: (getter: () => any) => void;\n add: (\n source: HTMLElement,\n target: HTMLElement,\n effect: Effect,\n options: InteractionParamsTypes[T],\n globalOptions?: InteractionGlobalOptions,\n ) => void;\n remove: (element: HTMLElement) => void;\n};\n\nexport type ViewEnterHandlerModule = InteractionHandlerModule<'viewEnter'> & {\n setOptions: (options: Partial<ViewEnterParams>) => 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 selectorCondition?: string;\n};\n"],"mappings":"","ignoreList":[]}
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { getEasing } from '@wix/motion';
|
|
2
|
+
/**
|
|
3
|
+
* Applies a selector condition predicate to a base selector.
|
|
4
|
+
* - If `&` is in the predicate, replace `&` with the base selector
|
|
5
|
+
* - If no `&`, assume `&<predicate>` (append predicate to base selector)
|
|
6
|
+
*/
|
|
7
|
+
function applySelectorCondition(baseSelector, predicate) {
|
|
8
|
+
if (predicate.includes('&')) {
|
|
9
|
+
return predicate.replace(/&/g, baseSelector);
|
|
10
|
+
}
|
|
11
|
+
return `${baseSelector}${predicate}`;
|
|
12
|
+
}
|
|
2
13
|
export function generateId() {
|
|
3
14
|
return 'wi-12343210'.replace(/\d/g, c => String.fromCharCode((+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4) + 97) // 97 for "a"
|
|
4
15
|
);
|
|
@@ -10,7 +21,8 @@ export function createTransitionCSS(_ref) {
|
|
|
10
21
|
effectId,
|
|
11
22
|
transition,
|
|
12
23
|
properties,
|
|
13
|
-
childSelector = '> :first-child'
|
|
24
|
+
childSelector = '> :first-child',
|
|
25
|
+
selectorCondition
|
|
14
26
|
} = _ref;
|
|
15
27
|
let transitions = [];
|
|
16
28
|
if (transition != null && transition.styleProperties) {
|
|
@@ -35,13 +47,21 @@ export function createTransitionCSS(_ref) {
|
|
|
35
47
|
}
|
|
36
48
|
const styleProperties = ((_properties2 = properties) == null ? void 0 : _properties2.map(property => `${property.name}: ${property.value};`)) || [];
|
|
37
49
|
const escapedKey = key.replace(/"/g, "'");
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
|
|
51
|
+
// Build selectors, applying condition if present
|
|
52
|
+
const stateSelector = `:is(:state(${effectId}), :--${effectId}) ${childSelector}`;
|
|
53
|
+
const dataAttrSelector = `[data-interact-effect~="${effectId}"] ${childSelector}`;
|
|
54
|
+
const finalStateSelector = selectorCondition ? applySelectorCondition(stateSelector, selectorCondition) : stateSelector;
|
|
55
|
+
const finalDataAttrSelector = selectorCondition ? applySelectorCondition(dataAttrSelector, selectorCondition) : dataAttrSelector;
|
|
56
|
+
const result = [`${finalStateSelector},
|
|
57
|
+
${finalDataAttrSelector} {
|
|
40
58
|
${styleProperties.join(`
|
|
41
59
|
`)}
|
|
42
60
|
}`];
|
|
43
61
|
if (transitions.length) {
|
|
44
|
-
|
|
62
|
+
const transitionSelector = `[data-interact-key="${escapedKey}"] ${childSelector}`;
|
|
63
|
+
const finalTransitionSelector = selectorCondition ? applySelectorCondition(transitionSelector, selectorCondition) : transitionSelector;
|
|
64
|
+
result.push(`@media (prefers-reduced-motion: no-preference) { ${finalTransitionSelector} {
|
|
45
65
|
transition: ${transitions.join(', ')};
|
|
46
66
|
} }`);
|
|
47
67
|
}
|
|
@@ -60,4 +80,13 @@ export function getMediaQuery(conditionNames, conditions) {
|
|
|
60
80
|
return mql;
|
|
61
81
|
}
|
|
62
82
|
}
|
|
83
|
+
export function getSelectorCondition(conditionNames, conditions) {
|
|
84
|
+
for (const name of conditionNames || []) {
|
|
85
|
+
const condition = conditions[name];
|
|
86
|
+
if ((condition == null ? void 0 : condition.type) === 'selector' && condition.predicate) {
|
|
87
|
+
return condition.predicate;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
63
92
|
//# sourceMappingURL=utils.js.map
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getEasing","
|
|
1
|
+
{"version":3,"names":["getEasing","applySelectorCondition","baseSelector","predicate","includes","replace","generateId","c","String","fromCharCode","crypto","getRandomValues","Uint8Array","createTransitionCSS","_ref","_properties2","key","effectId","transition","properties","childSelector","selectorCondition","transitions","styleProperties","duration","easing","delay","hasCustomPropertiesTransition","some","styleProperty","name","startsWith","map","_properties","filter","property","value","escapedKey","stateSelector","dataAttrSelector","finalStateSelector","finalDataAttrSelector","result","join","length","transitionSelector","finalTransitionSelector","push","getMediaQuery","conditionNames","conditions","conditionContent","conditionName","_conditions$condition","type","condition","mql","window","matchMedia","getSelectorCondition"],"sources":["../../src/utils.ts"],"sourcesContent":["import { getEasing } from '@wix/motion';\nimport type { Condition, CreateTransitionCSSParams } from './types';\n\n/**\n * Applies a selector condition predicate to a base selector.\n * - If `&` is in the predicate, replace `&` with the base selector\n * - If no `&`, assume `&<predicate>` (append predicate to base selector)\n */\nfunction applySelectorCondition(\n baseSelector: string,\n predicate: string,\n): string {\n if (predicate.includes('&')) {\n return predicate.replace(/&/g, baseSelector);\n }\n return `${baseSelector}${predicate}`;\n}\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 selectorCondition,\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 // Build selectors, applying condition if present\n const stateSelector = `:is(:state(${effectId}), :--${effectId}) ${childSelector}`;\n const dataAttrSelector = `[data-interact-effect~=\"${effectId}\"] ${childSelector}`;\n\n const finalStateSelector = selectorCondition\n ? applySelectorCondition(stateSelector, selectorCondition)\n : stateSelector;\n const finalDataAttrSelector = selectorCondition\n ? applySelectorCondition(dataAttrSelector, selectorCondition)\n : dataAttrSelector;\n\n const result = [\n `${finalStateSelector},\n ${finalDataAttrSelector} {\n ${styleProperties.join(`\n `)}\n }`,\n ];\n\n if (transitions.length) {\n const transitionSelector = `[data-interact-key=\"${escapedKey}\"] ${childSelector}`;\n const finalTransitionSelector = selectorCondition\n ? applySelectorCondition(transitionSelector, selectorCondition)\n : transitionSelector;\n result.push(`@media (prefers-reduced-motion: no-preference) { ${finalTransitionSelector} {\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\nexport function getSelectorCondition(\n conditionNames: string[] | undefined,\n conditions: Record<string, Condition>,\n): string | undefined {\n for (const name of conditionNames || []) {\n const condition = conditions[name];\n if (condition?.type === 'selector' && condition.predicate) {\n return condition.predicate;\n }\n }\n return;\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,aAAa;AAGvC;AACA;AACA;AACA;AACA;AACA,SAASC,sBAAsBA,CAC7BC,YAAoB,EACpBC,SAAiB,EACT;EACR,IAAIA,SAAS,CAACC,QAAQ,CAAC,GAAG,CAAC,EAAE;IAC3B,OAAOD,SAAS,CAACE,OAAO,CAAC,IAAI,EAAEH,YAAY,CAAC;EAC9C;EACA,OAAO,GAAGA,YAAY,GAAGC,SAAS,EAAE;AACtC;AAEA,OAAO,SAASG,UAAUA,CA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AAED,IAAI,MAAK,UAAU,IAAIC,SAAS,CAACpD,SAAS,EAAE;MACzD,OAAOoD,SAAS,CAACpD,SAAS;IAC5B;EACF;EACA;AACF","ignoreList":[]}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -97,7 +97,7 @@ export type EffectRef = EffectBase & {
|
|
|
97
97
|
};
|
|
98
98
|
export type Effect = EffectBase & (TimeEffect | ScrubEffect | TransitionEffect);
|
|
99
99
|
export type Condition = {
|
|
100
|
-
type: 'media' | 'container';
|
|
100
|
+
type: 'media' | 'container' | 'selector';
|
|
101
101
|
predicate?: string;
|
|
102
102
|
};
|
|
103
103
|
export type InteractionTrigger = {
|
|
@@ -149,6 +149,7 @@ export type InteractionParamsTypes = {
|
|
|
149
149
|
export type InteractionGlobalOptions = {
|
|
150
150
|
reducedMotion?: boolean;
|
|
151
151
|
allowA11yTriggers?: boolean;
|
|
152
|
+
selectorCondition?: string;
|
|
152
153
|
};
|
|
153
154
|
export type InteractionHandlerModule<T extends TriggerType> = {
|
|
154
155
|
registerOptionsGetter?: (getter: () => any) => void;
|
|
@@ -192,5 +193,6 @@ export type CreateTransitionCSSParams = {
|
|
|
192
193
|
transition?: TransitionEffect['transition'];
|
|
193
194
|
properties?: TransitionProperty[];
|
|
194
195
|
childSelector?: string;
|
|
196
|
+
selectorCondition?: string;
|
|
195
197
|
};
|
|
196
198
|
export {};
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Condition, CreateTransitionCSSParams } from './types';
|
|
2
2
|
export declare function generateId(): string;
|
|
3
|
-
export declare function createTransitionCSS({ key, effectId, transition, properties, childSelector, }: CreateTransitionCSSParams): string[];
|
|
3
|
+
export declare function createTransitionCSS({ key, effectId, transition, properties, childSelector, selectorCondition, }: CreateTransitionCSSParams): string[];
|
|
4
4
|
export declare function getMediaQuery(conditionNames: string[] | undefined, conditions: Record<string, Condition>): MediaQueryList | undefined;
|
|
5
|
+
export declare function getSelectorCondition(conditionNames: string[] | undefined, conditions: Record<string, Condition>): string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/interact",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.94.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "wow!Team",
|
|
6
6
|
"email": "wow-dev@wix.com"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/runtime": "^7.26.0",
|
|
35
|
-
"@wix/motion": "1.
|
|
35
|
+
"@wix/motion": "1.659.0",
|
|
36
36
|
"fastdom": "^1.0.12",
|
|
37
37
|
"fizban": "^0.7.0",
|
|
38
38
|
"kuliso": "^0.4.13"
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"wallaby": {
|
|
70
70
|
"autoDetect": true
|
|
71
71
|
},
|
|
72
|
-
"falconPackageHash": "
|
|
72
|
+
"falconPackageHash": "a0013388eb2676c7673bcb2580fa9c1e5dcca6b08066a0722d254d05"
|
|
73
73
|
}
|