motion-start 0.1.19 → 0.1.21

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 (99) hide show
  1. package/dist/animation/utils/is-animatable.d.ts +5 -0
  2. package/dist/animation/utils/is-animatable.d.ts.map +1 -1
  3. package/dist/animation/utils/is-animatable.js +1 -1
  4. package/dist/components/AnimatePresence/AnimatePresence.svelte +221 -188
  5. package/dist/components/AnimatePresence/AnimatePresence.svelte.d.ts.map +1 -1
  6. package/dist/components/AnimatePresence/PresenceChild/PresenceChild.svelte +77 -63
  7. package/dist/components/AnimatePresence/PresenceChild/PresenceChild.svelte.d.ts.map +1 -1
  8. package/dist/components/AnimatePresence/PresenceChild/types.d.ts +1 -0
  9. package/dist/components/AnimatePresence/PresenceChild/types.d.ts.map +1 -1
  10. package/dist/components/AnimatePresence/use-presence.d.ts.map +1 -1
  11. package/dist/components/AnimatePresence/use-presence.js +15 -12
  12. package/dist/components/AnimateSharedLayout/utils/crossfader.d.ts +5 -0
  13. package/dist/components/AnimateSharedLayout/utils/crossfader.d.ts.map +1 -1
  14. package/dist/components/AnimateSharedLayout/utils/crossfader.js +1 -1
  15. package/dist/context/LayoutEpochContext.d.ts +9 -0
  16. package/dist/context/LayoutEpochContext.d.ts.map +1 -0
  17. package/dist/context/LayoutEpochContext.js +13 -0
  18. package/dist/context/PresenceContext.d.ts +1 -0
  19. package/dist/context/PresenceContext.d.ts.map +1 -1
  20. package/dist/motion/features/Exit.svelte +6 -10
  21. package/dist/motion/features/Exit.svelte.d.ts +19 -5
  22. package/dist/motion/features/Exit.svelte.d.ts.map +1 -1
  23. package/dist/motion/features/layout/Animate.svelte +2 -0
  24. package/dist/motion/features/layout/Animate.svelte.d.ts.map +1 -1
  25. package/dist/motion/features/layout/Measure.svelte +144 -100
  26. package/dist/motion/features/layout/Measure.svelte.d.ts.map +1 -1
  27. package/dist/motion/features/layout/MeasureContextProvider.svelte +14 -1
  28. package/dist/motion/features/layout/MeasureContextProvider.svelte.d.ts.map +1 -1
  29. package/dist/motion/features/layout/utils.d.ts +5 -0
  30. package/dist/motion/features/layout/utils.d.ts.map +1 -1
  31. package/dist/motion/features/layout/utils.js +1 -1
  32. package/dist/motion/utils/UseVisualElement.svelte +10 -6
  33. package/dist/motion/utils/UseVisualElement.svelte.d.ts.map +1 -1
  34. package/dist/render/dom/projection/default-scale-correctors.d.ts +5 -0
  35. package/dist/render/dom/projection/default-scale-correctors.d.ts.map +1 -1
  36. package/dist/render/dom/projection/default-scale-correctors.js +1 -1
  37. package/dist/render/dom/utils/unit-conversion.d.ts +5 -0
  38. package/dist/render/dom/utils/unit-conversion.d.ts.map +1 -1
  39. package/dist/render/dom/utils/unit-conversion.js +1 -1
  40. package/dist/render/dom/value-types/animatable-none.d.ts +5 -0
  41. package/dist/render/dom/value-types/animatable-none.d.ts.map +1 -1
  42. package/dist/render/dom/value-types/animatable-none.js +1 -1
  43. package/dist/render/dom/value-types/defaults.d.ts +5 -0
  44. package/dist/render/dom/value-types/defaults.d.ts.map +1 -1
  45. package/dist/render/dom/value-types/defaults.js +1 -1
  46. package/dist/render/dom/value-types/dimensions.d.ts +5 -0
  47. package/dist/render/dom/value-types/dimensions.d.ts.map +1 -1
  48. package/dist/render/dom/value-types/dimensions.js +1 -1
  49. package/dist/render/dom/value-types/find.d.ts +5 -0
  50. package/dist/render/dom/value-types/find.d.ts.map +1 -1
  51. package/dist/render/dom/value-types/find.js +1 -1
  52. package/dist/render/dom/value-types/number.d.ts +5 -0
  53. package/dist/render/dom/value-types/number.d.ts.map +1 -1
  54. package/dist/render/dom/value-types/number.js +1 -1
  55. package/dist/render/dom/value-types/type-int.d.ts +5 -0
  56. package/dist/render/dom/value-types/type-int.d.ts.map +1 -1
  57. package/dist/render/dom/value-types/type-int.js +1 -1
  58. package/dist/render/svg/utils/path.d.ts +5 -0
  59. package/dist/render/svg/utils/path.d.ts.map +1 -1
  60. package/dist/render/svg/utils/path.js +1 -1
  61. package/dist/render/svg/utils/transform-origin.d.ts +5 -0
  62. package/dist/render/svg/utils/transform-origin.d.ts.map +1 -1
  63. package/dist/render/svg/utils/transform-origin.js +1 -1
  64. package/dist/utils/geometry/delta-apply.d.ts +5 -0
  65. package/dist/utils/geometry/delta-apply.d.ts.map +1 -1
  66. package/dist/utils/geometry/delta-apply.js +1 -1
  67. package/dist/utils/geometry/delta-calc.d.ts +5 -0
  68. package/dist/utils/geometry/delta-calc.d.ts.map +1 -1
  69. package/dist/utils/geometry/delta-calc.js +1 -1
  70. package/dist/utils/transform.d.ts +5 -0
  71. package/dist/utils/transform.d.ts.map +1 -1
  72. package/dist/utils/transform.js +1 -1
  73. package/dist/value/index.d.ts +5 -0
  74. package/dist/value/index.d.ts.map +1 -1
  75. package/dist/value/index.js +1 -1
  76. package/dist/value/scroll/use-element-scroll.d.ts +1 -1
  77. package/dist/value/scroll/use-element-scroll.d.ts.map +1 -1
  78. package/dist/value/scroll/use-element-scroll.js +2 -2
  79. package/dist/value/scroll/use-viewport-scroll.d.ts +1 -1
  80. package/dist/value/scroll/use-viewport-scroll.d.ts.map +1 -1
  81. package/dist/value/scroll/use-viewport-scroll.js +2 -2
  82. package/dist/value/use-combine-values.d.ts +1 -1
  83. package/dist/value/use-combine-values.d.ts.map +1 -1
  84. package/dist/value/use-combine-values.js +1 -1
  85. package/dist/value/use-motion-template.d.ts +1 -1
  86. package/dist/value/use-motion-template.d.ts.map +1 -1
  87. package/dist/value/use-motion-template.js +2 -2
  88. package/dist/value/use-spring.d.ts +6 -1
  89. package/dist/value/use-spring.d.ts.map +1 -1
  90. package/dist/value/use-spring.js +4 -4
  91. package/dist/value/use-transform.d.ts +2 -2
  92. package/dist/value/use-transform.d.ts.map +1 -1
  93. package/dist/value/use-transform.js +2 -2
  94. package/dist/value/utils/is-motion-value.d.ts +1 -1
  95. package/dist/value/utils/is-motion-value.d.ts.map +1 -1
  96. package/dist/value/utils/resolve-motion-value.d.ts +2 -2
  97. package/dist/value/utils/resolve-motion-value.d.ts.map +1 -1
  98. package/dist/value/utils/resolve-motion-value.js +0 -5
  99. package/package.json +6 -12
