@roxyapi/ui 0.18.1 → 0.18.2

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/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const ROXY_UI_VERSION = "0.18.1";
1
+ export declare const ROXY_UI_VERSION = "0.18.2";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roxyapi/ui",
3
- "version": "0.18.1",
3
+ "version": "0.18.2",
4
4
  "description": "Web components for the RoxyAPI catalog. Drop-in charts, tables, cards, forms for astrology, tarot, numerology, biorhythm, I Ching, crystals, dreams, angel numbers, and more. One key, beautiful in 30 minutes.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -314,7 +314,7 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
314
314
  ${
315
315
  periods.length > 0
316
316
  ? html`<div class="timeline" role="list">
317
- ${periods.map((p) => this.renderBar(p, maxYears))}
317
+ ${periods.map((p) => this.renderBar(p, maxYears, grainFor(maxYears)))}
318
318
  </div>`
319
319
  : nothing
320
320
  }`
@@ -562,7 +562,7 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
562
562
  return (now - start) / (end - start);
563
563
  }
564
564
 
565
- private renderBar(p: DashaPeriod, max: number) {
565
+ private renderBar(p: DashaPeriod, max: number, grain: DateGrain) {
566
566
  const years = p.durationYears;
567
567
  const width = max > 0 ? (years / max) * 100 : 0;
568
568
  const current = this.isCurrent(p);
@@ -589,16 +589,44 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
589
589
  }
590
590
  </span>
591
591
  <span class="dates">
592
- ${p.startDate ? formatYear(p.startDate) : ''}
593
- ${p.endDate ? html`- ${formatYear(p.endDate)}` : ''}
592
+ ${p.startDate ? formatBoundary(p.startDate, grain) : ''}
593
+ ${p.endDate ? html`- ${formatBoundary(p.endDate, grain)}` : ''}
594
594
  </span>
595
595
  </div>`;
596
596
  }
597
597
  }
598
598
 
599
- function formatYear(s: string): string {
600
- const m = s.match(/^(\d{4})/);
601
- return m ? m[1] : s;
599
+ /**
600
+ * How precise the bar date column has to be, chosen from the LONGEST period in
601
+ * the set.
602
+ *
603
+ * A Mahadasha spans years, so a bare year reads cleanly and keeps the column
604
+ * narrow. A Sookshma spans days: printed as a year, every one of the nine rows
605
+ * reads "1990 - 1990" and the column carries no information at exactly the level
606
+ * a reader opened the drill-down to see.
607
+ */
608
+ type DateGrain = 'year' | 'month' | 'day';
609
+
610
+ const DAYS_PER_YEAR = 365.25;
611
+
612
+ function grainFor(maxYears: number): DateGrain {
613
+ if (maxYears >= 2) return 'year';
614
+ if (maxYears >= 60 / DAYS_PER_YEAR) return 'month';
615
+ return 'day';
616
+ }
617
+
618
+ /** One end of a bar, at the chosen granularity. Day grain drops the year: these rows sit under a parent line that already states it, and the column is only 8rem wide. */
619
+ function formatBoundary(s: string, grain: DateGrain): string {
620
+ if (grain === 'year') {
621
+ const m = s.match(/^(\d{4})/);
622
+ return m ? m[1] : s;
623
+ }
624
+ const d = new Date(s);
625
+ if (Number.isNaN(d.getTime())) return s;
626
+ const month = d.toLocaleString('en', { month: 'short' });
627
+ return grain === 'month'
628
+ ? `${month} ${d.getFullYear()}`
629
+ : `${d.getDate()} ${month}`;
602
630
  }
603
631
 
604
632
  declare global {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/sync-version.ts. Do not edit.
2
- export const ROXY_UI_VERSION = '0.18.1';
2
+ export const ROXY_UI_VERSION = '0.18.2';