kaabalah 5.6.0 → 6.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.
@@ -1055,7 +1055,1082 @@ function getTarotRepresentation(lookup, deckId) {
1055
1055
  function resolveTarotImageUrl(lookup, deckId) {
1056
1056
  return getTarotRepresentation(lookup, deckId)?.imageUrl;
1057
1057
  }
1058
+ var TAROT_SPREAD_MINOR_RANKS = [
1059
+ "ace",
1060
+ "2",
1061
+ "3",
1062
+ "4",
1063
+ "5",
1064
+ "6",
1065
+ "7",
1066
+ "8",
1067
+ "9",
1068
+ "10"
1069
+ ];
1070
+ var EVENT_INNER_SLOT_KEYS = [
1071
+ "inner-1",
1072
+ "inner-2",
1073
+ "inner-3",
1074
+ "inner-4",
1075
+ "inner-5",
1076
+ "inner-6",
1077
+ "inner-7"
1078
+ ];
1079
+ var TAROT_CARD_BY_NUMBER = new Map(
1080
+ ARKANNUS.map((card) => [card.number, card])
1081
+ );
1082
+ function createEventOuterSlot(index, temporalPhase) {
1083
+ return {
1084
+ slotKey: `outer-${index}`,
1085
+ label: String(index),
1086
+ order: index,
1087
+ minCards: 1,
1088
+ maxCards: 1,
1089
+ validationRules: {
1090
+ allowedTypes: ["minor", "daat+royalship"]
1091
+ },
1092
+ manualSelectionRules: {
1093
+ allowedTypes: ["minor", "daat+royalship"]
1094
+ },
1095
+ drawRules: {
1096
+ allowedTypes: ["minor", "daat+royalship"]
1097
+ },
1098
+ metadata: {
1099
+ displayLabel: String(index),
1100
+ groupKey: "outer",
1101
+ temporalPhase
1102
+ }
1103
+ };
1104
+ }
1105
+ function createEventInnerSlot(index, label, note) {
1106
+ return {
1107
+ slotKey: `inner-${index}`,
1108
+ label,
1109
+ order: 100 + index,
1110
+ minCards: 1,
1111
+ maxCards: 1,
1112
+ validationRules: {
1113
+ allowedTypes: ["major"]
1114
+ },
1115
+ manualSelectionRules: {
1116
+ allowedTypes: ["major"],
1117
+ excludedCardFilenames: [
1118
+ "01_the_magician",
1119
+ "02_the_high_priestess"
1120
+ ]
1121
+ },
1122
+ drawRules: {
1123
+ allowedTypes: ["major"]
1124
+ },
1125
+ metadata: {
1126
+ displayLabel: `${index}.`,
1127
+ groupKey: "inner",
1128
+ note
1129
+ }
1130
+ };
1131
+ }
1132
+ var TAROT_SPREADS = [
1133
+ {
1134
+ spreadId: "quick-insight",
1135
+ label: "Quick Insight",
1136
+ description: "A single-card reading for immediate insight.",
1137
+ slots: [
1138
+ {
1139
+ slotKey: "quick-insight",
1140
+ label: "Quick Insight",
1141
+ order: 1,
1142
+ minCards: 1,
1143
+ maxCards: 1
1144
+ }
1145
+ ]
1146
+ },
1147
+ {
1148
+ spreadId: "conscious-reading",
1149
+ label: "Conscious Reading",
1150
+ description: "Three-card spread for conscious, unconscious, and subconscious layers.",
1151
+ slots: [
1152
+ {
1153
+ slotKey: "conscious",
1154
+ label: "Conscious",
1155
+ order: 1,
1156
+ minCards: 1,
1157
+ maxCards: 1,
1158
+ validationRules: {
1159
+ allowedTypes: ["major"]
1160
+ },
1161
+ manualSelectionRules: {
1162
+ allowedTypes: ["major"]
1163
+ },
1164
+ drawRules: {
1165
+ allowedTypes: ["major"]
1166
+ }
1167
+ },
1168
+ {
1169
+ slotKey: "unconscious",
1170
+ label: "Unconscious",
1171
+ order: 2,
1172
+ minCards: 1,
1173
+ maxCards: 1,
1174
+ validationRules: {
1175
+ allowedTypes: ["daat+royalship"]
1176
+ },
1177
+ manualSelectionRules: {
1178
+ allowedTypes: ["daat+royalship"]
1179
+ },
1180
+ drawRules: {
1181
+ allowedTypes: ["daat+royalship"]
1182
+ }
1183
+ },
1184
+ {
1185
+ slotKey: "subconscious",
1186
+ label: "Subconscious",
1187
+ order: 3,
1188
+ minCards: 1,
1189
+ maxCards: 1,
1190
+ validationRules: {
1191
+ allowedTypes: ["minor"]
1192
+ },
1193
+ manualSelectionRules: {
1194
+ allowedTypes: ["minor"]
1195
+ },
1196
+ drawRules: {
1197
+ allowedTypes: ["minor"]
1198
+ }
1199
+ }
1200
+ ]
1201
+ },
1202
+ {
1203
+ spreadId: "time-reading",
1204
+ label: "Time Reading",
1205
+ description: "Three major arcana cards for past, present, and future.",
1206
+ slots: [
1207
+ {
1208
+ slotKey: "past",
1209
+ label: "Past",
1210
+ order: 1,
1211
+ minCards: 1,
1212
+ maxCards: 1,
1213
+ validationRules: {
1214
+ allowedTypes: ["major"]
1215
+ },
1216
+ manualSelectionRules: {
1217
+ allowedTypes: ["major"]
1218
+ },
1219
+ drawRules: {
1220
+ allowedTypes: ["major"]
1221
+ }
1222
+ },
1223
+ {
1224
+ slotKey: "present",
1225
+ label: "Present",
1226
+ order: 2,
1227
+ minCards: 1,
1228
+ maxCards: 1,
1229
+ validationRules: {
1230
+ allowedTypes: ["major"]
1231
+ },
1232
+ manualSelectionRules: {
1233
+ allowedTypes: ["major"]
1234
+ },
1235
+ drawRules: {
1236
+ allowedTypes: ["major"]
1237
+ }
1238
+ },
1239
+ {
1240
+ slotKey: "future",
1241
+ label: "Future",
1242
+ order: 3,
1243
+ minCards: 1,
1244
+ maxCards: 1,
1245
+ validationRules: {
1246
+ allowedTypes: ["major"]
1247
+ },
1248
+ manualSelectionRules: {
1249
+ allowedTypes: ["major"]
1250
+ },
1251
+ drawRules: {
1252
+ allowedTypes: ["major"]
1253
+ }
1254
+ }
1255
+ ]
1256
+ },
1257
+ {
1258
+ spreadId: "dialectic-reading",
1259
+ label: "Dialectic Reading",
1260
+ description: "Three major arcana cards for thesis, antithesis, and synthesis.",
1261
+ slots: [
1262
+ {
1263
+ slotKey: "thesis",
1264
+ label: "Thesis",
1265
+ order: 1,
1266
+ minCards: 1,
1267
+ maxCards: 1,
1268
+ validationRules: {
1269
+ allowedTypes: ["major"]
1270
+ },
1271
+ manualSelectionRules: {
1272
+ allowedTypes: ["major"]
1273
+ },
1274
+ drawRules: {
1275
+ allowedTypes: ["major"]
1276
+ }
1277
+ },
1278
+ {
1279
+ slotKey: "antithesis",
1280
+ label: "Antithesis",
1281
+ order: 2,
1282
+ minCards: 1,
1283
+ maxCards: 1,
1284
+ validationRules: {
1285
+ allowedTypes: ["major"]
1286
+ },
1287
+ manualSelectionRules: {
1288
+ allowedTypes: ["major"]
1289
+ },
1290
+ drawRules: {
1291
+ allowedTypes: ["major"]
1292
+ }
1293
+ },
1294
+ {
1295
+ slotKey: "synthesis",
1296
+ label: "Synthesis",
1297
+ order: 3,
1298
+ minCards: 1,
1299
+ maxCards: 1,
1300
+ validationRules: {
1301
+ allowedTypes: ["major"]
1302
+ },
1303
+ manualSelectionRules: {
1304
+ allowedTypes: ["major"]
1305
+ },
1306
+ drawRules: {
1307
+ allowedTypes: ["major"]
1308
+ }
1309
+ }
1310
+ ]
1311
+ },
1312
+ {
1313
+ spreadId: "tree-of-life-reading",
1314
+ label: "Tree of Life Reading",
1315
+ description: "Ten numbered minor arcana slots mapped to the spheres plus four Daath court cards.",
1316
+ slots: [
1317
+ {
1318
+ slotKey: "kether",
1319
+ label: "Kether",
1320
+ order: 1,
1321
+ minCards: 1,
1322
+ maxCards: 1,
1323
+ validationRules: {
1324
+ allowedTypes: ["minor"],
1325
+ requiredRank: "ace"
1326
+ },
1327
+ manualSelectionRules: {
1328
+ allowedTypes: ["minor"],
1329
+ requiredRank: "ace"
1330
+ },
1331
+ drawRules: {
1332
+ allowedTypes: ["minor"],
1333
+ requiredRank: "ace"
1334
+ }
1335
+ },
1336
+ {
1337
+ slotKey: "chokhmah",
1338
+ label: "Chokhmah",
1339
+ order: 2,
1340
+ minCards: 1,
1341
+ maxCards: 1,
1342
+ validationRules: {
1343
+ allowedTypes: ["minor"],
1344
+ requiredRank: "2"
1345
+ },
1346
+ manualSelectionRules: {
1347
+ allowedTypes: ["minor"],
1348
+ requiredRank: "2"
1349
+ },
1350
+ drawRules: {
1351
+ allowedTypes: ["minor"],
1352
+ requiredRank: "2"
1353
+ }
1354
+ },
1355
+ {
1356
+ slotKey: "binah",
1357
+ label: "Binah",
1358
+ order: 3,
1359
+ minCards: 1,
1360
+ maxCards: 1,
1361
+ validationRules: {
1362
+ allowedTypes: ["minor"],
1363
+ requiredRank: "3"
1364
+ },
1365
+ manualSelectionRules: {
1366
+ allowedTypes: ["minor"],
1367
+ requiredRank: "3"
1368
+ },
1369
+ drawRules: {
1370
+ allowedTypes: ["minor"],
1371
+ requiredRank: "3"
1372
+ }
1373
+ },
1374
+ {
1375
+ slotKey: "chesed",
1376
+ label: "Chesed",
1377
+ order: 4,
1378
+ minCards: 1,
1379
+ maxCards: 1,
1380
+ validationRules: {
1381
+ allowedTypes: ["minor"],
1382
+ requiredRank: "4"
1383
+ },
1384
+ manualSelectionRules: {
1385
+ allowedTypes: ["minor"],
1386
+ requiredRank: "4"
1387
+ },
1388
+ drawRules: {
1389
+ allowedTypes: ["minor"],
1390
+ requiredRank: "4"
1391
+ }
1392
+ },
1393
+ {
1394
+ slotKey: "geburah",
1395
+ label: "Geburah",
1396
+ order: 5,
1397
+ minCards: 1,
1398
+ maxCards: 1,
1399
+ validationRules: {
1400
+ allowedTypes: ["minor"],
1401
+ requiredRank: "5"
1402
+ },
1403
+ manualSelectionRules: {
1404
+ allowedTypes: ["minor"],
1405
+ requiredRank: "5"
1406
+ },
1407
+ drawRules: {
1408
+ allowedTypes: ["minor"],
1409
+ requiredRank: "5"
1410
+ }
1411
+ },
1412
+ {
1413
+ slotKey: "tiphareth",
1414
+ label: "Tiphareth",
1415
+ order: 6,
1416
+ minCards: 1,
1417
+ maxCards: 1,
1418
+ validationRules: {
1419
+ allowedTypes: ["minor"],
1420
+ requiredRank: "6"
1421
+ },
1422
+ manualSelectionRules: {
1423
+ allowedTypes: ["minor"],
1424
+ requiredRank: "6"
1425
+ },
1426
+ drawRules: {
1427
+ allowedTypes: ["minor"],
1428
+ requiredRank: "6"
1429
+ }
1430
+ },
1431
+ {
1432
+ slotKey: "netzach",
1433
+ label: "Netzach",
1434
+ order: 7,
1435
+ minCards: 1,
1436
+ maxCards: 1,
1437
+ validationRules: {
1438
+ allowedTypes: ["minor"],
1439
+ requiredRank: "7"
1440
+ },
1441
+ manualSelectionRules: {
1442
+ allowedTypes: ["minor"],
1443
+ requiredRank: "7"
1444
+ },
1445
+ drawRules: {
1446
+ allowedTypes: ["minor"],
1447
+ requiredRank: "7"
1448
+ }
1449
+ },
1450
+ {
1451
+ slotKey: "hod",
1452
+ label: "Hod",
1453
+ order: 8,
1454
+ minCards: 1,
1455
+ maxCards: 1,
1456
+ validationRules: {
1457
+ allowedTypes: ["minor"],
1458
+ requiredRank: "8"
1459
+ },
1460
+ manualSelectionRules: {
1461
+ allowedTypes: ["minor"],
1462
+ requiredRank: "8"
1463
+ },
1464
+ drawRules: {
1465
+ allowedTypes: ["minor"],
1466
+ requiredRank: "8"
1467
+ }
1468
+ },
1469
+ {
1470
+ slotKey: "yesod",
1471
+ label: "Yesod",
1472
+ order: 9,
1473
+ minCards: 1,
1474
+ maxCards: 1,
1475
+ validationRules: {
1476
+ allowedTypes: ["minor"],
1477
+ requiredRank: "9"
1478
+ },
1479
+ manualSelectionRules: {
1480
+ allowedTypes: ["minor"],
1481
+ requiredRank: "9"
1482
+ },
1483
+ drawRules: {
1484
+ allowedTypes: ["minor"],
1485
+ requiredRank: "9"
1486
+ }
1487
+ },
1488
+ {
1489
+ slotKey: "malkuth",
1490
+ label: "Malkuth",
1491
+ order: 10,
1492
+ minCards: 1,
1493
+ maxCards: 1,
1494
+ validationRules: {
1495
+ allowedTypes: ["minor"],
1496
+ requiredRank: "10"
1497
+ },
1498
+ manualSelectionRules: {
1499
+ allowedTypes: ["minor"],
1500
+ requiredRank: "10"
1501
+ },
1502
+ drawRules: {
1503
+ allowedTypes: ["minor"],
1504
+ requiredRank: "10"
1505
+ }
1506
+ },
1507
+ {
1508
+ slotKey: "daath",
1509
+ label: "Daath",
1510
+ order: 11,
1511
+ minCards: 4,
1512
+ maxCards: 4,
1513
+ validationRules: {
1514
+ allowedTypes: ["daat+royalship"]
1515
+ },
1516
+ manualSelectionRules: {
1517
+ allowedTypes: ["daat+royalship"]
1518
+ },
1519
+ drawRules: {
1520
+ allowedTypes: ["daat+royalship"]
1521
+ }
1522
+ }
1523
+ ]
1524
+ },
1525
+ {
1526
+ spreadId: "celtic-cross",
1527
+ label: "Celtic Cross",
1528
+ description: "Classic ten-card Celtic Cross spread.",
1529
+ slots: [
1530
+ {
1531
+ slotKey: "present",
1532
+ label: "The Present",
1533
+ order: 1,
1534
+ minCards: 1,
1535
+ maxCards: 1,
1536
+ metadata: {
1537
+ displayLabel: "1."
1538
+ }
1539
+ },
1540
+ {
1541
+ slotKey: "challenge",
1542
+ label: "The Challenge",
1543
+ order: 2,
1544
+ minCards: 1,
1545
+ maxCards: 1,
1546
+ metadata: {
1547
+ displayLabel: "2.",
1548
+ orientation: "sideways"
1549
+ }
1550
+ },
1551
+ {
1552
+ slotKey: "above",
1553
+ label: "Above",
1554
+ order: 3,
1555
+ minCards: 1,
1556
+ maxCards: 1,
1557
+ metadata: {
1558
+ displayLabel: "3."
1559
+ }
1560
+ },
1561
+ {
1562
+ slotKey: "below",
1563
+ label: "Below",
1564
+ order: 4,
1565
+ minCards: 1,
1566
+ maxCards: 1,
1567
+ metadata: {
1568
+ displayLabel: "4."
1569
+ }
1570
+ },
1571
+ {
1572
+ slotKey: "behind",
1573
+ label: "Behind",
1574
+ order: 5,
1575
+ minCards: 1,
1576
+ maxCards: 1,
1577
+ metadata: {
1578
+ displayLabel: "5."
1579
+ }
1580
+ },
1581
+ {
1582
+ slotKey: "before",
1583
+ label: "Before",
1584
+ order: 6,
1585
+ minCards: 1,
1586
+ maxCards: 1,
1587
+ metadata: {
1588
+ displayLabel: "6."
1589
+ }
1590
+ },
1591
+ {
1592
+ slotKey: "self",
1593
+ label: "Self",
1594
+ order: 7,
1595
+ minCards: 1,
1596
+ maxCards: 1,
1597
+ metadata: {
1598
+ displayLabel: "7."
1599
+ }
1600
+ },
1601
+ {
1602
+ slotKey: "environment",
1603
+ label: "Environment",
1604
+ order: 8,
1605
+ minCards: 1,
1606
+ maxCards: 1,
1607
+ metadata: {
1608
+ displayLabel: "8."
1609
+ }
1610
+ },
1611
+ {
1612
+ slotKey: "hopes-fears",
1613
+ label: "Hopes/Fears",
1614
+ order: 9,
1615
+ minCards: 1,
1616
+ maxCards: 1,
1617
+ metadata: {
1618
+ displayLabel: "9."
1619
+ }
1620
+ },
1621
+ {
1622
+ slotKey: "outcome",
1623
+ label: "Outcome",
1624
+ order: 10,
1625
+ minCards: 1,
1626
+ maxCards: 1,
1627
+ metadata: {
1628
+ displayLabel: "10."
1629
+ }
1630
+ }
1631
+ ]
1632
+ },
1633
+ {
1634
+ spreadId: "event-reading",
1635
+ label: "Event Reading",
1636
+ description: "Papus-style event spread with outer minor/court cards, seven major cards, and an inquirer card.",
1637
+ contextRequirements: ["inquirerGender"],
1638
+ slots: [
1639
+ createEventOuterSlot(1, "past"),
1640
+ createEventOuterSlot(2, "past"),
1641
+ createEventOuterSlot(3, "past"),
1642
+ createEventOuterSlot(4, "past"),
1643
+ createEventOuterSlot(5, "present"),
1644
+ createEventOuterSlot(6, "present"),
1645
+ createEventOuterSlot(7, "present"),
1646
+ createEventOuterSlot(8, "present"),
1647
+ createEventOuterSlot(9, "future"),
1648
+ createEventOuterSlot(10, "future"),
1649
+ createEventOuterSlot(11, "future"),
1650
+ createEventOuterSlot(12, "future"),
1651
+ createEventInnerSlot(
1652
+ 1,
1653
+ "Commencement",
1654
+ "Character of the beginning phase."
1655
+ ),
1656
+ createEventInnerSlot(2, "Apogee", "Peak or zenith of the event."),
1657
+ createEventInnerSlot(
1658
+ 3,
1659
+ "Decline/Obstacle",
1660
+ "Challenges, obstacles, or decline."
1661
+ ),
1662
+ createEventInnerSlot(4, "Fall", "Conclusion or end phase."),
1663
+ createEventInnerSlot(
1664
+ 5,
1665
+ "The Past",
1666
+ "Special character or influence in the past."
1667
+ ),
1668
+ createEventInnerSlot(
1669
+ 6,
1670
+ "The Present",
1671
+ "Special character or influence in the present."
1672
+ ),
1673
+ createEventInnerSlot(
1674
+ 7,
1675
+ "The Future",
1676
+ "Special character or influence to come."
1677
+ ),
1678
+ {
1679
+ slotKey: "inquirer",
1680
+ label: "Inquirer",
1681
+ order: 200,
1682
+ minCards: 1,
1683
+ maxCards: 1,
1684
+ validationRules: {
1685
+ allowedTypes: ["major"]
1686
+ },
1687
+ manualSelectionRules: {
1688
+ allowedTypes: ["major"],
1689
+ allowedCardFilenames: [
1690
+ "01_the_magician",
1691
+ "02_the_high_priestess"
1692
+ ]
1693
+ },
1694
+ drawRules: {
1695
+ allowedTypes: ["major"]
1696
+ },
1697
+ metadata: {
1698
+ displayLabel: "Inquirer",
1699
+ groupKey: "center",
1700
+ note: "The querent's energy in this reading."
1701
+ }
1702
+ }
1703
+ ],
1704
+ specialRules: {
1705
+ inquirerCard: {
1706
+ slotKey: "inquirer",
1707
+ sourceSlotKeys: [...EVENT_INNER_SLOT_KEYS],
1708
+ cardNumbersByGender: {
1709
+ man: 1,
1710
+ woman: 2
1711
+ }
1712
+ }
1713
+ }
1714
+ }
1715
+ ];
1716
+ var TAROT_SPREAD_BY_ID = new Map(
1717
+ TAROT_SPREADS.map((spread) => [spread.spreadId, spread])
1718
+ );
1719
+ function cloneCardConstraint(constraint) {
1720
+ if (!constraint) {
1721
+ return void 0;
1722
+ }
1723
+ return {
1724
+ allowedTypes: constraint.allowedTypes ? [...constraint.allowedTypes] : void 0,
1725
+ requiredRank: constraint.requiredRank,
1726
+ allowedCardFilenames: constraint.allowedCardFilenames ? [...constraint.allowedCardFilenames] : void 0,
1727
+ excludedCardFilenames: constraint.excludedCardFilenames ? [...constraint.excludedCardFilenames] : void 0
1728
+ };
1729
+ }
1730
+ function cloneSlotDefinition(slot) {
1731
+ return {
1732
+ ...slot,
1733
+ validationRules: cloneCardConstraint(slot.validationRules),
1734
+ manualSelectionRules: cloneCardConstraint(slot.manualSelectionRules),
1735
+ drawRules: cloneCardConstraint(slot.drawRules),
1736
+ metadata: slot.metadata ? { ...slot.metadata } : void 0
1737
+ };
1738
+ }
1739
+ function cloneSpreadDefinition(spread) {
1740
+ return {
1741
+ ...spread,
1742
+ contextRequirements: spread.contextRequirements ? [...spread.contextRequirements] : void 0,
1743
+ slots: spread.slots.map(cloneSlotDefinition),
1744
+ specialRules: spread.specialRules?.inquirerCard ? {
1745
+ inquirerCard: {
1746
+ slotKey: spread.specialRules.inquirerCard.slotKey,
1747
+ sourceSlotKeys: [...spread.specialRules.inquirerCard.sourceSlotKeys],
1748
+ cardNumbersByGender: {
1749
+ ...spread.specialRules.inquirerCard.cardNumbersByGender
1750
+ }
1751
+ }
1752
+ } : void 0
1753
+ };
1754
+ }
1755
+ function getTarotCardByNumber(cardNumber) {
1756
+ return TAROT_CARD_BY_NUMBER.get(cardNumber);
1757
+ }
1758
+ function getTarotSpreadRuleForValidation(slot) {
1759
+ return slot.validationRules ?? slot.drawRules ?? slot.manualSelectionRules;
1760
+ }
1761
+ function getTarotSpreadRuleForDraw(slot) {
1762
+ return slot.drawRules ?? slot.validationRules ?? slot.manualSelectionRules;
1763
+ }
1764
+ function getTarotMinorRank(card) {
1765
+ if (card.type !== "minor") {
1766
+ return void 0;
1767
+ }
1768
+ const rank = card.tarotCardFilename.split("_")[0];
1769
+ return TAROT_SPREAD_MINOR_RANKS.includes(rank) ? rank : void 0;
1770
+ }
1771
+ function matchesTarotSpreadConstraint(card, constraint) {
1772
+ if (!constraint) {
1773
+ return true;
1774
+ }
1775
+ if (constraint.allowedTypes && !constraint.allowedTypes.includes(card.type)) {
1776
+ return false;
1777
+ }
1778
+ if (constraint.allowedCardFilenames && !constraint.allowedCardFilenames.includes(card.tarotCardFilename)) {
1779
+ return false;
1780
+ }
1781
+ if (constraint.excludedCardFilenames && constraint.excludedCardFilenames.includes(card.tarotCardFilename)) {
1782
+ return false;
1783
+ }
1784
+ if (constraint.requiredRank) {
1785
+ return getTarotMinorRank(card) === constraint.requiredRank;
1786
+ }
1787
+ return true;
1788
+ }
1789
+ function randomIndex(length, rng) {
1790
+ if (length <= 0) {
1791
+ throw new Error("Cannot draw from an empty pool.");
1792
+ }
1793
+ const raw = rng();
1794
+ if (!Number.isFinite(raw)) {
1795
+ throw new Error("Tarot spread RNG must return a finite number.");
1796
+ }
1797
+ const normalized = Math.min(Math.max(raw, 0), 1 - Number.EPSILON);
1798
+ return Math.floor(normalized * length);
1799
+ }
1800
+ function withSpreadCardOrientation(card, includeInverted, rng) {
1801
+ return {
1802
+ ...card,
1803
+ isInverted: includeInverted ? rng() < 0.5 : false
1804
+ };
1805
+ }
1806
+ function resolveTarotSpreadSelectionCard(card, slot, tarotCard) {
1807
+ return {
1808
+ ...card,
1809
+ slot,
1810
+ card: {
1811
+ ...tarotCard,
1812
+ isInverted: card.isInverted ?? false
1813
+ }
1814
+ };
1815
+ }
1816
+ function sortResolvedTarotSpreadCards(resolvedCards) {
1817
+ return [...resolvedCards].sort((left, right) => {
1818
+ if (left.slot.order !== right.slot.order) {
1819
+ return left.slot.order - right.slot.order;
1820
+ }
1821
+ return left.card.number - right.card.number;
1822
+ });
1823
+ }
1824
+ function validateEventInquirerCard(spread, resolvedCards, context, errors) {
1825
+ const inquirerRule = spread.specialRules?.inquirerCard;
1826
+ if (!inquirerRule) {
1827
+ return;
1828
+ }
1829
+ if (!context?.inquirerGender) {
1830
+ return;
1831
+ }
1832
+ const inquirerCardNumber = inquirerRule.cardNumbersByGender[context.inquirerGender];
1833
+ const sourceCards = resolvedCards.filter(
1834
+ (card) => inquirerRule.sourceSlotKeys.includes(card.slotKey)
1835
+ );
1836
+ const inquirerCards = resolvedCards.filter(
1837
+ (card) => card.slotKey === inquirerRule.slotKey
1838
+ );
1839
+ if (inquirerCards.length !== 1) {
1840
+ return;
1841
+ }
1842
+ const sourceContainsGenderCard = sourceCards.some(
1843
+ (card) => card.card.number === inquirerCardNumber
1844
+ );
1845
+ const totalGenderCardCount = [...sourceCards, ...inquirerCards].filter(
1846
+ (card) => card.card.number === inquirerCardNumber
1847
+ ).length;
1848
+ if (totalGenderCardCount !== 1) {
1849
+ errors.push({
1850
+ code: "INVALID_INQUIRER_CARD",
1851
+ slotKey: inquirerRule.slotKey,
1852
+ cardNumber: inquirerCardNumber,
1853
+ message: "Event Reading must contain the gendered inquirer card exactly once across the major arcana band and inquirer slot."
1854
+ });
1855
+ return;
1856
+ }
1857
+ if (!sourceContainsGenderCard && inquirerCards[0].card.number !== inquirerCardNumber) {
1858
+ errors.push({
1859
+ code: "INVALID_INQUIRER_CARD",
1860
+ slotKey: inquirerRule.slotKey,
1861
+ cardNumber: inquirerCards[0].card.number,
1862
+ message: "When the inquirer card was not drawn in the seven major slots, it must occupy the Inquirer slot."
1863
+ });
1864
+ }
1865
+ }
1866
+ function pickTarotCardFromPool(pool, constraint, rng) {
1867
+ const candidateIndexes = pool.reduce((indexes, card, index) => {
1868
+ if (matchesTarotSpreadConstraint(card, constraint)) {
1869
+ indexes.push(index);
1870
+ }
1871
+ return indexes;
1872
+ }, []);
1873
+ if (candidateIndexes.length === 0) {
1874
+ throw new Error("Unable to draw a tarot card that satisfies the spread rule.");
1875
+ }
1876
+ const pickedIndex = candidateIndexes[randomIndex(candidateIndexes.length, rng)];
1877
+ const [pickedCard] = pool.splice(pickedIndex, 1);
1878
+ return pickedCard;
1879
+ }
1880
+ function buildResolvedDrawnCard(slot, card, includeInverted, rng) {
1881
+ const drawnCard = withSpreadCardOrientation(card, includeInverted, rng);
1882
+ return {
1883
+ slotKey: slot.slotKey,
1884
+ cardNumber: drawnCard.number,
1885
+ isInverted: drawnCard.isInverted ?? false,
1886
+ slot,
1887
+ card: drawnCard
1888
+ };
1889
+ }
1890
+ function drawDefaultTarotSpread(spread, includeInverted, rng) {
1891
+ const deckPool = [...ARKANNUS];
1892
+ const drawnCards = [];
1893
+ for (const slot of spread.slots.slice().sort((left, right) => left.order - right.order)) {
1894
+ const drawRule = getTarotSpreadRuleForDraw(slot);
1895
+ for (let index = 0; index < slot.maxCards; index += 1) {
1896
+ const card = pickTarotCardFromPool(deckPool, drawRule, rng);
1897
+ drawnCards.push(
1898
+ buildResolvedDrawnCard(slot, card, includeInverted, rng)
1899
+ );
1900
+ }
1901
+ }
1902
+ return drawnCards;
1903
+ }
1904
+ function drawEventReadingSpread(spread, includeInverted, rng, context) {
1905
+ const inquirerRule = spread.specialRules?.inquirerCard;
1906
+ if (!inquirerRule || !context?.inquirerGender) {
1907
+ throw new Error(
1908
+ "Event Reading draw requires `context.inquirerGender`."
1909
+ );
1910
+ }
1911
+ const slotsByKey = new Map(
1912
+ spread.slots.map((slot) => [slot.slotKey, slot])
1913
+ );
1914
+ const outerPool = ARKANNUS.filter(
1915
+ (card) => card.type === "minor" || card.type === "daat+royalship"
1916
+ );
1917
+ const majorPool = ARKANNUS.filter((card) => card.type === "major");
1918
+ const drawnCards = [];
1919
+ for (const slot of spread.slots.filter((candidate) => candidate.metadata?.groupKey === "outer").sort((left, right) => left.order - right.order)) {
1920
+ const card = pickTarotCardFromPool(outerPool, getTarotSpreadRuleForDraw(slot), rng);
1921
+ drawnCards.push(buildResolvedDrawnCard(slot, card, includeInverted, rng));
1922
+ }
1923
+ for (const slotKey of inquirerRule.sourceSlotKeys) {
1924
+ const slot = slotsByKey.get(slotKey);
1925
+ if (!slot) {
1926
+ throw new Error(`Missing Event Reading slot definition for ${slotKey}.`);
1927
+ }
1928
+ const card = pickTarotCardFromPool(majorPool, getTarotSpreadRuleForDraw(slot), rng);
1929
+ drawnCards.push(buildResolvedDrawnCard(slot, card, includeInverted, rng));
1930
+ }
1931
+ const genderedInquirerCardNumber = inquirerRule.cardNumbersByGender[context.inquirerGender];
1932
+ const sourceContainsGenderedCard = drawnCards.some(
1933
+ (card) => inquirerRule.sourceSlotKeys.includes(card.slotKey) && card.card.number === genderedInquirerCardNumber
1934
+ );
1935
+ const inquirerSlot = slotsByKey.get(inquirerRule.slotKey);
1936
+ if (!inquirerSlot) {
1937
+ throw new Error(
1938
+ `Missing Event Reading slot definition for ${inquirerRule.slotKey}.`
1939
+ );
1940
+ }
1941
+ if (!sourceContainsGenderedCard) {
1942
+ const genderedCardIndex = majorPool.findIndex(
1943
+ (card) => card.number === genderedInquirerCardNumber
1944
+ );
1945
+ if (genderedCardIndex < 0) {
1946
+ throw new Error(
1947
+ "Unable to assign the Event Reading inquirer card from the remaining major arcana."
1948
+ );
1949
+ }
1950
+ const [genderedCard] = majorPool.splice(genderedCardIndex, 1);
1951
+ drawnCards.push(
1952
+ buildResolvedDrawnCard(inquirerSlot, genderedCard, includeInverted, rng)
1953
+ );
1954
+ } else {
1955
+ const replacement = pickTarotCardFromPool(
1956
+ majorPool,
1957
+ getTarotSpreadRuleForDraw(inquirerSlot),
1958
+ rng
1959
+ );
1960
+ drawnCards.push(
1961
+ buildResolvedDrawnCard(inquirerSlot, replacement, includeInverted, rng)
1962
+ );
1963
+ }
1964
+ return drawnCards;
1965
+ }
1966
+ function listTarotSpreads() {
1967
+ return TAROT_SPREADS.map(cloneSpreadDefinition);
1968
+ }
1969
+ function getTarotSpread(spreadId) {
1970
+ const spread = TAROT_SPREAD_BY_ID.get(spreadId);
1971
+ return spread ? cloneSpreadDefinition(spread) : void 0;
1972
+ }
1973
+ function validateTarotSpreadSelection(input) {
1974
+ const spread = TAROT_SPREAD_BY_ID.get(input.spreadId);
1975
+ const errors = [];
1976
+ if (!spread) {
1977
+ return {
1978
+ ok: false,
1979
+ isComplete: false,
1980
+ errors: [
1981
+ {
1982
+ code: "UNKNOWN_SPREAD",
1983
+ message: `Unknown tarot spread: ${input.spreadId}.`
1984
+ }
1985
+ ],
1986
+ resolvedCards: []
1987
+ };
1988
+ }
1989
+ const slotsByKey = new Map(
1990
+ spread.slots.map((slot) => [slot.slotKey, slot])
1991
+ );
1992
+ const seenCardNumbers = /* @__PURE__ */ new Set();
1993
+ const resolvedCards = [];
1994
+ for (const selectedCard of input.cards) {
1995
+ const slot = slotsByKey.get(selectedCard.slotKey);
1996
+ if (!slot) {
1997
+ errors.push({
1998
+ code: "UNKNOWN_SLOT",
1999
+ slotKey: selectedCard.slotKey,
2000
+ message: `Unknown slot for ${spread.label}: ${selectedCard.slotKey}.`
2001
+ });
2002
+ continue;
2003
+ }
2004
+ const tarotCard = getTarotCardByNumber(selectedCard.cardNumber);
2005
+ if (!tarotCard) {
2006
+ errors.push({
2007
+ code: "CARD_NOT_FOUND",
2008
+ slotKey: selectedCard.slotKey,
2009
+ cardNumber: selectedCard.cardNumber,
2010
+ message: `Unknown tarot card number: ${selectedCard.cardNumber}.`
2011
+ });
2012
+ continue;
2013
+ }
2014
+ if (seenCardNumbers.has(tarotCard.number)) {
2015
+ errors.push({
2016
+ code: "DUPLICATE_CARD",
2017
+ slotKey: selectedCard.slotKey,
2018
+ cardNumber: tarotCard.number,
2019
+ message: `Tarot card ${tarotCard.number} is duplicated across the spread.`
2020
+ });
2021
+ continue;
2022
+ }
2023
+ seenCardNumbers.add(tarotCard.number);
2024
+ resolvedCards.push(
2025
+ resolveTarotSpreadSelectionCard(selectedCard, slot, tarotCard)
2026
+ );
2027
+ }
2028
+ let isComplete = true;
2029
+ for (const slot of spread.slots) {
2030
+ const slotCards = resolvedCards.filter(
2031
+ (selectedCard) => selectedCard.slotKey === slot.slotKey
2032
+ );
2033
+ if (slotCards.length < slot.minCards) {
2034
+ isComplete = false;
2035
+ if (!input.allowPartial) {
2036
+ errors.push({
2037
+ code: "MISSING_REQUIRED_CARDS",
2038
+ slotKey: slot.slotKey,
2039
+ message: `${spread.label} requires ${slot.minCards} card(s) for ${slot.label}.`
2040
+ });
2041
+ }
2042
+ }
2043
+ if (slotCards.length > slot.maxCards) {
2044
+ isComplete = false;
2045
+ errors.push({
2046
+ code: "TOO_MANY_CARDS",
2047
+ slotKey: slot.slotKey,
2048
+ message: `${spread.label} allows at most ${slot.maxCards} card(s) for ${slot.label}.`
2049
+ });
2050
+ }
2051
+ const validationRule = getTarotSpreadRuleForValidation(slot);
2052
+ for (const slotCard of slotCards) {
2053
+ if (validationRule?.allowedTypes && !validationRule.allowedTypes.includes(slotCard.card.type)) {
2054
+ errors.push({
2055
+ code: "INVALID_CARD_TYPE",
2056
+ slotKey: slot.slotKey,
2057
+ cardNumber: slotCard.card.number,
2058
+ message: `${slot.label} does not accept ${slotCard.card.type} cards.`
2059
+ });
2060
+ }
2061
+ if (validationRule?.requiredRank && getTarotMinorRank(slotCard.card) !== validationRule.requiredRank) {
2062
+ errors.push({
2063
+ code: "INVALID_CARD_RANK",
2064
+ slotKey: slot.slotKey,
2065
+ cardNumber: slotCard.card.number,
2066
+ message: `${slot.label} requires a ${validationRule.requiredRank} minor arcana card.`
2067
+ });
2068
+ }
2069
+ if (validationRule?.allowedCardFilenames && !validationRule.allowedCardFilenames.includes(slotCard.card.tarotCardFilename)) {
2070
+ errors.push({
2071
+ code: "DISALLOWED_CARD",
2072
+ slotKey: slot.slotKey,
2073
+ cardNumber: slotCard.card.number,
2074
+ message: `${slotCard.card.tarotCard} is not allowed in ${slot.label}.`
2075
+ });
2076
+ }
2077
+ if (validationRule?.excludedCardFilenames && validationRule.excludedCardFilenames.includes(slotCard.card.tarotCardFilename)) {
2078
+ errors.push({
2079
+ code: "DISALLOWED_CARD",
2080
+ slotKey: slot.slotKey,
2081
+ cardNumber: slotCard.card.number,
2082
+ message: `${slotCard.card.tarotCard} is excluded from ${slot.label}.`
2083
+ });
2084
+ }
2085
+ }
2086
+ }
2087
+ if (spread.contextRequirements?.includes("inquirerGender") && !input.context?.inquirerGender) {
2088
+ isComplete = false;
2089
+ errors.push({
2090
+ code: "MISSING_CONTEXT",
2091
+ message: `${spread.label} requires \`context.inquirerGender\`.`
2092
+ });
2093
+ }
2094
+ validateEventInquirerCard(spread, resolvedCards, input.context, errors);
2095
+ const sortedResolvedCards = sortResolvedTarotSpreadCards(resolvedCards);
2096
+ return {
2097
+ ok: errors.length === 0,
2098
+ isComplete,
2099
+ spread: cloneSpreadDefinition(spread),
2100
+ resolvedCards: sortedResolvedCards,
2101
+ errors
2102
+ };
2103
+ }
2104
+ function drawTarotSpread(options) {
2105
+ const spread = TAROT_SPREAD_BY_ID.get(options.spreadId);
2106
+ if (!spread) {
2107
+ throw new Error(`Unknown tarot spread: ${options.spreadId}.`);
2108
+ }
2109
+ const rng = options.rng ?? Math.random;
2110
+ const includeInverted = options.includeInverted ?? false;
2111
+ const drawnCards = spread.spreadId === "event-reading" ? drawEventReadingSpread(spread, includeInverted, rng, options.context) : drawDefaultTarotSpread(spread, includeInverted, rng);
2112
+ const validation = validateTarotSpreadSelection({
2113
+ spreadId: spread.spreadId,
2114
+ cards: drawnCards.map((card) => ({
2115
+ slotKey: card.slotKey,
2116
+ cardNumber: card.cardNumber,
2117
+ isInverted: card.isInverted
2118
+ })),
2119
+ context: options.context
2120
+ });
2121
+ if (!validation.ok) {
2122
+ throw new Error(
2123
+ `Generated an invalid tarot spread selection for ${spread.label}: ${validation.errors.map((error) => error.message).join(" ")}`
2124
+ );
2125
+ }
2126
+ return {
2127
+ spread: cloneSpreadDefinition(spread),
2128
+ deckId: options.deckId ?? "rider-waite",
2129
+ context: options.context,
2130
+ cards: sortResolvedTarotSpreadCards(drawnCards)
2131
+ };
2132
+ }
1058
2133
 
1059
- export { ARKANNUS, TAROT_IMAGE_BASE_URL, getTarotArchetype, getTarotRepresentation, getTarotRepresentations, listTarotDecks, majorArcana, resolveTarotImageUrl, shuffleTarotDeck };
1060
- //# sourceMappingURL=chunk-U3JFWP24.mjs.map
1061
- //# sourceMappingURL=chunk-U3JFWP24.mjs.map
2134
+ export { ARKANNUS, TAROT_IMAGE_BASE_URL, drawTarotSpread, getTarotArchetype, getTarotRepresentation, getTarotRepresentations, getTarotSpread, listTarotDecks, listTarotSpreads, majorArcana, resolveTarotImageUrl, shuffleTarotDeck, validateTarotSpreadSelection };
2135
+ //# sourceMappingURL=chunk-7IXAG4KW.mjs.map
2136
+ //# sourceMappingURL=chunk-7IXAG4KW.mjs.map