astro 3.5.6 → 3.6.0
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/client.d.ts +24 -3
- package/components/ViewTransitions.astro +3 -2
- package/dist/core/build/generate.js +172 -159
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/routing/manifest/create.js +9 -5
- package/dist/core/routing/params.js +1 -1
- package/dist/i18n/middleware.js +2 -2
- package/dist/prefetch/index.d.ts +4 -0
- package/dist/prefetch/index.js +16 -8
- package/dist/runtime/server/transition.d.ts +5 -1
- package/dist/runtime/server/transition.js +17 -6
- package/dist/transitions/events.d.ts +36 -0
- package/dist/transitions/events.js +131 -0
- package/dist/transitions/index.d.ts +1 -0
- package/dist/transitions/index.js +2 -0
- package/dist/transitions/router.d.ts +6 -7
- package/dist/transitions/router.js +179 -111
- package/dist/transitions/types.d.ts +10 -0
- package/dist/transitions/types.js +0 -0
- package/dist/transitions/vite-plugin-transitions.js +8 -1
- package/package.json +5 -3
|
@@ -24,6 +24,13 @@ const getAnimations = (name) => {
|
|
|
24
24
|
if (typeof name === "object")
|
|
25
25
|
return name;
|
|
26
26
|
};
|
|
27
|
+
const addPairs = (animations, stylesheet) => {
|
|
28
|
+
for (const [direction, images] of Object.entries(animations)) {
|
|
29
|
+
for (const [image, rules] of Object.entries(images)) {
|
|
30
|
+
stylesheet.addAnimationPair(direction, image, rules);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
27
34
|
function renderTransition(result, hash, animationName, transitionName) {
|
|
28
35
|
if (!animationName)
|
|
29
36
|
animationName = "fade";
|
|
@@ -32,11 +39,7 @@ function renderTransition(result, hash, animationName, transitionName) {
|
|
|
32
39
|
const sheet = new ViewTransitionStyleSheet(scope, name);
|
|
33
40
|
const animations = getAnimations(animationName);
|
|
34
41
|
if (animations) {
|
|
35
|
-
|
|
36
|
-
for (const [image, rules] of Object.entries(images)) {
|
|
37
|
-
sheet.addAnimationPair(direction, image, rules);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
42
|
+
addPairs(animations, sheet);
|
|
40
43
|
} else if (animationName === "none") {
|
|
41
44
|
sheet.addFallback("old", "animation: none; mix-blend-mode: normal;");
|
|
42
45
|
sheet.addModern("old", "animation: none; opacity: 0; mix-blend-mode: normal;");
|
|
@@ -45,6 +48,13 @@ function renderTransition(result, hash, animationName, transitionName) {
|
|
|
45
48
|
result._metadata.extraHead.push(markHTMLString(`<style>${sheet.toString()}</style>`));
|
|
46
49
|
return scope;
|
|
47
50
|
}
|
|
51
|
+
function createAnimationScope(transitionName, animations) {
|
|
52
|
+
const hash = Math.random().toString(36).slice(2, 8);
|
|
53
|
+
const scope = `astro-${hash}`;
|
|
54
|
+
const sheet = new ViewTransitionStyleSheet(scope, transitionName);
|
|
55
|
+
addPairs(animations, sheet);
|
|
56
|
+
return { scope, styles: sheet.toString().replaceAll('"', "") };
|
|
57
|
+
}
|
|
48
58
|
class ViewTransitionStyleSheet {
|
|
49
59
|
constructor(scope, name) {
|
|
50
60
|
this.scope = scope;
|
|
@@ -87,7 +97,7 @@ class ViewTransitionStyleSheet {
|
|
|
87
97
|
addAnimationPair(direction, image, rules) {
|
|
88
98
|
const { scope, name } = this;
|
|
89
99
|
const animation = stringifyAnimation(rules);
|
|
90
|
-
const prefix = direction === "backwards" ? `[data-astro-transition=back]` : ""
|
|
100
|
+
const prefix = direction === "backwards" ? `[data-astro-transition=back]` : direction === "forwards" ? "" : `[data-astro-transition=${direction}]`;
|
|
91
101
|
this.addRule("modern", `${prefix}::view-transition-${image}(${name}) { ${animation} }`);
|
|
92
102
|
this.addRule(
|
|
93
103
|
"fallback",
|
|
@@ -152,6 +162,7 @@ function toTimeValue(num) {
|
|
|
152
162
|
return typeof num === "number" ? num + "ms" : num;
|
|
153
163
|
}
|
|
154
164
|
export {
|
|
165
|
+
createAnimationScope,
|
|
155
166
|
createTransitionScope,
|
|
156
167
|
renderTransition
|
|
157
168
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/// <reference types="@types/dom-view-transitions" />
|
|
2
|
+
import type { Direction, NavigationTypeString } from './types.js';
|
|
3
|
+
export declare const TRANSITION_BEFORE_PREPARATION = "astro:before-preparation";
|
|
4
|
+
export declare const TRANSITION_AFTER_PREPARATION = "astro:after-preparation";
|
|
5
|
+
export declare const TRANSITION_BEFORE_SWAP = "astro:before-swap";
|
|
6
|
+
export declare const TRANSITION_AFTER_SWAP = "astro:after-swap";
|
|
7
|
+
export declare const TRANSITION_PAGE_LOAD = "astro:page-load";
|
|
8
|
+
type Events = typeof TRANSITION_AFTER_PREPARATION | typeof TRANSITION_AFTER_SWAP | typeof TRANSITION_PAGE_LOAD;
|
|
9
|
+
export declare const triggerEvent: (name: Events) => boolean;
|
|
10
|
+
export declare const onPageLoad: () => boolean;
|
|
11
|
+
declare class BeforeEvent extends Event {
|
|
12
|
+
readonly from: URL;
|
|
13
|
+
to: URL;
|
|
14
|
+
direction: Direction | string;
|
|
15
|
+
readonly navigationType: NavigationTypeString;
|
|
16
|
+
readonly sourceElement: Element | undefined;
|
|
17
|
+
readonly info: any;
|
|
18
|
+
newDocument: Document;
|
|
19
|
+
constructor(type: string, eventInitDict: EventInit | undefined, from: URL, to: URL, direction: Direction | string, navigationType: NavigationTypeString, sourceElement: Element | undefined, info: any, newDocument: Document);
|
|
20
|
+
}
|
|
21
|
+
export declare const isTransitionBeforePreparationEvent: (value: any) => value is TransitionBeforePreparationEvent;
|
|
22
|
+
export declare class TransitionBeforePreparationEvent extends BeforeEvent {
|
|
23
|
+
formData: FormData | undefined;
|
|
24
|
+
loader: () => Promise<void>;
|
|
25
|
+
constructor(from: URL, to: URL, direction: Direction | string, navigationType: NavigationTypeString, sourceElement: Element | undefined, info: any, newDocument: Document, formData: FormData | undefined, loader: (event: TransitionBeforePreparationEvent) => Promise<void>);
|
|
26
|
+
}
|
|
27
|
+
export declare const isTransitionBeforeSwapEvent: (value: any) => value is TransitionBeforeSwapEvent;
|
|
28
|
+
export declare class TransitionBeforeSwapEvent extends BeforeEvent {
|
|
29
|
+
readonly direction: Direction | string;
|
|
30
|
+
readonly viewTransition: ViewTransition;
|
|
31
|
+
swap: () => void;
|
|
32
|
+
constructor(afterPreparation: BeforeEvent, viewTransition: ViewTransition, swap: (event: TransitionBeforeSwapEvent) => void);
|
|
33
|
+
}
|
|
34
|
+
export declare function doPreparation(from: URL, to: URL, direction: Direction | string, navigationType: NavigationTypeString, sourceElement: Element | undefined, info: any, formData: FormData | undefined, defaultLoader: (event: TransitionBeforePreparationEvent) => Promise<void>): Promise<TransitionBeforePreparationEvent>;
|
|
35
|
+
export declare function doSwap(afterPreparation: BeforeEvent, viewTransition: ViewTransition, defaultSwap: (event: TransitionBeforeSwapEvent) => void): Promise<TransitionBeforeSwapEvent>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { updateScrollPosition } from "./router.js";
|
|
2
|
+
const TRANSITION_BEFORE_PREPARATION = "astro:before-preparation";
|
|
3
|
+
const TRANSITION_AFTER_PREPARATION = "astro:after-preparation";
|
|
4
|
+
const TRANSITION_BEFORE_SWAP = "astro:before-swap";
|
|
5
|
+
const TRANSITION_AFTER_SWAP = "astro:after-swap";
|
|
6
|
+
const TRANSITION_PAGE_LOAD = "astro:page-load";
|
|
7
|
+
const triggerEvent = (name) => document.dispatchEvent(new Event(name));
|
|
8
|
+
const onPageLoad = () => triggerEvent(TRANSITION_PAGE_LOAD);
|
|
9
|
+
class BeforeEvent extends Event {
|
|
10
|
+
from;
|
|
11
|
+
to;
|
|
12
|
+
direction;
|
|
13
|
+
navigationType;
|
|
14
|
+
sourceElement;
|
|
15
|
+
info;
|
|
16
|
+
newDocument;
|
|
17
|
+
constructor(type, eventInitDict, from, to, direction, navigationType, sourceElement, info, newDocument) {
|
|
18
|
+
super(type, eventInitDict);
|
|
19
|
+
this.from = from;
|
|
20
|
+
this.to = to;
|
|
21
|
+
this.direction = direction;
|
|
22
|
+
this.navigationType = navigationType;
|
|
23
|
+
this.sourceElement = sourceElement;
|
|
24
|
+
this.info = info;
|
|
25
|
+
this.newDocument = newDocument;
|
|
26
|
+
Object.defineProperties(this, {
|
|
27
|
+
from: { enumerable: true },
|
|
28
|
+
to: { enumerable: true, writable: true },
|
|
29
|
+
direction: { enumerable: true, writable: true },
|
|
30
|
+
navigationType: { enumerable: true },
|
|
31
|
+
sourceElement: { enumerable: true },
|
|
32
|
+
info: { enumerable: true },
|
|
33
|
+
newDocument: { enumerable: true, writable: true }
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const isTransitionBeforePreparationEvent = (value) => value.type === TRANSITION_BEFORE_PREPARATION;
|
|
38
|
+
class TransitionBeforePreparationEvent extends BeforeEvent {
|
|
39
|
+
formData;
|
|
40
|
+
loader;
|
|
41
|
+
constructor(from, to, direction, navigationType, sourceElement, info, newDocument, formData, loader) {
|
|
42
|
+
super(
|
|
43
|
+
TRANSITION_BEFORE_PREPARATION,
|
|
44
|
+
{ cancelable: true },
|
|
45
|
+
from,
|
|
46
|
+
to,
|
|
47
|
+
direction,
|
|
48
|
+
navigationType,
|
|
49
|
+
sourceElement,
|
|
50
|
+
info,
|
|
51
|
+
newDocument
|
|
52
|
+
);
|
|
53
|
+
this.formData = formData;
|
|
54
|
+
this.loader = loader.bind(this, this);
|
|
55
|
+
Object.defineProperties(this, {
|
|
56
|
+
formData: { enumerable: true },
|
|
57
|
+
loader: { enumerable: true, writable: true }
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const isTransitionBeforeSwapEvent = (value) => value.type === TRANSITION_BEFORE_SWAP;
|
|
62
|
+
class TransitionBeforeSwapEvent extends BeforeEvent {
|
|
63
|
+
direction;
|
|
64
|
+
viewTransition;
|
|
65
|
+
swap;
|
|
66
|
+
constructor(afterPreparation, viewTransition, swap) {
|
|
67
|
+
super(
|
|
68
|
+
TRANSITION_BEFORE_SWAP,
|
|
69
|
+
void 0,
|
|
70
|
+
afterPreparation.from,
|
|
71
|
+
afterPreparation.to,
|
|
72
|
+
afterPreparation.direction,
|
|
73
|
+
afterPreparation.navigationType,
|
|
74
|
+
afterPreparation.sourceElement,
|
|
75
|
+
afterPreparation.info,
|
|
76
|
+
afterPreparation.newDocument
|
|
77
|
+
);
|
|
78
|
+
this.direction = afterPreparation.direction;
|
|
79
|
+
this.viewTransition = viewTransition;
|
|
80
|
+
this.swap = swap.bind(this, this);
|
|
81
|
+
Object.defineProperties(this, {
|
|
82
|
+
direction: { enumerable: true },
|
|
83
|
+
viewTransition: { enumerable: true },
|
|
84
|
+
swap: { enumerable: true, writable: true }
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function doPreparation(from, to, direction, navigationType, sourceElement, info, formData, defaultLoader) {
|
|
89
|
+
const event = new TransitionBeforePreparationEvent(
|
|
90
|
+
from,
|
|
91
|
+
to,
|
|
92
|
+
direction,
|
|
93
|
+
navigationType,
|
|
94
|
+
sourceElement,
|
|
95
|
+
info,
|
|
96
|
+
window.document,
|
|
97
|
+
formData,
|
|
98
|
+
defaultLoader
|
|
99
|
+
);
|
|
100
|
+
if (document.dispatchEvent(event)) {
|
|
101
|
+
await event.loader();
|
|
102
|
+
if (!event.defaultPrevented) {
|
|
103
|
+
triggerEvent(TRANSITION_AFTER_PREPARATION);
|
|
104
|
+
if (event.navigationType !== "traverse") {
|
|
105
|
+
updateScrollPosition({ scrollX, scrollY });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return event;
|
|
110
|
+
}
|
|
111
|
+
async function doSwap(afterPreparation, viewTransition, defaultSwap) {
|
|
112
|
+
const event = new TransitionBeforeSwapEvent(afterPreparation, viewTransition, defaultSwap);
|
|
113
|
+
document.dispatchEvent(event);
|
|
114
|
+
event.swap();
|
|
115
|
+
return event;
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
TRANSITION_AFTER_PREPARATION,
|
|
119
|
+
TRANSITION_AFTER_SWAP,
|
|
120
|
+
TRANSITION_BEFORE_PREPARATION,
|
|
121
|
+
TRANSITION_BEFORE_SWAP,
|
|
122
|
+
TRANSITION_PAGE_LOAD,
|
|
123
|
+
TransitionBeforePreparationEvent,
|
|
124
|
+
TransitionBeforeSwapEvent,
|
|
125
|
+
doPreparation,
|
|
126
|
+
doSwap,
|
|
127
|
+
isTransitionBeforePreparationEvent,
|
|
128
|
+
isTransitionBeforeSwapEvent,
|
|
129
|
+
onPageLoad,
|
|
130
|
+
triggerEvent
|
|
131
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createAnimationScope } from "../runtime/server/transition.js";
|
|
1
2
|
const EASE_IN_OUT_QUART = "cubic-bezier(0.76, 0, 0.24, 1)";
|
|
2
3
|
function slide({
|
|
3
4
|
duration
|
|
@@ -63,6 +64,7 @@ function fade({
|
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
export {
|
|
67
|
+
createAnimationScope,
|
|
66
68
|
fade,
|
|
67
69
|
slide
|
|
68
70
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
1
|
+
import type { Options } from './types.js';
|
|
2
|
+
export declare const updateScrollPosition: (positions: {
|
|
3
|
+
scrollX: number;
|
|
4
|
+
scrollY: number;
|
|
5
|
+
}) => void;
|
|
7
6
|
export declare const supportsViewTransitions: boolean;
|
|
8
7
|
export declare const transitionEnabledOnThisPage: () => boolean;
|
|
9
|
-
export declare function navigate(href: string, options?: Options): void
|
|
8
|
+
export declare function navigate(href: string, options?: Options): Promise<void>;
|