dsh-metaphysics 0.50.5 → 0.56.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 (44) hide show
  1. package/CHANGELOG.md +1102 -1005
  2. package/README.md +367 -355
  3. package/client.almanac.js +129 -0
  4. package/client.bazi.js +168 -0
  5. package/client.chenggu.js +129 -0
  6. package/client.convert.js +129 -0
  7. package/client.daliuren.js +167 -0
  8. package/client.fengshui.js +128 -0
  9. package/client.hepan.js +167 -0
  10. package/client.js +638 -18939
  11. package/client.liuyao.js +167 -0
  12. package/client.mbti.js +129 -0
  13. package/client.name.js +129 -0
  14. package/client.numerology.js +129 -0
  15. package/client.qimen.js +167 -0
  16. package/client.star.js +129 -0
  17. package/client.tarot.js +167 -0
  18. package/client.trend.js +167 -0
  19. package/client.xiaoliuren.js +129 -0
  20. package/client.zeri.js +129 -0
  21. package/client.ziwei.js +168 -0
  22. package/docs/assets/verification-badge.svg +13 -0
  23. package/engine/almanac.js +4 -4
  24. package/engine/bazi.js +98 -21
  25. package/engine/citations.js +320 -0
  26. package/engine/classics.js +567 -559
  27. package/engine/diff.js +350 -301
  28. package/engine/fengshui.js +272 -28
  29. package/engine/fingerprint.js +76 -0
  30. package/engine/followup.js +31 -3
  31. package/engine/geju.js +531 -475
  32. package/engine/index.js +311 -13
  33. package/engine/interpret-knowledge.js +502 -484
  34. package/engine/interpret-plain.js +383 -383
  35. package/engine/interpret.js +1885 -1867
  36. package/engine/qimen-ganying.js +134 -0
  37. package/engine/qimen-interpret.js +31 -9
  38. package/engine/qimen.js +16 -1
  39. package/engine/shensha.js +6 -3
  40. package/engine/trace.js +456 -0
  41. package/engine/ziwei.js +117 -8
  42. package/index.js +51 -3
  43. package/package.json +113 -106
  44. package//345/221/275/347/220/206/346/216/222/347/233/230.html +9418 -7122
@@ -0,0 +1,13 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="470" height="28" role="img" aria-label="公开对拍:0 处不符|128 例 · 5 剔除 · 312 紫微 · 20 奇门 · 12 交运">
2
+ <title>公开对拍:0 处不符|128 例 · 5 剔除 · 312 紫微 · 20 奇门 · 12 交运</title>
3
+ <linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient>
4
+ <rect width="470" height="28" rx="4" fill="#555"/>
5
+ <rect x="62" width="408" height="28" rx="4" fill="#1f6f3f"/>
6
+ <rect x="62" width="408" height="28" fill="url(#s)"/>
7
+ <rect width="66" height="28" rx="4" fill="#555"/>
8
+ <rect x="62" width="4" height="28" fill="#555"/>
9
+ <g fill="#fff" text-anchor="middle" font-family="Verdana,DejaVu Sans,sans-serif" font-size="11">
10
+ <text x="33" y="18">对拍</text>
11
+ <text x="266" y="18">0 处不符|128 例 · 5 剔除 · 312 紫微 · 20 奇门 · 12 交运</text>
12
+ </g>
13
+ </svg>
package/engine/almanac.js CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  toJDN, fromJDN, dayGanzhiIndex, ganzhiName, termWindow, termInstantJd, partsToJd, STEMS, BRANCHES, TERM_NAMES,
14
14
  } from './calendar.js';
15
15
  import { HEX64 } from './interpret-data.js';
16
+ import { sanheGroupOf } from './sanhe.js';
16
17
  import { assertCivil, daysInMonth } from './validate.js';
17
18
 
18
19
  /** 建除十二神(按日支相对月支顺数)。 */
