utopia-project 0.38.0 → 0.39.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.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/utopia/project/version.rb +1 -1
  4. data/pages/_page.xnode +1 -18
  5. data/pages/guides/show.xnode +0 -1
  6. data/pages/releases/index.xnode +0 -1
  7. data/public/_static/application.js +24 -0
  8. data/public/_static/links.js +18 -16
  9. data/public/_static/sidebar.js +205 -133
  10. data.tar.gz.sig +0 -0
  11. metadata +2 -74
  12. metadata.gz.sig +0 -0
  13. data/public/_components/jquery/jquery.js +0 -10716
  14. data/public/_components/jquery/jquery.min.js +0 -2
  15. data/public/_components/jquery/jquery.min.map +0 -1
  16. data/public/_components/jquery/jquery.slim.js +0 -8617
  17. data/public/_components/jquery/jquery.slim.min.js +0 -2
  18. data/public/_components/jquery/jquery.slim.min.map +0 -1
  19. data/public/_components/jquery-litebox/jquery.litebox.css +0 -23
  20. data/public/_components/jquery-litebox/jquery.litebox.gallery.css +0 -48
  21. data/public/_components/jquery-litebox/jquery.litebox.js +0 -30
  22. data/public/_components/jquery-syntax/base/jquery.syntax.brush.apache.css +0 -12
  23. data/public/_components/jquery-syntax/base/jquery.syntax.brush.applescript.css +0 -5
  24. data/public/_components/jquery-syntax/base/jquery.syntax.brush.assembly.css +0 -8
  25. data/public/_components/jquery-syntax/base/jquery.syntax.brush.bash-script.css +0 -4
  26. data/public/_components/jquery-syntax/base/jquery.syntax.brush.bash.css +0 -2
  27. data/public/_components/jquery-syntax/base/jquery.syntax.brush.clang.css +0 -6
  28. data/public/_components/jquery-syntax/base/jquery.syntax.brush.css.css +0 -14
  29. data/public/_components/jquery-syntax/base/jquery.syntax.brush.diff.css +0 -16
  30. data/public/_components/jquery-syntax/base/jquery.syntax.brush.html.css +0 -3
  31. data/public/_components/jquery-syntax/base/jquery.syntax.brush.ocaml.css +0 -3
  32. data/public/_components/jquery-syntax/base/jquery.syntax.brush.protobuf.css +0 -2
  33. data/public/_components/jquery-syntax/base/jquery.syntax.brush.python.css +0 -6
  34. data/public/_components/jquery-syntax/base/jquery.syntax.brush.ruby.css +0 -2
  35. data/public/_components/jquery-syntax/base/jquery.syntax.brush.xml.css +0 -35
  36. data/public/_components/jquery-syntax/base/jquery.syntax.core.css +0 -58
  37. data/public/_components/jquery-syntax/base/jquery.syntax.editor.css +0 -6
  38. data/public/_components/jquery-syntax/base/theme.js +0 -1
  39. data/public/_components/jquery-syntax/bright/jquery.syntax.core.css +0 -27
  40. data/public/_components/jquery-syntax/bright/theme.js +0 -1
  41. data/public/_components/jquery-syntax/jquery.syntax.brush.apache.js +0 -3
  42. data/public/_components/jquery-syntax/jquery.syntax.brush.applescript.js +0 -5
  43. data/public/_components/jquery-syntax/jquery.syntax.brush.assembly.js +0 -3
  44. data/public/_components/jquery-syntax/jquery.syntax.brush.bash-script.js +0 -4
  45. data/public/_components/jquery-syntax/jquery.syntax.brush.bash.js +0 -2
  46. data/public/_components/jquery-syntax/jquery.syntax.brush.basic.js +0 -5
  47. data/public/_components/jquery-syntax/jquery.syntax.brush.clang.js +0 -5
  48. data/public/_components/jquery-syntax/jquery.syntax.brush.csharp.js +0 -4
  49. data/public/_components/jquery-syntax/jquery.syntax.brush.css.js +0 -5
  50. data/public/_components/jquery-syntax/jquery.syntax.brush.diff.js +0 -2
  51. data/public/_components/jquery-syntax/jquery.syntax.brush.go.js +0 -3
  52. data/public/_components/jquery-syntax/jquery.syntax.brush.haskell.js +0 -3
  53. data/public/_components/jquery-syntax/jquery.syntax.brush.html.js +0 -4
  54. data/public/_components/jquery-syntax/jquery.syntax.brush.io.js +0 -3
  55. data/public/_components/jquery-syntax/jquery.syntax.brush.java.js +0 -4
  56. data/public/_components/jquery-syntax/jquery.syntax.brush.javascript.js +0 -3
  57. data/public/_components/jquery-syntax/jquery.syntax.brush.kai.js +0 -2
  58. data/public/_components/jquery-syntax/jquery.syntax.brush.lisp.js +0 -2
  59. data/public/_components/jquery-syntax/jquery.syntax.brush.lua.js +0 -3
  60. data/public/_components/jquery-syntax/jquery.syntax.brush.nginx.js +0 -2
  61. data/public/_components/jquery-syntax/jquery.syntax.brush.ocaml.js +0 -4
  62. data/public/_components/jquery-syntax/jquery.syntax.brush.ooc.js +0 -4
  63. data/public/_components/jquery-syntax/jquery.syntax.brush.pascal.js +0 -4
  64. data/public/_components/jquery-syntax/jquery.syntax.brush.perl5.js +0 -3
  65. data/public/_components/jquery-syntax/jquery.syntax.brush.php-script.js +0 -4
  66. data/public/_components/jquery-syntax/jquery.syntax.brush.php.js +0 -2
  67. data/public/_components/jquery-syntax/jquery.syntax.brush.plain.js +0 -2
  68. data/public/_components/jquery-syntax/jquery.syntax.brush.protobuf.js +0 -3
  69. data/public/_components/jquery-syntax/jquery.syntax.brush.python.js +0 -5
  70. data/public/_components/jquery-syntax/jquery.syntax.brush.ruby.js +0 -5
  71. data/public/_components/jquery-syntax/jquery.syntax.brush.scala.js +0 -4
  72. data/public/_components/jquery-syntax/jquery.syntax.brush.smalltalk.js +0 -2
  73. data/public/_components/jquery-syntax/jquery.syntax.brush.sql.js +0 -4
  74. data/public/_components/jquery-syntax/jquery.syntax.brush.super-collider.js +0 -3
  75. data/public/_components/jquery-syntax/jquery.syntax.brush.swift.js +0 -3
  76. data/public/_components/jquery-syntax/jquery.syntax.brush.xml.js +0 -4
  77. data/public/_components/jquery-syntax/jquery.syntax.brush.xrb.js +0 -2
  78. data/public/_components/jquery-syntax/jquery.syntax.brush.yaml.js +0 -2
  79. data/public/_components/jquery-syntax/jquery.syntax.cache.js +0 -7
  80. data/public/_components/jquery-syntax/jquery.syntax.core.js +0 -34
  81. data/public/_components/jquery-syntax/jquery.syntax.editor.js +0 -11
  82. data/public/_components/jquery-syntax/jquery.syntax.js +0 -8
  83. data/public/_components/jquery-syntax/jquery.syntax.min.js +0 -13
  84. data/public/_components/jquery-syntax/paper/jquery.syntax.core.css +0 -31
  85. data/public/_components/jquery-syntax/paper/theme.js +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00ba83cfcaea0e83dbd4e927e4ed1483fa7079c94b56c9a480616a421b04fcaa
