baremetal.js 1.0.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.
@@ -0,0 +1,90 @@
1
+ export function mount({ state }) {
2
+ console.log('[Transition Module] Mounted');
3
+
4
+ // Create Protected Root
5
+ let root = document.getElementById('baremetal-transition-root');
6
+ if (!root) {
7
+ root = document.createElement('div');
8
+ root.id = 'baremetal-transition-root';
9
+ document.body.appendChild(root);
10
+ }
11
+
12
+ // Create Progress Bar
13
+ const progressBar = document.createElement('div');
14
+ progressBar.style.position = 'fixed';
15
+ progressBar.style.top = '0';
16
+ progressBar.style.left = '0';
17
+ progressBar.style.height = '3px';
18
+ progressBar.style.backgroundColor = '#3498db'; // YouTube blue-ish
19
+ progressBar.style.width = '0%';
20
+ progressBar.style.zIndex = '999999';
21
+ progressBar.style.transition = 'width 0.2s ease-out, opacity 0.3s ease';
22
+ progressBar.style.opacity = '0';
23
+ progressBar.style.pointerEvents = 'none';
24
+
25
+ // Create Fade Overlay
26
+ const overlay = document.createElement('div');
27
+ overlay.style.position = 'fixed';
28
+ overlay.style.top = '0';
29
+ overlay.style.left = '0';
30
+ overlay.style.width = '100vw';
31
+ overlay.style.height = '100vh';
32
+ overlay.style.backgroundColor = 'rgba(255, 255, 255, 0.7)';
33
+ overlay.style.zIndex = '999998';
34
+ overlay.style.transition = 'opacity 0.3s ease';
35
+ overlay.style.opacity = '0';
36
+ overlay.style.pointerEvents = 'none';
37
+
38
+ root.appendChild(overlay);
39
+ root.appendChild(progressBar);
40
+
41
+ // Subscriptions
42
+ const unsubs = [];
43
+
44
+ unsubs.push(state.on('ROUTE_START', () => {
45
+ progressBar.style.backgroundColor = '#3498db'; // Reset to blue
46
+ progressBar.style.opacity = '1';
47
+ progressBar.style.width = '5%';
48
+
49
+ overlay.style.pointerEvents = 'all'; // block clicks during load
50
+ overlay.style.opacity = '1';
51
+ }));
52
+
53
+ unsubs.push(state.on('ROUTE_PROGRESS', (payload) => {
54
+ if (payload && payload.progress !== undefined) {
55
+ progressBar.style.width = `${payload.progress}%`;
56
+ }
57
+ }));
58
+
59
+ unsubs.push(state.on('ROUTE_END', () => {
60
+ progressBar.style.width = '100%';
61
+
62
+ setTimeout(() => {
63
+ progressBar.style.opacity = '0';
64
+ overlay.style.opacity = '0';
65
+ overlay.style.pointerEvents = 'none';
66
+
67
+ // Reset after fade out
68
+ setTimeout(() => {
69
+ progressBar.style.width = '0%';
70
+ }, 300);
71
+ }, 200);
72
+ }));
73
+
74
+ unsubs.push(state.on('ROUTE_ERROR', () => {
75
+ progressBar.style.backgroundColor = '#e74c3c'; // red
76
+ setTimeout(() => {
77
+ progressBar.style.opacity = '0';
78
+ overlay.style.opacity = '0';
79
+ overlay.style.pointerEvents = 'none';
80
+ }, 1000);
81
+ }));
82
+
83
+ return {
84
+ destroy: () => {
85
+ console.log('[Transition Module] Destroyed');
86
+ unsubs.forEach(u => u());
87
+ if (root.parentNode) root.parentNode.removeChild(root);
88
+ }
89
+ };
90
+ }