@@ -3,6 +3,11 @@ based on framer-motion@4.1.17,
3
3
  Copyright (c) 2018 Framer B.V.
4
4
  */
5
5
  import type { ResolvedValueTarget } from "../../types";
6
+ /**
7
+ based on framer-motion@4.0.3,
8
+ Copyright (c) 2018 Framer B.V.
9
+ */
10
+ import '../../utils/fix-process-env';
6
11
  /**
7
12
  * Check if a value is animatable. Examples:
8
13
  *
@@ -1 +1 @@
1
- {"version":3,"file":"is-animatable.d.ts","sourceRoot":"","sources":["../../../src/lib/motion-start/animation/utils/is-animatable.ts"],"names":[],"mappings":"AAAA;;;EAGE;AACF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAUvD;;;;;;;;GAQG;AACH,QAAA,IAAI,YAAY,GAAa,KAAK,MAAM,EAAE,OAAO,mBAAmB,YAgBnE,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"is-animatable.d.ts","sourceRoot":"","sources":["../../../src/lib/motion-start/animation/utils/is-animatable.ts"],"names":[],"mappings":"AAAA;;;EAGE;AACF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD;;;EAGE;AACF,OAAO,6BAA6B,CAAC;AAGrC;;;;;;;;GAQG;AACH,QAAA,IAAI,YAAY,GAAa,KAAK,MAAM,EAAE,OAAO,mBAAmB,YAgBnE,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -2,7 +2,7 @@
2
2
  based on framer-motion@4.0.3,
3
3
  Copyright (c) 2018 Framer B.V.
4
4
  */
