get_interpolator() — svelte Function Reference
Architecture documentation for the get_interpolator() function in tweened.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD b8022161_19de_22af_a730_eb7a4a47b4c2["get_interpolator()"] 99a316ef_52a9_1ecb_3a20_489761af28ad["tweened.js"] b8022161_19de_22af_a730_eb7a4a47b4c2 -->|defined in| 99a316ef_52a9_1ecb_3a20_489761af28ad 2c01da3b_6fe8_7031_6c99_5ae208e44c66["is_date()"] b8022161_19de_22af_a730_eb7a4a47b4c2 -->|calls| 2c01da3b_6fe8_7031_6c99_5ae208e44c66 style b8022161_19de_22af_a730_eb7a4a47b4c2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/motion/tweened.js lines 20–79
function get_interpolator(a, b) {
if (a === b || a !== a) return () => a;
const type = typeof a;
if (type !== typeof b || Array.isArray(a) !== Array.isArray(b)) {
throw new Error('Cannot interpolate values of different type');
}
if (Array.isArray(a)) {
const arr = /** @type {Array<any>} */ (b).map((bi, i) => {
return get_interpolator(/** @type {Array<any>} */ (a)[i], bi);
});
// @ts-ignore
return (t) => arr.map((fn) => fn(t));
}
if (type === 'object') {
if (!a || !b) {
throw new Error('Object cannot be null');
}
if (is_date(a) && is_date(b)) {
const an = a.getTime();
const bn = b.getTime();
const delta = bn - an;
// @ts-ignore
return (t) => new Date(an + t * delta);
}
const keys = Object.keys(b);
/** @type {Record<string, (t: number) => T>} */
const interpolators = {};
keys.forEach((key) => {
// @ts-ignore
interpolators[key] = get_interpolator(a[key], b[key]);
});
// @ts-ignore
return (t) => {
/** @type {Record<string, any>} */
const result = {};
keys.forEach((key) => {
result[key] = interpolators[key](t);
});
return result;
};
}
if (type === 'number') {
const delta = /** @type {number} */ (b) - /** @type {number} */ (a);
// @ts-ignore
return (t) => a + t * delta;
}
// for non-numeric values, snap to the final value immediately
return () => b;
}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does get_interpolator() do?
get_interpolator() is a function in the svelte codebase, defined in packages/svelte/src/motion/tweened.js.
Where is get_interpolator() defined?
get_interpolator() is defined in packages/svelte/src/motion/tweened.js at line 20.
What does get_interpolator() call?
get_interpolator() calls 1 function(s): is_date.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free