@ecopages/browser-router 0.2.1-beta.0 → 0.3.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/README.md +24 -7
- package/package.json +11 -8
- package/src/client/document-element-sync.d.ts +0 -7
- package/src/client/document-element-sync.js +28 -18
- package/src/client/dom/body-morpher.d.ts +27 -0
- package/src/client/dom/body-morpher.js +166 -0
- package/src/client/dom/dom-swapper.d.ts +7 -0
- package/src/client/dom/dom-swapper.js +15 -0
- package/src/client/dom/stylesheet-discovery.d.ts +12 -0
- package/src/client/dom/stylesheet-discovery.js +24 -0
- package/src/client/eco-router-perform-navigation.d.ts +13 -0
- package/src/client/eco-router-perform-navigation.js +24 -0
- package/src/client/eco-router.d.ts +2 -35
- package/src/client/eco-router.js +329 -479
- package/src/client/index.d.ts +3 -0
- package/src/client/index.js +3 -0
- package/src/client/navigation-commit-reload.d.ts +21 -0
- package/src/client/navigation-commit-reload.js +16 -0
- package/src/client/navigation-commit.d.ts +19 -0
- package/src/client/navigation-commit.js +83 -0
- package/src/client/services/prefetch-manager.d.ts +4 -15
- package/src/client/services/prefetch-manager.js +353 -370
- package/src/client/types.d.ts +16 -13
- package/src/client/types.js +21 -20
- package/src/index.d.ts +2 -5
- package/src/index.js +7 -18
- package/src/client/services/dom-swapper.d.ts +0 -168
- package/src/client/services/dom-swapper.js +0 -529
- package/src/client/services/index.d.ts +0 -8
- package/src/client/services/index.js +0 -10
- package/src/client/services/scroll-manager.d.ts +0 -19
- package/src/client/services/scroll-manager.js +0 -36
- package/src/client/services/view-transition-manager.d.ts +0 -29
- package/src/client/services/view-transition-manager.js +0 -54
- package/src/client/view-transition-utils.d.ts +0 -14
- package/src/client/view-transition-utils.js +0 -60
- package/src/styles.css +0 -218
- package/src/types.d.ts +0 -15
- package/src/types.js +0 -5
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* View transition utilities for applying transition names from data attributes.
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Applies view-transition-name CSS property to elements with data-view-transition attribute.
|
|
7
|
-
* By default, it also injects styles to prevent "ghosting" (sets animation: none) for clean morphing,
|
|
8
|
-
* unless data-view-transition-animate="fade" is present.
|
|
9
|
-
*/
|
|
10
|
-
export declare function applyViewTransitionNames(): void;
|
|
11
|
-
/**
|
|
12
|
-
* Clears view-transition-name CSS property from all elements.
|
|
13
|
-
*/
|
|
14
|
-
export declare function clearViewTransitionNames(): void;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const VIEW_TRANSITION_ATTR = "data-view-transition";
|
|
2
|
-
const VIEW_TRANSITION_ANIMATE_ATTR = "data-view-transition-animate";
|
|
3
|
-
const VIEW_TRANSITION_DURATION_ATTR = "data-view-transition-duration";
|
|
4
|
-
function applyViewTransitionNames() {
|
|
5
|
-
const elements = document.querySelectorAll(`[${VIEW_TRANSITION_ATTR}]`);
|
|
6
|
-
const morphNames = [];
|
|
7
|
-
const customDurations = [];
|
|
8
|
-
elements.forEach((el) => {
|
|
9
|
-
const name = el.getAttribute(VIEW_TRANSITION_ATTR);
|
|
10
|
-
if (name) {
|
|
11
|
-
el.style.viewTransitionName = name;
|
|
12
|
-
const animate = el.getAttribute(VIEW_TRANSITION_ANIMATE_ATTR);
|
|
13
|
-
if (animate !== "fade") {
|
|
14
|
-
morphNames.push(name);
|
|
15
|
-
}
|
|
16
|
-
const duration = el.getAttribute(VIEW_TRANSITION_DURATION_ATTR);
|
|
17
|
-
if (duration) {
|
|
18
|
-
customDurations.push({ name, duration });
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
if (morphNames.length > 0 || customDurations.length > 0) {
|
|
23
|
-
injectDynamicStyles(morphNames, customDurations);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function injectDynamicStyles(morphNames, customDurations) {
|
|
27
|
-
let styleEl = document.getElementById("eco-vt-dynamic-styles");
|
|
28
|
-
if (!styleEl) {
|
|
29
|
-
styleEl = document.createElement("style");
|
|
30
|
-
styleEl.id = "eco-vt-dynamic-styles";
|
|
31
|
-
styleEl.setAttribute("data-eco-persist", "");
|
|
32
|
-
document.head.appendChild(styleEl);
|
|
33
|
-
}
|
|
34
|
-
const morphCss = morphNames.map(
|
|
35
|
-
(name) => `
|
|
36
|
-
::view-transition-old(${name}) { display: none !important; }
|
|
37
|
-
::view-transition-new(${name}) { animation: none !important; opacity: 1 !important; }
|
|
38
|
-
`
|
|
39
|
-
).join("\n");
|
|
40
|
-
const durationCss = customDurations.map(
|
|
41
|
-
({ name, duration }) => `
|
|
42
|
-
::view-transition-group(${name}) { animation-duration: ${duration} !important; }
|
|
43
|
-
`
|
|
44
|
-
).join("\n");
|
|
45
|
-
styleEl.textContent = morphCss + "\n" + durationCss;
|
|
46
|
-
}
|
|
47
|
-
function clearViewTransitionNames() {
|
|
48
|
-
const elements = document.querySelectorAll(`[${VIEW_TRANSITION_ATTR}]`);
|
|
49
|
-
elements.forEach((el) => {
|
|
50
|
-
el.style.viewTransitionName = "";
|
|
51
|
-
});
|
|
52
|
-
const styleEl = document.getElementById("eco-vt-dynamic-styles");
|
|
53
|
-
if (styleEl) {
|
|
54
|
-
styleEl.textContent = "";
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export {
|
|
58
|
-
applyViewTransitionNames,
|
|
59
|
-
clearViewTransitionNames
|
|
60
|
-
};
|
package/src/styles.css
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default View Transition CSS for EcoPages transitions
|
|
3
|
-
*
|
|
4
|
-
* NOTE: This file is not exported from the package.
|
|
5
|
-
* JSR does not support CSS exports yet: https://github.com/jsr-io/jsr/issues/293
|
|
6
|
-
*
|
|
7
|
-
* Use the ecopages npm package instead:
|
|
8
|
-
* @import 'ecopages/css/view-transitions.css';
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/* Disable root animation to prevent full page flash during transitions */
|
|
12
|
-
::view-transition-old(root),
|
|
13
|
-
::view-transition-new(root) {
|
|
14
|
-
animation: none;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/* Shared element transitions animate position/size smoothly */
|
|
18
|
-
::view-transition-group(*) {
|
|
19
|
-
animation-duration: 180ms;
|
|
20
|
-
animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/* Prevent transitioning elements from affecting layout of non-transitioning elements */
|
|
24
|
-
::view-transition-image-pair(*) {
|
|
25
|
-
isolation: isolate;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/* Respect reduced motion preference */
|
|
29
|
-
@media (prefers-reduced-motion: reduce) {
|
|
30
|
-
::view-transition-group(*),
|
|
31
|
-
::view-transition-old(*),
|
|
32
|
-
::view-transition-new(*) {
|
|
33
|
-
animation: none !important;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@keyframes eco-fade-out {
|
|
38
|
-
from {
|
|
39
|
-
opacity: 1;
|
|
40
|
-
}
|
|
41
|
-
to {
|
|
42
|
-
opacity: 0;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@keyframes eco-fade-in {
|
|
47
|
-
from {
|
|
48
|
-
opacity: 0;
|
|
49
|
-
}
|
|
50
|
-
to {
|
|
51
|
-
opacity: 1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/* Slide transition for elements with view-transition-name: eco-slide */
|
|
56
|
-
::view-transition-image-pair(eco-slide) {
|
|
57
|
-
isolation: isolate;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
::view-transition-old(eco-slide),
|
|
61
|
-
::view-transition-new(eco-slide) {
|
|
62
|
-
animation-duration: 180ms;
|
|
63
|
-
animation-timing-function: ease-out;
|
|
64
|
-
mix-blend-mode: normal;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
::view-transition-old(eco-slide) {
|
|
68
|
-
animation-name: eco-slide-out;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
::view-transition-new(eco-slide) {
|
|
72
|
-
animation-name: eco-slide-in;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@keyframes eco-slide-out {
|
|
76
|
-
from {
|
|
77
|
-
opacity: 1;
|
|
78
|
-
transform: translateX(0);
|
|
79
|
-
}
|
|
80
|
-
to {
|
|
81
|
-
opacity: 0;
|
|
82
|
-
transform: translateX(-30px);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
@keyframes eco-slide-in {
|
|
87
|
-
from {
|
|
88
|
-
opacity: 0;
|
|
89
|
-
transform: translateX(30px);
|
|
90
|
-
}
|
|
91
|
-
to {
|
|
92
|
-
opacity: 1;
|
|
93
|
-
transform: translateX(0);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/* Persistent elements should not animate */
|
|
98
|
-
[data-eco-persist] {
|
|
99
|
-
view-transition-name: none;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/* Declarative transition attributes */
|
|
103
|
-
[data-eco-transition='slide'] {
|
|
104
|
-
view-transition-name: eco-slide;
|
|
105
|
-
}
|
|
106
|
-
[data-eco-transition='fade'] {
|
|
107
|
-
view-transition-name: eco-fade;
|
|
108
|
-
}
|
|
109
|
-
[data-eco-transition='zoom'] {
|
|
110
|
-
view-transition-name: eco-zoom;
|
|
111
|
-
}
|
|
112
|
-
[data-eco-transition='slide-up'] {
|
|
113
|
-
view-transition-name: eco-slide-up;
|
|
114
|
-
}
|
|
115
|
-
[data-eco-transition='slide-down'] {
|
|
116
|
-
view-transition-name: eco-slide-down;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/* FADE */
|
|
120
|
-
::view-transition-old(eco-fade) {
|
|
121
|
-
animation: eco-fade-out 180ms ease-out both;
|
|
122
|
-
}
|
|
123
|
-
::view-transition-new(eco-fade) {
|
|
124
|
-
animation: eco-fade-in 180ms ease-out both;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/* ZOOM */
|
|
128
|
-
::view-transition-image-pair(eco-zoom) {
|
|
129
|
-
isolation: isolate;
|
|
130
|
-
}
|
|
131
|
-
::view-transition-old(eco-zoom) {
|
|
132
|
-
animation: eco-zoom-out 180ms ease-in both;
|
|
133
|
-
}
|
|
134
|
-
::view-transition-new(eco-zoom) {
|
|
135
|
-
animation: eco-zoom-in 180ms ease-out both;
|
|
136
|
-
}
|
|
137
|
-
@keyframes eco-zoom-out {
|
|
138
|
-
from {
|
|
139
|
-
opacity: 1;
|
|
140
|
-
transform: scale(1);
|
|
141
|
-
}
|
|
142
|
-
to {
|
|
143
|
-
opacity: 0;
|
|
144
|
-
transform: scale(0.9);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
@keyframes eco-zoom-in {
|
|
148
|
-
from {
|
|
149
|
-
opacity: 0;
|
|
150
|
-
transform: scale(0.9);
|
|
151
|
-
}
|
|
152
|
-
to {
|
|
153
|
-
opacity: 1;
|
|
154
|
-
transform: scale(1);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/* SLIDE UP */
|
|
159
|
-
::view-transition-image-pair(eco-slide-up) {
|
|
160
|
-
isolation: isolate;
|
|
161
|
-
}
|
|
162
|
-
::view-transition-old(eco-slide-up) {
|
|
163
|
-
animation: eco-slide-up-out 180ms ease-in both;
|
|
164
|
-
}
|
|
165
|
-
::view-transition-new(eco-slide-up) {
|
|
166
|
-
animation: eco-slide-up-in 180ms ease-out both;
|
|
167
|
-
}
|
|
168
|
-
@keyframes eco-slide-up-out {
|
|
169
|
-
from {
|
|
170
|
-
opacity: 1;
|
|
171
|
-
transform: translateY(0);
|
|
172
|
-
}
|
|
173
|
-
to {
|
|
174
|
-
opacity: 0;
|
|
175
|
-
transform: translateY(-30px);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
@keyframes eco-slide-up-in {
|
|
179
|
-
from {
|
|
180
|
-
opacity: 0;
|
|
181
|
-
transform: translateY(30px);
|
|
182
|
-
}
|
|
183
|
-
to {
|
|
184
|
-
opacity: 1;
|
|
185
|
-
transform: translateY(0);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/* SLIDE DOWN */
|
|
190
|
-
::view-transition-image-pair(eco-slide-down) {
|
|
191
|
-
isolation: isolate;
|
|
192
|
-
}
|
|
193
|
-
::view-transition-old(eco-slide-down) {
|
|
194
|
-
animation: eco-slide-down-out 180ms ease-in both;
|
|
195
|
-
}
|
|
196
|
-
::view-transition-new(eco-slide-down) {
|
|
197
|
-
animation: eco-slide-down-in 180ms ease-out both;
|
|
198
|
-
}
|
|
199
|
-
@keyframes eco-slide-down-out {
|
|
200
|
-
from {
|
|
201
|
-
opacity: 1;
|
|
202
|
-
transform: translateY(0);
|
|
203
|
-
}
|
|
204
|
-
to {
|
|
205
|
-
opacity: 0;
|
|
206
|
-
transform: translateY(30px);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
@keyframes eco-slide-down-in {
|
|
210
|
-
from {
|
|
211
|
-
opacity: 0;
|
|
212
|
-
transform: translateY(-30px);
|
|
213
|
-
}
|
|
214
|
-
to {
|
|
215
|
-
opacity: 1;
|
|
216
|
-
transform: translateY(0);
|
|
217
|
-
}
|
|
218
|
-
}
|
package/src/types.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types for the @ecopages/browser-router package
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
import type { EcoNavigationEvent, EcoBeforeSwapEvent, EcoAfterSwapEvent } from './client/types';
|
|
6
|
-
export type { EcoRouterOptions, EcoNavigationEvent, EcoBeforeSwapEvent, EcoAfterSwapEvent } from './client/types';
|
|
7
|
-
export { DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC, DEFAULT_OPTIONS } from './client/types';
|
|
8
|
-
/**
|
|
9
|
-
* Custom event map for navigation lifecycle
|
|
10
|
-
*/
|
|
11
|
-
export interface EcoRouterEventMap {
|
|
12
|
-
'eco:before-swap': CustomEvent<EcoBeforeSwapEvent>;
|
|
13
|
-
'eco:after-swap': CustomEvent<EcoAfterSwapEvent>;
|
|
14
|
-
'eco:page-load': CustomEvent<EcoNavigationEvent>;
|
|
15
|
-
}
|