motion-start 0.0.1
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/LICENSE.md +21 -0
- package/README.md +39 -0
- package/package.json +64 -0
- package/src/animation/UseAnimatedState.svelte +86 -0
- package/src/animation/UseAnimation.svelte +61 -0
- package/src/animation/animate.ts +78 -0
- package/src/animation/animation-controls.ts +101 -0
- package/src/animation/types.ts +83 -0
- package/src/animation/use-animated-state.ts +1 -0
- package/src/animation/use-animation.ts +74 -0
- package/src/animation/utils/default-transitions.ts +70 -0
- package/src/animation/utils/easing.ts +55 -0
- package/src/animation/utils/is-animatable.ts +42 -0
- package/src/animation/utils/is-animation-controls.ts +17 -0
- package/src/animation/utils/is-keyframes-target.ts +17 -0
- package/src/animation/utils/transitions.ts +218 -0
- package/src/animation/utils/variant-resolvers.ts +15 -0
- package/src/components/AnimatePresence/AnimatePresence.svelte +180 -0
- package/src/components/AnimatePresence/PresenceChild/PresenceChild.svelte +78 -0
- package/src/components/AnimatePresence/PresenceChild/index.ts +7 -0
- package/src/components/AnimatePresence/PresenceChild/types.ts +10 -0
- package/src/components/AnimatePresence/index.ts +46 -0
- package/src/components/AnimatePresence/types.ts +79 -0
- package/src/components/AnimatePresence/use-presence.ts +90 -0
- package/src/components/AnimateSharedLayout/AnimateSharedLayout.svelte +239 -0
- package/src/components/AnimateSharedLayout/index.ts +11 -0
- package/src/components/AnimateSharedLayout/types.ts +111 -0
- package/src/components/AnimateSharedLayout/utils/batcher.ts +96 -0
- package/src/components/AnimateSharedLayout/utils/crossfader.ts +260 -0
- package/src/components/AnimateSharedLayout/utils/rotate.ts +48 -0
- package/src/components/AnimateSharedLayout/utils/stack.ts +160 -0
- package/src/components/LazyMotion/LazyMotion.svelte +82 -0
- package/src/components/LazyMotion/index.ts +42 -0
- package/src/components/LazyMotion/types.ts +58 -0
- package/src/components/MotionConfig/MotionConfig.svelte +56 -0
- package/src/components/MotionConfig/MotionConfigScaleCorrection.ts +47 -0
- package/src/components/MotionConfig/index.ts +20 -0
- package/src/components/MotionDiv.svelte +8 -0
- package/src/context/DOMcontext.ts +21 -0
- package/src/context/LayoutGroupContext.ts +13 -0
- package/src/context/LazyContext.ts +18 -0
- package/src/context/MotionConfigContext.ts +48 -0
- package/src/context/MotionContext/MotionContext.svelte +27 -0
- package/src/context/MotionContext/MotionContextProvider.svelte +22 -0
- package/src/context/MotionContext/UseCreateMotionContext.svelte +34 -0
- package/src/context/MotionContext/create.ts +1 -0
- package/src/context/MotionContext/index.ts +14 -0
- package/src/context/MotionContext/utils.ts +29 -0
- package/src/context/PresenceContext.ts +26 -0
- package/src/context/ScaleCorrectionProvider.svelte +27 -0
- package/src/context/SharedLayoutContext.ts +29 -0
- package/src/events/UseDomEvent.svelte +67 -0
- package/src/events/UsePointerEvent.svelte +76 -0
- package/src/events/event-info.ts +69 -0
- package/src/events/types.ts +15 -0
- package/src/events/use-dom-event.ts +48 -0
- package/src/events/use-pointer-event.ts +29 -0
- package/src/events/utils.ts +25 -0
- package/src/gestures/PanSession.ts +298 -0
- package/src/gestures/UseFocusGesture.svelte +31 -0
- package/src/gestures/UseGestures.svelte +17 -0
- package/src/gestures/UseHoverGesture.svelte +40 -0
- package/src/gestures/UsePanGesture.svelte +58 -0
- package/src/gestures/UseTapGesture.svelte +77 -0
- package/src/gestures/drag/UseDrag.svelte +55 -0
- package/src/gestures/drag/UseDragControls.svelte +145 -0
- package/src/gestures/drag/VisualElementDragControls.ts +632 -0
- package/src/gestures/drag/types.ts +307 -0
- package/src/gestures/drag/use-drag-controls.ts +148 -0
- package/src/gestures/drag/use-drag.ts +15 -0
- package/src/gestures/drag/utils/constraints.ts +157 -0
- package/src/gestures/drag/utils/lock.ts +69 -0
- package/src/gestures/types.ts +257 -0
- package/src/gestures/use-focus-gesture.ts +16 -0
- package/src/gestures/use-gestures.ts +2 -0
- package/src/gestures/use-hover-gesture.ts +10 -0
- package/src/gestures/use-pan-gesture.ts +22 -0
- package/src/gestures/use-tap-gesture.ts +14 -0
- package/src/gestures/utils/event-type.ts +24 -0
- package/src/gestures/utils/is-node-or-child.ts +31 -0
- package/src/index.ts +104 -0
- package/src/motion/Motion.svelte +246 -0
- package/src/motion/MotionSSR.svelte +244 -0
- package/src/motion/features/AnimationState.svelte +29 -0
- package/src/motion/features/Exit.svelte +32 -0
- package/src/motion/features/UseFeatures.svelte +39 -0
- package/src/motion/features/animations.ts +22 -0
- package/src/motion/features/definitions.ts +49 -0
- package/src/motion/features/drag.ts +24 -0
- package/src/motion/features/gestures.ts +24 -0
- package/src/motion/features/layout/Animate.svelte +314 -0
- package/src/motion/features/layout/Animate.ts +9 -0
- package/src/motion/features/layout/AnimateLayoutContextProvider.svelte +14 -0
- package/src/motion/features/layout/Measure.svelte +98 -0
- package/src/motion/features/layout/Measure.ts +9 -0
- package/src/motion/features/layout/MeasureContextProvider.svelte +32 -0
- package/src/motion/features/layout/index.ts +20 -0
- package/src/motion/features/layout/types.ts +71 -0
- package/src/motion/features/layout/utils.ts +40 -0
- package/src/motion/features/types.ts +53 -0
- package/src/motion/features/use-features.ts +16 -0
- package/src/motion/index.ts +64 -0
- package/src/motion/types.ts +278 -0
- package/src/motion/utils/UseLayoutId.svelte +18 -0
- package/src/motion/utils/UseVisualElement.svelte +104 -0
- package/src/motion/utils/UseVisualState.svelte +137 -0
- package/src/motion/utils/is-forced-motion-value.ts +23 -0
- package/src/motion/utils/make-renderless-component.ts +17 -0
- package/src/motion/utils/should-inhert-variant.ts +6 -0
- package/src/motion/utils/use-motion-ref.ts +41 -0
- package/src/motion/utils/use-visual-element.ts +13 -0
- package/src/motion/utils/use-visual-state.ts +24 -0
- package/src/motion/utils/valid-prop.ts +80 -0
- package/src/render/dom/M.svelte +16 -0
- package/src/render/dom/UseRender.svelte +37 -0
- package/src/render/dom/create-motion-class.ts +12 -0
- package/src/render/dom/create-visual-element.ts +22 -0
- package/src/render/dom/featureBundle.ts +22 -0
- package/src/render/dom/motion-minimal.ts +22 -0
- package/src/render/dom/motion-proxy.ts +107 -0
- package/src/render/dom/motion.ts +62 -0
- package/src/render/dom/projection/convert-to-relative.ts +40 -0
- package/src/render/dom/projection/default-scale-correctors.ts +138 -0
- package/src/render/dom/projection/measure.ts +28 -0
- package/src/render/dom/projection/relative-set.ts +27 -0
- package/src/render/dom/projection/scale-correction.ts +22 -0
- package/src/render/dom/projection/types.ts +13 -0
- package/src/render/dom/projection/utils.ts +69 -0
- package/src/render/dom/svg-visual-element.ts +114 -0
- package/src/render/dom/types.ts +32 -0
- package/src/render/dom/use-render.ts +11 -0
- package/src/render/dom/utils/UseInitialMotionProps.svelte +26 -0
- package/src/render/dom/utils/batch-layout.ts +77 -0
- package/src/render/dom/utils/camel-to-dash.ts +20 -0
- package/src/render/dom/utils/create-config.ts +33 -0
- package/src/render/dom/utils/css-variables-conversion.ts +121 -0
- package/src/render/dom/utils/filter-props.ts +55 -0
- package/src/render/dom/utils/is-css-variable.ts +18 -0
- package/src/render/dom/utils/is-svg-component.ts +41 -0
- package/src/render/dom/utils/parse-dom-variant.ts +26 -0
- package/src/render/dom/utils/unit-conversion.ts +258 -0
- package/src/render/dom/utils/use-html-props.ts +2 -0
- package/src/render/dom/utils/use-svg-props.ts +1 -0
- package/src/render/dom/value-types/animatable-none.ts +24 -0
- package/src/render/dom/value-types/defaults.ts +30 -0
- package/src/render/dom/value-types/dimensions.ts +27 -0
- package/src/render/dom/value-types/find.ts +31 -0
- package/src/render/dom/value-types/get-as-type.ts +21 -0
- package/src/render/dom/value-types/number.ts +83 -0
- package/src/render/dom/value-types/test.ts +17 -0
- package/src/render/dom/value-types/type-auto.ts +21 -0
- package/src/render/dom/value-types/type-int.ts +23 -0
- package/src/render/dom/value-types/types.ts +8 -0
- package/src/render/html/UseHTMLProps.svelte +33 -0
- package/src/render/html/UseInitialMotionValues.svelte +27 -0
- package/src/render/html/UseStyle.svelte +47 -0
- package/src/render/html/config-motion.ts +23 -0
- package/src/render/html/supported-elements.ts +10 -0
- package/src/render/html/types.ts +64 -0
- package/src/render/html/use-props.ts +14 -0
- package/src/render/html/utils/build-projection-transform.ts +53 -0
- package/src/render/html/utils/build-styles.ts +121 -0
- package/src/render/html/utils/build-transform.ts +79 -0
- package/src/render/html/utils/create-render-state.ts +18 -0
- package/src/render/html/utils/render.ts +22 -0
- package/src/render/html/utils/scrape-motion-values.ts +26 -0
- package/src/render/html/utils/transform.ts +51 -0
- package/src/render/html/visual-element.ts +129 -0
- package/src/render/index.ts +703 -0
- package/src/render/svg/UseSVGProps.svelte +34 -0
- package/src/render/svg/config-motion.ts +51 -0
- package/src/render/svg/lowercase-elements.ts +35 -0
- package/src/render/svg/supported-elements.ts +10 -0
- package/src/render/svg/types.ts +51 -0
- package/src/render/svg/use-props.ts +14 -0
- package/src/render/svg/utils/build-attrs.ts +58 -0
- package/src/render/svg/utils/camel-case-attrs.ts +27 -0
- package/src/render/svg/utils/create-render-state.ts +17 -0
- package/src/render/svg/utils/path.ts +49 -0
- package/src/render/svg/utils/render.ts +22 -0
- package/src/render/svg/utils/scrape-motion-values.ts +26 -0
- package/src/render/svg/utils/transform-origin.ts +30 -0
- package/src/render/svg/visual-element.ts +44 -0
- package/src/render/types.ts +148 -0
- package/src/render/utils/animation-state.ts +375 -0
- package/src/render/utils/animation.ts +167 -0
- package/src/render/utils/compare-by-depth.ts +18 -0
- package/src/render/utils/flat-tree.ts +35 -0
- package/src/render/utils/is-draggable.ts +17 -0
- package/src/render/utils/lifecycles.ts +172 -0
- package/src/render/utils/motion-values.ts +59 -0
- package/src/render/utils/projection.ts +38 -0
- package/src/render/utils/setters.ts +910 -0
- package/src/render/utils/state.ts +113 -0
- package/src/render/utils/types.ts +12 -0
- package/src/render/utils/variants.ts +76 -0
- package/src/types/geometry.ts +91 -0
- package/src/types.ts +1088 -0
- package/src/utils/UseUnmountEffect.svelte +11 -0
- package/src/utils/array.ts +18 -0
- package/src/utils/each-axis.ts +15 -0
- package/src/utils/errors.ts +22 -0
- package/src/utils/fix-process-env.ts +22 -0
- package/src/utils/geometry/delta-apply.ts +162 -0
- package/src/utils/geometry/delta-calc.ts +89 -0
- package/src/utils/geometry/index.ts +83 -0
- package/src/utils/is-browser.ts +12 -0
- package/src/utils/is-numerical-string.ts +15 -0
- package/src/utils/is-ref-object.ts +16 -0
- package/src/utils/noop.ts +15 -0
- package/src/utils/resolve-value.ts +23 -0
- package/src/utils/shallow-compare.ts +23 -0
- package/src/utils/subscription-manager.ts +49 -0
- package/src/utils/time-conversion.ts +18 -0
- package/src/utils/transform.ts +120 -0
- package/src/utils/use-constant.ts +23 -0
- package/src/utils/use-cycle.ts +78 -0
- package/src/utils/use-force-update.ts +7 -0
- package/src/utils/use-isomorphic-effect.ts +8 -0
- package/src/utils/use-reduced-motion.ts +70 -0
- package/src/utils/use-unmount-effect.ts +8 -0
- package/src/value/index.ts +409 -0
- package/src/value/scroll/use-element-scroll.ts +73 -0
- package/src/value/scroll/use-viewport-scroll.ts +81 -0
- package/src/value/scroll/utils.ts +76 -0
- package/src/value/use-combine-values.ts +53 -0
- package/src/value/use-motion-template.ts +57 -0
- package/src/value/use-motion-value.ts +27 -0
- package/src/value/use-spring.ts +84 -0
- package/src/value/use-transform.ts +216 -0
- package/src/value/use-velocity.ts +44 -0
- package/src/value/utils/is-motion-value.ts +15 -0
- package/src/value/utils/resolve-motion-value.ts +29 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { Easing } from "popmotion";
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface TransformOptions<T> {
|
|
10
|
+
/**
|
|
11
|
+
* Clamp values to within the given range. Defaults to `true`
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
clamp?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Easing functions to use on the interpolations between each value in the input and output ranges.
|
|
18
|
+
*
|
|
19
|
+
* If provided as an array, the array must be one item shorter than the input and output ranges, as the easings apply to the transition **between** each.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
ease?: Easing | Easing[];
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
mixer?: (from: T, to: T) => (v: number) => any;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Transforms numbers into other values by mapping them from an input range to an output range.
|
|
31
|
+
* Returns the type of the input provided.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
*
|
|
35
|
+
* Given an input range of `[0, 200]` and an output range of
|
|
36
|
+
* `[0, 1]`, this function will return a value between `0` and `1`.
|
|
37
|
+
* The input range must be a linear series of numbers. The output range
|
|
38
|
+
* can be any supported value type, such as numbers, colors, shadows, arrays, objects and more.
|
|
39
|
+
* Every value in the output range must be of the same type and in the same format.
|
|
40
|
+
*
|
|
41
|
+
* @motion
|
|
42
|
+
*
|
|
43
|
+
* ```jsx
|
|
44
|
+
* import { transform } from "svelte-motion"
|
|
45
|
+
*
|
|
46
|
+
*
|
|
47
|
+
* const inputRange = [0, 200]
|
|
48
|
+
* const outputRange = [0, 1]
|
|
49
|
+
* const output = transform(100, inputRange, outputRange)
|
|
50
|
+
*
|
|
51
|
+
* console.log(output) // Returns 0.5
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param inputValue - A number to transform between the input and output ranges.
|
|
55
|
+
* @param inputRange - A linear series of numbers (either all increasing or decreasing).
|
|
56
|
+
* @param outputRange - A series of numbers, colors, strings, or arrays/objects of those. Must be the same length as `inputRange`.
|
|
57
|
+
* @param options - Clamp: Clamp values to within the given range. Defaults to `true`.
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
function transform<T>(inputValue: number, inputRange: number[], outputRange: T[], options?: TransformOptions<T>): T;
|
|
62
|
+
/**
|
|
63
|
+
* @motion
|
|
64
|
+
*
|
|
65
|
+
* Transforms numbers into other values by mapping them from an input range to an output range.
|
|
66
|
+
*
|
|
67
|
+
* Given an input range of `[0, 200]` and an output range of
|
|
68
|
+
* `[0, 1]`, this function will return a value between `0` and `1`.
|
|
69
|
+
* The input range must be a linear series of numbers. The output range
|
|
70
|
+
* can be any supported value type, such as numbers, colors, shadows, arrays, objects and more.
|
|
71
|
+
* Every value in the output range must be of the same type and in the same format.
|
|
72
|
+
*
|
|
73
|
+
* ```jsx
|
|
74
|
+
|
|
75
|
+
* import { transform } from "svelte-motion"
|
|
76
|
+
*
|
|
77
|
+
* const inputRange = [-200, -100, 100, 200]
|
|
78
|
+
* const outputRange = [0, 1, 1, 0]
|
|
79
|
+
* const convertRange = transform(inputRange, outputRange)
|
|
80
|
+
* const output = convertRange(-150)
|
|
81
|
+
*
|
|
82
|
+
* console.log(output) // Returns 0.5
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @param inputRange - A linear series of numbers (either all increasing or decreasing).
|
|
86
|
+
* @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`.
|
|
87
|
+
* @param options - Clamp: clamp values to within the given range. Defaults to `true`.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
function transform<T>(inputRange: number[], outputRange: T[], options?: TransformOptions<T>): (inputValue: number) => T;
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
based on framer-motion@4.0.3,
|
|
96
|
+
Copyright (c) 2018 Framer B.V.
|
|
97
|
+
*/
|
|
98
|
+
import {fixed} from './fix-process-env';
|
|
99
|
+
import { __assign } from 'tslib';
|
|
100
|
+
import { interpolate } from 'popmotion';
|
|
101
|
+
import type { CustomValueType } from "../types";
|
|
102
|
+
|
|
103
|
+
var isCustomValueType = function (v: any): v is CustomValueType {
|
|
104
|
+
return typeof v === "object" && v.mix;
|
|
105
|
+
};
|
|
106
|
+
var getMixer = function (v: any) { return (isCustomValueType(v) ? v.mix : undefined); };
|
|
107
|
+
function transform<T>(...args: [number, number[], T[], TransformOptions<T>?]
|
|
108
|
+
| [number[], T[], TransformOptions<T>?]
|
|
109
|
+
) {
|
|
110
|
+
var useImmediate = !Array.isArray(args[0]);
|
|
111
|
+
var argOffset = useImmediate ? 0 : -1;
|
|
112
|
+
var inputValue = args[0 + argOffset] as number;
|
|
113
|
+
var inputRange = args[1 + argOffset] as number[];
|
|
114
|
+
var outputRange = args[2 + argOffset] as T[];
|
|
115
|
+
var options = args[3 + argOffset] as TransformOptions<T>;
|
|
116
|
+
var interpolator = interpolate(inputRange, outputRange, __assign({ mixer: getMixer(outputRange[0]) }, options));
|
|
117
|
+
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { transform };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
type Init<T> = () => T;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a constant value over the lifecycle of a component.
|
|
8
|
+
*
|
|
9
|
+
* Even if `useMemo` is provided an empty array as its final argument, it doesn't offer
|
|
10
|
+
* a guarantee that it won't re-run for performance reasons later on. By using `useConstant`
|
|
11
|
+
* you can ensure that initialisers don't execute twice or more.
|
|
12
|
+
*/
|
|
13
|
+
export function useConstant<T>(init: Init<T>): T;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates a constant value over the lifecycle of a component.
|
|
17
|
+
*
|
|
18
|
+
* Even if `useMemo` is provided an empty array as its final argument, it doesn't offer
|
|
19
|
+
* a guarantee that it won't re-run for performance reasons later on. By using `useConstant`
|
|
20
|
+
* you can ensure that initialisers don't execute twice or more.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// export { default as UseConstant } from './UseConstant.svelte';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { Writable } from 'svelte/store';
|
|
6
|
+
type Cycle = (i?: number) => void;
|
|
7
|
+
type CycleState<T> = [T, Cycle];
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
based on framer-motion@4.0.3,
|
|
12
|
+
Copyright (c) 2018 Framer B.V.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Cycles through a series of visual properties. Can be used to toggle between or cycle through animations. It works similar to `useState` in React. It is provided an initial array of possible states, and returns an array of two arguments.
|
|
16
|
+
*
|
|
17
|
+
* @library
|
|
18
|
+
*
|
|
19
|
+
* ```jsx
|
|
20
|
+
* import * as React from "react"
|
|
21
|
+
* import { Frame, useCycle } from "framer"
|
|
22
|
+
*
|
|
23
|
+
* export function MyComponent() {
|
|
24
|
+
* const [x, cycleX] = useCycle(0, 50, 100)
|
|
25
|
+
*
|
|
26
|
+
* return (
|
|
27
|
+
* <Frame
|
|
28
|
+
* animate={{ x: x }}
|
|
29
|
+
* onTap={() => cycleX()}
|
|
30
|
+
* />
|
|
31
|
+
* )
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @motion
|
|
36
|
+
*
|
|
37
|
+
* An index value can be passed to the returned `cycle` function to cycle to a specific index.
|
|
38
|
+
*
|
|
39
|
+
* ```jsx
|
|
40
|
+
* import * as React from "react"
|
|
41
|
+
* import { motion, useCycle } from "framer-motion"
|
|
42
|
+
*
|
|
43
|
+
* export const MyComponent = () => {
|
|
44
|
+
* const [x, cycleX] = useCycle(0, 50, 100)
|
|
45
|
+
*
|
|
46
|
+
* return (
|
|
47
|
+
* <MotionDiv
|
|
48
|
+
* animate={{ x: x }}
|
|
49
|
+
* onTap={() => cycleX()}
|
|
50
|
+
* />
|
|
51
|
+
* )
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @param items - items to cycle through
|
|
56
|
+
* @returns [currentState, cycleState]
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
// export { default as UseCycle } from './UseCycle.svelte';
|
|
61
|
+
import { wrap } from "popmotion";
|
|
62
|
+
import { writable } from 'svelte/store';
|
|
63
|
+
|
|
64
|
+
export const useCycle = <T>(...items: T[]) => {
|
|
65
|
+
let index = 0;
|
|
66
|
+
const x = writable(items[index]) as Writable<T> & {
|
|
67
|
+
/** Cycle through to next value or set the next value by index. */
|
|
68
|
+
next: ( index?: number ) => void
|
|
69
|
+
}
|
|
70
|
+
const next = (i?: number) => {
|
|
71
|
+
index = typeof i !== "number" ?
|
|
72
|
+
wrap(0, items.length, index + 1) :
|
|
73
|
+
i;
|
|
74
|
+
x.set(items[index])
|
|
75
|
+
}
|
|
76
|
+
x.next=next;
|
|
77
|
+
return x;
|
|
78
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import { useEffect } from "react";
|
|
6
|
+
export const useIsomorphicLayoutEffect: typeof useEffect;
|
|
7
|
+
|
|
8
|
+
// export { default as UseIsomorphicLayoutEffect } from './UseIsomorphicLayoutEffect.svelte';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { Writable, Readable } from 'svelte/store'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
based on framer-motion@4.0.3,
|
|
10
|
+
Copyright (c) 2018 Framer B.V.
|
|
11
|
+
*/
|
|
12
|
+
import { motionValue } from "../value";
|
|
13
|
+
import { derived } from "svelte/store";
|
|
14
|
+
// Does this device prefer reduced motion? Returns `null` server-side.
|
|
15
|
+
let prefersReducedMotion: Writable<boolean | null>;
|
|
16
|
+
|
|
17
|
+
function initPrefersReducedMotion() {
|
|
18
|
+
prefersReducedMotion = motionValue(null);
|
|
19
|
+
|
|
20
|
+
if (typeof window === "undefined") return;
|
|
21
|
+
|
|
22
|
+
if (window.matchMedia) {
|
|
23
|
+
const motionMediaQuery = window.matchMedia(
|
|
24
|
+
"(prefers-reduced-motion)"
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const setReducedMotionPreferences = () =>
|
|
28
|
+
prefersReducedMotion.set(motionMediaQuery.matches);
|
|
29
|
+
|
|
30
|
+
motionMediaQuery.addListener(setReducedMotionPreferences);
|
|
31
|
+
|
|
32
|
+
setReducedMotionPreferences();
|
|
33
|
+
} else {
|
|
34
|
+
prefersReducedMotion.set(false);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
42
|
+
*
|
|
43
|
+
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
44
|
+
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
45
|
+
*
|
|
46
|
+
* It will actively respond to changes and re-render your components with the latest setting.
|
|
47
|
+
*
|
|
48
|
+
* ```jsx
|
|
49
|
+
* export function Sidebar({ isOpen }) {
|
|
50
|
+
* const shouldReduceMotion = useReducedMotion()
|
|
51
|
+
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
52
|
+
*
|
|
53
|
+
* return (
|
|
54
|
+
* <MotionDiv animate={{
|
|
55
|
+
* opacity: isOpen ? 1 : 0,
|
|
56
|
+
* x: isOpen ? 0 : closedX
|
|
57
|
+
* }} />
|
|
58
|
+
* )
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @return boolean
|
|
63
|
+
*
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export const useReducedMotion = () => {
|
|
67
|
+
!prefersReducedMotion && initPrefersReducedMotion()
|
|
68
|
+
|
|
69
|
+
return derived(prefersReducedMotion,$v=>$v)
|
|
70
|
+
}
|