index.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. {% extends "base.html" %}
  2. {% block additional_styles %}
  3. .pattern-card {
  4. transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
  5. cursor: pointer;
  6. }
  7. .pattern-card:hover {
  8. transform: translateY(-4px);
  9. box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
  10. 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  11. }
  12. .pattern-card.selected {
  13. border: 2px solid #0c7ff2;
  14. }
  15. /* Pattern grid - responsive columns */
  16. #patternGrid {
  17. grid-template-columns: repeat(3, 1fr);
  18. justify-content: center;
  19. }
  20. @media (min-width: 480px) {
  21. #patternGrid {
  22. grid-template-columns: repeat(auto-fill, minmax(100px, 128px));
  23. }
  24. }
  25. @media (min-width: 1024px) {
  26. .preview-open .layout-content-container {
  27. margin-right: 28rem;
  28. }
  29. #patternPreviewPanel {
  30. transform: translateX(0);
  31. }
  32. }
  33. .delete-button-disabled {
  34. opacity: 0.5;
  35. cursor: not-allowed;
  36. pointer-events: none;
  37. background-color: #f3f4f6 !important;
  38. border-color: #d1d5db !important;
  39. color: #9ca3af !important;
  40. }
  41. /* Pattern preview styles */
  42. .pattern-preview {
  43. overflow: hidden;
  44. aspect-ratio: 1;
  45. display: flex;
  46. align-items: center;
  47. justify-content: center;
  48. border: 1px solid #e5e7eb;
  49. }
  50. .pattern-preview img {
  51. width: 100%;
  52. height: 100%;
  53. object-fit: contain;
  54. }
  55. /* Pattern preview panel styles */
  56. #patternPreviewPanel .bg-slate-200 {
  57. background-color: #f3f4f6;
  58. border: 1px solid #e5e7eb;
  59. border-radius: 9999px;
  60. overflow: hidden;
  61. }
  62. #patternPreviewPanel img {
  63. width: 100%;
  64. height: 100%;
  65. object-fit: contain;
  66. }
  67. /* Dark mode styles for index page */
  68. .dark .pattern-card {
  69. background-color: #262626;
  70. border-color: #404040;
  71. }
  72. .dark .pattern-card:hover {
  73. box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3),
  74. 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  75. }
  76. .dark .pattern-card.selected {
  77. border-color: #0c7ff2;
  78. }
  79. .dark .delete-button-disabled {
  80. background-color: #262626 !important;
  81. border-color: #404040 !important;
  82. color: #6b7280 !important;
  83. }
  84. .dark #patternPreviewPanel {
  85. background-color: #262626;
  86. }
  87. .dark #patternPreviewPanel header {
  88. border-color: #404040;
  89. }
  90. .dark #patternPreviewPanel h2 {
  91. color: #e5e5e5;
  92. }
  93. .dark #patternPreviewPanel .text-slate-500 {
  94. color: #9ca3af;
  95. }
  96. .dark #patternPreviewPanel .text-slate-700 {
  97. color: #d1d5db;
  98. }
  99. .dark #patternPreviewPanel .border-slate-300 {
  100. border-color: #404040;
  101. }
  102. .dark #patternPreviewPanel .bg-slate-200 {
  103. background-color: #262626;
  104. border-color: #404040;
  105. }
  106. .dark #patternPreviewPanel .hover\:bg-slate-100:hover {
  107. background-color: #404040;
  108. }
  109. .dark #patternPreviewPanel .hover\:text-slate-700:hover {
  110. color: #e5e5e5;
  111. }
  112. .dark .form-input {
  113. background-color: #262626;
  114. border-color: #404040;
  115. color: #e5e5e5;
  116. }
  117. .dark .form-input::placeholder {
  118. color: #9ca3af;
  119. }
  120. .dark .form-input:focus {
  121. border-color: #0c7ff2;
  122. ring-color: #0c7ff2;
  123. }
  124. .dark .bg-gray-50 {
  125. background-color: #1a1a1a;
  126. }
  127. .dark .bg-white {
  128. background-color: #262626;
  129. }
  130. .dark .text-gray-900 {
  131. color: #e5e5e5;
  132. }
  133. .dark .text-gray-500 {
  134. color: #9ca3af;
  135. }
  136. .dark .text-gray-400 {
  137. color: #9ca3af;
  138. }
  139. .dark .border-gray-300 {
  140. border-color: #404040;
  141. }
  142. .dark .hover\:bg-red-50:hover {
  143. background-color: #2d1a1a;
  144. }
  145. .dark .focus\:ring-offset-2 {
  146. --tw-ring-offset-color: #262626;
  147. }
  148. .dark .text-\[\#111518\] {
  149. color: #e5e5e5;
  150. }
  151. .dark .border-b-\[\#f0f2f5\] {
  152. border-color: #404040;
  153. }
  154. .dark .hover\:bg-slate-100:hover {
  155. background-color: #404040;
  156. }
  157. .dark .hover\:text-slate-700:hover {
  158. color: #e5e5e5;
  159. }
  160. .dark .has-\[\:checked\]\:bg-\[\#0b80ee\]:has(:checked) {
  161. background-color: #0c7ff2;
  162. }
  163. .dark .has-\[\:checked\]\:border-\[\#0b80ee\]:has(:checked) {
  164. border-color: #0c7ff2;
  165. }
  166. .dark .has-\[\:checked\]\:ring-\[\#0b80ee\]:has(:checked) {
  167. --tw-ring-color: #0c7ff2;
  168. }
  169. .dark .has-\[\:checked\]\:ring-offset-2:has(:checked) {
  170. --tw-ring-offset-color: #262626;
  171. }
  172. /* Dark mode pattern preview styles */
  173. .dark .pattern-preview {
  174. border-color: #404040;
  175. }
  176. .dark .pattern-preview img {
  177. filter: invert(1);
  178. }
  179. .dark #patternPreviewPanel img {
  180. filter: invert(1);
  181. }
  182. .dark .pattern-card img {
  183. filter: invert(1);
  184. background-color:rgb(229, 229, 229);
  185. }
  186. {% endblock %}
  187. {% block content %}
  188. <div class="layout-content-container flex flex-col w-full max-w-5xl mb-24">
  189. <div id="browseHeader" class="flex-none bg-gray-50 py-4">
  190. <div class="mt-2 sm:mt-8 lg:mt-2">
  191. <!-- Header Row -->
  192. <div class="flex items-center justify-between gap-2 mb-4">
  193. <h2 class="text-gray-900 text-3xl font-bold leading-tight tracking-tight">
  194. Browse Patterns
  195. </h2>
  196. <button
  197. id="cacheAllButton"
  198. class="inline-flex gap-1 sm:gap-2 transition-colors items-center justify-center rounded-lg px-3 sm:px-4 py-2 sm:py-2.5 text-xs sm:text-sm font-semibold text-gray-900 hover:text-slate-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 shrink-0"
  199. >
  200. <span class="material-icons text-sm pr-1 sm:pr-2">cached</span>
  201. <span class="hidden sm:inline">Cache All Previews</span>
  202. <span class="sm:hidden">Cache</span>
  203. </button>
  204. </div>
  205. <!-- Controls Row -->
  206. <div class="flex gap-1 sm:gap-2 items-center text-xs sm:text-sm min-w-0 overflow-x-auto mb-4">
  207. <div class="flex items-center gap-1">
  208. <span class="text-xs font-medium text-gray-700 hidden sm:inline">Sort:</span>
  209. <select id="browseSortFieldSelect" class="text-xs rounded border border-gray-300 bg-white text-gray-900 px-1 sm:px-2 py-1 min-w-0 flex-shrink" disabled>
  210. <option value="name">Name</option>
  211. <option value="date">Date Modified</option>
  212. <option value="coordinates">Coordinates</option>
  213. <option value="favorite">Favorite</option>
  214. </select>
  215. <button id="browseSortDirectionBtn" class="p-1 rounded hover:bg-gray-200 text-gray-500 opacity-50 cursor-not-allowed" title="Loading..." disabled>
  216. <span class="material-icons text-sm" id="browseSortDirectionIcon">arrow_upward</span>
  217. </button>
  218. </div>
  219. <div class="flex items-center gap-1 min-w-0">
  220. <span class="text-xs font-medium text-gray-700 hidden sm:inline">Folder:</span>
  221. <select id="browseCategoryFilterSelect" class="text-xs rounded border border-gray-300 bg-white text-gray-900 px-1 sm:px-2 py-1 min-w-0 flex-shrink" disabled>
  222. <option value="all">All Folders (loading...)</option>
  223. </select>
  224. </div>
  225. </div>
  226. </div>
  227. <div class="relative w-full sm:w-auto flex grow gap-2 items-center flex-wrap">
  228. <div class="flex gap-2 flex-1">
  229. <div class="relative flex-1">
  230. <input
  231. id="patternSearch"
  232. class="form-input block w-full h-11 rounded-lg border-gray-300 bg-gray-50 py-2.5 p-4 text-gray-900 placeholder-gray-500 focus:border-blue-500 focus:ring-1 focus:ring-blue-500 sm:text-sm"
  233. placeholder="Search patterns..."
  234. type="search"
  235. />
  236. <button
  237. id="searchButton"
  238. class="inline-flex absolute top-0 right-0 h-11 w-11 items-center justify-center rounded-lg bg-blue-600 p-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
  239. >
  240. <span class="material-icons text-sm font-semibold text-white">search</span>
  241. </button>
  242. </div>
  243. </div>
  244. <!-- Add Pattern Button -->
  245. <input
  246. type="file"
  247. id="patternFileInput"
  248. accept=".thr"
  249. multiple
  250. class="hidden"
  251. />
  252. <button
  253. aria-label="Add new pattern"
  254. class="inline-flex items-center justify-center rounded-lg h-11 w-11 bg-blue-600 text-white shadow-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 ml-2 text-xl font-bold"
  255. onclick="document.getElementById('patternFileInput').click()"
  256. >
  257. <span class="material-icons">add</span>
  258. </button>
  259. </div>
  260. </div>
  261. <section class="px-4 py-6">
  262. <div id="patternGrid" class="grid gap-2 sm:gap-4 md:gap-6">
  263. <!-- All patterns will be populated here -->
  264. </div>
  265. <!-- Spacer to allow scrolling past last patterns -->
  266. <div style="height: 200px; background: transparent;"></div>
  267. </section>
  268. </div>
  269. <!-- Pattern Preview Panel -->
  270. <div id="patternPreviewPanel"
  271. class="fixed top-0 bottom-0 right-0 w-full max-w-md transform translate-x-full transition-transform duration-300 ease-in-out z-40 lg:translate-x-0 lg:opacity-0 lg:pointer-events-none">
  272. <div class="h-full bg-white shadow-xl">
  273. <header class="flex items-center justify-between border-b border-solid border-b-[#f0f2f5] px-6 py-3 sm:py-4">
  274. <div class="flex items-center gap-3 text-[#111518]">
  275. <h2 id="patternPreviewTitle" class="text-[#111518] text-lg font-semibold leading-tight">Pattern
  276. Details</h2>
  277. </div>
  278. <button id="closePreviewPanel"
  279. class="flex cursor-pointer items-center justify-center rounded-full p-1.5 text-slate-500 hover:bg-slate-100 hover:text-slate-700 focus:outline-none focus:ring-2 focus:ring-[#0b80ee]">
  280. <span class="material-icons text-2xl">close</span>
  281. </button>
  282. </header>
  283. <div class="p-6 overflow-y-auto h-[calc(100%-4rem)]">
  284. <div class="mb-6 aspect-square w-full overflow-hidden pattern-preview rounded-full relative group">
  285. <img id="patternPreviewImage" alt="Pattern Preview" class="h-full w-full object-cover" src=""/>
  286. <!-- Play button overlay for animated preview -->
  287. <div id="previewPlayOverlay"
  288. class="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity duration-200 cursor-pointer">
  289. <div class="bg-white rounded-full p-3 shadow-lg flex items-center justify-center w-12 h-12">
  290. <span class="material-icons text-2xl text-gray-800">play_arrow</span>
  291. </div>
  292. </div>
  293. </div>
  294. <div class="mb-4 flex justify-between text-sm">
  295. <div class="flex items-center gap-2">
  296. <span class="text-slate-500">First:</span>
  297. <span id="firstCoordinate" class="font-semibold text-[#111518]">(0, 0)</span>
  298. </div>
  299. <div class="flex items-center gap-2">
  300. <span class="text-slate-500">Last:</span>
  301. <span id="lastCoordinate" class="font-semibold text-[#111518]">(0, 0)</span>
  302. </div>
  303. </div>
  304. <div class="mb-4">
  305. <h3 class="mb-2 text-sm font-semibold text-slate-700">Pre-Execution Action</h3>
  306. <div class="grid grid-cols-2 gap-2">
  307. <label class="group relative flex cursor-pointer items-center justify-center rounded-lg border border-slate-300 p-2 text-center text-sm font-medium text-slate-700 transition-all hover:border-[#0b80ee] has-[:checked]:border-[#0b80ee] has-[:checked]:bg-[#0b80ee] has-[:checked]:text-white has-[:checked]:ring-2 has-[:checked]:ring-[#0b80ee] has-[:checked]:ring-offset-2">
  308. Adaptive
  309. <input checked="" class="peer sr-only" name="preExecutionAction" type="radio" value="adaptive"/>
  310. </label>
  311. <label class="group relative flex cursor-pointer items-center justify-center rounded-lg border border-slate-300 p-2 text-center text-sm font-medium text-slate-700 transition-all hover:border-[#0b80ee] has-[:checked]:border-[#0b80ee] has-[:checked]:bg-[#0b80ee] has-[:checked]:text-white has-[:checked]:ring-2 has-[:checked]:ring-[#0b80ee] has-[:checked]:ring-offset-2">
  312. Clear From Center
  313. <input class="peer sr-only" name="preExecutionAction" type="radio" value="clear_from_in"/>
  314. </label>
  315. <label class="group relative flex cursor-pointer items-center justify-center rounded-lg border border-slate-300 p-2 text-center text-sm font-medium text-slate-700 transition-all hover:border-[#0b80ee] has-[:checked]:border-[#0b80ee] has-[:checked]:bg-[#0b80ee] has-[:checked]:text-white has-[:checked]:ring-2 has-[:checked]:ring-[#0b80ee] has-[:checked]:ring-offset-2">
  316. Clear From Perimeter
  317. <input class="peer sr-only" name="preExecutionAction" type="radio" value="clear_from_out"/>
  318. </label>
  319. <label class="group relative flex cursor-pointer items-center justify-center rounded-lg border border-slate-300 p-2 text-center text-sm font-medium text-slate-700 transition-all hover:border-[#0b80ee] has-[:checked]:border-[#0b80ee] has-[:checked]:bg-[#0b80ee] has-[:checked]:text-white has-[:checked]:ring-2 has-[:checked]:ring-[#0b80ee] has-[:checked]:ring-offset-2">
  320. Clear Sideway
  321. <input class="peer sr-only" name="preExecutionAction" type="radio" value="clear_sideway"/>
  322. </label>
  323. <label class="group relative flex cursor-pointer items-center justify-center rounded-lg border border-slate-300 p-2 text-center text-sm font-medium text-slate-700 transition-all hover:border-[#0b80ee] has-[:checked]:border-[#0b80ee] has-[:checked]:bg-[#0b80ee] has-[:checked]:text-white has-[:checked]:ring-2 has-[:checked]:ring-[#0b80ee] has-[:checked]:ring-offset-2">
  324. None
  325. <input class="peer sr-only" name="preExecutionAction" type="radio" value="none"/>
  326. </label>
  327. </div>
  328. </div>
  329. <div class="space-y-3">
  330. <button id="playPattern"
  331. class="flex w-full items-center justify-center gap-2 rounded-lg bg-[#0b80ee] px-4 py-2.5 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-opacity-90 focus:outline-none focus:ring-2 focus:ring-[#0b80ee] focus:ring-offset-2">
  332. <span class="material-icons text-lg">play_arrow</span>
  333. Play
  334. </button>
  335. <button id="deletePattern"
  336. class="flex w-full items-center justify-center gap-2 rounded-lg border border-red-500 px-4 py-2.5 text-sm font-semibold text-red-500 shadow-sm transition-colors hover:bg-red-50 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2">
  337. <span class="material-icons text-lg">delete</span>
  338. Delete
  339. </button>
  340. </div>
  341. </div>
  342. </div>
  343. </div>
  344. <!-- Animated Preview Modal -->
  345. <div id="animatedPreviewModal" class="fixed inset-0 bg-black bg-opacity-50 z-50 hidden">
  346. <div class="flex items-center justify-center min-h-screen p-4">
  347. <div class="bg-white rounded-lg shadow-xl max-w-4xl w-full max-h-[95vh] flex flex-col overflow-hidden">
  348. <!-- Modal Header -->
  349. <div class="flex items-center justify-between p-6 border-b border-gray-200 shrink-0">
  350. <h3 id="animatedPreviewTitle" class="text-xl font-semibold text-gray-900">Animated Preview</h3>
  351. <button id="closeAnimatedPreview" class="text-gray-400 hover:text-gray-600">
  352. <span class="material-icons text-2xl">close</span>
  353. </button>
  354. </div>
  355. <!-- Modal Content -->
  356. <div class="p-6 overflow-y-auto grow h-full">
  357. <!-- Canvas Container -->
  358. <div class="relative flex justify-center h-full">
  359. <canvas id="animatedPreviewCanvas"
  360. class="border border-gray-300 rounded-full dark:invert"></canvas>
  361. <!-- Play/Pause Overlay -->
  362. <div id="playPauseOverlay"
  363. class="absolute inset-0 flex items-center justify-center bg-black bg-opacity-20 opacity-0 transition-opacity duration-200 cursor-pointer rounded-full">
  364. <div class="bg-white rounded-full p-4 shadow-lg">
  365. <span id="playPauseIcon" class="material-icons text-3xl text-gray-800">play_arrow</span>
  366. </div>
  367. </div>
  368. </div>
  369. </div>
  370. <!-- Controls -->
  371. <div class="p-6 space-y-4 shrink-0">
  372. <!-- Speed Control -->
  373. <div>
  374. <label class="block text-sm font-medium text-gray-700 mb-2">Speed</label>
  375. <div class="flex items-center gap-4">
  376. <input type="range" id="speedSlider" min="0.1" max="5" step="0.1" value="1" class="flex-1">
  377. <span id="speedValue" class="text-sm font-medium text-gray-900 w-16">1x</span>
  378. </div>
  379. </div>
  380. <!-- Progress Control -->
  381. <div>
  382. <label class="block text-sm font-medium text-gray-700 mb-2">Progress</label>
  383. <div class="flex items-center gap-4">
  384. <input type="range" id="progressSlider" min="0" max="100" step="0.1" value="0"
  385. class="flex-1">
  386. <span id="progressValue" class="text-sm font-medium text-gray-900 w-20">0%</span>
  387. </div>
  388. </div>
  389. <!-- Control Buttons -->
  390. <div class="flex items-center justify-center gap-4">
  391. <button id="playPauseBtn"
  392. class="flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">
  393. <span id="playPauseBtnIcon" class="material-icons">play_arrow</span>
  394. <span id="playPauseBtnText">Play</span>
  395. </button>
  396. <button id="resetBtn"
  397. class="flex items-center gap-2 px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700">
  398. <span class="material-icons">replay</span>
  399. Reset
  400. </button>
  401. </div>
  402. </div>
  403. </div>
  404. </div>
  405. </div>
  406. {% endblock %}
  407. {% block scripts %}
  408. <script src="/static/js/index.js"></script>
  409. <script>
  410. // File upload is handled in index.js
  411. // Update delete button state when pattern is selected
  412. function updateDeleteButtonState(patternName) {
  413. const deleteButton = document.getElementById('deletePattern');
  414. if (!deleteButton) return;
  415. if (patternName && patternName.startsWith('custom_patterns/')) {
  416. deleteButton.classList.remove('delete-button-disabled');
  417. deleteButton.disabled = false;
  418. } else {
  419. deleteButton.classList.add('delete-button-disabled');
  420. deleteButton.disabled = true;
  421. }
  422. }
  423. // Override the selectPattern function to update delete button state
  424. const originalSelectPattern = window.selectPattern;
  425. window.selectPattern = function(pattern, card) {
  426. originalSelectPattern(pattern, card);
  427. updateDeleteButtonState(pattern);
  428. };
  429. // Initialize delete button state when the page loads
  430. document.addEventListener('DOMContentLoaded', function() {
  431. // Initially disable the delete button
  432. const deleteButton = document.getElementById('deletePattern');
  433. if (deleteButton) {
  434. deleteButton.classList.add('delete-button-disabled');
  435. deleteButton.disabled = true;
  436. }
  437. });
  438. // Override the loadPatterns function to update delete button state after loading
  439. const originalLoadPatterns = window.loadPatterns;
  440. window.loadPatterns = async function() {
  441. await originalLoadPatterns();
  442. // Update delete button state based on currently selected pattern
  443. const selectedPattern = document.querySelector('.pattern-card.selected');
  444. if (selectedPattern) {
  445. updateDeleteButtonState(selectedPattern.dataset.pattern);
  446. } else {
  447. updateDeleteButtonState(null);
  448. }
  449. };
  450. // Sticky search bar on desktop
  451. (function() {
  452. // Only apply on large screens (lg: 1024px+)
  453. const mediaQuery = window.matchMedia('(min-width: 1024px)');
  454. if (!mediaQuery.matches) return;
  455. // Create a compact fixed search bar
  456. const siteHeaderHeight = 56;
  457. let fixedBar = null;
  458. let isFixed = false;
  459. const triggerPoint = 150; // Scroll distance to trigger
  460. function createFixedBar() {
  461. if (fixedBar) return;
  462. fixedBar = document.createElement('div');
  463. fixedBar.id = 'fixedSearchBar';
  464. // Get actual header height
  465. const siteHeader = document.querySelector('header');
  466. const headerHeight = siteHeader ? siteHeader.offsetHeight : 64;
  467. fixedBar.style.cssText = `
  468. position: fixed;
  469. top: ${headerHeight}px;
  470. left: 0;
  471. right: 0;
  472. background: #f9fafb;
  473. border-bottom: 1px solid #e5e7eb;
  474. box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  475. z-index: 9;
  476. transform: translateY(-100%);
  477. transition: transform 0.2s ease;
  478. `;
  479. if (document.documentElement.classList.contains('dark')) {
  480. fixedBar.style.background = '#1a1a1a';
  481. fixedBar.style.borderColor = '#404040';
  482. }
  483. fixedBar.innerHTML = `
  484. <div class="max-w-5xl mx-auto px-4 py-2 flex items-center gap-3">
  485. <div class="flex items-center gap-1 shrink-0">
  486. <span class="text-xs font-medium text-gray-700 dark:text-gray-300">Sort:</span>
  487. <select id="fixedSortSelect" class="text-xs rounded border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 bg-white text-gray-900 px-2 py-1">
  488. <option value="name">Name</option>
  489. <option value="date">Date Modified</option>
  490. <option value="coordinates">Coordinates</option>
  491. <option value="favorite">Favorite</option>
  492. </select>
  493. <button id="fixedSortDirBtn" class="p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500">
  494. <span class="material-icons text-sm" id="fixedSortDirIcon">arrow_upward</span>
  495. </button>
  496. </div>
  497. <div class="relative flex-1">
  498. <input id="fixedSearchInput" class="form-input block w-full h-11 rounded-lg border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 bg-gray-50 py-2.5 p-4 text-gray-900 placeholder-gray-500 focus:border-blue-500 focus:ring-1 focus:ring-blue-500 sm:text-sm" placeholder="Search patterns..." type="search" />
  499. <button id="fixedSearchBtn" class="inline-flex absolute top-0 right-0 h-11 w-11 items-center justify-center rounded-lg bg-blue-600 p-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
  500. <span class="material-icons text-sm font-semibold text-white">search</span>
  501. </button>
  502. </div>
  503. <button id="fixedAddBtn" class="inline-flex items-center justify-center rounded-lg h-11 w-11 bg-blue-600 text-white shadow-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
  504. <span class="material-icons">add</span>
  505. </button>
  506. </div>
  507. `;
  508. document.body.appendChild(fixedBar);
  509. // Sync with main controls
  510. const mainSearch = document.getElementById('patternSearch');
  511. const fixedSearch = fixedBar.querySelector('#fixedSearchInput');
  512. const fixedSearchBtn = fixedBar.querySelector('#fixedSearchBtn');
  513. const fixedAdd = fixedBar.querySelector('#fixedAddBtn');
  514. // Search on Enter key
  515. fixedSearch.addEventListener('keypress', (e) => {
  516. if (e.key === 'Enter') {
  517. if (mainSearch) mainSearch.value = fixedSearch.value;
  518. if (typeof searchPatterns === 'function') {
  519. searchPatterns(fixedSearch.value.trim());
  520. }
  521. }
  522. });
  523. // Also sync on input for live typing
  524. fixedSearch.addEventListener('input', () => {
  525. if (mainSearch) mainSearch.value = fixedSearch.value;
  526. });
  527. // Search button click
  528. fixedSearchBtn.addEventListener('click', () => {
  529. if (mainSearch) mainSearch.value = fixedSearch.value;
  530. if (typeof searchPatterns === 'function') {
  531. searchPatterns(fixedSearch.value.trim());
  532. }
  533. });
  534. fixedAdd.addEventListener('click', () => {
  535. document.getElementById('patternFileInput')?.click();
  536. });
  537. // Sort controls sync
  538. const mainSortSelect = document.getElementById('browseSortFieldSelect');
  539. const mainSortDirBtn = document.getElementById('browseSortDirectionBtn');
  540. const mainSortDirIcon = document.getElementById('browseSortDirectionIcon');
  541. const fixedSortSelect = fixedBar.querySelector('#fixedSortSelect');
  542. const fixedSortDirBtn = fixedBar.querySelector('#fixedSortDirBtn');
  543. const fixedSortDirIcon = fixedBar.querySelector('#fixedSortDirIcon');
  544. // Sync initial values from main controls
  545. if (mainSortSelect) {
  546. fixedSortSelect.value = mainSortSelect.value;
  547. }
  548. if (mainSortDirIcon) {
  549. fixedSortDirIcon.textContent = mainSortDirIcon.textContent;
  550. }
  551. // Fixed sort select change -> sync to main and trigger sort
  552. fixedSortSelect.addEventListener('change', () => {
  553. if (mainSortSelect) {
  554. mainSortSelect.value = fixedSortSelect.value;
  555. mainSortSelect.dispatchEvent(new Event('change'));
  556. }
  557. });
  558. // Fixed sort direction button click -> sync to main and trigger sort
  559. fixedSortDirBtn.addEventListener('click', () => {
  560. if (mainSortDirBtn) {
  561. mainSortDirBtn.click();
  562. // After click, sync the icon
  563. setTimeout(() => {
  564. if (mainSortDirIcon) {
  565. fixedSortDirIcon.textContent = mainSortDirIcon.textContent;
  566. }
  567. }, 50);
  568. }
  569. });
  570. // Listen for changes on main controls to sync back to fixed
  571. if (mainSortSelect) {
  572. mainSortSelect.addEventListener('change', () => {
  573. fixedSortSelect.value = mainSortSelect.value;
  574. });
  575. }
  576. // Create observer to sync sort direction icon changes
  577. if (mainSortDirIcon) {
  578. const observer = new MutationObserver(() => {
  579. fixedSortDirIcon.textContent = mainSortDirIcon.textContent;
  580. });
  581. observer.observe(mainSortDirIcon, { childList: true, characterData: true, subtree: true });
  582. }
  583. }
  584. function handleScroll() {
  585. if (!mediaQuery.matches) return;
  586. if (window.scrollY > triggerPoint && !isFixed) {
  587. createFixedBar();
  588. requestAnimationFrame(() => {
  589. fixedBar.style.transform = 'translateY(0)';
  590. });
  591. isFixed = true;
  592. } else if (window.scrollY <= triggerPoint && isFixed) {
  593. if (fixedBar) {
  594. fixedBar.style.transform = 'translateY(-100%)';
  595. }
  596. isFixed = false;
  597. }
  598. }
  599. window.addEventListener('scroll', handleScroll, { passive: true });
  600. mediaQuery.addEventListener('change', (e) => {
  601. if (!e.matches && fixedBar) {
  602. fixedBar.remove();
  603. fixedBar = null;
  604. isFixed = false;
  605. }
  606. });
  607. })();
  608. </script>
  609. {% endblock %}