x-iztro 0.0.0-init → 0.7.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/dist/astro.d.ts +131 -0
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +179 -0
- package/dist/astro.js.map +1 -0
- package/dist/astrolabe.d.ts +222 -0
- package/dist/astrolabe.d.ts.map +1 -0
- package/dist/astrolabe.js +387 -0
- package/dist/astrolabe.js.map +1 -0
- package/dist/browser.d.ts +17 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +19 -0
- package/dist/browser.js.map +1 -0
- package/dist/data.d.ts +88 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +45 -0
- package/dist/data.js.map +1 -0
- package/dist/enums.d.ts +793 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +744 -0
- package/dist/enums.js.map +1 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +19 -0
- package/dist/errors.js.map +1 -0
- package/dist/horoscope.d.ts +203 -0
- package/dist/horoscope.d.ts.map +1 -0
- package/dist/horoscope.js +364 -0
- package/dist/horoscope.js.map +1 -0
- package/dist/i18n.d.ts +25 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +31 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +89 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +98 -0
- package/dist/internal.js.map +1 -0
- package/dist/knowledge.d.ts +210 -0
- package/dist/knowledge.d.ts.map +1 -0
- package/dist/knowledge.js +190 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +29 -0
- package/dist/node.js.map +1 -0
- package/dist/palace.d.ts +121 -0
- package/dist/palace.d.ts.map +1 -0
- package/dist/palace.js +234 -0
- package/dist/palace.js.map +1 -0
- package/dist/pattern.d.ts +60 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +87 -0
- package/dist/pattern.js.map +1 -0
- package/dist/raw-dates.d.ts +41 -0
- package/dist/raw-dates.d.ts.map +1 -0
- package/dist/raw-dates.js +42 -0
- package/dist/raw-dates.js.map +1 -0
- package/dist/reverse.d.ts +69 -0
- package/dist/reverse.d.ts.map +1 -0
- package/dist/reverse.js +33 -0
- package/dist/reverse.js.map +1 -0
- package/dist/runtime.d.ts +71 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +146 -0
- package/dist/runtime.js.map +1 -0
- package/dist/star-object.d.ts +44 -0
- package/dist/star-object.d.ts.map +1 -0
- package/dist/star-object.js +79 -0
- package/dist/star-object.js.map +1 -0
- package/dist/star.d.ts +215 -0
- package/dist/star.d.ts.map +1 -0
- package/dist/star.js +150 -0
- package/dist/star.js.map +1 -0
- package/dist/surpalaces.d.ts +68 -0
- package/dist/surpalaces.d.ts.map +1 -0
- package/dist/surpalaces.js +133 -0
- package/dist/surpalaces.js.map +1 -0
- package/dist/types-entry.d.ts +10 -0
- package/dist/types-entry.d.ts.map +1 -0
- package/dist/types-entry.js +9 -0
- package/dist/types-entry.js.map +1 -0
- package/dist/types.d.ts +402 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +47 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +74 -0
- package/dist/util.js.map +1 -0
- package/dist/x_iztro.wasm +0 -0
- package/package.json +73 -1
- package/src/astro.ts +270 -0
- package/src/astrolabe.ts +435 -0
- package/src/browser.ts +21 -0
- package/src/data.ts +123 -0
- package/src/enums.ts +835 -0
- package/src/errors.ts +29 -0
- package/src/horoscope.ts +418 -0
- package/src/i18n.ts +35 -0
- package/src/index.ts +56 -0
- package/src/internal.ts +162 -0
- package/src/knowledge.ts +355 -0
- package/src/node.ts +31 -0
- package/src/palace.ts +259 -0
- package/src/pattern.ts +98 -0
- package/src/raw-dates.ts +56 -0
- package/src/reverse.ts +90 -0
- package/src/runtime.ts +207 -0
- package/src/star-object.ts +87 -0
- package/src/star.ts +294 -0
- package/src/surpalaces.ts +157 -0
- package/src/types-entry.ts +10 -0
- package/src/types.ts +448 -0
- package/src/util.ts +97 -0
package/src/palace.ts
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 宫位。
|
|
3
|
+
*
|
|
4
|
+
* 宫位是星盘的基本单元:星耀落在宫位上,四化飞星在宫位之间发生,大限与小限也按宫位排布。
|
|
5
|
+
* 判断方法一律基于语言无关标识,同时兼容当前语言的星名与宫名。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { MUTAGEN_ORDER, type EarthlyBranch, type HeavenlyStem, type Mutagen, type PalaceName } from './enums.js';
|
|
9
|
+
import { chartQuery, palaceCharts } from './internal.js';
|
|
10
|
+
import type { Astrolabe } from './astrolabe.js';
|
|
11
|
+
import { Star, starIdentifiers } from './star-object.js';
|
|
12
|
+
import type { SurroundedPalaces } from './surpalaces.js';
|
|
13
|
+
import type { DecadalData, PalaceData, TextOptions } from './types.js';
|
|
14
|
+
|
|
15
|
+
/** 宫位的大限 */
|
|
16
|
+
export type Decadal = Readonly<DecadalData>;
|
|
17
|
+
|
|
18
|
+
/** 宫位定位:宫位对象、宫位索引 0-11,或宫名标识 / 当前语言的宫名 */
|
|
19
|
+
export type PalaceTarget = Palace | number | PalaceName | string;
|
|
20
|
+
|
|
21
|
+
/** 宫位 */
|
|
22
|
+
export class Palace {
|
|
23
|
+
/** 宫位索引 0-11,0 为寅宫 */
|
|
24
|
+
readonly index: number;
|
|
25
|
+
/** 宫名(按排盘语言翻译) */
|
|
26
|
+
readonly name: string;
|
|
27
|
+
/** 宫名标识 */
|
|
28
|
+
readonly nameKey: PalaceName;
|
|
29
|
+
/** 是否身宫 */
|
|
30
|
+
readonly isBodyPalace: boolean;
|
|
31
|
+
/** 是否来因宫 */
|
|
32
|
+
readonly isOriginalPalace: boolean;
|
|
33
|
+
/** 宫干(翻译文本) */
|
|
34
|
+
readonly heavenlyStem: string;
|
|
35
|
+
/** 宫干标识 */
|
|
36
|
+
readonly heavenlyStemKey: HeavenlyStem;
|
|
37
|
+
/** 宫支(翻译文本) */
|
|
38
|
+
readonly earthlyBranch: string;
|
|
39
|
+
/** 宫支标识 */
|
|
40
|
+
readonly earthlyBranchKey: EarthlyBranch;
|
|
41
|
+
/** 主星 */
|
|
42
|
+
readonly majorStars: readonly Star[];
|
|
43
|
+
/** 辅星 */
|
|
44
|
+
readonly minorStars: readonly Star[];
|
|
45
|
+
/** 杂耀 */
|
|
46
|
+
readonly adjectiveStars: readonly Star[];
|
|
47
|
+
/** 长生十二神(翻译文本) */
|
|
48
|
+
readonly changsheng12: string;
|
|
49
|
+
/** 长生十二神标识(`Changsheng12` 取值) */
|
|
50
|
+
readonly changsheng12Key: string;
|
|
51
|
+
/** 博士十二神(翻译文本) */
|
|
52
|
+
readonly boshi12: string;
|
|
53
|
+
/** 博士十二神标识(`Boshi12` 取值) */
|
|
54
|
+
readonly boshi12Key: string;
|
|
55
|
+
/** 将前十二神(翻译文本) */
|
|
56
|
+
readonly jiangqian12: string;
|
|
57
|
+
/** 将前十二神标识(`Jiangqian12` 取值) */
|
|
58
|
+
readonly jiangqian12Key: string;
|
|
59
|
+
/** 岁前十二神(翻译文本) */
|
|
60
|
+
readonly suiqian12: string;
|
|
61
|
+
/** 岁前十二神标识(`Suiqian12` 取值) */
|
|
62
|
+
readonly suiqian12Key: string;
|
|
63
|
+
/** 大限 */
|
|
64
|
+
readonly decadal: Decadal;
|
|
65
|
+
/** 小限经过的虚岁 */
|
|
66
|
+
readonly ages: readonly number[];
|
|
67
|
+
/**
|
|
68
|
+
* 本宫天干化出的四颗星标识,顺序为禄、权、科、忌。
|
|
69
|
+
* 取自排盘时生效的四化表,自定义四化表(`ChartConfig.mutagens`)会反映在这里,飞星判断随之改变。
|
|
70
|
+
*/
|
|
71
|
+
readonly mutagenStarKeys: readonly [string, string, string, string];
|
|
72
|
+
|
|
73
|
+
/** 由内核 DTO 构造;挂到星盘上的宫位由星盘构造时回填所属星盘 */
|
|
74
|
+
constructor(data: PalaceData) {
|
|
75
|
+
this.index = data.index;
|
|
76
|
+
this.name = data.name;
|
|
77
|
+
this.nameKey = data.nameKey;
|
|
78
|
+
this.isBodyPalace = data.isBodyPalace;
|
|
79
|
+
this.isOriginalPalace = data.isOriginalPalace;
|
|
80
|
+
this.heavenlyStem = data.heavenlyStem;
|
|
81
|
+
this.heavenlyStemKey = data.heavenlyStemKey;
|
|
82
|
+
this.earthlyBranch = data.earthlyBranch;
|
|
83
|
+
this.earthlyBranchKey = data.earthlyBranchKey;
|
|
84
|
+
this.majorStars = data.majorStars.map((s) => new Star(s));
|
|
85
|
+
this.minorStars = data.minorStars.map((s) => new Star(s));
|
|
86
|
+
this.adjectiveStars = data.adjectiveStars.map((s) => new Star(s));
|
|
87
|
+
this.changsheng12 = data.changsheng12;
|
|
88
|
+
this.changsheng12Key = data.changsheng12Key;
|
|
89
|
+
this.boshi12 = data.boshi12;
|
|
90
|
+
this.boshi12Key = data.boshi12Key;
|
|
91
|
+
this.jiangqian12 = data.jiangqian12;
|
|
92
|
+
this.jiangqian12Key = data.jiangqian12Key;
|
|
93
|
+
this.suiqian12 = data.suiqian12;
|
|
94
|
+
this.suiqian12Key = data.suiqian12Key;
|
|
95
|
+
this.decadal = { ...data.decadal, range: [data.decadal.range[0], data.decadal.range[1]] };
|
|
96
|
+
this.ages = [...data.ages];
|
|
97
|
+
this.mutagenStarKeys = [...data.mutagenStarKeys];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ------ 星耀判断 ------
|
|
101
|
+
|
|
102
|
+
/** 是否包含指定的 **全部** 星耀(星耀标识或当前语言的星名) */
|
|
103
|
+
has(stars: readonly string[]): boolean {
|
|
104
|
+
const ids = this.#identifiers();
|
|
105
|
+
return stars.every((s) => ids.has(s));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** 是否 **一颗都不** 包含指定的星耀 */
|
|
109
|
+
notHave(stars: readonly string[]): boolean {
|
|
110
|
+
const ids = this.#identifiers();
|
|
111
|
+
return stars.every((s) => !ids.has(s));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 是否包含指定星耀中的 **至少一颗** */
|
|
115
|
+
hasOneOf(stars: readonly string[]): boolean {
|
|
116
|
+
const ids = this.#identifiers();
|
|
117
|
+
return stars.some((s) => ids.has(s));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** 是否有指定四化(只看主星与辅星) */
|
|
121
|
+
hasMutagen(mutagen: Mutagen): boolean {
|
|
122
|
+
return [...this.majorStars, ...this.minorStars].some((s) => s.mutagenKey === mutagen);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** 是否没有指定四化 */
|
|
126
|
+
notHaveMutagen(mutagen: Mutagen): boolean {
|
|
127
|
+
return !this.hasMutagen(mutagen);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 是否空宫(无十四主星)。
|
|
132
|
+
*
|
|
133
|
+
* @param excludeStars 视为「不空」的星耀;宫内出现其中任一颗即不作空宫论
|
|
134
|
+
*/
|
|
135
|
+
isEmpty(excludeStars?: readonly string[]): boolean {
|
|
136
|
+
if (this.majorStars.length > 0) return false;
|
|
137
|
+
return !(excludeStars !== undefined && this.hasOneOf(excludeStars));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** 宫位所属星盘;脱离星盘单独构造的宫位为 undefined */
|
|
141
|
+
astrolabe(): Astrolabe | undefined {
|
|
142
|
+
return palaceCharts.get(this);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 本宫的语义化文本:面向语言模型与人的单宫完整描述(Markdown 子集,按排盘语言输出)。
|
|
147
|
+
*
|
|
148
|
+
* @throws Error 宫位脱离星盘单独构造,没有排盘上下文可转发
|
|
149
|
+
* @throws IztroError `knowledge: true` 而排盘语言没有内嵌包(目前只有 zh-CN);
|
|
150
|
+
* `knowledgeDepth: 'summary'` 而未给 knowledge,或所给的包缺摘要
|
|
151
|
+
*/
|
|
152
|
+
toText(options: TextOptions = {}): string {
|
|
153
|
+
return chartQuery(this.#chart('toText'), 'palaceToText', {
|
|
154
|
+
palaceIndex: this.index,
|
|
155
|
+
knowledge: options.knowledge,
|
|
156
|
+
detail: options.detail,
|
|
157
|
+
knowledgeDepth: options.knowledgeDepth,
|
|
158
|
+
patternConfig: options.config,
|
|
159
|
+
}) as string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** 本宫的对宫(索引 +6);命宫对迁移、财帛对福德。脱离星盘时为 undefined */
|
|
163
|
+
oppositePalace(): Palace | undefined {
|
|
164
|
+
return palaceCharts.get(this)?.palaces[(this.index + 6) % 12];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** 本宫的三方四正;脱离星盘时为 undefined */
|
|
168
|
+
surroundedPalaces(): SurroundedPalaces | undefined {
|
|
169
|
+
return palaceCharts.get(this)?.surroundedPalaces(this.index);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ------ 四化飞星 ------
|
|
173
|
+
|
|
174
|
+
/** 本宫天干在指定四化位上的星耀标识,顺序同传入顺序 */
|
|
175
|
+
mutagenStars(mutagens: Mutagen | readonly Mutagen[]): string[] {
|
|
176
|
+
const list = typeof mutagens === 'string' ? [mutagens] : mutagens;
|
|
177
|
+
const out: string[] = [];
|
|
178
|
+
for (const m of list) {
|
|
179
|
+
const idx = MUTAGEN_ORDER.indexOf(m);
|
|
180
|
+
const key = idx < 0 ? undefined : this.mutagenStarKeys[idx];
|
|
181
|
+
if (key !== undefined) out.push(key);
|
|
182
|
+
}
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** 本宫天干的指定四化星是否 **全部** 落在目标宫位;四化列表为空时为 false */
|
|
187
|
+
fliesTo(target: PalaceTarget, mutagens: Mutagen | readonly Mutagen[]): boolean {
|
|
188
|
+
const to = this.#resolve(target);
|
|
189
|
+
if (to === undefined) return false;
|
|
190
|
+
const stars = this.mutagenStars(mutagens);
|
|
191
|
+
return stars.length > 0 && to.has(stars);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** 本宫天干的指定四化星是否有 **任意一颗** 落在目标宫位;四化列表为空时为 true */
|
|
195
|
+
fliesOneOfTo(target: PalaceTarget, mutagens: Mutagen | readonly Mutagen[]): boolean {
|
|
196
|
+
const to = this.#resolve(target);
|
|
197
|
+
if (to === undefined) return false;
|
|
198
|
+
const stars = this.mutagenStars(mutagens);
|
|
199
|
+
return stars.length === 0 || to.hasOneOf(stars);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** 本宫天干的指定四化星是否 **一颗都不** 落在目标宫位;四化列表为空时为 true */
|
|
203
|
+
notFlyTo(target: PalaceTarget, mutagens: Mutagen | readonly Mutagen[]): boolean {
|
|
204
|
+
const to = this.#resolve(target);
|
|
205
|
+
if (to === undefined) return false;
|
|
206
|
+
const stars = this.mutagenStars(mutagens);
|
|
207
|
+
return stars.length === 0 || to.notHave(stars);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** 本宫天干的指定四化星是否 **全部** 落在本宫(自化) */
|
|
211
|
+
selfMutaged(mutagens: Mutagen | readonly Mutagen[]): boolean {
|
|
212
|
+
return this.has(this.mutagenStars(mutagens));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** 本宫是否有指定四化中任一种自化;不传或传空表示检查全部四化 */
|
|
216
|
+
selfMutagedOneOf(mutagens?: Mutagen | readonly Mutagen[]): boolean {
|
|
217
|
+
return this.hasOneOf(this.mutagenStars(orAllMutagens(mutagens)));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** 本宫是否没有指定四化中的任何一种自化;不传或传空表示检查全部四化 */
|
|
221
|
+
notSelfMutaged(mutagens?: Mutagen | readonly Mutagen[]): boolean {
|
|
222
|
+
return this.notHave(this.mutagenStars(orAllMutagens(mutagens)));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 本宫天干四化分别飞入哪些宫位:[禄, 权, 科, 忌],找不到的为 undefined。
|
|
227
|
+
*
|
|
228
|
+
* @param allPalaces 检索范围;不传取所属星盘的十二宫,脱离星盘且不传时返回空数组
|
|
229
|
+
*/
|
|
230
|
+
mutagedPlaces(allPalaces?: readonly Palace[]): (Palace | undefined)[] {
|
|
231
|
+
const palaces = allPalaces ?? palaceCharts.get(this)?.palaces;
|
|
232
|
+
if (palaces === undefined) return [];
|
|
233
|
+
return this.mutagenStars(MUTAGEN_ORDER).map((key) => palaces.find((p) => p.has([key])));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
#resolve(target: PalaceTarget): Palace | undefined {
|
|
237
|
+
if (target instanceof Palace) return target;
|
|
238
|
+
return palaceCharts.get(this)?.palace(target);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
#identifiers(): Set<string> {
|
|
242
|
+
return starIdentifiers([...this.majorStars, ...this.minorStars, ...this.adjectiveStars]);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
#chart(method: string): Astrolabe {
|
|
246
|
+
const chart = palaceCharts.get(this);
|
|
247
|
+
if (chart === undefined) {
|
|
248
|
+
throw new Error(`${method} needs the owning chart: get the palace from an Astrolabe`);
|
|
249
|
+
}
|
|
250
|
+
return chart;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** 空值回退为全部四化,顺序为禄、权、科、忌 */
|
|
255
|
+
function orAllMutagens(mutagens: Mutagen | readonly Mutagen[] | undefined): readonly Mutagen[] {
|
|
256
|
+
if (mutagens === undefined) return MUTAGEN_ORDER;
|
|
257
|
+
const list = typeof mutagens === 'string' ? [mutagens] : mutagens;
|
|
258
|
+
return list.length > 0 ? list : MUTAGEN_ORDER;
|
|
259
|
+
}
|
package/src/pattern.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 格局命中。
|
|
3
|
+
*
|
|
4
|
+
* 判定在内核完成(规则见文档站「格局」一页),这里只把命中结果包成对象。
|
|
5
|
+
* 本命盘调用 `Astrolabe.patterns()`,运限某层视角调用 `Horoscope.patterns(scope)`。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Brightness, Mutagen, PalaceName, PatternKey, Scope } from './enums.js';
|
|
9
|
+
import type { PatternHitData, PatternStarData } from './types.js';
|
|
10
|
+
|
|
11
|
+
/** 参与成格的一颗星及其落宫 */
|
|
12
|
+
export class PatternStar {
|
|
13
|
+
/** 星耀标识 */
|
|
14
|
+
readonly key: string;
|
|
15
|
+
/** 星耀名称(按排盘语言翻译) */
|
|
16
|
+
readonly name: string;
|
|
17
|
+
/** 落宫索引 0-11,0 为寅宫 */
|
|
18
|
+
readonly palaceIndex: number;
|
|
19
|
+
/** 亮度显示文本,无亮度为 undefined */
|
|
20
|
+
readonly brightness: string | undefined;
|
|
21
|
+
/** 亮度标识,无亮度为 undefined */
|
|
22
|
+
readonly brightnessKey: Brightness | undefined;
|
|
23
|
+
/** 判定视角下的四化显示文本(本命为生年四化,运限为该层四化),无四化为 undefined */
|
|
24
|
+
readonly mutagen: string | undefined;
|
|
25
|
+
/** 四化标识,无四化为 undefined */
|
|
26
|
+
readonly mutagenKey: Mutagen | undefined;
|
|
27
|
+
|
|
28
|
+
constructor(data: PatternStarData) {
|
|
29
|
+
this.key = data.key;
|
|
30
|
+
this.name = data.name;
|
|
31
|
+
this.palaceIndex = data.palaceIndex;
|
|
32
|
+
this.brightness = data.brightness;
|
|
33
|
+
this.brightnessKey = data.brightnessKey;
|
|
34
|
+
this.mutagen = data.mutagen;
|
|
35
|
+
this.mutagenKey = data.mutagenKey;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 亮度是否为指定值 */
|
|
39
|
+
hasBrightness(brightness: Brightness): boolean {
|
|
40
|
+
return this.brightnessKey !== undefined && this.brightnessKey === brightness;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 四化是否为指定值 */
|
|
44
|
+
hasMutagen(mutagen: Mutagen): boolean {
|
|
45
|
+
return this.mutagenKey !== undefined && this.mutagenKey === mutagen;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 一次格局命中 */
|
|
50
|
+
export class PatternHit {
|
|
51
|
+
/** 格局标识(`PatternKey` 取值) */
|
|
52
|
+
readonly key: PatternKey;
|
|
53
|
+
/** 格局名称(按排盘语言翻译) */
|
|
54
|
+
readonly name: string;
|
|
55
|
+
/** 判定视角:本命为 origin,运限为该层 */
|
|
56
|
+
readonly scope: Scope;
|
|
57
|
+
/** 成格所在宫位索引 0-11:多数为命宫,「身命」类可为身宫,任一宫成格的为实际落宫 */
|
|
58
|
+
readonly palaceIndex: number;
|
|
59
|
+
/** 成格宫位在该视角下的宫名(按排盘语言翻译) */
|
|
60
|
+
readonly palaceName: string;
|
|
61
|
+
/** 宫名标识 */
|
|
62
|
+
readonly palaceNameKey: PalaceName;
|
|
63
|
+
/** 「破格 / 加杀平常」条件是否触发:成格照报,仅作标记 */
|
|
64
|
+
readonly broken: boolean;
|
|
65
|
+
/** 参与成格的星与落宫 */
|
|
66
|
+
readonly stars: readonly PatternStar[];
|
|
67
|
+
/** 多口径格局命中的口径(如君臣庆会四形式),单口径为 undefined */
|
|
68
|
+
readonly variant: string | undefined;
|
|
69
|
+
readonly #data: PatternHitData;
|
|
70
|
+
|
|
71
|
+
constructor(data: PatternHitData) {
|
|
72
|
+
this.#data = data;
|
|
73
|
+
this.key = data.key as PatternKey;
|
|
74
|
+
this.name = data.name;
|
|
75
|
+
this.scope = data.scope;
|
|
76
|
+
this.palaceIndex = data.palaceIndex;
|
|
77
|
+
this.palaceName = data.palaceName;
|
|
78
|
+
this.palaceNameKey = data.palaceNameKey;
|
|
79
|
+
this.broken = data.broken;
|
|
80
|
+
this.stars = data.stars.map((s) => new PatternStar(s));
|
|
81
|
+
this.variant = data.variant;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 是否为指定格局 */
|
|
85
|
+
is(key: PatternKey): boolean {
|
|
86
|
+
return this.key === key;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 成格宫位在该视角下是否为指定宫名(宫名标识或当前语言的宫名) */
|
|
90
|
+
inPalace(name: PalaceName | string): boolean {
|
|
91
|
+
return name === this.palaceNameKey || name === this.palaceName;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 命中的 DTO(camelCase 键,值按排盘语言翻译)的深拷贝 */
|
|
95
|
+
toJSON(): PatternHitData {
|
|
96
|
+
return structuredClone(this.#data);
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/raw-dates.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 星盘上的结构化出生日期:数字化农历生日与四柱干支。
|
|
3
|
+
*
|
|
4
|
+
* 是 `lunarDate` / `chineseDate` 两个展示串的数据形式,做日期运算或按干支查表时用它,不必解析展示串。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { EarthlyBranch, HeavenlyStem } from './enums.js';
|
|
8
|
+
import type { Pillar } from './reverse.js';
|
|
9
|
+
import type { RawChineseDateData, RawLunarDate } from './types.js';
|
|
10
|
+
|
|
11
|
+
/** 四柱干支:每柱 [天干, 地支],译文与标识两组 */
|
|
12
|
+
export class RawChineseDate {
|
|
13
|
+
/** 年柱(翻译文本) */
|
|
14
|
+
readonly yearly: readonly [string, string];
|
|
15
|
+
/** 月柱(翻译文本) */
|
|
16
|
+
readonly monthly: readonly [string, string];
|
|
17
|
+
/** 日柱(翻译文本) */
|
|
18
|
+
readonly daily: readonly [string, string];
|
|
19
|
+
/** 时柱(翻译文本) */
|
|
20
|
+
readonly hourly: readonly [string, string];
|
|
21
|
+
/** 年柱标识 */
|
|
22
|
+
readonly yearlyKeys: readonly [HeavenlyStem, EarthlyBranch];
|
|
23
|
+
/** 月柱标识 */
|
|
24
|
+
readonly monthlyKeys: readonly [HeavenlyStem, EarthlyBranch];
|
|
25
|
+
/** 日柱标识 */
|
|
26
|
+
readonly dailyKeys: readonly [HeavenlyStem, EarthlyBranch];
|
|
27
|
+
/** 时柱标识 */
|
|
28
|
+
readonly hourlyKeys: readonly [HeavenlyStem, EarthlyBranch];
|
|
29
|
+
|
|
30
|
+
constructor(data: RawChineseDateData) {
|
|
31
|
+
this.yearly = [...data.yearly];
|
|
32
|
+
this.monthly = [...data.monthly];
|
|
33
|
+
this.daily = [...data.daily];
|
|
34
|
+
this.hourly = [...data.hourly];
|
|
35
|
+
this.yearlyKeys = [...data.yearlyKeys];
|
|
36
|
+
this.monthlyKeys = [...data.monthlyKeys];
|
|
37
|
+
this.dailyKeys = [...data.dailyKeys];
|
|
38
|
+
this.hourlyKeys = [...data.hourlyKeys];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 四柱标识 [年, 月, 日, 时],可直接交给 `util.translateChineseDate`,
|
|
43
|
+
* 或展开交给 `solarDatesByBazi(...pillarKeys)`。
|
|
44
|
+
*/
|
|
45
|
+
pillarKeys(): [Pillar, Pillar, Pillar, Pillar] {
|
|
46
|
+
return [this.yearlyKeys, this.monthlyKeys, this.dailyKeys, this.hourlyKeys];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 结构化的出生日期 */
|
|
51
|
+
export interface RawDates {
|
|
52
|
+
/** 数字化农历生日 */
|
|
53
|
+
readonly lunarDate: Readonly<RawLunarDate>;
|
|
54
|
+
/** 四柱干支 */
|
|
55
|
+
readonly chineseDate: RawChineseDate;
|
|
56
|
+
}
|
package/src/reverse.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 反推:由八字四柱或星盘特征反查候选生辰。
|
|
3
|
+
*
|
|
4
|
+
* 计算全部在内核完成(剪枝枚举 + 正排终验,与正向排盘零分歧)。星盘布局与性别无关,反推的目标是生辰,故不收性别。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { EarthlyBranch, FiveElementsClass, HeavenlyStem, TimeIndex } from './enums.js';
|
|
8
|
+
import { query } from './runtime.js';
|
|
9
|
+
import type { ChartConfig } from './types.js';
|
|
10
|
+
|
|
11
|
+
/** 一柱干支:[天干标识, 地支标识] */
|
|
12
|
+
export type Pillar = readonly [HeavenlyStem, EarthlyBranch];
|
|
13
|
+
|
|
14
|
+
/** 一个候选生辰,可直接交给 `astro.bySolar` 排盘 */
|
|
15
|
+
export interface BirthCandidate {
|
|
16
|
+
/** 公历日期 `Y-M-D` */
|
|
17
|
+
solarDate: string;
|
|
18
|
+
/** 时辰索引 0-12(0 为早子时,12 为晚子时) */
|
|
19
|
+
timeIndex: TimeIndex;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 一颗星与其落宫地支:星盘特征反推的原子条件 */
|
|
23
|
+
export interface StarPosition {
|
|
24
|
+
/** 星耀标识(须为本命盘星耀,流耀不接受) */
|
|
25
|
+
star: string;
|
|
26
|
+
/** 落宫地支标识 */
|
|
27
|
+
branch: EarthlyBranch;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 星盘特征反推的条件集。全部可选,但至少要给一个条件;条件越具体(命宫地支、生年四化、主星落宫)反推越快 */
|
|
31
|
+
export interface ReverseCriteria {
|
|
32
|
+
/** 命宫地支 */
|
|
33
|
+
soulBranch?: EarthlyBranch | undefined;
|
|
34
|
+
/** 身宫地支 */
|
|
35
|
+
bodyBranch?: EarthlyBranch | undefined;
|
|
36
|
+
/** 五行局 */
|
|
37
|
+
fiveElementsClass?: FiveElementsClass | undefined;
|
|
38
|
+
/** 星耀落宫条件,全部须同时满足 */
|
|
39
|
+
stars?: readonly StarPosition[] | undefined;
|
|
40
|
+
/** 生年四化 [禄, 权, 科, 忌] 各自是哪颗星(星耀标识),不限定的位次写 null */
|
|
41
|
+
mutagens?: readonly [string | null, string | null, string | null, string | null] | undefined;
|
|
42
|
+
/** 公历年闭区间 [起, 止],须落在 1-9999 内;默认 [1900, 2100] */
|
|
43
|
+
yearRange?: readonly [number, number] | undefined;
|
|
44
|
+
/** 是否修正闰月(与排盘入参同义),默认 true */
|
|
45
|
+
fixLeap?: boolean | undefined;
|
|
46
|
+
/** 候选数上限:达到即停止搜索并置 truncated;省略或 0 取内核默认(512) */
|
|
47
|
+
limit?: number | undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 星盘特征反推的结果 */
|
|
51
|
+
export interface ReverseResult {
|
|
52
|
+
/** 满足全部条件的候选生辰,按枚举序:农历年升序,年内依 月→时辰→日;同一年内不保证公历日期升序 */
|
|
53
|
+
candidates: BirthCandidate[];
|
|
54
|
+
/** 是否因达到候选数上限而提前截断;截断时枚举序更靠后的解未被搜索,其中可能有公历日期更早的解 */
|
|
55
|
+
truncated: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 由八字四柱反查公历生辰。
|
|
60
|
+
*
|
|
61
|
+
* 四柱按 config 的分界口径解释(年柱 yearDivide、月柱 horoscopeDivide、晚子归属 dayDivide),
|
|
62
|
+
* 与星盘 `rawDates.chineseDate` 同一套语义。一组四柱在范围内通常每约 60 年出现一次;子时可能给出早晚子两个候选。
|
|
63
|
+
*
|
|
64
|
+
* @param options.yearRange 公历年闭区间,默认 [1900, 2100],须落在 1-9999 内
|
|
65
|
+
* @throws IztroError 干支阴阳不配、年份范围非法
|
|
66
|
+
*/
|
|
67
|
+
export function solarDatesByBazi(
|
|
68
|
+
yearly: Pillar,
|
|
69
|
+
monthly: Pillar,
|
|
70
|
+
daily: Pillar,
|
|
71
|
+
hourly: Pillar,
|
|
72
|
+
options: { yearRange?: readonly [number, number]; config?: ChartConfig } = {},
|
|
73
|
+
): BirthCandidate[] {
|
|
74
|
+
const [startYear, endYear] = options.yearRange ?? [1900, 2100];
|
|
75
|
+
return query('solarDatesByBazi', {
|
|
76
|
+
pillars: [yearly, monthly, daily, hourly],
|
|
77
|
+
startYear,
|
|
78
|
+
endYear,
|
|
79
|
+
config: options.config,
|
|
80
|
+
}) as BirthCandidate[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 由星盘特征反查候选生辰。排盘配置贯穿判定(四化表、派别、分界都按它算),候选用同一配置排盘必满足全部条件。
|
|
85
|
+
*
|
|
86
|
+
* @throws IztroError 条件为空、包含流耀、年份范围非法
|
|
87
|
+
*/
|
|
88
|
+
export function reverseChart(criteria: ReverseCriteria, config?: ChartConfig): ReverseResult {
|
|
89
|
+
return query('reverseChart', { reverseCriteria: criteria, config }) as ReverseResult;
|
|
90
|
+
}
|