Projectrix v0.1.4 alpha
Previously, Projectrix required that the subject and target coexist, which meant proper FLIP animations were not possible. This release fixes that shortcoming:
- added measureSubject() and Measurement
/**
* measures a subject for future projections. useful if the subject and target cannot coexist,
* such as a flip animation where the subject is the target's past
*/
export function measureSubject(subject: HTMLElement): Measurement;
export type Measurement = {
acr: ActualClientRect; // from getActualClientRect
border: BorderMeasurement;
};
export type BorderMeasurement = { /* style, top, right, bottom, left, radius */ };
- updated getProjection() to also accept Measurement for the subject
export function getProjection(
subject: HTMLElement | Measurement, // the element or measurement that you plan to align the target to
target: HTMLElement, // the element that you plan to modify
options?: ProjectionOptions,
): ProjectionResults;
- updated FlipDemo.svelte to showcase a proper FLIP animation
https://tg.projectrix.dev/demos/flip
- updated readme's Flip usage example
import { getProjection, measureSubject, setInlineStyles, clearInlineStyles } from 'projectrix';
import { animate } from 'motion';
function flip(target: HTMLElement, nextParent: HTMLElement): void {
const subject = measureSubject(target);
nextParent.append(target);
requestAnimationFrame(() => {
const { toSubject, toTargetOrigin } = getProjection(subject, target);
// set target to subject's projection
setInlineStyles(target, toSubject);
// FLIP back to origin
const flipAnimation = animate(
target,
{ ...toTargetOrigin },
{
duration: 1,
easing: 'ease-out',
},
);
// clear inline styles once they're redundant
flipAnimation.finished.then(() => clearInlineStyles(target, toTargetOrigin));
});
}