4
- data.tar.gz: 48b8ceb3698e82e2d3f460f53f5e085540251c4e054abe0ff0560133de2d5d40
3
+ metadata.gz: 21be268fb201720abe3d699eba3f8a71ebee79896293f8aaa0861a592d650dab
4
+ data.tar.gz: 93c814b9d849ad90d3a7761cf6d4c9bd2713293fb7de7bb48b5b2f28b3c8b34d
5
5
  SHA512:
6
- metadata.gz: e59af3ae609bd5d28aafaaf9af6d7d50acb365e625986b8983277fe71d0615afb95552f32b24d27c586c15417c4e1e376db1353968d116b8dedf7c919b0e8286
7
- data.tar.gz: 6e3652aa2c16b3406afb0c8ab4cb47d2f259ad5b2c15e4c368c50d6df6214e60c79e3c11ca4d592f54e4b5332dd30fe3d8f3876f9ff4fee34ecc961a9548f7b5
6
+ metadata.gz: b0ece167920bd1069f74879b53a1844948808613e6865ecc3984861c9d6c6fe89bb9d2b98e60cb545523c488c8d5c439f8f5ff7a3b589a54222225272c3837f7
7
+ data.tar.gz: 885452bfa693632fae6fedb2970ec85575e7633fe2f98c62f06195f524f3fb4d27333b7eb399abfeb33455b5e6a4a390393a8163e526d5534f2528544048de68
checksums.yaml.gz.sig CHANGED
Binary file
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Utopia
7
7
  module Project
