@ecopages/browser-router 0.2.0-alpha.2 → 0.2.0-alpha.21

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.
Files changed (67) hide show
  1. package/CHANGELOG.md +8 -6
  2. package/README.md +60 -37
  3. package/package.json +4 -2
  4. package/src/client/document-element-sync.d.ts +24 -0
  5. package/src/client/document-element-sync.js +20 -0
  6. package/src/client/eco-router.d.ts +35 -1
  7. package/src/client/eco-router.js +337 -68
  8. package/src/client/services/dom-swapper.d.ts +101 -0
  9. package/src/client/services/dom-swapper.js +306 -39
  10. package/src/client/services/prefetch-manager.d.ts +7 -3
  11. package/src/client/services/prefetch-manager.js +26 -11
  12. package/src/client/services/view-transition-manager.d.ts +7 -1
  13. package/src/client/services/view-transition-manager.js +21 -5
  14. package/src/client/types.d.ts +12 -0
  15. package/src/client/types.js +4 -0
  16. package/src/index.d.ts +2 -1
  17. package/src/index.js +9 -2
  18. package/src/types.d.ts +1 -1
  19. package/src/types.js +2 -1
  20. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Initialization-should-create-router-instance-1.png +0 -0
  21. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Initialization-should-start-and-stop-without-errors-1.png +0 -0
  22. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Lifecycle-Events-should-dispatch-eco-before-swap--eco-after-swap--and-eco-page-load-events-1.png +0 -0
  23. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Lifecycle-Events-should-dispatch-eco-page-load-event-after-animation-frame-1.png +0 -0
  24. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Lifecycle-Events-should-provide-event-details-with-url-and-direction-1.png +0 -0
  25. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Custom-Link-Selector-should-work-with-data-attribute-selector-1.png +0 -0
  26. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Custom-Reload-Attribute-should-intercept-links-with-default-reload-attribute-when-custom-is-set-1.png +0 -0
  27. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Custom-link-selector-should-only-intercept-links-matching-custom-selector-1.png +0 -0
  28. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-External-Links--should-NOT-intercept--should-NOT-intercept-external-links-1.png +0 -0
  29. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Internal-Links-should-intercept-clicks-on-relative-path-links-1.png +0 -0
  30. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Internal-Links-should-intercept-clicks-on-same-origin-absolute-URLs-1.png +0 -0
  31. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Link-Attributes--should-NOT-intercept--should-NOT-intercept-links-with-download-attribute-1.png +0 -0
  32. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Link-Attributes--should-NOT-intercept--should-intercept-links-with-target---self--1.png +0 -0
  33. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Modifier-keys-should-NOT-intercept-alt-click-1.png +0 -0
  34. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Modifier-keys-should-NOT-intercept-ctrl-click-1.png +0 -0
  35. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Modifier-keys-should-NOT-intercept-meta-click--cmd-on-Mac--1.png +0 -0
  36. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Modifier-keys-should-NOT-intercept-middle-mouse-button-click-1.png +0 -0
  37. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Modifier-keys-should-NOT-intercept-right-mouse-button-click-1.png +0 -0
  38. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Modifier-keys-should-NOT-intercept-shift-click-1.png +0 -0
  39. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-NOT-intercept-external-links--different-origin--1.png +0 -0
  40. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-NOT-intercept-hash-only-links-1.png +0 -0
  41. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-NOT-intercept-javascript--links-1.png +0 -0
  42. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-NOT-intercept-links-with-custom-reload-attribute-1.png +0 -0
  43. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-NOT-intercept-links-with-data-eco-reload-attribute-1.png +0 -0
  44. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-NOT-intercept-links-with-download-attribute-1.png +0 -0
  45. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-NOT-intercept-links-with-empty-href-1.png +0 -0
  46. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-NOT-intercept-links-with-target---blank--1.png +0 -0
  47. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-NOT-intercept-links-with-target---parent--1.png +0 -0
  48. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-NOT-intercept-links-without-href-attribute-1.png +0 -0
  49. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-intercept-internal-links-with-absolute-same-origin-paths-1.png +0 -0
  50. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-intercept-internal-links-with-relative-paths-1.png +0 -0
  51. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-Should-intercept-nested-elements-inside-links-1.png +0 -0
  52. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Link-Interception-should-NOT-intercept-external-links-1.png +0 -0
  53. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Navigation-Abort-should-abort-previous-navigation-when-new-one-starts-1.png +0 -0
  54. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Programmatic-Navigation-should-navigate-and-update-history-with-pushState-1.png +0 -0
  55. package/src/client/__screenshots__/eco-router.test.browser.ts/EcoRouter-Programmatic-Navigation-should-use-replaceState-when-replace-option-is-true-1.png +0 -0
  56. package/src/client/__screenshots__/eco-router.test.ts/EcoRouter-Error-Handling-should-fall-back-to-full-page-navigation-on-fetch-error-1.png +0 -0
  57. package/src/client/__screenshots__/eco-router.test.ts/EcoRouter-Error-Handling-should-log-error-and-attempt-fallback-navigation-on-fetch-error-1.png +0 -0
  58. package/src/client/eco-router.ts +0 -290
  59. package/src/client/services/dom-swapper.ts +0 -325
  60. package/src/client/services/index.ts +0 -9
  61. package/src/client/services/prefetch-manager.ts +0 -451
  62. package/src/client/services/scroll-manager.ts +0 -48
  63. package/src/client/services/view-transition-manager.ts +0 -75
  64. package/src/client/types.ts +0 -109
  65. package/src/client/view-transition-utils.ts +0 -98
  66. package/src/index.ts +0 -19
  67. package/src/types.ts +0 -19
