@jjlmoya/utils-pets 1.2.0 → 1.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jjlmoya/utils-pets",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@iconify-json/mdi": "^1.2.3",
40
- "@jjlmoya/utils-shared": "1.0.2",
40
+ "@jjlmoya/utils-shared": "^1.1.0",
41
41
  "astro": "^6.1.2",
42
42
  "astro-icon": "^1.1.0"
43
43
  },
@@ -21,7 +21,7 @@ const { ui } = Astro.props;
21
21
  </div>
22
22
  <div id="share-icon-cat" class="hidden"><Icon name="mdi:cat" /></div>
23
23
  </div>
24
- <h1 id="share-pet-name"></h1>
24
+ <p id="share-pet-name"></p>
25
25
  </div>
26
26
  <div class="age-share-card-body">
27
27
  <p class="age-share-human-label">{ui.humanAgeLabel}</p>
@@ -164,21 +164,30 @@ const { ui } = Astro.props;
164
164
  type PetAgeState,
165
165
  } from "./handlers";
166
166
 
167
- function setupPetTypeListener(state: PetAgeState, els: Required<ReturnType<typeof getElements>>, onUpdate: () => void) {
167
+ function setupPetTypeListener(
168
+ state: PetAgeState,
169
+ els: Required<ReturnType<typeof getElements>>,
170
+ onUpdate: () => void,
171
+ ) {
168
172
  els.petBtns.forEach((btn) => {
169
173
  btn.addEventListener("click", () => {
170
174
  state.petType = (btn.dataset.type || "dog") as PetSpecies;
171
175
  els.petBtns.forEach((b) => b.classList.remove("active"));
172
176
  btn.classList.add("active");
173
177
  if (els.dogSizeSelector) {
174
- els.dogSizeSelector.style.display = state.petType === "dog" ? "block" : "none";
178
+ els.dogSizeSelector.style.display =
179
+ state.petType === "dog" ? "block" : "none";
175
180
  }
176
181
  onUpdate();
177
182
  });
178
183
  });
179
184
  }
180
185
 
181
- function setupSizeListener(state: PetAgeState, els: Required<ReturnType<typeof getElements>>, onUpdate: () => void) {
186
+ function setupSizeListener(
187
+ state: PetAgeState,
188
+ els: Required<ReturnType<typeof getElements>>,
189
+ onUpdate: () => void,
190
+ ) {
182
191
  els.sizeBtns.forEach((btn) => {
183
192
  btn.addEventListener("click", () => {
184
193
  state.dogSize = (btn.dataset.size || "small") as DogSize;
@@ -189,22 +198,55 @@ const { ui } = Astro.props;
189
198
  });
190
199
  }
191
200
 
192
- function setupBirthYearListener(state: PetAgeState, birthYearInput: HTMLInputElement, currentYear: number, onUpdate: () => void) {
201
+ function setupBirthYearListener(
202
+ state: PetAgeState,
203
+ birthYearInput: HTMLInputElement,
204
+ currentYear: number,
205
+ onUpdate: () => void,
206
+ ) {
193
207
  birthYearInput.addEventListener("input", (e) => {
194
208
  const val = (e.target as HTMLInputElement).value;
195
209
  state.birthYear = validateBirthYear(val, currentYear);
196
- birthYearInput.classList.toggle("age-input-valid", state.birthYear !== null);
197
- birthYearInput.classList.toggle("age-input-error", val.length === 4 && !state.birthYear);
210
+ birthYearInput.classList.toggle(
211
+ "age-input-valid",
212
+ state.birthYear !== null,
213
+ );
214
+ birthYearInput.classList.toggle(
215
+ "age-input-error",
216
+ val.length === 4 && !state.birthYear,
217
+ );
198
218
  onUpdate();
199
219
  });
200
220
  }
201
221
 
202
- function setupShareListener(state: PetAgeState, els: Required<ReturnType<typeof getElements>>, birthYearInput: HTMLInputElement) {
222
+ function setupBasicListeners(
223
+ state: PetAgeState,
224
+ els: Required<ReturnType<typeof getElements>>,
225
+ onUpdate: () => void,
226
+ ) {
227
+ document.getElementById("create-new-btn")?.addEventListener("click", () => {
228
+ window.location.href = window.location.origin + window.location.pathname;
229
+ });
230
+
231
+ els.petNameInput?.addEventListener("input", (e) => {
232
+ state.petName = (e.target as HTMLInputElement).value;
233
+ onUpdate();
234
+ });
235
+ }
236
+
237
+ function setupShareListener(
238
+ state: PetAgeState,
239
+ els: Required<ReturnType<typeof getElements>>,
240
+ birthYearInput: HTMLInputElement,
241
+ ) {
203
242
  els.shareBtn?.addEventListener("click", async () => {
204
243
  if (!state.birthYear) {
205
244
  birthYearInput.focus();
206
245
  birthYearInput.classList.add("age-input-error");
207
- setTimeout(() => birthYearInput.classList.remove("age-input-error"), 500);
246
+ setTimeout(
247
+ () => birthYearInput.classList.remove("age-input-error"),
248
+ 500,
249
+ );
208
250
  return;
209
251
  }
210
252
 
@@ -221,7 +263,9 @@ const { ui } = Astro.props;
221
263
  }
222
264
 
223
265
  function initPetAge() {
224
- const birthYearInput = document.getElementById("birth-year-input") as HTMLInputElement;
266
+ const birthYearInput = document.getElementById(
267
+ "birth-year-input",
268
+ ) as HTMLInputElement;
225
269
  const container = document.getElementById("calculator-container");
226
270
 
227
271
  if (!birthYearInput || !container) return;
@@ -229,26 +273,22 @@ const { ui } = Astro.props;
229
273
  const uiData = JSON.parse(container.dataset.ui || "{}");
230
274
  const els = getElements() as Required<ReturnType<typeof getElements>>;
231
275
  const currentYear = new Date().getFullYear();
232
-
233
- const state: PetAgeState = { petType: "dog", dogSize: "small", birthYear: null, petName: "" };
276
+ const state: PetAgeState = {
277
+ petType: "dog",
278
+ dogSize: "small",
279
+ birthYear: null,
280
+ petName: "",
281
+ };
234
282
 
235
283
  birthYearInput.max = currentYear.toString();
236
284
  showShareMode(state, els, uiData, currentYear);
237
-
238
285
  const shareDomain = document.getElementById("share-domain");
239
286
  if (shareDomain) shareDomain.textContent = window.location.hostname;
240
287
 
241
- const onUpdate = () => updateResultsDisplay(state, els, uiData, currentYear);
242
-
243
- document.getElementById("create-new-btn")?.addEventListener("click", () => {
244
- window.location.href = window.location.origin + window.location.pathname;
245
- });
246
-
247
- els.petNameInput?.addEventListener("input", (e) => {
248
- state.petName = (e.target as HTMLInputElement).value;
249
- onUpdate();
250
- });
288
+ const onUpdate = () =>
289
+ updateResultsDisplay(state, els, uiData, currentYear);
251
290
 
291
+ setupBasicListeners(state, els, onUpdate);
252
292
  setupPetTypeListener(state, els, onUpdate);
253
293
  setupSizeListener(state, els, onUpdate);
254
294
  setupBirthYearListener(state, birthYearInput, currentYear, onUpdate);
@@ -2,7 +2,7 @@ import type { WithContext, SoftwareApplication } from 'schema-dts';
2
2
  import type { PetAgeUI, PetAgeLocaleContent } from '../index';
3
3
 
4
4
  const slug = 'pet-age-calculator';
5
- const title = 'Pet Age Calculator | Dogs and Cats to Human Years';
5
+ const title = 'Pet Age Calculator';
6
6
  const description = 'Find out your dog or cat\'s real age in human years. Forget the multiply-by-7 rule. Use our calculator based on current veterinary science.';
7
7
 
8
8
  const ui: PetAgeUI = {
@@ -2,7 +2,7 @@ import type { WithContext, SoftwareApplication } from 'schema-dts';
2
2
  import type { PetAgeUI, PetAgeLocaleContent } from '../index';
3
3
 
4
4
  const slug = 'calculadora-edad-mascotas';
5
- const title = 'Calculadora de Edad de Mascotas | Perros y Gatos a Años Humanos';
5
+ const title = 'Calculadora de Edad de Mascotas';
6
6
  const description = 'Descubre la edad real de tu perro o gato en años humanos. Olvida la regla de multiplicar por 7. Usa nuestra calculadora basada en ciencia veterinaria actual.';
7
7
 
8
8
  const ui: PetAgeUI = {
@@ -2,7 +2,7 @@ import type { WithContext, SoftwareApplication } from 'schema-dts';
2
2
  import type { PetAgeUI, PetAgeLocaleContent } from '../index';
3
3
 
4
4
  const slug = 'calculatrice-age-animaux';
5
- const title = 'Calculatrice d\'Âge des Animaux | Chiens et Chats en Années Humaines';
5
+ const title = 'Calculatrice d\'Âge des Animaux';
6
6
  const description = 'Découvrez l\'âge réel de votre chien ou chat en années humaines. Oubliez la règle de multiplier par 7. Utilisez notre calculatrice basée sur la science vétérinaire actuelle.';
7
7
 
8
8
  const ui: PetAgeUI = {
@@ -2,7 +2,7 @@ import type { WithContext, SoftwareApplication } from 'schema-dts';
2
2
  import type { PetRationUI, PetRationLocaleContent } from '../index';
3
3
 
4
4
  const slug = 'pet-daily-ration-calculator';
5
- const title = 'Pet Daily Ration Calculator | Canine and Feline Nutrition';
5
+ const title = 'Pet Daily Ration Calculator';
6
6
  const description = 'Calculate the exact amount of food your dog or cat needs. Tool based on veterinary RER and DER formulas for a healthy weight.';
7
7
 
8
8
  const ui: PetRationUI = {
@@ -2,7 +2,7 @@ import type { WithContext, SoftwareApplication } from 'schema-dts';
2
2
  import type { PetRationUI, PetRationLocaleContent } from '../index';
3
3
 
4
4
  const slug = 'calculadora-racion-diaria-mascotas';
5
- const title = 'Calculadora de Ración Diaria para Mascotas | Nutrición Canina y Felina';
5
+ const title = 'Calculadora de Ración Diaria para Mascotas';
6
6
  const description = 'Calcula la cantidad exacta de comida que necesita tu perro o gato. Herramienta basada en fórmulas veterinarias RER y DER para un peso saludable.';
7
7
 
8
8
  const ui: PetRationUI = {
@@ -2,7 +2,7 @@ import type { WithContext, SoftwareApplication } from 'schema-dts';
2
2
  import type { PetRationUI, PetRationLocaleContent } from '../index';
3
3
 
4
4
  const slug = 'calculatrice-ration-quotidienne-animaux';
5
- const title = 'Calculatrice de Ration Quotidienne pour Animaux | Nutrition Canine et Féline';
5
+ const title = 'Calculatrice de Ration Quotidienne pour Animaux';
6
6
  const description = 'Calculez la quantité exacte de nourriture dont votre chien ou chat a besoin. Outil basé sur les formules vétérinaires RER et DER pour un poids sain.';
7
7
 
8
8
  const ui: PetRationUI = {