motion-v 0.3.1-beta.1 → 0.4.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 (64) hide show
  1. package/dist/cjs/index.js +1826 -47
  2. package/dist/es/components/LayoutGroup.vue.mjs +39 -0
  3. package/dist/es/components/LayoutGroup.vue2.mjs +4 -0
  4. package/dist/es/components/Motion.vue.mjs +22 -10
  5. package/dist/es/components/context.mjs +12 -1
  6. package/dist/es/components/group.mjs +30 -0
  7. package/dist/es/components/use-force-update.mjs +11 -0
  8. package/dist/es/constants/index.mjs +8 -2
  9. package/dist/es/external/.pnpm/@vueuse_shared@12.0.0_typescript@5.5.4/external/@vueuse/shared/index.mjs +6 -0
  10. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/events/add-dom-event.mjs +7 -0
  11. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/frameloop/microtask.mjs +6 -0
  12. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/animation/mix-values.mjs +60 -0
  13. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/geometry/copy.mjs +19 -0
  14. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/geometry/delta-apply.mjs +81 -0
  15. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/geometry/delta-calc.mjs +55 -0
  16. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/geometry/delta-remove.mjs +40 -0
  17. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/geometry/models.mjs +13 -1
  18. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/geometry/utils.mjs +34 -0
  19. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/node/DocumentProjectionNode.mjs +13 -0
  20. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/node/HTMLProjectionNode.mjs +28 -0
  21. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/node/create-projection-node.mjs +1086 -0
  22. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/node/state.mjs +15 -0
  23. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/shared/stack.mjs +94 -0
  24. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/styles/scale-border-radius.mjs +26 -0
  25. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/styles/scale-box-shadow.mjs +25 -0
  26. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/styles/scale-correction.mjs +4 -0
  27. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/styles/transform.mjs +36 -0
  28. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/utils/each-axis.mjs +6 -0
  29. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/projection/utils/has-transform.mjs +20 -0
  30. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/render/utils/compare-by-depth.mjs +4 -0
  31. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/render/utils/flat-tree.mjs +24 -0
  32. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/utils/resolve-value.mjs +4 -0
  33. package/dist/es/external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/value/utils/resolve-motion-value.mjs +9 -0
  34. package/dist/es/features/events.mjs +2 -2
  35. package/dist/es/features/feature-manager.mjs +3 -1
  36. package/dist/es/features/gestures/hover.mjs +1 -1
  37. package/dist/es/features/gestures/in-view.mjs +1 -1
  38. package/dist/es/features/gestures/press.mjs +1 -1
  39. package/dist/es/features/layout/config.mjs +21 -0
  40. package/dist/es/features/layout/layout.mjs +74 -0
  41. package/dist/es/features/layout/utils.mjs +8 -0
  42. package/dist/es/features/svg.mjs +1 -1
  43. package/dist/es/index.mjs +17 -0
  44. package/dist/es/state/create-visual-element.mjs +9 -0
  45. package/dist/es/state/motion-state.mjs +24 -11
  46. package/dist/es/state/style.mjs +2 -2
  47. package/dist/es/state/transform.mjs +0 -1
  48. package/dist/es/value/use-motion-value-event.mjs +11 -0
  49. package/dist/es/value/use-velocity.mjs +20 -0
  50. package/dist/src/components/LayoutGroup.d.ts +30 -0
  51. package/dist/src/components/context.d.ts +17 -0
  52. package/dist/src/components/group.d.ts +7 -0
  53. package/dist/src/components/use-force-update.d.ts +2 -0
  54. package/dist/src/features/index.d.ts +1 -0
  55. package/dist/src/features/layout/config.d.ts +8 -0
  56. package/dist/src/features/layout/layout.d.ts +10 -0
  57. package/dist/src/features/layout/types.d.ts +7 -0
  58. package/dist/src/features/layout/utils.d.ts +4 -0
  59. package/dist/src/index.d.ts +2 -0
  60. package/dist/src/state/create-visual-element.d.ts +1 -0
  61. package/dist/src/state/motion-state.d.ts +1 -2
  62. package/dist/src/types/state.d.ts +2 -1
  63. package/dist/src/value/index.d.ts +4 -0
  64. package/package.json +1 -1
