@jjlmoya/utils-chrono 1.2.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 (277) hide show
  1. package/package.json +65 -0
  2. package/scripts/postinstall.mjs +27 -0
  3. package/src/category/ChronoCategorySEO.astro +8 -0
  4. package/src/category/i18n/de.ts +23 -0
  5. package/src/category/i18n/en.ts +23 -0
  6. package/src/category/i18n/es.ts +23 -0
  7. package/src/category/i18n/fr.ts +23 -0
  8. package/src/category/i18n/id.ts +23 -0
  9. package/src/category/i18n/it.ts +23 -0
  10. package/src/category/i18n/ja.ts +23 -0
  11. package/src/category/i18n/ko.ts +23 -0
  12. package/src/category/i18n/nl.ts +23 -0
  13. package/src/category/i18n/pl.ts +23 -0
  14. package/src/category/i18n/pt.ts +23 -0
  15. package/src/category/i18n/ru.ts +23 -0
  16. package/src/category/i18n/sv.ts +23 -0
  17. package/src/category/i18n/tr.ts +23 -0
  18. package/src/category/i18n/zh.ts +23 -0
  19. package/src/category/index.ts +42 -0
  20. package/src/components/PreviewNavSidebar.astro +116 -0
  21. package/src/components/PreviewToolbar.astro +143 -0
  22. package/src/data.ts +11 -0
  23. package/src/entries.ts +32 -0
  24. package/src/env.d.ts +5 -0
  25. package/src/index.ts +28 -0
  26. package/src/layouts/PreviewLayout.astro +117 -0
  27. package/src/pages/[locale]/[slug].astro +161 -0
  28. package/src/pages/[locale].astro +251 -0
  29. package/src/pages/index.astro +4 -0
  30. package/src/tests/faq_count.test.ts +19 -0
  31. package/src/tests/i18n_coverage.test.ts +36 -0
  32. package/src/tests/locale_completeness.test.ts +29 -0
  33. package/src/tests/mocks/astro_mock.js +2 -0
  34. package/src/tests/no_h1_in_components.test.ts +48 -0
  35. package/src/tests/schemas_fulfillment.test.ts +23 -0
  36. package/src/tests/seo_length.test.ts +22 -0
  37. package/src/tests/shared-test-helpers.ts +56 -0
  38. package/src/tests/slug_language_code_format.test.ts +23 -0
  39. package/src/tests/slug_uniqueness.test.ts +81 -0
  40. package/src/tests/title_quality.test.ts +55 -0
  41. package/src/tests/tool_exports.test.ts +34 -0
  42. package/src/tests/tool_validation.test.ts +18 -0
  43. package/src/tool/beat-rate-converter/beat-rate-converter.css +301 -0
  44. package/src/tool/beat-rate-converter/bibliography.astro +16 -0
  45. package/src/tool/beat-rate-converter/bibliography.ts +12 -0
  46. package/src/tool/beat-rate-converter/client.ts +46 -0
  47. package/src/tool/beat-rate-converter/component.astro +15 -0
  48. package/src/tool/beat-rate-converter/components/ConverterPanel.astro +87 -0
  49. package/src/tool/beat-rate-converter/entry.ts +42 -0
  50. package/src/tool/beat-rate-converter/i18n/de.ts +138 -0
  51. package/src/tool/beat-rate-converter/i18n/en.ts +138 -0
  52. package/src/tool/beat-rate-converter/i18n/es.ts +138 -0
  53. package/src/tool/beat-rate-converter/i18n/fr.ts +138 -0
  54. package/src/tool/beat-rate-converter/i18n/id.ts +138 -0
  55. package/src/tool/beat-rate-converter/i18n/it.ts +138 -0
  56. package/src/tool/beat-rate-converter/i18n/ja.ts +138 -0
  57. package/src/tool/beat-rate-converter/i18n/ko.ts +138 -0
  58. package/src/tool/beat-rate-converter/i18n/nl.ts +138 -0
  59. package/src/tool/beat-rate-converter/i18n/pl.ts +138 -0
  60. package/src/tool/beat-rate-converter/i18n/pt.ts +138 -0
  61. package/src/tool/beat-rate-converter/i18n/ru.ts +138 -0
  62. package/src/tool/beat-rate-converter/i18n/sv.ts +138 -0
  63. package/src/tool/beat-rate-converter/i18n/tr.ts +138 -0
  64. package/src/tool/beat-rate-converter/i18n/zh.ts +138 -0
  65. package/src/tool/beat-rate-converter/index.ts +11 -0
  66. package/src/tool/beat-rate-converter/seo.astro +16 -0
  67. package/src/tool/crown-reference-guide/bibliography.astro +16 -0
  68. package/src/tool/crown-reference-guide/bibliography.ts +20 -0
  69. package/src/tool/crown-reference-guide/client.ts +193 -0
  70. package/src/tool/crown-reference-guide/component.astro +69 -0
  71. package/src/tool/crown-reference-guide/components/CrownView.astro +40 -0
  72. package/src/tool/crown-reference-guide/components/MovementSelector.astro +26 -0
  73. package/src/tool/crown-reference-guide/components/PositionPanel.astro +59 -0
  74. package/src/tool/crown-reference-guide/crown-reference-guide.css +383 -0
  75. package/src/tool/crown-reference-guide/entry.ts +60 -0
  76. package/src/tool/crown-reference-guide/i18n/de.ts +207 -0
  77. package/src/tool/crown-reference-guide/i18n/en.ts +207 -0
  78. package/src/tool/crown-reference-guide/i18n/es.ts +207 -0
  79. package/src/tool/crown-reference-guide/i18n/fr.ts +207 -0
  80. package/src/tool/crown-reference-guide/i18n/id.ts +207 -0
  81. package/src/tool/crown-reference-guide/i18n/it.ts +207 -0
  82. package/src/tool/crown-reference-guide/i18n/ja.ts +207 -0
  83. package/src/tool/crown-reference-guide/i18n/ko.ts +207 -0
  84. package/src/tool/crown-reference-guide/i18n/nl.ts +207 -0
  85. package/src/tool/crown-reference-guide/i18n/pl.ts +207 -0
  86. package/src/tool/crown-reference-guide/i18n/pt.ts +207 -0
  87. package/src/tool/crown-reference-guide/i18n/ru.ts +207 -0
  88. package/src/tool/crown-reference-guide/i18n/sv.ts +207 -0
  89. package/src/tool/crown-reference-guide/i18n/tr.ts +207 -0
  90. package/src/tool/crown-reference-guide/i18n/zh.ts +207 -0
  91. package/src/tool/crown-reference-guide/index.ts +11 -0
  92. package/src/tool/crown-reference-guide/seo.astro +16 -0
  93. package/src/tool/crown-reference-guide/utils.ts +0 -0
  94. package/src/tool/demagnetizing-timer/bibliography.astro +16 -0
  95. package/src/tool/demagnetizing-timer/bibliography.ts +12 -0
  96. package/src/tool/demagnetizing-timer/client.ts +221 -0
  97. package/src/tool/demagnetizing-timer/component.astro +15 -0
  98. package/src/tool/demagnetizing-timer/components/TimerPanel.astro +92 -0
  99. package/src/tool/demagnetizing-timer/demagnetizing-timer.css +389 -0
  100. package/src/tool/demagnetizing-timer/entry.ts +50 -0
  101. package/src/tool/demagnetizing-timer/helpers/field.ts +134 -0
  102. package/src/tool/demagnetizing-timer/i18n/de.ts +143 -0
  103. package/src/tool/demagnetizing-timer/i18n/en.ts +143 -0
  104. package/src/tool/demagnetizing-timer/i18n/es.ts +143 -0
  105. package/src/tool/demagnetizing-timer/i18n/fr.ts +143 -0
  106. package/src/tool/demagnetizing-timer/i18n/id.ts +143 -0
  107. package/src/tool/demagnetizing-timer/i18n/it.ts +143 -0
  108. package/src/tool/demagnetizing-timer/i18n/ja.ts +143 -0
  109. package/src/tool/demagnetizing-timer/i18n/ko.ts +143 -0
  110. package/src/tool/demagnetizing-timer/i18n/nl.ts +143 -0
  111. package/src/tool/demagnetizing-timer/i18n/pl.ts +143 -0
  112. package/src/tool/demagnetizing-timer/i18n/pt.ts +143 -0
  113. package/src/tool/demagnetizing-timer/i18n/ru.ts +143 -0
  114. package/src/tool/demagnetizing-timer/i18n/sv.ts +143 -0
  115. package/src/tool/demagnetizing-timer/i18n/tr.ts +143 -0
  116. package/src/tool/demagnetizing-timer/i18n/zh.ts +143 -0
  117. package/src/tool/demagnetizing-timer/index.ts +11 -0
  118. package/src/tool/demagnetizing-timer/seo.astro +16 -0
  119. package/src/tool/demagnetizing-timer/utils.ts +0 -0
  120. package/src/tool/power-reserve-estimator/bibliography.astro +16 -0
  121. package/src/tool/power-reserve-estimator/bibliography.ts +16 -0
  122. package/src/tool/power-reserve-estimator/client.ts +139 -0
  123. package/src/tool/power-reserve-estimator/component.astro +15 -0
  124. package/src/tool/power-reserve-estimator/components/EstimatorPanel.astro +150 -0
  125. package/src/tool/power-reserve-estimator/entry.ts +51 -0
  126. package/src/tool/power-reserve-estimator/i18n/de.ts +158 -0
  127. package/src/tool/power-reserve-estimator/i18n/en.ts +158 -0
  128. package/src/tool/power-reserve-estimator/i18n/es.ts +158 -0
  129. package/src/tool/power-reserve-estimator/i18n/fr.ts +158 -0
  130. package/src/tool/power-reserve-estimator/i18n/id.ts +158 -0
  131. package/src/tool/power-reserve-estimator/i18n/it.ts +158 -0
  132. package/src/tool/power-reserve-estimator/i18n/ja.ts +158 -0
  133. package/src/tool/power-reserve-estimator/i18n/ko.ts +158 -0
  134. package/src/tool/power-reserve-estimator/i18n/nl.ts +158 -0
  135. package/src/tool/power-reserve-estimator/i18n/pl.ts +158 -0
  136. package/src/tool/power-reserve-estimator/i18n/pt.ts +158 -0
  137. package/src/tool/power-reserve-estimator/i18n/ru.ts +158 -0
  138. package/src/tool/power-reserve-estimator/i18n/sv.ts +158 -0
  139. package/src/tool/power-reserve-estimator/i18n/tr.ts +158 -0
  140. package/src/tool/power-reserve-estimator/i18n/zh.ts +158 -0
  141. package/src/tool/power-reserve-estimator/index.ts +11 -0
  142. package/src/tool/power-reserve-estimator/power-reserve-estimator.css +402 -0
  143. package/src/tool/power-reserve-estimator/seo.astro +16 -0
  144. package/src/tool/strap-taper-calculator/bibliography.astro +16 -0
  145. package/src/tool/strap-taper-calculator/bibliography.ts +12 -0
  146. package/src/tool/strap-taper-calculator/client.ts +129 -0
  147. package/src/tool/strap-taper-calculator/component.astro +15 -0
  148. package/src/tool/strap-taper-calculator/components/CalculatorPanel.astro +114 -0
  149. package/src/tool/strap-taper-calculator/entry.ts +56 -0
  150. package/src/tool/strap-taper-calculator/i18n/de.ts +152 -0
  151. package/src/tool/strap-taper-calculator/i18n/en.ts +152 -0
  152. package/src/tool/strap-taper-calculator/i18n/es.ts +152 -0
  153. package/src/tool/strap-taper-calculator/i18n/fr.ts +152 -0
  154. package/src/tool/strap-taper-calculator/i18n/id.ts +152 -0
  155. package/src/tool/strap-taper-calculator/i18n/it.ts +152 -0
  156. package/src/tool/strap-taper-calculator/i18n/ja.ts +152 -0
  157. package/src/tool/strap-taper-calculator/i18n/ko.ts +152 -0
  158. package/src/tool/strap-taper-calculator/i18n/nl.ts +152 -0
  159. package/src/tool/strap-taper-calculator/i18n/pl.ts +152 -0
  160. package/src/tool/strap-taper-calculator/i18n/pt.ts +152 -0
  161. package/src/tool/strap-taper-calculator/i18n/ru.ts +152 -0
  162. package/src/tool/strap-taper-calculator/i18n/sv.ts +152 -0
  163. package/src/tool/strap-taper-calculator/i18n/tr.ts +152 -0
  164. package/src/tool/strap-taper-calculator/i18n/zh.ts +152 -0
  165. package/src/tool/strap-taper-calculator/index.ts +11 -0
  166. package/src/tool/strap-taper-calculator/seo.astro +16 -0
  167. package/src/tool/strap-taper-calculator/strap-taper-calculator.css +320 -0
  168. package/src/tool/watch-accuracy-tracker/bibliography.astro +16 -0
  169. package/src/tool/watch-accuracy-tracker/bibliography.ts +12 -0
  170. package/src/tool/watch-accuracy-tracker/chart.ts +126 -0
  171. package/src/tool/watch-accuracy-tracker/client.ts +287 -0
  172. package/src/tool/watch-accuracy-tracker/component.astro +35 -0
  173. package/src/tool/watch-accuracy-tracker/components/AccuracyTracker.astro +96 -0
  174. package/src/tool/watch-accuracy-tracker/components/DriftPredictor.astro +126 -0
  175. package/src/tool/watch-accuracy-tracker/components/LogHistory.astro +66 -0
  176. package/src/tool/watch-accuracy-tracker/entry.ts +94 -0
  177. package/src/tool/watch-accuracy-tracker/i18n/de.ts +167 -0
  178. package/src/tool/watch-accuracy-tracker/i18n/en.ts +167 -0
  179. package/src/tool/watch-accuracy-tracker/i18n/es.ts +167 -0
  180. package/src/tool/watch-accuracy-tracker/i18n/fr.ts +167 -0
  181. package/src/tool/watch-accuracy-tracker/i18n/id.ts +167 -0
  182. package/src/tool/watch-accuracy-tracker/i18n/it.ts +167 -0
  183. package/src/tool/watch-accuracy-tracker/i18n/ja.ts +167 -0
  184. package/src/tool/watch-accuracy-tracker/i18n/ko.ts +167 -0
  185. package/src/tool/watch-accuracy-tracker/i18n/nl.ts +167 -0
  186. package/src/tool/watch-accuracy-tracker/i18n/pl.ts +167 -0
  187. package/src/tool/watch-accuracy-tracker/i18n/pt.ts +167 -0
  188. package/src/tool/watch-accuracy-tracker/i18n/ru.ts +167 -0
  189. package/src/tool/watch-accuracy-tracker/i18n/sv.ts +167 -0
  190. package/src/tool/watch-accuracy-tracker/i18n/tr.ts +167 -0
  191. package/src/tool/watch-accuracy-tracker/i18n/zh.ts +167 -0
  192. package/src/tool/watch-accuracy-tracker/index.ts +9 -0
  193. package/src/tool/watch-accuracy-tracker/logger.ts +105 -0
  194. package/src/tool/watch-accuracy-tracker/seo.astro +16 -0
  195. package/src/tool/watch-accuracy-tracker/utils.ts +99 -0
  196. package/src/tool/watch-accuracy-tracker/watch-accuracy-tracker.css +564 -0
  197. package/src/tool/watch-savings-planner/bibliography.astro +16 -0
  198. package/src/tool/watch-savings-planner/bibliography.ts +8 -0
  199. package/src/tool/watch-savings-planner/client.ts +271 -0
  200. package/src/tool/watch-savings-planner/component.astro +33 -0
  201. package/src/tool/watch-savings-planner/components/AddGoalForm.astro +49 -0
  202. package/src/tool/watch-savings-planner/components/GoalCard.astro +58 -0
  203. package/src/tool/watch-savings-planner/entry.ts +62 -0
  204. package/src/tool/watch-savings-planner/i18n/de.ts +153 -0
  205. package/src/tool/watch-savings-planner/i18n/en.ts +155 -0
  206. package/src/tool/watch-savings-planner/i18n/es.ts +153 -0
  207. package/src/tool/watch-savings-planner/i18n/fr.ts +153 -0
  208. package/src/tool/watch-savings-planner/i18n/id.ts +153 -0
  209. package/src/tool/watch-savings-planner/i18n/it.ts +153 -0
  210. package/src/tool/watch-savings-planner/i18n/ja.ts +153 -0
  211. package/src/tool/watch-savings-planner/i18n/ko.ts +153 -0
  212. package/src/tool/watch-savings-planner/i18n/nl.ts +153 -0
  213. package/src/tool/watch-savings-planner/i18n/pl.ts +153 -0
  214. package/src/tool/watch-savings-planner/i18n/pt.ts +153 -0
  215. package/src/tool/watch-savings-planner/i18n/ru.ts +153 -0
  216. package/src/tool/watch-savings-planner/i18n/sv.ts +153 -0
  217. package/src/tool/watch-savings-planner/i18n/tr.ts +153 -0
  218. package/src/tool/watch-savings-planner/i18n/zh.ts +153 -0
  219. package/src/tool/watch-savings-planner/index.ts +11 -0
  220. package/src/tool/watch-savings-planner/seo.astro +16 -0
  221. package/src/tool/watch-savings-planner/utils.ts +0 -0
  222. package/src/tool/watch-savings-planner/watch-savings-planner.css +460 -0
  223. package/src/tool/water-resistance-converter/bibliography.astro +16 -0
  224. package/src/tool/water-resistance-converter/bibliography.ts +16 -0
  225. package/src/tool/water-resistance-converter/client.ts +56 -0
  226. package/src/tool/water-resistance-converter/component.astro +15 -0
  227. package/src/tool/water-resistance-converter/components/ConverterPanel.astro +113 -0
  228. package/src/tool/water-resistance-converter/entry.ts +52 -0
  229. package/src/tool/water-resistance-converter/i18n/de.ts +148 -0
  230. package/src/tool/water-resistance-converter/i18n/en.ts +148 -0
  231. package/src/tool/water-resistance-converter/i18n/es.ts +148 -0
  232. package/src/tool/water-resistance-converter/i18n/fr.ts +148 -0
  233. package/src/tool/water-resistance-converter/i18n/id.ts +148 -0
  234. package/src/tool/water-resistance-converter/i18n/it.ts +148 -0
  235. package/src/tool/water-resistance-converter/i18n/ja.ts +148 -0
  236. package/src/tool/water-resistance-converter/i18n/ko.ts +148 -0
  237. package/src/tool/water-resistance-converter/i18n/nl.ts +148 -0
  238. package/src/tool/water-resistance-converter/i18n/pl.ts +148 -0
  239. package/src/tool/water-resistance-converter/i18n/pt.ts +148 -0
  240. package/src/tool/water-resistance-converter/i18n/ru.ts +148 -0
  241. package/src/tool/water-resistance-converter/i18n/sv.ts +148 -0
  242. package/src/tool/water-resistance-converter/i18n/tr.ts +148 -0
  243. package/src/tool/water-resistance-converter/i18n/zh.ts +148 -0
  244. package/src/tool/water-resistance-converter/index.ts +11 -0
  245. package/src/tool/water-resistance-converter/seo.astro +16 -0
  246. package/src/tool/water-resistance-converter/water-resistance-converter.css +254 -0
  247. package/src/tool/wrist-presence-calculator/bibliography.astro +16 -0
  248. package/src/tool/wrist-presence-calculator/bibliography.ts +12 -0
  249. package/src/tool/wrist-presence-calculator/client.ts +180 -0
  250. package/src/tool/wrist-presence-calculator/component.astro +23 -0
  251. package/src/tool/wrist-presence-calculator/components/CalculatorInputs.astro +97 -0
  252. package/src/tool/wrist-presence-calculator/components/FitResult.astro +68 -0
  253. package/src/tool/wrist-presence-calculator/components/Visualizer.astro +16 -0
  254. package/src/tool/wrist-presence-calculator/entry.ts +59 -0
  255. package/src/tool/wrist-presence-calculator/helpers/canvas.ts +189 -0
  256. package/src/tool/wrist-presence-calculator/helpers/results.ts +78 -0
  257. package/src/tool/wrist-presence-calculator/i18n/de.ts +139 -0
  258. package/src/tool/wrist-presence-calculator/i18n/en.ts +155 -0
  259. package/src/tool/wrist-presence-calculator/i18n/es.ts +139 -0
  260. package/src/tool/wrist-presence-calculator/i18n/fr.ts +139 -0
  261. package/src/tool/wrist-presence-calculator/i18n/id.ts +139 -0
  262. package/src/tool/wrist-presence-calculator/i18n/it.ts +139 -0
  263. package/src/tool/wrist-presence-calculator/i18n/ja.ts +139 -0
  264. package/src/tool/wrist-presence-calculator/i18n/ko.ts +139 -0
  265. package/src/tool/wrist-presence-calculator/i18n/nl.ts +139 -0
  266. package/src/tool/wrist-presence-calculator/i18n/pl.ts +139 -0
  267. package/src/tool/wrist-presence-calculator/i18n/pt.ts +139 -0
  268. package/src/tool/wrist-presence-calculator/i18n/ru.ts +139 -0
  269. package/src/tool/wrist-presence-calculator/i18n/sv.ts +139 -0
  270. package/src/tool/wrist-presence-calculator/i18n/tr.ts +139 -0
  271. package/src/tool/wrist-presence-calculator/i18n/zh.ts +155 -0
  272. package/src/tool/wrist-presence-calculator/index.ts +11 -0
  273. package/src/tool/wrist-presence-calculator/seo.astro +16 -0
  274. package/src/tool/wrist-presence-calculator/utils.ts +30 -0
  275. package/src/tool/wrist-presence-calculator/wrist-presence-calculator.css +372 -0
  276. package/src/tools.ts +26 -0
  277. package/src/types.ts +70 -0
