@semiont/api-client 0.2.33-build.85 → 0.2.33

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 +1 @@
1
- export { ai as BoundingBox, F as FragmentSelector, ax as JWTTokenSchema, Z as LOCALES, Y as LocaleInfo, ah as Point, i as Selector, h as SvgSelector, V as TextPosition, T as TextPositionSelector, g as TextQuoteSelector, aq as ValidatedAnnotation, av as ValidationFailure, aw as ValidationResult, au as ValidationSuccess, al as createCircleSvg, ak as createPolygonSvg, aj as createRectangleSvg, ag as decodeRepresentation, at as decodeWithCharset, Q as extractBoundingBox, as as extractCharset, ap as extractContext, W as findTextWithContext, a2 as formatLocaleDisplay, a3 as getAllLocaleCodes, H as getAnnotationExactText, j as getBodySource, k as getBodyType, a7 as getChecksum, x as getCommentText, aa as getCreator, ab as getDerivedFrom, D as getExactText, O as getFragmentSelector, a8 as getLanguage, a1 as getLocaleEnglishName, _ as getLocaleInfo, a0 as getLocaleNativeName, af as getNodeEncoding, a6 as getPrimaryMediaType, a5 as getPrimaryRepresentation, I as getPrimarySelector, ad as getResourceEntityTypes, a4 as getResourceId, a9 as getStorageUri, N as getSvgSelector, n as getTargetSelector, m as getTargetSource, K as getTextPositionSelector, L as getTextQuoteSelector, q as hasTargetSelector, ac as isArchived, t as isAssessment, l as isBodyResolved, u as isComment, ae as isDraft, r as isHighlight, s as isReference, z as isResolvedReference, y as isStubReference, v as isTag, az as isValidEmail, an as normalizeCoordinates, am as parseSvgSelector, ao as scaleSvgToNative, ar as validateAndCorrectOffsets, ay as validateData, P as validateSvgMarkup, X as verifyPosition } from '../index-BT3m5lva.js';
1
+ export { al as BoundingBox, F as FragmentSelector, aA as JWTTokenSchema, a1 as LOCALES, a0 as LocaleInfo, W as MatchQuality, ak as Point, i as Selector, h as SvgSelector, V as TextPosition, T as TextPositionSelector, g as TextQuoteSelector, at as ValidatedAnnotation, ay as ValidationFailure, az as ValidationResult, ax as ValidationSuccess, ao as createCircleSvg, an as createPolygonSvg, am as createRectangleSvg, aj as decodeRepresentation, aw as decodeWithCharset, Q as extractBoundingBox, av as extractCharset, as as extractContext, Y as findBestTextMatch, Z as findTextWithContext, a5 as formatLocaleDisplay, a6 as getAllLocaleCodes, H as getAnnotationExactText, j as getBodySource, k as getBodyType, aa as getChecksum, x as getCommentText, ad as getCreator, ae as getDerivedFrom, D as getExactText, O as getFragmentSelector, ab as getLanguage, a4 as getLocaleEnglishName, a2 as getLocaleInfo, a3 as getLocaleNativeName, ai as getNodeEncoding, a9 as getPrimaryMediaType, a8 as getPrimaryRepresentation, I as getPrimarySelector, ag as getResourceEntityTypes, a7 as getResourceId, ac as getStorageUri, N as getSvgSelector, n as getTargetSelector, m as getTargetSource, K as getTextPositionSelector, L as getTextQuoteSelector, q as hasTargetSelector, af as isArchived, t as isAssessment, l as isBodyResolved, u as isComment, ah as isDraft, r as isHighlight, s as isReference, z as isResolvedReference, y as isStubReference, v as isTag, aC as isValidEmail, aq as normalizeCoordinates, X as normalizeText, ap as parseSvgSelector, ar as scaleSvgToNative, au as validateAndCorrectOffsets, aB as validateData, P as validateSvgMarkup, _ as verifyPosition } from '../index-CJqmerJr.js';
@@ -198,7 +198,94 @@ function extractBoundingBox(svg) {
198
198
  }
