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.
Files changed (233) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +39 -0
  3. package/package.json +64 -0
  4. package/src/animation/UseAnimatedState.svelte +86 -0
  5. package/src/animation/UseAnimation.svelte +61 -0
  6. package/src/animation/animate.ts +78 -0
  7. package/src/animation/animation-controls.ts +101 -0
  8. package/src/animation/types.ts +83 -0
  9. package/src/animation/use-animated-state.ts +1 -0
  10. package/src/animation/use-animation.ts +74 -0
  11. package/src/animation/utils/default-transitions.ts +70 -0
  12. package/src/animation/utils/easing.ts +55 -0
  13. package/src/animation/utils/is-animatable.ts +42 -0
  14. package/src/animation/utils/is-animation-controls.ts +17 -0
  15. package/src/animation/utils/is-keyframes-target.ts +17 -0
  16. package/src/animation/utils/transitions.ts +218 -0
  17. package/src/animation/utils/variant-resolvers.ts +15 -0
  18. package/src/components/AnimatePresence/AnimatePresence.svelte +180 -0
  19. package/src/components/AnimatePresence/PresenceChild/PresenceChild.svelte +78 -0
  20. package/src/components/AnimatePresence/PresenceChild/index.ts +7 -0
  21. package/src/components/AnimatePresence/PresenceChild/types.ts +10 -0
  22. package/src/components/AnimatePresence/index.ts +46 -0
  23. package/src/components/AnimatePresence/types.ts +79 -0
  24. package/src/components/AnimatePresence/use-presence.ts +90 -0
  25. package/src/components/AnimateSharedLayout/AnimateSharedLayout.svelte +239 -0
  26. package/src/components/AnimateSharedLayout/index.ts +11 -0
  27. package/src/components/AnimateSharedLayout/types.ts +111 -0
  28. package/src/components/AnimateSharedLayout/utils/batcher.ts +96 -0
  29. package/src/components/AnimateSharedLayout/utils/crossfader.ts +260 -0
  30. package/src/components/AnimateSharedLayout/utils/rotate.ts +48 -0
  31. package/src/components/AnimateSharedLayout/utils/stack.ts +160 -0
  32. package/src/components/LazyMotion/LazyMotion.svelte +82 -0
  33. package/src/components/LazyMotion/index.ts +42 -0
  34. package/src/components/LazyMotion/types.ts +58 -0
  35. package/src/components/MotionConfig/MotionConfig.svelte +56 -0
  36. package/src/components/MotionConfig/MotionConfigScaleCorrection.ts +47 -0
  37. package/src/components/MotionConfig/index.ts +20 -0
  38. package/src/components/MotionDiv.svelte +8 -0
  39. package/src/context/DOMcontext.ts +21 -0
  40. package/src/context/LayoutGroupContext.ts +13 -0
  41. package/src/context/LazyContext.ts +18 -0
  42. package/src/context/MotionConfigContext.ts +48 -0
  43. package/src/context/MotionContext/MotionContext.svelte +27 -0
  44. package/src/context/MotionContext/MotionContextProvider.svelte +22 -0
  45. package/src/context/MotionContext/UseCreateMotionContext.svelte +34 -0
  46. package/src/context/MotionContext/create.ts +1 -0
  47. package/src/context/MotionContext/index.ts +14 -0
  48. package/src/context/MotionContext/utils.ts +29 -0
  49. package/src/context/PresenceContext.ts +26 -0
  50. package/src/context/ScaleCorrectionProvider.svelte +27 -0
  51. package/src/context/SharedLayoutContext.ts +29 -0
  52. package/src/events/UseDomEvent.svelte +67 -0
  53. package/src/events/UsePointerEvent.svelte +76 -0
  54. package/src/events/event-info.ts +69 -0
  55. package/src/events/types.ts +15 -0
  56. package/src/events/use-dom-event.ts +48 -0
  57. package/src/events/use-pointer-event.ts +29 -0
  58. package/src/events/utils.ts +25 -0
  59. package/src/gestures/PanSession.ts +298 -0
  60. package/src/gestures/UseFocusGesture.svelte +31 -0
  61. package/src/gestures/UseGestures.svelte +17 -0
  62. package/src/gestures/UseHoverGesture.svelte +40 -0
  63. package/src/gestures/UsePanGesture.svelte +58 -0
  64. package/src/gestures/UseTapGesture.svelte +77 -0
  65. package/src/gestures/drag/UseDrag.svelte +55 -0
  66. package/src/gestures/drag/UseDragControls.svelte +145 -0
  67. package/src/gestures/drag/VisualElementDragControls.ts +632 -0
  68. package/src/gestures/drag/types.ts +307 -0
  69. package/src/gestures/drag/use-drag-controls.ts +148 -0
  70. package/src/gestures/drag/use-drag.ts +15 -0
  71. package/src/gestures/drag/utils/constraints.ts +157 -0
  72. package/src/gestures/drag/utils/lock.ts +69 -0
  73. package/src/gestures/types.ts +257 -0
  74. package/src/gestures/use-focus-gesture.ts +16 -0
  75. package/src/gestures/use-gestures.ts +2 -0
  76. package/src/gestures/use-hover-gesture.ts +10 -0
  77. package/src/gestures/use-pan-gesture.ts +22 -0
  78. package/src/gestures/use-tap-gesture.ts +14 -0
  79. package/src/gestures/utils/event-type.ts +24 -0
  80. package/src/gestures/utils/is-node-or-child.ts +31 -0
  81. package/src/index.ts +104 -0
  82. package/src/motion/Motion.svelte +246 -0
  83. package/src/motion/MotionSSR.svelte +244 -0
  84. package/src/motion/features/AnimationState.svelte +29 -0
  85. package/src/motion/features/Exit.svelte +32 -0
  86. package/src/motion/features/UseFeatures.svelte +39 -0
  87. package/src/motion/features/animations.ts +22 -0
  88. package/src/motion/features/definitions.ts +49 -0
  89. package/src/motion/features/drag.ts +24 -0
  90. package/src/motion/features/gestures.ts +24 -0
  91. package/src/motion/features/layout/Animate.svelte +314 -0
  92. package/src/motion/features/layout/Animate.ts +9 -0
  93. package/src/motion/features/layout/AnimateLayoutContextProvider.svelte +14 -0
  94. package/src/motion/features/layout/Measure.svelte +98 -0
  95. package/src/motion/features/layout/Measure.ts +9 -0
  96. package/src/motion/features/layout/MeasureContextProvider.svelte +32 -0
  97. package/src/motion/features/layout/index.ts +20 -0
  98. package/src/motion/features/layout/types.ts +71 -0
  99. package/src/motion/features/layout/utils.ts +40 -0
  100. package/src/motion/features/types.ts +53 -0
  101. package/src/motion/features/use-features.ts +16 -0
  102. package/src/motion/index.ts +64 -0
  103. package/src/motion/types.ts +278 -0
  104. package/src/motion/utils/UseLayoutId.svelte +18 -0
  105. package/src/motion/utils/UseVisualElement.svelte +104 -0
  106. package/src/motion/utils/UseVisualState.svelte +137 -0
  107. package/src/motion/utils/is-forced-motion-value.ts +23 -0
  108. package/src/motion/utils/make-renderless-component.ts +17 -0
  109. package/src/motion/utils/should-inhert-variant.ts +6 -0
  110. package/src/motion/utils/use-motion-ref.ts +41 -0
  111. package/src/motion/utils/use-visual-element.ts +13 -0
  112. package/src/motion/utils/use-visual-state.ts +24 -0
  113. package/src/motion/utils/valid-prop.ts +80 -0
  114. package/src/render/dom/M.svelte +16 -0
  115. package/src/render/dom/UseRender.svelte +37 -0
  116. package/src/render/dom/create-motion-class.ts +12 -0
  117. package/src/render/dom/create-visual-element.ts +22 -0
  118. package/src/render/dom/featureBundle.ts +22 -0
  119. package/src/render/dom/motion-minimal.ts +22 -0
  120. package/src/render/dom/motion-proxy.ts +107 -0
  121. package/src/render/dom/motion.ts +62 -0
  122. package/src/render/dom/projection/convert-to-relative.ts +40 -0
  123. package/src/render/dom/projection/default-scale-correctors.ts +138 -0
  124. package/src/render/dom/projection/measure.ts +28 -0
  125. package/src/render/dom/projection/relative-set.ts +27 -0
  126. package/src/render/dom/projection/scale-correction.ts +22 -0
  127. package/src/render/dom/projection/types.ts +13 -0
  128. package/src/render/dom/projection/utils.ts +69 -0
  129. package/src/render/dom/svg-visual-element.ts +114 -0
  130. package/src/render/dom/types.ts +32 -0
  131. package/src/render/dom/use-render.ts +11 -0
  132. package/src/render/dom/utils/UseInitialMotionProps.svelte +26 -0
  133. package/src/render/dom/utils/batch-layout.ts +77 -0
  134. package/src/render/dom/utils/camel-to-dash.ts +20 -0
  135. package/src/render/dom/utils/create-config.ts +33 -0
  136. package/src/render/dom/utils/css-variables-conversion.ts +121 -0
  137. package/src/render/dom/utils/filter-props.ts +55 -0
  138. package/src/render/dom/utils/is-css-variable.ts +18 -0
  139. package/src/render/dom/utils/is-svg-component.ts +41 -0
  140. package/src/render/dom/utils/parse-dom-variant.ts +26 -0
  141. package/src/render/dom/utils/unit-conversion.ts +258 -0
  142. package/src/render/dom/utils/use-html-props.ts +2 -0
  143. package/src/render/dom/utils/use-svg-props.ts +1 -0
  144. package/src/render/dom/value-types/animatable-none.ts +24 -0
  145. package/src/render/dom/value-types/defaults.ts +30 -0
  146. package/src/render/dom/value-types/dimensions.ts +27 -0
  147. package/src/render/dom/value-types/find.ts +31 -0
  148. package/src/render/dom/value-types/get-as-type.ts +21 -0
  149. package/src/render/dom/value-types/number.ts +83 -0
  150. package/src/render/dom/value-types/test.ts +17 -0
  151. package/src/render/dom/value-types/type-auto.ts +21 -0
  152. package/src/render/dom/value-types/type-int.ts +23 -0
  153. package/src/render/dom/value-types/types.ts +8 -0
  154. package/src/render/html/UseHTMLProps.svelte +33 -0
  155. package/src/render/html/UseInitialMotionValues.svelte +27 -0
  156. package/src/render/html/UseStyle.svelte +47 -0
  157. package/src/render/html/config-motion.ts +23 -0
  158. package/src/render/html/supported-elements.ts +10 -0
  159. package/src/render/html/types.ts +64 -0
  160. package/src/render/html/use-props.ts +14 -0
  161. package/src/render/html/utils/build-projection-transform.ts +53 -0
  162. package/src/render/html/utils/build-styles.ts +121 -0
  163. package/src/render/html/utils/build-transform.ts +79 -0
  164. package/src/render/html/utils/create-render-state.ts +18 -0
  165. package/src/render/html/utils/render.ts +22 -0
  166. package/src/render/html/utils/scrape-motion-values.ts +26 -0
  167. package/src/render/html/utils/transform.ts +51 -0
  168. package/src/render/html/visual-element.ts +129 -0
  169. package/src/render/index.ts +703 -0
  170. package/src/render/svg/UseSVGProps.svelte +34 -0
  171. package/src/render/svg/config-motion.ts +51 -0
  172. package/src/render/svg/lowercase-elements.ts +35 -0
  173. package/src/render/svg/supported-elements.ts +10 -0
  174. package/src/render/svg/types.ts +51 -0
  175. package/src/render/svg/use-props.ts +14 -0
  176. package/src/render/svg/utils/build-attrs.ts +58 -0
  177. package/src/render/svg/utils/camel-case-attrs.ts +27 -0
  178. package/src/render/svg/utils/create-render-state.ts +17 -0
  179. package/src/render/svg/utils/path.ts +49 -0
  180. package/src/render/svg/utils/render.ts +22 -0
  181. package/src/render/svg/utils/scrape-motion-values.ts +26 -0
  182. package/src/render/svg/utils/transform-origin.ts +30 -0
  183. package/src/render/svg/visual-element.ts +44 -0
  184. package/src/render/types.ts +148 -0
  185. package/src/render/utils/animation-state.ts +375 -0
  186. package/src/render/utils/animation.ts +167 -0
  187. package/src/render/utils/compare-by-depth.ts +18 -0
  188. package/src/render/utils/flat-tree.ts +35 -0
  189. package/src/render/utils/is-draggable.ts +17 -0
  190. package/src/render/utils/lifecycles.ts +172 -0
  191. package/src/render/utils/motion-values.ts +59 -0
  192. package/src/render/utils/projection.ts +38 -0
  193. package/src/render/utils/setters.ts +910 -0
  194. package/src/render/utils/state.ts +113 -0
  195. package/src/render/utils/types.ts +12 -0
  196. package/src/render/utils/variants.ts +76 -0
  197. package/src/types/geometry.ts +91 -0
  198. package/src/types.ts +1088 -0
  199. package/src/utils/UseUnmountEffect.svelte +11 -0
  200. package/src/utils/array.ts +18 -0
  201. package/src/utils/each-axis.ts +15 -0
  202. package/src/utils/errors.ts +22 -0
  203. package/src/utils/fix-process-env.ts +22 -0
  204. package/src/utils/geometry/delta-apply.ts +162 -0
  205. package/src/utils/geometry/delta-calc.ts +89 -0
  206. package/src/utils/geometry/index.ts +83 -0
  207. package/src/utils/is-browser.ts +12 -0
  208. package/src/utils/is-numerical-string.ts +15 -0
  209. package/src/utils/is-ref-object.ts +16 -0
  210. package/src/utils/noop.ts +15 -0
  211. package/src/utils/resolve-value.ts +23 -0
  212. package/src/utils/shallow-compare.ts +23 -0
  213. package/src/utils/subscription-manager.ts +49 -0
  214. package/src/utils/time-conversion.ts +18 -0
  215. package/src/utils/transform.ts +120 -0
  216. package/src/utils/use-constant.ts +23 -0
  217. package/src/utils/use-cycle.ts +78 -0
  218. package/src/utils/use-force-update.ts +7 -0
  219. package/src/utils/use-isomorphic-effect.ts +8 -0
  220. package/src/utils/use-reduced-motion.ts +70 -0
  221. package/src/utils/use-unmount-effect.ts +8 -0
  222. package/src/value/index.ts +409 -0
  223. package/src/value/scroll/use-element-scroll.ts +73 -0
  224. package/src/value/scroll/use-viewport-scroll.ts +81 -0
  225. package/src/value/scroll/utils.ts +76 -0
  226. package/src/value/use-combine-values.ts +53 -0
  227. package/src/value/use-motion-template.ts +57 -0
  228. package/src/value/use-motion-value.ts +27 -0
  229. package/src/value/use-spring.ts +84 -0
  230. package/src/value/use-transform.ts +216 -0
  231. package/src/value/use-velocity.ts +44 -0
  232. package/src/value/utils/is-motion-value.ts +15 -0
  233. package/src/value/utils/resolve-motion-value.ts +29 -0
