@roxyapi/ui 0.4.1 → 0.6.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 (235) hide show
  1. package/AGENTS.md +21 -0
  2. package/README.md +17 -1
  3. package/dist/cdn/components/ashtakavarga-grid.js +3 -362
  4. package/dist/cdn/components/ashtakavarga-grid.js.map +4 -4
  5. package/dist/cdn/components/biorhythm-chart.js +3 -226
  6. package/dist/cdn/components/biorhythm-chart.js.map +4 -4
  7. package/dist/cdn/components/choghadiya-grid.js +3 -232
  8. package/dist/cdn/components/choghadiya-grid.js.map +4 -4
  9. package/dist/cdn/components/compatibility-card.js +3 -231
  10. package/dist/cdn/components/compatibility-card.js.map +4 -4
  11. package/dist/cdn/components/dasha-timeline.js +3 -283
  12. package/dist/cdn/components/dasha-timeline.js.map +4 -4
  13. package/dist/cdn/components/data.js +3 -230
  14. package/dist/cdn/components/data.js.map +4 -4
  15. package/dist/cdn/components/divisional-chart.js +3 -356
  16. package/dist/cdn/components/divisional-chart.js.map +4 -4
  17. package/dist/cdn/components/dosha-card.js +3 -226
  18. package/dist/cdn/components/dosha-card.js.map +4 -4
  19. package/dist/cdn/components/endpoint-form.js +2 -243
  20. package/dist/cdn/components/endpoint-form.js.map +2 -2
  21. package/dist/cdn/components/guna-milan.js +3 -270
  22. package/dist/cdn/components/guna-milan.js.map +4 -4
  23. package/dist/cdn/components/hexagram.js +3 -247
  24. package/dist/cdn/components/hexagram.js.map +4 -4
  25. package/dist/cdn/components/horoscope-card.js +3 -281
  26. package/dist/cdn/components/horoscope-card.js.map +4 -4
  27. package/dist/cdn/components/kp-chart.js +3 -278
  28. package/dist/cdn/components/kp-chart.js.map +4 -4
  29. package/dist/cdn/components/kp-planets-table.js +3 -196
  30. package/dist/cdn/components/kp-planets-table.js.map +4 -4
  31. package/dist/cdn/components/kp-ruling-planets.js +3 -241
  32. package/dist/cdn/components/kp-ruling-planets.js.map +4 -4
  33. package/dist/cdn/components/location-search.js +2 -240
  34. package/dist/cdn/components/location-search.js.map +2 -2
  35. package/dist/cdn/components/moon-phase.js +3 -223
  36. package/dist/cdn/components/moon-phase.js.map +4 -4
  37. package/dist/cdn/components/nakshatra-card.js +3 -201
  38. package/dist/cdn/components/nakshatra-card.js.map +4 -4
  39. package/dist/cdn/components/natal-chart.js +3 -563
  40. package/dist/cdn/components/natal-chart.js.map +4 -4
  41. package/dist/cdn/components/numerology-card.js +3 -233
  42. package/dist/cdn/components/numerology-card.js.map +4 -4
  43. package/dist/cdn/components/panchang-table.js +3 -220
  44. package/dist/cdn/components/panchang-table.js.map +4 -4
  45. package/dist/cdn/components/shadbala-table.js +3 -284
  46. package/dist/cdn/components/shadbala-table.js.map +4 -4
  47. package/dist/cdn/components/synastry-chart.js +3 -399
  48. package/dist/cdn/components/synastry-chart.js.map +4 -4
  49. package/dist/cdn/components/tarot-card.js +3 -261
  50. package/dist/cdn/components/tarot-card.js.map +4 -4
  51. package/dist/cdn/components/tarot-spread.js +3 -249
  52. package/dist/cdn/components/tarot-spread.js.map +4 -4
  53. package/dist/cdn/components/transits-table.js +3 -382
  54. package/dist/cdn/components/transits-table.js.map +4 -4
  55. package/dist/cdn/components/vedic-kundli.js +3 -305
  56. package/dist/cdn/components/vedic-kundli.js.map +4 -4
  57. package/dist/cdn/components/vedic-planets-table.js +3 -203
  58. package/dist/cdn/components/vedic-planets-table.js.map +4 -4
  59. package/dist/cdn/components/western-planets-table.js +3 -192
  60. package/dist/cdn/components/western-planets-table.js.map +4 -4
  61. package/dist/cdn/components/yoga-list.js +3 -306
  62. package/dist/cdn/components/yoga-list.js.map +4 -4
  63. package/dist/cdn/roxy-ui.js +3 -5102
  64. package/dist/cdn/roxy-ui.js.map +4 -4
  65. package/dist/cdn/widgets.js +1 -114
  66. package/dist/components/ashtakavarga-grid.d.ts +1 -0
  67. package/dist/components/ashtakavarga-grid.d.ts.map +1 -1
  68. package/dist/components/ashtakavarga-grid.js +1 -531
  69. package/dist/components/ashtakavarga-grid.js.map +4 -4
  70. package/dist/components/biorhythm-chart.d.ts +1 -0
  71. package/dist/components/biorhythm-chart.d.ts.map +1 -1
  72. package/dist/components/biorhythm-chart.js +1 -332
  73. package/dist/components/biorhythm-chart.js.map +4 -4
  74. package/dist/components/choghadiya-grid.d.ts +1 -0
  75. package/dist/components/choghadiya-grid.d.ts.map +1 -1
  76. package/dist/components/choghadiya-grid.js +1 -351
  77. package/dist/components/choghadiya-grid.js.map +4 -4
  78. package/dist/components/compatibility-card.d.ts +1 -0
  79. package/dist/components/compatibility-card.d.ts.map +1 -1
  80. package/dist/components/compatibility-card.js +1 -313
  81. package/dist/components/compatibility-card.js.map +4 -4
  82. package/dist/components/dasha-timeline.d.ts +1 -0
  83. package/dist/components/dasha-timeline.d.ts.map +1 -1
  84. package/dist/components/dasha-timeline.js +1 -401
  85. package/dist/components/dasha-timeline.js.map +4 -4
  86. package/dist/components/data.d.ts +1 -0
  87. package/dist/components/data.d.ts.map +1 -1
  88. package/dist/components/data.js +1 -362
  89. package/dist/components/data.js.map +4 -4
  90. package/dist/components/divisional-chart.d.ts +1 -0
  91. package/dist/components/divisional-chart.d.ts.map +1 -1
  92. package/dist/components/divisional-chart.js +1 -886
  93. package/dist/components/divisional-chart.js.map +4 -4
  94. package/dist/components/dosha-card.d.ts +1 -0
  95. package/dist/components/dosha-card.d.ts.map +1 -1
  96. package/dist/components/dosha-card.js +1 -293
  97. package/dist/components/dosha-card.js.map +4 -4
  98. package/dist/components/endpoint-form.js +1 -505
  99. package/dist/components/endpoint-form.js.map +3 -3
  100. package/dist/components/guna-milan.d.ts +1 -0
  101. package/dist/components/guna-milan.d.ts.map +1 -1
  102. package/dist/components/guna-milan.js +1 -374
  103. package/dist/components/guna-milan.js.map +4 -4
  104. package/dist/components/hexagram.d.ts +1 -0
  105. package/dist/components/hexagram.d.ts.map +1 -1
  106. package/dist/components/hexagram.js +1 -380
  107. package/dist/components/hexagram.js.map +4 -4
  108. package/dist/components/horoscope-card.d.ts +1 -0
  109. package/dist/components/horoscope-card.d.ts.map +1 -1
  110. package/dist/components/horoscope-card.js +1 -381
  111. package/dist/components/horoscope-card.js.map +4 -4
  112. package/dist/components/kp-chart.d.ts +1 -0
  113. package/dist/components/kp-chart.d.ts.map +1 -1
  114. package/dist/components/kp-chart.js +1 -395
  115. package/dist/components/kp-chart.js.map +4 -4
  116. package/dist/components/kp-planets-table.d.ts +1 -0
  117. package/dist/components/kp-planets-table.d.ts.map +1 -1
  118. package/dist/components/kp-planets-table.js +1 -246
  119. package/dist/components/kp-planets-table.js.map +4 -4
  120. package/dist/components/kp-ruling-planets.d.ts +1 -0
  121. package/dist/components/kp-ruling-planets.d.ts.map +1 -1
  122. package/dist/components/kp-ruling-planets.js +1 -288
  123. package/dist/components/kp-ruling-planets.js.map +4 -4
  124. package/dist/components/location-search.js +1 -461
  125. package/dist/components/location-search.js.map +3 -3
  126. package/dist/components/moon-phase.d.ts +1 -0
  127. package/dist/components/moon-phase.d.ts.map +1 -1
  128. package/dist/components/moon-phase.js +1 -327
  129. package/dist/components/moon-phase.js.map +4 -4
  130. package/dist/components/nakshatra-card.d.ts +1 -0
  131. package/dist/components/nakshatra-card.d.ts.map +1 -1
  132. package/dist/components/nakshatra-card.js +1 -244
  133. package/dist/components/nakshatra-card.js.map +4 -4
  134. package/dist/components/natal-chart.d.ts +1 -1
  135. package/dist/components/natal-chart.d.ts.map +1 -1
  136. package/dist/components/natal-chart.js +1 -1040
  137. package/dist/components/natal-chart.js.map +4 -4
  138. package/dist/components/numerology-card.d.ts +1 -0
  139. package/dist/components/numerology-card.d.ts.map +1 -1
  140. package/dist/components/numerology-card.js +1 -315
  141. package/dist/components/numerology-card.js.map +4 -4
  142. package/dist/components/panchang-table.d.ts +1 -0
  143. package/dist/components/panchang-table.d.ts.map +1 -1
  144. package/dist/components/panchang-table.js +1 -350
  145. package/dist/components/panchang-table.js.map +4 -4
  146. package/dist/components/shadbala-table.d.ts +1 -0
  147. package/dist/components/shadbala-table.d.ts.map +1 -1
  148. package/dist/components/shadbala-table.js +1 -413
  149. package/dist/components/shadbala-table.js.map +4 -4
  150. package/dist/components/synastry-chart.d.ts +1 -0
  151. package/dist/components/synastry-chart.d.ts.map +1 -1
  152. package/dist/components/synastry-chart.js +1 -658
  153. package/dist/components/synastry-chart.js.map +4 -4
  154. package/dist/components/tarot-card.d.ts +1 -0
  155. package/dist/components/tarot-card.d.ts.map +1 -1
  156. package/dist/components/tarot-card.js +1 -333
  157. package/dist/components/tarot-card.js.map +4 -4
  158. package/dist/components/tarot-spread.d.ts +1 -0
  159. package/dist/components/tarot-spread.d.ts.map +1 -1
  160. package/dist/components/tarot-spread.js +1 -310
  161. package/dist/components/tarot-spread.js.map +4 -4
  162. package/dist/components/transits-table.d.ts +3 -0
  163. package/dist/components/transits-table.d.ts.map +1 -1
  164. package/dist/components/transits-table.js +1 -548
  165. package/dist/components/transits-table.js.map +4 -4
  166. package/dist/components/vedic-kundli.d.ts +1 -0
  167. package/dist/components/vedic-kundli.d.ts.map +1 -1
  168. package/dist/components/vedic-kundli.js +1 -802
  169. package/dist/components/vedic-kundli.js.map +4 -4
  170. package/dist/components/vedic-planets-table.d.ts +1 -0
  171. package/dist/components/vedic-planets-table.d.ts.map +1 -1
  172. package/dist/components/vedic-planets-table.js +1 -368
  173. package/dist/components/vedic-planets-table.js.map +4 -4
  174. package/dist/components/western-planets-table.d.ts +1 -0
  175. package/dist/components/western-planets-table.d.ts.map +1 -1
  176. package/dist/components/western-planets-table.js +1 -363
  177. package/dist/components/western-planets-table.js.map +4 -4
  178. package/dist/components/yoga-list.d.ts +1 -0
  179. package/dist/components/yoga-list.d.ts.map +1 -1
  180. package/dist/components/yoga-list.js +1 -383
  181. package/dist/components/yoga-list.js.map +4 -4
  182. package/dist/index.cjs +1 -8653
  183. package/dist/index.cjs.map +4 -4
  184. package/dist/index.js +1 -8633
  185. package/dist/index.js.map +4 -4
  186. package/dist/types/index.d.ts +1 -1
  187. package/dist/types/index.d.ts.map +1 -1
  188. package/dist/types/types.gen.d.ts +590 -202
  189. package/dist/types/types.gen.d.ts.map +1 -1
  190. package/dist/utils/disclosure.d.ts +16 -0
  191. package/dist/utils/disclosure.d.ts.map +1 -0
  192. package/dist/utils/kundli-render.d.ts.map +1 -1
  193. package/dist/utils/kundli-styles.d.ts.map +1 -1
  194. package/dist/utils/markup-data.d.ts +57 -0
  195. package/dist/utils/markup-data.d.ts.map +1 -0
  196. package/dist/utils/tablist.d.ts +44 -0
  197. package/dist/utils/tablist.d.ts.map +1 -0
  198. package/dist/version.d.ts +1 -1
  199. package/package.json +3 -1
  200. package/src/components/ashtakavarga-grid.ts +9 -0
  201. package/src/components/biorhythm-chart.ts +9 -0
  202. package/src/components/choghadiya-grid.ts +9 -0
  203. package/src/components/compatibility-card.ts +9 -0
  204. package/src/components/dasha-timeline.ts +19 -1
  205. package/src/components/data.ts +9 -0
  206. package/src/components/divisional-chart.ts +11 -0
  207. package/src/components/dosha-card.ts +9 -0
  208. package/src/components/guna-milan.ts +9 -0
  209. package/src/components/hexagram.ts +9 -0
  210. package/src/components/horoscope-card.ts +9 -0
  211. package/src/components/kp-chart.ts +9 -0
  212. package/src/components/kp-planets-table.ts +9 -0
  213. package/src/components/kp-ruling-planets.ts +9 -0
  214. package/src/components/moon-phase.ts +9 -0
  215. package/src/components/nakshatra-card.ts +9 -0
  216. package/src/components/natal-chart.ts +46 -62
  217. package/src/components/numerology-card.ts +9 -0
  218. package/src/components/panchang-table.ts +9 -0
  219. package/src/components/shadbala-table.ts +9 -0
  220. package/src/components/synastry-chart.ts +9 -0
  221. package/src/components/tarot-card.ts +9 -0
  222. package/src/components/tarot-spread.ts +9 -0
  223. package/src/components/transits-table.ts +54 -18
  224. package/src/components/vedic-kundli.ts +11 -1
  225. package/src/components/vedic-planets-table.ts +9 -0
  226. package/src/components/western-planets-table.ts +9 -0
  227. package/src/components/yoga-list.ts +9 -0
  228. package/src/types/index.ts +1 -1
  229. package/src/types/types.gen.ts +602 -200
  230. package/src/utils/disclosure.ts +62 -0
  231. package/src/utils/kundli-render.ts +21 -35
  232. package/src/utils/kundli-styles.ts +0 -31
  233. package/src/utils/markup-data.ts +115 -0
  234. package/src/utils/tablist.ts +124 -0
  235. package/src/version.ts +1 -1
