xiaochengtu 1.0.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.
@@ -0,0 +1,412 @@
1
+ /**
2
+ * 八卦枚举
3
+ * Bagua (Eight Trigrams) enumeration
4
+ */
5
+ declare enum Trigram {
6
+ /** 乾 - Heaven */
7
+ Qian = "qian",
8
+ /** 兑 - Lake */
9
+ Dui = "dui",
10
+ /** 离 - Fire */
11
+ Li = "li",
12
+ /** 震 - Thunder */
13
+ Zhen = "zhen",
14
+ /** 巽 - Wind */
15
+ Xun = "xun",
16
+ /** 坎 - Water */
17
+ Kan = "kan",
18
+ /** 艮 - Mountain */
19
+ Gen = "gen",
20
+ /** 坤 - Earth */
21
+ Kun = "kun"
22
+ }
23
+ /**
24
+ * 五行枚举
25
+ * Wu Xing (Five Elements) enumeration
26
+ */
27
+ declare enum WuXing {
28
+ /** 金 - Metal */
29
+ Metal = "metal",
30
+ /** 木 - Wood */
31
+ Wood = "wood",
32
+ /** 水 - Water */
33
+ Water = "water",
34
+ /** 火 - Fire */
35
+ Fire = "fire",
36
+ /** 土 - Earth */
37
+ Earth = "earth"
38
+ }
39
+ /**
40
+ * 阴阳枚举
41
+ * Yin-Yang enumeration
42
+ */
43
+ declare enum YinYang {
44
+ /** 阳 */
45
+ Yang = "yang",
46
+ /** 阴 */
47
+ Yin = "yin"
48
+ }
49
+ /**
50
+ * 动态属性(升/降)
51
+ * Dynamic property (Rising/Falling)
52
+ */
53
+ declare enum DynamicProperty {
54
+ /** 升 - 外引 (Rising/Outward) */
55
+ Rising = "rising",
56
+ /** 降 - 内引 (Falling/Inward) */
57
+ Falling = "falling"
58
+ }
59
+ /**
60
+ * 四象类型
61
+ * Four Images type
62
+ */
63
+ declare enum FourImages {
64
+ /** 阖 - 向心/凝聚 */
65
+ He = "he",
66
+ /** 辟 - 离心/发散 */
67
+ Pi = "pi",
68
+ /** 往 - 外引 */
69
+ Wang = "wang",
70
+ /** 来 - 内引 */
71
+ Lai = "lai"
72
+ }
73
+ /**
74
+ * 配对结果
75
+ * Matching result
76
+ */
77
+ declare enum MatchResult {
78
+ /** 得配 - 吉 */
79
+ Match = "match",
80
+ /** 失配 - 凶 */
81
+ Mismatch = "mismatch"
82
+ }
83
+ /**
84
+ * 九宫位置
85
+ * Nine Palace positions
86
+ */
87
+ declare enum Palace {
88
+ /** 坎宫 - 正北 */
89
+ Kan = 1,
90
+ /** 坤宫 - 西南 */
91
+ Kun = 2,
92
+ /** 震宫 - 正东 */
93
+ Zhen = 3,
94
+ /** 巽宫 - 东南 */
95
+ Xun = 4,
96
+ /** 中宫 - 中央 */
97
+ Center = 5,
98
+ /** 乾宫 - 西北 */
99
+ Qian = 6,
100
+ /** 兑宫 - 正西 */
101
+ Dui = 7,
102
+ /** 艮宫 - 东北 */
103
+ Gen = 8,
104
+ /** 离宫 - 正南 */
105
+ Li = 9
106
+ }
107
+ /**
108
+ * 八卦属性
109
+ * Trigram properties
110
+ */
111
+ interface TrigramProperties {
112
+ /** 卦名 */
113
+ name: string;
114
+ /** 中文名 */
115
+ chineseName: string;
116
+ /** 先天数 */
117
+ priorHeavenNumber: number;
118
+ /** 五行 */
119
+ wuXing: WuXing;
120
+ /** 阴阳 */
121
+ yinYang: YinYang;
122
+ /** 动态属性 */
123
+ dynamicProperty: DynamicProperty;
124
+ /** 对应地盘宫位 */
125
+ palacePosition: Palace;
126
+ }
127
+ /**
128
+ * 六十四卦(重卦)
129
+ * Hexagram (64 hexagrams)
130
+ */
131
+ interface Hexagram {
132
+ /** 上卦 */
133
+ upper: Trigram;
134
+ /** 下卦 */
135
+ lower: Trigram;
136
+ }
137
+ /**
138
+ * 九宫盘面
139
+ * Nine Palace board
140
+ */
141
+ interface NinePalaceBoard {
142
+ /** Grid1 - 坎宫 */
143
+ grid1: Trigram;
144
+ /** Grid2 - 坤宫 */
145
+ grid2: Trigram;
146
+ /** Grid3 - 震宫 */
147
+ grid3: Trigram;
148
+ /** Grid4 - 巽宫 */
149
+ grid4: Trigram;
150
+ /** Grid5 - 中宫 */
151
+ grid5: Trigram;
152
+ /** Grid6 - 乾宫 */
153
+ grid6: Trigram;
154
+ /** Grid7 - 兑宫 */
155
+ grid7: Trigram;
156
+ /** Grid8 - 艮宫 */
157
+ grid8: Trigram;
158
+ /** Grid9 - 离宫 */
159
+ grid9: Trigram;
160
+ }
161
+ /**
162
+ * 单宫分析结果
163
+ * Single palace analysis result
164
+ */
165
+ interface PalaceAnalysis {
166
+ /** 宫位 */
167
+ palace: Palace;
168
+ /** 天盘卦 */
169
+ skyTrigram: Trigram;
170
+ /** 地盘卦 */
171
+ earthTrigram: Trigram;
172
+ /** 四象 */
173
+ fourImage: FourImages;
174
+ /** 配对结果 */
175
+ matchResult: MatchResult;
176
+ /** 综合吉凶描述 */
177
+ fortune: string;
178
+ }
179
+ /**
180
+ * 完整排盘结果
181
+ * Complete divination result
182
+ */
183
+ interface XiaoChengTuResult {
184
+ /** 本卦 */
185
+ baseHexagram: Hexagram;
186
+ /** 变卦 */
187
+ changedHexagram: Hexagram;
188
+ /** 本卦互卦 */
189
+ baseMutualHexagram: Hexagram;
190
+ /** 变卦互卦 */
191
+ changedMutualHexagram: Hexagram;
192
+ /** 九宫天盘 */
193
+ board: NinePalaceBoard;
194
+ /** 各宫分析 */
195
+ palaceAnalyses: PalaceAnalysis[];
196
+ }
197
+
198
+ /**
199
+ * 八卦属性表
200
+ * Trigram properties lookup table
201
+ */
202
+ declare const TRIGRAM_PROPERTIES: Record<Trigram, TrigramProperties>;
203
+ /**
204
+ * 先天数到八卦的映射
205
+ * Prior Heaven number to Trigram mapping
206
+ */
207
+ declare const NUMBER_TO_TRIGRAM: Record<number, Trigram>;
208
+ /**
209
+ * 宫位到地盘八卦的映射
210
+ * Palace to Earth trigram mapping
211
+ */
212
+ declare const PALACE_TO_EARTH_TRIGRAM: Record<Palace, Trigram>;
213
+ declare const TRIGRAM_BINARY_CORRECT: Record<Trigram, [number, number, number]>;
214
+ /**
215
+ * 从二进制转换到八卦
216
+ * Binary to Trigram conversion
217
+ */
218
+ declare const BINARY_TO_TRIGRAM: Record<string, Trigram>;
219
+ /**
220
+ * 同位异性卦列表(用于定中宫判断)
221
+ * Same position, opposite nature hexagrams
222
+ */
223
+ declare const OPPOSITE_HEXAGRAMS: Array<{
224
+ upper: Trigram;
225
+ lower: Trigram;
226
+ name: string;
227
+ }>;
228
+
229
+ /**
230
+ * 数字取余转换为八卦
231
+ * Convert number to trigram (with modulo 8)
232
+ * @param num - 输入数字
233
+ * @returns 对应的八卦
234
+ */
235
+ declare function numberToTrigram(num: number): Trigram;
236
+ /**
237
+ * 生成互卦
238
+ * Generate mutual hexagram from a hexagram
239
+ * 互卦:取原卦的 3-5 爻为上卦,2-4 爻为下卦
240
+ * @param hexagram - 原卦
241
+ * @returns 互卦
242
+ */
243
+ declare function generateMutualHexagram(hexagram: Hexagram): Hexagram;
244
+ /**
245
+ * 判断是否为八纯卦
246
+ * Check if hexagram is pure (upper = lower)
247
+ * @param hexagram - 卦象
248
+ * @returns 是否为八纯卦
249
+ */
250
+ declare function isPureHexagram(hexagram: Hexagram): boolean;
251
+ /**
252
+ * 判断是否为同位异性卦
253
+ * Check if hexagram is an opposite-nature hexagram
254
+ * @param hexagram - 卦象
255
+ * @returns 是否为同位异性卦
256
+ */
257
+ declare function isOppositeHexagram(hexagram: Hexagram): boolean;
258
+ /**
259
+ * 归藏算法计算中宫
260
+ * Guicang algorithm for center palace calculation
261
+ * 同性为阴,异性为阳
262
+ * @param upper - 上卦
263
+ * @param lower - 下卦
264
+ * @returns 归藏结果卦
265
+ */
266
+ declare function guiCangAlgorithm(upper: Trigram, lower: Trigram): Trigram;
267
+ /**
268
+ * 计算中宫
269
+ * Calculate center palace trigram
270
+ * @param baseHexagram - 本卦
271
+ * @param changedHexagram - 变卦
272
+ * @returns 中宫八卦
273
+ */
274
+ declare function calculateCenterPalace(baseHexagram: Hexagram, changedHexagram: Hexagram): Trigram;
275
+ /**
276
+ * 装天盘
277
+ * Build sky palace board
278
+ * @param baseHexagram - 本卦
279
+ * @param changedHexagram - 变卦
280
+ * @param baseMutualHexagram - 本卦互卦
281
+ * @param changedMutualHexagram - 变卦互卦
282
+ * @param centerTrigram - 中宫卦
283
+ * @returns 九宫天盘
284
+ */
285
+ declare function buildSkyBoard(baseHexagram: Hexagram, changedHexagram: Hexagram, baseMutualHexagram: Hexagram, changedMutualHexagram: Hexagram, centerTrigram: Trigram): NinePalaceBoard;
286
+ /**
287
+ * 计算四象
288
+ * Calculate four images
289
+ * @param skyTrigram - 天盘卦
290
+ * @param earthTrigram - 地盘卦
291
+ * @returns 四象类型
292
+ */
293
+ declare function calculateFourImages(skyTrigram: Trigram, earthTrigram: Trigram): FourImages;
294
+ /**
295
+ * 计算配对结果
296
+ * Calculate matching result
297
+ * @param skyTrigram - 天盘卦
298
+ * @param earthTrigram - 地盘卦
299
+ * @returns 配对结果
300
+ */
301
+ declare function calculateMatchResult(skyTrigram: Trigram, earthTrigram: Trigram): MatchResult;
302
+ /**
303
+ * 生成吉凶描述
304
+ * Generate fortune description
305
+ * @param fourImage - 四象
306
+ * @param matchResult - 配对结果
307
+ * @returns 吉凶描述
308
+ */
309
+ declare function generateFortuneDescription(fourImage: FourImages, matchResult: MatchResult): string;
310
+ /**
311
+ * 分析单宫
312
+ * Analyze single palace
313
+ * @param palace - 宫位
314
+ * @param skyTrigram - 天盘卦
315
+ * @returns 宫位分析结果
316
+ */
317
+ declare function analyzePalace(palace: Palace, skyTrigram: Trigram): PalaceAnalysis;
318
+ /**
319
+ * 获取八卦的中文名称
320
+ * Get Chinese name of trigram
321
+ * @param trigram - 八卦
322
+ * @returns 中文名称
323
+ */
324
+ declare function getTrigramChineseName(trigram: Trigram): string;
325
+ /**
326
+ * 获取宫位的中文名称
327
+ * Get Chinese name of palace
328
+ * @param palace - 宫位
329
+ * @returns 中文名称
330
+ */
331
+ declare function getPalaceChineseName(palace: Palace): string;
332
+
333
+ /**
334
+ * 小成图排盘输入参数
335
+ */
336
+ interface XiaoChengTuInput {
337
+ /** 本卦 */
338
+ baseHexagram: Hexagram;
339
+ /** 变卦 */
340
+ changedHexagram: Hexagram;
341
+ }
342
+ /**
343
+ * 数字起卦输入参数
344
+ */
345
+ interface NumberDivinationInput {
346
+ /** 本卦上卦数字 */
347
+ baseUpper: number;
348
+ /** 本卦下卦数字 */
349
+ baseLower: number;
350
+ /** 变卦上卦数字 */
351
+ changedUpper: number;
352
+ /** 变卦下卦数字 */
353
+ changedLower: number;
354
+ }
355
+ /**
356
+ * 小成图排盘主类
357
+ * XiaoChengTu main class
358
+ */
359
+ declare class XiaoChengTu {
360
+ private baseHexagram;
361
+ private changedHexagram;
362
+ private baseMutualHexagram;
363
+ private changedMutualHexagram;
364
+ private centerTrigram;
365
+ private result;
366
+ /**
367
+ * 使用卦象初始化
368
+ * @param input - 本卦和变卦
369
+ */
370
+ constructor(input: XiaoChengTuInput);
371
+ /**
372
+ * 从数字创建小成图实例
373
+ * Create XiaoChengTu instance from numbers
374
+ * @param input - 数字起卦参数
375
+ * @returns XiaoChengTu 实例
376
+ */
377
+ static fromNumbers(input: NumberDivinationInput): XiaoChengTu;
378
+ /**
379
+ * 随机起卦
380
+ * Generate random divination
381
+ * @returns XiaoChengTu 实例
382
+ */
383
+ static random(): XiaoChengTu;
384
+ /**
385
+ * 时间起卦
386
+ * Generate divination from current time
387
+ * @param date - 可选,指定时间。默认使用当前时间
388
+ * @returns XiaoChengTu 实例
389
+ */
390
+ static fromTime(date?: Date): XiaoChengTu;
391
+ /**
392
+ * 执行排盘
393
+ * Execute divination and generate result
394
+ * @returns 排盘结果
395
+ */
396
+ divine(): XiaoChengTuResult;
397
+ /**
398
+ * 获取指定宫位的分析结果
399
+ * Get analysis result for specific palace
400
+ * @param palace - 宫位
401
+ * @returns 宫位分析结果
402
+ */
403
+ getPalaceAnalysis(palace: Palace): PalaceAnalysis | undefined;
404
+ /**
405
+ * 输出盘面字符串(用于调试)
406
+ * Output board as string (for debugging)
407
+ * @returns 盘面字符串
408
+ */
409
+ toString(): string;
410
+ }
411
+
412
+ export { BINARY_TO_TRIGRAM, DynamicProperty, FourImages, type Hexagram, MatchResult, NUMBER_TO_TRIGRAM, type NinePalaceBoard, type NumberDivinationInput, OPPOSITE_HEXAGRAMS, PALACE_TO_EARTH_TRIGRAM, Palace, type PalaceAnalysis, TRIGRAM_BINARY_CORRECT, TRIGRAM_PROPERTIES, Trigram, type TrigramProperties, WuXing, XiaoChengTu, type XiaoChengTuInput, type XiaoChengTuResult, YinYang, analyzePalace, buildSkyBoard, calculateCenterPalace, calculateFourImages, calculateMatchResult, generateFortuneDescription, generateMutualHexagram, getPalaceChineseName, getTrigramChineseName, guiCangAlgorithm, isOppositeHexagram, isPureHexagram, numberToTrigram };