@jjlmoya/utils-babies 1.2.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.
Files changed (27) hide show
  1. package/package.json +1 -1
  2. package/src/tool/baby-feeding-calculator/bibliography.astro +8 -4
  3. package/src/tool/baby-feeding-calculator/component.astro +208 -177
  4. package/src/tool/baby-feeding-calculator/style.css +317 -229
  5. package/src/tool/baby-percentile-calculator/bibliography.astro +8 -4
  6. package/src/tool/baby-percentile-calculator/component.astro +98 -240
  7. package/src/tool/baby-percentile-calculator/i18n/en.ts +1 -0
  8. package/src/tool/baby-percentile-calculator/i18n/es.ts +1 -0
  9. package/src/tool/baby-percentile-calculator/i18n/fr.ts +1 -0
  10. package/src/tool/baby-percentile-calculator/index.ts +1 -0
  11. package/src/tool/baby-percentile-calculator/style.css +342 -268
  12. package/src/tool/baby-size-converter/bibliography.astro +8 -4
  13. package/src/tool/baby-size-converter/component.astro +221 -212
  14. package/src/tool/baby-size-converter/style.css +433 -263
  15. package/src/tool/fertile-days-estimator/bibliography.astro +8 -4
  16. package/src/tool/fertile-days-estimator/component.astro +202 -200
  17. package/src/tool/fertile-days-estimator/style.css +408 -270
  18. package/src/tool/pregnancy-calculator/bibliography.astro +8 -4
  19. package/src/tool/pregnancy-calculator/component.astro +50 -8
  20. package/src/tool/pregnancy-calculator/i18n/en.ts +8 -0
  21. package/src/tool/pregnancy-calculator/i18n/es.ts +8 -0
  22. package/src/tool/pregnancy-calculator/i18n/fr.ts +8 -0
  23. package/src/tool/pregnancy-calculator/index.ts +8 -0
  24. package/src/tool/pregnancy-calculator/style.css +351 -134
  25. package/src/tool/vaccination-calendar/bibliography.astro +8 -4
  26. package/src/tool/vaccination-calendar/component.astro +120 -124
  27. package/src/tool/vaccination-calendar/style.css +296 -209
@@ -1,7 +1,11 @@
1
1
  ---
2
2
  import { Bibliography as BibliographyUI } from '@jjlmoya/utils-shared';
3
- import type { BibliographyEntry } from '../../types';
4
- interface Props { links?: BibliographyEntry[]; title: string; }
5
- const { links = [], title } = Astro.props;
3
+ import { pregnancyCalculator } from './index';
4
+ import type { KnownLocale } from '../../types';
5
+
6
+ interface Props { locale?: KnownLocale; }
7
+ const { locale = 'es' } = Astro.props;
8
+ const content = await pregnancyCalculator.i18n[locale]?.();
9
+ if (!content) return null;
6
10
  ---
7
- <BibliographyUI links={links} title={title} />
11
+ <BibliographyUI links={content.bibliography} title={content.bibliographyTitle ?? ''} />
@@ -89,6 +89,12 @@ const { ui } = Astro.props;
89
89
  <p class="pregnancy-calculator-mp-empty-body">{ui.labelStartBody}</p>
90
90
  </div>
91
91
 
92
+ <div class="pregnancy-calculator-mp-egg" id="pc-mp-egg" style="display:none">
93
+ <div class="pregnancy-calculator-egg-dot" id="pc-egg-dot"></div>
94
+ <div class="pregnancy-calculator-egg-title" id="pc-egg-title"></div>
95
+ <p class="pregnancy-calculator-egg-body" id="pc-egg-body"></p>
96
+ </div>
97
+
92
98
  <div class="pregnancy-calculator-mp-results" id="pc-mp-results" style="display:none">
93
99
  <div class="pregnancy-calculator-mp-top-row">
94
100
  <span class="pregnancy-calculator-mp-badge" id="pc-mp-badge">Semana —</span>
@@ -127,8 +133,10 @@ const { ui } = Astro.props;
127
133
  </div>
128
134
 
129
135
  <div class="pregnancy-calculator-right">
130
- <div class="pregnancy-calculator-tl-header">{ui.labelTimeline}</div>
131
- <div class="pregnancy-calculator-tl-scroll" id="pc-tl-scroll"></div>
136
+ <div class="pregnancy-calculator-tl-inner">
137
+ <div class="pregnancy-calculator-tl-header">{ui.labelTimeline}</div>
138
+ <div class="pregnancy-calculator-tl-scroll" id="pc-tl-scroll"></div>
139
+ </div>
132
140
  </div>