199
199
 
200
200
  // src/utils/fuzzy-anchor.ts
201
- function findTextWithContext(content, exact, prefix, suffix) {
201
+ function normalizeText(text) {
202
+ return text.replace(/\s+/g, " ").replace(/[\u2018\u2019]/g, "'").replace(/[\u201C\u201D]/g, '"').replace(/\u2014/g, "--").replace(/\u2013/g, "-").trim();
203
+ }
204
+ function levenshteinDistance(str1, str2) {
205
+ const len1 = str1.length;
206
+ const len2 = str2.length;
207
+ const matrix = [];
208
+ for (let i = 0; i <= len1; i++) {
209
+ matrix[i] = [i];
210
+ }
211
+ for (let j = 0; j <= len2; j++) {
212
+ matrix[0][j] = j;
213
+ }
214
+ for (let i = 1; i <= len1; i++) {
215
+ for (let j = 1; j <= len2; j++) {
216
+ const cost = str1[i - 1] === str2[j - 1] ? 0 : 1;
217
+ const deletion = matrix[i - 1][j] + 1;
218
+ const insertion = matrix[i][j - 1] + 1;
219
+ const substitution = matrix[i - 1][j - 1] + cost;
220
+ matrix[i][j] = Math.min(deletion, insertion, substitution);
221
+ }
222
+ }
223
+ return matrix[len1][len2];
224
+ }
225
+ function findBestTextMatch(content, searchText, positionHint) {
226
+ const maxFuzzyDistance = Math.max(5, Math.floor(searchText.length * 0.05));
227
+ const exactIndex = content.indexOf(searchText);
228
+ if (exactIndex !== -1) {
229
+ return {
230
+ start: exactIndex,
231
+ end: exactIndex + searchText.length,
232
+ matchQuality: "exact"
233
+ };
234
+ }
235
+ const normalizedSearch = normalizeText(searchText);
236
+ const normalizedContent = normalizeText(content);
237
+ const normalizedIndex = normalizedContent.indexOf(normalizedSearch);
238
+ if (normalizedIndex !== -1) {
239
+ let actualPos = 0;
240
+ let normalizedPos = 0;
241
+ while (normalizedPos < normalizedIndex && actualPos < content.length) {
242
+ const char = content[actualPos];
243
+ const normalizedChar = normalizeText(char);
244
+ if (normalizedChar) {
245
+ normalizedPos += normalizedChar.length;
246
+ }
247
+ actualPos++;
248
+ }
249
+ return {
250
+ start: actualPos,
251
+ end: actualPos + searchText.length,
252
+ matchQuality: "normalized"
253
+ };
254
+ }
255
+ const lowerContent = content.toLowerCase();
256
+ const lowerSearch = searchText.toLowerCase();
257
+ const caseInsensitiveIndex = lowerContent.indexOf(lowerSearch);
258
+ if (caseInsensitiveIndex !== -1) {
259
+ return {
260
+ start: caseInsensitiveIndex,
261
+ end: caseInsensitiveIndex + searchText.length,
262
+ matchQuality: "case-insensitive"
263
+ };
264
+ }
265
+ const windowSize = searchText.length;
266
+ const searchRadius = Math.min(500, content.length);
267
+ const searchStart = positionHint !== void 0 ? Math.max(0, positionHint - searchRadius) : 0;
268
+ const searchEnd = positionHint !== void 0 ? Math.min(content.length, positionHint + searchRadius) : content.length;
269
+ let bestMatch = null;
270
+ for (let i = searchStart; i <= searchEnd - windowSize; i++) {
271
+ const candidate = content.substring(i, i + windowSize);
272
+ const distance = levenshteinDistance(searchText, candidate);
273
+ if (distance <= maxFuzzyDistance) {
274
+ if (!bestMatch || distance < bestMatch.distance) {
275
+ bestMatch = { start: i, distance };
276
+ }
277
+ }
278
+ }
279
+ if (bestMatch) {
280
+ return {
281
+ start: bestMatch.start,
282
+ end: bestMatch.start + windowSize,
283
+ matchQuality: "fuzzy"
284
+ };
285
+ }
286
+ return null;
287
+ }
288
+ function findTextWithContext(content, exact, prefix, suffix, positionHint) {
202
289
  if (!exact) return null;
203
290
  const occurrences = [];
204
291
  let index = content.indexOf(exact);
@@ -207,7 +294,15 @@ function findTextWithContext(content, exact, prefix, suffix) {
207
294
  index = content.indexOf(exact, index + 1);
208
295
  }
209
296
  if (occurrences.length === 0) {
210
- console.warn(`[FuzzyAnchor] Text not found: "${exact.substring(0, 50)}..."`);
297
+ console.warn(`[FuzzyAnchor] Exact text not found, trying fuzzy match: "${exact.substring(0, 50)}..."`);
298
+ const fuzzyMatch = findBestTextMatch(content, exact, positionHint);
299
+ if (fuzzyMatch) {
300
+ console.warn(
301
+ `[FuzzyAnchor] Found ${fuzzyMatch.matchQuality} match at position ${fuzzyMatch.start}`
302
+ );
303
+ return { start: fuzzyMatch.start, end: fuzzyMatch.end };
304
+ }
305
+ console.warn(`[FuzzyAnchor] No acceptable match found for: "${exact.substring(0, 50)}..."`);
211
306
  return null;
212
307
  }
213
308
  if (occurrences.length === 1) {
@@ -235,7 +330,7 @@ function findTextWithContext(content, exact, prefix, suffix) {
235
330
  const fuzzyPrefixMatch = !prefix || actualPrefix.includes(prefix.trim());
236
331
  const fuzzySuffixMatch = !suffix || actualSuffix.includes(suffix.trim());
237
332
  if (fuzzyPrefixMatch && fuzzySuffixMatch) {
238
- console.warn(`[FuzzyAnchor] Using fuzzy match at position ${pos2}`);
333
+ console.warn(`[FuzzyAnchor] Using fuzzy context match at position ${pos2}`);
239
334
  return { start: pos2, end: pos2 + exact.length };
240
335
  }
241
336
  }
@@ -505,75 +600,6 @@ function extractContext(content, start, end) {
505
600
  }
506
601
  return { prefix, suffix };
507
602
  }
508
- function levenshteinDistance(str1, str2) {
509
- const len1 = str1.length;
510
- const len2 = str2.length;
511
- const matrix = [];
512
- for (let i = 0; i <= len1; i++) {
513
- matrix[i] = [i];
514
- }
515
- for (let j = 0; j <= len2; j++) {
516
- matrix[0][j] = j;
517
- }
518
- for (let i = 1; i <= len1; i++) {
519
- for (let j = 1; j <= len2; j++) {
520
- const cost = str1[i - 1] === str2[j - 1] ? 0 : 1;
521
- const deletion = matrix[i - 1][j] + 1;
522
- const insertion = matrix[i][j - 1] + 1;
523
- const substitution = matrix[i - 1][j - 1] + cost;
524
- matrix[i][j] = Math.min(deletion, insertion, substitution);
525
- }
526
- }
527
- return matrix[len1][len2];
528
- }
529
- function findBestMatch(content, searchText, aiStart, aiEnd) {
530
- const maxFuzzyDistance = Math.max(5, Math.floor(searchText.length * 0.05));
531
- const exactIndex = content.indexOf(searchText);
532
- if (exactIndex !== -1) {
533
- return {
534
- start: exactIndex,
535
- end: exactIndex + searchText.length,
536
- matchQuality: "exact"
537
- };
538
- }
539
- console.log("[findBestMatch] Exact match failed, trying case-insensitive...");
540
- const lowerContent = content.toLowerCase();
541
- const lowerSearch = searchText.toLowerCase();
542
- const caseInsensitiveIndex = lowerContent.indexOf(lowerSearch);
543
- if (caseInsensitiveIndex !== -1) {
544
- console.log("[findBestMatch] Found case-insensitive match");
545
- return {
546
- start: caseInsensitiveIndex,
547
- end: caseInsensitiveIndex + searchText.length,
548
- matchQuality: "case-insensitive"
549
- };
550
- }
551
- console.log("[findBestMatch] Case-insensitive failed, trying fuzzy match...");
552
- const windowSize = searchText.length;
553
- const searchRadius = Math.min(500, content.length);
554
- const searchStart = Math.max(0, aiStart - searchRadius);
555
- const searchEnd = Math.min(content.length, aiEnd + searchRadius);
556
- let bestMatch = null;
557
- for (let i = searchStart; i <= searchEnd - windowSize; i++) {
558
- const candidate = content.substring(i, i + windowSize);
559
- const distance = levenshteinDistance(searchText, candidate);
560
- if (distance <= maxFuzzyDistance) {
561
- if (!bestMatch || distance < bestMatch.distance) {
562
- bestMatch = { start: i, distance };
563
- console.log(`[findBestMatch] Found fuzzy match at ${i} with distance ${distance}`);
564
- }
565
- }
566
- }
567
- if (bestMatch) {
568
- return {
569
- start: bestMatch.start,
570
- end: bestMatch.start + windowSize,
571
- matchQuality: "fuzzy"
572
- };
573
- }
574
- console.log("[findBestMatch] No acceptable match found");
575
- return null;
576
- }
577
603
  function validateAndCorrectOffsets(content, aiStart, aiEnd, exact) {
578
604
  const exactPreview = exact.length > 50 ? exact.substring(0, 50) + "..." : exact;
579
605
  const textAtOffset = content.substring(aiStart, aiEnd);
@@ -597,7 +623,7 @@ function validateAndCorrectOffsets(content, aiStart, aiEnd, exact) {
597
623
  Found at AI offset (${aiStart}-${aiEnd}): "${foundPreview}"
598
624
  Attempting multi-strategy search...`
599
625
  );
600
- const match = findBestMatch(content, exact, aiStart, aiEnd);
626
+ const match = findBestTextMatch(content, exact, aiStart);
601
627
  if (!match) {
602
628
  const exactLong = exact.length > 100 ? exact.substring(0, 100) + "..." : exact;
603
629
  console.error(
@@ -702,6 +728,6 @@ function isValidEmail(email) {
702
728
  return emailRegex.test(email);
703
729
  }
704
730
 
705
- export { JWTTokenSchema, LOCALES, createCircleSvg, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, extractBoundingBox, extractCharset, extractContext, findTextWithContext, formatLocaleDisplay, getAllLocaleCodes, getAnnotationExactText, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getNodeEncoding, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isArchived, isAssessment, isBodyResolved, isComment, isDraft, isHighlight, isReference, isResolvedReference, isStubReference, isTag, isValidEmail, normalizeCoordinates, parseSvgSelector, scaleSvgToNative, validateAndCorrectOffsets, validateData, validateSvgMarkup, verifyPosition };
731
+ export { JWTTokenSchema, LOCALES, createCircleSvg, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findTextWithContext, formatLocaleDisplay, getAllLocaleCodes, getAnnotationExactText, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getNodeEncoding, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isArchived, isAssessment, isBodyResolved, isComment, isDraft, isHighlight, isReference, isResolvedReference, isStubReference, isTag, isValidEmail, normalizeCoordinates, normalizeText, parseSvgSelector, scaleSvgToNative, validateAndCorrectOffsets, validateData, validateSvgMarkup, verifyPosition };
706
732
  //# sourceMappingURL=index.js.map
707
733
  //# sourceMappingURL=index.js.map