@@ -0,0 +1,39 @@
1
+ import { defineComponent, watch, renderSlot } from "vue";
2
+ import { injectLayoutGroup, provideLayoutGroup, shouldInheritId, shouldInheritGroup } from "./context.mjs";
3
+ import { nodeGroup } from "./group.mjs";
4
+ import { useForceUpdate } from "./use-force-update.mjs";
5
+ const _sfc_main = /* @__PURE__ */ defineComponent({
6
+ __name: "LayoutGroup",
7
+ props: {
8
+ id: {},
9
+ inherit: { type: [Boolean, String] }
10
+ },
11
+ setup(__props) {
12
+ const props = __props;
13
+ const layoutGroup = injectLayoutGroup(null);
14
+ const [forceRender, key] = useForceUpdate();
15
+ function generateId() {
16
+ const upstreamId = layoutGroup == null ? void 0 : layoutGroup.id;
17
+ return shouldInheritId(props.inherit) && upstreamId ? props.id ? `${upstreamId}-${props.id}` : upstreamId : props.id;
18
+ }
19
+ function generateGroup() {
20
+ return shouldInheritGroup(props.inherit) ? (layoutGroup == null ? void 0 : layoutGroup.group) || nodeGroup() : nodeGroup();
21
+ }
22
+ const memoizedContext = {
23
+ id: generateId(),
24
+ group: generateGroup(),
25
+ forceRender,
26
+ key
27
+ };
28
+ watch(key, () => {
29
+ memoizedContext.id = generateId();
30
+ });
31
+ provideLayoutGroup(memoizedContext);
32
+ return (_ctx, _cache) => {
33
+ return renderSlot(_ctx.$slots, "default");
34
+ };
35
+ }
36
+ });
37
+ export {
38
+ _sfc_main as default
39
+ };
@@ -0,0 +1,4 @@
1
+ import _sfc_main from "./LayoutGroup.vue.mjs";
2
+ export {
3
+ _sfc_main as default
4
+ };
@@ -1,6 +1,6 @@
1
1
  import { defineComponent, mergeDefaults, ref, useAttrs, getCurrentInstance, onMounted, onUnmounted, onUpdated, openBlock, createBlock, unref, mergeProps, withCtx, renderSlot } from "vue";
2
- import { injectMotion, provideMotion } from "./context.mjs";
3
- import { createStyles, convertSvgStyleToAttributes } from "../state/style.mjs";
2
+ import { injectMotion, injectLayoutGroup, provideMotion } from "./context.mjs";
3
+ import { convertSvgStyleToAttributes, createStyles } from "../state/style.mjs";
4
4
  import { Primitive } from "./Primitive.mjs";
5
5
  import { MotionState } from "../state/motion-state.mjs";
6
6
  import { isSVGElement } from "../state/utils.mjs";
@@ -34,20 +34,30 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
34
34
  onPressStart: { type: Function },
35
35
  onPressEnd: { type: Function },
36
36
  onViewEnter: { type: Function },
37
- onViewLeave: { type: Function }
37
+ onViewLeave: { type: Function },
38
+ layout: { type: Boolean },
39
+ layoutId: {},
40
+ layoutScroll: { type: Boolean },
41
+ layoutRoot: { type: Boolean },
42
+ "data-framer-portal-id": {}
38
43
  }, {
39
44
  as: "div",
40
45
  asChild: false,
41
46
  initial: void 0,
42
47
  animate: void 0,
43
48
  hover: void 0,
44
- inView: void 0
49
+ inView: void 0,
50
+ layout: false,
51
+ layoutId: void 0,
52
+ layoutScroll: false,
53
+ layoutRoot: false
45
54
  }),
