bazi-chart 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AskingMing (https://askingming.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # bazi-chart
2
+
3
+ > React component + adapters for rendering Bazi / Four Pillars (八字·四柱) charts. Bilingual, inline styles, SSR-safe. Part of [BaziKit](../../README.md).
4
+
5
+ Feed `<BaziChart />` your chart data — it auto-detects the input shape, normalizes it, and renders a complete chart in Chinese, English, or both. It never calculates anything itself.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install bazi-chart
11
+ ```
12
+
13
+ `react` (>= 17) is a peer dependency. Terminology comes from [`bazi-terms`](../bazi-terms) (installed automatically).
14
+
15
+ ## Usage
16
+
17
+ `<BaziChart />` accepts either **raw output from your Bazi engine** (the two most common community shapes are auto-detected) or a **pre-normalized `NormalizedChart`**:
18
+
19
+ ```tsx
20
+ import { BaziChart } from 'bazi-chart';
21
+
22
+ // `data` = raw engine output (auto-detected) …
23
+ export default function Chart({ data }) {
24
+ return <BaziChart data={data} lang="both" theme="light" />;
25
+ }
26
+ ```
27
+
28
+ ```tsx
29
+ import { BaziChart } from 'bazi-chart';
30
+ import type { NormalizedChart } from 'bazi-chart';
31
+
32
+ // … or a chart object you built yourself.
33
+ export default ({ chart }: { chart: NormalizedChart }) => (
34
+ <BaziChart chart={chart} lang="en" theme="dark" />
35
+ );
36
+ ```
37
+
38
+ ### What it renders
39
+
40
+ Four Pillars (with main star, stem/branch glyphs colour-coded by element, hidden stems and their ten gods, Na Yin, growth stage, void branches and Shen Sha), Five-Element score bars, interactions (刑冲合会), the Luck Pillar (大运) timeline, and auxiliary palaces (命宫/身宫/胎元/胎息) when the source provides them.
41
+
42
+ ## Props
43
+
44
+ | Prop | Type | Default | Description |
45
+ | --- | --- | --- | --- |
46
+ | `data` | `unknown` | — | Raw chart data. Auto-detected and normalized. |
47
+ | `chart` | `NormalizedChart` | — | Pre-normalized chart; takes precedence over `data`. |
48
+ | `lang` | `'zh' \| 'en' \| 'both'` | `'both'` | Render language. `'both'` shows `中文 · English`. |
49
+ | `theme` | `'light' \| 'dark'` | `'light'` | Colour theme. |
50
+ | `showDaYun` | `boolean` | `true` | Show the Luck Pillar timeline. |
51
+ | `showInteractions` | `boolean` | `true` | Show the interactions panel. |
52
+ | `showFiveElements` | `boolean` | `true` | Show element score bars (when the source emits them). |
53
+ | `showShenSha` | `boolean` | `true` | Show per-pillar Shen Sha (when the source emits them). |
54
+ | `style` | `CSSProperties` | — | Merged onto the root container. |
55
+
56
+ ## Adapters
57
+
58
+ Use them directly when you want the normalized data without the component (e.g. for a custom UI, a table export, or an API response):
59
+
60
+ ```ts
61
+ import { normalize, detectEngine, fromBaziObject, fromPillarMap } from 'bazi-chart';
62
+
63
+ detectEngine(engineOutput); // 'baziObject' | 'pillarMap' | 'normalized' | 'unknown'
64
+
65
+ const chart = normalize(engineOutput); // dispatches to the right adapter
66
+ // chart.pillars, chart.dayMaster, chart.daYun, chart.interactions, ...
67
+
68
+ // Or call an adapter explicitly:
69
+ const a = fromBaziObject(baziObjectOutput); // top-level 八字 object
70
+ const b = fromPillarMap(pillarMapOutput); // pillars keyed by year/month/day/hour
71
+ ```
72
+
73
+ `normalize()` throws a clear error for unrecognized input.
74
+
75
+ ### The `NormalizedChart` model
76
+
77
+ One engine-agnostic shape (`meta`, `solarTime`, `dayMaster`, `pillars`, `fiveElements`, `daYun`, `interactions`, `extras`). Adapters only **reshape** raw output and keep original Chinese values; everything derivable (element, polarity, colour, translations) is resolved at render time via `bazi-terms`. Sections a source does not emit (e.g. element scores or palaces) are simply `undefined`.
78
+
79
+ ## Styling
80
+
81
+ Inline styles only — no CSS import, no build step, safe for SSR and any meta-framework (Next.js, Remix, Astro). Element colours follow the traditional Five-Element palette (wood=green, fire=red, earth=brown, metal=gold, water=blue), tuned for contrast in both themes. Override the surface with the `style` prop or wrap the component in your own container.
82
+
83
+ ## License
84
+
85
+ [MIT](./LICENSE) © 2026 [AskingMing](https://askingming.com).