index.html 27 KB

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