46
55
  setup(__props) {
47
56
  const props = __props;
48
57
  const { initial: presenceInitial, safeUnmount } = injectAnimatePresence({ initial: ref(void 0), safeUnmount: () => true });
49
58
  const parentState = injectMotion(null);
50
59
  const attrs = useAttrs();
60
+ const layoutGroup = injectLayoutGroup({});
51
61
  const state = new MotionState(
52
62
  {
53
63
  ...attrs,
@@ -61,8 +71,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
61
71
  state.mount(instance == null ? void 0 : instance.vnode.el);
62
72
  state.update({
63
73
  ...attrs,
64
- ...props,
65
- style: { ...createStyles(state.getTarget()), ...props.style }
74
+ ...props
66
75
  });
67
76
  });
68
77
  onUnmounted(() => {
@@ -91,23 +100,26 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
91
100
  Object.assign(attrsProps, attributes);
92
101
  Object.assign(styleProps, style, props.style);
93
102
  } else {
94
- Object.assign(styleProps, props.style, state.getTarget());
103
+ Object.assign(styleProps, state.getTarget(), props.style);
95
104
  }
96
105
  }
97
106
  styleProps = createStyles(styleProps);
98
- attrsProps.style = createStyles(styleProps);
107
+ attrsProps.style = styleProps;
99
108
  return attrsProps;
100
109
  }
101
110
  return (_ctx, _cache) => {
111
+ var _a, _b;
102
112
  return openBlock(), createBlock(unref(Primitive), mergeProps({
103
113
  as: _ctx.as,
104
114
  "as-child": _ctx.asChild
105
- }, getProps()), {
115
+ }, getProps(), {
116
+ "data-layout-group-key": (_b = (_a = unref(layoutGroup)) == null ? void 0 : _a.key) == null ? void 0 : _b.value
117
+ }), {
106
118
  default: withCtx(() => [
107
119
  renderSlot(_ctx.$slots, "default")
108
120
  ]),
109
121
  _: 3
110
- }, 16, ["as", "as-child"]);
122
+ }, 16, ["as", "as-child", "data-layout-group-key"]);
111
123
  };
112
124
  }
113
125
  });
@@ -1,6 +1,17 @@
1
1
  import { createContext } from "../utils/createContext.mjs";
2
2
  const [injectMotion, provideMotion] = createContext("Motion");
3
+ const [injectLayoutGroup, provideLayoutGroup] = createContext("LayoutGroup");
4
+ function shouldInheritGroup(inherit) {
5
+ return inherit === true;
6
+ }
7
+ function shouldInheritId(inherit) {
8
+ return shouldInheritGroup(inherit === true) || inherit === "id";
9
+ }
3
10
  export {
11
+ injectLayoutGroup,
4
12
  injectMotion,
5
- provideMotion
13
+ provideLayoutGroup,
14
+ provideMotion,
15
+ shouldInheritGroup,
16
+ shouldInheritId
6
17
  };
@@ -0,0 +1,30 @@
1
+ function notify(node) {
2
+ return !node.isLayoutDirty && node.willUpdate(false);
3
+ }
4
+ function nodeGroup() {
5
+ const nodes = /* @__PURE__ */ new Set();
6
+ const subscriptions = /* @__PURE__ */ new WeakMap();
7
+ const dirtyAll = () => nodes.forEach(notify);
8
+ return {
9
+ add: (node) => {
10
+ nodes.add(node);
11
+ subscriptions.set(
12
+ node,
13
+ node.addEventListener("willUpdate", dirtyAll)
14
+ );
15
+ },
16
+ remove: (node) => {
17
+ nodes.delete(node);
18
+ const unsubscribe = subscriptions.get(node);
19
+ if (unsubscribe) {
20
+ unsubscribe();
21
+ subscriptions.delete(node);
22
+ }
23
+ dirtyAll();
24
+ },
25
+ dirty: dirtyAll
26
+ };
27
+ }
28
+ export {
29
+ nodeGroup
30
+ };
@@ -0,0 +1,11 @@
1
+ import { ref } from "vue";
2
+ function useForceUpdate() {
3
+ const key = ref(0);
4
+ function forceUpdate() {
5
+ key.value++;
6
+ }
7
+ return [forceUpdate, key];
8
+ }
9
+ export {
10
+ useForceUpdate
11
+ };
@@ -1,7 +1,8 @@
1
1
  const components = {
2
2
  motion: [
3
3
  "Motion",
4
- "MotionPresence"
4
+ "MotionPresence",
5
+ "LayoutGroup"
5
6
  ]
6
7
  };