5
- import { fixed } from '../../utils/fix-process-env';
5
+ import '../../utils/fix-process-env';
6
6
  import { complex } from 'style-value-types';
7
7
  /**
8
8
  * Check if a value is animatable. Examples:
@@ -1,188 +1,221 @@
1
- <!-- based on framer-motion@4.0.3,
2
- Copyright (c) 2018 Framer B.V. -->
3
-
4
- <script lang="ts" generics="T extends {key:any}">
5
- import type { ConditionalGeneric, AnimatePresenceProps } from "./index.js";
6
- import { getContext } from "svelte";
7
- import {
8
- SharedLayoutContext,
9
- isSharedLayout,
10
- } from "../../context/SharedLayoutContext.js";
11
- import PresenceChild from "./PresenceChild/PresenceChild.svelte";
12
- import type { Writable } from "svelte/store";
13
- import {
14
- type SharedLayoutSyncMethods,
15
- type SyncLayoutBatcher,
16
- } from "../AnimateSharedLayout/types.js";
17
-
18
- type $$Props = AnimatePresenceProps<ConditionalGeneric<T>>;
19
-
20
- export let list: $$Props["list"] = undefined,
21
- custom: $$Props["custom"] = undefined,
22
- initial: $$Props["initial"] = true,
23
- onExitComplete: $$Props["onExitComplete"] = undefined,
24
- exitBeforeEnter: $$Props["exitBeforeEnter"] = undefined,
25
- presenceAffectsLayout = true,
26
- show: $$Props["show"] = undefined,
27
- isCustom = false;
28
-
29
- let _list = list !== undefined ? list : show ? [{ key: 1 }] : [];
30
- $: _list = list !== undefined ? list : show ? [{ key: 1 }] : [];
31
-
32
- const layoutContext =
33
- getContext<Writable<SyncLayoutBatcher | SharedLayoutSyncMethods>>(
34
- SharedLayoutContext,
35
- ) || SharedLayoutContext(isCustom);
36
-
37
- $: forceRender = () => {
38
- if (isSharedLayout($layoutContext)) {
39
- $layoutContext.forceUpdate();
40
- }
41
- _list = [..._list];
42
- };
43
-
44
- function getChildKey(child: { key: number }) {
45
- return child.key || "";
46
- }
47
-
48
- let isInitialRender = true;
49
- let filteredChildren = _list;
50
- $: filteredChildren = _list;
51
-
52
- let presentChildren = filteredChildren;
53
- let allChildren = new Map<string | number, { key: number }>();
54
- let exiting = new Set<"" | number>();
55
- const updateChildLookup = (
56
- children: { key: number }[],
57
- allChild: Map<string | number, { key: number }>,
58
- ) => {
59
- children.forEach((child) => {
60
- const key = getChildKey(child);
61
- allChild.set(key, child);
62
- });
63
- };
64
- $: updateChildLookup(filteredChildren, allChildren);
65
-
66
- let childrenToRender: {
67
- present: boolean;
68
- item: any;
69
- key: any;
70
- onExit: undefined | (() => void);
71
- }[] = [
72
- ...filteredChildren.map((v) => ({
73
- present: true,
74
- item: v,
75
- key: v.key,
76
- onExit: undefined,
77
- })),
78
- ];
79
-
80
- $: if (!isInitialRender) {
81
- // If this is a subsequent render, deal with entering and exiting children
82
- childrenToRender = [
83
- ...filteredChildren.map((v) => ({
84
- present: true,
85
- item: v,
86
- key: v.key,
87
- onExit: undefined,
88
- })),
89
- ];
90
-
91
- // Diff the keys of the currently-present and target children to update our
92
- // exiting list.
93
- const presentKeys = presentChildren.map(getChildKey);
94
- const targetKeys = filteredChildren.map(getChildKey);
95
- // Diff the present children with our target children and mark those that are exiting
96
- const numPresent = presentKeys.length;
97
- for (let i = 0; i < numPresent; i++) {
98
- const key = presentKeys[i];
99
- if (targetKeys.indexOf(key) === -1) {
100
- exiting.add(key);
101
- } else {
102
- // In case this key has re-entered, remove from the exiting list
103
- exiting.delete(key);
104
- }
105
- }
106
-
107
- // If we currently have exiting children, and we're deferring rendering incoming children
108
- // until after all current children have exiting, empty the childrenToRender array
109
- if (exitBeforeEnter && exiting.size) {
110
- childrenToRender = [];
111
- }
112
- // Loop through all currently exiting components and clone them to overwrite `animate`
113
- // with any `exit` prop they might have defined.
114
- exiting.forEach((key) => {
115
- // If this component is actually entering again, early return
116
- if (targetKeys.indexOf(key) !== -1) return;
117
-
118
- const child = allChildren.get(key);
119
- if (!child) return;
120
-
121
- const insertionIndex = presentKeys.indexOf(key);
122
-
123
- const onExit = () => {
124
- allChildren.delete(key);
125
- exiting.delete(key);
126
-
127
- // Remove this child from the present children
128
- const removeIndex = presentChildren.findIndex(
129
- (presentChild) => presentChild.key === key,
130
- );
131
-
132
- if (removeIndex < 0) {
133
- return;
134
- }
135
- presentChildren.splice(removeIndex, 1);
136
-
137
- // Defer re-rendering until all exiting children have indeed left
138
- if (!exiting.size) {
139
- presentChildren = [...filteredChildren];
140
- forceRender();
141
- onExitComplete && onExitComplete();
142
- }
143
- };
144
-
145
- childrenToRender.splice(insertionIndex, 0, {
146
- present: false,
147
- item: child,
148
- key: getChildKey(child),
149
- onExit,
150
- });
151
- });
152
- // Add `MotionContext` even to children that don't need it to ensure we're rendering
153
- // the same tree between renders
154
-
155
- /*
156
- childrenToRender = childrenToRender.map((child) => {
157
- const key = child.key as string | number;
158
- return exiting.has(key) ? (
159
- child
160
- ) : (
161
- <PresenceChild
162
- key={getChildKey(child)}
163
- isPresent
164
- presenceAffectsLayout={presenceAffectsLayout}
165
- >
166
- {child}
167
- </PresenceChild>
168
- );
169
- });
170
- */
171
- presentChildren = childrenToRender;
172
- } else {
173
- isInitialRender = false;
174
- }
175
- </script>
176
-
177
- {#each childrenToRender as child (getChildKey(child))}
178
- <PresenceChild
179
- isPresent={child.present}
180
- initial={initial ? undefined : false}
181
- custom={child.onExit ? custom : undefined}
182
- {presenceAffectsLayout}
183
- onExitComplete={child.onExit}
184
- {isCustom}
185
- >
186
- <slot item={child.item} />
187
- </PresenceChild>
188
- {/each}
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script lang="ts" generics="T extends {key:any}">
5
+ import type { ConditionalGeneric, AnimatePresenceProps } from "./index.js";
6
+ import { getContext, setContext, tick } from "svelte";
7
+ import {
8
+ SharedLayoutContext,
9
+ isSharedLayout,
10
+ } from "../../context/SharedLayoutContext.js";
11
+ import PresenceChild from "./PresenceChild/PresenceChild.svelte";
12
+ import type { Writable } from "svelte/store";
13
+ import {
14
+ type SharedLayoutSyncMethods,
15
+ type SyncLayoutBatcher,
16
+ } from "../AnimateSharedLayout/types.js";
17
+ import {
18
+ LayoutEpochContext,
19
+ createLayoutEpoch,
20
+ type LayoutEpoch,
21
+ } from "../../context/LayoutEpochContext.js";
22
+
23
+ type $$Props = AnimatePresenceProps<ConditionalGeneric<T>>;
24
+
25
+ export let list: $$Props["list"] = undefined,
26
+ custom: $$Props["custom"] = undefined,
27
+ initial: $$Props["initial"] = true,
28
+ onExitComplete: $$Props["onExitComplete"] = undefined,
29
+ exitBeforeEnter: $$Props["exitBeforeEnter"] = undefined,
30
+ presenceAffectsLayout = true,
31
+ show: $$Props["show"] = undefined,
32
+ isCustom = false;
33
+
34
+ let _list = list !== undefined ? list : show ? [{ key: 1 }] : [];
35
+ $: _list = list !== undefined ? list : show ? [{ key: 1 }] : [];
36
+
37
+ const layoutContext =
38
+ getContext<Writable<SyncLayoutBatcher | SharedLayoutSyncMethods>>(
39
+ SharedLayoutContext,
40
+ ) || SharedLayoutContext(isCustom);
41
+
42
+ // Single epoch store. Measure subscribes to it for synchronous snapshots
43
+ // (store.update fires subscribers before DOM changes) and MeasureContextProvider
44
+ // reads it reactively to trigger afterU → syncLayout.flush() after DOM settles.
45
+ const layoutEpoch = createLayoutEpoch();
46
+ setContext(LayoutEpochContext, layoutEpoch);
47
+
48
+ // Snapshot sibling positions (snapshot=true) and notify shared layout before
49
+ // a DOM change so Measure can FLIP elements to their new spots.
50
+ // Called by forceRender (post-exit) and by the addition path in the reactive
51
+ // block below — both cases need the same snapshot + shared-layout notification.
52
+ function snapshotLayout() {
53
+ if (presenceAffectsLayout) {
54
+ layoutEpoch.update((v) => ({ n: v.n + 1, snapshot: true }));
55
+ }
56
+ if (isSharedLayout($layoutContext)) {
57
+ $layoutContext.forceUpdate();
58
+ }
59
+ }
60
+
61
+ $: forceRender = () => {
62
+ snapshotLayout();
63
+ _list = [..._list];
64
+ };
65
+
66
+ function getChildKey(child: { key: number }) {
67
+ return child.key || "";
68
+ }
69
+
70
+ let isInitialRender = true;
71
+ let filteredChildren = _list;
72
+ $: filteredChildren = _list;
73
+
74
+ let presentChildren = filteredChildren;
75
+ let allChildren = new Map<string | number, { key: number }>();
76
+ let exiting = new Set<"" | number>();
77
+ const updateChildLookup = (
78
+ children: { key: number }[],
79
+ allChild: Map<string | number, { key: number }>,
80
+ ) => {
81
+ children.forEach((child) => {
82
+ const key = getChildKey(child);
83
+ allChild.set(key, child);
84
+ });
85
+ };
86
+ $: updateChildLookup(filteredChildren, allChildren);
87
+
88
+ let childrenToRender: {
89
+ present: boolean;
90
+ item: any;
91
+ key: any;
92
+ onExit: undefined | (() => void);
93
+ }[] = [
94
+ ...filteredChildren.map((v) => ({
95
+ present: true,
96
+ item: v,
97
+ key: v.key,
98
+ onExit: undefined,
99
+ })),
100
+ ];
101
+
102
+ $: if (!isInitialRender) {
103
+ const presentKeys = presentChildren.map(getChildKey);
104
+ const targetKeys = filteredChildren.map(getChildKey);
105
+
106
+ const hasRemovals = presentKeys.some(
107
+ (k) => targetKeys.indexOf(k) === -1,
108
+ );
109
+ const hasAdditions = targetKeys.some(
110
+ (k) => presentKeys.indexOf(k) === -1,
111
+ );
112
+
113
+ if (hasRemovals) {
114
+ // Flush-only epoch (snapshot=false): drives animateF → safeToRemove for the
115
+ // exiting layout element (id2 registration). Deferred by one tick so that
116
+ // PresenceChild's $effect (Svelte 5) has fired, updating PresenceContext and
117
+ // therefore visualElement.isPresent before Measure.svelte's epoch handler
118
+ // checks !visualElement.isPresent. Siblings are skipped here; forceRender
119
+ // fires snapshotLayout() after the exit completes so they FLIP.
120
+ tick().then(() =>
121
+ layoutEpoch.update((v) => ({ n: v.n + 1, snapshot: false })),
122
+ );
123
+ } else if (hasAdditions) {
124
+ // Snapshot sibling positions before the DOM update (same logic as
125
+ // forceRender) so they FLIP to their new positions after the incoming
126
+ // element shifts them. presenceAffectsLayout and shared-layout notify
127
+ // are handled inside snapshotLayout().
128
+ snapshotLayout();
129
+ }
130
+ // No epoch when hasRemovals=false && hasAdditions=false: this is a
131
+ // forceRender-triggered re-run (no real diff). forceRender already fired
132
+ // snapshotLayout() before _list=[..._list], so we must not fire again.
133
+
134
+ // If this is a subsequent render, deal with entering and exiting children
135
+ childrenToRender = [
136
+ ...filteredChildren.map((v) => ({
137
+ present: true,
138
+ item: v,
139
+ key: v.key,
140
+ onExit: undefined,
141
+ })),
142
+ ];
143
+
144
+ // Diff the present children with our target children and mark those that are exiting
145
+ const numPresent = presentKeys.length;
146
+ for (let i = 0; i < numPresent; i++) {
147
+ const key = presentKeys[i];
148
+ if (targetKeys.indexOf(key) === -1) {
149
+ exiting.add(key);
150
+ } else {
151
+ // In case this key has re-entered, remove from the exiting list
152
+ exiting.delete(key);
153
+ }
154
+ }
155
+
156
+ // If we currently have exiting children, and we're deferring rendering incoming children
157
+ // until after all current children have exiting, empty the childrenToRender array
158
+ if (exitBeforeEnter && exiting.size) {
159
+ childrenToRender = [];
160
+ }
161
+ // Loop through all currently exiting components and clone them to overwrite animate
162
+ // with any exit prop they might have defined.
163
+ exiting.forEach((key) => {
164
+ // If this component is actually entering again, early return
165
+ if (targetKeys.indexOf(key) !== -1) return;
166
+
167
+ const child = allChildren.get(key);
168
+ if (!child) return;
169
+
170
+ const insertionIndex = presentKeys.indexOf(key);
171
+
172
+ const onExit = () => {
173
+ allChildren.delete(key);
174
+ exiting.delete(key);
175
+
176
+ // Remove this child from the present children
177
+ const removeIndex = presentChildren.findIndex(
178
+ (presentChild) => presentChild.key === key,
179
+ );
180
+
181
+ if (removeIndex < 0) {
182
+ return;
183
+ }
184
+ presentChildren.splice(removeIndex, 1);
185
+
186
+ // Defer re-rendering until all exiting children have indeed left
187
+ if (!exiting.size) {
188
+ presentChildren = [...filteredChildren];
189
+ forceRender();
190
+ onExitComplete && onExitComplete();
191
+ }
192
+ };
193
+
194
+ childrenToRender.splice(insertionIndex, 0, {
195
+ present: false,
196
+ item: child,
197
+ key: getChildKey(child),
198
+ onExit,
199
+ });
200
+ });
201
+ presentChildren = childrenToRender;
202
+ // framermotion doesn't pass initial after initial render, but we want to be able to trigger it on new children
203
+ initial = true;
204
+ } else {
205
+ isInitialRender = false;
206
+ }
207
+ </script>
208
+
209
+ {#each childrenToRender as child (getChildKey(child))}
210
+ <PresenceChild
211
+ isPresent={child.present}
212
+ initial={initial ? undefined : false}
213
+ custom={child.onExit ? custom : undefined}
214
+ {presenceAffectsLayout}
215
+ onExitComplete={child.onExit}
216
+ {isCustom}
217
+ presenceKey={child.key}
218
+ >
219
+ <slot item={child.item} />
220
+ </PresenceChild>
221
+ {/each}
@@ -1 +1 @@
1
- {"version":3,"file":"AnimatePresence.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/motion-start/components/AnimatePresence/AnimatePresence.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA8L3E,cAAM,iBAAiB,CAAC,CAAC,SAAS;IAAC,GAAG,EAAC,GAAG,CAAA;CAAC;IACvC,KAAK;IAGL,MAAM;;;IAGN,KAAK;;;;;IAGL,QAAQ;IACR,OAAO;CACV;AAED,UAAU,qBAAqB;IAC3B,KAAK,CAAC,SAAS;QAAC,GAAG,EAAC,GAAG,CAAA;KAAC,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAE;QAAC,QAAQ,CAAC,EAAE,GAAG,CAAA;KAAC,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;KAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACha,CAAC,CAAC,SAAS;QAAC,GAAG,EAAC,GAAG,CAAA;KAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC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. -->
3
3
  <svelte:options runes />
4
4
 
5
5
  <script lang="ts" module>
6
- let presenceId = 0;
7
- function getPresenceId() {
8
- const id = presenceId;
9
- presenceId++;
10
- return id;
11
- }
12
- function newChildrenMap(): Map<number, boolean> {
13
- return new Map<number, boolean>();
14
- }
6
+ let presenceId = 0;
7
+ function getPresenceId() {
8
+ const id = presenceId;
9
+ presenceId++;
10
+ return id;
11
+ }
12
+ function newChildrenMap(): Map<number, boolean> {
13
+ return new Map<number, boolean>();
14
+ }
15
15
  </script>
16
16
 
17
17
  <script lang="ts">
18
- import { setContext, tick } from "svelte";
19
- import { setDomContext } from "../../../context/DOMcontext.js";
20
- import { PresenceContext } from "../../../context/PresenceContext.js";
21
- import type { PresenceChildProps } from "./index.js";
18
+ import { setContext, tick, untrack } from "svelte";
19
+ import { setDomContext } from "../../../context/DOMcontext.js";
20
+ import { PresenceContext } from "../../../context/PresenceContext.js";
21
+ import type { PresenceChildProps } from "./index.js";
22
22
 
23
- interface Props extends PresenceChildProps {}
23
+ interface Props extends PresenceChildProps {}
24
24
 
25
- let {
26
- isPresent,
27
- onExitComplete = undefined,
28
- initial = undefined,
29
- custom = undefined,
30
- presenceAffectsLayout,
31
- isCustom,
32
- children,
33
- }: Props = $props();
25
+ let {
26
+ isPresent,
27
+ onExitComplete = undefined,
28
+ initial = undefined,
29
+ custom = undefined,
30
+ presenceAffectsLayout,
31
+ isCustom,
32
+ children,
33
+ presenceKey = undefined,
34
+ }: Props = $props();
34
35
 
35
- const presenceChildren = newChildrenMap();
36
- const id = getPresenceId();
36
+ const presenceChildren = newChildrenMap();
37
+ const id = getPresenceId();
37
38
 
38
- const refresh = $derived(presenceAffectsLayout ? undefined : isPresent);
39
+ const refresh = $derived(presenceAffectsLayout ? undefined : isPresent);
39
40
 
40
- const memoContext = (flag?: boolean) => {
41
- return {
42
- id,
43
- initial,
44
- isPresent,
45
- custom,
46
- onExitComplete: (childId: number) => {
47
- presenceChildren.set(childId, true);
48
- let allComplete = true;
49
- presenceChildren.forEach((isComplete) => {
50
- if (!isComplete) allComplete = false;
51
- });
41
+ const memoContext = (flag?: boolean) => {
42
+ return {
43
+ id,
44
+ presenceKey,
45
+ initial,
46
+ isPresent,
47
+ custom,
48
+ onExitComplete: (childId: number) => {
49
+ if (!presenceChildren.has(childId)) return;
50
+ if (presenceChildren.get(childId) === true) return;
51
+ presenceChildren.set(childId, true);
52
+ let allComplete = true;
53
+ presenceChildren.forEach((isComplete) => {
54
+ if (!isComplete) allComplete = false;
55
+ });
52
56
 
53
- allComplete && onExitComplete?.();
54
- },
55
- register: (childId: number) => {
56
- presenceChildren.set(childId, false);
57
- return () => presenceChildren.delete(childId);
58
- },
59
- };
57
+ allComplete && onExitComplete?.();
58
+ },
59
+ register: (childId: number) => {
60
+ presenceChildren.set(childId, false);
61
+ return () => presenceChildren.delete(childId);
62
+ },
60
63
  };
61
- let context = PresenceContext();
62
-
63
- $effect(() => {
64
- if (presenceAffectsLayout) {
65
- context.set(memoContext());
66
- }
67
- });
64
+ };
65
+ let context = PresenceContext();
66
+ // Set synchronously so children's usePresence() sees a non-null value via get()
67
+ context.set(memoContext());
68
68
 
69
- $effect(() => context.set(memoContext(refresh)));
69
+ // Update context when relevant props change
70
+ $effect(() => {
71
+ if (presenceAffectsLayout) {
72
+ // Track all relevant props
73
+ isPresent;
74
+ initial;
75
+ custom;
76
+ // But set context without tracking to avoid loops
77
+ untrack(() => context.set(memoContext()));
78
+ } else {
79
+ // When presenceAffectsLayout is false, only track isPresent via refresh
80
+ refresh;
81
+ untrack(() => context.set(memoContext()));
82
+ }
83
+ });
70
84
 
71
- const keyset = (flag?: boolean) => {
72
- presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
73
- };
74
- $effect(() => {
75
- keyset(isPresent);
76
- tick().then(() => {
77
- !isPresent && !presenceChildren.size && onExitComplete?.();
78
- });
85
+ const keyset = (flag?: boolean) => {
86
+ presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
87
+ };
88
+ $effect(() => {
89
+ keyset(isPresent);
90
+ tick().then(() => {
91
+ !isPresent && !presenceChildren.size && onExitComplete?.();
79
92
  });
80
- setContext(PresenceContext, context);
81
- setDomContext("Presence", isCustom, context);
93
+ });
94
+ setContext(PresenceContext, context);
95
+ setDomContext("Presence", isCustom, context);
82
96
  </script>
83
97
 
84
98
  {@render children?.()}
@@ -1 +1 @@
1
- {"version":3,"file":"PresenceChild.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/motion-start/components/AnimatePresence/PresenceChild/PresenceChild.svelte.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGjD,UAAU,KAAM,SAAQ,kBAAkB;CAAG;AA4EjD,QAAA,MAAM,aAAa,2CAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"PresenceChild.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/motion-start/components/AnimatePresence/PresenceChild/PresenceChild.svelte.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGnD,UAAU,KAAM,SAAQ,kBAAkB;CAAG;AA0F/C,QAAA,MAAM,aAAa,2CAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
@@ -8,5 +8,6 @@ export interface PresenceChildProps {
8
8
  custom?: any;
9
9
  presenceAffectsLayout: boolean;
10
10
  isCustom: boolean;
11
+ presenceKey?: any;
11
12
  }
12
13
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/motion-start/components/AnimatePresence/PresenceChild/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,OAAO,CAAC,EAAE,KAAK,GAAG,aAAa,CAAC;IAChC,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,qBAAqB,EAAE,OAAO,CAAC;IAC/B,QAAQ,EAAE,OAAO,CAAC;CAClB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/motion-start/components/AnimatePresence/PresenceChild/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,OAAO,CAAC,EAAE,KAAK,GAAG,aAAa,CAAC;IAChC,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,qBAAqB,EAAE,OAAO,CAAC;IAC/B,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,GAAG,CAAC;CAClB"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-presence.d.ts","sourceRoot":"","sources":["../../../src/lib/motion-start/components/AnimatePresence/use-presence.ts"],"names":[],"mappings":"AAAA;;;EAGE;AACF,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAO1E,MAAM,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC;AACtC,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAA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