expo-pretext 0.2.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.
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/android/src/main/java/expo/modules/pretext/ExpoPretextModule.kt +354 -0
- package/expo-module.config.json +9 -0
- package/ios/ExpoPretext.podspec +20 -0
- package/ios/ExpoPretext.swift +444 -0
- package/package.json +59 -0
- package/src/ExpoPretext.ts +70 -0
- package/src/__tests__/cache.test.ts +71 -0
- package/src/__tests__/font-utils.test.ts +69 -0
- package/src/__tests__/layout.test.ts +300 -0
- package/src/__tests__/obstacle-layout.test.ts +127 -0
- package/src/__tests__/setup-mocks.ts +14 -0
- package/src/analysis.ts +1208 -0
- package/src/bidi.ts +175 -0
- package/src/build.ts +503 -0
- package/src/cache.ts +59 -0
- package/src/engine-profile.ts +38 -0
- package/src/font-utils.ts +50 -0
- package/src/generated/bidi-data.ts +998 -0
- package/src/hooks/useFlashListHeights.ts +88 -0
- package/src/hooks/usePreparedText.ts +16 -0
- package/src/hooks/useTextHeight.ts +45 -0
- package/src/index.ts +56 -0
- package/src/layout.ts +353 -0
- package/src/line-break.ts +1113 -0
- package/src/obstacle-layout.ts +193 -0
- package/src/prepare.ts +246 -0
- package/src/rich-inline.ts +647 -0
- package/src/streaming.ts +61 -0
- package/src/types.ts +104 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
// All shared types for expo-pretext.
|
|
3
|
+
// TextStyle uses RN conventions (object, not CSS string).
|
|
4
|
+
// Prepared types are opaque — consumers use them as handles.
|
|
5
|
+
|
|
6
|
+
export type TextStyle = {
|
|
7
|
+
fontFamily: string
|
|
8
|
+
fontSize: number
|
|
9
|
+
lineHeight?: number
|
|
10
|
+
fontWeight?: '400' | '500' | '600' | '700' | 'bold' | 'normal'
|
|
11
|
+
fontStyle?: 'normal' | 'italic'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type WhiteSpaceMode = 'normal' | 'pre-wrap'
|
|
15
|
+
|
|
16
|
+
export type PrepareOptions = {
|
|
17
|
+
whiteSpace?: WhiteSpaceMode
|
|
18
|
+
locale?: string
|
|
19
|
+
accuracy?: 'fast' | 'exact'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type LayoutResult = {
|
|
23
|
+
height: number
|
|
24
|
+
lineCount: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type LayoutCursor = {
|
|
28
|
+
segmentIndex: number
|
|
29
|
+
graphemeIndex: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type LayoutLine = {
|
|
33
|
+
text: string
|
|
34
|
+
width: number
|
|
35
|
+
start: LayoutCursor
|
|
36
|
+
end: LayoutCursor
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type LayoutLineRange = {
|
|
40
|
+
width: number
|
|
41
|
+
start: LayoutCursor
|
|
42
|
+
end: LayoutCursor
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type LayoutWithLinesResult = LayoutResult & {
|
|
46
|
+
lines: LayoutLine[]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Opaque prepared handles
|
|
50
|
+
declare const preparedTextBrand: unique symbol
|
|
51
|
+
export type PreparedText = { readonly [preparedTextBrand]: true }
|
|
52
|
+
|
|
53
|
+
declare const preparedTextWithSegmentsBrand: unique symbol
|
|
54
|
+
export type PreparedTextWithSegments = {
|
|
55
|
+
readonly [preparedTextWithSegmentsBrand]: true
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Inline flow types
|
|
59
|
+
export type InlineFlowItem = {
|
|
60
|
+
text: string
|
|
61
|
+
style: TextStyle
|
|
62
|
+
atomic?: boolean
|
|
63
|
+
extraWidth?: number
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare const preparedInlineFlowBrand: unique symbol
|
|
67
|
+
export type PreparedInlineFlow = {
|
|
68
|
+
readonly [preparedInlineFlowBrand]: true
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type InlineFlowCursor = {
|
|
72
|
+
itemIndex: number
|
|
73
|
+
segmentIndex: number
|
|
74
|
+
graphemeIndex: number
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type InlineFlowFragment = {
|
|
78
|
+
itemIndex: number
|
|
79
|
+
text: string
|
|
80
|
+
gapBefore: number
|
|
81
|
+
occupiedWidth: number
|
|
82
|
+
start: LayoutCursor
|
|
83
|
+
end: LayoutCursor
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type InlineFlowLine = {
|
|
87
|
+
fragments: InlineFlowFragment[]
|
|
88
|
+
width: number
|
|
89
|
+
end: InlineFlowCursor
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Native module types (internal)
|
|
93
|
+
export type FontDescriptor = {
|
|
94
|
+
fontFamily: string
|
|
95
|
+
fontSize: number
|
|
96
|
+
fontWeight?: string
|
|
97
|
+
fontStyle?: string
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type NativeSegmentResult = {
|
|
101
|
+
segments: string[]
|
|
102
|
+
isWordLike: boolean[]
|
|
103
|
+
widths: number[]
|
|
104
|
+
}
|