scripture-guide 1.0.95 → 1.1.1

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.
@@ -1,4 +1,4 @@
1
- /* scripture-guide v1.0.95 */
1
+ /* scripture-guide v1.1.1 */
2
2
 
3
3
  // src/data/canons/bible/structure.mjs
4
4
  var structure_default = {
@@ -849,7 +849,7 @@ var structure_default = {
849
849
  "first_verse_id": 17317
850
850
  },
851
851
  {
852
- "key": "solomon_s_song",
852
+ "key": "song_of_solomon",
853
853
  "order": 22,
854
854
  "chapters": 8,
855
855
  "verses": [
@@ -2489,9 +2489,11 @@ var en_default = {
2489
2489
  ]
2490
2490
  },
2491
2491
  "song_of_solomon": {
2492
- "name": "Song of Solomon",
2493
- "pattern": "(?<!solomon's )(the )*song*\\.*(?: *of *solomon)*",
2492
+ "name": "Solomon's Song",
2493
+ "pattern": "(?<!solomon['\u2019]?s )(the )*song*\\.*(?: *of *solomon)*",
2494
2494
  "alt": [
2495
+ "solomon\u2019s song",
2496
+ "solomons song",
2495
2497
  "song",
2496
2498
  "sos",
2497
2499
  "ss",
@@ -3200,6 +3202,16 @@ var en_default3 = {
3200
3202
  "cited at",
3201
3203
  "also"
3202
3204
  ],
3205
+ "capitalized_only": [
3206
+ "is",
3207
+ "am",
3208
+ "he",
3209
+ "re",
3210
+ "la",
3211
+ "co",
3212
+ "col",
3213
+ "act"
3214
+ ],
3203
3215
  "pre_rules": [
3204
3216
  [
3205
3217
  "\\bgospel\\s+(?:of|according\\s+to)\\s+",
@@ -3261,6 +3273,10 @@ var en_default3 = {
3261
3273
  "\\bfourth\\s+(?=[A-Za-z])",
3262
3274
  "4 "
3263
3275
  ],
3276
+ [
3277
+ "(\\d)\\s+&\\s+",
3278
+ "$1; "
3279
+ ],
3264
3280
  [
3265
3281
  "[.]{2,}",
3266
3282
  ";"
@@ -31245,7 +31261,8 @@ function buildRegexData() {
31245
31261
  books,
31246
31262
  pre_rules: en_default3.pre_rules || [],
31247
31263
  post_rules: en_default3.post_rules || [],
31248
- joiners: en_default3.joiners || []
31264
+ joiners: en_default3.joiners || [],
31265
+ capitalized_only: en_default3.capitalized_only || []
31249
31266
  };
31250
31267
  }
31251
31268
  function transformBooks(bibleBooks, ldsBooks) {
@@ -31415,10 +31432,12 @@ var rangesOverlap = (range1, range2) => {
31415
31432
  var removeOverlaps = (matches, content, preferenceResolver = null) => {
31416
31433
  if (matches.length <= 1) return matches;
31417
31434
  const result = [];
31435
+ const sorted = matches.every((m, i) => i === 0 || m[0] >= matches[i - 1][0]);
31436
+ let includedMaxEnd = -Infinity;
31418
31437
  for (let i = 0; i < matches.length; i++) {
31419
31438
  const current = matches[i];
31420
31439
  let shouldInclude = true;
31421
- for (const included of result) {
31440
+ if (!sorted || includedMaxEnd > current[0]) for (const included of result) {
31422
31441
  if (rangesOverlap(current, included)) {
31423
31442
  shouldInclude = false;
31424
31443
  break;
@@ -31427,6 +31446,7 @@ var removeOverlaps = (matches, content, preferenceResolver = null) => {
31427
31446
  if (shouldInclude) {
31428
31447
  for (let j = i + 1; j < matches.length; j++) {
31429
31448
  const next = matches[j];
31449
+ if (sorted && next[0] >= current[1]) break;
31430
31450
  if (rangesOverlap(current, next)) {
31431
31451
  if (preferenceResolver) {
31432
31452
  const preferred = preferenceResolver(current, next, content);
@@ -31447,10 +31467,27 @@ var removeOverlaps = (matches, content, preferenceResolver = null) => {
31447
31467
  }
31448
31468
  if (shouldInclude) {
31449
31469
  result.push(current);
31470
+ includedMaxEnd = Math.max(includedMaxEnd, current[1]);
31450
31471
  }
31451
31472
  }
31452
31473
  return result;
31453
31474
  };
31475
+ var spanCoverage = (spans) => {
31476
+ const sorted = [...spans || []].sort((a, b) => a[0] - b[0]);
31477
+ const maxEnd = [];
31478
+ for (let i = 0; i < sorted.length; i++) maxEnd.push(Math.max(sorted[i][1], i ? maxEnd[i - 1] : -Infinity));
31479
+ return (position) => {
31480
+ let lo = 0, hi = sorted.length - 1, last = -1;
31481
+ while (lo <= hi) {
31482
+ const mid = lo + hi >> 1;
31483
+ if (sorted[mid][0] <= position) {
31484
+ last = mid;
31485
+ lo = mid + 1;
31486
+ } else hi = mid - 1;
31487
+ }
31488
+ return last >= 0 && maxEnd[last] > position;
31489
+ };
31490
+ };
31454
31491
  var calculateGaps = (matches) => {
31455
31492
  return matches.reduce((prev, current, index) => {
31456
31493
  if (index === 0) return prev;
@@ -31494,7 +31531,7 @@ var mergeAdjacentMatches = (matches, gapMergeFlags, compatibilityCheck = null) =
31494
31531
  if (prevIndex.length > 2 && current.length > 2) {
31495
31532
  const startPos = prevIndex[0];
31496
31533
  const endPos = current[1];
31497
- const combinedText = prevIndex[2] + ";" + current[2];
31534
+ const combinedText = prevIndex[2] + "; " + current[2];
31498
31535
  const combinedVerseIds = [...prevIndex[3] || [], ...current[3] || []];
31499
31536
  const merged = [startPos, endPos, combinedText, combinedVerseIds];
31500
31537
  prev[prev.length - 1] = merged;
@@ -31511,6 +31548,7 @@ var mergeAdjacentMatches = (matches, gapMergeFlags, compatibilityCheck = null) =
31511
31548
  };
31512
31549
  var gapCanMerge = (gapString, joiners) => {
31513
31550
  if (!/\S/.test(gapString)) return true;
31551
+ if (/^\s*\./.test(gapString)) return false;
31514
31552
  const list = Array.isArray(joiners) ? joiners : joiners && joiners.patterns || [];
31515
31553
  let residue = gapString;
31516
31554
  for (const joiner of list) {
@@ -31567,24 +31605,29 @@ var findMatches = (content, books, lang_extra) => {
31567
31605
  normalizedContent = normalizedContent.replace(new RegExp(entity, "g"), unicode);
31568
31606
  });
31569
31607
  const tail = lang_extra.tail ? new RegExp(lang_extra.tail, "ig") : /[^0-9]+$/;
31570
- const preBookMatch = lang_extra.book || `(First|I|1|1st|Second|II|2|2nd|Third|III|3|3rd|Fourth|IV|4|4th)*\\s*(books* of)*\\s*`;
31608
+ const preBookMatch = lang_extra.book || `(?:(?:First|Second|Third|Fourth|1st|2nd|3rd|4th|III|II|IV|I|[1-4])\\s*)?(?:books? of\\s*)?`;
31571
31609
  const matchingBooks = findMatchingBooks(normalizedContent, books);
31572
31610
  const gap = "[ \\t]*(?:\\n(?![ \\t]*\\n)[ \\t]*)?(?:,[ \\t]*sec(?:tion)?\\.?[ \\t]*)?\\(?[ \\t]*(?=[0-9])";
31573
31611
  const core = "(?:[0-9:.;,~\u2014\u2013-]|[ \\t]|\\n(?![ \\t]*\\n)|and\\b|cf\\b|\\()*[0-9]";
31574
31612
  const postBookMatch = lang_extra.chapter || gap + core;
31613
+ const capitalizedOnlyAbbreviations = new Set(
31614
+ (lang_extra.capitalizedOnly || []).map((i) => String(i).toLowerCase())
31615
+ );
31575
31616
  const fullBookMatches = matchingBooks.map((bookMatch) => {
31576
31617
  const patternString = preBookMatch + bookMatch;
31577
31618
  const pattern = new RegExp(patternString, "ig");
31578
31619
  const stringMatch = pattern.test(normalizedContent) ? patternString : null;
31579
31620
  return stringMatch;
31580
31621
  }).filter((x) => !!x);
31581
- const bookSubStrings = fullBookMatches.map((bookMatch) => {
31622
+ const allBookSubStrings = fullBookMatches.map((bookMatch) => {
31582
31623
  const substrings = normalizedContent.match(new RegExp(bookMatch, "ig")).flat();
31583
31624
  return substrings;
31584
- }).flat().reduce((prev, current) => {
31585
- if (prev.includes(current)) return prev;
31586
- return [...prev, current];
31587
- }, []).filter((i) => !!i).map((substring) => {
31625
+ }).flat();
31626
+ const bookSubStrings = [...new Set(allBookSubStrings)].filter((i) => !!i).filter((substring) => {
31627
+ const token = substring.trim();
31628
+ if (!capitalizedOnlyAbbreviations.has(token.toLowerCase())) return true;
31629
+ return token !== token.toLowerCase();
31630
+ }).map((substring) => {
31588
31631
  substring = substring.trim();
31589
31632
  let positions = [];
31590
31633
  let index = normalizedContent.indexOf(substring);
@@ -31604,39 +31647,54 @@ var findMatches = (content, books, lang_extra) => {
31604
31647
  return [substring, positions];
31605
31648
  }).filter((i) => !!i);
31606
31649
  const possiblyOverlappingMatches = bookSubStrings.map(([substring, positions]) => {
31650
+ let pattern = null;
31651
+ try {
31652
+ pattern = new RegExp(substring + postBookMatch, "iy");
31653
+ } catch (e) {
31654
+ return [];
31655
+ }
31607
31656
  return positions.map(
31608
31657
  (i) => {
31609
- let pattern = null;
31610
- try {
31611
- pattern = new RegExp(substring + postBookMatch, "ig");
31612
- } catch (e) {
31613
- return null;
31614
- }
31615
- const match = normalizedContent.slice(i).match(pattern)?.[0]?.replace(tail, "").trim();
31658
+ pattern.lastIndex = i;
31659
+ const match = pattern.exec(normalizedContent)?.[0]?.replace(tail, "").trim();
31616
31660
  if (!match) return null;
31617
31661
  const len = match.length;
31618
31662
  const pos = i;
31619
31663
  const [posIn, posOut] = [pos, pos + len];
31664
+ if (/[0-9]$/.test(match) && /[A-Z]/.test(normalizedContent[posOut] || "")) return null;
31620
31665
  return [match, posIn, posOut];
31621
31666
  }
31622
31667
  );
31623
31668
  }).flat().filter((i) => !!i);
31669
+ const byStart = [...possiblyOverlappingMatches].sort((a, b) => a[1] - b[1]);
31670
+ const maxEndUpTo = [];
31671
+ byStart.forEach(([, , e1], i) => maxEndUpTo.push(Math.max(e1, i ? maxEndUpTo[i - 1] : -Infinity)));
31672
+ const cutPoint = (string, end) => {
31673
+ let lo = 0, hi = byStart.length - 1, first = byStart.length;
31674
+ while (lo <= hi) {
31675
+ const mid = lo + hi >> 1;
31676
+ if (maxEndUpTo[mid] > end) {
31677
+ first = mid;
31678
+ hi = mid - 1;
31679
+ } else lo = mid + 1;
31680
+ }
31681
+ for (let k = first; k < byStart.length && byStart[k][1] < end; k++) {
31682
+ const [s, s1, e1] = byStart[k];
31683
+ if (s !== string && e1 > end) return s1;
31684
+ }
31685
+ return end;
31686
+ };
31624
31687
  const matchesWithReferences = possiblyOverlappingMatches.map(([string, start, end]) => {
31625
- const overLappingItems = possiblyOverlappingMatches.filter(([s, s1, e1]) => s !== string && s1 < end && e1 > end);
31626
- const hasOverlap = overLappingItems.length > 0;
31627
- const newEnd = hasOverlap ? Math.min(...overLappingItems.map(([s, s1, e1]) => s1)) : end;
31688
+ const newEnd = cutPoint(string, end);
31628
31689
  const newString = normalizedContent.slice(start, newEnd);
31629
31690
  return newString.replace(tail, "").trim();
31630
31691
  }).filter((i) => !!i);
31631
- const matches = matchesWithReferences.map((string) => {
31692
+ const matches = [...new Set(matchesWithReferences)].map((string) => {
31632
31693
  const pattern = new RegExp(string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "ig");
31633
31694
  const matches2 = normalizedContent.match(pattern)?.map((i) => i.trim().replace(tail, ""));
31634
31695
  return matches2;
31635
- }).flat().reduce((prev, current) => {
31636
- if (prev.includes(current)) return prev;
31637
- return [...prev, current];
31638
- }, []).filter((i) => !!i);
31639
- return matches;
31696
+ }).flat();
31697
+ return [...new Set(matches)].filter((i) => !!i);
31640
31698
  };
31641
31699
  function findMatchIndexes(content, matches, lookupReference2, lang_extra) {
31642
31700
  const tail = lang_extra.tail ? new RegExp(lang_extra.tail, "ig") : /[^0-9]+$/;
@@ -31659,6 +31717,7 @@ function findMatchIndexes(content, matches, lookupReference2, lang_extra) {
31659
31717
  const next = array[index + 1];
31660
31718
  if (next && next[0] < end && next[1] > end) {
31661
31719
  end = next[0];
31720
+ end = start + content.slice(start, end).replace(tail, "").length;
31662
31721
  }
31663
31722
  return [start, end];
31664
31723
  });
@@ -31706,7 +31765,7 @@ var processReferenceDetection = (content, books, lang_extra, lookupReference2, c
31706
31765
  var collectReferencesWithContext = (content, books, lang_extra, lookupReference2, options) => {
31707
31766
  const explicitMatches = findMatches(content, books, lang_extra);
31708
31767
  const explicitIndices = findMatchIndexes(content, explicitMatches, lookupReference2, lang_extra) || [];
31709
- const impliedMatches = findImpliedReferences(content, explicitMatches, explicitIndices, lookupReference2, options);
31768
+ const impliedMatches = findImpliedReferences(content, explicitMatches, explicitIndices, lookupReference2, options, lang_extra);
31710
31769
  const explicitMatchesWithRefs = explicitIndices.map(([start, end]) => {
31711
31770
  const originalText = content.substring(start, end);
31712
31771
  const verification = lookupReference2(originalText);
@@ -31797,7 +31856,21 @@ var getNearestBookContext = (position, bookContexts, maxDistance) => {
31797
31856
  }
31798
31857
  return bestContext;
31799
31858
  };
31800
- var findImpliedReferences = (content, explicitMatches, explicitIndices, lookupReference2, options) => {
31859
+ var CITATION_CONNECTIVES = ["including", "namely", "e.g", "i.e"];
31860
+ var bindsToBookContext = (tail, joiners) => {
31861
+ const trimmed = tail.replace(/\s+$/, "");
31862
+ if (!trimmed) return true;
31863
+ if (/[;&([]$/.test(trimmed)) return true;
31864
+ const list = Array.isArray(joiners) ? joiners : joiners && joiners.patterns || [];
31865
+ const words = /* @__PURE__ */ new Set([
31866
+ ...list.filter((j) => typeof j === "string" && /[a-z]/i.test(j)).map((j) => j.toLowerCase().replace(/\.+$/, "").split(/\s+/).pop()),
31867
+ ...CITATION_CONNECTIVES
31868
+ ]);
31869
+ const lastWord = (trimmed.match(/[A-Za-z.']+$/) || [""])[0].toLowerCase().replace(/[.']+$/, "");
31870
+ return lastWord !== "" && words.has(lastWord);
31871
+ };
31872
+ var findImpliedReferences = (content, explicitMatches, explicitIndices, lookupReference2, options, lang_extra = {}) => {
31873
+ const joiners = lang_extra && (lang_extra.unrestrictedJoiners || lang_extra.joiners) || ["and", ";", ",", "&", "compare", "see also", "see", "cf", "c.f.", "cited at", "also"];
31801
31874
  const matches = [];
31802
31875
  const bookContexts = findBookContexts(content, explicitMatches, explicitIndices, lookupReference2);
31803
31876
  const verseGroupPattern = /\b(?:vv?\.?\s*|vs\.?\s*|verses?\s+)([\d:,\s–—-]+?)(?=\s*[).;\n]|$)/gi;
@@ -31816,19 +31889,21 @@ var findImpliedReferences = (content, explicitMatches, explicitIndices, lookupRe
31816
31889
  }
31817
31890
  }
31818
31891
  const chapterVersePattern = /\b(\d+):(\d+(?:[–—-]\d+)?(?:\s*,\s*\d+(?:[–—-]\d+)?)*)/g;
31892
+ const insideExplicit = spanCoverage(explicitIndices || []);
31819
31893
  while ((match = chapterVersePattern.exec(content)) !== null) {
31820
31894
  const fullMatch = match[0];
31821
31895
  const chapter = match[1];
31822
31896
  const verses = match[2];
31823
31897
  const position = match.index;
31824
- const isPartOfExplicit = explicitIndices && explicitIndices.some(
31825
- ([start, end]) => position >= start && position < end
31826
- );
31898
+ const isPartOfExplicit = insideExplicit(position);
31827
31899
  if (isPartOfExplicit) {
31828
31900
  continue;
31829
31901
  }
31902
+ if (/^\s*(?:[ap]\.?\s?m\b\.?|o['’]?clock\b)/i.test(content.slice(position + fullMatch.length))) {
31903
+ continue;
31904
+ }
31830
31905
  const context = getNearestBookContext(position, bookContexts, options.maxContextDistance);
31831
- if (context) {
31906
+ if (context && (options.strictImpliedBooks === false || bindsToBookContext(content.slice(context.endPosition, position), joiners))) {
31832
31907
  const impliedRef = `${context.book} ${chapter}:${verses}`;
31833
31908
  const verification = lookupReference2(impliedRef);
31834
31909
  if (verification.verse_ids && verification.verse_ids.length > 0) {
@@ -31925,6 +32000,11 @@ var convertCanon = (verseIds, options = {}) => {
31925
32000
  return result;
31926
32001
  };
31927
32002
 
32003
+ // src/slug.mjs
32004
+ function toSlug(ref) {
32005
+ return ref.trim().toLowerCase().replace(/[־᠆‐‒–—―﹣-‑]+/gu, "-").replace(/[\s:]+/g, ".").replace(/\.+/g, ".").replace(/;\./g, ";").replace(/,\./g, ",").replace(/\.;/g, ";").replace(/\.,/g, ",");
32006
+ }
32007
+
31928
32008
  // src/config.mjs
31929
32009
  var MAX_RANGE_SIZE = 1e3;
31930
32010
  var MAX_CHAPTER = 200;
@@ -31958,11 +32038,20 @@ for (const [canonKey, canonData] of Object.entries(extraCanons)) {
31958
32038
  });
31959
32039
  }
31960
32040
  }
31961
- var indexCache = {
31962
- refIndex: null,
31963
- refIndexHash: null,
31964
- verseIdIndex: null,
31965
- verseIdIndexHash: null
32041
+ var INDEX_CACHE_LIMIT = 4;
32042
+ var refIndexCache = /* @__PURE__ */ new Map();
32043
+ var verseIdIndexCache = /* @__PURE__ */ new Map();
32044
+ var cachedIndex = (cache, key, build) => {
32045
+ if (cache.has(key)) {
32046
+ const value2 = cache.get(key);
32047
+ cache.delete(key);
32048
+ cache.set(key, value2);
32049
+ return value2;
32050
+ }
32051
+ const value = build();
32052
+ cache.set(key, value);
32053
+ if (cache.size > INDEX_CACHE_LIMIT) cache.delete(cache.keys().next().value);
32054
+ return value;
31966
32055
  };
31967
32056
  var hashConfig = (config) => {
31968
32057
  return (config?.language || "en") + ":" + (config?.canon || DEFAULTS.canon);
@@ -32039,7 +32128,8 @@ var lookupReference = function(query, optionsOrLanguage = {}, legacyConfig = nul
32039
32128
  const effectiveLanguage = getEffectiveLanguage(language);
32040
32129
  const { convertTo, includeParallel } = lookupConfig;
32041
32130
  const canon = lookupConfig.canon || getEffectiveCanon();
32042
- const lookupResult = lookupInLanguage(query, effectiveLanguage, canon);
32131
+ const limit = rangeLimit(lookupConfig.maxVerses);
32132
+ const lookupResult = lookupInLanguage(query, effectiveLanguage, canon, limit);
32043
32133
  const verse_ids = lookupResult.verse_ids;
32044
32134
  const errors = lookupResult.errors;
32045
32135
  if (verse_ids?.length) {
@@ -32068,7 +32158,7 @@ var lookupReference = function(query, optionsOrLanguage = {}, legacyConfig = nul
32068
32158
  return result;
32069
32159
  }
32070
32160
  if (!lookupConfig.noMulti) {
32071
- const fallbackResult = lookupWithLanguageFallback(query, effectiveLanguage, canon);
32161
+ const fallbackResult = lookupWithLanguageFallback(query, effectiveLanguage, canon, limit);
32072
32162
  if (fallbackResult.verse_ids.length === 0 && errors) {
32073
32163
  fallbackResult.error = errors.join("; ");
32074
32164
  }
@@ -32081,14 +32171,17 @@ var lookupReference = function(query, optionsOrLanguage = {}, legacyConfig = nul
32081
32171
  error: errors ? errors.join("; ") : void 0
32082
32172
  };
32083
32173
  };
32084
- var lookupInLanguage = function(query, language, canon = null) {
32174
+ var rangeLimit = function(maxVerses) {
32175
+ return Number.isInteger(maxVerses) && maxVerses > 0 ? maxVerses : MAX_RANGE_SIZE;
32176
+ };
32177
+ var lookupInLanguage = function(query, language, canon = null, limit = MAX_RANGE_SIZE) {
32085
32178
  const config = getLanguageConfig(language, canon);
32086
32179
  let ref = cleanReference(query, config);
32087
32180
  let refs = splitReferences(ref, config);
32088
32181
  let verse_ids = [];
32089
32182
  let errors = [];
32090
32183
  for (let i in refs) {
32091
- const result = lookupSingleRef(refs[i], config);
32184
+ const result = lookupSingleRef(refs[i], config, limit);
32092
32185
  if (result && result.error) {
32093
32186
  errors.push(result.error);
32094
32187
  } else if (Array.isArray(result)) {
@@ -32102,10 +32195,17 @@ var lookupInLanguage = function(query, language, canon = null) {
32102
32195
  errors: errors.length > 0 ? errors : void 0
32103
32196
  };
32104
32197
  };
32105
- var lookupWithLanguageFallback = function(query, targetLanguage, canon = null) {
32198
+ var detectionLookup = function(language) {
32199
+ const seen = /* @__PURE__ */ new Map();
32200
+ return (query) => {
32201
+ if (!seen.has(query)) seen.set(query, lookupReference(query, { language, noMulti: true }));
32202
+ return seen.get(query);
32203
+ };
32204
+ };
32205
+ var lookupWithLanguageFallback = function(query, targetLanguage, canon = null, limit = MAX_RANGE_SIZE) {
32106
32206
  const fallbackLanguages = targetLanguage !== "en" ? ["en", ...Object.keys(raw_lang).filter((lang) => lang !== "en" && lang !== targetLanguage)] : Object.keys(raw_lang).filter((lang) => lang !== targetLanguage);
32107
32207
  for (const lang of fallbackLanguages) {
32108
- const lookupResult = lookupInLanguage(query, lang, canon);
32208
+ const lookupResult = lookupInLanguage(query, lang, canon, limit);
32109
32209
  const verse_ids = lookupResult.verse_ids;
32110
32210
  if (verse_ids?.length) {
32111
32211
  const refInTargetLanguage = generateReference(verse_ids, { language: targetLanguage, canon });
@@ -32122,9 +32222,9 @@ var lookupWithLanguageFallback = function(query, targetLanguage, canon = null) {
32122
32222
  "verse_ids": []
32123
32223
  };
32124
32224
  };
32125
- var lookupSingleRef = function(ref, config) {
32225
+ var lookupSingleRef = function(ref, config, limit = MAX_RANGE_SIZE) {
32126
32226
  const booksWithDashRegex = /^(joseph|조셉)/i;
32127
- if (!booksWithDashRegex.test(ref) && ref.match(/[—-](\d\s)*[\D]/ig)) return lookupMultiBookRange(ref, config);
32227
+ if (!booksWithDashRegex.test(ref) && ref.match(/[—-](\d\s)*[\D]/ig)) return lookupMultiBookRange(ref, config, limit);
32128
32228
  let book = getBook(ref, config);
32129
32229
  if (!book) {
32130
32230
  return {
@@ -32133,7 +32233,7 @@ var lookupSingleRef = function(ref, config) {
32133
32233
  };
32134
32234
  }
32135
32235
  let ranges = getRanges(ref, book);
32136
- let verse_ids = loadVerseIds(book, ranges, config);
32236
+ let verse_ids = loadVerseIds(book, ranges, config, limit);
32137
32237
  return verse_ids;
32138
32238
  };
32139
32239
  var validateVerseIdsMixed = function(verse_ids) {
@@ -32169,7 +32269,7 @@ var generateReference = function(verse_ids, optionsOrLanguage = {}, legacyOption
32169
32269
  let ref = refs.join("; ");
32170
32270
  return ref;
32171
32271
  };
32172
- var lookupMultiBookRange = function(cleanRef, config) {
32272
+ var lookupMultiBookRange = function(cleanRef, config, limit = MAX_RANGE_SIZE) {
32173
32273
  let range = cleanRef.split(/[—-]/);
32174
32274
  if (!range[0].match(/[:]/)) {
32175
32275
  if (range[0].match(/\d+\s*$/)) range[0] = range[0].trim() + ":1";
@@ -32190,7 +32290,7 @@ var lookupMultiBookRange = function(cleanRef, config) {
32190
32290
  let end = lookupSingleRef(range[1], config)[0];
32191
32291
  let all_verse_ids = [];
32192
32292
  for (let i = start; i <= end; i++) {
32193
- if (all_verse_ids.length >= MAX_RANGE_SIZE) break;
32293
+ if (all_verse_ids.length >= limit) break;
32194
32294
  all_verse_ids.push(i);
32195
32295
  }
32196
32296
  return all_verse_ids;
@@ -32203,41 +32303,44 @@ var strToHash = function(str) {
32203
32303
  }
32204
32304
  return `==${hash}==`;
32205
32305
  };
32306
+ var cleanRulesCache = /* @__PURE__ */ new WeakMap();
32307
+ var cleanRules = function(config) {
32308
+ let rules = cleanRulesCache.get(config);
32309
+ if (rules) return rules;
32310
+ const pre = (config.raw_regex.pre_rules || []).map((rule) => [new RegExp(rule.pattern ?? rule[0], "ig"), rule.replacement ?? rule[1] ?? ""]);
32311
+ const [wordBreak, buffer] = config.raw_regex.spacing || ["\\b", ""];
32312
+ let srcbooks = config.raw_regex.books;
32313
+ let dstbooks = buffer ? config.raw_regex.books.map((i) => [i[1], i[1]]) : [];
32314
+ let bookMatchList = [...dstbooks, ...srcbooks].sort((a, b) => b[0].length - a[0].length);
32315
+ let hashCypher = {};
32316
+ for (const [, book] of bookMatchList) hashCypher[book] = strToHash(book);
32317
+ const bookRules = bookMatchList.map(([pattern, book]) => [new RegExp(wordBreak + buffer + pattern + buffer + "\\.*" + wordBreak, "ig"), hashCypher[book] || book]);
32318
+ const hashes = Object.values(hashCypher);
32319
+ rules = { pre, buffer, books: Object.keys(hashCypher), hashes, bookRules, hashRe: new RegExp(hashes.join("|"), "g") };
32320
+ cleanRulesCache.set(config, rules);
32321
+ return rules;
32322
+ };
32206
32323
  var cleanReference = function(messyReference, config) {
32207
32324
  let ref = messyReference.replace(/[\s]+/g, " ").trim();
32208
32325
  ref = ref.replace(/(\d)\s+and\s+(\d)/g, "$1,$2");
32209
32326
  ref = ref.replace(/[()]/g, " ");
32210
32327
  ref = ref.replace(/\bsec(?:tion)?\b\.?/ig, " ");
32211
- let regex = config.raw_regex.pre_rules;
32212
- for (let i in regex) {
32213
- var re = new RegExp(regex[i].pattern ?? regex[i][0], "ig");
32214
- ref = ref.replace(re, regex[i].replacement ?? regex[i][1] ?? "");
32215
- }
32328
+ ref = ref.replace(/(\d)[.](?=(?:\d[.\s]*)?\p{L})/gu, "$1 ");
32329
+ ref = ref.replace(/(\d)\s+(?=\d[\s.]*\p{L}[\p{L}\s.&'-]{0,40}?[\s.]\d)/gu, "$1; ");
32330
+ const rules = cleanRules(config);
32331
+ for (const [re, replacement] of rules.pre) ref = ref.replace(re, replacement);
32216
32332
  ref = ref.replace(/(\d+)[.](\d+)/g, "$1:$2");
32217
32333
  ref = ref.replace(/[.]/g, "");
32218
32334
  ref = ref.replace(/;/g, "; ");
32219
32335
  ref = ref.replace(/^([0-9;,:-]+)(\d+)/g, "$1 $2");
32220
32336
  ref = ref.replace(/([–-])(\D+)/g, " $1 $2 ");
32221
- const [wordBreak, buffer] = config.raw_regex.spacing || ["\\b", ""];
32222
- let srcbooks = config.raw_regex.books;
32223
- let dstbooks = buffer ? config.raw_regex.books.map((i) => [i[1], i[1]]) : [];
32224
- let bookMatchList = [...dstbooks, ...srcbooks].sort((a, b) => b[0].length - a[0].length);
32225
- regex = bookMatchList;
32226
- let hashCypher = {};
32227
- for (let i in regex) {
32228
- const [, book] = regex[i];
32229
- const hash = strToHash(book);
32230
- hashCypher[book] = hash;
32231
- }
32232
- for (let i in regex) {
32233
- var re = new RegExp(wordBreak + buffer + regex[i][0] + buffer + "\\.*" + wordBreak, "ig");
32234
- let replacement = hashCypher[regex[i][1]] || regex[i][1];
32337
+ const { buffer, books, hashes } = rules;
32338
+ for (const [re, replacement] of rules.bookRules) {
32235
32339
  ref = (buffer + ref + buffer).replace(re, replacement).trim();
32236
32340
  }
32237
- const books = Object.keys(hashCypher);
32238
- const hashes = Object.values(hashCypher);
32341
+ ref = ref.replace(/(\d)\s*(==\d+==)(?=\s*\d)/g, "$1; $2");
32239
32342
  ref = ref.replace(
32240
- new RegExp(hashes.join("|"), "g"),
32343
+ rules.hashRe,
32241
32344
  function(match) {
32242
32345
  const bookValue = books[hashes.indexOf(match)];
32243
32346
  return bookValue + " ";
@@ -32265,6 +32368,11 @@ var splitReferences = function(compoundReference, config) {
32265
32368
  let completeRefs = [];
32266
32369
  for (let i in refs) {
32267
32370
  const ref = refs[i];
32371
+ const multiBook = ref.match(/^(.*?\D)\s*\d[\d:,]*\s*[—-]\s*((?:\d\s*)?\D+?)\s*\d[\d:,]*$/);
32372
+ if (multiBook && bookExists(multiBook[1].trim(), config) && bookExists(multiBook[2].trim(), config)) {
32373
+ completeRefs.push(ref.trim());
32374
+ continue;
32375
+ }
32268
32376
  let pieces = ref.split(/([0-9:,-]+)$/);
32269
32377
  const firstPiece = pieces[0].trim();
32270
32378
  runningBook = bookExists(firstPiece, config) ? firstPiece : runningBook;
@@ -32367,11 +32475,11 @@ var getRanges = function(ref) {
32367
32475
  ;
32368
32476
  return ranges;
32369
32477
  };
32370
- var loadVerseIds = function(book, ranges, config) {
32478
+ var loadVerseIds = function(book, ranges, config, limit = MAX_RANGE_SIZE) {
32371
32479
  let refIndex = loadRefIndex(config);
32372
32480
  let verseList = [];
32373
32481
  for (let i in ranges) {
32374
- if (verseList.length >= MAX_RANGE_SIZE) break;
32482
+ if (verseList.length >= limit) break;
32375
32483
  let range = ranges[i];
32376
32484
  let matches = range.match(/(\d+): *([\dX]+)-*([\dX]*)/);
32377
32485
  if (!matches) continue;
@@ -32385,7 +32493,7 @@ var loadVerseIds = function(book, ranges, config) {
32385
32493
  start = Math.max(1, Math.min(start, MAX_VERSE));
32386
32494
  end = Math.max(start, Math.min(end, MAX_VERSE));
32387
32495
  for (let verse_num = start; verse_num <= end; verse_num++) {
32388
- if (verseList.length >= MAX_RANGE_SIZE) break;
32496
+ if (verseList.length >= limit) break;
32389
32497
  if (refIndex[book]?.[chapter]?.[verse_num]) {
32390
32498
  verseList.push(refIndex[book][chapter][verse_num]);
32391
32499
  }
@@ -32475,10 +32583,9 @@ var loadRefsFromRanges = function(ranges, config) {
32475
32583
  return refs;
32476
32584
  };
32477
32585
  var loadRefIndex = function(config) {
32478
- const configHash = hashConfig(config);
32479
- if (indexCache.refIndex && indexCache.refIndexHash === configHash) {
32480
- return indexCache.refIndex;
32481
- }
32586
+ return cachedIndex(refIndexCache, hashConfig(config), () => buildRefIndex(config));
32587
+ };
32588
+ var buildRefIndex = function(config) {
32482
32589
  let refIndex = {};
32483
32590
  let verse_id = 1;
32484
32591
  let book_list = Object.keys(config.raw_index);
@@ -32495,15 +32602,12 @@ var loadRefIndex = function(config) {
32495
32602
  }
32496
32603
  }
32497
32604
  }
32498
- indexCache.refIndex = refIndex;
32499
- indexCache.refIndexHash = configHash;
32500
32605
  return refIndex;
32501
32606
  };
32502
32607
  var loadVerseIdIndex = function(config) {
32503
- const configHash = hashConfig(config);
32504
- if (indexCache.verseIdIndex && indexCache.verseIdIndexHash === configHash) {
32505
- return indexCache.verseIdIndex;
32506
- }
32608
+ return cachedIndex(verseIdIndexCache, hashConfig(config), () => buildVerseIdIndex(config));
32609
+ };
32610
+ var buildVerseIdIndex = function(config) {
32507
32611
  let verseIdIndex = [null];
32508
32612
  let book_list = Object.keys(config.raw_index);
32509
32613
  for (let a in book_list) {
@@ -32516,8 +32620,6 @@ var loadVerseIdIndex = function(config) {
32516
32620
  }
32517
32621
  }
32518
32622
  }
32519
- indexCache.verseIdIndex = verseIdIndex;
32520
- indexCache.verseIdIndexHash = configHash;
32521
32623
  return verseIdIndex;
32522
32624
  };
32523
32625
  var bookExists = function(book, config) {
@@ -32547,7 +32649,7 @@ var restrictJoinersToStructural = (lang_extra) => {
32547
32649
  } else {
32548
32650
  joiners = [...STRUCTURAL_JOINERS];
32549
32651
  }
32550
- return { ...src, joiners };
32652
+ return { ...src, joiners, unrestrictedJoiners: src.joiners };
32551
32653
  };
32552
32654
  var detectReferences = (content, callBack, options = null) => {
32553
32655
  if (typeof options === "string" || options === null) {
@@ -32561,7 +32663,10 @@ var detectReferences = (content, callBack, options = null) => {
32561
32663
  maxContextDistance: 500,
32562
32664
  enableImpliedBooks: true,
32563
32665
  enableVerseAbbrev: true,
32564
- chainAcrossMarkers: true
32666
+ chainAcrossMarkers: true,
32667
+ // A bare "6:3" binds to an earlier book only when the token before it is
32668
+ // citation material. false restores pre-1.0.98 distance-only binding.
32669
+ strictImpliedBooks: true
32565
32670
  };
32566
32671
  const finalOptions = { ...defaultOptions, ...options };
32567
32672
  callBack = callBack ? callBack : (i) => {
@@ -32574,9 +32679,9 @@ var detectReferences = (content, callBack, options = null) => {
32574
32679
  const books = [...dst, ...src];
32575
32680
  const langExtra = finalOptions.chainAcrossMarkers === false ? restrictJoinersToStructural(config.lang_extra) : config.lang_extra;
32576
32681
  if (finalOptions.contextAware) {
32577
- return detectReferencesWithContext(content, books, langExtra, (query) => lookupReference(query, effectiveLanguage), callBack, finalOptions, generateReference);
32682
+ return detectReferencesWithContext(content, books, langExtra, detectionLookup(effectiveLanguage), callBack, finalOptions, generateReference);
32578
32683
  }
32579
- return processReferenceDetection(content, books, langExtra, (query) => lookupReference(query, effectiveLanguage), callBack);
32684
+ return processReferenceDetection(content, books, langExtra, detectionLookup(effectiveLanguage), callBack);
32580
32685
  };
32581
32686
  var findReferences = (content, options = null) => {
32582
32687
  if (typeof options === "string" || options === null) {
@@ -32591,7 +32696,10 @@ var findReferences = (content, options = null) => {
32591
32696
  enableVerseAbbrev: true,
32592
32697
  abbreviations: true,
32593
32698
  chapterOnly: true,
32594
- chainAcrossMarkers: true
32699
+ chainAcrossMarkers: true,
32700
+ // A bare "6:3" binds to an earlier book only when the token before it is
32701
+ // citation material. false restores pre-1.0.98 distance-only binding.
32702
+ strictImpliedBooks: true
32595
32703
  };
32596
32704
  const finalOptions = { ...defaultOptions, ...options };
32597
32705
  const effectiveLanguage = getEffectiveLanguage(finalOptions.language);
@@ -32599,7 +32707,7 @@ var findReferences = (content, options = null) => {
32599
32707
  const src = config.raw_regex.books.map((i) => i[0]);
32600
32708
  const dst = [...new Set(config.raw_regex.books.map((i) => i[1]))];
32601
32709
  const books = [...dst, ...src];
32602
- const lookup = (query) => lookupReference(query, effectiveLanguage);
32710
+ const lookup = detectionLookup(effectiveLanguage);
32603
32711
  const langExtra = finalOptions.chainAcrossMarkers === false ? restrictJoinersToStructural(config.lang_extra) : config.lang_extra;
32604
32712
  const found = finalOptions.contextAware ? collectReferencesWithContext(content, books, langExtra, lookup, finalOptions) : collectReferences(content, books, langExtra, lookup);
32605
32713
  let records = found.filter((m) => m.verse_ids.length > 0).map(({ start, end, text, verse_ids }) => ({
@@ -32690,9 +32798,15 @@ var applyDetectionFlags = (records, opts) => {
32690
32798
  }
32691
32799
  return out;
32692
32800
  };
32801
+ var languageConfigCache = /* @__PURE__ */ new Map();
32693
32802
  var getLanguageConfig = function(language, canon = null) {
32694
32803
  const effectiveLanguage = language && raw_lang[language] ? language : "en";
32695
32804
  const effectiveCanon = canon && extraCanons[canon] ? canon : DEFAULTS.canon;
32805
+ const key = `${effectiveLanguage}|${effectiveCanon}`;
32806
+ if (!languageConfigCache.has(key)) languageConfigCache.set(key, buildLanguageConfig(effectiveLanguage, effectiveCanon));
32807
+ return languageConfigCache.get(key);
32808
+ };
32809
+ var buildLanguageConfig = function(effectiveLanguage, effectiveCanon) {
32696
32810
  const config = {
32697
32811
  language: effectiveLanguage,
32698
32812
  canon: effectiveCanon,
@@ -32703,6 +32817,7 @@ var getLanguageConfig = function(language, canon = null) {
32703
32817
  };
32704
32818
  if (effectiveLanguage === "en" || !raw_lang[effectiveLanguage]) {
32705
32819
  config.lang_extra.joiners = config.raw_regex.joiners;
32820
+ config.lang_extra.capitalizedOnly = config.raw_regex.capitalized_only || [];
32706
32821
  return applyCanonOverride(config, effectiveCanon);
32707
32822
  }
32708
32823
  const langData2 = raw_lang[effectiveLanguage];
@@ -32763,6 +32878,7 @@ export {
32763
32878
  setCanon,
32764
32879
  setLanguage as setLang,
32765
32880
  setLanguage,
32881
+ toSlug,
32766
32882
  generateReference as verseId2Ref
32767
32883
  };
32768
32884
  //# sourceMappingURL=scriptures.mjs.map