@@ -0,0 +1,27 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { VisualElement } from "../../types";
6
+
7
+
8
+ /**
9
+ based on framer-motion@4.1.11,
10
+ Copyright (c) 2018 Framer B.V.
11
+ */
12
+ import { calcRelativeOffset } from '../../../motion/features/layout/utils.js';
13
+ import { eachAxis } from '../../../utils/each-axis.js';
14
+
15
+ function setCurrentViewportBox(visualElement: VisualElement) {
16
+ var projectionParent = visualElement.getProjectionParent();
17
+ if (!projectionParent) {
18
+ visualElement.rebaseProjectionTarget();
19
+ return;
20
+ }
21
+ var relativeOffset = calcRelativeOffset(projectionParent.getLayoutState().layout, visualElement.getLayoutState().layout);
22
+ eachAxis(function (axis) {
23
+ visualElement.setProjectionTargetAxis(axis, relativeOffset[axis].min, relativeOffset[axis].max, true);
24
+ });
25
+ }
26
+
27
+ export { setCurrentViewportBox };
@@ -0,0 +1,22 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { ScaleCorrectionDefinitionMap } from "./types";
6
+
7
+
8
+ /**
9
+ based on framer-motion@4.0.3,
10
+ Copyright (c) 2018 Framer B.V.
11
+ */
12
+ var valueScaleCorrection: ScaleCorrectionDefinitionMap = {};
13
+ /**
14
+ * @internal
15
+ */
16
+ function addScaleCorrection(correctors: ScaleCorrectionDefinitionMap) {
17
+ for (var key in correctors) {
18
+ valueScaleCorrection[key] = correctors[key];
19
+ }
20
+ }
21
+
22
+ export { addScaleCorrection, valueScaleCorrection };
@@ -0,0 +1,13 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { LayoutState, TargetProjection } from "../../utils/state";
6
+ export type ScaleCorrection = (latest: string | number, layoutState: LayoutState, projection: TargetProjection) => string | number;
7
+ export interface ScaleCorrectionDefinition {
8
+ process: ScaleCorrection;
9
+ applyTo?: string[];
10
+ }
11
+ export type ScaleCorrectionDefinitionMap = {
12
+ [key: string]: ScaleCorrectionDefinition;
13
+ };
@@ -0,0 +1,69 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { VisualElement } from "../../types";
6
+
7
+
8
+ /**
9
+ based on framer-motion@4.1.11,
10
+ Copyright (c) 2018 Framer B.V.
11
+ */
12
+
13
+ import sync from 'framesync';
14
+ import { copyAxisBox } from '../../../utils/geometry/index.js';
15
+ import { compareByDepth } from '../../utils/compare-by-depth.js';
16
+
17
+ function isProjecting(visualElement: VisualElement) {
18
+ var isEnabled = visualElement.projection.isEnabled;
19
+ return isEnabled || visualElement.shouldResetTransform();
20
+ }
21
+ function collectProjectingAncestors(visualElement: VisualElement, ancestors?: VisualElement[]) {
22
+ if (ancestors === void 0) { ancestors = []; }
23
+ var parent = visualElement.parent;
24
+ if (parent)
25
+ collectProjectingAncestors(parent, ancestors);
26
+ if (isProjecting(visualElement))
27
+ ancestors.push(visualElement);
28
+ return ancestors;
29
+ }
30
+ function collectProjectingChildren(visualElement: VisualElement) {
31
+ var children = <VisualElement[]>[];
32
+ var addChild = function (child) {
33
+ if (isProjecting(child))
34
+ children.push(child);
35
+ child.children.forEach(addChild);
36
+ };
37
+ visualElement.children.forEach(addChild);
38
+ return children.sort(compareByDepth);
39
+ }
40
+ /**
41
+ * Update the layoutState by measuring the DOM layout. This
42
+ * should be called after resetting any layout-affecting transforms.
43
+ */
44
+ function updateLayoutMeasurement(visualElement: VisualElement) {
45
+ if (visualElement.shouldResetTransform())
46
+ return;
47
+ var layoutState = visualElement.getLayoutState();
48
+ visualElement.notifyBeforeLayoutMeasure(layoutState.layout);
49
+ layoutState.isHydrated = true;
50
+ layoutState.layout = visualElement.measureViewportBox();
51
+ layoutState.layoutCorrected = copyAxisBox(layoutState.layout);
52
+ visualElement.notifyLayoutMeasure(layoutState.layout, visualElement.prevViewportBox || layoutState.layout);
53
+ sync.update(function () { return visualElement.rebaseProjectionTarget(); });
54
+ }
55
+ /**
56
+ * Record the viewport box as it was before an expected mutation/re-render
57
+ */
58
+ function snapshotViewportBox(visualElement: VisualElement, nc?: any) {
59
+ if (visualElement.shouldResetTransform())
60
+ return;
61
+ if (!nc) visualElement.prevViewportBox = visualElement.measureViewportBox(false);
62
+ /**
63
+ * Update targetBox to match the prevViewportBox. This is just to ensure
64
+ * that targetBox is affected by scroll in the same way as the measured box
65
+ */
66
+ visualElement.rebaseProjectionTarget(false, visualElement.prevViewportBox);
67
+ }
68
+
69
+ export { collectProjectingAncestors, collectProjectingChildren, snapshotViewportBox, updateLayoutMeasurement };
@@ -0,0 +1,114 @@
1
+ /**
2
+ based on framer-motion@4.0.3,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import { visualElement } from ".."
6
+ import { isMotionValue } from "../../value/utils/is-motion-value"
7
+ import { htmlConfig } from "../html/visual-element"
8
+ import { buildSVGAttrs } from "../svg/utils/build-attrs"
9
+ import { camelToDash } from "./utils/camel-to-dash"
10
+ import { camelCaseAttributes } from "../svg/utils/camel-case-attrs"
11
+ import { isTransformProp } from "../html/utils/transform"
12
+ import { getDefaultValueType } from "./value-types/defaults";
13
+
14
+ const zeroDimensions = {
15
+ x: 0,
16
+ y: 0,
17
+ width: 0,
18
+ height: 0,
19
+ }
20
+
21
+ export const svgMutableState = () => ({
22
+ ...htmlConfig.createRenderState(),
23
+ attrs: {},
24
+ dimensions: zeroDimensions,
25
+ })
26
+
27
+ export const svgVisualElement = visualElement({
28
+ ...(htmlConfig),
29
+ createRenderState: svgMutableState,
30
+ onMount(element, instance, mutableState) {
31
+ try {
32
+ mutableState.dimensions =
33
+ typeof (instance).getBBox === "function"
34
+ ? (instance).getBBox()
35
+ : (instance.getBoundingClientRect())
36
+ } catch (e) {
37
+ // Most likely trying to measure an unrendered element under Firefox
38
+ mutableState.dimensions = zeroDimensions
39
+ }
40
+
41
+ if (isPath(instance)) {
42
+ mutableState.totalPathLength = instance.getTotalLength()
43
+ }
44
+
45
+ /**
46
+ * Ensure we render the element as soon as possible to reflect the measured dimensions.
47
+ * Preferably this would happen synchronously but we put it in rAF to prevent layout thrashing.
48
+ */
49
+ element.scheduleRender()
50
+ },
51
+
52
+ getBaseTarget(props, key) {
53
+ return props[key]
54
+ },
55
+
56
+ readValueFromInstance(domElement, key) {
57
+ if (isTransformProp(key)) {
58
+ return getDefaultValueType(key)?.default || 0
59
+ }
60
+ key = !camelCaseAttributes.has(key) ? camelToDash(key) : key
61
+ return domElement.getAttribute(key)
62
+ },
63
+
64
+ scrapeMotionValuesFromProps(props) {
65
+ const newValues = htmlConfig.scrapeMotionValuesFromProps(props)
66
+
67
+ for (let key in props) {
68
+ if (isMotionValue(props[key])) {
69
+ if (key === "x" || key === "y") {
70
+ key = "attr" + key.toUpperCase()
71
+ }
72
+ newValues[key] = props[key]
73
+ }
74
+ }
75
+
76
+ return newValues
77
+ },
78
+
79
+ build(
80
+ _element,
81
+ renderState,
82
+ latestValues,
83
+ projection,
84
+ layoutState,
85
+ options,
86
+ props
87
+ ) {
88
+ buildSVGAttrs(
89
+ renderState,
90
+ latestValues,
91
+ projection,
92
+ layoutState,
93
+ options,
94
+ props.transformTemplate
95
+ )
96
+ },
97
+
98
+ render(element, mutableState) {
99
+ htmlConfig.render(element, mutableState)
100
+
101
+ for (const key in mutableState.attrs) {
102
+ element.setAttribute(
103
+ !camelCaseAttributes.has(key) ? camelToDash(key) : key,
104
+ mutableState.attrs[key]
105
+ )
106
+ }
107
+ },
108
+ })
109
+
110
+ function isPath(
111
+ element
112
+ ){
113
+ return element.tagName === "path"
114
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { TransformPoint2D } from "../../types/geometry";
6
+ import type { HTMLMotionComponents } from "../html/types";
7
+ import type { SVGMotionComponents } from "../svg/types";
8
+ export interface DOMVisualElementOptions {
9
+ /**
10
+ * A function that can map a page point between spaces. Used by Framer
11
+ * to support dragging and layout animations within scaled space.
12
+ *
13
+ * @public
14
+ */
15
+ transformPagePoint?: TransformPoint2D;
16
+ /**
17
+ * Allow `transform` to be set as `"none"` if all transforms are their default
18
+ * values. Switching to this removes the element as a GPU layer which can lead to subtle
19
+ * graphical shifts.
20
+ *
21
+ * @public
22
+ */
23
+ allowTransformNone?: boolean;
24
+ /**
25
+ * Allow this element to be GPU-accelerated. We currently enable this by
26
+ * adding a `translateZ(0)`.
27
+ *
28
+ * @public
29
+ */
30
+ enableHardwareAcceleration?: boolean;
31
+ }
32
+ export type DOMMotionComponents = HTMLMotionComponents & SVGMotionComponents;
@@ -0,0 +1,11 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { RenderComponent } from "../../motion/features/types";
6
+ import type { HTMLRenderState } from "../html/types";
7
+ import type { SVGRenderState } from "../svg/types";
8
+ export type createUseRender = (forwardMotionProps?: boolean) => RenderComponent<SVGElement | HTMLElement, HTMLRenderState | SVGRenderState>;
9
+
10
+ export { default as UseRender } from './UseRender.svelte';
11
+
@@ -0,0 +1,26 @@
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script lang="ts">
5
+ import { isMotionValue } from "../../../value/utils/is-motion-value.js";
6
+
7
+ export let visualElement, props;
8
+ const createAttrs = (visualElement, props) => {
9
+ const { attrs } = visualElement.build();
10
+ const resolvedMotionValueProps = {};
11
+
12
+ for (const key in props) {
13
+ if (isMotionValue(props[key])) {
14
+ resolvedMotionValueProps[key] = props[key].get();
15
+ }
16
+ }
17
+
18
+ return { ...attrs, ...resolvedMotionValueProps };
19
+ };
20
+ let svgProps = createAttrs(visualElement, props);
21
+ $: if (visualElement.isStatic) {
22
+ svgProps = createAttrs(visualElement, props);
23
+ }
24
+ </script>
25
+
26
+ <slot {svgProps} />
@@ -0,0 +1,77 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ type Job = () => void;
6
+ type JobSetter = (job: Job) => void;
7
+ type ReadWrites = (read: JobSetter, write: JobSetter) => void;
8
+
9
+ /**
10
+ based on framer-motion@4.1.15,
11
+ Copyright (c) 2018 Framer B.V.
12
+ */
13
+ import sync from 'framesync';
14
+
15
+ var unresolvedJobs = new Set();
16
+ var layoutState = {
17
+ isMeasuringLayout: false,
18
+ };
19
+ function pushJob(stack, job, pointer) {
20
+ if (!stack[pointer])
21
+ stack[pointer] = [];
22
+ stack[pointer].push(job);
23
+ }
24
+ function batchLayout(callback: ReadWrites) {
25
+ unresolvedJobs.add(callback);
26
+ return function () { return unresolvedJobs.delete(callback); };
27
+ }
28
+ function flushLayout() {
29
+ if (!unresolvedJobs.size)
30
+ return;
31
+ var pointer = 0;
32
+ var reads = [[]];
33
+ var writes = [];
34
+ var setRead = function (job) { return pushJob(reads, job, pointer); };
35
+ var setWrite = function (job) {
36
+ pushJob(writes, job, pointer);
37
+ pointer++;
38
+ };
39
+ /**
40
+ * Resolve jobs into their array stacks
41
+ */
42
+ unresolvedJobs.forEach(function (callback) {
43
+ callback(setRead, setWrite);
44
+ pointer = 0;
45
+ });
46
+ unresolvedJobs.clear();
47
+ /**
48
+ * Mark that we're currently measuring layouts. This allows us to, for instance, ignore
49
+ * hover events that might be triggered as a result of resetting transforms.
50
+ *
51
+ * The postRender/setTimeout combo seems like an odd bit of scheduling but what it's saying
52
+ * is *after* the next render, wait 10ms before re-enabling hover events. Waiting until the
53
+ * next frame completely will result in missed, valid hover events. But events seem to
54
+ * be fired async from their actual action, so setting this to false too soon can still
55
+ * trigger events from layout measurements.
56
+ *
57
+ * Note: If we figure out a way of measuring layout while transforms remain applied, this can be removed.
58
+ * I have attempted unregistering event listeners and setting CSS to pointer-events: none
59
+ * but neither seem to work as expected.
60
+ */
61
+ layoutState.isMeasuringLayout = true;
62
+ sync.postRender(function () {
63
+ setTimeout(function () { return (layoutState.isMeasuringLayout = false); }, 10);
64
+ });
65
+ /**
66
+ * Execute jobs
67
+ */
68
+ var numStacks = writes.length;
69
+ for (var i = 0; i <= numStacks; i++) {
70
+ reads[i] && reads[i].forEach(executeJob);
71
+ writes[i] && writes[i].forEach(executeJob);
72
+ }
73
+ }
74
+ var executeJob = function (job) { return job(); };
75
+
76
+ export { batchLayout, flushLayout, layoutState };
77
+
@@ -0,0 +1,20 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+
6
+
7
+ /**
8
+ based on framer-motion@4.0.3,
9
+ Copyright (c) 2018 Framer B.V.
10
+ */
11
+ var CAMEL_CASE_PATTERN = /([a-z])([A-Z])/g;
12
+ var REPLACE_TEMPLATE = "$1-$2";
13
+ /**
14
+ * Convert camelCase to dash-case properties.
15
+ */
16
+ var camelToDash = function (str: string) {
17
+ return str.replace(CAMEL_CASE_PATTERN, REPLACE_TEMPLATE).toLowerCase();
18
+ };
19
+
20
+ export { camelToDash };
@@ -0,0 +1,33 @@
1
+
2
+ /**
3
+ based on framer-motion@4.1.17,
4
+ Copyright (c) 2018 Framer B.V.
5
+ */
6
+ import type { MotionComponentConfig } from "../../../motion";
7
+ import type { FeatureComponents } from "../../../motion/features/types";
8
+ import type { HTMLRenderState } from "../../html/types";
9
+ import type { SVGRenderState } from "../../svg/types";
10
+ import type { CreateVisualElement } from "../../types";
11
+ import type { CustomMotionComponentConfig } from "../motion-proxy";
12
+
13
+
14
+ /**
15
+ based on framer-motion@4.0.3,
16
+ Copyright (c) 2018 Framer B.V.
17
+ */
18
+ import { __assign } from 'tslib';
19
+ import { htmlMotionConfig } from '../../html/config-motion.js';
20
+ import { svgMotionConfig } from '../../svg/config-motion.js';
21
+ import { createUseRender } from '../use-render.js';
22
+ import { isSVGComponent } from './is-svg-component.js';
23
+
24
+ function createDomMotionConfig<Props>(Component: string | React.ComponentType<Props>, { forwardMotionProps }: CustomMotionComponentConfig, preloadedFeatures?: FeatureComponents, createVisualElement?: CreateVisualElement<any>) {
25
+ var baseConfig = isSVGComponent(Component)
26
+ ? svgMotionConfig
27
+ : htmlMotionConfig;
28
+ return __assign(__assign({}, baseConfig), { preloadedFeatures: preloadedFeatures, useRender: createUseRender(forwardMotionProps), createVisualElement: createVisualElement,
29
+ Component: Component }) as MotionComponentConfig<SVGElement, SVGRenderState> | MotionComponentConfig<HTMLElement, HTMLRenderState>;
30
+ }
31
+
32
+ export { createDomMotionConfig };
33
+
@@ -0,0 +1,121 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { Target, TargetWithKeyframes } from "../../../types";
6
+ import type { VisualElement } from "../../types";
7
+ /**
8
+ * Parse Framer's special CSS variable format into a CSS token and a fallback.
9
+ *
10
+ * ```
11
+ * `var(--foo, #fff)` => [`--foo`, '#fff']
12
+ * ```
13
+ *
14
+ * @param current
15
+ */
16
+ // export declare const cssVariableRegex: RegExp;
17
+ // export declare function parseCSSVariable(current: string): string[] | undefined[];
18
+ /**
19
+ * Resolve CSS variables from
20
+ *
21
+ * @internal
22
+ */
23
+ // export declare function resolveCSSVariables(): ;
24
+
25
+
26
+ /**
27
+ based on framer-motion@4.0.3,
28
+ Copyright (c) 2018 Framer B.V.
29
+ */
30
+ import { __assign, __read } from 'tslib';
31
+ // import { invariant } from '../../../utils/errors.js';
32
+
33
+ function isCSSVariable(value) {
34
+ return typeof value === "string" && value.startsWith("var(--");
35
+ }
36
+ /**
37
+ * Parse Framer's special CSS variable format into a CSS token and a fallback.
38
+ *
39
+ * ```
40
+ * `var(--foo, #fff)` => [`--foo`, '#fff']
41
+ * ```
42
+ *
43
+ * @param current
44
+ */
45
+ var cssVariableRegex = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/;
46
+ function parseCSSVariable(current: string): string[] | undefined[] {
47
+ var match = cssVariableRegex.exec(current);
48
+ if (!match)
49
+ return [,];
50
+ var _a = __read(match, 3), token = _a[1], fallback = _a[2];
51
+ return [token, fallback];
52
+ }
53
+ var maxDepth = 4;
54
+ function getVariableValue(current, element, depth) {
55
+ if (depth === void 0) { depth = 1; }
56
+ //invariant(depth <= maxDepth, "Max CSS variable fallback depth detected in property \"" + current + "\". This may indicate a circular fallback dependency.");
57
+ var _a = __read(parseCSSVariable(current), 2), token = _a[0], fallback = _a[1];
58
+ // No CSS variable detected
59
+ if (!token)
60
+ return;
61
+ // Attempt to read this CSS variable off the element
62
+ var resolved = window.getComputedStyle(element).getPropertyValue(token);
63
+ if (resolved) {
64
+ return resolved.trim();
65
+ }
66
+ else if (isCSSVariable(fallback)) {
67
+ // The fallback might itself be a CSS variable, in which case we attempt to resolve it too.
68
+ return getVariableValue(fallback, element, depth + 1);
69
+ }
70
+ else {
71
+ return fallback;
72
+ }
73
+ }
74
+ /**
75
+ * Resolve CSS variables from
76
+ *
77
+ * @internal
78
+ */
79
+ function resolveCSSVariables(visualElement: VisualElement, { ...target }: TargetWithKeyframes, transitionEnd: Target | undefined): {
80
+ target: TargetWithKeyframes;
81
+ transitionEnd?: Target;
82
+ } {
83
+ var element = visualElement.getInstance();
84
+ if (!(element instanceof HTMLElement))
85
+ return { target: target, transitionEnd: transitionEnd };
86
+ // If `transitionEnd` isn't `undefined`, clone it. We could clone `target` and `transitionEnd`
87
+ // only if they change but I think this reads clearer and this isn't a performance-critical path.
88
+ if (transitionEnd) {
89
+ transitionEnd = __assign({}, transitionEnd);
90
+ }
91
+ // Go through existing `MotionValue`s and ensure any existing CSS variables are resolved
92
+ visualElement.forEachValue(function (value) {
93
+ var current = value.get();
94
+ if (!isCSSVariable(current))
95
+ return;
96
+ var resolved = getVariableValue(current, element);
97
+ if (resolved)
98
+ value.set(resolved);
99
+ });
100
+ // Cycle through every target property and resolve CSS variables. Currently
101
+ // we only read single-var properties like `var(--foo)`, not `calc(var(--foo) + 20px)`
102
+ for (var key in target) {
103
+ var current = target[key];
104
+ if (!isCSSVariable(current))
105
+ continue;
106
+ var resolved = getVariableValue(current, element);
107
+ if (!resolved)
108
+ continue;
109
+ // Clone target if it hasn't already been
110
+ target[key] = resolved;
111
+ // If the user hasn't already set this key on `transitionEnd`, set it to the unresolved
112
+ // CSS variable. This will ensure that after the animation the component will reflect
113
+ // changes in the value of the CSS variable.
114
+ if (transitionEnd)
115
+ (_b = transitionEnd[key]) !== null && _b !== void 0 ? _b : (transitionEnd[key] = current);
116
+ }
117
+ return { target: target, transitionEnd: transitionEnd };
118
+ }
119
+
120
+ export { cssVariableRegex, parseCSSVariable, resolveCSSVariables };
121
+
@@ -0,0 +1,55 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { MotionProps } from "../../../motion/types";
6
+
7
+
8
+ /**
9
+ based on framer-motion@4.0.3,
10
+ Copyright (c) 2018 Framer B.V.
11
+ */
12
+ import { isValidMotionProp } from '../../../motion/utils/valid-prop.js';
13
+
14
+ var shouldForward = function (key) { return !isValidMotionProp(key); };
15
+ /**
16
+ * Emotion and Styled Components both allow users to pass through arbitrary props to their components
17
+ * to dynamically generate CSS. They both use the `@emotion/is-prop-valid` package to determine which
18
+ * of these should be passed to the underlying DOM node.
19
+ *
20
+ * However, when styling a Motion component `styled(MotionDiv)`, both packages pass through *all* props
21
+ * as it's seen as an arbitrary component rather than a DOM node. Motion only allows arbitrary props
22
+ * passed through the `custom` prop so it doesn't *need* the payload or computational overhead of
23
+ * `@emotion/is-prop-valid`, however to fix this problem we need to use it.
24
+ *
25
+ * By making it an optionalDependency we can offer this functionality only in the situations where it's
26
+ * actually required.
27
+ */
28
+ try {
29
+ var emotionIsPropValid_1 = require("@emotion/is-prop-valid").default;
30
+ shouldForward = function (key) {
31
+ // Handle events explicitly as Emotion validates them all as true
32
+ if (key.startsWith("on")) {
33
+ return !isValidMotionProp(key);
34
+ }
35
+ else {
36
+ return emotionIsPropValid_1(key);
37
+ }
38
+ };
39
+ }
40
+ catch (_a) {
41
+ // We don't need to actually do anything here - the fallback is the existing `isPropValid`.
42
+ }
43
+ function filterProps(props: MotionProps, isDom: boolean, forwardMotionProps: boolean) {
44
+ var filteredProps = {};
45
+ for (var key in props) {
46
+ if (shouldForward(key) ||
47
+ (forwardMotionProps === true && isValidMotionProp(key)) ||
48
+ (!isDom && !isValidMotionProp(key))) {
49
+ filteredProps[key] = props[key];
50
+ }
51
+ }
52
+ return filteredProps;
53
+ }
54
+
55
+ export { filterProps };
@@ -0,0 +1,18 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+
6
+
7
+ /**
8
+ based on framer-motion@4.0.3,
9
+ Copyright (c) 2018 Framer B.V.
10
+ */
11
+ /**
12
+ * Returns true if the provided key is a CSS variable
13
+ */
14
+ function isCSSVariable(key: string) {
15
+ return key.startsWith("--");
16
+ }
17
+
18
+ export { isCSSVariable };