@humanspeak/svelte-motion 0.5.1 → 0.5.3
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/components/projection.context.d.ts +22 -0
- package/dist/components/projection.context.js +56 -0
- package/dist/html/_MotionContainer.svelte +328 -24
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +78 -0
- package/dist/utils/drag.d.ts +42 -11
- package/dist/utils/drag.js +103 -12
- package/dist/utils/layout.d.ts +26 -2
- package/dist/utils/layout.js +13 -2
- package/dist/utils/pan.d.ts +135 -0
- package/dist/utils/pan.js +426 -0
- package/dist/utils/projection.d.ts +287 -0
- package/dist/utils/projection.js +392 -0
- package/dist/utils/style.d.ts +23 -0
- package/dist/utils/style.js +27 -0
- package/dist/utils/variants.d.ts +26 -0
- package/dist/utils/variants.js +42 -0
- package/package.json +5 -5
package/dist/utils/style.d.ts
CHANGED
|
@@ -3,3 +3,26 @@
|
|
|
3
3
|
* This is used during SSR to reflect the initial state in server-rendered markup.
|
|
4
4
|
*/
|
|
5
5
|
export declare const mergeInlineStyles: (existingStyle: unknown, initial: Record<string, unknown> | null | undefined, animateFallback?: Record<string, unknown> | null | undefined) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Extract the user-authored `transform` declaration from a `style` prop.
|
|
8
|
+
*
|
|
9
|
+
* Used by the projection system as the "base" transform a node resets to
|
|
10
|
+
* while measuring — the value the user wrote, independent of any
|
|
11
|
+
* motion-applied transform (`initial`/`animate`/FLIP/drag) that lands on
|
|
12
|
+
* `element.style.transform` after mount. Reading it from the `style` prop
|
|
13
|
+
* rather than the live inline style is what keeps an `initial={{ x }}` (or
|
|
14
|
+
* any transform-type initial/animate) from being mistaken for the base.
|
|
15
|
+
*
|
|
16
|
+
* Returns `''` when the prop is not a string or carries no transform.
|
|
17
|
+
*
|
|
18
|
+
* @param style The component's `style` prop.
|
|
19
|
+
* @returns The user's `transform` value, or `''`.
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* extractTransform('opacity: 0.5; transform: translateX(10px) scale(2)')
|
|
23
|
+
* // => 'translateX(10px) scale(2)'
|
|
24
|
+
* extractTransform('color: red') // => ''
|
|
25
|
+
* extractTransform({ color: 'red' }) // => '' (non-string)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const extractTransform: (style: unknown) => string;
|
package/dist/utils/style.js
CHANGED
|
@@ -117,6 +117,33 @@ export const mergeInlineStyles = (existingStyle, initial, animateFallback) => {
|
|
|
117
117
|
}
|
|
118
118
|
return stringifyStyleObject(base);
|
|
119
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* Extract the user-authored `transform` declaration from a `style` prop.
|
|
122
|
+
*
|
|
123
|
+
* Used by the projection system as the "base" transform a node resets to
|
|
124
|
+
* while measuring — the value the user wrote, independent of any
|
|
125
|
+
* motion-applied transform (`initial`/`animate`/FLIP/drag) that lands on
|
|
126
|
+
* `element.style.transform` after mount. Reading it from the `style` prop
|
|
127
|
+
* rather than the live inline style is what keeps an `initial={{ x }}` (or
|
|
128
|
+
* any transform-type initial/animate) from being mistaken for the base.
|
|
129
|
+
*
|
|
130
|
+
* Returns `''` when the prop is not a string or carries no transform.
|
|
131
|
+
*
|
|
132
|
+
* @param style The component's `style` prop.
|
|
133
|
+
* @returns The user's `transform` value, or `''`.
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* extractTransform('opacity: 0.5; transform: translateX(10px) scale(2)')
|
|
137
|
+
* // => 'translateX(10px) scale(2)'
|
|
138
|
+
* extractTransform('color: red') // => ''
|
|
139
|
+
* extractTransform({ color: 'red' }) // => '' (non-string)
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export const extractTransform = (style) => {
|
|
143
|
+
if (typeof style !== 'string')
|
|
144
|
+
return '';
|
|
145
|
+
return parseStyleString(style).transform ?? '';
|
|
146
|
+
};
|
|
120
147
|
const parseStyleString = (style) => {
|
|
121
148
|
const out = {};
|
|
122
149
|
style
|
package/dist/utils/variants.d.ts
CHANGED
|
@@ -148,3 +148,29 @@ export declare const resolveExit: (exit: MotionExit, variants: Variants | undefi
|
|
|
148
148
|
* ```
|
|
149
149
|
*/
|
|
150
150
|
export declare const resolveWhile: (value: MotionWhileTap | MotionWhileHover | MotionWhileFocus | MotionWhileDrag | MotionWhileInView, variants: Variants | undefined, custom?: unknown) => DOMKeyframesDefinition | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* Collapse each keyframe value to the value the element comes to REST at
|
|
153
|
+
* — the last element of a keyframe array, or the value itself otherwise.
|
|
154
|
+
*
|
|
155
|
+
* Used when deriving the post-animation inline style baseline: an
|
|
156
|
+
* `animate={{ x: [0, 100, 50] }}` settles at `50`, so the resting inline
|
|
157
|
+
* transform must reflect `50`, not the first keyframe. Mirrors
|
|
158
|
+
* framer-motion, whose `buildTransform` reads the motion value as a
|
|
159
|
+
* scalar that has already settled at the final keyframe
|
|
160
|
+
* (`motion-dom/.../build-transform.ts`).
|
|
161
|
+
*
|
|
162
|
+
* @param keyframes - Resolved animate keyframes (scalars and/or arrays),
|
|
163
|
+
* or `undefined`.
|
|
164
|
+
* @returns A new object with each value collapsed to its resting scalar,
|
|
165
|
+
* or `undefined` when given `undefined`. Keys whose value is an empty
|
|
166
|
+
* array are omitted (no resting value).
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* resolveRestingValues({ x: [0, 100, 50], scaleX: 1 }) // { x: 50, scaleX: 1 }
|
|
171
|
+
* resolveRestingValues({ opacity: 0.5 }) // { opacity: 0.5 }
|
|
172
|
+
* resolveRestingValues({ x: [], y: 5 }) // { y: 5 } (empty array dropped)
|
|
173
|
+
* resolveRestingValues(undefined) // undefined
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export declare const resolveRestingValues: (keyframes: DOMKeyframesDefinition | undefined) => DOMKeyframesDefinition | undefined;
|
package/dist/utils/variants.js
CHANGED
|
@@ -210,3 +210,45 @@ export const resolveWhile = (value, variants, custom) => {
|
|
|
210
210
|
return resolveVariantList(variants, value, custom);
|
|
211
211
|
return value;
|
|
212
212
|
};
|
|
213
|
+
/**
|
|
214
|
+
* Collapse each keyframe value to the value the element comes to REST at
|
|
215
|
+
* — the last element of a keyframe array, or the value itself otherwise.
|
|
216
|
+
*
|
|
217
|
+
* Used when deriving the post-animation inline style baseline: an
|
|
218
|
+
* `animate={{ x: [0, 100, 50] }}` settles at `50`, so the resting inline
|
|
219
|
+
* transform must reflect `50`, not the first keyframe. Mirrors
|
|
220
|
+
* framer-motion, whose `buildTransform` reads the motion value as a
|
|
221
|
+
* scalar that has already settled at the final keyframe
|
|
222
|
+
* (`motion-dom/.../build-transform.ts`).
|
|
223
|
+
*
|
|
224
|
+
* @param keyframes - Resolved animate keyframes (scalars and/or arrays),
|
|
225
|
+
* or `undefined`.
|
|
226
|
+
* @returns A new object with each value collapsed to its resting scalar,
|
|
227
|
+
* or `undefined` when given `undefined`. Keys whose value is an empty
|
|
228
|
+
* array are omitted (no resting value).
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* resolveRestingValues({ x: [0, 100, 50], scaleX: 1 }) // { x: 50, scaleX: 1 }
|
|
233
|
+
* resolveRestingValues({ opacity: 0.5 }) // { opacity: 0.5 }
|
|
234
|
+
* resolveRestingValues({ x: [], y: 5 }) // { y: 5 } (empty array dropped)
|
|
235
|
+
* resolveRestingValues(undefined) // undefined
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
export const resolveRestingValues = (keyframes) => {
|
|
239
|
+
if (keyframes === undefined)
|
|
240
|
+
return undefined;
|
|
241
|
+
const out = {};
|
|
242
|
+
for (const [key, value] of Object.entries(keyframes)) {
|
|
243
|
+
if (Array.isArray(value)) {
|
|
244
|
+
// An empty array has no resting value — omit the key rather than
|
|
245
|
+
// emitting `value[-1]` (undefined).
|
|
246
|
+
if (value.length > 0)
|
|
247
|
+
out[key] = value[value.length - 1];
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
out[key] = value;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return out;
|
|
254
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humanspeak/svelte-motion",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Framer Motion for Svelte 5. Declarative motion.<tag> components with AnimatePresence exit animations, gestures (hover, tap, drag, focus, in-view), variants, FLIP layout animations, shared-layout transitions, spring physics, and scroll-linked motion values. The drop-in Framer Motion alternative for Svelte and SvelteKit.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svelte",
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"@eslint/js": "^10.0.1",
|
|
105
105
|
"@playwright/test": "^1.60.0",
|
|
106
106
|
"@sveltejs/adapter-auto": "^7.0.1",
|
|
107
|
-
"@sveltejs/kit": "^2.
|
|
107
|
+
"@sveltejs/kit": "^2.61.1",
|
|
108
108
|
"@sveltejs/package": "^2.5.7",
|
|
109
109
|
"@sveltejs/vite-plugin-svelte": "^7.1.2",
|
|
110
110
|
"@tailwindcss/aspect-ratio": "^0.4.2",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"eslint": "^10.4.0",
|
|
120
120
|
"eslint-config-prettier": "10.1.8",
|
|
121
121
|
"eslint-plugin-import": "2.32.0",
|
|
122
|
-
"eslint-plugin-svelte": "3.
|
|
122
|
+
"eslint-plugin-svelte": "3.18.0",
|
|
123
123
|
"eslint-plugin-unused-imports": "4.4.1",
|
|
124
124
|
"esm-env": "^1.2.2",
|
|
125
125
|
"globals": "^17.6.0",
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
"prettier": "^3.8.3",
|
|
132
132
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
133
133
|
"prettier-plugin-sort-json": "^4.2.0",
|
|
134
|
-
"prettier-plugin-svelte": "^
|
|
134
|
+
"prettier-plugin-svelte": "^4.0.1",
|
|
135
135
|
"prettier-plugin-tailwindcss": "^0.8.0",
|
|
136
136
|
"publint": "^0.3.21",
|
|
137
137
|
"runed": "0.37.1",
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
"tailwindcss-animate": "^1.0.7",
|
|
145
145
|
"tsx": "^4.22.3",
|
|
146
146
|
"typescript": "^6.0.3",
|
|
147
|
-
"typescript-eslint": "^8.
|
|
147
|
+
"typescript-eslint": "^8.60.0",
|
|
148
148
|
"vite": "^8.0.14",
|
|
149
149
|
"vite-tsconfig-paths": "^6.1.1",
|
|
150
150
|
"vitest": "^4.1.7"
|