8
- VERSION = "0.38.0"
8
+ VERSION = "0.39.0"
9
9
  end
10
10
  end
data/pages/_page.xnode CHANGED
@@ -16,24 +16,7 @@
16
16
  <link rel="stylesheet" href="/_static/site.css" type="text/css" media="screen" />
17
17
 
18
18
  #{Utopia::Project::IMPORT_MAP.relative_to(request.env["REQUEST_PATH"]).to_html}
19
-
20
- <script src="/_components/jquery/jquery.min.js"></script>
21
-
22
- <script src="/_static/links.js"></script>
23
-
24
- <script type="module">
25
- // <![CDATA[
26
- import {Syntax} from '@socketry/syntax';
27
- document.addEventListener('DOMContentLoaded', async function() {
28
- await Syntax.highlight();
29
- });
30
-
31
- import mermaid from 'mermaid';
32
- const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
33
- const theme = isDarkMode ? 'dark' : 'default';
34
- mermaid.initialize({startOnLoad: true, theme: theme});
35
- // ]]>
36
- </script>
19
+ <script type="module" src="/_static/application.js"></script>
37
20
  </head>
38
21
  <body>
39
22
  <content:header />
@@ -28,5 +28,4 @@
28
28
  end
29
29
  ?>
30
30
  </div>
31
- <script src="/_static/sidebar.js"></script>
32
31
  </content:page>
@@ -7,7 +7,6 @@
7
7
  <div class="content">
8
8
  #{Markup.raw document.to_html}
9
9
  </div>
10
- <script src="/_static/sidebar.js"></script>
11
10
  </content:page>
12
11
  <?r else ?>
