kaabalah 4.6.0 → 4.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.
@@ -288,6 +288,32 @@ function getAvailableLetters(tree, includeDigraphs) {
288
288
  const digraphs = includeDigraphs ? Array.from(DIGRAPHS) : [];
289
289
  return [...singleLetters, ...digraphs];
290
290
  }
291
+ function parseSuggestionToLetterUnits(text) {
292
+ const upper = text.toUpperCase();
293
+ const units = [];
294
+ let i = 0;
295
+ while (i < upper.length) {
296
+ const char = upper[i];
297
+ if (i + 1 < upper.length) {
298
+ const twoChar = char + upper[i + 1].toLowerCase();
299
+ if (DIGRAPHS.has(twoChar)) {
300
+ units.push(twoChar);
301
+ i += 2;
302
+ continue;
303
+ }
304
+ }
305
+ units.push(char);
306
+ i += 1;
307
+ }
308
+ return units;
309
+ }
310
+ function countLetterUnits(units) {
311
+ const counts = /* @__PURE__ */ new Map();
312
+ for (const unit of units) {
313
+ counts.set(unit, (counts.get(unit) || 0) + 1);
314
+ }
315
+ return counts;
316
+ }
291
317
  var reverseGematria = (options, tree) => {
292
318
  const {
293
319
  targetVowels,
@@ -296,7 +322,10 @@ var reverseGematria = (options, tree) => {
296
322
  minLength = 1,
297
323
  maxLength = 8,
298
324
  maxResults = 100,
299
- includeDigraphs = true
325
+ includeDigraphs = true,
326
+ maxLetterRepeat,
327
+ suggestionText,
328
+ suggestionMode = "subsequence"
300
329
  } = options;
301
330
  if (targetVowels === void 0 && targetConsonants === void 0 && targetSynthesis === void 0) {
302
331
  return { results: [], hasMore: false, totalFound: 0 };
@@ -304,6 +333,13 @@ var reverseGematria = (options, tree) => {
304
333
  if (!tree) {
305
334
  tree = chunk5AIYNAGI_js.createTree({ system: chunk5AIYNAGI_js.SYSTEM, parts: [] });
306
335
  }
336
+ if (suggestionText !== void 0) {
337
+ if (suggestionMode === "subsequence") {
338
+ return reverseGematriaFromSubsequence(options, tree);
339
+ } else {
340
+ return reverseGematriaAnagram(options, tree);
341
+ }
342
+ }
307
343
  const results = [];
308
344
  let totalFound = 0;
309
345
  let hasMore = false;
@@ -316,7 +352,7 @@ var reverseGematria = (options, tree) => {
316
352
  }
317
353
  return letterInfoCache.get(cacheKey);
318
354
  };
319
- const backtrack = (currentLetters, currentInfos, runningVowelsSum, runningConsonantsSum) => {
355
+ const backtrack = (currentLetters, currentInfos, runningVowelsSum, runningConsonantsSum, letterCounts) => {
320
356
  if (results.length >= maxResults) {
321
357
  hasMore = true;
322
358
  return;
@@ -382,6 +418,12 @@ var reverseGematria = (options, tree) => {
382
418
  const isStarting = currentLength === 0;
383
419
  const letterInfo = getLetterInfoCached(letter, isStarting);
384
420
  if (!letterInfo) continue;
421
+ if (maxLetterRepeat !== void 0) {
422
+ const currentCount = letterCounts.get(letter) || 0;
423
+ if (currentCount >= maxLetterRepeat) {
424
+ continue;
425
+ }
426
+ }
385
427
  const value = letterInfo.normalValue;
386
428
  const newVowelsSum = runningVowelsSum + (letterInfo.isVowel ? value : 0);
387
429
  const newConsonantsSum = runningConsonantsSum + (letterInfo.isVowel ? 0 : value);
@@ -396,22 +438,373 @@ var reverseGematria = (options, tree) => {
396
438
  }
397
439
  currentLetters.push(letter);
398
440
  currentInfos.push(letterInfo);
399
- backtrack(currentLetters, currentInfos, newVowelsSum, newConsonantsSum);
441
+ letterCounts.set(letter, (letterCounts.get(letter) || 0) + 1);
442
+ backtrack(currentLetters, currentInfos, newVowelsSum, newConsonantsSum, letterCounts);
400
443
  currentLetters.pop();
401
444
  currentInfos.pop();
445
+ letterCounts.set(letter, letterCounts.get(letter) - 1);
402
446
  if (results.length >= maxResults) {
403
447
  hasMore = true;
404
448
  return;
405
449
  }
406
450
  }
407
451
  };
408
- backtrack([], [], 0, 0);
452
+ backtrack([], [], 0, 0, /* @__PURE__ */ new Map());
409
453
  return {
410
454
  results,
411
455
  hasMore,
412
456
  totalFound
413
457
  };
414
458
  };
459
+ function reverseGematriaAnagram(options, tree) {
460
+ const {
461
+ targetVowels,
462
+ targetConsonants,
463
+ targetSynthesis,
464
+ minLength = 1,
465
+ maxLength = 8,
466
+ maxResults = 100,
467
+ maxLetterRepeat,
468
+ suggestionText = ""
469
+ } = options;
470
+ const results = [];
471
+ let totalFound = 0;
472
+ let hasMore = false;
473
+ const suggestionUnits = parseSuggestionToLetterUnits(suggestionText);
474
+ const letterUnits = suggestionUnits.filter((u) => u !== " ");
475
+ const maxSpaces = suggestionUnits.filter((u) => u === " ").length;
476
+ const availablePool = countLetterUnits(letterUnits);
477
+ const availableLetters = Array.from(availablePool.keys());
478
+ const letterInfoCache = /* @__PURE__ */ new Map();
479
+ const getLetterInfoCached = (letter, isStarting) => {
480
+ const cacheKey = `${letter}-${isStarting}`;
481
+ if (!letterInfoCache.has(cacheKey)) {
482
+ letterInfoCache.set(cacheKey, buildLetterInfo(tree, letter, isStarting));
483
+ }
484
+ return letterInfoCache.get(cacheKey);
485
+ };
486
+ const seenResults = /* @__PURE__ */ new Set();
487
+ const backtrack = (currentLetters, currentInfos, runningVowelsSum, runningConsonantsSum, letterCounts, usedFromPool, spacesUsed) => {
488
+ if (results.length >= maxResults) {
489
+ hasMore = true;
490
+ return;
491
+ }
492
+ const letterOnlyLength = currentLetters.filter((l) => l !== " ").length;
493
+ if (letterOnlyLength >= minLength && letterOnlyLength <= maxLength) {
494
+ let actualVowelsSum = runningVowelsSum;
495
+ let actualConsonantsSum = runningConsonantsSum;
496
+ if (currentInfos.length > 1) {
497
+ const lastInfo = currentInfos[currentInfos.length - 1];
498
+ if (lastInfo.endingValue !== void 0) {
499
+ const diff = lastInfo.endingValue - lastInfo.normalValue;
500
+ if (lastInfo.isVowel) {
501
+ actualVowelsSum += diff;
502
+ } else {
503
+ actualConsonantsSum += diff;
504
+ }
505
+ }
506
+ }
507
+ const actualSynthesisSum = actualVowelsSum + actualConsonantsSum;
508
+ const matchesVowels = targetVowels === void 0 || actualVowelsSum === targetVowels;
509
+ const matchesConsonants = targetConsonants === void 0 || actualConsonantsSum === targetConsonants;
510
+ const matchesSynthesis = targetSynthesis === void 0 || actualSynthesisSum === targetSynthesis;
511
+ if (matchesVowels && matchesConsonants && matchesSynthesis) {
512
+ const lettersStr = currentLetters.join("").toUpperCase();
513
+ if (!seenResults.has(lettersStr)) {
514
+ seenResults.add(lettersStr);
515
+ totalFound++;
516
+ if (results.length < maxResults) {
517
+ const letterDetails = currentInfos.map((info, idx) => {
518
+ const isEnding = idx === currentInfos.length - 1 && currentInfos.length > 1;
519
+ const useEndingValue = isEnding && info.endingValue !== void 0;
520
+ return {
521
+ latinLetterId: chunk5AIYNAGI_js.id("latinLetter" /* LATIN_LETTER */, info.letter),
522
+ value: useEndingValue ? info.endingValue : info.normalValue,
523
+ hebrewLetterId: info.hebrewLetterId,
524
+ hebrewCharacter: useEndingValue && info.hebrewCharacterWhenEnding ? info.hebrewCharacterWhenEnding : info.hebrewCharacter,
525
+ isVowel: info.isVowel
526
+ };
527
+ });
528
+ results.push({
529
+ letters: lettersStr,
530
+ letterDetails,
531
+ vowelsSum: actualVowelsSum,
532
+ consonantsSum: actualConsonantsSum,
533
+ synthesisSum: actualSynthesisSum
534
+ });
535
+ } else {
536
+ hasMore = true;
537
+ }
538
+ }
539
+ }
540
+ }
541
+ if (letterOnlyLength >= maxLength) {
542
+ return;
543
+ }
544
+ if (targetVowels !== void 0 && runningVowelsSum > targetVowels) {
545
+ return;
546
+ }
547
+ if (targetConsonants !== void 0 && runningConsonantsSum > targetConsonants) {
548
+ return;
549
+ }
550
+ if (targetSynthesis !== void 0 && runningVowelsSum + runningConsonantsSum > targetSynthesis) {
551
+ return;
552
+ }
553
+ if (spacesUsed < maxSpaces && currentLetters.length > 0 && currentLetters[currentLetters.length - 1] !== " ") {
554
+ currentLetters.push(" ");
555
+ backtrack(
556
+ currentLetters,
557
+ currentInfos,
558
+ runningVowelsSum,
559
+ runningConsonantsSum,
560
+ letterCounts,
561
+ usedFromPool,
562
+ spacesUsed + 1
563
+ );
564
+ currentLetters.pop();
565
+ if (results.length >= maxResults) {
566
+ hasMore = true;
567
+ return;
568
+ }
569
+ }
570
+ for (const letter of availableLetters) {
571
+ const poolLimit = availablePool.get(letter) || 0;
572
+ const usedCount = usedFromPool.get(letter) || 0;
573
+ if (usedCount >= poolLimit) {
574
+ continue;
575
+ }
576
+ if (maxLetterRepeat !== void 0) {
577
+ const currentCount = letterCounts.get(letter) || 0;
578
+ if (currentCount >= maxLetterRepeat) {
579
+ continue;
580
+ }
581
+ }
582
+ const isStarting = currentInfos.length === 0;
583
+ const letterInfo = getLetterInfoCached(letter, isStarting);
584
+ if (!letterInfo) continue;
585
+ const value = letterInfo.normalValue;
586
+ const newVowelsSum = runningVowelsSum + (letterInfo.isVowel ? value : 0);
587
+ const newConsonantsSum = runningConsonantsSum + (letterInfo.isVowel ? 0 : value);
588
+ if (targetVowels !== void 0 && newVowelsSum > targetVowels) {
589
+ continue;
590
+ }
591
+ if (targetConsonants !== void 0 && newConsonantsSum > targetConsonants) {
592
+ continue;
593
+ }
594
+ if (targetSynthesis !== void 0 && newVowelsSum + newConsonantsSum > targetSynthesis) {
595
+ continue;
596
+ }
597
+ currentLetters.push(letter);
598
+ currentInfos.push(letterInfo);
599
+ letterCounts.set(letter, (letterCounts.get(letter) || 0) + 1);
600
+ usedFromPool.set(letter, usedCount + 1);
601
+ backtrack(
602
+ currentLetters,
603
+ currentInfos,
604
+ newVowelsSum,
605
+ newConsonantsSum,
606
+ letterCounts,
607
+ usedFromPool,
608
+ spacesUsed
609
+ );
610
+ currentLetters.pop();
611
+ currentInfos.pop();
612
+ letterCounts.set(letter, letterCounts.get(letter) - 1);
613
+ usedFromPool.set(letter, usedCount);
614
+ if (results.length >= maxResults) {
615
+ hasMore = true;
616
+ return;
617
+ }
618
+ }
619
+ };
620
+ backtrack([], [], 0, 0, /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), 0);
621
+ return {
622
+ results,
623
+ hasMore,
624
+ totalFound
625
+ };
626
+ }
627
+ function reverseGematriaFromSubsequence(options, tree) {
628
+ const {
629
+ targetVowels,
630
+ targetConsonants,
631
+ targetSynthesis,
632
+ minLength = 1,
633
+ maxLength = 8,
634
+ maxResults = 100,
635
+ maxLetterRepeat,
636
+ suggestionText = ""
637
+ } = options;
638
+ const results = [];
639
+ let totalFound = 0;
640
+ let hasMore = false;
641
+ const suggestionUnits = parseSuggestionToLetterUnits(suggestionText);
642
+ const letterUnitsWithPositions = [];
643
+ for (let i = 0; i < suggestionUnits.length; i++) {
644
+ letterUnitsWithPositions.push({
645
+ unit: suggestionUnits[i],
646
+ isSpace: suggestionUnits[i] === " ",
647
+ originalIndex: i
648
+ });
649
+ }
650
+ const letterOnlyUnits = letterUnitsWithPositions.filter((u) => !u.isSpace);
651
+ const maxSpaces = letterUnitsWithPositions.filter((u) => u.isSpace).length;
652
+ const letterInfoCache = /* @__PURE__ */ new Map();
653
+ const getLetterInfoCached = (letter, isStarting) => {
654
+ const cacheKey = `${letter}-${isStarting}`;
655
+ if (!letterInfoCache.has(cacheKey)) {
656
+ letterInfoCache.set(cacheKey, buildLetterInfo(tree, letter, isStarting));
657
+ }
658
+ return letterInfoCache.get(cacheKey);
659
+ };
660
+ const seenResults = /* @__PURE__ */ new Set();
661
+ const generateSubsequences = (index, currentLetters, currentInfos, runningVowelsSum, runningConsonantsSum, letterCounts, spacesUsed) => {
662
+ if (results.length >= maxResults) {
663
+ hasMore = true;
664
+ return;
665
+ }
666
+ const letterOnlyLength = currentLetters.filter((l) => l !== " ").length;
667
+ if (letterOnlyLength >= minLength && letterOnlyLength <= maxLength) {
668
+ let actualVowelsSum = runningVowelsSum;
669
+ let actualConsonantsSum = runningConsonantsSum;
670
+ if (currentInfos.length > 1) {
671
+ const lastInfo = currentInfos[currentInfos.length - 1];
672
+ if (lastInfo.endingValue !== void 0) {
673
+ const diff = lastInfo.endingValue - lastInfo.normalValue;
674
+ if (lastInfo.isVowel) {
675
+ actualVowelsSum += diff;
676
+ } else {
677
+ actualConsonantsSum += diff;
678
+ }
679
+ }
680
+ }
681
+ const actualSynthesisSum = actualVowelsSum + actualConsonantsSum;
682
+ const matchesVowels = targetVowels === void 0 || actualVowelsSum === targetVowels;
683
+ const matchesConsonants = targetConsonants === void 0 || actualConsonantsSum === targetConsonants;
684
+ const matchesSynthesis = targetSynthesis === void 0 || actualSynthesisSum === targetSynthesis;
685
+ if (matchesVowels && matchesConsonants && matchesSynthesis) {
686
+ const lettersStr = currentLetters.join("").toUpperCase();
687
+ if (!seenResults.has(lettersStr)) {
688
+ seenResults.add(lettersStr);
689
+ totalFound++;
690
+ if (results.length < maxResults) {
691
+ const letterDetails = currentInfos.map((info, idx) => {
692
+ const isEnding = idx === currentInfos.length - 1 && currentInfos.length > 1;
693
+ const useEndingValue = isEnding && info.endingValue !== void 0;
694
+ return {
695
+ latinLetterId: chunk5AIYNAGI_js.id("latinLetter" /* LATIN_LETTER */, info.letter),
696
+ value: useEndingValue ? info.endingValue : info.normalValue,
697
+ hebrewLetterId: info.hebrewLetterId,
698
+ hebrewCharacter: useEndingValue && info.hebrewCharacterWhenEnding ? info.hebrewCharacterWhenEnding : info.hebrewCharacter,
699
+ isVowel: info.isVowel
700
+ };
701
+ });
702
+ results.push({
703
+ letters: lettersStr,
704
+ letterDetails,
705
+ vowelsSum: actualVowelsSum,
706
+ consonantsSum: actualConsonantsSum,
707
+ synthesisSum: actualSynthesisSum
708
+ });
709
+ } else {
710
+ hasMore = true;
711
+ }
712
+ }
713
+ }
714
+ }
715
+ if (index >= letterOnlyUnits.length || letterOnlyLength >= maxLength) {
716
+ return;
717
+ }
718
+ if (targetVowels !== void 0 && runningVowelsSum > targetVowels) {
719
+ return;
720
+ }
721
+ if (targetConsonants !== void 0 && runningConsonantsSum > targetConsonants) {
722
+ return;
723
+ }
724
+ if (targetSynthesis !== void 0 && runningVowelsSum + runningConsonantsSum > targetSynthesis) {
725
+ return;
726
+ }
727
+ generateSubsequences(
728
+ index + 1,
729
+ currentLetters,
730
+ currentInfos,
731
+ runningVowelsSum,
732
+ runningConsonantsSum,
733
+ letterCounts,
734
+ spacesUsed
735
+ );
736
+ if (results.length >= maxResults) {
737
+ hasMore = true;
738
+ return;
739
+ }
740
+ const letter = letterOnlyUnits[index].unit;
741
+ if (maxLetterRepeat !== void 0) {
742
+ const currentCount = letterCounts.get(letter) || 0;
743
+ if (currentCount >= maxLetterRepeat) {
744
+ return;
745
+ }
746
+ }
747
+ const isStarting = currentInfos.length === 0;
748
+ const letterInfo = getLetterInfoCached(letter, isStarting);
749
+ if (!letterInfo) return;
750
+ const value = letterInfo.normalValue;
751
+ const newVowelsSum = runningVowelsSum + (letterInfo.isVowel ? value : 0);
752
+ const newConsonantsSum = runningConsonantsSum + (letterInfo.isVowel ? 0 : value);
753
+ if (targetVowels !== void 0 && newVowelsSum > targetVowels) {
754
+ return;
755
+ }
756
+ if (targetConsonants !== void 0 && newConsonantsSum > targetConsonants) {
757
+ return;
758
+ }
759
+ if (targetSynthesis !== void 0 && newVowelsSum + newConsonantsSum > targetSynthesis) {
760
+ return;
761
+ }
762
+ currentLetters.push(letter);
763
+ currentInfos.push(letterInfo);
764
+ letterCounts.set(letter, (letterCounts.get(letter) || 0) + 1);
765
+ generateSubsequences(
766
+ index + 1,
767
+ currentLetters,
768
+ currentInfos,
769
+ newVowelsSum,
770
+ newConsonantsSum,
771
+ letterCounts,
772
+ spacesUsed
773
+ );
774
+ currentLetters.pop();
775
+ currentInfos.pop();
776
+ letterCounts.set(letter, letterCounts.get(letter) - 1);
777
+ if (results.length >= maxResults) {
778
+ hasMore = true;
779
+ return;
780
+ }
781
+ if (spacesUsed < maxSpaces && currentLetters.length > 0 && currentLetters[currentLetters.length - 1] !== " ") {
782
+ currentLetters.push(" ");
783
+ currentLetters.push(letter);
784
+ currentInfos.push(letterInfo);
785
+ letterCounts.set(letter, (letterCounts.get(letter) || 0) + 1);
786
+ generateSubsequences(
787
+ index + 1,
788
+ currentLetters,
789
+ currentInfos,
790
+ newVowelsSum,
791
+ newConsonantsSum,
792
+ letterCounts,
793
+ spacesUsed + 1
794
+ );
795
+ currentLetters.pop();
796
+ currentLetters.pop();
797
+ currentInfos.pop();
798
+ letterCounts.set(letter, letterCounts.get(letter) - 1);
799
+ }
800
+ };
801
+ generateSubsequences(0, [], [], 0, 0, /* @__PURE__ */ new Map(), 0);
802
+ return {
803
+ results,
804
+ hasMore,
805
+ totalFound
806
+ };
807
+ }
415
808
  var calculateGematria = (phrase, options = {
416
809
  missing: false,
417
810
  percentages: false
@@ -481,5 +874,5 @@ var calculateGematria = (phrase, options = {
481
874
  exports.calculateGematria = calculateGematria;
482
875
  exports.data_exports = data_exports;
483
876
  exports.reverseGematria = reverseGematria;
484
- //# sourceMappingURL=chunk-Y2LGJEWP.js.map
485
- //# sourceMappingURL=chunk-Y2LGJEWP.js.map
877
+ //# sourceMappingURL=chunk-JOYHXU24.js.map
878
+ //# sourceMappingURL=chunk-JOYHXU24.js.map