@roxyapi/ui 0.18.1 → 0.18.3

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.3";
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.3",
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",
@@ -239,7 +239,8 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
239
239
  * Which dasha endpoint fed this element. `sub`, `antara` and `sookshma` are the
240
240
  * three drill-down levels and render identically; they stay distinct because
241
241
  * each maps one-to-one onto its endpoint binding, which is what lets a widget
242
- * pick a level. The LABELS come from the payload, not from here.
242
+ * pick a level. The heading and the level LABELS come from the payload, not
243
+ * from here, so a host that cannot set attributes still renders correctly.
243
244
  */
244
245
  @property({ type: String, reflect: true })
245
246
  period: 'current' | 'major' | 'sub' | 'antara' | 'sookshma' = 'current';
@@ -248,11 +249,6 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
248
249
  @state()
249
250
  private view: 'timeline' | 'readings' | 'frame' = 'timeline';
250
251
 
251
- /** True for any of the drill-down levels, which share one layout. */
252
- private get isDrillDown(): boolean {
253
- return this.period !== 'current' && this.period !== 'major';
254
- }
255
-
256
252
  protected renderEmpty() {
257
253
  return html`<div class="roxy-empty" role="status">No dasha data</div>`;
258
254
  }
@@ -314,7 +310,7 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
314
310
  ${
315
311
  periods.length > 0
316
312
  ? html`<div class="timeline" role="list">
317
- ${periods.map((p) => this.renderBar(p, maxYears))}
313
+ ${periods.map((p) => this.renderBar(p, maxYears, grainFor(maxYears)))}
318
314
  </div>`
319
315
  : nothing
320
316
  }`
@@ -412,16 +408,25 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
412
408
  </dl>`;
413
409
  }
414
410
 
411
+ /**
412
+ * Heading, decided by the PAYLOAD first and the `period` attribute only as a
413
+ * tie-break.
414
+ *
415
+ * Not every host can set the attribute. The WordPress plugin maps an
416
+ * operationId to a bare component tag with no attrs, so every dasha shortcode
417
+ * arrives with the default `period="current"`; keying off the attribute alone
418
+ * titled an antardasha list "Active dashas" there. A drill-down response is
419
+ * self-identifying (it carries a parent period), so the markup does not need
420
+ * to be told.
421
+ */
415
422
  private heading(d: DashaData): string {
416
- if (this.period === 'major') return 'Vimshottari Mahadasha';
417
- if (this.isDrillDown) {
418
- const parent = parentOf(d);
419
- const level = levelOf(d);
420
- return parent
421
- ? `${level}s in ${parent.period.planet} ${parent.label}`
422
- : `${level}s`;
423
+ const parent = parentOf(d);
424
+ if (parent) {
425
+ return `${levelOf(d)}s in ${parent.period.planet} ${parent.label}`;
423
426
  }
424
- return 'Active dashas';
427
+ if ('mahadashas' in d) return 'Vimshottari Mahadasha';
428
+ if ('mahadasha' in d) return 'Active dashas';
429
+ return this.period === 'major' ? 'Vimshottari Mahadasha' : 'Active dashas';
425
430
  }
426
431
 
427
432
  /**
@@ -562,7 +567,7 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
562
567
  return (now - start) / (end - start);
563
568
  }
564
569
 
565
- private renderBar(p: DashaPeriod, max: number) {
570
+ private renderBar(p: DashaPeriod, max: number, grain: DateGrain) {
566
571
  const years = p.durationYears;
567
572
  const width = max > 0 ? (years / max) * 100 : 0;
568
573
  const current = this.isCurrent(p);
@@ -589,16 +594,44 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
589
594
  }
590
595
  </span>
591
596
  <span class="dates">
592
- ${p.startDate ? formatYear(p.startDate) : ''}
593
- ${p.endDate ? html`- ${formatYear(p.endDate)}` : ''}
597
+ ${p.startDate ? formatBoundary(p.startDate, grain) : ''}
598
+ ${p.endDate ? html`- ${formatBoundary(p.endDate, grain)}` : ''}
594
599
  </span>
595
600
  </div>`;
596
601
  }
597
602
  }
598
603
 
599
- function formatYear(s: string): string {
600
- const m = s.match(/^(\d{4})/);
601
- return m ? m[1] : s;
604
+ /**
605
+ * How precise the bar date column has to be, chosen from the LONGEST period in
606
+ * the set.
607
+ *
608
+ * A Mahadasha spans years, so a bare year reads cleanly and keeps the column
609
+ * narrow. A Sookshma spans days: printed as a year, every one of the nine rows
610
+ * reads "1990 - 1990" and the column carries no information at exactly the level
611
+ * a reader opened the drill-down to see.
612
+ */
613
+ type DateGrain = 'year' | 'month' | 'day';
614
+
615
+ const DAYS_PER_YEAR = 365.25;
616
+
617
+ function grainFor(maxYears: number): DateGrain {
618
+ if (maxYears >= 2) return 'year';
619
+ if (maxYears >= 60 / DAYS_PER_YEAR) return 'month';
620
+ return 'day';
621
+ }
622
+
623
+ /** 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. */
624
+ function formatBoundary(s: string, grain: DateGrain): string {
625
+ if (grain === 'year') {
626
+ const m = s.match(/^(\d{4})/);
627
+ return m ? m[1] : s;
628
+ }
629
+ const d = new Date(s);
630
+ if (Number.isNaN(d.getTime())) return s;
631
+ const month = d.toLocaleString('en', { month: 'short' });
632
+ return grain === 'month'
633
+ ? `${month} ${d.getFullYear()}`
634
+ : `${d.getDate()} ${month}`;
602
635
  }
603
636
 
604
637
  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.3';