133
141
 
134
142
  </div>
@@ -155,6 +163,10 @@ const { ui } = Astro.props;
155
163
  const sdEdd = root.querySelector('#pc-sd-edd') as HTMLElement;
156
164
  const sdBtnCal = root.querySelector('#pc-sd-btn-cal') as HTMLButtonElement;
157
165
  const mpEmpty = root.querySelector('#pc-mp-empty') as HTMLElement;
166
+ const mpEgg = root.querySelector('#pc-mp-egg') as HTMLElement;
167
+ const eggDot = root.querySelector('#pc-egg-dot') as HTMLElement;
168
+ const eggTitle = root.querySelector('#pc-egg-title') as HTMLElement;
169
+ const eggBody = root.querySelector('#pc-egg-body') as HTMLElement;
158
170
  const mpResults = root.querySelector('#pc-mp-results') as HTMLElement;
159
171
  const mpBadge = root.querySelector('#pc-mp-badge') as HTMLElement;
160
172
  const mpAnalogy = root.querySelector('#pc-mp-analogy') as HTMLElement;
@@ -210,7 +222,7 @@ const { ui } = Astro.props;
210
222
  info.className = 'pregnancy-calculator-tl-info';
211
223
  const num = document.createElement('span');
212
224
  num.className = 'pregnancy-calculator-tl-num';
213
- num.textContent = String(w);
225
+ num.textContent = `${ui['labelSem'] ?? 'Sem'} ${w}`;
214
226
  const label = document.createElement('span');
215
227
  label.className = 'pregnancy-calculator-tl-label';
216
228
  label.textContent = timelineLabels[w] ?? '';
@@ -279,6 +291,20 @@ const { ui } = Astro.props;
279
291
  root.classList.add(`pregnancy-calculator-t${tri}`);
280
292
  }
281
293
 
