@teamturing/react-kit 2.4.0 → 2.5.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/core/Dialog/index.d.ts +16 -0
- package/dist/core/DialogHandler/index.d.ts +13 -0
- package/dist/core/Grid/index.d.ts +2 -2
- package/dist/core/MotionView/index.d.ts +3 -0
- package/dist/core/Stack/index.d.ts +2 -2
- package/dist/hook/useDialogHandler.d.ts +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9762 -323
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/isFunction.d.ts +1 -0
- package/esm/core/Dialog/index.js +188 -0
- package/esm/core/DialogHandler/index.js +33 -0
- package/esm/core/MotionView/index.js +6 -0
- package/esm/hook/useDialogHandler.js +14 -0
- package/esm/index.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/instant.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/js/driver-frameloop.js +16 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/js/index.js +303 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/create-accelerated-animation.js +199 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/easing.js +31 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/index.js +23 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/utils/get-final-keyframe.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/inertia.js +87 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/keyframes.js +51 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/spring/find.js +89 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/spring/index.js +129 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/utils/calc-duration.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/utils/velocity.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/motion-value.js +101 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/single-value.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/visual-element-target.js +71 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/visual-element-variant.js +63 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/visual-element.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/animation/optimized-appear/data-id.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/default-transitions.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-animatable.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-animation-controls.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-keyframes-target.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-none.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/keyframes.js +45 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/transitions.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/PopChild.js +71 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/PresenceChild.js +56 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/index.js +158 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/use-presence.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/context/LayoutGroupContext.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/context/LazyContext.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionConfigContext.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionContext/create.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionContext/index.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionContext/utils.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/context/PresenceContext.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/context/SwitchLayoutGroupContext.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/debug/record.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/easing/anticipate.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/back.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/easing/circ.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/easing/cubic-bezier.js +51 -0
- package/esm/node_modules/framer-motion/dist/es/easing/ease.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/easing/modifiers/mirror.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/modifiers/reverse.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/utils/is-bezier-definition.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/easing/utils/is-easing-array.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/utils/map.js +37 -0
- package/esm/node_modules/framer-motion/dist/es/events/add-dom-event.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/events/add-pointer-event.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/events/event-info.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/events/utils/is-primary-pointer.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/frameloop/batcher.js +60 -0
- package/esm/node_modules/framer-motion/dist/es/frameloop/frame.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/frameloop/render-step.js +104 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/VisualElementDragControls.js +457 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/index.js +27 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/utils/constraints.js +125 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/utils/lock.js +53 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/focus.js +41 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/hover.js +32 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/pan/PanSession.js +148 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/pan/index.js +46 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/press.js +120 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/utils/is-node-or-child.js +20 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/Feature.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/animation/exit.js +31 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/animation/index.js +38 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/animations.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/definitions.js +28 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/drag.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/gestures.js +21 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/layout/MeasureLayout.js +131 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/layout.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/load-features.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/viewport/index.js +72 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/viewport/observers.js +49 -0
- package/esm/node_modules/framer-motion/dist/es/motion/index.js +79 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/is-forced-motion-value.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/symbol.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/use-motion-ref.js +33 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/use-visual-element.js +75 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/use-visual-state.js +81 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/valid-prop.js +59 -0
- package/esm/node_modules/framer-motion/dist/es/projection/animation/mix-values.js +93 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/conversion.js +33 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/copy.js +20 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/delta-apply.js +122 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/delta-calc.js +41 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/delta-remove.js +54 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/models.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/utils.js +25 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/DocumentProjectionNode.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/HTMLProjectionNode.js +27 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/create-projection-node.js +1494 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/state.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/projection/shared/stack.js +112 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/scale-border-radius.js +41 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/scale-box-shadow.js +35 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/scale-correction.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/transform.js +42 -0
- package/esm/node_modules/framer-motion/dist/es/projection/utils/each-axis.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/projection/utils/has-transform.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/projection/utils/measure.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/render/VisualElement.js +507 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/DOMVisualElement.js +48 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/create-visual-element.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/motion-proxy.js +47 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/motion.js +23 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/use-render.js +35 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/camel-to-dash.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/create-config.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/css-variables-conversion.js +89 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/filter-props.js +57 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/is-css-variable.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/is-svg-component.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/is-svg-element.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/parse-dom-variant.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/unit-conversion.js +230 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/animatable-none.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/defaults.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/dimensions.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/find.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/get-as-type.js +10 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/number.js +72 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/test.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/type-auto.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/type-int.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/HTMLVisualElement.js +55 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/config-motion.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/use-props.js +57 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/build-styles.js +74 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/build-transform.js +45 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/create-render-state.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/render.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/scrape-motion-values.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/transform.js +28 -0
- package/esm/node_modules/framer-motion/dist/es/render/store.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/SVGVisualElement.js +46 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/config-motion.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/lowercase-elements.js +33 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/use-props.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/build-attrs.js +52 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/camel-case-attrs.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/create-render-state.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/is-svg-tag.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/path.js +32 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/render.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/scrape-motion-values.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/transform-origin.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/animation-state.js +319 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/compare-by-depth.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/flat-tree.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/is-controlling-variants.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/is-variant-label.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/motion-values.js +63 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/resolve-dynamic-variants.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/resolve-variants.js +26 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/setters.js +101 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/variant-props.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/utils/array.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/clamp.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/utils/delay.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/utils/distance.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/utils/errors.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/utils/hsla-to-rgba.js +42 -0
- package/esm/node_modules/framer-motion/dist/es/utils/interpolate.js +92 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-browser.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-numerical-string.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-ref-object.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-zero-value-string.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/memo.js +10 -0
- package/esm/node_modules/framer-motion/dist/es/utils/mix-color.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/utils/mix-complex.js +64 -0
- package/esm/node_modules/framer-motion/dist/es/utils/mix.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/utils/noop.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/utils/offsets/default.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/utils/offsets/fill.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/utils/offsets/time.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/utils/pipe.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/progress.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/utils/reduced-motion/index.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/utils/reduced-motion/state.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/utils/resolve-value.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/shallow-compare.js +14 -0
- package/esm/node_modules/framer-motion/dist/es/utils/subscription-manager.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/utils/time-conversion.js +10 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-constant.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-force-update.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-instant-transition-state.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-is-mounted.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-isomorphic-effect.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-unmount-effect.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/utils/velocity-per-second.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/warn-once.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/value/index.js +331 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/hex.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/hsla.js +22 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/index.js +28 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/rgba.js +25 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/utils.js +23 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/complex/filter.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/complex/index.js +92 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/numbers/index.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/numbers/units.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/utils.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/value/use-will-change/is.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/value/utils/is-motion-value.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/value/utils/resolve-motion-value.js +16 -0
- package/esm/packages/icons/esm/Close.js +17 -0
- package/esm/packages/token-studio/esm/token/elevation/index.js +5 -1
- package/esm/utils/isFunction.js +3 -0
- package/package.json +3 -3
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { SubscriptionManager } from '../utils/subscription-manager.js';
|
|
2
|
+
import { velocityPerSecond } from '../utils/velocity-per-second.js';
|
|
3
|
+
import { warnOnce } from '../utils/warn-once.js';
|
|
4
|
+
import { frame, frameData } from '../frameloop/frame.js';
|
|
5
|
+
|
|
6
|
+
const isFloat = (value) => {
|
|
7
|
+
return !isNaN(parseFloat(value));
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* `MotionValue` is used to track the state and velocity of motion values.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
class MotionValue {
|
|
15
|
+
/**
|
|
16
|
+
* @param init - The initiating value
|
|
17
|
+
* @param config - Optional configuration options
|
|
18
|
+
*
|
|
19
|
+
* - `transformer`: A function to transform incoming values with.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
constructor(init, options = {}) {
|
|
24
|
+
/**
|
|
25
|
+
* This will be replaced by the build step with the latest version number.
|
|
26
|
+
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
27
|
+
*/
|
|
28
|
+
this.version = "10.16.4";
|
|
29
|
+
/**
|
|
30
|
+
* Duration, in milliseconds, since last updating frame.
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
this.timeDelta = 0;
|
|
35
|
+
/**
|
|
36
|
+
* Timestamp of the last time this `MotionValue` was updated.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
this.lastUpdated = 0;
|
|
41
|
+
/**
|
|
42
|
+
* Tracks whether this value can output a velocity. Currently this is only true
|
|
43
|
+
* if the value is numerical, but we might be able to widen the scope here and support
|
|
44
|
+
* other value types.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
this.canTrackVelocity = false;
|
|
49
|
+
/**
|
|
50
|
+
* An object containing a SubscriptionManager for each active event.
|
|
51
|
+
*/
|
|
52
|
+
this.events = {};
|
|
53
|
+
this.updateAndNotify = (v, render = true) => {
|
|
54
|
+
this.prev = this.current;
|
|
55
|
+
this.current = v;
|
|
56
|
+
// Update timestamp
|
|
57
|
+
const { delta, timestamp } = frameData;
|
|
58
|
+
if (this.lastUpdated !== timestamp) {
|
|
59
|
+
this.timeDelta = delta;
|
|
60
|
+
this.lastUpdated = timestamp;
|
|
61
|
+
frame.postRender(this.scheduleVelocityCheck);
|
|
62
|
+
}
|
|
63
|
+
// Update update subscribers
|
|
64
|
+
if (this.prev !== this.current && this.events.change) {
|
|
65
|
+
this.events.change.notify(this.current);
|
|
66
|
+
}
|
|
67
|
+
// Update velocity subscribers
|
|
68
|
+
if (this.events.velocityChange) {
|
|
69
|
+
this.events.velocityChange.notify(this.getVelocity());
|
|
70
|
+
}
|
|
71
|
+
// Update render subscribers
|
|
72
|
+
if (render && this.events.renderRequest) {
|
|
73
|
+
this.events.renderRequest.notify(this.current);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Schedule a velocity check for the next frame.
|
|
78
|
+
*
|
|
79
|
+
* This is an instanced and bound function to prevent generating a new
|
|
80
|
+
* function once per frame.
|
|
81
|
+
*
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
this.scheduleVelocityCheck = () => frame.postRender(this.velocityCheck);
|
|
85
|
+
/**
|
|
86
|
+
* Updates `prev` with `current` if the value hasn't been updated this frame.
|
|
87
|
+
* This ensures velocity calculations return `0`.
|
|
88
|
+
*
|
|
89
|
+
* This is an instanced and bound function to prevent generating a new
|
|
90
|
+
* function once per frame.
|
|
91
|
+
*
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
this.velocityCheck = ({ timestamp }) => {
|
|
95
|
+
if (timestamp !== this.lastUpdated) {
|
|
96
|
+
this.prev = this.current;
|
|
97
|
+
if (this.events.velocityChange) {
|
|
98
|
+
this.events.velocityChange.notify(this.getVelocity());
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
this.hasAnimated = false;
|
|
103
|
+
this.prev = this.current = init;
|
|
104
|
+
this.canTrackVelocity = isFloat(this.current);
|
|
105
|
+
this.owner = options.owner;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Adds a function that will be notified when the `MotionValue` is updated.
|
|
109
|
+
*
|
|
110
|
+
* It returns a function that, when called, will cancel the subscription.
|
|
111
|
+
*
|
|
112
|
+
* When calling `onChange` inside a React component, it should be wrapped with the
|
|
113
|
+
* `useEffect` hook. As it returns an unsubscribe function, this should be returned
|
|
114
|
+
* from the `useEffect` function to ensure you don't add duplicate subscribers..
|
|
115
|
+
*
|
|
116
|
+
* ```jsx
|
|
117
|
+
* export const MyComponent = () => {
|
|
118
|
+
* const x = useMotionValue(0)
|
|
119
|
+
* const y = useMotionValue(0)
|
|
120
|
+
* const opacity = useMotionValue(1)
|
|
121
|
+
*
|
|
122
|
+
* useEffect(() => {
|
|
123
|
+
* function updateOpacity() {
|
|
124
|
+
* const maxXY = Math.max(x.get(), y.get())
|
|
125
|
+
* const newOpacity = transform(maxXY, [0, 100], [1, 0])
|
|
126
|
+
* opacity.set(newOpacity)
|
|
127
|
+
* }
|
|
128
|
+
*
|
|
129
|
+
* const unsubscribeX = x.on("change", updateOpacity)
|
|
130
|
+
* const unsubscribeY = y.on("change", updateOpacity)
|
|
131
|
+
*
|
|
132
|
+
* return () => {
|
|
133
|
+
* unsubscribeX()
|
|
134
|
+
* unsubscribeY()
|
|
135
|
+
* }
|
|
136
|
+
* }, [])
|
|
137
|
+
*
|
|
138
|
+
* return <motion.div style={{ x }} />
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @param subscriber - A function that receives the latest value.
|
|
143
|
+
* @returns A function that, when called, will cancel this subscription.
|
|
144
|
+
*
|
|
145
|
+
* @deprecated
|
|
146
|
+
*/
|
|
147
|
+
onChange(subscription) {
|
|
148
|
+
if (process.env.NODE_ENV !== "production") {
|
|
149
|
+
warnOnce(false, `value.onChange(callback) is deprecated. Switch to value.on("change", callback).`);
|
|
150
|
+
}
|
|
151
|
+
return this.on("change", subscription);
|
|
152
|
+
}
|
|
153
|
+
on(eventName, callback) {
|
|
154
|
+
if (!this.events[eventName]) {
|
|
155
|
+
this.events[eventName] = new SubscriptionManager();
|
|
156
|
+
}
|
|
157
|
+
const unsubscribe = this.events[eventName].add(callback);
|
|
158
|
+
if (eventName === "change") {
|
|
159
|
+
return () => {
|
|
160
|
+
unsubscribe();
|
|
161
|
+
/**
|
|
162
|
+
* If we have no more change listeners by the start
|
|
163
|
+
* of the next frame, stop active animations.
|
|
164
|
+
*/
|
|
165
|
+
frame.read(() => {
|
|
166
|
+
if (!this.events.change.getSize()) {
|
|
167
|
+
this.stop();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
return unsubscribe;
|
|
173
|
+
}
|
|
174
|
+
clearListeners() {
|
|
175
|
+
for (const eventManagers in this.events) {
|
|
176
|
+
this.events[eventManagers].clear();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Attaches a passive effect to the `MotionValue`.
|
|
181
|
+
*
|
|
182
|
+
* @internal
|
|
183
|
+
*/
|
|
184
|
+
attach(passiveEffect, stopPassiveEffect) {
|
|
185
|
+
this.passiveEffect = passiveEffect;
|
|
186
|
+
this.stopPassiveEffect = stopPassiveEffect;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Sets the state of the `MotionValue`.
|
|
190
|
+
*
|
|
191
|
+
* @remarks
|
|
192
|
+
*
|
|
193
|
+
* ```jsx
|
|
194
|
+
* const x = useMotionValue(0)
|
|
195
|
+
* x.set(10)
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @param latest - Latest value to set.
|
|
199
|
+
* @param render - Whether to notify render subscribers. Defaults to `true`
|
|
200
|
+
*
|
|
201
|
+
* @public
|
|
202
|
+
*/
|
|
203
|
+
set(v, render = true) {
|
|
204
|
+
if (!render || !this.passiveEffect) {
|
|
205
|
+
this.updateAndNotify(v, render);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
this.passiveEffect(v, this.updateAndNotify);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
setWithVelocity(prev, current, delta) {
|
|
212
|
+
this.set(current);
|
|
213
|
+
this.prev = prev;
|
|
214
|
+
this.timeDelta = delta;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Set the state of the `MotionValue`, stopping any active animations,
|
|
218
|
+
* effects, and resets velocity to `0`.
|
|
219
|
+
*/
|
|
220
|
+
jump(v) {
|
|
221
|
+
this.updateAndNotify(v);
|
|
222
|
+
this.prev = v;
|
|
223
|
+
this.stop();
|
|
224
|
+
if (this.stopPassiveEffect)
|
|
225
|
+
this.stopPassiveEffect();
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Returns the latest state of `MotionValue`
|
|
229
|
+
*
|
|
230
|
+
* @returns - The latest state of `MotionValue`
|
|
231
|
+
*
|
|
232
|
+
* @public
|
|
233
|
+
*/
|
|
234
|
+
get() {
|
|
235
|
+
return this.current;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* @public
|
|
239
|
+
*/
|
|
240
|
+
getPrevious() {
|
|
241
|
+
return this.prev;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Returns the latest velocity of `MotionValue`
|
|
245
|
+
*
|
|
246
|
+
* @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.
|
|
247
|
+
*
|
|
248
|
+
* @public
|
|
249
|
+
*/
|
|
250
|
+
getVelocity() {
|
|
251
|
+
// This could be isFloat(this.prev) && isFloat(this.current), but that would be wasteful
|
|
252
|
+
return this.canTrackVelocity
|
|
253
|
+
? // These casts could be avoided if parseFloat would be typed better
|
|
254
|
+
velocityPerSecond(parseFloat(this.current) -
|
|
255
|
+
parseFloat(this.prev), this.timeDelta)
|
|
256
|
+
: 0;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Registers a new animation to control this `MotionValue`. Only one
|
|
260
|
+
* animation can drive a `MotionValue` at one time.
|
|
261
|
+
*
|
|
262
|
+
* ```jsx
|
|
263
|
+
* value.start()
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @param animation - A function that starts the provided animation
|
|
267
|
+
*
|
|
268
|
+
* @internal
|
|
269
|
+
*/
|
|
270
|
+
start(startAnimation) {
|
|
271
|
+
this.stop();
|
|
272
|
+
return new Promise((resolve) => {
|
|
273
|
+
this.hasAnimated = true;
|
|
274
|
+
this.animation = startAnimation(resolve);
|
|
275
|
+
if (this.events.animationStart) {
|
|
276
|
+
this.events.animationStart.notify();
|
|
277
|
+
}
|
|
278
|
+
}).then(() => {
|
|
279
|
+
if (this.events.animationComplete) {
|
|
280
|
+
this.events.animationComplete.notify();
|
|
281
|
+
}
|
|
282
|
+
this.clearAnimation();
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Stop the currently active animation.
|
|
287
|
+
*
|
|
288
|
+
* @public
|
|
289
|
+
*/
|
|
290
|
+
stop() {
|
|
291
|
+
if (this.animation) {
|
|
292
|
+
this.animation.stop();
|
|
293
|
+
if (this.events.animationCancel) {
|
|
294
|
+
this.events.animationCancel.notify();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
this.clearAnimation();
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Returns `true` if this value is currently animating.
|
|
301
|
+
*
|
|
302
|
+
* @public
|
|
303
|
+
*/
|
|
304
|
+
isAnimating() {
|
|
305
|
+
return !!this.animation;
|
|
306
|
+
}
|
|
307
|
+
clearAnimation() {
|
|
308
|
+
delete this.animation;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Destroy and clean up subscribers to this `MotionValue`.
|
|
312
|
+
*
|
|
313
|
+
* The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically
|
|
314
|
+
* handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually
|
|
315
|
+
* created a `MotionValue` via the `motionValue` function.
|
|
316
|
+
*
|
|
317
|
+
* @public
|
|
318
|
+
*/
|
|
319
|
+
destroy() {
|
|
320
|
+
this.clearListeners();
|
|
321
|
+
this.stop();
|
|
322
|
+
if (this.stopPassiveEffect) {
|
|
323
|
+
this.stopPassiveEffect();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function motionValue(init, options) {
|
|
328
|
+
return new MotionValue(init, options);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export { MotionValue, motionValue };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { rgba } from './rgba.js';
|
|
2
|
+
import { isColorString } from './utils.js';
|
|
3
|
+
|
|
4
|
+
function parseHex(v) {
|
|
5
|
+
let r = "";
|
|
6
|
+
let g = "";
|
|
7
|
+
let b = "";
|
|
8
|
+
let a = "";
|
|
9
|
+
// If we have 6 characters, ie #FF0000
|
|
10
|
+
if (v.length > 5) {
|
|
11
|
+
r = v.substring(1, 3);
|
|
12
|
+
g = v.substring(3, 5);
|
|
13
|
+
b = v.substring(5, 7);
|
|
14
|
+
a = v.substring(7, 9);
|
|
15
|
+
// Or we have 3 characters, ie #F00
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
r = v.substring(1, 2);
|
|
19
|
+
g = v.substring(2, 3);
|
|
20
|
+
b = v.substring(3, 4);
|
|
21
|
+
a = v.substring(4, 5);
|
|
22
|
+
r += r;
|
|
23
|
+
g += g;
|
|
24
|
+
b += b;
|
|
25
|
+
a += a;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
red: parseInt(r, 16),
|
|
29
|
+
green: parseInt(g, 16),
|
|
30
|
+
blue: parseInt(b, 16),
|
|
31
|
+
alpha: a ? parseInt(a, 16) / 255 : 1,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const hex = {
|
|
35
|
+
test: isColorString("#"),
|
|
36
|
+
parse: parseHex,
|
|
37
|
+
transform: rgba.transform,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { hex };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { alpha } from '../numbers/index.js';
|
|
2
|
+
import { percent } from '../numbers/units.js';
|
|
3
|
+
import { sanitize } from '../utils.js';
|
|
4
|
+
import { isColorString, splitColor } from './utils.js';
|
|
5
|
+
|
|
6
|
+
const hsla = {
|
|
7
|
+
test: isColorString("hsl", "hue"),
|
|
8
|
+
parse: splitColor("hue", "saturation", "lightness"),
|
|
9
|
+
transform: ({ hue, saturation, lightness, alpha: alpha$1 = 1 }) => {
|
|
10
|
+
return ("hsla(" +
|
|
11
|
+
Math.round(hue) +
|
|
12
|
+
", " +
|
|
13
|
+
percent.transform(sanitize(saturation)) +
|
|
14
|
+
", " +
|
|
15
|
+
percent.transform(sanitize(lightness)) +
|
|
16
|
+
", " +
|
|
17
|
+
sanitize(alpha.transform(alpha$1)) +
|
|
18
|
+
")");
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { hsla };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isString } from '../utils.js';
|
|
2
|
+
import { hex } from './hex.js';
|
|
3
|
+
import { hsla } from './hsla.js';
|
|
4
|
+
import { rgba } from './rgba.js';
|
|
5
|
+
|
|
6
|
+
const color = {
|
|
7
|
+
test: (v) => rgba.test(v) || hex.test(v) || hsla.test(v),
|
|
8
|
+
parse: (v) => {
|
|
9
|
+
if (rgba.test(v)) {
|
|
10
|
+
return rgba.parse(v);
|
|
11
|
+
}
|
|
12
|
+
else if (hsla.test(v)) {
|
|
13
|
+
return hsla.parse(v);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return hex.parse(v);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
transform: (v) => {
|
|
20
|
+
return isString(v)
|
|
21
|
+
? v
|
|
22
|
+
: v.hasOwnProperty("red")
|
|
23
|
+
? rgba.transform(v)
|
|
24
|
+
: hsla.transform(v);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { color };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { clamp } from '../../../utils/clamp.js';
|
|
2
|
+
import { number, alpha } from '../numbers/index.js';
|
|
3
|
+
import { sanitize } from '../utils.js';
|
|
4
|
+
import { isColorString, splitColor } from './utils.js';
|
|
5
|
+
|
|
6
|
+
const clampRgbUnit = (v) => clamp(0, 255, v);
|
|
7
|
+
const rgbUnit = {
|
|
8
|
+
...number,
|
|
9
|
+
transform: (v) => Math.round(clampRgbUnit(v)),
|
|
10
|
+
};
|
|
11
|
+
const rgba = {
|
|
12
|
+
test: isColorString("rgb", "red"),
|
|
13
|
+
parse: splitColor("red", "green", "blue"),
|
|
14
|
+
transform: ({ red, green, blue, alpha: alpha$1 = 1 }) => "rgba(" +
|
|
15
|
+
rgbUnit.transform(red) +
|
|
16
|
+
", " +
|
|
17
|
+
rgbUnit.transform(green) +
|
|
18
|
+
", " +
|
|
19
|
+
rgbUnit.transform(blue) +
|
|
20
|
+
", " +
|
|
21
|
+
sanitize(alpha.transform(alpha$1)) +
|
|
22
|
+
")",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { rgbUnit, rgba };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isString, singleColorRegex, floatRegex } from '../utils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the provided string is a color, ie rgba(0,0,0,0) or #000,
|
|
5
|
+
* but false if a number or multiple colors
|
|
6
|
+
*/
|
|
7
|
+
const isColorString = (type, testProp) => (v) => {
|
|
8
|
+
return Boolean((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) ||
|
|
9
|
+
(testProp && Object.prototype.hasOwnProperty.call(v, testProp)));
|
|
10
|
+
};
|
|
11
|
+
const splitColor = (aName, bName, cName) => (v) => {
|
|
12
|
+
if (!isString(v))
|
|
13
|
+
return v;
|
|
14
|
+
const [a, b, c, alpha] = v.match(floatRegex);
|
|
15
|
+
return {
|
|
16
|
+
[aName]: parseFloat(a),
|
|
17
|
+
[bName]: parseFloat(b),
|
|
18
|
+
[cName]: parseFloat(c),
|
|
19
|
+
alpha: alpha !== undefined ? parseFloat(alpha) : 1,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { isColorString, splitColor };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { complex } from './index.js';
|
|
2
|
+
import { floatRegex } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Properties that should default to 1 or 100%
|
|
6
|
+
*/
|
|
7
|
+
const maxDefaults = new Set(["brightness", "contrast", "saturate", "opacity"]);
|
|
8
|
+
function applyDefaultFilter(v) {
|
|
9
|
+
const [name, value] = v.slice(0, -1).split("(");
|
|
10
|
+
if (name === "drop-shadow")
|
|
11
|
+
return v;
|
|
12
|
+
const [number] = value.match(floatRegex) || [];
|
|
13
|
+
if (!number)
|
|
14
|
+
return v;
|
|
15
|
+
const unit = value.replace(number, "");
|
|
16
|
+
let defaultValue = maxDefaults.has(name) ? 1 : 0;
|
|
17
|
+
if (number !== value)
|
|
18
|
+
defaultValue *= 100;
|
|
19
|
+
return name + "(" + defaultValue + unit + ")";
|
|
20
|
+
}
|
|
21
|
+
const functionRegex = /([a-z-]*)\(.*?\)/g;
|
|
22
|
+
const filter = {
|
|
23
|
+
...complex,
|
|
24
|
+
getAnimatableNone: (v) => {
|
|
25
|
+
const functions = v.match(functionRegex);
|
|
26
|
+
return functions ? functions.map(applyDefaultFilter).join(" ") : v;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { filter };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { cssVariableRegex } from '../../../render/dom/utils/is-css-variable.js';
|
|
2
|
+
import { noop } from '../../../utils/noop.js';
|
|
3
|
+
import { color } from '../color/index.js';
|
|
4
|
+
import { number } from '../numbers/index.js';
|
|
5
|
+
import { colorRegex, isString, floatRegex, sanitize } from '../utils.js';
|
|
6
|
+
|
|
7
|
+
function test(v) {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
return (isNaN(v) &&
|
|
10
|
+
isString(v) &&
|
|
11
|
+
(((_a = v.match(floatRegex)) === null || _a === void 0 ? void 0 : _a.length) || 0) +
|
|
12
|
+
(((_b = v.match(colorRegex)) === null || _b === void 0 ? void 0 : _b.length) || 0) >
|
|
13
|
+
0);
|
|
14
|
+
}
|
|
15
|
+
const cssVarTokeniser = {
|
|
16
|
+
regex: cssVariableRegex,
|
|
17
|
+
countKey: "Vars",
|
|
18
|
+
token: "${v}",
|
|
19
|
+
parse: noop,
|
|
20
|
+
};
|
|
21
|
+
const colorTokeniser = {
|
|
22
|
+
regex: colorRegex,
|
|
23
|
+
countKey: "Colors",
|
|
24
|
+
token: "${c}",
|
|
25
|
+
parse: color.parse,
|
|
26
|
+
};
|
|
27
|
+
const numberTokeniser = {
|
|
28
|
+
regex: floatRegex,
|
|
29
|
+
countKey: "Numbers",
|
|
30
|
+
token: "${n}",
|
|
31
|
+
parse: number.parse,
|
|
32
|
+
};
|
|
33
|
+
function tokenise(info, { regex, countKey, token, parse }) {
|
|
34
|
+
const matches = info.tokenised.match(regex);
|
|
35
|
+
if (!matches)
|
|
36
|
+
return;
|
|
37
|
+
info["num" + countKey] = matches.length;
|
|
38
|
+
info.tokenised = info.tokenised.replace(regex, token);
|
|
39
|
+
info.values.push(...matches.map(parse));
|
|
40
|
+
}
|
|
41
|
+
function analyseComplexValue(value) {
|
|
42
|
+
const originalValue = value.toString();
|
|
43
|
+
const info = {
|
|
44
|
+
value: originalValue,
|
|
45
|
+
tokenised: originalValue,
|
|
46
|
+
values: [],
|
|
47
|
+
numVars: 0,
|
|
48
|
+
numColors: 0,
|
|
49
|
+
numNumbers: 0,
|
|
50
|
+
};
|
|
51
|
+
if (info.value.includes("var(--"))
|
|
52
|
+
tokenise(info, cssVarTokeniser);
|
|
53
|
+
tokenise(info, colorTokeniser);
|
|
54
|
+
tokenise(info, numberTokeniser);
|
|
55
|
+
return info;
|
|
56
|
+
}
|
|
57
|
+
function parseComplexValue(v) {
|
|
58
|
+
return analyseComplexValue(v).values;
|
|
59
|
+
}
|
|
60
|
+
function createTransformer(source) {
|
|
61
|
+
const { values, numColors, numVars, tokenised } = analyseComplexValue(source);
|
|
62
|
+
const numValues = values.length;
|
|
63
|
+
return (v) => {
|
|
64
|
+
let output = tokenised;
|
|
65
|
+
for (let i = 0; i < numValues; i++) {
|
|
66
|
+
if (i < numVars) {
|
|
67
|
+
output = output.replace(cssVarTokeniser.token, v[i]);
|
|
68
|
+
}
|
|
69
|
+
else if (i < numVars + numColors) {
|
|
70
|
+
output = output.replace(colorTokeniser.token, color.transform(v[i]));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
output = output.replace(numberTokeniser.token, sanitize(v[i]));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return output;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const convertNumbersToZero = (v) => typeof v === "number" ? 0 : v;
|
|
80
|
+
function getAnimatableNone(v) {
|
|
81
|
+
const parsed = parseComplexValue(v);
|
|
82
|
+
const transformer = createTransformer(v);
|
|
83
|
+
return transformer(parsed.map(convertNumbersToZero));
|
|
84
|
+
}
|
|
85
|
+
const complex = {
|
|
86
|
+
test,
|
|
87
|
+
parse: parseComplexValue,
|
|
88
|
+
createTransformer,
|
|
89
|
+
getAnimatableNone,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export { analyseComplexValue, complex };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { clamp } from '../../../utils/clamp.js';
|
|
2
|
+
|
|
3
|
+
const number = {
|
|
4
|
+
test: (v) => typeof v === "number",
|
|
5
|
+
parse: parseFloat,
|
|
6
|
+
transform: (v) => v,
|
|
7
|
+
};
|
|
8
|
+
const alpha = {
|
|
9
|
+
...number,
|
|
10
|
+
transform: (v) => clamp(0, 1, v),
|
|
11
|
+
};
|
|
12
|
+
const scale = {
|
|
13
|
+
...number,
|
|
14
|
+
default: 1,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { alpha, number, scale };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isString } from '../utils.js';
|
|
2
|
+
|
|
3
|
+
const createUnitType = (unit) => ({
|
|
4
|
+
test: (v) => isString(v) && v.endsWith(unit) && v.split(" ").length === 1,
|
|
5
|
+
parse: parseFloat,
|
|
6
|
+
transform: (v) => `${v}${unit}`,
|
|
7
|
+
});
|
|
8
|
+
const degrees = createUnitType("deg");
|
|
9
|
+
const percent = createUnitType("%");
|
|
10
|
+
const px = createUnitType("px");
|
|
11
|
+
const vh = createUnitType("vh");
|
|
12
|
+
const vw = createUnitType("vw");
|
|
13
|
+
const progressPercentage = {
|
|
14
|
+
...percent,
|
|
15
|
+
parse: (v) => percent.parse(v) / 100,
|
|
16
|
+
transform: (v) => percent.transform(v * 100),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { degrees, percent, progressPercentage, px, vh, vw };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO: When we move from string as a source of truth to data models
|
|
3
|
+
* everything in this folder should probably be referred to as models vs types
|
|
4
|
+
*/
|
|
5
|
+
// If this number is a decimal, make it just five decimal places
|
|
6
|
+
// to avoid exponents
|
|
7
|
+
const sanitize = (v) => Math.round(v * 100000) / 100000;
|
|
8
|
+
const floatRegex = /(-)?([\d]*\.?[\d])+/g;
|
|
9
|
+
const colorRegex = /(#[0-9a-f]{3,8}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2}(-?[\d\.]+%?)\s*[\,\/]?\s*[\d\.]*%?\))/gi;
|
|
10
|
+
const singleColorRegex = /^(#[0-9a-f]{3,8}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2}(-?[\d\.]+%?)\s*[\,\/]?\s*[\d\.]*%?\))$/i;
|
|
11
|
+
function isString(v) {
|
|
12
|
+
return typeof v === "string";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { colorRegex, floatRegex, isString, sanitize, singleColorRegex };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isCustomValue } from '../../utils/resolve-value.js';
|
|
2
|
+
import { isMotionValue } from './is-motion-value.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
|
|
6
|
+
*
|
|
7
|
+
* TODO: Remove and move to library
|
|
8
|
+
*/
|
|
9
|
+
function resolveMotionValue(value) {
|
|
10
|
+
const unwrappedValue = isMotionValue(value) ? value.get() : value;
|
|
11
|
+
return isCustomValue(unwrappedValue)
|
|
12
|
+
? unwrappedValue.toValue()
|
|
13
|
+
: unwrappedValue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { resolveMotionValue };
|