@roxyapi/ui 0.9.0 → 0.11.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/AGENTS.md +53 -27
- package/README.md +42 -12
- package/components-catalog.json +1022 -0
- package/dist/cdn/components/angel-number-card.js +52 -0
- package/dist/cdn/components/angel-number-card.js.map +7 -0
- package/dist/cdn/components/angel-number-lookup.js +52 -0
- package/dist/cdn/components/angel-number-lookup.js.map +7 -0
- package/dist/cdn/components/ashtakavarga-grid.js +10 -3
- package/dist/cdn/components/ashtakavarga-grid.js.map +4 -4
- package/dist/cdn/components/aspects-table.js +52 -0
- package/dist/cdn/components/aspects-table.js.map +7 -0
- package/dist/cdn/components/biorhythm-chart.js +10 -3
- package/dist/cdn/components/biorhythm-chart.js.map +4 -4
- package/dist/cdn/components/bodygraph.js +17 -10
- package/dist/cdn/components/bodygraph.js.map +4 -4
- package/dist/cdn/components/choghadiya-grid.js +10 -3
- package/dist/cdn/components/choghadiya-grid.js.map +4 -4
- package/dist/cdn/components/compatibility-card.js +10 -3
- package/dist/cdn/components/compatibility-card.js.map +4 -4
- package/dist/cdn/components/crystal-card.js +52 -0
- package/dist/cdn/components/crystal-card.js.map +7 -0
- package/dist/cdn/components/crystal-grid.js +52 -0
- package/dist/cdn/components/crystal-grid.js.map +7 -0
- package/dist/cdn/components/dasha-timeline.js +10 -3
- package/dist/cdn/components/dasha-timeline.js.map +4 -4
- package/dist/cdn/components/data.js +10 -3
- package/dist/cdn/components/data.js.map +4 -4
- package/dist/cdn/components/divisional-chart.js +31 -24
- package/dist/cdn/components/divisional-chart.js.map +4 -4
- package/dist/cdn/components/dosha-card.js +10 -3
- package/dist/cdn/components/dosha-card.js.map +4 -4
- package/dist/cdn/components/dream-card.js +52 -0
- package/dist/cdn/components/dream-card.js.map +7 -0
- package/dist/cdn/components/dream-search.js +52 -0
- package/dist/cdn/components/dream-search.js.map +7 -0
- package/dist/cdn/components/endpoint-form.js +3 -3
- package/dist/cdn/components/endpoint-form.js.map +3 -3
- package/dist/cdn/components/forecast-digest.js +52 -0
- package/dist/cdn/components/forecast-digest.js.map +7 -0
- package/dist/cdn/components/forecast-timeline.js +10 -3
- package/dist/cdn/components/forecast-timeline.js.map +4 -4
- package/dist/cdn/components/guna-milan.js +10 -3
- package/dist/cdn/components/guna-milan.js.map +4 -4
- package/dist/cdn/components/hd-connection.js +52 -0
- package/dist/cdn/components/hd-connection.js.map +7 -0
- package/dist/cdn/components/hd-penta.js +52 -0
- package/dist/cdn/components/hd-penta.js.map +7 -0
- package/dist/cdn/components/hd-variables.js +52 -0
- package/dist/cdn/components/hd-variables.js.map +7 -0
- package/dist/cdn/components/hexagram.js +10 -3
- package/dist/cdn/components/hexagram.js.map +4 -4
- package/dist/cdn/components/hora-table.js +52 -0
- package/dist/cdn/components/hora-table.js.map +7 -0
- package/dist/cdn/components/horoscope-card.js +10 -3
- package/dist/cdn/components/horoscope-card.js.map +4 -4
- package/dist/cdn/components/kp-chart.js +10 -3
- package/dist/cdn/components/kp-chart.js.map +4 -4
- package/dist/cdn/components/kp-planets-table.js +10 -3
- package/dist/cdn/components/kp-planets-table.js.map +4 -4
- package/dist/cdn/components/kp-ruling-planets.js +10 -3
- package/dist/cdn/components/kp-ruling-planets.js.map +4 -4
- package/dist/cdn/components/location-search.js +3 -3
- package/dist/cdn/components/location-search.js.map +2 -2
- package/dist/cdn/components/moon-phase.js +10 -3
- package/dist/cdn/components/moon-phase.js.map +4 -4
- package/dist/cdn/components/nakshatra-card.js +10 -3
- package/dist/cdn/components/nakshatra-card.js.map +4 -4
- package/dist/cdn/components/natal-chart.js +16 -9
- package/dist/cdn/components/natal-chart.js.map +4 -4
- package/dist/cdn/components/numerology-card.js +10 -3
- package/dist/cdn/components/numerology-card.js.map +4 -4
- package/dist/cdn/components/panchang-table.js +10 -3
- package/dist/cdn/components/panchang-table.js.map +4 -4
- package/dist/cdn/components/reference-card.js +52 -0
- package/dist/cdn/components/reference-card.js.map +7 -0
- package/dist/cdn/components/shadbala-table.js +10 -3
- package/dist/cdn/components/shadbala-table.js.map +4 -4
- package/dist/cdn/components/synastry-chart.js +16 -9
- package/dist/cdn/components/synastry-chart.js.map +4 -4
- package/dist/cdn/components/tarot-card.js +10 -3
- package/dist/cdn/components/tarot-card.js.map +4 -4
- package/dist/cdn/components/tarot-catalog.js +52 -0
- package/dist/cdn/components/tarot-catalog.js.map +7 -0
- package/dist/cdn/components/tarot-spread.js +10 -3
- package/dist/cdn/components/tarot-spread.js.map +4 -4
- package/dist/cdn/components/transits-table.js +10 -3
- package/dist/cdn/components/transits-table.js.map +4 -4
- package/dist/cdn/components/vedic-aspects.js +52 -0
- package/dist/cdn/components/vedic-aspects.js.map +7 -0
- package/dist/cdn/components/vedic-kundli.js +31 -24
- package/dist/cdn/components/vedic-kundli.js.map +4 -4
- package/dist/cdn/components/vedic-planets-table.js +10 -3
- package/dist/cdn/components/vedic-planets-table.js.map +4 -4
- package/dist/cdn/components/western-planets-table.js +10 -3
- package/dist/cdn/components/western-planets-table.js.map +4 -4
- package/dist/cdn/components/yoga-list.js +10 -3
- package/dist/cdn/components/yoga-list.js.map +4 -4
- package/dist/cdn/roxy-ui.js +92 -81
- package/dist/cdn/roxy-ui.js.map +4 -4
- package/dist/components/angel-number-card.d.ts +17 -0
- package/dist/components/angel-number-card.d.ts.map +1 -0
- package/dist/components/angel-number-card.js +2 -0
- package/dist/components/angel-number-card.js.map +7 -0
- package/dist/components/angel-number-lookup.d.ts +21 -0
- package/dist/components/angel-number-lookup.d.ts.map +1 -0
- package/dist/components/angel-number-lookup.js +2 -0
- package/dist/components/angel-number-lookup.js.map +7 -0
- package/dist/components/ashtakavarga-grid.d.ts +4 -5
- package/dist/components/ashtakavarga-grid.d.ts.map +1 -1
- package/dist/components/ashtakavarga-grid.js +1 -1
- package/dist/components/ashtakavarga-grid.js.map +4 -4
- package/dist/components/aspects-table.d.ts +23 -0
- package/dist/components/aspects-table.d.ts.map +1 -0
- package/dist/components/aspects-table.js +2 -0
- package/dist/components/aspects-table.js.map +7 -0
- package/dist/components/biorhythm-chart.d.ts +4 -5
- package/dist/components/biorhythm-chart.d.ts.map +1 -1
- package/dist/components/biorhythm-chart.js +1 -1
- package/dist/components/biorhythm-chart.js.map +4 -4
- package/dist/components/bodygraph.d.ts +4 -5
- package/dist/components/bodygraph.d.ts.map +1 -1
- package/dist/components/bodygraph.js +9 -9
- package/dist/components/bodygraph.js.map +4 -4
- package/dist/components/choghadiya-grid.d.ts +4 -5
- package/dist/components/choghadiya-grid.d.ts.map +1 -1
- package/dist/components/choghadiya-grid.js +1 -1
- package/dist/components/choghadiya-grid.js.map +4 -4
- package/dist/components/compatibility-card.d.ts +4 -5
- package/dist/components/compatibility-card.d.ts.map +1 -1
- package/dist/components/compatibility-card.js +1 -1
- package/dist/components/compatibility-card.js.map +4 -4
- package/dist/components/crystal-card.d.ts +19 -0
- package/dist/components/crystal-card.d.ts.map +1 -0
- package/dist/components/crystal-card.js +2 -0
- package/dist/components/crystal-card.js.map +7 -0
- package/dist/components/crystal-grid.d.ts +26 -0
- package/dist/components/crystal-grid.d.ts.map +1 -0
- package/dist/components/crystal-grid.js +2 -0
- package/dist/components/crystal-grid.js.map +7 -0
- package/dist/components/dasha-timeline.d.ts +4 -5
- package/dist/components/dasha-timeline.d.ts.map +1 -1
- package/dist/components/dasha-timeline.js +1 -1
- package/dist/components/dasha-timeline.js.map +4 -4
- package/dist/components/data.d.ts +5 -8
- package/dist/components/data.d.ts.map +1 -1
- package/dist/components/data.js +1 -1
- package/dist/components/data.js.map +4 -4
- package/dist/components/divisional-chart.d.ts +4 -5
- package/dist/components/divisional-chart.d.ts.map +1 -1
- package/dist/components/divisional-chart.js +59 -59
- package/dist/components/divisional-chart.js.map +4 -4
- package/dist/components/dosha-card.d.ts +4 -5
- package/dist/components/dosha-card.d.ts.map +1 -1
- package/dist/components/dosha-card.js +1 -1
- package/dist/components/dosha-card.js.map +4 -4
- package/dist/components/dream-card.d.ts +16 -0
- package/dist/components/dream-card.d.ts.map +1 -0
- package/dist/components/dream-card.js +2 -0
- package/dist/components/dream-card.js.map +7 -0
- package/dist/components/dream-search.d.ts +18 -0
- package/dist/components/dream-search.d.ts.map +1 -0
- package/dist/components/dream-search.js +2 -0
- package/dist/components/dream-search.js.map +7 -0
- package/dist/components/endpoint-form.d.ts +10 -5
- package/dist/components/endpoint-form.d.ts.map +1 -1
- package/dist/components/endpoint-form.js +1 -1
- package/dist/components/endpoint-form.js.map +3 -3
- package/dist/components/forecast-digest.d.ts +19 -0
- package/dist/components/forecast-digest.d.ts.map +1 -0
- package/dist/components/forecast-digest.js +2 -0
- package/dist/components/forecast-digest.js.map +7 -0
- package/dist/components/forecast-timeline.d.ts +8 -6
- package/dist/components/forecast-timeline.d.ts.map +1 -1
- package/dist/components/forecast-timeline.js +1 -1
- package/dist/components/forecast-timeline.js.map +4 -4
- package/dist/components/guna-milan.d.ts +4 -5
- package/dist/components/guna-milan.d.ts.map +1 -1
- package/dist/components/guna-milan.js +1 -1
- package/dist/components/guna-milan.js.map +4 -4
- package/dist/components/hd-connection.d.ts +18 -0
- package/dist/components/hd-connection.d.ts.map +1 -0
- package/dist/components/hd-connection.js +2 -0
- package/dist/components/hd-connection.js.map +7 -0
- package/dist/components/hd-penta.d.ts +18 -0
- package/dist/components/hd-penta.d.ts.map +1 -0
- package/dist/components/hd-penta.js +2 -0
- package/dist/components/hd-penta.js.map +7 -0
- package/dist/components/hd-variables.d.ts +17 -0
- package/dist/components/hd-variables.d.ts.map +1 -0
- package/dist/components/hd-variables.js +2 -0
- package/dist/components/hd-variables.js.map +7 -0
- package/dist/components/hexagram.d.ts +4 -5
- package/dist/components/hexagram.d.ts.map +1 -1
- package/dist/components/hexagram.js +1 -1
- package/dist/components/hexagram.js.map +4 -4
- package/dist/components/hora-table.d.ts +17 -0
- package/dist/components/hora-table.d.ts.map +1 -0
- package/dist/components/hora-table.js +2 -0
- package/dist/components/hora-table.js.map +7 -0
- package/dist/components/horoscope-card.d.ts +4 -5
- package/dist/components/horoscope-card.d.ts.map +1 -1
- package/dist/components/horoscope-card.js +1 -1
- package/dist/components/horoscope-card.js.map +4 -4
- package/dist/components/kp-chart.d.ts +4 -5
- package/dist/components/kp-chart.d.ts.map +1 -1
- package/dist/components/kp-chart.js +1 -1
- package/dist/components/kp-chart.js.map +4 -4
- package/dist/components/kp-planets-table.d.ts +4 -5
- package/dist/components/kp-planets-table.d.ts.map +1 -1
- package/dist/components/kp-planets-table.js +1 -1
- package/dist/components/kp-planets-table.js.map +4 -4
- package/dist/components/kp-ruling-planets.d.ts +4 -5
- package/dist/components/kp-ruling-planets.d.ts.map +1 -1
- package/dist/components/kp-ruling-planets.js +1 -1
- package/dist/components/kp-ruling-planets.js.map +4 -4
- package/dist/components/location-search.js +1 -1
- package/dist/components/location-search.js.map +2 -2
- package/dist/components/moon-phase.d.ts +5 -5
- package/dist/components/moon-phase.d.ts.map +1 -1
- package/dist/components/moon-phase.js +1 -1
- package/dist/components/moon-phase.js.map +4 -4
- package/dist/components/nakshatra-card.d.ts +4 -5
- package/dist/components/nakshatra-card.d.ts.map +1 -1
- package/dist/components/nakshatra-card.js +1 -1
- package/dist/components/nakshatra-card.js.map +4 -4
- package/dist/components/natal-chart.d.ts +4 -5
- package/dist/components/natal-chart.d.ts.map +1 -1
- package/dist/components/natal-chart.js +8 -8
- package/dist/components/natal-chart.js.map +4 -4
- package/dist/components/numerology-card.d.ts +15 -10
- package/dist/components/numerology-card.d.ts.map +1 -1
- package/dist/components/numerology-card.js +1 -1
- package/dist/components/numerology-card.js.map +4 -4
- package/dist/components/panchang-table.d.ts +4 -5
- package/dist/components/panchang-table.d.ts.map +1 -1
- package/dist/components/panchang-table.js +1 -1
- package/dist/components/panchang-table.js.map +4 -4
- package/dist/components/reference-card.d.ts +19 -0
- package/dist/components/reference-card.d.ts.map +1 -0
- package/dist/components/reference-card.js +2 -0
- package/dist/components/reference-card.js.map +7 -0
- package/dist/components/shadbala-table.d.ts +4 -5
- package/dist/components/shadbala-table.d.ts.map +1 -1
- package/dist/components/shadbala-table.js +1 -1
- package/dist/components/shadbala-table.js.map +4 -4
- package/dist/components/synastry-chart.d.ts +4 -5
- package/dist/components/synastry-chart.d.ts.map +1 -1
- package/dist/components/synastry-chart.js +7 -7
- package/dist/components/synastry-chart.js.map +4 -4
- package/dist/components/tarot-card.d.ts +4 -5
- package/dist/components/tarot-card.d.ts.map +1 -1
- package/dist/components/tarot-card.js +1 -1
- package/dist/components/tarot-card.js.map +4 -4
- package/dist/components/tarot-catalog.d.ts +20 -0
- package/dist/components/tarot-catalog.d.ts.map +1 -0
- package/dist/components/tarot-catalog.js +2 -0
- package/dist/components/tarot-catalog.js.map +7 -0
- package/dist/components/tarot-spread.d.ts +7 -8
- package/dist/components/tarot-spread.d.ts.map +1 -1
- package/dist/components/tarot-spread.js +1 -1
- package/dist/components/tarot-spread.js.map +4 -4
- package/dist/components/transits-table.d.ts +4 -5
- package/dist/components/transits-table.d.ts.map +1 -1
- package/dist/components/transits-table.js +1 -1
- package/dist/components/transits-table.js.map +4 -4
- package/dist/components/vedic-aspects.d.ts +16 -0
- package/dist/components/vedic-aspects.d.ts.map +1 -0
- package/dist/components/vedic-aspects.js +2 -0
- package/dist/components/vedic-aspects.js.map +7 -0
- package/dist/components/vedic-kundli.d.ts +22 -5
- package/dist/components/vedic-kundli.d.ts.map +1 -1
- package/dist/components/vedic-kundli.js +63 -63
- package/dist/components/vedic-kundli.js.map +4 -4
- package/dist/components/vedic-planets-table.d.ts +4 -5
- package/dist/components/vedic-planets-table.d.ts.map +1 -1
- package/dist/components/vedic-planets-table.js +1 -1
- package/dist/components/vedic-planets-table.js.map +4 -4
- package/dist/components/western-planets-table.d.ts +4 -5
- package/dist/components/western-planets-table.d.ts.map +1 -1
- package/dist/components/western-planets-table.js +1 -1
- package/dist/components/western-planets-table.js.map +4 -4
- package/dist/components/yoga-list.d.ts +6 -7
- package/dist/components/yoga-list.d.ts.map +1 -1
- package/dist/components/yoga-list.js +1 -1
- package/dist/components/yoga-list.js.map +4 -4
- package/dist/generated/endpoint-bindings.d.ts +15 -0
- package/dist/generated/endpoint-bindings.d.ts.map +1 -0
- package/dist/index.cjs +73 -73
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +71 -71
- package/dist/index.js.map +4 -4
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.json +39 -24
- package/dist/styles/tokens-css.d.ts +1 -1
- package/dist/styles/tokens-css.d.ts.map +1 -1
- package/dist/styles/tokens.css +4 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.gen.d.ts +1103 -164
- package/dist/types/types.gen.d.ts.map +1 -1
- package/dist/utils/angel-sections.d.ts +14 -0
- package/dist/utils/angel-sections.d.ts.map +1 -0
- package/dist/utils/base-element.d.ts +73 -0
- package/dist/utils/base-element.d.ts.map +1 -0
- package/dist/utils/base-styles.d.ts.map +1 -1
- package/dist/utils/fetch-controller.d.ts +60 -0
- package/dist/utils/fetch-controller.d.ts.map +1 -0
- package/dist/utils/kundli-render.d.ts +2 -1
- package/dist/utils/kundli-render.d.ts.map +1 -1
- package/dist/utils/kundli-styles.d.ts.map +1 -1
- package/dist/utils/markup-data.d.ts +34 -0
- package/dist/utils/markup-data.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/components/angel-number-card.ts +210 -0
- package/src/components/angel-number-lookup.ts +207 -0
- package/src/components/ashtakavarga-grid.ts +15 -20
- package/src/components/aspects-table.ts +329 -0
- package/src/components/biorhythm-chart.ts +14 -18
- package/src/components/bodygraph.ts +9 -20
- package/src/components/choghadiya-grid.ts +15 -19
- package/src/components/compatibility-card.ts +9 -19
- package/src/components/crystal-card.ts +242 -0
- package/src/components/crystal-grid.ts +182 -0
- package/src/components/dasha-timeline.ts +9 -20
- package/src/components/data.ts +8 -27
- package/src/components/divisional-chart.ts +10 -18
- package/src/components/dosha-card.ts +8 -19
- package/src/components/dream-card.ts +88 -0
- package/src/components/dream-search.ts +135 -0
- package/src/components/endpoint-form.ts +149 -55
- package/src/components/forecast-digest.ts +213 -0
- package/src/components/forecast-timeline.ts +24 -19
- package/src/components/guna-milan.ts +8 -19
- package/src/components/hd-connection.ts +188 -0
- package/src/components/hd-penta.ts +165 -0
- package/src/components/hd-variables.ts +128 -0
- package/src/components/hexagram.ts +10 -18
- package/src/components/hora-table.ts +149 -0
- package/src/components/horoscope-card.ts +9 -19
- package/src/components/kp-chart.ts +11 -20
- package/src/components/kp-planets-table.ts +11 -20
- package/src/components/kp-ruling-planets.ts +8 -18
- package/src/components/moon-phase.ts +10 -19
- package/src/components/nakshatra-card.ts +11 -20
- package/src/components/natal-chart.ts +20 -23
- package/src/components/numerology-card.ts +90 -31
- package/src/components/panchang-table.ts +9 -19
- package/src/components/reference-card.ts +212 -0
- package/src/components/shadbala-table.ts +15 -18
- package/src/components/synastry-chart.ts +17 -20
- package/src/components/tarot-card.ts +9 -20
- package/src/components/tarot-catalog.ts +129 -0
- package/src/components/tarot-spread.ts +20 -21
- package/src/components/transits-table.ts +17 -20
- package/src/components/vedic-aspects.ts +188 -0
- package/src/components/vedic-kundli.ts +46 -19
- package/src/components/vedic-planets-table.ts +11 -19
- package/src/components/western-planets-table.ts +11 -19
- package/src/components/yoga-list.ts +17 -23
- package/src/generated/endpoint-bindings.ts +655 -0
- package/src/index.ts +27 -0
- package/src/manifest.ts +198 -6
- package/src/styles/tokens-css.ts +4 -0
- package/src/styles/tokens.css +4 -0
- package/src/types/index.ts +1 -1
- package/src/types/types.gen.ts +1123 -164
- package/src/utils/angel-sections.ts +38 -0
- package/src/utils/base-element.ts +183 -0
- package/src/utils/base-styles.ts +33 -0
- package/src/utils/fetch-controller.ts +166 -0
- package/src/utils/kundli-render.ts +9 -2
- package/src/utils/kundli-styles.ts +7 -1
- package/src/utils/markup-data.ts +45 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ordered angel-number interpretation sections, shared by the angel-number card and lookup components so the field list, labels, and display order live in one place instead of being duplicated per component.
|
|
3
|
+
*
|
|
4
|
+
* @remarks The life-area keys (`spiritual`, `love`, `career`, `money`, `twinFlame`) mirror the `meaning` object in the angel-numbers OpenAPI response; `biblical` and `shadow` are top-level siblings present only on a known meaning, not on the digit-root fallback. Any absent field is skipped, so the one builder serves a full known meaning and the leaner digit-root reading alike.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface MeaningSection {
|
|
8
|
+
label: string;
|
|
9
|
+
body: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const LIFE_AREA_SECTIONS: ReadonlyArray<{ key: string; label: string }> = [
|
|
13
|
+
{ key: 'spiritual', label: 'Spiritual' },
|
|
14
|
+
{ key: 'love', label: 'Love' },
|
|
15
|
+
{ key: 'career', label: 'Career' },
|
|
16
|
+
{ key: 'money', label: 'Money' },
|
|
17
|
+
{ key: 'twinFlame', label: 'Twin flame' },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Build the present-only interpretation sections in canonical order: the life areas first, then the optional `biblical` and `shadow` readings. An empty or missing field is omitted so the caller can render whatever the response actually carries.
|
|
22
|
+
*/
|
|
23
|
+
export function buildMeaningSections(
|
|
24
|
+
meaning: Record<string, string> | undefined,
|
|
25
|
+
biblical?: string,
|
|
26
|
+
shadow?: string,
|
|
27
|
+
): MeaningSection[] {
|
|
28
|
+
const sections: MeaningSection[] = [];
|
|
29
|
+
if (meaning) {
|
|
30
|
+
for (const s of LIFE_AREA_SECTIONS) {
|
|
31
|
+
const body = meaning[s.key];
|
|
32
|
+
if (body) sections.push({ label: s.label, body });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (biblical) sections.push({ label: 'Biblical', body: biblical });
|
|
36
|
+
if (shadow) sections.push({ label: 'Shadow', body: shadow });
|
|
37
|
+
return sections;
|
|
38
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CSSResultGroup,
|
|
3
|
+
html,
|
|
4
|
+
LitElement,
|
|
5
|
+
type PropertyValues,
|
|
6
|
+
} from 'lit';
|
|
7
|
+
import { property, state } from 'lit/decorators.js';
|
|
8
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
9
|
+
import { baseStyles } from './base-styles.js';
|
|
10
|
+
import { buildRequest, FetchController } from './fetch-controller.js';
|
|
11
|
+
import { MarkupDataController } from './markup-data.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Shared base for every data-driven Roxy component. Consolidates the things every component used to repeat by hand and adds the self-contained, drop-in behavior: controlled-mode hydration, an opt-in self-fetch (form, request, loading, error, empty), the typed `data` slot, and the render switch. A subclass implements one method, {@link RoxyDataElement.renderData}.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Two render modes, one component, which is the whole drop-in contract:
|
|
18
|
+
*
|
|
19
|
+
* - Controlled: a server (WordPress, JSX SSR, static HTML) fetches the response and injects it as a direct-child `<script type="application/json" class="roxy-data">`. {@link MarkupDataController} hydrates `data` from it on connect. No key reaches the browser. This is the path the WordPress plugin drives, and it is unchanged by the base class.
|
|
20
|
+
* - Uncontrolled: no data is injected, but a `data-endpoint` and a `pk_` `publishable-key` are set. The component renders its own `<roxy-endpoint-form>` (an internal detail, never placed by the consumer), and on submit fetches through {@link FetchController}, which refuses any non-publishable key. The result populates `data` and the component renders it.
|
|
21
|
+
*
|
|
22
|
+
* The JavaScript `data` property always wins over markup, so a host that assigns `el.data = …` after upgrade is authoritative.
|
|
23
|
+
*
|
|
24
|
+
* Self-fetch needs `<roxy-endpoint-form>` (and `<roxy-location-search>`) registered. The CDN bundle and the full `@roxyapi/ui` entry register everything; per-component ESM consumers that want self-fetch import the form component too.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* @customElement('roxy-dream-card')
|
|
29
|
+
* export class RoxyDreamCard extends RoxyDataElement<GetDreamSymbolResponse> {
|
|
30
|
+
* static styles = [baseStyles, css`.card { … }`];
|
|
31
|
+
* protected renderData(d: GetDreamSymbolResponse) {
|
|
32
|
+
* return html`<article class="card">…</article>`;
|
|
33
|
+
* }
|
|
34
|
+
* protected renderEmpty() {
|
|
35
|
+
* return html`<div class="roxy-empty" role="status">No dream symbol</div>`;
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export abstract class RoxyDataElement<T = unknown> extends LitElement {
|
|
41
|
+
static styles: CSSResultGroup = [baseStyles];
|
|
42
|
+
|
|
43
|
+
/** Typed RoxyAPI response. Assigned in JavaScript, hydrated from the roxy-data island, or set by a self-fetch. */
|
|
44
|
+
@property({ attribute: false })
|
|
45
|
+
data: T | null = null;
|
|
46
|
+
|
|
47
|
+
/** Endpoint path for self-fetch, e.g. "astrology/natal-chart" or "dreams/symbols/{id}". Empty disables self-fetch (controlled mode only). */
|
|
48
|
+
@property({ type: String, attribute: 'data-endpoint' })
|
|
49
|
+
endpoint = '';
|
|
50
|
+
|
|
51
|
+
/** HTTP method for self-fetch. */
|
|
52
|
+
@property({ type: String })
|
|
53
|
+
method: 'GET' | 'POST' = 'POST';
|
|
54
|
+
|
|
55
|
+
/** Browser-safe publishable key (pk_) for self-fetch. A secret key is refused client-side. */
|
|
56
|
+
@property({ type: String, attribute: 'publishable-key' })
|
|
57
|
+
publishableKey?: string;
|
|
58
|
+
|
|
59
|
+
/** Override the API origin for self-hosted or proxied deployments. */
|
|
60
|
+
@property({ type: String, attribute: 'base-url' })
|
|
61
|
+
baseUrl?: string;
|
|
62
|
+
|
|
63
|
+
/** Override the OpenAPI spec URL the self-fetch form introspects. */
|
|
64
|
+
@property({ type: String, attribute: 'spec-url' })
|
|
65
|
+
specUrl?: string;
|
|
66
|
+
|
|
67
|
+
/** Consumer backend route that proxies the request (holds the secret key). When set, self-fetch POSTs the request here instead of calling RoxyAPI directly, so no key reaches the browser. The server-rendered (WordPress) path. */
|
|
68
|
+
@property({ type: String, attribute: 'submit-url' })
|
|
69
|
+
submitUrl?: string;
|
|
70
|
+
|
|
71
|
+
/** Persist the last self-fetch form values in sessionStorage (keyed by endpoint) and prefill the form on reload. */
|
|
72
|
+
@property({ type: Boolean })
|
|
73
|
+
remember = false;
|
|
74
|
+
|
|
75
|
+
/** True while an uncontrolled self-fetch is in flight. Public so {@link FetchController} can drive it. */
|
|
76
|
+
@state()
|
|
77
|
+
loading = false;
|
|
78
|
+
|
|
79
|
+
/** Message from a failed self-fetch, or null. Public so {@link FetchController} can drive it. */
|
|
80
|
+
@state()
|
|
81
|
+
error: string | null = null;
|
|
82
|
+
|
|
83
|
+
private fetcher: FetchController<T>;
|
|
84
|
+
|
|
85
|
+
constructor() {
|
|
86
|
+
super();
|
|
87
|
+
// Controlled mode: hydrate `data` from a direct-child roxy-data island when
|
|
88
|
+
// no JS property was assigned. Keyless; the server already fetched.
|
|
89
|
+
new MarkupDataController<T>(this);
|
|
90
|
+
this.fetcher = new FetchController<T>(this);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
protected willUpdate(changed: PropertyValues): void {
|
|
94
|
+
if (changed.has('publishableKey')) {
|
|
95
|
+
this.fetcher.publishableKey = this.publishableKey;
|
|
96
|
+
}
|
|
97
|
+
if (changed.has('baseUrl') && this.baseUrl) {
|
|
98
|
+
this.fetcher.baseUrl = this.baseUrl;
|
|
99
|
+
}
|
|
100
|
+
if (changed.has('submitUrl')) {
|
|
101
|
+
this.fetcher.submitUrl = this.submitUrl;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
render(): unknown {
|
|
106
|
+
if (this.loading) return this.renderLoading();
|
|
107
|
+
if (this.error != null) return this.renderError(this.error);
|
|
108
|
+
if (this.data != null) return this.renderData(this.data);
|
|
109
|
+
return this.renderNoData();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Render the populated response. The single method every component implements. */
|
|
113
|
+
protected abstract renderData(data: T): unknown;
|
|
114
|
+
|
|
115
|
+
/** The data-absent branch: the self-fetch form when an endpoint is set, otherwise the empty state. */
|
|
116
|
+
protected renderNoData(): unknown {
|
|
117
|
+
return this.endpoint ? this.renderForm() : this.renderEmpty();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Internal self-fetch form. Reuses the introspecting `<roxy-endpoint-form>`; the consumer never places it. */
|
|
121
|
+
protected renderForm(): unknown {
|
|
122
|
+
return html`<roxy-endpoint-form
|
|
123
|
+
data-endpoint=${this.endpoint}
|
|
124
|
+
method=${this.method}
|
|
125
|
+
spec-url=${ifDefined(this.specUrl)}
|
|
126
|
+
.initialValues=${this.remember ? this.readRemembered() : undefined}
|
|
127
|
+
@roxy-submit=${this.onFormSubmit}
|
|
128
|
+
></roxy-endpoint-form>`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private onFormSubmit = (e: Event) => {
|
|
132
|
+
const detail = (e as CustomEvent).detail as {
|
|
133
|
+
values: Record<string, unknown>;
|
|
134
|
+
};
|
|
135
|
+
if (this.remember) this.writeRemembered(detail.values);
|
|
136
|
+
void this.fetcher.run(
|
|
137
|
+
buildRequest(this.endpoint, this.method, detail.values),
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/** sessionStorage key for this component's remembered form values, scoped by endpoint. */
|
|
142
|
+
private rememberKey(): string {
|
|
143
|
+
return `roxy-ui:form:${this.endpoint}`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private readRemembered(): Record<string, unknown> | undefined {
|
|
147
|
+
try {
|
|
148
|
+
const raw = sessionStorage.getItem(this.rememberKey());
|
|
149
|
+
return raw ? (JSON.parse(raw) as Record<string, unknown>) : undefined;
|
|
150
|
+
} catch {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private writeRemembered(values: Record<string, unknown>): void {
|
|
156
|
+
try {
|
|
157
|
+
sessionStorage.setItem(this.rememberKey(), JSON.stringify(values));
|
|
158
|
+
} catch {
|
|
159
|
+
// Private mode / disabled storage: remembering is best-effort, never fatal.
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Terminal empty state. Subclasses override for a domain-specific message. */
|
|
164
|
+
protected renderEmpty(): unknown {
|
|
165
|
+
return html`<div class="roxy-empty" role="status">No data</div>`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Loading placeholder shown during a self-fetch. */
|
|
169
|
+
protected renderLoading(): unknown {
|
|
170
|
+
return html`<div
|
|
171
|
+
class="roxy-skeleton"
|
|
172
|
+
style="height: 8rem"
|
|
173
|
+
role="status"
|
|
174
|
+
aria-label="Loading"
|
|
175
|
+
></div>`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Error state shown when a self-fetch fails. Keeps the form in view so the request can be retried. */
|
|
179
|
+
protected renderError(message: string): unknown {
|
|
180
|
+
const banner = html`<div class="roxy-error" role="alert">${message}</div>`;
|
|
181
|
+
return this.endpoint ? html`${banner}${this.renderForm()}` : banner;
|
|
182
|
+
}
|
|
183
|
+
}
|
package/src/utils/base-styles.ts
CHANGED
|
@@ -25,6 +25,18 @@ export const baseStyles = css`
|
|
|
25
25
|
var(--roxy-motion-easing, cubic-bezier(0.4, 0, 0.2, 1)) both;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Opt out of the component's own card surface. When the embedder already
|
|
30
|
+
* wraps the component in their own card, set the \`bare\` attribute to drop
|
|
31
|
+
* the painted background + shadow so there is no nested card chrome. The
|
|
32
|
+
* inner border stays a hairline; override --roxy-border to remove it too.
|
|
33
|
+
*/
|
|
34
|
+
:host([bare]) {
|
|
35
|
+
--roxy-surface: transparent;
|
|
36
|
+
--roxy-shadow-sm: none;
|
|
37
|
+
--roxy-shadow-md: none;
|
|
38
|
+
}
|
|
39
|
+
|
|
28
40
|
*,
|
|
29
41
|
*::before,
|
|
30
42
|
*::after {
|
|
@@ -82,6 +94,27 @@ export const baseStyles = css`
|
|
|
82
94
|
font-size: var(--roxy-text-sm, 0.875rem);
|
|
83
95
|
}
|
|
84
96
|
|
|
97
|
+
.roxy-error {
|
|
98
|
+
display: grid;
|
|
99
|
+
gap: var(--roxy-space-sm, 0.5rem);
|
|
100
|
+
justify-items: start;
|
|
101
|
+
padding: var(--roxy-space-lg, 1.5rem);
|
|
102
|
+
background: var(--roxy-surface, #fff);
|
|
103
|
+
border: 1px solid var(--roxy-danger, #dc2626);
|
|
104
|
+
border-radius: var(--roxy-radius-md, 8px);
|
|
105
|
+
color: var(--roxy-danger-fg, #991b1b);
|
|
106
|
+
font-size: var(--roxy-text-sm, 0.875rem);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* Opt-in component backdrop. A component that paints content directly (table,
|
|
110
|
+
* grid, prose) adds this to its root so it sits on an owned, theme-aware
|
|
111
|
+
* surface rather than inheriting the page background, which may not match the
|
|
112
|
+
* resolved token theme and would render text on a same-tone background. */
|
|
113
|
+
.roxy-surface {
|
|
114
|
+
background: var(--roxy-surface, #fff);
|
|
115
|
+
color: var(--roxy-fg, #0a0a0a);
|
|
116
|
+
}
|
|
117
|
+
|
|
85
118
|
:host(:focus-within) .roxy-card {
|
|
86
119
|
outline: 2px solid var(--roxy-ring, rgba(245, 158, 11, 0.4));
|
|
87
120
|
outline-offset: 2px;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Host slots the controller drives. {@link RoxyDataElement} satisfies this, so
|
|
5
|
+
* the form mixin can attach a controller without the component wiring state by hand.
|
|
6
|
+
*/
|
|
7
|
+
interface FetchHost<T> extends ReactiveControllerHost {
|
|
8
|
+
data: T | null;
|
|
9
|
+
loading: boolean;
|
|
10
|
+
error: string | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Default RoxyAPI v2 origin. A component overrides it per instance via its `base-url` attribute. */
|
|
14
|
+
const DEFAULT_BASE_URL = 'https://roxyapi.com/api/v2';
|
|
15
|
+
|
|
16
|
+
/** A single request the controller issues on the component's behalf. */
|
|
17
|
+
export interface RoxyRequest {
|
|
18
|
+
/** Path under the API base, e.g. "/dreams/symbols/water" or "/astrology/natal-chart". */
|
|
19
|
+
path: string;
|
|
20
|
+
method?: 'GET' | 'POST';
|
|
21
|
+
/** JSON body for POST endpoints. */
|
|
22
|
+
body?: unknown;
|
|
23
|
+
/** Query string parameters; nullish values are dropped. */
|
|
24
|
+
query?: Record<string, string | number | undefined>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Client-side fetch for uncontrolled (self-fetching) components: drives `host.data` / `host.loading` / `host.error` and cancels a stale request when a newer one starts or the host disconnects.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* Security boundary. The only credential this ever sends is a `pk_` publishable key, which carries a server-side origin allowlist. A secret (`sk_`) or legacy unprefixed key is refused before any network call and surfaced as an error, so a server secret cannot leak into a browser request. This centralizes the guard that originated in `<roxy-location-search>` so every self-fetching component enforces it identically.
|
|
32
|
+
*
|
|
33
|
+
* Controlled-mode components never construct this. When a server injects the response as a `<script class="roxy-data">` island, there is no key and no fetch, which is the path server-rendered consumers (WordPress, JSX SSR, static HTML) rely on.
|
|
34
|
+
*/
|
|
35
|
+
export class FetchController<T = unknown> implements ReactiveController {
|
|
36
|
+
private readonly host: FetchHost<T>;
|
|
37
|
+
private abort?: AbortController;
|
|
38
|
+
|
|
39
|
+
/** Browser-safe publishable key. Set by the host from its `publishable-key` attribute. */
|
|
40
|
+
publishableKey?: string;
|
|
41
|
+
/** API origin, overridable for self-hosted or proxied deployments. */
|
|
42
|
+
baseUrl = DEFAULT_BASE_URL;
|
|
43
|
+
/**
|
|
44
|
+
* Consumer backend route that holds the secret key. When set, the request is POSTed here as `{ path, method, body, query }` instead of called against RoxyAPI directly, so no key (publishable or secret) is sent from the browser. This is the canonical path for server-rendered hosts (WordPress); the backend proxies the request with its own `sk_` key and returns the JSON response.
|
|
45
|
+
*/
|
|
46
|
+
submitUrl?: string;
|
|
47
|
+
|
|
48
|
+
constructor(host: FetchHost<T>) {
|
|
49
|
+
this.host = host;
|
|
50
|
+
host.addController(this);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
hostDisconnected() {
|
|
54
|
+
this.abort?.abort();
|
|
55
|
+
this.abort = undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Issue the request and resolve once `host.data` (success) or `host.error`
|
|
60
|
+
* (failure) is set. A no-op return when a non-publishable key is present:
|
|
61
|
+
* the error is already surfaced and nothing is sent.
|
|
62
|
+
*/
|
|
63
|
+
async run(req: RoxyRequest): Promise<void> {
|
|
64
|
+
// submit-url proxy: no key leaves the browser; the consumer's backend holds it.
|
|
65
|
+
if (!this.submitUrl && this.secretKeyRefused()) return;
|
|
66
|
+
this.abort?.abort();
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
this.abort = controller;
|
|
69
|
+
this.host.loading = true;
|
|
70
|
+
this.host.error = null;
|
|
71
|
+
try {
|
|
72
|
+
const res = this.submitUrl
|
|
73
|
+
? await fetch(this.submitUrl, {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
headers: {
|
|
76
|
+
Accept: 'application/json',
|
|
77
|
+
'Content-Type': 'application/json',
|
|
78
|
+
},
|
|
79
|
+
body: JSON.stringify(req),
|
|
80
|
+
signal: controller.signal,
|
|
81
|
+
})
|
|
82
|
+
: await this.callApi(req, controller.signal);
|
|
83
|
+
if (!res.ok) throw new Error(await this.readError(res));
|
|
84
|
+
const json = (await res.json()) as T;
|
|
85
|
+
if (controller.signal.aborted) return;
|
|
86
|
+
this.host.data = json;
|
|
87
|
+
} catch (err) {
|
|
88
|
+
if ((err as { name?: string })?.name === 'AbortError') return;
|
|
89
|
+
this.host.error = err instanceof Error ? err.message : String(err);
|
|
90
|
+
} finally {
|
|
91
|
+
if (this.abort === controller) this.abort = undefined;
|
|
92
|
+
if (!controller.signal.aborted) this.host.loading = false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Direct call against RoxyAPI with the publishable key (the no-backend path). */
|
|
97
|
+
private callApi(req: RoxyRequest, signal: AbortSignal): Promise<Response> {
|
|
98
|
+
const url = new URL(`${this.baseUrl}${req.path}`);
|
|
99
|
+
for (const [k, v] of Object.entries(req.query ?? {})) {
|
|
100
|
+
if (v != null) url.searchParams.set(k, String(v));
|
|
101
|
+
}
|
|
102
|
+
const headers: Record<string, string> = { Accept: 'application/json' };
|
|
103
|
+
if (this.publishableKey) headers['X-API-Key'] = this.publishableKey;
|
|
104
|
+
if (req.body != null) headers['Content-Type'] = 'application/json';
|
|
105
|
+
return fetch(url, {
|
|
106
|
+
method: req.method ?? 'GET',
|
|
107
|
+
headers,
|
|
108
|
+
body: req.body != null ? JSON.stringify(req.body) : undefined,
|
|
109
|
+
signal,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** True when a key is set and it is not a browser-safe `pk_` publishable key. Surfaces the error and refuses to send. */
|
|
114
|
+
private secretKeyRefused(): boolean {
|
|
115
|
+
const key = this.publishableKey;
|
|
116
|
+
if (!key || key.startsWith('pk_')) return false;
|
|
117
|
+
this.host.error =
|
|
118
|
+
'Client-side components accept a pk_ publishable key only. Use a publishable key with an origin allowlist, or render server-side.';
|
|
119
|
+
(this.host as unknown as EventTarget).dispatchEvent(
|
|
120
|
+
new CustomEvent('roxy-validation-error', {
|
|
121
|
+
detail: { reason: 'possible-secret-key' },
|
|
122
|
+
bubbles: true,
|
|
123
|
+
composed: true,
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Surface the `{ error, code }` message the API returns on failure, falling back to the status code. */
|
|
130
|
+
private async readError(res: Response): Promise<string> {
|
|
131
|
+
try {
|
|
132
|
+
const body = (await res.json()) as { error?: string };
|
|
133
|
+
if (body?.error) return body.error;
|
|
134
|
+
} catch {
|
|
135
|
+
// Non-JSON error body: fall through to the status line.
|
|
136
|
+
}
|
|
137
|
+
return `Request failed (${res.status})`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Translate flat form values into a {@link RoxyRequest} for an endpoint. The `{name}` segments in the endpoint template are substituted from the values and removed; the rest become the JSON body for POST or query parameters for GET. This is the spec-light request builder the base element uses to turn a `<roxy-endpoint-form>` submission into a self-fetch, so a component needs no per-endpoint glue.
|
|
143
|
+
*/
|
|
144
|
+
export function buildRequest(
|
|
145
|
+
endpoint: string,
|
|
146
|
+
method: 'GET' | 'POST',
|
|
147
|
+
values: Record<string, unknown>,
|
|
148
|
+
): RoxyRequest {
|
|
149
|
+
const rest: Record<string, unknown> = { ...values };
|
|
150
|
+
const path = `/${endpoint.replace(/^\//, '')}`.replace(
|
|
151
|
+
/\{([^}]+)\}/g,
|
|
152
|
+
(_match, name: string) => {
|
|
153
|
+
const v = rest[name];
|
|
154
|
+
delete rest[name];
|
|
155
|
+
return encodeURIComponent(String(v ?? ''));
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
const query: Record<string, string | number | undefined> = {};
|
|
159
|
+
const body: Record<string, unknown> = {};
|
|
160
|
+
for (const [k, v] of Object.entries(rest)) {
|
|
161
|
+
if (v === undefined || v === '') continue;
|
|
162
|
+
if (method === 'GET') query[k] = v as string | number;
|
|
163
|
+
else body[k] = v;
|
|
164
|
+
}
|
|
165
|
+
return { path, method, query, body: method === 'POST' ? body : undefined };
|
|
166
|
+
}
|
|
@@ -173,6 +173,7 @@ function renderPlanetStack(
|
|
|
173
173
|
*
|
|
174
174
|
* @param meta - Graha-keyed map; missing rashi entries are skipped.
|
|
175
175
|
* @param divisionLabel - Optional title written inside the chart centre.
|
|
176
|
+
* @param lagnaOverride - Optional rashi/sign name (case-insensitive, e.g. `"cancer"`) that replaces the `meta.Lagna`-derived ascendant. Drives the Chandra Lagna (Moon-as-ascendant) and other reference-point views: the `meta` of a `/birth-chart` response always carries the Janma Lagna as its `Lagna` key, so this is the only way to pivot the houses without a second request. Ignored when it does not resolve to a known sign.
|
|
176
177
|
*/
|
|
177
178
|
export function toKundliViewModel(
|
|
178
179
|
meta: Record<
|
|
@@ -187,14 +188,20 @@ export function toKundliViewModel(
|
|
|
187
188
|
}
|
|
188
189
|
>,
|
|
189
190
|
divisionLabel?: string,
|
|
191
|
+
lagnaOverride?: string,
|
|
190
192
|
): KundliViewModel {
|
|
191
193
|
const placements: Record<string, PlacedGraha[]> = {};
|
|
192
194
|
for (const sign of SIGNS_ORDER) placements[sign.toLowerCase()] = [];
|
|
193
|
-
|
|
195
|
+
const override = lagnaOverride
|
|
196
|
+
? (RASHI_TO_SIGN[lagnaOverride.toLowerCase()] ?? '')
|
|
197
|
+
: '';
|
|
198
|
+
let lagnaSign = override;
|
|
194
199
|
for (const [name, pos] of Object.entries(meta ?? {})) {
|
|
195
200
|
const rashiKey = (pos?.rashi ?? '').toLowerCase();
|
|
196
201
|
if (name === 'Lagna' || pos?.graha === 'Lagna') {
|
|
197
|
-
|
|
202
|
+
// An explicit override pins the ascendant; otherwise the Janma Lagna
|
|
203
|
+
// from meta is the reference point.
|
|
204
|
+
if (!override) lagnaSign = RASHI_TO_SIGN[rashiKey] ?? '';
|
|
198
205
|
continue;
|
|
199
206
|
}
|
|
200
207
|
if (!rashiKey || !(rashiKey in placements)) continue;
|
|
@@ -13,6 +13,12 @@ import { css } from 'lit';
|
|
|
13
13
|
*/
|
|
14
14
|
export const kundliStyles = css`
|
|
15
15
|
.wrap {
|
|
16
|
+
background: var(--roxy-surface, #fff);
|
|
17
|
+
color: var(--roxy-fg, #0a0a0a);
|
|
18
|
+
border: 1px solid var(--roxy-border, #e4e4e7);
|
|
19
|
+
border-radius: var(--roxy-radius-md, 8px);
|
|
20
|
+
padding: var(--roxy-space-lg, 1.5rem);
|
|
21
|
+
box-shadow: var(--roxy-shadow-sm);
|
|
16
22
|
display: grid;
|
|
17
23
|
gap: var(--roxy-space-md, 1rem);
|
|
18
24
|
}
|
|
@@ -31,7 +37,7 @@ export const kundliStyles = css`
|
|
|
31
37
|
svg {
|
|
32
38
|
display: block;
|
|
33
39
|
width: 100%;
|
|
34
|
-
max-width: 560px;
|
|
40
|
+
max-width: var(--roxy-chart-max-width, 560px);
|
|
35
41
|
aspect-ratio: 1 / 1;
|
|
36
42
|
height: auto;
|
|
37
43
|
margin: 0 auto;
|
package/src/utils/markup-data.ts
CHANGED
|
@@ -12,6 +12,51 @@ import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
|
12
12
|
*/
|
|
13
13
|
const ROXY_DATA_CLASS = 'roxy-data';
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Serialize a RoxyAPI response for embedding inside an inline `<script type="application/json" class="roxy-data">`. This is the safe writer counterpart to {@link MarkupDataController}, the reader: server-rendered and cached consumers (WordPress, JSX SSR, static HTML) emit the script with this, and the component hydrates `data` from it on connect.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Use this instead of a bare `JSON.stringify`. A raw stringify of a response that contains the literal text `</script>` (common in long interpretation prose) closes the script element early, corrupting the page and creating an HTML-injection vector. This escapes the script-unsafe characters to their `\uXXXX` JSON escapes, which `JSON.parse` restores to the original characters, so the value the component receives is identical to the response you passed.
|
|
20
|
+
*
|
|
21
|
+
* `<` is the load-bearing escape (it defeats `</script>` and `<!--`). `>` and `&` are escaped for defence in depth, and U+2028 / U+2029 because they are valid in JSON yet are line terminators in a `<script>` context and break some parsers. The escapes introduce only `\uXXXX` sequences, so the replacements never feed each other and order is irrelevant.
|
|
22
|
+
*
|
|
23
|
+
* Pass the unwrapped RoxyAPI response, the same shape you would assign to `element.data`. Do not pass the SDK envelope (`{ data, error, request, response }`).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { serializeRoxyData } from '@roxyapi/ui';
|
|
28
|
+
*
|
|
29
|
+
* const { data } = await roxy.dreams.getDreamSymbol({ path: { id: 'water' } });
|
|
30
|
+
* const html = `<roxy-dream-card><script type="application/json" class="roxy-data">${serializeRoxyData(data)}</script></roxy-dream-card>`;
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function serializeRoxyData(data: unknown): string {
|
|
34
|
+
return JSON.stringify(data)
|
|
35
|
+
.replace(/</g, '\\u003c')
|
|
36
|
+
.replace(/>/g, '\\u003e')
|
|
37
|
+
.replace(/&/g, '\\u0026')
|
|
38
|
+
.replace(/\u2028/g, '\\u2028')
|
|
39
|
+
.replace(/\u2029/g, '\\u2029');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Build the complete `<script type="application/json" class="roxy-data">…</script>` element a server nests inside a `roxy-*` component for the no-JavaScript hydration path. The payload is escaped via {@link serializeRoxyData}, so it is safe to drop straight into HTML output.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* The element carries both `type="application/json"` and `class="roxy-data"` because {@link MarkupDataController} reads only a direct-child script that has both. Emit one of these inside the target component; the JavaScript `data` property still wins if it is later assigned.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { roxyDataScript } from '@roxyapi/ui';
|
|
51
|
+
*
|
|
52
|
+
* const { data } = await roxy.crystals.getCrystal({ path: { id: 'amethyst' } });
|
|
53
|
+
* const html = `<roxy-crystal-grid>${roxyDataScript(data)}</roxy-crystal-grid>`;
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export function roxyDataScript(data: unknown): string {
|
|
57
|
+
return `<script type="application/json" class="${ROXY_DATA_CLASS}">${serializeRoxyData(data)}</script>`;
|
|
58
|
+
}
|
|
59
|
+
|
|
15
60
|
/**
|
|
16
61
|
* 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
62
|
*/
|
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.
|
|
2
|
+
export const ROXY_UI_VERSION = '0.11.0';
|