13
12
  <content:page>
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Application Initialization
3
+ * Main entry point for client-side functionality
4
+ */
5
+
6
+ // Import dependencies:
7
+ import {Syntax} from '@socketry/syntax';
8
+ import mermaid from 'mermaid';
9
+ import {initializeSectionHeadingLinks} from './links.js';
10
+ import {SidebarNavigation} from './sidebar.js';
11
+
12
+ // Initialize Mermaid with theme detection:
13
+ const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
14
+ const theme = isDarkMode ? 'dark' : 'default';
15
+ mermaid.initialize({startOnLoad: true, theme: theme});
16
+
17
+ // Initialize section self-links:
18
+ initializeSectionHeadingLinks();
19
+
20
+ // Initialize sidebar navigation:
21
+ SidebarNavigation.initialize();
22
+
23
+ // Initialize syntax highlighting:
24
+ await Syntax.highlight();
@@ -1,21 +1,23 @@
1
- jQuery(function() {
2
- $.each($('section[id]'), function(index, element) {
3
- let anchor = document.createElement('a');
4
-
5
- anchor.appendChild(
6
- document.createTextNode("¶")
7
- );
1
+ /**
2
+ * Section Heading Links
3
+ * Adds pilcrow () self-links to section headings for easy linking
4
+ */
5
+
6
+ export function initializeSectionHeadingLinks() {
7
+ const sections = document.querySelectorAll('section[id]');
8
+
9
+ sections.forEach(element => {
10
+ const anchor = document.createElement('a');
8
11
 
12
+ anchor.appendChild(document.createTextNode("¶"));
9
13
  anchor.href = "#" + element.id;
10
14
  anchor.className = "self";
11
15
 
12
- let heading = element.firstChild;
13
- anchor.title = heading.innerText;
14
-
15
- heading.appendChild(
16
- document.createTextNode(' ')
17
- );
18
-
19
- heading.appendChild(anchor);
16
+ const heading = element.firstChild;
17
+ if (heading) {
18
+ anchor.title = heading.innerText;
19
+ heading.appendChild(document.createTextNode(' '));
20
+ heading.appendChild(anchor);
21
+ }
20
22
  });
21
- });
23
+ }
@@ -3,77 +3,116 @@
3
3
  * Progressive enhancement for sidebar navigation with scroll tracking
4
4
  */
5
5
 
6
- (function() {
7
- 'use strict';
8
-
9
- // Only run if we have a sidebar navigation
10
- const sidebarNav = document.querySelector('.sidebar nav');
11
- if (!sidebarNav) return;
12
-
13
- const navLinks = sidebarNav.querySelectorAll('a[href*="#"]');
14
-
15
- // Build a map of sidebar links by their fragment IDs
16
- const sidebarLinksByFragment = new Map();
17
- navLinks.forEach(link => {
18
- const href = link.getAttribute('href');
19
- const fragmentIndex = href.indexOf('#');
20
- if (fragmentIndex !== -1) {
21
- const fragment = href.substring(fragmentIndex + 1);
22
- sidebarLinksByFragment.set(fragment, link);
23
- }
24
- });
6
+ class SidebarNavigation {
7
+ static extractFragment(href) {
8
+ const index = href.indexOf('#');
9
+ return index !== -1 ? href.substring(index + 1) : null;
10
+ }
25
11
 
26
- if (sidebarLinksByFragment.size === 0) return;
12
+ constructor(sidebarNav, sidebarLinksByFragment, allSections, sections, navLinks, sectionToSidebarLinkMap) {
13
+ this.sidebarNav = sidebarNav;
14
+ this.navLinks = navLinks;
15
+ this.currentActive = null;
16
+ this.sidebarLinksByFragment = sidebarLinksByFragment;
17
+ this.allSections = allSections;
18
+ this.sections = sections;
19
+ this.sectionToSidebarLinkMap = sectionToSidebarLinkMap;
20
+
21
+ // Store references for cleanup
22
+ this.scrollTimer = null;
23
+ this.scrollHandler = null;
24
+ this.resizeHandler = null;
25
+ this.clickHandlers = new Map();
26
+
27
+ // Initialize
28
+ this.setupEventListeners();
29
+
30
+ // Initial update without changing page state (preserves URL fragments)
31
+ this.updateActiveLink(false);
32
+ }
27
33
 
28
- // Get all sections/headings on the page and annotate them with their sidebar link
29
- const allSections = Array.from(document.querySelectorAll('section, h1, h2, h3, h4, h5, h6'))
30
- .filter(el => el.id) // Only keep elements with IDs
31
- .map(el => {
32
- // Get the section element (section or heading's parent)
33
- const sectionElement = el.tagName === 'SECTION' ? el : (el.closest('section') || el.parentElement);
34
- return { element: sectionElement, id: el.id };
34
+ setupEventListeners() {
35
+ // Throttled scroll handler
36
+ this.scrollHandler = () => {
37
+ if (this.scrollTimer) return;
38
+
39
+ this.scrollTimer = setTimeout(() => {
40
+ this.updateActiveLink();
41
+ this.scrollTimer = null;
42
+ }, 100);
43
+ };
44
+
45
+ this.resizeHandler = () => this.updateActiveLink();
46
+
47
+ // Set up event listeners
48
+ window.addEventListener('scroll', this.scrollHandler, { passive: true });
49
+ window.addEventListener('resize', this.resizeHandler, { passive: true });
50
+
51
+ // Smooth scroll enhancement for sidebar navigation links
52
+ this.navLinks.forEach(link => {
53
+ const clickHandler = (event) => {
54
+ const href = link.getAttribute('href');
55
+ const fragment = SidebarNavigation.extractFragment(href);
56
+
57
+ if (!fragment) return;
58
+
59
+ const target = document.getElementById(fragment);
60
+
61
+ if (target) {
62
+ event.preventDefault();
63
+
64
+ // Update URL to trigger :target and let browser handle scrolling
65
+ window.location.hash = fragment;
66
+
67
+ link.focus();
68
+ }
69
+ };
70
+
71
+ this.clickHandlers.set(link, clickHandler);
72
+ link.addEventListener('click', clickHandler);
35
73
  });
74
+ }
36
75
 
37
- // Annotate each section with which sidebar link should be active
38
- // Walk through in DOM order and track the "last seen" sidebar link
39
- let lastSeenSidebarId = null;
40
- allSections.forEach(({element, id}) => {
41
- if (sidebarLinksByFragment.has(id)) {
42
- // This section has a sidebar link - use it
43
- lastSeenSidebarId = id;
44
- }
45
- // Annotate the section element with the sidebar link to activate
46
- if (lastSeenSidebarId) {
47
- element.dataset.sidebarLink = lastSeenSidebarId;
76
+ destroy() {
77
+ // Clear any pending timer
78
+ if (this.scrollTimer) {
79
+ clearTimeout(this.scrollTimer);
80
+ this.scrollTimer = null;
48
81
  }
49
- });
50
-
51
- // Build sections array with link references for active state tracking
52
- const sections = Array.from(sidebarLinksByFragment.entries()).map(([id, link]) => {
53
- let sectionElement = document.getElementById(id);
54
82
 
55
- if (!sectionElement && id !== CSS.escape(id)) {
56
- sectionElement = document.querySelector(`#${CSS.escape(id)}`);
83
+ // Remove window event listeners
84
+ if (this.scrollHandler) {
85
+ window.removeEventListener('scroll', this.scrollHandler);
86
+ this.scrollHandler = null;
57
87
  }
58
88
 
59
- if (sectionElement && sectionElement.tagName.match(/^H[1-6]$/)) {
60
- sectionElement = sectionElement.closest('section') || sectionElement.parentElement;
89
+ if (this.resizeHandler) {
90
+ window.removeEventListener('resize', this.resizeHandler);
91
+ this.resizeHandler = null;
61
92
  }
62
93
 
63
- return sectionElement ? { link, sectionElement, id } : null;
64
- }).filter(Boolean);
65
-
66
- if (sections.length === 0) return;
67
-
68
- let currentActive = null;
94
+ // Remove click handlers from all links
95
+ this.clickHandlers.forEach((handler, link) => {
96
+ link.removeEventListener('click', handler);
97
+ });
98
+ this.clickHandlers.clear();
99
+
100
+ // Clear the section-to-sidebar-link mapping
101
+ this.sectionToSidebarLinkMap.clear();
102
+
103
+ // Remove active class from current link
104
+ if (this.currentActive) {
105
+ this.currentActive.link.classList.remove('active');
106
+ this.currentActive = null;
107
+ }
108
+ }
69
109
 
70
- function updateActiveLink(updatePageState = true) {
71
- let activeSectionData = null;
110
+ findCurrentSection() {
72
111
  let smallestValidBottom = Infinity;
73
112
  let currentSectionElement = null;
74
113
 
75
114
  // Find which section the user is currently viewing
76
- allSections.forEach(({element}) => {
115
+ this.allSections.forEach(({element}) => {
77
116
  const rect = element.getBoundingClientRect();
78
117
  const sectionBottom = rect.bottom;
79
118
 
@@ -87,54 +126,68 @@
87
126
  }
88
127
  });
89
128
 
90
- // Look up which sidebar link should be active using the data attribute
91
- if (currentSectionElement && currentSectionElement.dataset.sidebarLink) {
92
- const sidebarLinkId = currentSectionElement.dataset.sidebarLink;
93
- activeSectionData = sections.find(s => s.id === sidebarLinkId);
129
+ // Look up which sidebar link should be active using the map
130
+ if (currentSectionElement) {
131
+ const sidebarLinkId = this.sectionToSidebarLinkMap.get(currentSectionElement);
132
+ if (sidebarLinkId) {
133
+ return this.sections.find(s => s.id === sidebarLinkId);
134
+ }
94
135
  }
95
136
 
96
- // If still no section found, fall back to the last section
97
- if (!activeSectionData && sections.length > 0) {
98
- activeSectionData = sections[sections.length - 1];
137
+ // If no section found, fall back to the last section
138
+ return this.sections.length > 0 ? this.sections[this.sections.length - 1] : null;
139
+ }
140
+
141
+ setActiveSection(activeSectionData) {
142
+ // Remove previous active
143
+ if (this.currentActive) {
144
+ this.currentActive.link.classList.remove('active');
99
145
  }
100
146
 
101
- // Update active link
102
- if (activeSectionData !== currentActive) {
103
- // Remove previous active
104
- if (currentActive) {
105
- currentActive.link.classList.remove('active');
147
+ // Set new active
148
+ if (activeSectionData) {
149
+ activeSectionData.link.classList.add('active');
150
+ this.currentActive = activeSectionData;
151
+ } else {
152
+ this.currentActive = null;
153
+ }
154
+ }
155
+
156
+ updateUrlFragment(sectionId) {
157
+ if (sectionId) {
158
+ const newFragment = '#' + sectionId;
159
+ if (window.location.hash !== newFragment) {
160
+ history.replaceState(null, null, newFragment);
161
+ }
162
+ } else {
163
+ // Clear fragment if no active section
164
+ if (window.location.hash) {
165
+ history.replaceState(null, null, window.location.pathname);
106
166
  }
167
+ }
168
+ }
169
+
170
+ updateActiveLink(updatePageState = true) {
171
+ const activeSectionData = this.findCurrentSection();
172
+
173
+ // Only update if section changed
174
+ if (activeSectionData !== this.currentActive) {
175
+ this.setActiveSection(activeSectionData);
107
176
 
108
- // Set new active
109
- if (activeSectionData) {
110
- activeSectionData.link.classList.add('active');
111
- currentActive = activeSectionData;
112
-
113
- if (updatePageState) {
114
- // Update URL fragment to reflect current section
115
- const newFragment = '#' + activeSectionData.id;
116
- if (window.location.hash !== newFragment) {
117
- history.replaceState(null, null, newFragment);
118
- }
119
-
120
- // Auto-scroll sidebar to keep active item visible
121
- scrollToActiveItem(activeSectionData.link);
122
- }
123
- } else {
124
- currentActive = null;
125
-
126
- if (updatePageState) {
127
- // Clear fragment if no active section
128
- if (window.location.hash) {
129
- history.replaceState(null, null, window.location.pathname);
130
- }
177
+ if (updatePageState) {
178
+ if (activeSectionData) {
179
+ this.updateUrlFragment(activeSectionData.id);
180
+ this.scrollToActiveItem(activeSectionData.link);
181
+ } else {
182
+ this.updateUrlFragment(null);
131
183
  }
132
184
  }
133
185
  }
134
186
  }
135
187
 
136
- function scrollToActiveItem(activeLink) {
137
- const sidebar = activeLink.closest('.sidebar');
188
+ scrollToActiveItem(activeLink) {
189
+ // Use the sidebar nav container we already have
190
+ const sidebar = this.sidebarNav.closest('.sidebar');
138
191
  if (!sidebar) return;
139
192
 
140
193
  const sidebarRect = sidebar.getBoundingClientRect();
@@ -159,50 +212,69 @@
159
212
  }
160
213
  }
161
214
 
162
- // Throttled scroll handler
163
- let scrollTimer = null;
164
-
165
- function onScroll() {
166
- if (scrollTimer) return;
215
+ // Static method to initialize with default selector
216
+ static initialize(selector = '.sidebar nav') {
217
+ const sidebarNav = document.querySelector(selector);
218
+ if (!sidebarNav) return null;
167
219
 
168
- scrollTimer = setTimeout(() => {
169
- updateActiveLink();
170
- scrollTimer = null;
171
- }, 100);
172
- }
173
-
174
- // Initialize and set up event listeners
175
- window.addEventListener('scroll', onScroll, { passive: true });
176
- window.addEventListener('resize', updateActiveLink, { passive: true });
177
-
178
- // Initial update without changing page state (preserves URL fragments):
179
- updateActiveLink(false);
180
-
181
- // Smooth scroll enhancement for sidebar navigation links
182
- navLinks.forEach(link => {
183
- link.addEventListener('click', (event) => {
220
+ const navLinks = sidebarNav.querySelectorAll('a[href*="#"]');
221
+
222
+ // Build a map of sidebar links by their fragment IDs
223
+ const sidebarLinksByFragment = new Map();
224
+ navLinks.forEach(link => {
184
225
  const href = link.getAttribute('href');
185
- // Extract fragment from both "#section" and "page.html#section" formats
186
- const fragmentIndex = href.indexOf('#');
187
- if (fragmentIndex === -1) return;
188
- const fragment = href.substring(fragmentIndex + 1);
226
+ const fragment = SidebarNavigation.extractFragment(href);
189
227
 
190
- // Try to find the target using the fragment
191
- let target = document.getElementById(fragment);
192
-
193
- // If not found, try with CSS.escape for special characters
194
- if (!target && fragment !== CSS.escape(fragment)) {
195
- target = document.querySelector(`#${CSS.escape(fragment)}`);
228
+ if (fragment) {
229
+ sidebarLinksByFragment.set(fragment, link);
230
+ }
231
+ });
232
+
233
+ // Early exit if no sidebar links with fragments
234
+ if (sidebarLinksByFragment.size === 0) return null;
235
+
236
+ // Get all sections/headings on the page and annotate them with their sidebar link
237
+ const allSections = Array.from(document.querySelectorAll('section, h1, h2, h3, h4, h5, h6'))
238
+ .filter(el => el.id) // Only keep elements with IDs
239
+ .map(el => {
240
+ // Get the section element (section or heading's parent)
241
+ const sectionElement = el.tagName === 'SECTION' ? el : (el.closest('section') || el.parentElement);
242
+ return { element: sectionElement, id: el.id };
243
+ });
244
+
245
+ // Annotate each section with which sidebar link should be active
246
+ // Walk through in DOM order and track the "last seen" sidebar link
247
+ // Store mapping in a Map instead of mutating DOM with data attributes
248
+ const sectionToSidebarLinkMap = new Map();
249
+ let lastSeenSidebarId = null;
250
+ allSections.forEach(({element, id}) => {
251
+ if (sidebarLinksByFragment.has(id)) {
252
+ // This section has a sidebar link - use it
253
+ lastSeenSidebarId = id;
254
+ }
255
+ // Map the section element to the sidebar link to activate
256
+ if (lastSeenSidebarId) {
257
+ sectionToSidebarLinkMap.set(element, lastSeenSidebarId);
196
258
  }
259
+ });
260
+
261
+ // Build sections array with link references for active state tracking
262
+ const sections = Array.from(sidebarLinksByFragment.entries()).map(([id, link]) => {
263
+ let sectionElement = document.getElementById(id);
197
264
 
198
- if (target) {
199
- event.preventDefault();
200
-
201
- // Update URL to trigger :target and let browser handle scrolling
202
- window.location.hash = fragment;
265
+ if (sectionElement && sectionElement.tagName.match(/^H[1-6]$/)) {
266
+ sectionElement = sectionElement.closest('section') || sectionElement.parentElement;
203
267
  }
268
+
269
+ return sectionElement ? { link, sectionElement, id } : null;
270
+ }).filter(Boolean);
271
+
272
+ // Early exit if no valid sections found
273
+ if (sections.length === 0) return null;
274
+
275
+ // All checks passed - create the instance
276
+ return new SidebarNavigation(sidebarNav, sidebarLinksByFragment, allSections, sections, navLinks, sectionToSidebarLinkMap);
277
+ }
278
+ }
204
279
 
205
- link.focus();
206
- });
207
- });
208
- })();
280
+ export { SidebarNavigation };
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utopia-project
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.38.0
4
+ version: 0.39.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -267,79 +267,6 @@ files:
267
267
  - public/_components/@socketry/syntax/themes/base/xrb.css
268
268
  - public/_components/@socketry/syntax/themes/base/yaml.css
269
269
  - public/_components/@socketry/syntax/themes/theming.md
270
- - public/_components/jquery-litebox/jquery.litebox.css
271
- - public/_components/jquery-litebox/jquery.litebox.gallery.css
272
- - public/_components/jquery-litebox/jquery.litebox.js
273
- - public/_components/jquery-syntax/base/jquery.syntax.brush.apache.css
274
- - public/_components/jquery-syntax/base/jquery.syntax.brush.applescript.css
275
- - public/_components/jquery-syntax/base/jquery.syntax.brush.assembly.css
276
- - public/_components/jquery-syntax/base/jquery.syntax.brush.bash-script.css
277
- - public/_components/jquery-syntax/base/jquery.syntax.brush.bash.css
278
- - public/_components/jquery-syntax/base/jquery.syntax.brush.clang.css
279
- - public/_components/jquery-syntax/base/jquery.syntax.brush.css.css
280
- - public/_components/jquery-syntax/base/jquery.syntax.brush.diff.css
281
- - public/_components/jquery-syntax/base/jquery.syntax.brush.html.css
282
- - public/_components/jquery-syntax/base/jquery.syntax.brush.ocaml.css
283
- - public/_components/jquery-syntax/base/jquery.syntax.brush.protobuf.css
284
- - public/_components/jquery-syntax/base/jquery.syntax.brush.python.css
285
- - public/_components/jquery-syntax/base/jquery.syntax.brush.ruby.css
286
- - public/_components/jquery-syntax/base/jquery.syntax.brush.xml.css
287
- - public/_components/jquery-syntax/base/jquery.syntax.core.css
288
- - public/_components/jquery-syntax/base/jquery.syntax.editor.css
289
- - public/_components/jquery-syntax/base/theme.js
290
- - public/_components/jquery-syntax/bright/jquery.syntax.core.css
291
- - public/_components/jquery-syntax/bright/theme.js
292
- - public/_components/jquery-syntax/jquery.syntax.brush.apache.js
293
- - public/_components/jquery-syntax/jquery.syntax.brush.applescript.js
294
- - public/_components/jquery-syntax/jquery.syntax.brush.assembly.js
295
- - public/_components/jquery-syntax/jquery.syntax.brush.bash-script.js
296
- - public/_components/jquery-syntax/jquery.syntax.brush.bash.js
297
- - public/_components/jquery-syntax/jquery.syntax.brush.basic.js
298
- - public/_components/jquery-syntax/jquery.syntax.brush.clang.js
299
- - public/_components/jquery-syntax/jquery.syntax.brush.csharp.js
300
- - public/_components/jquery-syntax/jquery.syntax.brush.css.js
301
- - public/_components/jquery-syntax/jquery.syntax.brush.diff.js
302
- - public/_components/jquery-syntax/jquery.syntax.brush.go.js
303
- - public/_components/jquery-syntax/jquery.syntax.brush.haskell.js
304
- - public/_components/jquery-syntax/jquery.syntax.brush.html.js
305
- - public/_components/jquery-syntax/jquery.syntax.brush.io.js
306
- - public/_components/jquery-syntax/jquery.syntax.brush.java.js
307
- - public/_components/jquery-syntax/jquery.syntax.brush.javascript.js
308
- - public/_components/jquery-syntax/jquery.syntax.brush.kai.js
309
- - public/_components/jquery-syntax/jquery.syntax.brush.lisp.js
310
- - public/_components/jquery-syntax/jquery.syntax.brush.lua.js
311
- - public/_components/jquery-syntax/jquery.syntax.brush.nginx.js
312
- - public/_components/jquery-syntax/jquery.syntax.brush.ocaml.js
313
- - public/_components/jquery-syntax/jquery.syntax.brush.ooc.js
314
- - public/_components/jquery-syntax/jquery.syntax.brush.pascal.js
315
- - public/_components/jquery-syntax/jquery.syntax.brush.perl5.js
316
- - public/_components/jquery-syntax/jquery.syntax.brush.php-script.js
317
- - public/_components/jquery-syntax/jquery.syntax.brush.php.js
318
- - public/_components/jquery-syntax/jquery.syntax.brush.plain.js
319
- - public/_components/jquery-syntax/jquery.syntax.brush.protobuf.js
320
- - public/_components/jquery-syntax/jquery.syntax.brush.python.js
321
- - public/_components/jquery-syntax/jquery.syntax.brush.ruby.js
322
- - public/_components/jquery-syntax/jquery.syntax.brush.scala.js
323
- - public/_components/jquery-syntax/jquery.syntax.brush.smalltalk.js
324
- - public/_components/jquery-syntax/jquery.syntax.brush.sql.js
325
- - public/_components/jquery-syntax/jquery.syntax.brush.super-collider.js
326
- - public/_components/jquery-syntax/jquery.syntax.brush.swift.js
327
- - public/_components/jquery-syntax/jquery.syntax.brush.xml.js
328
- - public/_components/jquery-syntax/jquery.syntax.brush.xrb.js
329
- - public/_components/jquery-syntax/jquery.syntax.brush.yaml.js
330
- - public/_components/jquery-syntax/jquery.syntax.cache.js
331
- - public/_components/jquery-syntax/jquery.syntax.core.js
332
- - public/_components/jquery-syntax/jquery.syntax.editor.js
333
- - public/_components/jquery-syntax/jquery.syntax.js
334
- - public/_components/jquery-syntax/jquery.syntax.min.js
335
- - public/_components/jquery-syntax/paper/jquery.syntax.core.css
336
- - public/_components/jquery-syntax/paper/theme.js
337
- - public/_components/jquery/jquery.js
338
- - public/_components/jquery/jquery.min.js
339
- - public/_components/jquery/jquery.min.map
340
- - public/_components/jquery/jquery.slim.js
341
- - public/_components/jquery/jquery.slim.min.js
342
- - public/_components/jquery/jquery.slim.min.map
343
270
  - public/_components/mermaid/chunks/mermaid.core/architectureDiagram-VXUJARFQ.mjs
344
271
  - public/_components/mermaid/chunks/mermaid.core/architectureDiagram-VXUJARFQ.mjs.map
345
272
  - public/_components/mermaid/chunks/mermaid.core/blockDiagram-VD42YOAC.mjs
@@ -738,6 +665,7 @@ files:
738
665
  - public/_components/mermaid/mermaid.js.map
739
666
  - public/_components/mermaid/mermaid.min.js
740
667
  - public/_components/mermaid/mermaid.min.js.map
668
+ - public/_static/application.js
741
669
  - public/_static/icon.png
742
670
  - public/_static/links.js
743
671
  - public/_static/sidebar.js
metadata.gz.sig CHANGED
Binary file