@@ -59,8 +60,8 @@ const XI_SHEN = { 甲: '东北', 乙: '西北', 丙: '西南', 丁: '正南',
59
60
  export const SHENGXIAO = ['鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪'];
60
61
  const SHA_BY_GROUP = { 申子辰: '南', 寅午戌: '北', 巳酉丑: '东', 亥卯未: '西' };
61
62
  function shaOf(branch) {
62
- for (const [g, v] of Object.entries(SHA_BY_GROUP)) if (g.includes(branch)) return v;
63
- return null;
63
+ const g = sanheGroupOf(branch);
64
+ return g ? SHA_BY_GROUP[g.branches.join('')] || null : null;
64
65
  }
65
66
 
66
67
  /** 24 小时制 → 时辰地支。 */
@@ -172,7 +173,6 @@ const TAI_SHEN = {
172
173
 
173
174
  /** 六合 / 三合(对日支取吉配生肖)。 */
174
175
  const LIUHE = { 子: '丑', 丑: '子', 寅: '亥', 亥: '寅', 卯: '戌', 戌: '卯', 辰: '酉', 酉: '辰', 巳: '申', 申: '巳', 午: '未', 未: '午' };
175
- const SANHE = { 申: '申子辰', 子: '申子辰', 辰: '申子辰', 亥: '亥卯未', 卯: '亥卯未', 未: '亥卯未', 寅: '寅午戌', 午: '寅午戌', 戌: '寅午戌', 巳: '巳酉丑', 酉: '巳酉丑', 丑: '巳酉丑' };
176
176
 
177
177
  /** 每日一卦:日期哈希确定性映射到通行本 64 卦(同日同卦)。 */
178
178
  export function dailyHexagram(year, month, day) {
@@ -259,7 +259,7 @@ export function buildAlmanac(input) {
259
259
  luck: shen ? shen.luck : null,
260
260
  };
261
261
  });
262
- const sanheGroup = SANHE[dayBranch] || '';
262
+ const sanheGroup = sanheGroupOf(dayBranch)?.branches.join('') || '';
263
263
  const liuheBranch = LIUHE[dayBranch] || null;
264
264
  const lucky = {
265
265
  liuhe: liuheBranch ? SHENGXIAO[BRANCHES.indexOf(liuheBranch)] : null,
package/engine/bazi.js CHANGED
@@ -81,6 +81,68 @@ const XING_SELF = ['辰', '午', '酉', '亥'];
81
81
 
82
82
  const hasPair = (list, a, b) => list.includes(a + b) || list.includes(b + a);
83
83
 
84
+ // 旺衰用的合会折根:三会成方、三合成局时,参与支按化神折去本气;
85
+ // 六合折半;已并入会/合局的支归该局,六合只折局外那一支(否则「巳午未会火 + 午未合土」会把火局自己折掉,
86
+ // 「亥子丑会水 + 寅亥合木」也会把壬日的亥水比劫折半)。
87
+ // 只参与旺衰量化,不改盘面关系列表;半合/半会不折,避免把「有合意」当成「已成局」。
88
+ function branchRootFactors(pillars, me) {
89
+ const inMe = Object.keys(GENERATES).find((k) => GENERATES[k] === me);
90
+ const branches = ['year', 'month', 'day', 'hour'].map((k) => pillars[k].branch);
91
+ const set = new Set(branches);
92
+ const factor = {};
93
+ for (const b of branches) factor[b] = 1;
94
+ const notes = [];
95
+ const inJu = new Set();
96
+ const apply = (key, el, f, kind) => {
97
+ const hit = [];
98
+ for (const b of [...key]) {
99
+ if ((factor[b] ?? 1) > f) { factor[b] = f; hit.push(b); }
100
+ inJu.add(b);
101
+ }
102
+ if (hit.length && f < 1) notes.push(`${key}${kind}${el},${hit.join('')}根气按${Math.round(f * 10)}成计`);
103
+ };
104
+ for (const [k, el] of Object.entries(SANHUI)) {
105
+ if (![...k].every((c) => set.has(c))) continue;
106
+ apply(k, el, el === me ? 1 : el === inMe ? 0.6 : 0.1, '三会');
107
+ }
108
+ for (const [k, el] of Object.entries(SANHE)) {
109
+ if (![...k].every((c) => set.has(c))) continue;
110
+ apply(k, el, el === me ? 1 : el === inMe ? 0.6 : 0.2, '三合');
111
+ }
112
+ for (let i = 0; i < branches.length; i++) {
113
+ for (let j = i + 1; j < branches.length; j++) {
114
+ const a = branches[i];
115
+ const b = branches[j];
116
+ const el = BRANCH_HE[a + b] || BRANCH_HE[b + a];
117
+ if (!el) continue;
118
+ if (inJu.has(a) && inJu.has(b)) continue;
119
+ const f = el === me ? 1 : el === inMe ? 0.8 : 0.5;
120
+ const hit = [];
121
+ for (const x of [a, b]) {
122
+ if (inJu.has(x)) continue;
123
+ if ((factor[x] ?? 1) > f) { factor[x] = f; hit.push(x); }
124
+ }
125
+ if (hit.length && f < 1) notes.push(`${a}${b}合${el},${hit.join('')}根气按${Math.round(f * 10)}成计`);
126
+ }
127
+ }
128
+ return { factor, notes, inJu };
129
+ }
130
+
131
+ // 天干生扶是否真有根:折根后同类藏干累计 ≥0.3 才算有根(余气 0.3 折半后不足,作虚透)。
132
+ const ROOT_EFFECTIVE_MIN = 0.3;
133
+ function rootedWeightOf(pillars, el, factor) {
134
+ let w = 0;
135
+ for (const k of ['year', 'month', 'day', 'hour']) {
136
+ const pl = pillars[k];
137
+ const f = factor[pl.branch] ?? 1;
138
+ if (f <= 0.1) continue;
139
+ pl.hidden.forEach((h, i) => {
140
+ if (STEM_ELEMENT[h.stem] === el) w += (ROOT_HIDDEN_WEIGHT[i] ?? 0.1) * f;
141
+ });
142
+ }
143
+ return w;
144
+ }
145
+
84
146
  /** 干支关系:五合、相冲、相克;六合、三合半合、三会半会拱会、冲、害、破、刑 */
85
147
  export function buildRelations(pillars) {
86
148
  const stems = ['year', 'month', 'day', 'hour'].map((k) => pillars[k].stem);
@@ -93,7 +155,8 @@ export function buildRelations(pillars) {
93
155
  const b = stems[j];
94
156
  if (a === b) continue;
95
157
  const he = STEM_HE[a + b] || STEM_HE[b + a];
96
- if (he) { stemOut.push({ text: `${a}${b}合化${he}`, rank: 0 }); continue; }
158
+ // 五合只是「有合」;是否真化要看月令、化神与争合妒合,不在这一层断言
159
+ if (he) { stemOut.push({ text: `${a}${b}合(化${he}待定)`, rank: 0 }); continue; }
97
160
  if (hasPair(STEM_CHONG_PAIRS, a, b)) { stemOut.push({ text: `${a}${b}相冲`, rank: 1 }); continue; }
98
161
  const ea = STEM_ELEMENT[a];
99
162
  const eb = STEM_ELEMENT[b];
@@ -443,14 +506,16 @@ export function buildBazi(input) {
443
506
  else if (OVERCOMES[me] === seasonEl) { monthW = 0.5; monthWord = '囚'; }
444
507
  else { monthW = 0; monthWord = '死'; }
445
508
 
509
+ const factorInfo = branchRootFactors(pillars, me);
446
510
  let rootScore = 0;
447
511
  const rootBranches = [];
448
512
  for (const key of ['year', 'month', 'day', 'hour']) {
449
513
  const pl = pillars[key];
514
+ const f = factorInfo.factor[pl.branch] ?? 1;
450
515
  let hit = false;
451
516
  pl.hidden.forEach((h, i) => {
452
- if (STEM_ELEMENT[h.stem] === me) { rootScore += ROOT_HIDDEN_WEIGHT[i] ?? 0.1; hit = true; }
453
- else if (GENERATES[STEM_ELEMENT[h.stem]] === me) { rootScore += (ROOT_HIDDEN_WEIGHT[i] ?? 0.1) * 0.4; hit = true; }
517
+ if (STEM_ELEMENT[h.stem] === me) { rootScore += (ROOT_HIDDEN_WEIGHT[i] ?? 0.1) * f; hit = true; }
518
+ else if (GENERATES[STEM_ELEMENT[h.stem]] === me) { rootScore += (ROOT_HIDDEN_WEIGHT[i] ?? 0.1) * 0.4 * f; hit = true; }
454
519
  });
455
520
  if (hit) rootBranches.push(pl.branch);
456
521
  }
@@ -458,23 +523,30 @@ export function buildBazi(input) {
458
523
  let helpScore = 0;
459
524
  const helpers = [];
460
525
  const drainers = [];
526
+ const virtualHelpers = [];
461
527
  for (const key of ['year', 'month', 'hour']) {
462
528
  const st = pillars[key].stem;
463
529
  const el2 = STEM_ELEMENT[st];
464
- if (el2 === me) { helpScore += 1; helpers.push(st); }
465
- else if (GENERATES[el2] === me) { helpScore += 0.8; helpers.push(st); }
466
- else if (OVERCOMES[el2] === me) { helpScore -= 1; drainers.push(st); }
530
+ if (el2 === me || GENERATES[el2] === me) {
531
+ // 天干有根才出得上力;虚透(折根后不足 0.3)只按半力计
532
+ const base = el2 === me ? 1 : 0.8;
533
+ if (rootedWeightOf(pillars, el2, factorInfo.factor) >= ROOT_EFFECTIVE_MIN) helpScore += base;
534
+ else { helpScore += base * 0.5; virtualHelpers.push(st); }
535
+ helpers.push(st);
536
+ } else if (OVERCOMES[el2] === me) { helpScore -= 1; drainers.push(st); }
467
537
  else if (OVERCOMES[me] === el2) { helpScore -= 0.8; drainers.push(st); }
468
538
  else { helpScore -= 0.5; drainers.push(st); }
469
539
  }
470
540
 
471
541
  const total = Math.round((monthW + rootScore + helpScore) * 10) / 10;
472
542
  const level = total >= 4 ? '身强' : total >= 2.5 ? '偏强' : total >= 1.5 ? '中和' : total >= 0.5 ? '偏弱' : '身弱';
543
+ const structureText = factorInfo.notes.length ? `;合会折根:${factorInfo.notes.join('、')}` : '';
544
+ const virtualText = virtualHelpers.length ? `;虚透${virtualHelpers.join('')}帮扶减半` : '';
473
545
  const strength = {
474
546
  level,
475
547
  score: total,
476
- detail: `月令${monthBranch}${seasonEl},日主${me}${monthWord}(${monthW});通根${rootBranches.join('') || '无'}(${rootScore.toFixed(1)});天干帮扶${helpers.join('') || '无'}/耗泄${drainers.join('') || '无'}(${helpScore.toFixed(1)})`,
477
- method: '月令权重 3/2/1/0.5/0 + 地支藏干通根 + 天干帮扶,量化后分档;属简化算法,非唯一流派',
548
+ detail: `月令${monthBranch}${seasonEl},日主${me}${monthWord}(${monthW});通根${rootBranches.join('') || '无'}(${rootScore.toFixed(1)});天干帮扶${helpers.join('') || '无'}/耗泄${drainers.join('') || '无'}(${helpScore.toFixed(1)})${structureText}${virtualText}`,
549
+ method: '月令权重 3/2/1/0.5/0 + 地支藏干通根(三会/三合/六合折根)+ 天干帮扶(虚透减半),量化后分档;属简化算法,非唯一流派',
478
550
  parts: {
479
551
  season: { branch: monthBranch, element: seasonEl, word: monthWord, weight: monthW },
480
552
  roots: rootBranches,
@@ -482,6 +554,8 @@ export function buildBazi(input) {
482
554
  helpers,
483
555
  drainers,
484
556
  helpScore: Math.round(helpScore * 10) / 10,
557
+ structure: factorInfo.notes,
558
+ virtualHelpers,
485
559
  },
486
560
  };
487
561
 
@@ -576,22 +650,24 @@ export function buildBazi(input) {
576
650
 
577
651
  const p = jdToParts(jd);
578
652
 
579
- // ── 胎元 / 命宫 / 身宫 ──
653
+ // ── 胎元 / 胎息 / 命宫 / 身宫 ──
580
654
  // 胎元:月柱天干进一位、地支进三位(受胎之月的干支)
581
655
  const mStemIdx = STEMS.indexOf(pillars.month.stem);
582
656
  const mBranchIdx = BRANCHES.indexOf(pillars.month.branch);
583
657
  const taiyuan = ganzhiName(sexagenaryIndex((mStemIdx + 1) % 10, (mBranchIdx + 3) % 12));
584
- // 命宫:以子月起正月顺数至生月,再自该宫起子时逆数至生时
658
+ // 胎息:日柱天干五合、地支六合(六合两支序数之和恒为 1 mod 12)
659
+ const dayStemIdx = STEMS.indexOf(pillars.day.stem);
660
+ const dayBranchIdx = BRANCHES.indexOf(pillars.day.branch);
661
+ const taixi = ganzhiName(sexagenaryIndex((dayStemIdx + 5) % 10, (1 - dayBranchIdx + 12) % 12));
662
+ // 命宫 / 身宫:以生月、生时两支的合数定宫(Tyme 口径)。
663
+ // 命宫:27 − 月支 − 时支,取模后 +2;身宫:11 + 月支 + 时支,取模后 +2。
664
+ // 两支合数落 0–11 后并入六十甲子,天干随年干自然对齐,无需另推五虎遁。
585
665
  const hourBrIdxForGong = BRANCHES.indexOf(pillars.hour.branch);
586
- const soulIdx = (((mBranchIdx - hourBrIdxForGong) % 12) + 12) % 12;
587
- // 命宫天干按五虎遁从年干起(寅为正月)
588
- const yinStem = ((STEMS.indexOf(pillars.year.stem) % 5) * 2 + 2) % 10;
589
- const soulStemIdx = (yinStem + ((soulIdx - 2 + 12) % 12)) % 10;
590
- const minggong = ganzhiName(sexagenaryIndex(soulStemIdx, soulIdx));
591
- // 身宫:命宫对宫(相隔六位)
592
- const bodyIdx = (soulIdx + 6) % 12;
593
- const bodyStemIdx = (yinStem + ((bodyIdx - 2 + 12) % 12)) % 10;
594
- const shengong = ganzhiName(sexagenaryIndex(bodyStemIdx, bodyIdx));
666
+ const yearStemIdxForGong = STEMS.indexOf(pillars.year.stem);
667
+ const mingIdx = (((yearStemIdxForGong * 12 + ((27 - mBranchIdx - hourBrIdxForGong) % 12) + 2) % 60) + 60) % 60;
668
+ const bodyIdx = (((yearStemIdxForGong * 12 + ((11 + mBranchIdx + hourBrIdxForGong) % 12) + 2) % 60) + 60) % 60;
669
+ const minggong = ganzhiName(mingIdx);
670
+ const shengong = ganzhiName(bodyIdx);
595
671
 
596
672
  // 人元司权:按节令到出生日的日差定当权藏干(节当日为第 1 日)
597
673
  const renyuan = renyuanOf(BRANCHES[monthBranchIdx], jdnBase, prevJieTerm.jd);
@@ -602,8 +678,9 @@ export function buildBazi(input) {
602
678
  relations: buildRelations(pillars),
603
679
  palaces: {
604
680
  taiyuan: { ganzhi: taiyuan.name, note: '月干进一、月支进三' },
605
- minggong: { ganzhi: minggong.name, branch: minggong.branch, note: '子月起正月顺数至生月,再逆数至生时;干按五虎遁' },
606
- shengong: { ganzhi: shengong.name, branch: shengong.branch, note: '命宫对宫' },
681
+ taixi: { ganzhi: taixi.name, note: '日干五合、日支六合' },
682
+ minggong: { ganzhi: minggong.name, branch: minggong.branch, note: '生月与生时支合数定宫(27 减,取模后 +2);干随六十甲子' },
683
+ shengong: { ganzhi: shengong.name, branch: shengong.branch, note: '生月与生时支合数定宫(11 加,取模后 +2);干随六十甲子' },
607
684
  },
608
685
  input: {
609
686
  civil: { year, month, day, hour, minute },
@@ -0,0 +1,320 @@
1
+ // B6 引文索引:把「知识卡 → 书名 / 卷章 / 原文 / 链接」做成一张可核验的表。
2
+ //
3
+ // 两类来源:
4
+ // ① CLASSICS(engine/classics.js):八字三书,已有原文、卷章与典藏网链接;
5
+ // ② CITATIONS(本文件):紫微斗数全书,原文取自维基文库,链接到卷页。
6
+ //
7
+ // CARD_CITATIONS 给每张知识卡一个去处:
8
+ // refs 已定位到可核验原文,测试会核验 quote 是否是来源正文的子串;
9
+ // general 属于通行说 / 尚未定位到单一条文,明确标出why,不冒充原文;
10
+ // todo 尚未实现或尚未录入。
11
+ // test/citations.test.mjs 会逐条检查,并把索引导出到 docs/citations.html。
12
+
13
+ import { CLASSICS, CLASSIC_BOOKS } from './classics.js';
14
+ import { KNOWLEDGE } from './interpret-knowledge.js';
15
+ import { PATTERN_BREAK_RULES } from './ziwei.js';
16
+
17
+ export const CITATION_BOOKS = {
18
+ ziwei: {
19
+ name: '紫微斗数全书',
20
+ author: '宋·陈抟(传)',
21
+ base: 'https://zh.wikisource.org/wiki/紫微斗數全書',
22
+ },
23
+ };
24
+
25
+ // 紫微原文条目:quote 按维基文库通行本照录,plain 是本站自撰白话。
26
+ export const CITATIONS = [
27
+ {
28
+ id: 'zw-poge-sanfang',
29
+ book: 'ziwei',
30
+ chapter: '卷三·谈星要论',
31
+ quote: '及命宫星辰庙旺,三方有恶星守照破格。',
32
+ plain: '命宫主星虽庙旺,三方四正见恶星也会破格。',
33
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
34
+ },
35
+ {
36
+ id: 'zw-poge-ruge',
37
+ book: 'ziwei',
38
+ chapter: '卷三·论人命入格',
39
+ quote: '若居陷地又加杀化忌,为下格之命,不以入格而论也。',
40
+ plain: '星落陷地又见煞星、化忌,就不按入格来论。',
41
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
42
+ },
43
+ {
44
+ id: 'zw-poge-huaxiong',
45
+ book: 'ziwei',
46
+ chapter: '卷三·论人命入格',
47
+ quote: '又入格不化吉而化凶,只以本命吉凶多寡而断之。',
48
+ plain: '入了格却化吉少、化凶多,只能按原局吉凶的多寡来断。',
49
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
50
+ },
51
+ {
52
+ id: 'zw-shiyin',
53
+ book: 'ziwei',
54
+ chapter: '卷一·增补太微赋',
55
+ quote: '巨门子午二宫逢,身命逢之必贵荣,更得三方科禄照,石中隐玉是丰隆。',
56
+ plain: '巨门在子午守命,要三方有化科、化禄照会,石中隐玉才成格。',
57
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷一',
58
+ },
59
+ {
60
+ id: 'zw-jiju-poge',
61
+ book: 'ziwei',
62
+ chapter: '卷三·论诸星同垣各司所宜分别富贵贫贱夭寿',
63
+ quote: '因甲禄到寅卯宫有擎羊破格耳。',
64
+ plain: '巨机本可取贵,但擎羊落宫会把格局破掉。',
65
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
66
+ },
67
+ {
68
+ id: 'zw-riyue-jia',
69
+ book: 'ziwei',
70
+ chapter: '卷三·论诸星同垣各司所宜分别富贵贫贱夭寿',
71
+ quote: '加羊陀冲守,宜僧。',
72
+ plain: '日月夹命再加羊陀冲守,吉意大减。',
73
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
74
+ },
75
+ {
76
+ id: 'zw-changqu',
77
+ book: 'ziwei',
78
+ chapter: '卷三·论诸星同垣各司所宜分别富贵贫贱夭寿',
79
+ quote: '昌曲陷宫凶杀破虚誉之隆 凶杀即羊陀空劫。',
80
+ plain: '昌曲落陷再逢凶杀,名声易成虚誉;这里的凶杀指羊陀空劫。',
81
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
82
+ },
83
+ {
84
+ id: 'zw-kuiyue',
85
+ book: 'ziwei',
86
+ chapter: '卷三·论诸星同垣各司所宜分别富贵贫贱夭寿',
87
+ quote: '魁钺重逢杀凑痼疾尤多 杀乃羊铃空劫。',
88
+ plain: '魁钺夹命再凑煞星,贵气减等;煞指羊铃空劫。',
89
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
90
+ },
91
+ {
92
+ id: 'zw-jiyue',
93
+ book: 'ziwei',
94
+ chapter: '卷三·论诸星同垣各司所宜分别富贵贫贱夭寿',
95
+ quote: '机月同梁作吏人 命在寅申方论,加吉不论,无吉无杀亦是平常人,凶杀空劫化忌为下格。',
96
+ plain: '机月同梁要在寅申论;无吉无杀只是平常,逢凶杀空劫化忌则降为下格。',
97
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
98
+ },
99
+ {
100
+ id: 'zw-tanwu',
101
+ book: 'ziwei',
102
+ chapter: '卷三·论诸星同垣各司所宜分别富贵贫贱夭寿',
103
+ quote: '贪武申宫为下格 化忌方论。',
104
+ plain: '武贪在申本可论格,但带化忌才作下格论。',
105
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
106
+ },
107
+ {
108
+ id: 'zw-huotan',
109
+ book: 'ziwei',
110
+ chapter: '卷一·增补太微赋',
111
+ quote: '火遇贪狼照命宫,封侯食禄是英雄,三方倘若无凶杀,到老应知福寿隆。',
112
+ plain: '火贪照命本是贵格,前提是三方没有凶杀;见煞则破。',
113
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷一',
114
+ },
115
+ {
116
+ id: 'zw-luma',
117
+ book: 'ziwei',
118
+ chapter: '卷一·诸星问答论·问天马星所主若何',
119
+ quote: '如与禄存同宫,谓之禄马交驰,又曰折鞭马',
120
+ plain: '禄存与天马同宫才叫禄马交驰。',
121
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷一',
122
+ },
123
+ {
124
+ id: 'zw-luma-kong',
125
+ book: 'ziwei',
126
+ chapter: '卷一·诸星问答论·问天马星所主若何',
127
+ quote: '逢空亡谓之死马、亡马',
128
+ plain: '禄马逢空亡,称死马、亡马,奔走之力被劫。',
129
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷一',
130
+ },
131
+ {
132
+ id: 'zw-luma-tuo',
133
+ book: 'ziwei',
134
+ chapter: '卷一·诸星问答论·问天马星所主若何',
135
+ quote: '遇陀罗谓之折足马',
136
+ plain: '禄马遇陀罗,称折足马,动而受阻。',
137
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷一',
138
+ },
139
+ {
140
+ id: 'zw-sihua-ji',
141
+ book: 'ziwei',
142
+ chapter: '卷一·诸星问答论·问化忌星所主若何',
143
+ quote: '如会紫府、昌曲、左右、科权禄,与忌同宫又兼四杀共处,即发财亦不佳,功名亦不成就。',
144
+ plain: '吉星与化忌、四杀同处,即使发财也不好,功名难成。',
145
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷一',
146
+ },
147
+ {
148
+ id: 'zw-sihua-lu',
149
+ book: 'ziwei',
150
+ chapter: '卷一·诸星问答论·问化禄星所主若何',
151
+ quote: '禄为福德之神。守身命官禄之位,科权相逢必作大臣之职。',
152
+ plain: '化禄主福,与科权相会可论官职。',
153
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷一',
154
+ },
155
+ {
156
+ id: 'zw-sihua-quan',
157
+ book: 'ziwei',
158
+ chapter: '卷一·诸星问答论·问化权星所主若何',
159
+ quote: '权星掌判生杀之神。守身命科禄相逢出将入相。',
160
+ plain: '化权主掌判,与科禄相会主权位。',
161
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷一',
162
+ },
163
+ {
164
+ id: 'zw-sihua-ke',
165
+ book: 'ziwei',
166
+ chapter: '卷一·诸星问答论·问化科星所主若何',
167
+ quote: '科星上界应试,主掌文墨之星。守身命权禄相逢宰臣之贵。',
168
+ plain: '化科主文墨名声,与权禄相会主贵。',
169
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷一',
170
+ },
171
+ {
172
+ id: 'zw-sanfang',
173
+ book: 'ziwei',
174
+ chapter: '卷三·谈星要论',
175
+ quote: '三看迁移财帛官禄三方星辰刑冲克破。',
176
+ plain: '第三步就看迁移、财帛、官禄这组三方有没有刑冲克破。',
177
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
178
+ },
179
+ {
180
+ id: 'zw-shenming',
181
+ book: 'ziwei',
182
+ chapter: '卷三·谈星要论',
183
+ quote: '看身安命禄马不落空亡天空截空最紧,旬空次之。',
184
+ plain: '看身命先看禄马有没有落空亡、天空、截空。',
185
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
186
+ },
187
+ {
188
+ id: 'zw-daxian',
189
+ book: 'ziwei',
190
+ chapter: '卷三·论大限十年祸福何如',
191
+ quote: '如宫分星缠全吉庙旺得地,无擎羊陀罗火铃空劫者,主十年安静,人财全美。',
192
+ plain: '大限宫吉星庙旺且不见羊陀火铃空劫,十年较安稳。',
193
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
194
+ },
195
+ {
196
+ id: 'zw-miaowang',
197
+ book: 'ziwei',
198
+ chapter: '卷三·论诸星同垣各司所宜分别富贵贫贱夭寿',
199
+ quote: '天机 庙子午 旺辰酉 陷丑未',
200
+ plain: '天机的庙旺陷地:子午庙、辰酉旺、丑未陷。',
201
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷三',
202
+ },
203
+ {
204
+ id: 'zw-kongjie',
205
+ book: 'ziwei',
206
+ chapter: '卷一·诸星问答论·问天空地劫所主若何',
207
+ quote: '二星守身命,遇吉则吉,遇凶则凶。如四杀冲照,轻者下贱,重者六畜之命。',
208
+ plain: '空劫守身命,吉凶随会照而定;再逢四杀冲照则加重。',
209
+ url: 'https://zh.wikisource.org/wiki/紫微斗數全書/卷一',
210
+ },
211
+ ];
212
+
213
+ const BOOK_OF = {
214
+ ...Object.fromEntries(Object.entries(CLASSIC_BOOKS).map(([k, v]) => [k, v])),
215
+ ...CITATION_BOOKS,
216
+ };
217
+
218
+ export function citationOf(id) {
219
+ const hit = CITATIONS.find((c) => c.id === id) || CLASSICS.find((c) => c.id === id);
220
+ if (!hit) return null;
221
+ const book = BOOK_OF[hit.book];
222
+ return {
223
+ ...hit,
224
+ bookName: book ? book.name : hit.book,
225
+ bookAuthor: book ? book.author : '',
226
+ };
227
+ }
228
+
229
+ // 每张知识卡的去处。refs 为已定位原文;general / todo 必须写 reason,不冒充引文。
230
+ export const CARD_CITATIONS = {
231
+ // ── 八字:已定位(子平真诠 / 滴天髓 / 三命通会)
232
+ 'bazi-yueling-siquan': { refs: ['smt-renyuan'] },
233
+ 'bazi-geju': { refs: ['zp-yongshen'] },
234
+ 'bazi-suiyun': { refs: ['smt-suiyun'] },
235
+ 'bazi-sanming-duizhao': { refs: ['zp-zhenguan', 'smt-guansha-liu'] },
236
+ 'bazi-geju-chengbai': { refs: ['zp-chengbai'] },
237
+ 'bazi-huagi-bianhua': { refs: ['zp-bianhua'] },
238
+ 'bazi-zaji-quyong': { refs: ['zp-zaji'] },
239
+ 'bazi-zhuanwang-yuanwen': { refs: ['smt-quzhi', 'smt-yanshang', 'smt-congge', 'smt-runxia', 'smt-jiasi'] },
240
+ 'bazi-congge-yuanwen': { refs: ['smt-congsha', 'smt-congcai'] },
241
+ 'bazi-tongguan': { refs: ['dt-tongguan'] },
242
+ // ── 八字:通行说,暂未定位单一条文
243
+ 'bazi-tonggen-tougan': { status: 'general', book: '滴天髓', chapter: '通神论', reason: '原文为「天干得一比肩,不如得支中一墓库」一路的取象,未定位到单一整句' },
244
+ 'bazi-wangxiang': { status: 'general', book: '五行大义', chapter: '旺相休囚死', reason: '通行五行旺衰说,未见可照录的单条原文' },
245
+ 'bazi-shensha': { status: 'general', book: '三命通会', chapter: '神煞篇', reason: '神煞散见诸卷,未定位到单一条文' },
246
+ 'bazi-tiaohou': { status: 'general', book: '穷通宝鉴', chapter: '调候用神', reason: '调候表按日干月令分散,未定位到单一条文' },
247
+ 'bazi-liuqin': { status: 'general', book: '子平真诠 / 滴天髓', chapter: '六亲', reason: '星宫同参为两书通义,未定位到单一条文' },
248
+ 'bazi-kongwang': { status: 'general', book: '渊海子平', chapter: '旬空', reason: '旬空出空为通行说,未定位到单一条文' },
249
+ 'bazi-xingchong': { status: 'general', book: '三命通会', chapter: '论刑冲合害', reason: '刑冲合害散见诸卷,未定位到单一条文' },
250
+ 'bazi-dayun-jiaoqi': { status: 'general', book: '渊海子平', chapter: '起运法', reason: '三日折一年为通行起运法,未定位到单一条文' },
251
+ // ── 紫微:已定位(紫微斗数全书)
252
+ 'ziwei-sanfang': { refs: ['zw-sanfang'] },
253
+ 'ziwei-sihua': { refs: ['zw-sihua-lu', 'zw-sihua-ji'] },
254
+ 'ziwei-miaowang': { refs: ['zw-miaowang'] },
255
+ 'ziwei-daxian': { refs: ['zw-daxian'] },
256
+ 'ziwei-shengong': { refs: ['zw-shenming'] },
257
+ 'ziwei-kongjie': { refs: ['zw-kongjie'] },
258
+ 'ziwei-poge': { refs: ['zw-poge-ruge', 'zw-poge-sanfang'] },
259
+ // ── 紫微:飞星派读法不在《全书》原文内
260
+ 'ziwei-feixing': { status: 'general', book: '紫微斗数全书 / 飞星派', chapter: '四化篇', reason: '宫干飞化属飞星派传法,非《全书》单条原文' },
261
+ 'ziwei-sanfang-fei': { status: 'general', book: '紫微斗数全书 / 飞星派', chapter: '四化篇', reason: '三方四正同飞属飞星派读法,未定位到单条原文' },
262
+ 'ziwei-jichuanji': { status: 'general', book: '紫微斗数全书 / 飞星派', chapter: '四化篇', reason: '忌转忌串连属飞星派读法,未定位到单条原文' },
263
+ // ── 六爻:条目未录入原文,先标通行说
264
+ 'liuyao-yongshen': { status: 'general', book: '卜筮正宗 / 增删卜易', chapter: '用神章、伏神章', reason: '原文待录入;当前按通行用神法实现' },
265
+ 'liuyao-wangshuai': { status: 'general', book: '卜筮正宗', chapter: '月建日辰章', reason: '原文待录入' },
266
+ 'liuyao-dongbian': { status: 'general', book: '卜筮正宗 / 增删卜易', chapter: '动变章、进神退神', reason: '原文待录入' },
267
+ 'liuyao-fushen': { status: 'general', book: '卜筮正宗 / 增删卜易', chapter: '伏神章', reason: '原文待录入' },
268
+ 'liuyao-yongshen-shuai': { status: 'general', book: '增删卜易 / 卜筮正宗', chapter: '月建章、日辰章', reason: '原文待录入' },
269
+ 'liuyao-quanggu-shuai': { status: 'general', book: '增删卜易 / 卜筮正宗', chapter: '六爻旺衰论', reason: '原文待录入' },
270
+ 'liuyao-yingqi': { status: 'general', book: '卜筮正宗 / 增删卜易', chapter: '应期章', reason: '原文待录入' },
271
+ 'liuyao-liushen': { status: 'general', book: '卜筮正宗', chapter: '六神章', reason: '原文待录入' },
272
+ 'liuyao-liuchong': { status: 'general', book: '卜筮正宗 / 增删卜易', chapter: '六冲章', reason: '原文待录入' },
273
+ 'liuyao-liuhe': { status: 'general', book: '卜筮正宗', chapter: '六合章', reason: '原文待录入' },
274
+ 'liuyao-fanyin': { status: 'general', book: '增删卜易 / 卜筮正宗', chapter: '反吟伏吟篇', reason: '原文待录入' },
275
+ 'liuyao-fuyin': { status: 'general', book: '增删卜易 / 卜筮正宗', chapter: '伏吟篇', reason: '原文待录入' },
276
+ 'liuyao-jintui': { status: 'general', book: '增删卜易', chapter: '进神退神章', reason: '原文待录入' },
277
+ 'liuyao-jintui-yong': { status: 'general', book: '增删卜易', chapter: '进神退神章、用神章', reason: '原文待录入' },
278
+ 'liuyao-yingqi-exact': { status: 'todo', book: '卜筮正宗', chapter: '应期章', reason: '逐条应期尚未实现,等 20+ 条有应验日期的卦例' },
279
+ // ── 其他体系:原文待录入
280
+ 'meihua-tiyong': { status: 'general', book: '梅花易数', chapter: '体用篇', reason: '原文待录入' },
281
+ 'daliuren-sike': { status: 'general', book: '大六壬大全', chapter: '九宗门取传法', reason: '原文待录入' },
282
+ 'qimen-yinyang': { status: 'general', book: '烟波钓叟歌 / 奇门遁甲统宗', chapter: '阴阳遁与拆补', reason: '原文待录入' },
283
+ 'qimen-jixing': { status: 'general', book: '烟波钓叟歌 / 奇门遁甲统宗', chapter: '刑格注', reason: '原文待录入' },
284
+ 'qimen-rumu': { status: 'general', book: '奇门遁甲统宗 / 五行大义', chapter: '三奇入墓条', reason: '原文待录入' },
285
+ 'qimen-wangshuai': { status: 'general', book: '奇门遁甲统宗 / 五行大义', chapter: '门星旺衰条', reason: '原文待录入' },
286
+ 'qimen-wangshuai-yong': { status: 'general', book: '奇门遁甲统宗 / 烟波钓叟歌', chapter: '门宫生克注', reason: '原文待录入' },
287
+ 'qimen-gan-shengke': { status: 'general', book: '奇门遁甲统宗 / 烟波钓叟歌', chapter: '干宫生克条', reason: '原文待录入' },
288
+ 'qimen-ganying': { status: 'general', book: '奇门十干应克 / 奇门遁甲元灵经', chapter: '通行 100 组表 / 卷二·天盘加地盘吉凶', reason: '100 组为通行表汇编,元灵经只存甲、乙、丙三组,非单条原文' },
289
+ 'tarot-orientation': { status: 'general', book: '韦特塔罗', chapter: '逆位读法', reason: '韦特体系无中文古籍原文,逆位读法属近代流派' },
290
+ };
291
+
292
+ export function allCitations() {
293
+ return [...CLASSICS.map((c) => citationOf(c.id)), ...CITATIONS.map((c) => citationOf(c.id))];
294
+ }
295
+
296
+ /** 把知识卡的 source 补成「原 source + 可核验引文索引」;general/todo 不伪造原文 */
297
+ export function citationSourceOf(cardId, fallback = '') {
298
+ const entry = CARD_CITATIONS[cardId];
299
+ if (!entry) {
300
+ return { source: fallback, citations: [], status: 'general', reason: '未建立引文索引' };
301
+ }
302
+ if (Array.isArray(entry.refs) && entry.refs.length) {
303
+ const citations = entry.refs.map(citationOf).filter(Boolean);
304
+ const index = citations.map((c) => `《${c.bookName}·${c.chapter}》${c.url}`).join(';');
305
+ return { source: `${fallback}(原文索引:${index})`, citations, status: 'verified' };
306
+ }
307
+ return {
308
+ source: `${fallback}(${entry.status === 'todo' ? '待补原文' : '通行说,原文待补'}:${entry.book || ''}${entry.chapter ? `·${entry.chapter}` : ''})`,
309
+ citations: [],
310
+ status: entry.status || 'general',
311
+ reason: entry.reason || '',
312
+ };
313
+ }
314
+
315
+ /** 破格规则的引文:给测试与报告页共用 */
316
+ export function patternCitations() {
317
+ return Object.entries(PATTERN_BREAK_RULES)
318
+ .filter(([, rule]) => Array.isArray(rule.citationIds) && rule.citationIds.length)
319
+ .map(([name, rule]) => ({ name, citationIds: rule.citationIds, citations: rule.citationIds.map(citationOf).filter(Boolean) }));
320
+ }