@@ -0,0 +1,62 @@
1
+ import type { TemplateResult } from 'lit';
2
+ import { css, html } from 'lit';
3
+
4
+ /**
5
+ * Disclosure chevron for `<details>`/`<summary>` accordions. Replaces the
6
+ * browser default triangle with a thin chevron that rotates when the host
7
+ * `<details>` opens. Render it inside the `<summary>` and pair with
8
+ * {@link disclosureStyles}.
9
+ */
10
+ export function chevron(): TemplateResult {
11
+ return html`<svg
12
+ class="roxy-chevron"
13
+ viewBox="0 0 16 16"
14
+ width="14"
15
+ height="14"
16
+ aria-hidden="true"
17
+ >
18
+ <path
19
+ d="M4 6l4 4 4-4"
20
+ fill="none"
21
+ stroke="currentColor"
22
+ stroke-width="1.5"
23
+ stroke-linecap="round"
24
+ stroke-linejoin="round"
25
+ />
26
+ </svg>`;
27
+ }
28
+
29
+ /**
30
+ * Shared `<details>` accordion styling: hides the native disclosure triangle
31
+ * and rotates the {@link chevron} 180 degrees when the accordion is open.
32
+ * Import into any component that renders disclosure accordions so the chevron
33
+ * looks and behaves identically.
34
+ */
35
+ export const disclosureStyles = css`
36
+ summary {
37
+ list-style: none;
38
+ }
39
+ summary::-webkit-details-marker {
40
+ display: none;
41
+ }
42
+ /* Explicit size: components that draw a chart set a global svg { width: 100% }
43
+ rule, and an element selector beats the SVG width/height attributes. This
44
+ class selector wins back the 14px icon size. */
45
+ .roxy-chevron {
46
+ flex-shrink: 0;
47
+ width: 14px;
48
+ height: 14px;
49
+ aspect-ratio: auto;
50
+ color: var(--roxy-muted, #71717a);
51
+ transition: transform var(--roxy-motion-duration, 200ms)
52
+ var(--roxy-motion-easing, ease);
53
+ }
54
+ details[open] > summary .roxy-chevron {
55
+ transform: rotate(180deg);
56
+ }
57
+ @media (prefers-reduced-motion: reduce) {
58
+ .roxy-chevron {
59
+ transition: none;
60
+ }
61
+ }
62
+ `;
@@ -1,8 +1,9 @@
1
1
  import type { TemplateResult } from 'lit';