294
+ function showEasterEgg(reason: 'future' | 'too-old'): void {
295
+ eggDot.dataset.reason = reason;
296
+ if (reason === 'future') {
297
+ eggTitle.textContent = ui['eggFutureTitle'] ?? '';
298
+ eggBody.textContent = ui['eggFutureBody'] ?? '';
299
+ } else {
300
+ eggTitle.textContent = ui['eggTooOldTitle'] ?? '';
301
+ eggBody.textContent = ui['eggTooOldBody'] ?? '';
302
+ }
303
+ mpEmpty.style.display = 'none';
304
+ mpResults.style.display = 'none';
305
+ mpEgg.style.display = '';
306
+ }
307
+
282
308
  function renderStats(result: CalcResult): void {
283
309
  if (!result.valid) {
284
310
  sdWeeks.textContent = '—';
@@ -287,8 +313,11 @@ const { ui } = Astro.props;
287
313
  sdBtnCal.disabled = true;
288
314
  return;
289
315
  }
290
- sdWeeks.textContent = `${result.weeks}+${result.days}`;
291
- sdTri.textContent = String(result.trimester);
316
+ const wFmt = (ui['weeksFormat'] ?? '{w}s {d}d')
317
+ .replace('{w}', String(result.weeks))
318
+ .replace('{d}', String(result.days));
319
+ sdWeeks.textContent = wFmt;
320
+ sdTri.textContent = `${result.trimester}${ui['trimesterSuffix'] ?? ''}`;
292
321
  sdEdd.textContent = fmtEdd.format(result.edd);
293
322
  sdBtnCal.disabled = false;
294
323
  applyTrimester(result.trimester);
@@ -305,7 +334,7 @@ const { ui } = Astro.props;
305
334
 
306
335
  function renderMilestone(weeks: number, cat: string, partner: boolean): void {
307
336
  const ms = getMilestone(weeks);
308
- mpBadge.textContent = `Semana ${weeks}`;
337
+ mpBadge.textContent = `${ui['labelWeekBadge'] ?? 'Semana'} ${weeks}`;
309
338
  mpAnalogy.textContent = ms.analogies[cat as 'fruits' | 'geek' | 'sweets'] ?? ms.analogies.fruits;
310
339
  mpSize.textContent = ms.size;
311
340
  mpBio.textContent = ms.biolook;
@@ -342,16 +371,29 @@ const { ui } = Astro.props;
342
371
  updateMethodUI(s.method);
343
372
  updatePartnerUI(s.partner);
344
373
  updateAnalogyTabs(s.analogyCat);
345
- if (!s.result || !s.result.valid) {
374
+ if (!s.result) {
375
+ mpEmpty.style.display = '';
376
+ mpEgg.style.display = 'none';
377
+ mpResults.style.display = 'none';
378
+ return;
379
+ }
380
+ if (!s.result.valid && s.result.outOfRange) {
381
+ renderStats(s.result);
382
+ showEasterEgg(s.result.outOfRange);
383
+ return;
384
+ }
385
+ if (!s.result.valid) {
346
386
  mpEmpty.style.display = '';
387
+ mpEgg.style.display = 'none';
347
388
  mpResults.style.display = 'none';
348
- if (s.result) renderStats(s.result);
389
+ renderStats(s.result);
349
390
  return;
350
391
  }
351
392
  renderStats(s.result);
352
393
  renderMilestone(s.result.weeks, s.analogyCat, s.partner);
353
394
  renderTimeline(s.result.weeks);
354
395
  mpEmpty.style.display = 'none';
396
+ mpEgg.style.display = 'none';
355
397
  mpResults.style.display = '';
356
398
  mpResults.classList.add('pregnancy-calculator-mp-enter');
357
399
  }
@@ -109,6 +109,14 @@ export const content: PregnancyCalculatorLocaleContent = {
109
109
  labelTimeline: 'Timeline',
110
110
  labelStartHere: 'Start here',
111
111
  labelStartBody: 'Select the date of your last period to discover which week you are in.',
112
+ labelSem: 'Wk',
113
+ labelWeekBadge: 'Week',
114
+ weeksFormat: '{w}w {d}d',
115
+ trimesterSuffix: '',
116
+ eggFutureTitle: 'Time traveller detected',
117
+ eggFutureBody: "That date hasn't arrived yet. Come back when reality catches up.",
118
+ eggTooOldTitle: 'Expired date',
119
+ eggTooOldBody: 'More than 40 weeks have passed since that date. If all went well, baby is already in the world.',
112
120
  faqTitle: 'Frequently asked questions',
113
121
  bibliographyTitle: 'References',
114
122
  },
@@ -109,6 +109,14 @@ export const content: PregnancyCalculatorLocaleContent = {
109
109
  labelTimeline: 'Línea de tiempo',
110
110
  labelStartHere: 'Empieza aquí',
111
111
  labelStartBody: 'Selecciona la fecha de tu última regla y descubre en qué semana estás.',
112
+ labelSem: 'Sem',
113
+ labelWeekBadge: 'Semana',
114
+ weeksFormat: '{w}s {d}d',
115
+ trimesterSuffix: 'º',
116
+ eggFutureTitle: 'Viajera en el tiempo detectada',
117
+ eggFutureBody: 'Esa fecha aún no ha llegado. Vuelve cuando la realidad te alcance.',
118
+ eggTooOldTitle: 'Fecha caducada',
119
+ eggTooOldBody: 'Han pasado más de 40 semanas desde esa fecha. Si todo fue bien, ya es mundo exterior.',
112
120
  faqTitle: 'Preguntas frecuentes',
113
121
  bibliographyTitle: 'Referencias',
114
122
  },
@@ -109,6 +109,14 @@ export const content: PregnancyCalculatorLocaleContent = {
109
109
  labelTimeline: 'Chronologie',
110
110
  labelStartHere: 'Commencez ici',
111
111
  labelStartBody: 'Sélectionnez la date de vos dernières règles pour découvrir à quelle semaine vous en êtes.',
112
+ labelSem: 'Sem',
113
+ labelWeekBadge: 'Semaine',
114
+ weeksFormat: '{w}s {d}j',
115
+ trimesterSuffix: 'e',
116
+ eggFutureTitle: 'Voyageuse temporelle détectée',
117
+ eggFutureBody: 'Cette date n\'est pas encore arrivée. Revenez quand la réalité vous rattrapera.',
118
+ eggTooOldTitle: 'Date expirée',
119
+ eggTooOldBody: 'Plus de 40 semaines se sont écoulées depuis cette date. Si tout s\'est bien passé, bébé est déjà dans le monde.',
112
120
  faqTitle: 'Questions fréquentes',
113
121
  bibliographyTitle: 'Références',
114
122
  },
@@ -29,6 +29,14 @@ export interface PregnancyCalculatorUI {
29
29
  labelTimeline: string;
30
30
  labelStartHere: string;
31
31
  labelStartBody: string;
32
+ labelSem: string;
33
+ labelWeekBadge: string;
34
+ weeksFormat: string;
35
+ trimesterSuffix: string;
36
+ eggFutureTitle: string;
37
+ eggFutureBody: string;
38
+ eggTooOldTitle: string;
39
+ eggTooOldBody: string;
32
40
  faqTitle: string;
33
41
  bibliographyTitle: string;
34
42
  }