7
8
  const utilities = {
@@ -11,7 +12,12 @@ const utilities = {
11
12
  "useMotionTemplate",
12
13
  "useSpring",
13
14
  "useScroll",
14
- "useMotionValue"
15
+ "useMotionValue",
16
+ "useVelocity",
17
+ "useAnimate",
18
+ "useInView",
19
+ "useAnimationFrame",
20
+ "useMotionValueEvent"
15
21
  ]
16
22
  };
17
23
  export {
@@ -0,0 +1,6 @@
1
+ import "vue";
2
+ typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
3
+ const isDef = (val) => typeof val !== "undefined";
4
+ export {
5
+ isDef
6
+ };
@@ -0,0 +1,7 @@
1
+ function addDomEvent(target, eventName, handler, options = { passive: true }) {
2
+ target.addEventListener(eventName, handler, options);
3
+ return () => target.removeEventListener(eventName, handler);
4
+ }
5
+ export {
6
+ addDomEvent
7
+ };
@@ -0,0 +1,6 @@
1
+ import { createRenderBatcher } from "./batcher.mjs";
2
+ const { schedule: microtask, cancel: cancelMicrotask } = createRenderBatcher(queueMicrotask, false);
3
+ export {
4
+ cancelMicrotask,
5
+ microtask
6
+ };
@@ -0,0 +1,60 @@
1
+ import { circOut } from "../../easing/circ.mjs";
2
+ import { progress } from "../../utils/progress.mjs";
3
+ import { mixNumber } from "../../utils/mix/number.mjs";
4
+ import { noop } from "../../utils/noop.mjs";
5
+ import { percent, px } from "../../value/types/numbers/units.mjs";
6
+ const borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];
7
+ const numBorders = borders.length;
8
+ const asNumber = (value) => typeof value === "string" ? parseFloat(value) : value;
9
+ const isPx = (value) => typeof value === "number" || px.test(value);
10
+ function mixValues(target, follow, lead, progress2, shouldCrossfadeOpacity, isOnlyMember) {
11
+ if (shouldCrossfadeOpacity) {
12
+ target.opacity = mixNumber(
13
+ 0,
14
+ // TODO Reinstate this if only child
15
+ lead.opacity !== void 0 ? lead.opacity : 1,
16
+ easeCrossfadeIn(progress2)
17
+ );
18
+ target.opacityExit = mixNumber(follow.opacity !== void 0 ? follow.opacity : 1, 0, easeCrossfadeOut(progress2));
19
+ } else if (isOnlyMember) {
20
+ target.opacity = mixNumber(follow.opacity !== void 0 ? follow.opacity : 1, lead.opacity !== void 0 ? lead.opacity : 1, progress2);
21
+ }
22
+ for (let i = 0; i < numBorders; i++) {
23
+ const borderLabel = `border${borders[i]}Radius`;
24
+ let followRadius = getRadius(follow, borderLabel);
25
+ let leadRadius = getRadius(lead, borderLabel);
26
+ if (followRadius === void 0 && leadRadius === void 0)
27
+ continue;
28
+ followRadius || (followRadius = 0);
29
+ leadRadius || (leadRadius = 0);
30
+ const canMix = followRadius === 0 || leadRadius === 0 || isPx(followRadius) === isPx(leadRadius);
31
+ if (canMix) {
32
+ target[borderLabel] = Math.max(mixNumber(asNumber(followRadius), asNumber(leadRadius), progress2), 0);
33
+ if (percent.test(leadRadius) || percent.test(followRadius)) {
34
+ target[borderLabel] += "%";
35
+ }
36
+ } else {
37
+ target[borderLabel] = leadRadius;
38
+ }
39
+ }
40
+ if (follow.rotate || lead.rotate) {
41
+ target.rotate = mixNumber(follow.rotate || 0, lead.rotate || 0, progress2);
42
+ }
43
+ }
44
+ function getRadius(values, radiusName) {
45
+ return values[radiusName] !== void 0 ? values[radiusName] : values.borderRadius;
46
+ }
47
+ const easeCrossfadeIn = /* @__PURE__ */ compress(0, 0.5, circOut);
48
+ const easeCrossfadeOut = /* @__PURE__ */ compress(0.5, 0.95, noop);
49
+ function compress(min, max, easing) {
50
+ return (p) => {
51
+ if (p < min)
52
+ return 0;
53
+ if (p > max)
54
+ return 1;
55
+ return easing(progress(min, max, p));
56
+ };
57
+ }
58
+ export {
59
+ mixValues
60
+ };
@@ -0,0 +1,19 @@
1
+ function copyAxisInto(axis, originAxis) {
2
+ axis.min = originAxis.min;
3
+ axis.max = originAxis.max;
4
+ }
5
+ function copyBoxInto(box, originBox) {
6
+ copyAxisInto(box.x, originBox.x);
7
+ copyAxisInto(box.y, originBox.y);
8
+ }
9
+ function copyAxisDeltaInto(delta, originDelta) {
10
+ delta.translate = originDelta.translate;
11
+ delta.scale = originDelta.scale;
12
+ delta.originPoint = originDelta.originPoint;
13
+ delta.origin = originDelta.origin;
14
+ }
15
+ export {
16
+ copyAxisDeltaInto,
17
+ copyAxisInto,
18
+ copyBoxInto
19
+ };
@@ -0,0 +1,81 @@
1
+ import { mixNumber } from "../../utils/mix/number.mjs";
2
+ import { hasTransform } from "../utils/has-transform.mjs";
3
+ function scalePoint(point, scale, originPoint) {
4
+ const distanceFromOrigin = point - originPoint;
5
+ const scaled = scale * distanceFromOrigin;
6
+ return originPoint + scaled;
7
+ }
8
+ function applyPointDelta(point, translate, scale, originPoint, boxScale) {
9
+ if (boxScale !== void 0) {
10
+ point = scalePoint(point, boxScale, originPoint);
11
+ }
12
+ return scalePoint(point, scale, originPoint) + translate;
13
+ }
14
+ function applyAxisDelta(axis, translate = 0, scale = 1, originPoint, boxScale) {
15
+ axis.min = applyPointDelta(axis.min, translate, scale, originPoint, boxScale);
16
+ axis.max = applyPointDelta(axis.max, translate, scale, originPoint, boxScale);
17
+ }
18
+ function applyBoxDelta(box, { x, y }) {
19
+ applyAxisDelta(box.x, x.translate, x.scale, x.originPoint);
20
+ applyAxisDelta(box.y, y.translate, y.scale, y.originPoint);
21
+ }
22
+ const TREE_SCALE_SNAP_MIN = 0.999999999999;
23
+ const TREE_SCALE_SNAP_MAX = 1.0000000000001;
24
+ function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
25
+ const treeLength = treePath.length;
26
+ if (!treeLength)
27
+ return;
28
+ treeScale.x = treeScale.y = 1;
29
+ let node;
30
+ let delta;
31
+ for (let i = 0; i < treeLength; i++) {
32
+ node = treePath[i];
33
+ delta = node.projectionDelta;
34
+ const { visualElement } = node.options;
35
+ if (visualElement && visualElement.props.style && visualElement.props.style.display === "contents") {
36
+ continue;
37
+ }
38
+ if (isSharedTransition && node.options.layoutScroll && node.scroll && node !== node.root) {
39
+ transformBox(box, {
40
+ x: -node.scroll.offset.x,
41
+ y: -node.scroll.offset.y
42
+ });
43
+ }
44
+ if (delta) {
45
+ treeScale.x *= delta.x.scale;
46
+ treeScale.y *= delta.y.scale;
47
+ applyBoxDelta(box, delta);
48
+ }
49
+ if (isSharedTransition && hasTransform(node.latestValues)) {
50
+ transformBox(box, node.latestValues);
51
+ }
52
+ }
53
+ if (treeScale.x < TREE_SCALE_SNAP_MAX && treeScale.x > TREE_SCALE_SNAP_MIN) {
54
+ treeScale.x = 1;
55
+ }
56
+ if (treeScale.y < TREE_SCALE_SNAP_MAX && treeScale.y > TREE_SCALE_SNAP_MIN) {
57
+ treeScale.y = 1;
58
+ }
59
+ }
60
+ function translateAxis(axis, distance) {
61
+ axis.min = axis.min + distance;
62
+ axis.max = axis.max + distance;
63
+ }
64
+ function transformAxis(axis, axisTranslate, axisScale, boxScale, axisOrigin = 0.5) {
65
+ const originPoint = mixNumber(axis.min, axis.max, axisOrigin);
66
+ applyAxisDelta(axis, axisTranslate, axisScale, originPoint, boxScale);
67
+ }
68
+ function transformBox(box, transform) {
69
+ transformAxis(box.x, transform.x, transform.scaleX, transform.scale, transform.originX);
70
+ transformAxis(box.y, transform.y, transform.scaleY, transform.scale, transform.originY);
71
+ }
72
+ export {
73
+ applyAxisDelta,
74
+ applyBoxDelta,
75
+ applyPointDelta,
76
+ applyTreeDeltas,
77
+ scalePoint,
78
+ transformAxis,
79
+ transformBox,
80
+ translateAxis
81
+ };
@@ -0,0 +1,55 @@
1
+ import { mixNumber } from "../../utils/mix/number.mjs";
2
+ const SCALE_PRECISION = 1e-4;
3
+ const SCALE_MIN = 1 - SCALE_PRECISION;
4
+ const SCALE_MAX = 1 + SCALE_PRECISION;
5
+ const TRANSLATE_PRECISION = 0.01;
6
+ const TRANSLATE_MIN = 0 - TRANSLATE_PRECISION;
7
+ const TRANSLATE_MAX = 0 + TRANSLATE_PRECISION;
8
+ function calcLength(axis) {
9
+ return axis.max - axis.min;
10
+ }
11
+ function isNear(value, target, maxDistance) {
12
+ return Math.abs(value - target) <= maxDistance;
13
+ }
14
+ function calcAxisDelta(delta, source, target, origin = 0.5) {
15
+ delta.origin = origin;
16
+ delta.originPoint = mixNumber(source.min, source.max, delta.origin);
17
+ delta.scale = calcLength(target) / calcLength(source);
18
+ delta.translate = mixNumber(target.min, target.max, delta.origin) - delta.originPoint;
19
+ if (delta.scale >= SCALE_MIN && delta.scale <= SCALE_MAX || isNaN(delta.scale)) {
20
+ delta.scale = 1;
21
+ }
22
+ if (delta.translate >= TRANSLATE_MIN && delta.translate <= TRANSLATE_MAX || isNaN(delta.translate)) {
23
+ delta.translate = 0;
24
+ }
25
+ }
26
+ function calcBoxDelta(delta, source, target, origin) {
27
+ calcAxisDelta(delta.x, source.x, target.x, origin ? origin.originX : void 0);
28
+ calcAxisDelta(delta.y, source.y, target.y, origin ? origin.originY : void 0);
29
+ }
30
+ function calcRelativeAxis(target, relative, parent) {
31
+ target.min = parent.min + relative.min;
32
+ target.max = target.min + calcLength(relative);
33
+ }
34
+ function calcRelativeBox(target, relative, parent) {
35
+ calcRelativeAxis(target.x, relative.x, parent.x);
36
+ calcRelativeAxis(target.y, relative.y, parent.y);
37
+ }
38
+ function calcRelativeAxisPosition(target, layout, parent) {
39
+ target.min = layout.min - parent.min;
40
+ target.max = target.min + calcLength(layout);
41
+ }
42
+ function calcRelativePosition(target, layout, parent) {
43
+ calcRelativeAxisPosition(target.x, layout.x, parent.x);
44
+ calcRelativeAxisPosition(target.y, layout.y, parent.y);
45
+ }
46
+ export {
47
+ calcAxisDelta,
48
+ calcBoxDelta,
49
+ calcLength,
50
+ calcRelativeAxis,
51
+ calcRelativeAxisPosition,
52
+ calcRelativeBox,
53
+ calcRelativePosition,
54
+ isNear
55
+ };
@@ -0,0 +1,40 @@
1
+ import { mixNumber } from "../../utils/mix/number.mjs";
2
+ import { percent } from "../../value/types/numbers/units.mjs";
3
+ import { scalePoint } from "./delta-apply.mjs";
4
+ function removePointDelta(point, translate, scale, originPoint, boxScale) {
5
+ point -= translate;
6
+ point = scalePoint(point, 1 / scale, originPoint);
7
+ if (boxScale !== void 0) {
8
+ point = scalePoint(point, 1 / boxScale, originPoint);
9
+ }
10
+ return point;
11
+ }
12
+ function removeAxisDelta(axis, translate = 0, scale = 1, origin = 0.5, boxScale, originAxis = axis, sourceAxis = axis) {
13
+ if (percent.test(translate)) {
14
+ translate = parseFloat(translate);
15
+ const relativeProgress = mixNumber(sourceAxis.min, sourceAxis.max, translate / 100);
16
+ translate = relativeProgress - sourceAxis.min;
17
+ }
18
+ if (typeof translate !== "number")
19
+ return;
20
+ let originPoint = mixNumber(originAxis.min, originAxis.max, origin);
21
+ if (axis === originAxis)
22
+ originPoint -= translate;
23
+ axis.min = removePointDelta(axis.min, translate, scale, originPoint, boxScale);
24
+ axis.max = removePointDelta(axis.max, translate, scale, originPoint, boxScale);
25
+ }
26
+ function removeAxisTransforms(axis, transforms, [key, scaleKey, originKey], origin, sourceAxis) {
27
+ removeAxisDelta(axis, transforms[key], transforms[scaleKey], transforms[originKey], transforms.scale, origin, sourceAxis);
28
+ }
29
+ const xKeys = ["x", "scaleX", "originX"];
30
+ const yKeys = ["y", "scaleY", "originY"];
31
+ function removeBoxTransforms(box, transforms, originBox, sourceBox) {
32
+ removeAxisTransforms(box.x, transforms, xKeys, originBox ? originBox.x : void 0, sourceBox ? sourceBox.x : void 0);
33
+ removeAxisTransforms(box.y, transforms, yKeys, originBox ? originBox.y : void 0, sourceBox ? sourceBox.y : void 0);
34
+ }
35
+ export {
36
+ removeAxisDelta,
37
+ removeAxisTransforms,
38
+ removeBoxTransforms,
39
+ removePointDelta
40
+ };
@@ -1,3 +1,13 @@
1
+ const createAxisDelta = () => ({
2
+ translate: 0,
3
+ scale: 1,
4
+ origin: 0,
5
+ originPoint: 0
6
+ });
7
+ const createDelta = () => ({
8
+ x: createAxisDelta(),
9
+ y: createAxisDelta()
10
+ });
1
11
  const createAxis = () => ({ min: 0, max: 0 });