@@ -0,0 +1,16 @@
1
+ ---
2
+ import { SEORenderer } from '@jjlmoya/utils-shared';
3
+ import { crownReferenceGuide } from './index';
4
+ import type { KnownLocale } from '../../types';
5
+
6
+ interface Props {
7
+ locale?: KnownLocale;
8
+ }
9
+
10
+ const { locale = 'en' } = Astro.props;
11
+ const loader = crownReferenceGuide.i18n[locale] || crownReferenceGuide.i18n.en;
12
+ const content = await loader?.();
13
+ if (!content) return null;
14
+ ---
15
+
16
+ {content.seo?.length > 0 && <SEORenderer content={{ locale, sections: content.seo }} />}
File without changes
@@ -0,0 +1,16 @@
1
+ ---
2
+ import { Bibliography as SharedBibliography } from '@jjlmoya/utils-shared';
3
+ import { demagnetizingTimer } from './index';
4
+ import type { KnownLocale } from '../../types';
5
+
6
+ interface Props {
7
+ locale?: KnownLocale;
8
+ }
9
+
10
+ const { locale = 'en' } = Astro.props as Props;
11
+ const loader = demagnetizingTimer.i18n[locale] || demagnetizingTimer.i18n.en;
12
+ const content = await loader?.();
13
+ if (!content) return null;
14
+ ---
15
+
16
+ {content && <SharedBibliography links={content.bibliography} />}
@@ -0,0 +1,12 @@
1
+ import type { BibliographyEntry } from '../../types';
2
+
3
+ export const bibliography: BibliographyEntry[] = [
4
+ {
5
+ name: 'How to Demagnetize a Watch Movement',
6
+ url: 'https://en.wikipedia.org/wiki/Demagnetization',
7
+ },
8
+ {
9
+ name: 'How to Demagnetize A Watch',
10
+ url: 'https://teddybaldassarre.com/en-int/blogs/watches/how-to-demagnetize-a-watch',
11
+ },
12
+ ];
@@ -0,0 +1,221 @@
1
+ import { MagneticField } from './helpers/field';
2
+
3
+ const mainEl = document.querySelector('.tool-main-card') as HTMLElement;
4
+ const ui = mainEl ? JSON.parse(mainEl.dataset.ui || '{}') : {};
5
+
6
+ let duration = 1;
7
+ let elapsed = 0;
8
+ let running = false;
9
+ let animFrameId: number | null = null;
10
+ let startTimestamp: number | null = null;
11
+
12
+ const fieldCanvas = document.getElementById('field-canvas') as HTMLCanvasElement;
13
+ const field = new MagneticField(fieldCanvas);
14
+
15
+ const circle = document.getElementById('timer-circle') as HTMLElement;
16
+ const glowRing = document.getElementById('timer-glow-ring') as HTMLElement;
17
+ const progressRing = document.getElementById('timer-progress-ring') as SVGElement;
18
+ const timerValue = document.getElementById('timer-value') as HTMLElement;
19
+ const timerStatus = document.getElementById('timer-status') as HTMLElement;
20
+ const startBtn = document.getElementById('start-btn') as HTMLButtonElement;
21
+ const stopBtn = document.getElementById('stop-btn') as HTMLButtonElement;
22
+ const resetBtn = document.getElementById('reset-btn') as HTMLButtonElement;
23
+ const chips = document.querySelectorAll('.chip') as NodeListOf<HTMLButtonElement>;
24
+
25
+ const circumference = 326.73;
26
+ let audioCtx: AudioContext | null = null;
27
+
28
+ function getAudioContext(): AudioContext {
29
+ if (!audioCtx) {
30
+ audioCtx = new (window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext)();
31
+ }
32
+ return audioCtx;
33
+ }
34
+
35
+ function playBeep(frequency: number, durationMs: number, volume = 0.25, type: OscillatorType = 'sine') {
36
+ try {
37
+ const ctx = getAudioContext();
38
+ const osc = ctx.createOscillator();
39
+ const gain = ctx.createGain();
40
+ osc.type = type;
41
+ osc.frequency.value = frequency;
42
+ gain.gain.value = volume;
43
+ gain.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + durationMs / 1000);
44
+ osc.connect(gain);
45
+ gain.connect(ctx.destination);
46
+ osc.start(ctx.currentTime);
47
+ osc.stop(ctx.currentTime + durationMs / 1000);
48
+ } catch {
49
+ }
50
+ }
51
+
52
+ function playStartBeep() {
53
+ playBeep(523, 80, 0.2);
54
+ setTimeout(() => playBeep(659, 80, 0.2), 80);
55
+ setTimeout(() => playBeep(784, 120, 0.25), 160);
56
+ }
57
+
58
+ function playEndBeep() {
59
+ playBeep(784, 100, 0.25);
60
+ setTimeout(() => playBeep(659, 100, 0.2), 100);
61
+ setTimeout(() => playBeep(523, 200, 0.25), 200);
62
+ }
63
+
64
+ function playTickBeep() {
65
+ playBeep(880, 30, 0.12);
66
+ }
67
+
68
+ let pulseAnimFrame: number | null = null;
69
+
70
+ function startPulseAnimation() {
71
+ let phase = 0;
72
+ const step = 0.05;
73
+
74
+ function tick() {
75
+ phase += step;
76
+ const s = 1 + Math.sin(phase * Math.PI * 2) * 0.02;
77
+ glowRing.style.transform = `translate(-50%, -50%) scale(${s})`;
78
+ glowRing.style.opacity = String(0.3 + Math.sin(phase * Math.PI * 2) * 0.15);
79
+ pulseAnimFrame = requestAnimationFrame(tick);
80
+ }
81
+
82
+ if (pulseAnimFrame) cancelAnimationFrame(pulseAnimFrame);
83
+ pulseAnimFrame = requestAnimationFrame(tick);
84
+ }
85
+
86
+ function stopPulseAnimation() {
87
+ if (pulseAnimFrame) {
88
+ cancelAnimationFrame(pulseAnimFrame);
89
+ pulseAnimFrame = null;
90
+ }
91
+ glowRing.style.transform = 'translate(-50%, -50%) scale(1)';
92
+ glowRing.style.opacity = '0';
93
+ }
94
+
95
+ function setPhase(phase: 'ready' | 'pressing' | 'releasing' | 'complete') {
96
+ circle.className = 'timer-circle';
97
+
98
+ if (phase === 'pressing') {
99
+ circle.classList.add('phase-pressing');
100
+ timerStatus.textContent = ui.holdPhase || 'Hold the button...';
101
+ timerStatus.className = 'timer-status-pill status-pressing';
102
+ startPulseAnimation();
103
+ } else if (phase === 'releasing') {
104
+ circle.classList.add('phase-releasing');
105
+ timerStatus.textContent = ui.releasePhase || 'Release now!';
106
+ timerStatus.className = 'timer-status-pill status-releasing';
107
+ stopPulseAnimation();
108
+ glowRing.style.opacity = '0.6';
109
+ } else if (phase === 'complete') {
110
+ circle.classList.add('phase-complete');
111
+ timerStatus.textContent = ui.completePhase || 'Done!';
112
+ timerStatus.className = 'timer-status-pill status-complete';
113
+ glowRing.style.opacity = '0.2';
114
+ } else {
115
+ timerStatus.textContent = ui.ready || 'Ready';
116
+ timerStatus.className = 'timer-status-pill';
117
+ stopPulseAnimation();
118
+ glowRing.style.opacity = '0';
119
+ }
120
+ }
121
+
122
+ function updateDisplay(time: number) {
123
+ timerValue.textContent = time.toFixed(1);
124
+ const progress = Math.min(time / duration, 1);
125
+ const offset = circumference * (1 - progress);
126
+ progressRing.setAttribute('stroke-dashoffset', offset.toString());
127
+ }
128
+
129
+ function stopTimer() {
130
+ running = false;
131
+ if (animFrameId !== null) {
132
+ cancelAnimationFrame(animFrameId);
133
+ animFrameId = null;
134
+ }
135
+ startBtn.disabled = false;
136
+ stopBtn.disabled = true;
137
+ }
138
+
139
+ let lastTickSecond = -1;
140
+
141
+ function tick(timestamp: number) {
142
+ if (!startTimestamp) {
143
+ startTimestamp = timestamp;
144
+ }
145
+
146
+ const rawElapsed = (timestamp - startTimestamp) / 1000;
147
+ elapsed = Math.min(rawElapsed, duration);
148
+
149
+ updateDisplay(elapsed);
150
+
151
+ const currentSecond = Math.floor(elapsed);
152
+ if (currentSecond > lastTickSecond) {
153
+ lastTickSecond = currentSecond;
154
+ if (elapsed < duration) {
155
+ playTickBeep();
156
+ }
157
+ }
158
+
159
+ if (elapsed >= duration) {
160
+ setPhase('releasing');
161
+ playEndBeep();
162
+ stopTimer();
163
+ setTimeout(() => {
164
+ setPhase('complete');
165
+ }, 1000);
166
+ return;
167
+ }
168
+
169
+ animFrameId = requestAnimationFrame(tick);
170
+ }
171
+
172
+ function startTimer() {
173
+ if (running) return;
174
+ running = true;
175
+ elapsed = 0;
176
+ startTimestamp = null;
177
+ lastTickSecond = -1;
178
+ startBtn.disabled = true;
179
+ stopBtn.disabled = false;
180
+ field.resize();
181
+ field.start();
182
+ setPhase('pressing');
183
+ playStartBeep();
184
+ updateDisplay(0);
185
+ animFrameId = requestAnimationFrame(tick);
186
+ }
187
+
188
+ function resetTimer() {
189
+ stopTimer();
190
+ field.stop();
191
+ elapsed = 0;
192
+ startTimestamp = null;
193
+ lastTickSecond = -1;
194
+ updateDisplay(0);
195
+ setPhase('ready');
196
+ circle.className = 'timer-circle';
197
+ }
198
+
199
+ startBtn.addEventListener('click', startTimer);
200
+
201
+ stopBtn.addEventListener('click', () => {
202
+ field.stop();
203
+ stopTimer();
204
+ setPhase('ready');
205
+ });
206
+
207
+ resetBtn.addEventListener('click', resetTimer);
208
+
209
+ chips.forEach((chip) => {
210
+ chip.addEventListener('click', () => {
211
+ if (running) return;
212
+ chips.forEach((c) => c.classList.remove('active'));
213
+ chip.classList.add('active');
214
+ duration = parseInt(chip.dataset.duration || '1', 10);
215
+ resetTimer();
216
+ });
217
+ });
218
+
219
+ window.addEventListener('resize', () => field.resize());
220
+
221
+ resetTimer();
@@ -0,0 +1,15 @@
1
+ ---
2
+ import TimerPanel from './components/TimerPanel.astro';
3
+
4
+ interface Props {
5
+ ui: Record<string, string>;
6
+ }
7
+
8
+ const { ui } = Astro.props;
9
+ ---
10
+
11
+ <div class="tool-main-card" data-ui={JSON.stringify(ui)}>
12
+ <TimerPanel labels={ui} />
13
+ </div>
14
+
15
+ <script src="./client.ts"></script>
@@ -0,0 +1,92 @@
1
+ ---
2
+ interface Props {
3
+ labels: Record<string, string>;
4
+ }
5
+
6
+ const { labels } = Astro.props;
7
+ ---
8
+
9
+ <div class="timer-panel">
10
+ <div class="timer-display-section">
11
+ <div class="timer-circle-wrapper">
12
+ <canvas class="field-canvas" id="field-canvas"></canvas>
13
+ <div class="timer-circle" id="timer-circle">
14
+ <svg class="timer-svg" viewBox="0 0 120 120">
15
+ <defs>
16
+ <filter id="glow">
17
+ <feGaussianBlur stdDeviation="2.5" result="blur" />
18
+ <feMerge>
19
+ <feMergeNode in="blur" />
20
+ <feMergeNode in="SourceGraphic" />
21
+ </feMerge>
22
+ </filter>
23
+ </defs>
24
+ <circle class="timer-bg-ring" cx="60" cy="60" r="52" />
25
+ <circle class="timer-progress-ring" id="timer-progress-ring" cx="60" cy="60" r="52"
26
+ stroke-dasharray="326.73" stroke-dashoffset="0" filter="url(#glow)" />
27
+ </svg>
28
+ <div class="timer-text" id="timer-text">
29
+ <span class="timer-value" id="timer-value">0.0</span>
30
+ <span class="timer-unit" id="timer-unit">{labels.seconds || "s"}</span>
31
+ </div>
32
+ <div class="timer-glow-ring" id="timer-glow-ring"></div>
33
+ </div>
34
+ </div>
35
+ <div class="timer-status-pill" id="timer-status">{labels.ready || "Ready"}</div>
36
+ </div>
37
+
38
+ <div class="timer-controls">
39
+ <button type="button" class="timer-btn start-btn" id="start-btn">
40
+ <svg class="btn-icon" viewBox="0 0 24 24" width="18" height="18">
41
+ <path d="M8 5v14l11-7z" fill="currentColor" />
42
+ </svg>
43
+ {labels.startButton || "Start"}
44
+ </button>
45
+ <button type="button" class="timer-btn stop-btn" id="stop-btn" disabled>
46
+ <svg class="btn-icon" viewBox="0 0 24 24" width="18" height="18">
47
+ <rect x="6" y="6" width="12" height="12" rx="1" fill="currentColor" />
48
+ </svg>
49
+ {labels.stopButton || "Stop"}
50
+ </button>
51
+ <button type="button" class="timer-btn reset-btn" id="reset-btn">
52
+ <svg class="btn-icon" viewBox="0 0 24 24" width="18" height="18">
53
+ <path d="M17.65 6.35A7.958 7.958 0 0012 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0112 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z" fill="currentColor" />
54
+ </svg>
55
+ </button>
56
+ </div>
57
+
58
+ <div class="duration-selector">
59
+ <div class="chip-group-label">{labels.durationLabel || "Pulse"}</div>
60
+ <div class="chip-group">
61
+ <button type="button" class="chip active" data-duration="1">1s</button>
62
+ <button type="button" class="chip" data-duration="2">2s</button>
63
+ <button type="button" class="chip" data-duration="3">3s</button>
64
+ </div>
65
+ </div>
66
+
67
+ <div class="steps-section">
68
+ <div class="step-row">
69
+ <div class="step-marker">1</div>
70
+ <span class="step-text">{labels.step1 || "Place watch on demagnetizer."}</span>
71
+ </div>
72
+ <div class="step-row">
73
+ <div class="step-marker">2</div>
74
+ <span class="step-text">{labels.step2 || "Press Start, hold button for set duration."}</span>
75
+ </div>
76
+ <div class="step-row">
77
+ <div class="step-marker">3</div>
78
+ <span class="step-text">{labels.step3 || "Release button, move watch away slowly."}</span>
79
+ </div>
80
+ <div class="step-row">
81
+ <div class="step-marker">4</div>
82
+ <span class="step-text">{labels.step4 || "Repeat 2–3 times, rotating the watch."}</span>
83
+ </div>
84
+ </div>
85
+
86
+ <div class="tip-row">
87
+ <svg class="tip-icon" viewBox="0 0 24 24" width="16" height="16">
88
+ <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" fill="currentColor" />
89
+ </svg>
90
+ <span class="tip-text">{labels.tipContent || "Keep the watch at least 1 meter away when powered on."}</span>
91
+ </div>
92
+ </div>