@@ -1,98 +0,0 @@
1
- /**
2
- * View transition utilities for applying transition names from data attributes.
3
- * @module
4
- */
5
-
6
- const VIEW_TRANSITION_ATTR = 'data-view-transition';
7
- const VIEW_TRANSITION_ANIMATE_ATTR = 'data-view-transition-animate';
8
- const VIEW_TRANSITION_DURATION_ATTR = 'data-view-transition-duration';
9
-
10
- /**
11
- * Applies view-transition-name CSS property to elements with data-view-transition attribute.
12
- * By default, it also injects styles to prevent "ghosting" (sets animation: none) for clean morphing,
13
- * unless data-view-transition-animate="fade" is present.
14
- */
15
- export function applyViewTransitionNames(): void {
16
- const elements = document.querySelectorAll(`[${VIEW_TRANSITION_ATTR}]`);
17
- const morphNames: string[] = [];
18
- const customDurations: { name: string; duration: string }[] = [];
19
-
20
- elements.forEach((el) => {
21
- const name = el.getAttribute(VIEW_TRANSITION_ATTR);
22
- if (name) {
23
- (el as HTMLElement).style.viewTransitionName = name;
24
-
25
- /**
26
- * By default, we apply a clean geometric morph (no cross-fade/ghosting).
27
- * The 'fade' value is reserved for opting out of this behavior.
28
- */
29
- const animate = el.getAttribute(VIEW_TRANSITION_ANIMATE_ATTR);
30
- if (animate !== 'fade') {
31
- morphNames.push(name);
32
- }
33
-
34
- const duration = el.getAttribute(VIEW_TRANSITION_DURATION_ATTR);
35
- if (duration) {
36
- customDurations.push({ name, duration });
37
- }
38
- }
39
- });
40
-
41
- if (morphNames.length > 0 || customDurations.length > 0) {
42
- injectDynamicStyles(morphNames, customDurations);
43
- }
44
- }
45
-
46
- /**
47
- * Injects dynamic CSS to hide old snapshots and apply custom durations.
48
- */
49
- function injectDynamicStyles(morphNames: string[], customDurations: { name: string; duration: string }[]) {
50
- let styleEl = document.getElementById('eco-vt-dynamic-styles');
51
- if (!styleEl) {
52
- styleEl = document.createElement('style');
53
- styleEl.id = 'eco-vt-dynamic-styles';
54
- /**
55
- * Persistence is required to prevent the head-morpher from removing this style tag during navigation.
56
- * @see {@link DomSwapper}
57
- */
58
- styleEl.setAttribute('data-eco-persist', '');
59
- document.head.appendChild(styleEl);
60
- }
61
-
62
- const morphCss = morphNames
63
- .map(
64
- (name) => `
65
- ::view-transition-old(${name}) { display: none !important; }
66
- ::view-transition-new(${name}) { animation: none !important; opacity: 1 !important; }
67
- `,
68
- )
69
- .join('\n');
70
-
71
- const durationCss = customDurations
72
- .map(
73
- ({ name, duration }) => `
74
- ::view-transition-group(${name}) { animation-duration: ${duration} !important; }
75
- `,
76
- )
77
- .join('\n');
78
-
79
- styleEl.textContent = morphCss + '\n' + durationCss;
80
- }
81
-
82
- /**
83
- * Clears view-transition-name CSS property from all elements.
84
- */
85
- export function clearViewTransitionNames(): void {
86
- const elements = document.querySelectorAll(`[${VIEW_TRANSITION_ATTR}]`);
87
- elements.forEach((el) => {
88
- (el as HTMLElement).style.viewTransitionName = '';
89
- });
90
-
91
- /**
92
- * Cleanup dynamic styles to ensure a clean slate for the next transition.
93
- */
94
- const styleEl = document.getElementById('eco-vt-dynamic-styles');
95
- if (styleEl) {
96
- styleEl.textContent = '';
97
- }
98
- }
package/src/index.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * @ecopages/browser-router
3
- * Client-side navigation and view transitions for Ecopages
4
- * @module
5
- */
6
-
7
- export type {
8
- EcoRouterOptions,
9
- EcoNavigationEvent,
10
- EcoBeforeSwapEvent,
11
- EcoAfterSwapEvent,
12
- EcoRouterEventMap,
13
- } from './types.ts';
14
-
15
- export { DEFAULT_OPTIONS } from './types.ts';
16
-
17
- export { EcoRouter, createRouter } from './client/eco-router.ts';
18
-
19
- export { DomSwapper, ScrollManager, ViewTransitionManager } from './client/services/index.ts';
package/src/types.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * Types for the @ecopages/browser-router package
3
- * @module
4
- */
5
-
6
- import type { EcoNavigationEvent, EcoBeforeSwapEvent, EcoAfterSwapEvent } from './client/types';
7
-
8
- export type { EcoRouterOptions, EcoNavigationEvent, EcoBeforeSwapEvent, EcoAfterSwapEvent } from './client/types';
9
-
10
- export { DEFAULT_OPTIONS } from './client/types';
11
-
12
- /**
13
- * Custom event map for navigation lifecycle
14
- */
15
- export interface EcoRouterEventMap {
16
- 'eco:before-swap': CustomEvent<EcoBeforeSwapEvent>;
17
- 'eco:after-swap': CustomEvent<EcoAfterSwapEvent>;
18
- 'eco:page-load': CustomEvent<EcoNavigationEvent>;
19
- }