2
- import { html, nothing, svg } from 'lit';
2
+ import { nothing, svg } from 'lit';
3
3
  import { PLANET_ABBR, SIGN_ABBR, SIGNS_ORDER } from '../tokens/index.js';
4
4
  import { longitudeToSignPosition } from './degree.js';
5
5
  import { capitalize } from './string.js';
6
+ import { renderTablist } from './tablist.js';
6
7
 
7
8
  /**
8
9
  * Canonical viewBox geometry for every kundli style. The chart is drawn into a
@@ -320,6 +321,11 @@ function renderSouthCell(
320
321
  ? svg`<text class="house-num" x=${r.x + r.w - 6} y=${r.y + 12} text-anchor="end" dominant-baseline="central">${houseNum}</text>`
321
322
  : nothing
322
323
  }
324
+ ${
325
+ isLagna
326
+ ? svg`<text class="lagna-marker" x=${cx} y=${r.y + 26} text-anchor="middle" dominant-baseline="central">Asc</text>`
327
+ : nothing
328
+ }
323
329
  ${planets.length ? renderPlanetStack(planets, sign, cx, cy + 4, 14) : nothing}
324
330
  </g>
325
331
  `;
@@ -453,9 +459,15 @@ function renderNorthCell(
453
459
  // always stays comfortably inside its triangle or diamond.
454
460
  const rashiOffsetY = Math.min(14, Math.abs(c.y - CENTRE) * 0.45 + 6);
455
461
  const ascOffsetY = rashiOffsetY + 12;
462
+ // North cells carry only a rasi number by convention. The ascendant also
463
+ // names its sign so the reader can see which sign rises without translating
464
+ // the number; other cells stay number-only.
465
+ const rashiLabel = isLagna
466
+ ? `${rashiNum} · ${SIGN_ABBR[sign] ?? sign.slice(0, 2)}`
467
+ : `${rashiNum}`;
456
468
  return svg`
457
469
  <g class=${isLagna ? 'cell lagna' : 'cell'}>
458
- <text class="rashi-num" x=${c.x} y=${c.y - rashiOffsetY} text-anchor="middle" dominant-baseline="central">${rashiNum}</text>
470
+ <text class="rashi-num" x=${c.x} y=${c.y - rashiOffsetY} text-anchor="middle" dominant-baseline="central">${rashiLabel}</text>
459
471
  ${
460
472
  isLagna
461
473
  ? svg`<text class="lagna-marker" x=${c.x} y=${c.y - ascOffsetY} text-anchor="middle" dominant-baseline="central">Asc</text>`
@@ -705,37 +717,11 @@ export function renderKundliStyleTablist(
705
717
  active: ChartStyle,
706
718
  setStyle: (next: ChartStyle) => void,
707
719
  ): TemplateResult {
708
- const onKeyDown = (e: KeyboardEvent) => {
709
- const idx = CHART_STYLES.findIndex((s) => s.id === active);
710
- if (e.key === 'ArrowRight') {
711
- e.preventDefault();
712
- const next = CHART_STYLES[(idx + 1) % CHART_STYLES.length];
713
- if (next) setStyle(next.id);
714
- } else if (e.key === 'ArrowLeft') {
715
- e.preventDefault();
716
- const next =
717
- CHART_STYLES[(idx - 1 + CHART_STYLES.length) % CHART_STYLES.length];
718
- if (next) setStyle(next.id);
719
- }
720
- };
721
- return html`<div
722
- class="kundli-tablist"
723
- role="tablist"
724
- aria-label="Kundli style"
725
- @keydown=${onKeyDown}
726
- >
727
- ${CHART_STYLES.map(
728
- (s) => html`<button
729
- type="button"
730
- class="kundli-tab"
731
- role="tab"
732
- id="kundli-tab-${s.id}"
733
- aria-selected=${active === s.id ? 'true' : 'false'}
734
- tabindex=${active === s.id ? '0' : '-1'}
735
- @click=${() => setStyle(s.id)}
736
- >
737
- ${s.label}
738
- </button>`,
739
- )}
740
- </div>`;
720
+ return renderTablist({
721
+ items: CHART_STYLES,
722
+ active,
723
+ onSelect: setStyle,
724
+ label: 'Kundli style',
725
+ idPrefix: 'kundli',
726
+ });
741
727
  }
@@ -28,37 +28,6 @@ export const kundliStyles = css`
28
28
  font-weight: var(--roxy-weight-bold, 600);
29
29
  margin: 0;
30
30
  }
31
- .kundli-tablist {
32
- display: inline-flex;
33
- gap: 2px;
34
- border-bottom: 2px solid var(--roxy-border, #e4e4e7);
35
- }
36
- .kundli-tab {
37
- padding: var(--roxy-space-xs, 0.25rem) var(--roxy-space-md, 1rem);
38
- font-size: var(--roxy-text-sm, 0.875rem);
39
- background: none;
40
- border: none;
41
- border-bottom: 2px solid transparent;
42
- margin-bottom: -2px;
43
- cursor: pointer;
44
- color: var(--roxy-muted, #71717a);
45
- font-family: inherit;
46
- transition: color var(--roxy-motion-duration, 200ms)
47
- var(--roxy-motion-easing, ease);
48
- }
49
- .kundli-tab[aria-selected='true'] {
50
- color: var(--roxy-accent-fg, #b45309);
51
- border-bottom-color: var(--roxy-accent, #f59e0b);
52
- font-weight: var(--roxy-weight-bold, 600);
53
- }
54
- .kundli-tab:hover:not([aria-selected='true']) {
55
- color: var(--roxy-fg, #0a0a0a);
56
- }
57
- .kundli-tab:focus-visible {
58
- outline: 2px solid var(--roxy-ring, rgba(245, 158, 11, 0.4));
59
- outline-offset: 2px;
60
- border-radius: 4px;
61
- }
62
31
  svg {
63
32
  display: block;
64
33
  width: 100%;
@@ -0,0 +1,115 @@
1
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
2
+
3
+ /**
4
+ * Marker class on the inline JSON script a server emits inside a component.
5
+ *
6
+ * @example
7
+ * ```html
8
+ * <roxy-natal-chart>
9
+ * <script type="application/json" class="roxy-data">{ ...response... }</script>
10
+ * </roxy-natal-chart>
11
+ * ```
12
+ */
13
+ const ROXY_DATA_CLASS = 'roxy-data';
14
+
15
+ /**
16
+ * True when the element is a `<script type="application/json">`. Uses tag name and attribute rather than `instanceof HTMLScriptElement` so the check holds in every DOM implementation, including server-rendered and hydration runtimes where the constructor global may be absent.
17
+ */
18
+ function isJsonScript(el: Element): boolean {
19
+ return (
20
+ el.nodeName === 'SCRIPT' && el.getAttribute('type') === 'application/json'
21
+ );
22
+ }
23
+
24
+ /**
25
+ * Host shape the controller drives: any reactive element that exposes a public `data` slot. The controller only writes `data` when the host left it unset, so the JavaScript property path always wins.
26
+ */
27
+ interface DataHost extends ReactiveControllerHost, HTMLElement {
28
+ data?: unknown;
29
+ }
30
+
31
+ /**
32
+ * Reactive controller that lets a component hydrate its `data` from embedded markup when no `data` property was assigned in JavaScript.
33
+ *
34
+ * @remarks
35
+ * The server-side and cached-render model: a backend renders the RoxyAPI response into a direct-child `<script type="application/json" class="roxy-data">` element, ships static HTML, and never runs per-element JavaScript to assign a property. On connect this controller reads that script, parses it, and feeds the result to the host. The JavaScript property path is untouched and authoritative: if `host.data` already holds a value when the host connects, the controller does nothing and the markup is ignored.
36
+ *
37
+ * Source resolution order on connect, first hit wins:
38
+ *
39
+ * 1. `host.data` already set in JavaScript -> leave it, read nothing.
40
+ * 2. A direct-child `<script type="application/json" class="roxy-data">` -> parse and use. Direct-child only, so a nested component's own script is never read by an ancestor.
41
+ *
42
+ * Fetching from a URL is intentionally unsupported: that would require a browser-visible key and breaks the server-rendered, cached model these consumers rely on.
43
+ *
44
+ * Timing: {@link hostConnected} runs inside the host `connectedCallback`. For an element parsed from server HTML, its direct children are present by the time the custom element upgrades and connects, so the script is readable here. For an element created with `document.createElement` and connected before any child is appended, there is nothing to read and the property path is the only source, which is exactly the existing behavior.
45
+ *
46
+ * Failure is safe: malformed JSON or a missing script leaves `host.data` untouched, so the host renders its normal empty state.
47
+ *
48
+ * Reading the script never mutates it, and only the marked script is touched, so any sibling fallback markup a server nested inside the element (for no-JavaScript, AMP, or crawler rendering) is left in place.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * import { MarkupDataController } from '../utils/markup-data.js';
53
+ *
54
+ * export class RoxyExample extends LitElement {
55
+ * constructor() {
56
+ * super();
57
+ * new MarkupDataController(this);
58
+ * }
59
+ *
60
+ * @property({ attribute: false })
61
+ * data: ExampleResponse | null = null;
62
+ * }
63
+ * ```
64
+ */
65
+ export class MarkupDataController<T = unknown> implements ReactiveController {
66
+ private readonly host: DataHost;
67
+
68
+ constructor(host: DataHost) {
69
+ this.host = host;
70
+ host.addController(this);
71
+ }
72
+
73
+ hostConnected() {
74
+ // Property path wins. If the consumer (React, vanilla `.data =`, the
75
+ // widgets script, an MCP agent) already set data, never look at markup.
76
+ if (this.host.data != null) return;
77
+
78
+ const parsed = this.read();
79
+ if (parsed === undefined) return;
80
+
81
+ this.host.data = parsed as T;
82
+ this.host.requestUpdate();
83
+ }
84
+
85
+ /**
86
+ * Resolve the embedded payload. Returns `undefined` when there is nothing valid to read so the caller can leave `host.data` untouched.
87
+ */
88
+ private read(): T | undefined {
89
+ const inline = this.findInlineScript();
90
+ return inline ? this.parse(inline.textContent) : undefined;
91
+ }
92
+
93
+ /**
94
+ * Direct-child `<script type="application/json" class="roxy-data">`. Scoped to immediate children so a nested data-driven component never has its script read by an ancestor, and so sibling fallback markup is ignored.
95
+ */
96
+ private findInlineScript(): Element | null {
97
+ for (const child of Array.from(this.host.children)) {
98
+ if (isJsonScript(child) && child.classList.contains(ROXY_DATA_CLASS)) {
99
+ return child;
100
+ }
101
+ }
102
+ return null;
103
+ }
104
+
105
+ private parse(text: string | null): T | undefined {
106
+ if (!text?.trim()) return undefined;
107
+ try {
108
+ return JSON.parse(text) as T;
109
+ } catch {
110
+ // Malformed embedded JSON: fail safe, leave the host empty state in
111
+ // place rather than throwing during connect.
112
+ return undefined;
113
+ }
114
+ }
115
+ }
@@ -0,0 +1,124 @@
1
+ import type { TemplateResult } from 'lit';
2
+ import { css, html, nothing } from 'lit';
3
+
4
+ /** A single tab in a {@link renderTablist} strip. */
5
+ export interface TablistItem<T extends string = string> {
6
+ id: T;
7
+ label: string;
8
+ }
9
+
10
+ /**
11
+ * Shared styling for every horizontal tab strip in the library (natal chart
12
+ * views, transits, kundli styles). Keeping one rule set means the tabs look
13
+ * identical everywhere and theme through the same --roxy-* tokens.
14
+ */
15
+ export const tablistStyles = css`
16
+ .roxy-tablist {
17
+ display: flex;
18
+ gap: 2px;
19
+ border-bottom: 2px solid var(--roxy-border, #e4e4e7);
20
+ }
21
+ .roxy-tab {
22
+ padding: var(--roxy-space-xs, 0.25rem) var(--roxy-space-md, 1rem);
23
+ font-size: var(--roxy-text-sm, 0.875rem);
24
+ background: none;
25
+ border: none;
26
+ border-bottom: 2px solid transparent;
27
+ margin-bottom: -2px;
28
+ cursor: pointer;
29
+ color: var(--roxy-muted, #71717a);
30
+ font-family: inherit;
31
+ transition: color var(--roxy-motion-duration, 200ms)
32
+ var(--roxy-motion-easing, ease);
33
+ }
34
+ .roxy-tab[aria-selected='true'] {
35
+ color: var(--roxy-accent-fg, #b45309);
36
+ border-bottom-color: var(--roxy-accent, #f59e0b);
37
+ font-weight: var(--roxy-weight-bold, 600);
38
+ }
39
+ .roxy-tab:hover:not([aria-selected='true']) {
40
+ color: var(--roxy-fg, #0a0a0a);
41
+ }
42
+ .roxy-tab:focus-visible {
43
+ outline: 2px solid var(--roxy-ring, rgba(245, 158, 11, 0.4));
44
+ outline-offset: 2px;
45
+ border-radius: 4px;
46
+ }
47
+ `;
48
+
49
+ /**
50
+ * Render a WAI-ARIA tablist. The host component owns the active-tab state; this
51
+ * helper draws the buttons, wires click plus Left/Right arrow navigation with a
52
+ * roving tabindex, and moves focus to the newly selected tab. Pair with
53
+ * {@link tablistStyles}.
54
+ *
55
+ * Pass `controls: true` when each tab governs a sibling
56
+ * `<div role="tabpanel" id="${idPrefix}-panel-${id}">` so the buttons advertise
57
+ * `aria-controls`. Omit it for tablists that swap a single rendered view in
58
+ * place with no separate panel element (the kundli style switch).
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * renderTablist({
63
+ * items: [{ id: 'wheel', label: 'Wheel' }, { id: 'grid', label: 'Aspect grid' }],
64
+ * active: this.view,
65
+ * onSelect: (v) => { this.view = v; },
66
+ * label: 'Natal chart views',
67
+ * idPrefix: 'natal',
68
+ * controls: true,
69
+ * })
70
+ * ```
71
+ */
72
+ export function renderTablist<T extends string>(opts: {
73
+ items: ReadonlyArray<TablistItem<T>>;
74
+ active: T;
75
+ onSelect: (id: T) => void;
76
+ label: string;
77
+ idPrefix: string;
78
+ controls?: boolean;
79
+ }): TemplateResult {
80
+ const { items, active, onSelect, label, idPrefix, controls = false } = opts;
81
+ const onKeyDown = (e: KeyboardEvent) => {
82
+ if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft') return;
83
+ e.preventDefault();
84
+ const idx = items.findIndex((it) => it.id === active);
85
+ if (idx === -1) return;
86
+ const delta = e.key === 'ArrowRight' ? 1 : -1;
87
+ const next = items[(idx + delta + items.length) % items.length];
88
+ if (!next) return;
89
+ onSelect(next.id);
90
+ const root = (e.currentTarget as HTMLElement).getRootNode() as
91
+ | ShadowRoot
92
+ | Document;
93
+ requestAnimationFrame(() => {
94
+ root
95
+ .querySelector<HTMLButtonElement>(`#${idPrefix}-tab-${next.id}`)
96
+ ?.focus();
97
+ });
98
+ };
99
+ return html`<div
100
+ class="roxy-tablist"
101
+ role="tablist"
102
+ aria-label=${label}
103
+ @keydown=${onKeyDown}
104
+ >
105
+ ${items.map(
106
+ (it) => html`<button
107
+ type="button"
108
+ class="roxy-tab"
109
+ role="tab"
110
+ id="${idPrefix}-tab-${it.id}"
111
+ aria-selected=${active === it.id ? 'true' : 'false'}
112
+ aria-controls=${
113
+ // Only the active panel is rendered, so only the active tab points
114
+ // at a live element; otherwise aria-controls would dangle.
115
+ controls && active === it.id ? `${idPrefix}-panel-${it.id}` : nothing
116
+ }
117
+ tabindex=${active === it.id ? '0' : '-1'}
118
+ @click=${() => onSelect(it.id)}
119
+ >
120
+ ${it.label}
121
+ </button>`,
122
+ )}
123
+ </div>`;
124
+ }
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.4.1';
2
+ export const ROXY_UI_VERSION = '0.6.0';