@jjlmoya/utils-pets 1.1.0 → 1.3.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 +1 -1
- package/src/tool/petAge/component.astro +63 -23
- package/src/tool/petAge/i18n/en.ts +1 -1
- package/src/tool/petAge/i18n/es.ts +1 -1
- package/src/tool/petAge/i18n/fr.ts +1 -1
- package/src/tool/petRation/i18n/en.ts +1 -1
- package/src/tool/petRation/i18n/es.ts +1 -1
- package/src/tool/petRation/i18n/fr.ts +1 -1
- package/src/types.ts +2 -2
package/package.json
CHANGED
|
@@ -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
|
-
<
|
|
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(
|
|
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 =
|
|
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(
|
|
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(
|
|
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(
|
|
197
|
-
|
|
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
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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 = () =>
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 = {
|
package/src/types.ts
CHANGED
|
@@ -60,8 +60,8 @@ export interface PetToolEntry<TUI extends Record<string, string> = Record<string
|
|
|
60
60
|
export interface ToolDefinition {
|
|
61
61
|
entry: PetToolEntry;
|
|
62
62
|
Component: unknown;
|
|
63
|
-
SEOComponent
|
|
64
|
-
BibliographyComponent
|
|
63
|
+
SEOComponent: unknown;
|
|
64
|
+
BibliographyComponent: unknown;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export interface PetCategoryEntry {
|