@noxlovette/material 0.8.2 → 0.8.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.
|
@@ -30,6 +30,7 @@ import { springTokens, springTransition } from './spring.js';
|
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
const FILL = '--md-container-transform-color';
|
|
33
|
+
const SHADOW = '--md-container-transform-shadow';
|
|
33
34
|
const resolve = (target) => typeof target === 'string'
|
|
34
35
|
? document.querySelector(target)
|
|
35
36
|
: target instanceof Element
|
|
@@ -46,16 +47,33 @@ const fillOf = (target) => {
|
|
|
46
47
|
const colour = target ? getComputedStyle(target).backgroundColor : '';
|
|
47
48
|
return colour && !TRANSPARENT.has(colour) ? colour : 'transparent';
|
|
48
49
|
};
|
|
50
|
+
/*
|
|
51
|
+
The container's elevation while it morphs. Motion clips the group (`overflow: clip`) whenever
|
|
52
|
+
the aspect ratio changes, which cuts the shadow out of both snapshots, so an elevated
|
|
53
|
+
destination (a floating pane) would only get its shadow when the live DOM takes over at the
|
|
54
|
+
end. The group's own `box-shadow` isn't clipped by its overflow, so it carries the shadow
|
|
55
|
+
instead: the destination's when it has one (opening into an elevated pane), otherwise the
|
|
56
|
+
source's (closing it back into a flat card), so the container stays elevated the whole way.
|
|
57
|
+
*/
|
|
58
|
+
const shadowOf = (target) => {
|
|
59
|
+
const shadow = target ? getComputedStyle(target).boxShadow : '';
|
|
60
|
+
return shadow && shadow !== 'none' ? shadow : undefined;
|
|
61
|
+
};
|
|
49
62
|
export const containerTransform = (update, { from, to, spring = springTokens.spatial }) => {
|
|
50
63
|
// The incoming snapshot is opaque wherever the destination is, and the outgoing one fades off
|
|
51
64
|
// it (motion.css layers them), so nothing behind shows through. The fill (motion.css) covers
|
|
52
65
|
// the rest of a destination with its own background, e.g. a full-screen view's area below the
|
|
53
|
-
// incoming snapshot's top as the bar grows
|
|
54
|
-
//
|
|
66
|
+
// incoming snapshot's top as the bar grows, and the shadow keeps its elevation (`shadowOf`).
|
|
67
|
+
// Only the transition's group reads the properties, and they're rewritten before each new
|
|
68
|
+
// snapshot, so they're left in place afterwards.
|
|
55
69
|
const root = document.documentElement;
|
|
56
70
|
const updateAndFill = async () => {
|
|
71
|
+
// Read before `update`, which may unmount it.
|
|
72
|
+
const fromShadow = shadowOf(resolve(from));
|
|
57
73
|
await update();
|
|
58
|
-
|
|
74
|
+
const target = resolve(to);
|
|
75
|
+
root.style.setProperty(FILL, fillOf(target));
|
|
76
|
+
root.style.setProperty(SHADOW, shadowOf(target) ?? fromShadow ?? 'none');
|
|
59
77
|
};
|
|
60
78
|
// The class lets motion.css keep both snapshots at their width, clipped by the container.
|
|
61
79
|
const builder = animateView(updateAndFill, springTransition(spring))
|
package/dist/styles/motion.css
CHANGED
|
@@ -362,7 +362,12 @@
|
|
|
362
362
|
animation-name: none !important;
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
/*
|
|
365
|
+
/*
|
|
366
|
+
Filled with the destination's own background while it morphs, and elevated with its shadow
|
|
367
|
+
(or the source's), which Motion's crop clip would otherwise cut out of the snapshots. Both set
|
|
368
|
+
by containerTransform.
|
|
369
|
+
*/
|
|
366
370
|
::view-transition-group(.md-container-transform) {
|
|
367
371
|
background-color: var(--md-container-transform-color, transparent);
|
|
372
|
+
box-shadow: var(--md-container-transform-shadow, none);
|
|
368
373
|
}
|