@flighthq/textsegment 0.5.1-next.1069.554a2ac → 0.5.1-next.1197.6a425ce
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.
- package/README.md +2 -2
- package/dist/enableTextSegmentGuards.js +1 -1
- package/dist/enableTextSegmentGuards.js.map +1 -1
- package/dist/textSegment.d.ts +4 -4
- package/dist/textSegment.d.ts.map +1 -1
- package/dist/textSegment.js +6 -6
- package/dist/textSegment.js.map +1 -1
- package/dist/textSegmentBoundary.d.ts +8 -8
- package/dist/textSegmentBoundary.d.ts.map +1 -1
- package/dist/textSegmentBoundary.js +18 -18
- package/dist/textSegmentBoundary.js.map +1 -1
- package/dist/textSegmenterBackend.d.ts +9 -9
- package/dist/textSegmenterBackend.d.ts.map +1 -1
- package/dist/textSegmenterBackend.js +6 -6
- package/dist/textSegmenterBackend.js.map +1 -1
- package/package.json +4 -4
- package/src/textSegment.test.ts +14 -15
- package/src/textSegmentBoundary.test.ts +8 -6
- package/src/textSegmenterBackend.test.ts +10 -11
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/textsegment`. The `@
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/textsegment@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/textsegment@0.5.1-next.1197.6a425ce](https://github.com/flighthq/flight/tree/6a425ce64e6d501dac8218fe625e73d58da88639/packages/textsegment)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/6a425ce64e6d501dac8218fe625e73d58da88639/LICENSE.md)
|
|
@@ -11,7 +11,7 @@ export function enableTextSegmentGuards() {
|
|
|
11
11
|
}
|
|
12
12
|
function warnOnMissingIntlSegmenter() {
|
|
13
13
|
logOnce('textsegment:intl-segmenter-unavailable', LogLevel.Warn, {
|
|
14
|
-
message: 'segmentGraphemes: Intl.Segmenter is unavailable and no replacement provider was supplied, so segmentation returned no results. Install a backend with setTextSegmenterBackend(backend), or pass a
|
|
14
|
+
message: 'segmentGraphemes: Intl.Segmenter is unavailable and no replacement provider was supplied, so segmentation returned no results. Install a backend with setTextSegmenterBackend(backend), or pass a HostTextSegmenterProvider directly to the operation.',
|
|
15
15
|
}, 'textsegment');
|
|
16
16
|
}
|
|
17
17
|
//# sourceMappingURL=enableTextSegmentGuards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableTextSegmentGuards.js","sourceRoot":"","sources":["../src/enableTextSegmentGuards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,iEAAiE;AACjE,MAAM,UAAU,wBAAwB;IACtC,mBAAmB,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,uBAAuB;IACrC,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,0BAA0B;IACjC,OAAO,CACL,wCAAwC,EACxC,QAAQ,CAAC,IAAI,EACb;QACE,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"enableTextSegmentGuards.js","sourceRoot":"","sources":["../src/enableTextSegmentGuards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,iEAAiE;AACjE,MAAM,UAAU,wBAAwB;IACtC,mBAAmB,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,uBAAuB;IACrC,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,0BAA0B;IACjC,OAAO,CACL,wCAAwC,EACxC,QAAQ,CAAC,IAAI,EACb;QACE,OAAO,EACL,wPAAwP;KAC3P,EACD,aAAa,CACd,CAAC;AACJ,CAAC"}
|
package/dist/textSegment.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function segmentGraphemes(text: string, locale?: string,
|
|
3
|
-
export declare function segmentSentences(text: string, locale?: string,
|
|
4
|
-
export declare function segmentWords(text: string, locale?: string,
|
|
1
|
+
import type { HostTextSegmenterProvider, TextSegment } from '@flighthq/types/contract';
|
|
2
|
+
export declare function segmentGraphemes(text: string, locale?: string, hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): readonly TextSegment[];
|
|
3
|
+
export declare function segmentSentences(text: string, locale?: string, hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): readonly TextSegment[];
|
|
4
|
+
export declare function segmentWords(text: string, locale?: string, hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): readonly TextSegment[];
|
|
5
5
|
//# sourceMappingURL=textSegment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textSegment.d.ts","sourceRoot":"","sources":["../src/textSegment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"textSegment.d.ts","sourceRoot":"","sources":["../src/textSegment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAQvF,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,EACf,iBAAiB,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GACtD,SAAS,WAAW,EAAE,CAExB;AAID,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,EACf,iBAAiB,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GACtD,SAAS,WAAW,EAAE,CAExB;AAKD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,EACf,iBAAiB,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GACtD,SAAS,WAAW,EAAE,CAExB"}
|
package/dist/textSegment.js
CHANGED
|
@@ -3,18 +3,18 @@ import { getTextSegmenterBackend } from './textSegmenterBackend';
|
|
|
3
3
|
// user-perceived character: an emoji ZWJ sequence or a base-plus-combining-mark cluster is a single
|
|
4
4
|
// segment, not its constituent code points. `locale` is threaded to the backend for the rare
|
|
5
5
|
// locale-tailored cases. isWordLike is absent on grapheme segments.
|
|
6
|
-
export function segmentGraphemes(text, locale,
|
|
7
|
-
return getTextSegmenterBackend(
|
|
6
|
+
export function segmentGraphemes(text, locale, hostTextSegmenter) {
|
|
7
|
+
return getTextSegmenterBackend(hostTextSegmenter).segment(text, 'grapheme', locale);
|
|
8
8
|
}
|
|
9
9
|
// Enumerates the sentences of `text` (UAX #29) via the active backend, in order and covering the
|
|
10
10
|
// whole string. isWordLike is absent on sentence segments.
|
|
11
|
-
export function segmentSentences(text, locale,
|
|
12
|
-
return getTextSegmenterBackend(
|
|
11
|
+
export function segmentSentences(text, locale, hostTextSegmenter) {
|
|
12
|
+
return getTextSegmenterBackend(hostTextSegmenter).segment(text, 'sentence', locale);
|
|
13
13
|
}
|
|
14
14
|
// Enumerates the words of `text` (UAX #29) via the active backend. Word segments carry isWordLike:
|
|
15
15
|
// true for letters/numbers (a real word), false for the punctuation and whitespace runs between
|
|
16
16
|
// them. Filter on isWordLike to keep only words. `locale` is threaded to the backend.
|
|
17
|
-
export function segmentWords(text, locale,
|
|
18
|
-
return getTextSegmenterBackend(
|
|
17
|
+
export function segmentWords(text, locale, hostTextSegmenter) {
|
|
18
|
+
return getTextSegmenterBackend(hostTextSegmenter).segment(text, 'word', locale);
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=textSegment.js.map
|
package/dist/textSegment.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textSegment.js","sourceRoot":"","sources":["../src/textSegment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,mGAAmG;AACnG,oGAAoG;AACpG,6FAA6F;AAC7F,oEAAoE;AACpE,MAAM,UAAU,gBAAgB,
|
|
1
|
+
{"version":3,"file":"textSegment.js","sourceRoot":"","sources":["../src/textSegment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,mGAAmG;AACnG,oGAAoG;AACpG,6FAA6F;AAC7F,oEAAoE;AACpE,MAAM,UAAU,gBAAgB,CAC9B,IAAY,EACZ,MAAe,EACf,iBAAuD;IAEvD,OAAO,uBAAuB,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AACtF,CAAC;AAED,iGAAiG;AACjG,2DAA2D;AAC3D,MAAM,UAAU,gBAAgB,CAC9B,IAAY,EACZ,MAAe,EACf,iBAAuD;IAEvD,OAAO,uBAAuB,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AACtF,CAAC;AAED,mGAAmG;AACnG,gGAAgG;AAChG,sFAAsF;AACtF,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,MAAe,EACf,iBAAuD;IAEvD,OAAO,uBAAuB,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAClF,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function getNextGraphemeBoundary(text: string, index: number, locale?: string,
|
|
3
|
-
export declare function getNextSentenceBoundary(text: string, index: number, locale?: string,
|
|
4
|
-
export declare function getNextWordBoundary(text: string, index: number, locale?: string,
|
|
5
|
-
export declare function getPreviousGraphemeBoundary(text: string, index: number, locale?: string,
|
|
6
|
-
export declare function getPreviousSentenceBoundary(text: string, index: number, locale?: string,
|
|
7
|
-
export declare function getPreviousWordBoundary(text: string, index: number, locale?: string,
|
|
8
|
-
export declare function getWordRangeAt(text: string, index: number, locale?: string,
|
|
1
|
+
import type { HostTextSegmenterProvider, TextSegmentRange } from '@flighthq/types/contract';
|
|
2
|
+
export declare function getNextGraphemeBoundary(text: string, index: number, locale?: string, hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): number;
|
|
3
|
+
export declare function getNextSentenceBoundary(text: string, index: number, locale?: string, hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): number;
|
|
4
|
+
export declare function getNextWordBoundary(text: string, index: number, locale?: string, hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): number;
|
|
5
|
+
export declare function getPreviousGraphemeBoundary(text: string, index: number, locale?: string, hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): number;
|
|
6
|
+
export declare function getPreviousSentenceBoundary(text: string, index: number, locale?: string, hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): number;
|
|
7
|
+
export declare function getPreviousWordBoundary(text: string, index: number, locale?: string, hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): number;
|
|
8
|
+
export declare function getWordRangeAt(text: string, index: number, locale?: string, hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): TextSegmentRange | null;
|
|
9
9
|
//# sourceMappingURL=textSegmentBoundary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textSegmentBoundary.d.ts","sourceRoot":"","sources":["../src/textSegmentBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"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b,MAAM,CAAC,EAAE,MAAM,EACf,iBAAiB,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GACtD,gBAAgB,GAAG,IAAI,CAyBzB"}
|
|
@@ -3,48 +3,48 @@ import { reportTextSegmenterUnavailable } from './textSegmentGuards';
|
|
|
3
3
|
// Returns the next grapheme-cluster boundary at or after `index` — the offset a caret lands on when
|
|
4
4
|
// stepping right by one user-perceived character, so an emoji or combining sequence is crossed in a
|
|
5
5
|
// single step. `index` is clamped into [0, text.length]; at or past the end it returns text.length.
|
|
6
|
-
export function getNextGraphemeBoundary(text, index, locale,
|
|
7
|
-
return getNextTextSegmentBoundary(text, index, 'grapheme', locale,
|
|
6
|
+
export function getNextGraphemeBoundary(text, index, locale, hostTextSegmenter) {
|
|
7
|
+
return getNextTextSegmentBoundary(text, index, 'grapheme', locale, hostTextSegmenter);
|
|
8
8
|
}
|
|
9
9
|
// Returns the next sentence boundary at or after `index`. The bundled Intl path stops its iterator as
|
|
10
10
|
// soon as the answer is known and does not materialize the sentence strings or a segment array.
|
|
11
|
-
export function getNextSentenceBoundary(text, index, locale,
|
|
12
|
-
return getNextTextSegmentBoundary(text, index, 'sentence', locale,
|
|
11
|
+
export function getNextSentenceBoundary(text, index, locale, hostTextSegmenter) {
|
|
12
|
+
return getNextTextSegmentBoundary(text, index, 'sentence', locale, hostTextSegmenter);
|
|
13
13
|
}
|
|
14
14
|
// Returns the next word boundary at or after `index` — the offset a caret lands on when jumping right
|
|
15
15
|
// by one word (Ctrl/Alt-Right). `index` is clamped into [0, text.length]; at or past the end it
|
|
16
16
|
// returns text.length.
|
|
17
|
-
export function getNextWordBoundary(text, index, locale,
|
|
18
|
-
return getNextTextSegmentBoundary(text, index, 'word', locale,
|
|
17
|
+
export function getNextWordBoundary(text, index, locale, hostTextSegmenter) {
|
|
18
|
+
return getNextTextSegmentBoundary(text, index, 'word', locale, hostTextSegmenter);
|
|
19
19
|
}
|
|
20
20
|
// Returns the previous grapheme-cluster boundary at or before `index` — the offset a caret lands on
|
|
21
21
|
// when stepping left by one user-perceived character. `index` is clamped into [0, text.length]; at or
|
|
22
22
|
// before the start it returns 0.
|
|
23
|
-
export function getPreviousGraphemeBoundary(text, index, locale,
|
|
24
|
-
return getPreviousTextSegmentBoundary(text, index, 'grapheme', locale,
|
|
23
|
+
export function getPreviousGraphemeBoundary(text, index, locale, hostTextSegmenter) {
|
|
24
|
+
return getPreviousTextSegmentBoundary(text, index, 'grapheme', locale, hostTextSegmenter);
|
|
25
25
|
}
|
|
26
26
|
// Returns the previous sentence boundary at or before `index`. The bundled Intl path walks offsets
|
|
27
27
|
// directly and avoids building TextSegment records; custom backends retain their existing array seam.
|
|
28
|
-
export function getPreviousSentenceBoundary(text, index, locale,
|
|
29
|
-
return getPreviousTextSegmentBoundary(text, index, 'sentence', locale,
|
|
28
|
+
export function getPreviousSentenceBoundary(text, index, locale, hostTextSegmenter) {
|
|
29
|
+
return getPreviousTextSegmentBoundary(text, index, 'sentence', locale, hostTextSegmenter);
|
|
30
30
|
}
|
|
31
31
|
// Returns the previous word boundary at or before `index` — the offset a caret lands on when jumping
|
|
32
32
|
// left by one word. `index` is clamped into [0, text.length]; at or before the start it returns 0.
|
|
33
|
-
export function getPreviousWordBoundary(text, index, locale,
|
|
34
|
-
return getPreviousTextSegmentBoundary(text, index, 'word', locale,
|
|
33
|
+
export function getPreviousWordBoundary(text, index, locale, hostTextSegmenter) {
|
|
34
|
+
return getPreviousTextSegmentBoundary(text, index, 'word', locale, hostTextSegmenter);
|
|
35
35
|
}
|
|
36
36
|
// Returns the word-like segment's range covering `index`, for double-click / word-select. `index` is
|
|
37
37
|
// clamped into [0, text.length]; at the very end it resolves against the last character. Returns null
|
|
38
38
|
// when the covered segment is not word-like (whitespace or punctuation) or the text is empty — the
|
|
39
39
|
// caller should then select nothing, mirroring how a double-click on a space selects no word.
|
|
40
|
-
export function getWordRangeAt(text, index, locale,
|
|
40
|
+
export function getWordRangeAt(text, index, locale, hostTextSegmenter) {
|
|
41
41
|
if (text.length === 0)
|
|
42
42
|
return null;
|
|
43
43
|
const clamped = clampIndex(index, text.length);
|
|
44
44
|
// At the trailing boundary there is no segment starting at text.length; resolve against the last
|
|
45
45
|
// character so a double-click at the end still selects the final word.
|
|
46
46
|
const lookup = clamped === text.length ? text.length - 1 : clamped;
|
|
47
|
-
const backend = getTextSegmenterBackend(
|
|
47
|
+
const backend = getTextSegmenterBackend(hostTextSegmenter);
|
|
48
48
|
if (backend === webTextSegmenterBackend) {
|
|
49
49
|
const segmenter = getBoundarySegmenter(locale, 'word');
|
|
50
50
|
if (segmenter === null)
|
|
@@ -83,11 +83,11 @@ function getBoundarySegmenter(locale, granularity) {
|
|
|
83
83
|
boundarySegmenterCache.set(key, segmenter);
|
|
84
84
|
return segmenter;
|
|
85
85
|
}
|
|
86
|
-
function getNextTextSegmentBoundary(text, index, granularity, locale,
|
|
86
|
+
function getNextTextSegmentBoundary(text, index, granularity, locale, hostTextSegmenter) {
|
|
87
87
|
const from = clampIndex(index, text.length);
|
|
88
88
|
if (from >= text.length)
|
|
89
89
|
return text.length;
|
|
90
|
-
const backend = getTextSegmenterBackend(
|
|
90
|
+
const backend = getTextSegmenterBackend(hostTextSegmenter);
|
|
91
91
|
if (backend !== webTextSegmenterBackend) {
|
|
92
92
|
return nextSegmentBoundary(backend.segment(text, granularity, locale), from, text.length);
|
|
93
93
|
}
|
|
@@ -100,11 +100,11 @@ function getNextTextSegmentBoundary(text, index, granularity, locale, host) {
|
|
|
100
100
|
}
|
|
101
101
|
return text.length;
|
|
102
102
|
}
|
|
103
|
-
function getPreviousTextSegmentBoundary(text, index, granularity, locale,
|
|
103
|
+
function getPreviousTextSegmentBoundary(text, index, granularity, locale, hostTextSegmenter) {
|
|
104
104
|
const from = clampIndex(index, text.length);
|
|
105
105
|
if (from <= 0)
|
|
106
106
|
return 0;
|
|
107
|
-
const backend = getTextSegmenterBackend(
|
|
107
|
+
const backend = getTextSegmenterBackend(hostTextSegmenter);
|
|
108
108
|
if (backend !== webTextSegmenterBackend)
|
|
109
109
|
return previousSegmentBoundary(backend.segment(text, granularity, locale), from);
|
|
110
110
|
const segmenter = getBoundarySegmenter(locale, granularity);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textSegmentBoundary.js","sourceRoot":"","sources":["../src/textSegmentBoundary.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"textSegmentBoundary.js","sourceRoot":"","sources":["../src/textSegmentBoundary.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAC1F,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAErE,oGAAoG;AACpG,oGAAoG;AACpG,oGAAoG;AACpG,MAAM,UAAU,uBAAuB,CACrC,IAAY,EACZ,KAAa,EACb,MAAe,EACf,iBAAuD;IAEvD,OAAO,0BAA0B,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACxF,CAAC;AAED,sGAAsG;AACtG,gGAAgG;AAChG,MAAM,UAAU,uBAAuB,CACrC,IAAY,EACZ,KAAa,EACb,MAAe,EACf,iBAAuD;IAEvD,OAAO,0BAA0B,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACxF,CAAC;AAED,sGAAsG;AACtG,gGAAgG;AAChG,uBAAuB;AACvB,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,KAAa,EACb,MAAe,EACf,iBAAuD;IAEvD,OAAO,0BAA0B,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACpF,CAAC;AAED,oGAAoG;AACpG,sGAAsG;AACtG,iCAAiC;AACjC,MAAM,UAAU,2BAA2B,CACzC,IAAY,EACZ,KAAa,EACb,MAAe,EACf,iBAAuD;IAEvD,OAAO,8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AAI,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAClC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,CAAC,KAAK,GAAG,IAAI;YAAE,OAAO,OAAO,CAAC,KAAK,CAAC;IACjD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,uBAAuB,CAAC,QAAgC,EAAE,KAAa;IAC9E,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAC7E,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,IAAI,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IACxB,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,CAAC,KAAK,IAAI,IAAI;YAAE,MAAM;QACjC,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC;IAC3B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAA0B,CAAC;AACjE,MAAM,iCAAiC,GAAG,EAAE,CAAC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { EntityConstruction,
|
|
2
|
-
export declare function createWebTextSegmenterBackend():
|
|
3
|
-
export declare const webTextSegmenterBackend:
|
|
1
|
+
import type { EntityConstruction, HostTextSegmenterProvider, TextSegmenterBackendExplanation } from '@flighthq/types/contract';
|
|
2
|
+
export declare function createWebTextSegmenterBackend(): HostTextSegmenterProvider;
|
|
3
|
+
export declare const webTextSegmenterBackend: HostTextSegmenterProvider;
|
|
4
4
|
/** Describes which provider an operation would use and whether Intl.Segmenter is present. */
|
|
5
|
-
export declare function explainTextSegmenterBackend(
|
|
6
|
-
export declare function getTextSegmenterBackend(
|
|
7
|
-
export declare function initializeWebTextSegmenterBackend(out: EntityConstruction<
|
|
5
|
+
export declare function explainTextSegmenterBackend(hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): TextSegmenterBackendExplanation;
|
|
6
|
+
export declare function getTextSegmenterBackend(hostTextSegmenter?: Readonly<HostTextSegmenterProvider>): HostTextSegmenterProvider;
|
|
7
|
+
export declare function initializeWebTextSegmenterBackend(out: EntityConstruction<HostTextSegmenterProvider>): void;
|
|
8
8
|
/**
|
|
9
9
|
* Installs the backend used by calls that omit an explicit host; pass null to restore the stable
|
|
10
10
|
* bundled web default.
|
|
11
11
|
*
|
|
12
|
-
* @deprecated Pass a
|
|
13
|
-
* source compatibility until the legacy global path is removed.
|
|
12
|
+
* @deprecated Pass a HostTextSegmenterProvider to the segmentation or boundary operation. Retained
|
|
13
|
+
* for source compatibility until the legacy global path is removed.
|
|
14
14
|
*/
|
|
15
|
-
export declare function setTextSegmenterBackend(backend:
|
|
15
|
+
export declare function setTextSegmenterBackend(backend: HostTextSegmenterProvider | null): void;
|
|
16
16
|
//# sourceMappingURL=textSegmenterBackend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textSegmenterBackend.d.ts","sourceRoot":"","sources":["../src/textSegmenterBackend.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"textSegmenterBackend.d.ts","sourceRoot":"","sources":["../src/textSegmenterBackend.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EAGzB,+BAA+B,EAChC,MAAM,0BAA0B,CAAC;AAUlC,wBAAgB,6BAA6B,IAAI,yBAAyB,CAIzE;AAID,eAAO,MAAM,uBAAuB,EAAE,yBAA2D,CAAC;AAElG,6FAA6F;AAC7F,wBAAgB,2BAA2B,CACzC,iBAAiB,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GACtD,+BAA+B,CASjC;AAKD,wBAAgB,uBAAuB,CACrC,iBAAiB,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GACtD,yBAAyB,CAE3B;AAED,wBAAgB,iCAAiC,CAAC,GAAG,EAAE,kBAAkB,CAAC,yBAAyB,CAAC,GAAG,IAAI,CAE1G;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,yBAAyB,GAAG,IAAI,GAAG,IAAI,CAEvF"}
|
|
@@ -15,8 +15,8 @@ export function createWebTextSegmenterBackend() {
|
|
|
15
15
|
// capability object; callers that omit a host receive it as the final fallback.
|
|
16
16
|
export const webTextSegmenterBackend = createWebTextSegmenterBackend();
|
|
17
17
|
/** Describes which provider an operation would use and whether Intl.Segmenter is present. */
|
|
18
|
-
export function explainTextSegmenterBackend(
|
|
19
|
-
const backend = getTextSegmenterBackend(
|
|
18
|
+
export function explainTextSegmenterBackend(hostTextSegmenter) {
|
|
19
|
+
const backend = getTextSegmenterBackend(hostTextSegmenter);
|
|
20
20
|
const web = backend === webTextSegmenterBackend;
|
|
21
21
|
const intlSegmenterAvailable = hasIntlSegmenter();
|
|
22
22
|
return {
|
|
@@ -28,8 +28,8 @@ export function explainTextSegmenterBackend(host) {
|
|
|
28
28
|
// Returns the explicit host's provider when supplied, then the legacy installed backend, and
|
|
29
29
|
// finally the bundled web provider. The explicit dependency always wins, so independent callers
|
|
30
30
|
// can interleave different hosts without mutating shared capability state.
|
|
31
|
-
export function getTextSegmenterBackend(
|
|
32
|
-
return
|
|
31
|
+
export function getTextSegmenterBackend(hostTextSegmenter) {
|
|
32
|
+
return hostTextSegmenter ?? _backend ?? webTextSegmenterBackend;
|
|
33
33
|
}
|
|
34
34
|
export function initializeWebTextSegmenterBackend(out) {
|
|
35
35
|
out.segment = segmentWithIntlSegmenter;
|
|
@@ -38,8 +38,8 @@ export function initializeWebTextSegmenterBackend(out) {
|
|
|
38
38
|
* Installs the backend used by calls that omit an explicit host; pass null to restore the stable
|
|
39
39
|
* bundled web default.
|
|
40
40
|
*
|
|
41
|
-
* @deprecated Pass a
|
|
42
|
-
* source compatibility until the legacy global path is removed.
|
|
41
|
+
* @deprecated Pass a HostTextSegmenterProvider to the segmentation or boundary operation. Retained
|
|
42
|
+
* for source compatibility until the legacy global path is removed.
|
|
43
43
|
*/
|
|
44
44
|
export function setTextSegmenterBackend(backend) {
|
|
45
45
|
_backend = backend;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textSegmenterBackend.js","sourceRoot":"","sources":["../src/textSegmenterBackend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"textSegmenterBackend.js","sourceRoot":"","sources":["../src/textSegmenterBackend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AASzE,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAErE,gGAAgG;AAChG,gGAAgG;AAChG,mGAAmG;AACnG,oGAAoG;AACpG,kGAAkG;AAClG,mCAAmC;AACnC,MAAM,UAAU,6BAA6B;IAC3C,MAAM,GAAG,GAAG,cAAc,EAA6B,CAAC;IACxD,iCAAiC,CAAC,GAAG,CAAC,CAAC;IACvC,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,4FAA4F;AAC5F,gFAAgF;AAChF,MAAM,CAAC,MAAM,uBAAuB,GAA8B,6BAA6B,EAAE,CAAC;AAElG,6FAA6F;AAC7F,MAAM,UAAU,2BAA2B,CACzC,iBAAuD;IAEvD,MAAM,OAAO,GAAG,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAG,OAAO,KAAK,uBAAuB,CAAC;IAChD,MAAM,sBAAsB,GAAG,gBAAgB,EAAE,CAAC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1197.6a425ce",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.5.1-next.
|
|
42
|
-
"@flighthq/log": "0.5.1-next.
|
|
43
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/entity": "0.5.1-next.1197.6a425ce",
|
|
42
|
+
"@flighthq/log": "0.5.1-next.1197.6a425ce",
|
|
43
|
+
"@flighthq/types": "0.5.1-next.1197.6a425ce"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^5.3.0"
|
package/src/textSegment.test.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import type { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
3
|
-
import type {
|
|
4
|
-
HasTextSegmenter,
|
|
5
|
-
TextSegment,
|
|
6
|
-
TextSegmentGranularity,
|
|
7
|
-
TextSegmenterBackend,
|
|
8
|
-
} from '@flighthq/types/contract';
|
|
3
|
+
import type { HostTextSegmenterProvider, TextSegment, TextSegmentGranularity } from '@flighthq/types/contract';
|
|
9
4
|
|
|
10
5
|
import { segmentGraphemes, segmentSentences, segmentWords } from './textSegment';
|
|
11
6
|
import { setTextSegmenterBackend } from './textSegmenterBackend';
|
|
@@ -15,21 +10,23 @@ afterEach(() => setTextSegmenterBackend(null));
|
|
|
15
10
|
describe('segmentGraphemes', () => {
|
|
16
11
|
it('accepts an optional explicit segmenter host without breaking the existing signature', () => {
|
|
17
12
|
expectTypeOf(segmentGraphemes).toEqualTypeOf<
|
|
18
|
-
(text: string, locale?: string,
|
|
13
|
+
(text: string, locale?: string, hostTextSegmenter?: Readonly<HostTextSegmenterProvider>) => readonly TextSegment[]
|
|
19
14
|
>();
|
|
20
15
|
});
|
|
21
16
|
|
|
22
17
|
it('gives an explicit host precedence over the legacy installed backend', () => {
|
|
23
18
|
setTextSegmenterBackend(taggingBackend('legacy'));
|
|
24
|
-
expect(segmentGraphemes('hi', undefined, segmenterHost(taggingBackend('explicit')))[0].text).toBe(
|
|
19
|
+
expect(segmentGraphemes('hi', undefined, segmenterHost(taggingBackend('explicit')).text.segmenter)[0].text).toBe(
|
|
20
|
+
'explicit',
|
|
21
|
+
);
|
|
25
22
|
});
|
|
26
23
|
|
|
27
24
|
it('isolates callers that interleave different explicit hosts', () => {
|
|
28
25
|
const first = segmenterHost(taggingBackend('first'));
|
|
29
26
|
const second = segmenterHost(taggingBackend('second'));
|
|
30
|
-
expect(segmentGraphemes('hi', undefined, first)[0].text).toBe('first');
|
|
31
|
-
expect(segmentGraphemes('hi', undefined, second)[0].text).toBe('second');
|
|
32
|
-
expect(segmentGraphemes('hi', undefined, first)[0].text).toBe('first');
|
|
27
|
+
expect(segmentGraphemes('hi', undefined, first.text.segmenter)[0].text).toBe('first');
|
|
28
|
+
expect(segmentGraphemes('hi', undefined, second.text.segmenter)[0].text).toBe('second');
|
|
29
|
+
expect(segmentGraphemes('hi', undefined, first.text.segmenter)[0].text).toBe('first');
|
|
33
30
|
});
|
|
34
31
|
|
|
35
32
|
it('treats a ZWJ family emoji as one grapheme', () => {
|
|
@@ -47,7 +44,7 @@ describe('segmentGraphemes', () => {
|
|
|
47
44
|
|
|
48
45
|
it('threads the locale argument to the active backend', () => {
|
|
49
46
|
let seenLocale: string | undefined = 'unset';
|
|
50
|
-
const fake = allocateEntity<
|
|
47
|
+
const fake = allocateEntity<HostTextSegmenterProvider>();
|
|
51
48
|
fake.segment = (text: string, _granularity: TextSegmentGranularity, locale?: string): readonly TextSegment[] => {
|
|
52
49
|
seenLocale = locale;
|
|
53
50
|
return [{ start: 0, end: text.length, text }];
|
|
@@ -58,12 +55,14 @@ describe('segmentGraphemes', () => {
|
|
|
58
55
|
});
|
|
59
56
|
});
|
|
60
57
|
|
|
61
|
-
function segmenterHost(segmenter:
|
|
58
|
+
function segmenterHost(segmenter: HostTextSegmenterProvider): {
|
|
59
|
+
readonly text: { readonly segmenter: HostTextSegmenterProvider };
|
|
60
|
+
} {
|
|
62
61
|
return { text: { segmenter } };
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
function taggingBackend(tag: string):
|
|
66
|
-
const out = allocateEntity<
|
|
64
|
+
function taggingBackend(tag: string): HostTextSegmenterProvider {
|
|
65
|
+
const out = allocateEntity<HostTextSegmenterProvider>();
|
|
67
66
|
out.segment = () => [{ start: 0, end: tag.length, text: tag }];
|
|
68
67
|
return finishEntity(out);
|
|
69
68
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import type { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
3
|
-
import type {
|
|
3
|
+
import type { HostTextSegmenterProvider } from '@flighthq/types/contract';
|
|
4
4
|
import { vi } from 'vitest';
|
|
5
5
|
|
|
6
6
|
import {
|
|
@@ -103,17 +103,19 @@ describe('getPreviousWordBoundary', () => {
|
|
|
103
103
|
|
|
104
104
|
describe('getWordRangeAt', () => {
|
|
105
105
|
it('threads an explicit host through the boundary helper', () => {
|
|
106
|
-
const explicit = allocateEntity<
|
|
106
|
+
const explicit = allocateEntity<HostTextSegmenterProvider>();
|
|
107
107
|
explicit.segment = (text: string) => [{ start: 0, end: text.length, text, isWordLike: true }];
|
|
108
|
-
const host:
|
|
108
|
+
const host: { readonly text: { readonly segmenter: HostTextSegmenterProvider } } = {
|
|
109
|
+
text: { segmenter: finishEntity(explicit) },
|
|
110
|
+
};
|
|
109
111
|
setTextSegmenterBackend(
|
|
110
112
|
(() => {
|
|
111
|
-
const out = allocateEntity<
|
|
113
|
+
const out = allocateEntity<HostTextSegmenterProvider>();
|
|
112
114
|
out.segment = () => [];
|
|
113
115
|
return finishEntity(out);
|
|
114
116
|
})(),
|
|
115
117
|
);
|
|
116
|
-
expect(getWordRangeAt('word', 1, undefined, host)).toEqual({ start: 0, end: 4 });
|
|
118
|
+
expect(getWordRangeAt('word', 1, undefined, host.text.segmenter)).toEqual({ start: 0, end: 4 });
|
|
117
119
|
});
|
|
118
120
|
|
|
119
121
|
it('returns the word range under an index', () => {
|
|
@@ -136,7 +138,7 @@ describe('getWordRangeAt', () => {
|
|
|
136
138
|
let seenLocale: string | undefined = 'unset';
|
|
137
139
|
setTextSegmenterBackend(
|
|
138
140
|
(() => {
|
|
139
|
-
const out = allocateEntity<
|
|
141
|
+
const out = allocateEntity<HostTextSegmenterProvider>();
|
|
140
142
|
out.segment = (text: string, _granularity: string, locale: string) => {
|
|
141
143
|
seenLocale = locale;
|
|
142
144
|
return [{ start: 0, end: text.length, text, isWordLike: true }];
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import type { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
3
|
-
import type {
|
|
4
|
-
HasTextSegmenter,
|
|
5
|
-
TextSegment,
|
|
6
|
-
TextSegmentGranularity,
|
|
7
|
-
TextSegmenterBackend,
|
|
8
|
-
} from '@flighthq/types/contract';
|
|
3
|
+
import type { HostTextSegmenterProvider, TextSegment, TextSegmentGranularity } from '@flighthq/types/contract';
|
|
9
4
|
import { vi } from 'vitest';
|
|
10
5
|
|
|
11
6
|
import {
|
|
@@ -17,7 +12,7 @@ import {
|
|
|
17
12
|
webTextSegmenterBackend,
|
|
18
13
|
} from './textSegmenterBackend';
|
|
19
14
|
|
|
20
|
-
interface RecordingBackend extends
|
|
15
|
+
interface RecordingBackend extends HostTextSegmenterProvider {
|
|
21
16
|
calls: Array<{ text: string; granularity: TextSegmentGranularity; locale: string | undefined }>;
|
|
22
17
|
}
|
|
23
18
|
|
|
@@ -71,7 +66,7 @@ describe('explainTextSegmenterBackend', () => {
|
|
|
71
66
|
});
|
|
72
67
|
|
|
73
68
|
it('identifies a custom provider independently of Intl availability', () => {
|
|
74
|
-
expect(explainTextSegmenterBackend(segmenterHost(recordingBackend()))).toEqual({
|
|
69
|
+
expect(explainTextSegmenterBackend(segmenterHost(recordingBackend()).text.segmenter)).toEqual({
|
|
75
70
|
available: true,
|
|
76
71
|
backend: 'custom',
|
|
77
72
|
intlSegmenterAvailable: true,
|
|
@@ -92,9 +87,11 @@ describe('getTextSegmenterBackend', () => {
|
|
|
92
87
|
it('returns an explicit host provider ahead of the legacy backend', () => {
|
|
93
88
|
const legacy = recordingBackend();
|
|
94
89
|
const explicit = recordingBackend();
|
|
95
|
-
const host:
|
|
90
|
+
const host: { readonly text: { readonly segmenter: HostTextSegmenterProvider } } = {
|
|
91
|
+
text: { segmenter: explicit },
|
|
92
|
+
};
|
|
96
93
|
setTextSegmenterBackend(legacy);
|
|
97
|
-
expect(getTextSegmenterBackend(host)).toBe(explicit);
|
|
94
|
+
expect(getTextSegmenterBackend(host.text.segmenter)).toBe(explicit);
|
|
98
95
|
});
|
|
99
96
|
|
|
100
97
|
it('falls back to the stable bundled web backend when none is registered', () => {
|
|
@@ -141,6 +138,8 @@ describe('webTextSegmenterBackend', () => {
|
|
|
141
138
|
});
|
|
142
139
|
});
|
|
143
140
|
|
|
144
|
-
function segmenterHost(segmenter:
|
|
141
|
+
function segmenterHost(segmenter: HostTextSegmenterProvider): {
|
|
142
|
+
readonly text: { readonly segmenter: HostTextSegmenterProvider };
|
|
143
|
+
} {
|
|
145
144
|
return { text: { segmenter } };
|
|
146
145
|
}
|