2
12
  const createBox = () => ({
3
13
  x: createAxis(),
@@ -5,5 +15,7 @@ const createBox = () => ({
5
15
  });
6
16
  export {
7
17
  createAxis,
8
- createBox
18
+ createAxisDelta,
19
+ createBox,
20
+ createDelta
9
21
  };
@@ -0,0 +1,34 @@
1
+ import { calcLength } from "./delta-calc.mjs";
2
+ function isAxisDeltaZero(delta) {
3
+ return delta.translate === 0 && delta.scale === 1;
4
+ }
5
+ function isDeltaZero(delta) {
6
+ return isAxisDeltaZero(delta.x) && isAxisDeltaZero(delta.y);
7
+ }
8
+ function axisEquals(a, b) {
9
+ return a.min === b.min && a.max === b.max;
10
+ }
11
+ function boxEquals(a, b) {
12
+ return axisEquals(a.x, b.x) && axisEquals(a.y, b.y);
13
+ }
14
+ function axisEqualsRounded(a, b) {
15
+ return Math.round(a.min) === Math.round(b.min) && Math.round(a.max) === Math.round(b.max);
16
+ }
17
+ function boxEqualsRounded(a, b) {
18
+ return axisEqualsRounded(a.x, b.x) && axisEqualsRounded(a.y, b.y);
19
+ }
20
+ function aspectRatio(box) {
21
+ return calcLength(box.x) / calcLength(box.y);
22
+ }
23
+ function axisDeltaEquals(a, b) {
24
+ return a.translate === b.translate && a.scale === b.scale && a.originPoint === b.originPoint;
25
+ }
26
+ export {
27
+ aspectRatio,
28
+ axisDeltaEquals,
29
+ axisEquals,
30
+ axisEqualsRounded,
31
+ boxEquals,
32
+ boxEqualsRounded,
33
+ isDeltaZero
34
+ };
@@ -0,0 +1,13 @@
1
+ import { createProjectionNode } from "./create-projection-node.mjs";
2
+ import { addDomEvent } from "../../events/add-dom-event.mjs";
3
+ const DocumentProjectionNode = createProjectionNode({
4
+ attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
5
+ measureScroll: () => ({
6
+ x: document.documentElement.scrollLeft || document.body.scrollLeft,
7
+ y: document.documentElement.scrollTop || document.body.scrollTop
8
+ }),
9
+ checkIsScrollRoot: () => true
10
+ });
11
+ export {
12
+ DocumentProjectionNode
13
+ };
@@ -0,0 +1,28 @@
1
+ import { createProjectionNode } from "./create-projection-node.mjs";
2
+ import { DocumentProjectionNode } from "./DocumentProjectionNode.mjs";
3
+ const rootProjectionNode = {
4
+ current: void 0
5
+ };
6
+ const HTMLProjectionNode = createProjectionNode({
7
+ measureScroll: (instance) => ({
8
+ x: instance.scrollLeft,
9
+ y: instance.scrollTop
10
+ }),
11
+ defaultParent: () => {
12
+ if (!rootProjectionNode.current) {
13
+ const documentNode = new DocumentProjectionNode({});
14
+ documentNode.mount(window);
15
+ documentNode.setOptions({ layoutScroll: true });
16
+ rootProjectionNode.current = documentNode;
17
+ }
18
+ return rootProjectionNode.current;
19
+ },
20
+ resetTransform: (instance, value) => {
21
+ instance.style.transform = value !== void 0 ? value : "none";
22
+ },
23
+ checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed")
24
+ });
25
+ export {
26
+ HTMLProjectionNode,
27
+ rootProjectionNode
28
+ };