@shopify/react-native-skia 0.1.221 → 0.1.223

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.
Files changed (223) hide show
  1. package/android/cpp/rnskia-android/RNSkAndroidView.h +3 -0
  2. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +1 -0
  3. package/android/cpp/rnskia-android/SkiaOpenGLHelper.h +0 -1
  4. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +46 -6
  5. package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +3 -3
  6. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +8 -14
  7. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +93 -105
  8. package/cpp/api/JsiSkApi.h +5 -0
  9. package/cpp/api/JsiSkFontMgrFactory.h +9 -4
  10. package/cpp/api/JsiSkParagraph.h +135 -0
  11. package/cpp/api/JsiSkParagraphBuilder.h +159 -0
  12. package/cpp/api/JsiSkParagraphStyle.h +124 -0
  13. package/cpp/api/JsiSkStrutStyle.h +96 -0
  14. package/cpp/api/JsiSkTextStyle.h +185 -0
  15. package/cpp/jsi/JsiHostObject.h +21 -0
  16. package/cpp/rnskia/dom/JsiDomApi.h +4 -0
  17. package/cpp/rnskia/dom/nodes/JsiParagraphNode.h +62 -0
  18. package/cpp/rnskia/dom/props/ParagraphProp.h +45 -0
  19. package/cpp/skia/modules/skunicode/include/SkUnicode.h +312 -0
  20. package/cpp/skia/src/base/SkTInternalLList.h +304 -0
  21. package/cpp/skia/src/base/SkUTF.h +95 -0
  22. package/cpp/skia/src/core/SkLRUCache.h +130 -0
  23. package/cpp/utils/RNSkLog.h +3 -3
  24. package/lib/commonjs/dom/nodes/JsiSkDOM.d.ts +2 -0
  25. package/lib/commonjs/dom/nodes/JsiSkDOM.js +7 -0
  26. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  27. package/lib/commonjs/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
  28. package/lib/commonjs/dom/nodes/drawings/ParagraphNode.js +41 -0
  29. package/lib/commonjs/dom/nodes/drawings/ParagraphNode.js.map +1 -0
  30. package/lib/commonjs/dom/types/NodeType.d.ts +2 -1
  31. package/lib/commonjs/dom/types/NodeType.js +1 -0
  32. package/lib/commonjs/dom/types/NodeType.js.map +1 -1
  33. package/lib/commonjs/dom/types/Paragraph.d.ts +8 -0
  34. package/lib/commonjs/dom/types/Paragraph.js +6 -0
  35. package/lib/commonjs/dom/types/Paragraph.js.map +1 -0
  36. package/lib/commonjs/dom/types/SkDOM.d.ts +2 -0
  37. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  38. package/lib/commonjs/dom/types/index.d.ts +1 -0
  39. package/lib/commonjs/dom/types/index.js +13 -0
  40. package/lib/commonjs/dom/types/index.js.map +1 -1
  41. package/lib/commonjs/renderer/HostComponents.d.ts +3 -1
  42. package/lib/commonjs/renderer/HostComponents.js +4 -0
  43. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  44. package/lib/commonjs/renderer/components/index.d.ts +1 -0
  45. package/lib/commonjs/renderer/components/index.js +13 -0
  46. package/lib/commonjs/renderer/components/index.js.map +1 -1
  47. package/lib/commonjs/renderer/components/paragraph/Paragraph.d.ts +4 -0
  48. package/lib/commonjs/renderer/components/paragraph/Paragraph.js +17 -0
  49. package/lib/commonjs/renderer/components/paragraph/Paragraph.js.map +1 -0
  50. package/lib/commonjs/renderer/components/paragraph/index.d.ts +1 -0
  51. package/lib/commonjs/renderer/components/paragraph/index.js +19 -0
  52. package/lib/commonjs/renderer/components/paragraph/index.js.map +1 -0
  53. package/lib/commonjs/skia/types/Paragraph/Paragraph.d.ts +56 -0
  54. package/lib/commonjs/skia/types/Paragraph/Paragraph.js +6 -0
  55. package/lib/commonjs/skia/types/Paragraph/Paragraph.js.map +1 -0
  56. package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
  57. package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.js +18 -0
  58. package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.js.map +1 -0
  59. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
  60. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.js +36 -0
  61. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.js.map +1 -0
  62. package/lib/commonjs/skia/types/Paragraph/TextStyle.d.ts +62 -0
  63. package/lib/commonjs/skia/types/Paragraph/TextStyle.js +35 -0
  64. package/lib/commonjs/skia/types/Paragraph/TextStyle.js.map +1 -0
  65. package/lib/commonjs/skia/types/Paragraph/index.d.ts +6 -0
  66. package/lib/commonjs/skia/types/Paragraph/index.js +84 -0
  67. package/lib/commonjs/skia/types/Paragraph/index.js.map +1 -0
  68. package/lib/commonjs/skia/types/Skia.d.ts +2 -0
  69. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  70. package/lib/commonjs/skia/types/index.d.ts +1 -0
  71. package/lib/commonjs/skia/types/index.js +13 -0
  72. package/lib/commonjs/skia/types/index.js.map +1 -1
  73. package/lib/commonjs/skia/web/JsiSkImage.js +0 -6
  74. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  75. package/lib/commonjs/skia/web/JsiSkParagraph.d.ts +16 -0
  76. package/lib/commonjs/skia/web/JsiSkParagraph.js +91 -0
  77. package/lib/commonjs/skia/web/JsiSkParagraph.js.map +1 -0
  78. package/lib/commonjs/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
  79. package/lib/commonjs/skia/web/JsiSkParagraphBuilder.js +85 -0
  80. package/lib/commonjs/skia/web/JsiSkParagraphBuilder.js.map +1 -0
  81. package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
  82. package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.js +34 -0
  83. package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.js.map +1 -0
  84. package/lib/commonjs/skia/web/JsiSkParagraphStyle.d.ts +5 -0
  85. package/lib/commonjs/skia/web/JsiSkParagraphStyle.js +59 -0
  86. package/lib/commonjs/skia/web/JsiSkParagraphStyle.js.map +1 -0
  87. package/lib/commonjs/skia/web/JsiSkTextStyle.d.ts +5 -0
  88. package/lib/commonjs/skia/web/JsiSkTextStyle.js +54 -0
  89. package/lib/commonjs/skia/web/JsiSkTextStyle.js.map +1 -0
  90. package/lib/commonjs/skia/web/JsiSkia.js +4 -1
  91. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  92. package/lib/module/dom/nodes/JsiSkDOM.d.ts +2 -0
  93. package/lib/module/dom/nodes/JsiSkDOM.js +6 -0
  94. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  95. package/lib/module/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
  96. package/lib/module/dom/nodes/drawings/ParagraphNode.js +30 -0
  97. package/lib/module/dom/nodes/drawings/ParagraphNode.js.map +1 -0
  98. package/lib/module/dom/types/NodeType.d.ts +2 -1
  99. package/lib/module/dom/types/NodeType.js +1 -0
  100. package/lib/module/dom/types/NodeType.js.map +1 -1
  101. package/lib/module/dom/types/Paragraph.d.ts +8 -0
  102. package/lib/module/dom/types/Paragraph.js +2 -0
  103. package/lib/module/dom/types/Paragraph.js.map +1 -0
  104. package/lib/module/dom/types/SkDOM.d.ts +2 -0
  105. package/lib/module/dom/types/SkDOM.js.map +1 -1
  106. package/lib/module/dom/types/index.d.ts +1 -0
  107. package/lib/module/dom/types/index.js +1 -0
  108. package/lib/module/dom/types/index.js.map +1 -1
  109. package/lib/module/renderer/HostComponents.d.ts +3 -1
  110. package/lib/module/renderer/HostComponents.js +4 -0
  111. package/lib/module/renderer/HostComponents.js.map +1 -1
  112. package/lib/module/renderer/components/index.d.ts +1 -0
  113. package/lib/module/renderer/components/index.js +1 -0
  114. package/lib/module/renderer/components/index.js.map +1 -1
  115. package/lib/module/renderer/components/paragraph/Paragraph.d.ts +4 -0
  116. package/lib/module/renderer/components/paragraph/Paragraph.js +5 -0
  117. package/lib/module/renderer/components/paragraph/Paragraph.js.map +1 -0
  118. package/lib/module/renderer/components/paragraph/index.d.ts +1 -0
  119. package/lib/module/renderer/components/paragraph/index.js +2 -0
  120. package/lib/module/renderer/components/paragraph/index.js.map +1 -0
  121. package/lib/module/skia/types/Paragraph/Paragraph.d.ts +56 -0
  122. package/lib/module/skia/types/Paragraph/Paragraph.js +2 -0
  123. package/lib/module/skia/types/Paragraph/Paragraph.js.map +1 -0
  124. package/lib/module/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
  125. package/lib/module/skia/types/Paragraph/ParagraphBuilder.js +11 -0
  126. package/lib/module/skia/types/Paragraph/ParagraphBuilder.js.map +1 -0
  127. package/lib/module/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
  128. package/lib/module/skia/types/Paragraph/ParagraphStyle.js +27 -0
  129. package/lib/module/skia/types/Paragraph/ParagraphStyle.js.map +1 -0
  130. package/lib/module/skia/types/Paragraph/TextStyle.d.ts +62 -0
  131. package/lib/module/skia/types/Paragraph/TextStyle.js +26 -0
  132. package/lib/module/skia/types/Paragraph/TextStyle.js.map +1 -0
  133. package/lib/module/skia/types/Paragraph/index.d.ts +6 -0
  134. package/lib/module/skia/types/Paragraph/index.js +7 -0
  135. package/lib/module/skia/types/Paragraph/index.js.map +1 -0
  136. package/lib/module/skia/types/Skia.d.ts +2 -0
  137. package/lib/module/skia/types/Skia.js.map +1 -1
  138. package/lib/module/skia/types/index.d.ts +1 -0
  139. package/lib/module/skia/types/index.js +1 -0
  140. package/lib/module/skia/types/index.js.map +1 -1
  141. package/lib/module/skia/web/JsiSkImage.js +0 -6
  142. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  143. package/lib/module/skia/web/JsiSkParagraph.d.ts +16 -0
  144. package/lib/module/skia/web/JsiSkParagraph.js +81 -0
  145. package/lib/module/skia/web/JsiSkParagraph.js.map +1 -0
  146. package/lib/module/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
  147. package/lib/module/skia/web/JsiSkParagraphBuilder.js +73 -0
  148. package/lib/module/skia/web/JsiSkParagraphBuilder.js.map +1 -0
  149. package/lib/module/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
  150. package/lib/module/skia/web/JsiSkParagraphBuilderFactory.js +21 -0
  151. package/lib/module/skia/web/JsiSkParagraphBuilderFactory.js.map +1 -0
  152. package/lib/module/skia/web/JsiSkParagraphStyle.d.ts +5 -0
  153. package/lib/module/skia/web/JsiSkParagraphStyle.js +49 -0
  154. package/lib/module/skia/web/JsiSkParagraphStyle.js.map +1 -0
  155. package/lib/module/skia/web/JsiSkTextStyle.d.ts +5 -0
  156. package/lib/module/skia/web/JsiSkTextStyle.js +45 -0
  157. package/lib/module/skia/web/JsiSkTextStyle.js.map +1 -0
  158. package/lib/module/skia/web/JsiSkia.js +3 -1
  159. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  160. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  161. package/lib/typescript/src/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
  162. package/lib/typescript/src/dom/types/NodeType.d.ts +2 -1
  163. package/lib/typescript/src/dom/types/Paragraph.d.ts +8 -0
  164. package/lib/typescript/src/dom/types/SkDOM.d.ts +2 -0
  165. package/lib/typescript/src/dom/types/index.d.ts +1 -0
  166. package/lib/typescript/src/renderer/HostComponents.d.ts +3 -1
  167. package/lib/typescript/src/renderer/components/index.d.ts +1 -0
  168. package/lib/typescript/src/renderer/components/paragraph/Paragraph.d.ts +4 -0
  169. package/lib/typescript/src/renderer/components/paragraph/index.d.ts +1 -0
  170. package/lib/typescript/src/skia/types/Paragraph/Paragraph.d.ts +56 -0
  171. package/lib/typescript/src/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
  172. package/lib/typescript/src/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
  173. package/lib/typescript/src/skia/types/Paragraph/TextStyle.d.ts +62 -0
  174. package/lib/typescript/src/skia/types/Paragraph/index.d.ts +6 -0
  175. package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
  176. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  177. package/lib/typescript/src/skia/web/JsiSkParagraph.d.ts +16 -0
  178. package/lib/typescript/src/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
  179. package/lib/typescript/src/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
  180. package/lib/typescript/src/skia/web/JsiSkParagraphStyle.d.ts +5 -0
  181. package/lib/typescript/src/skia/web/JsiSkTextStyle.d.ts +5 -0
  182. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  183. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  184. package/libs/ios/libskottie.xcframework/Info.plist +5 -5
  185. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  186. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  187. package/libs/ios/libskparagraph.xcframework/Info.plist +5 -5
  188. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  189. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  190. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  191. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  192. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  193. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  194. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
  195. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
  196. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  197. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  198. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  199. package/package.json +1 -1
  200. package/src/dom/nodes/JsiSkDOM.ts +9 -0
  201. package/src/dom/nodes/drawings/ParagraphNode.ts +22 -0
  202. package/src/dom/types/NodeType.ts +3 -0
  203. package/src/dom/types/Paragraph.ts +10 -0
  204. package/src/dom/types/SkDOM.ts +4 -0
  205. package/src/dom/types/index.ts +1 -0
  206. package/src/renderer/HostComponents.ts +10 -0
  207. package/src/renderer/components/index.ts +2 -0
  208. package/src/renderer/components/paragraph/Paragraph.tsx +8 -0
  209. package/src/renderer/components/paragraph/index.ts +1 -0
  210. package/src/skia/types/Paragraph/Paragraph.ts +59 -0
  211. package/src/skia/types/Paragraph/ParagraphBuilder.ts +96 -0
  212. package/src/skia/types/Paragraph/ParagraphStyle.ts +45 -0
  213. package/src/skia/types/Paragraph/TextStyle.ts +70 -0
  214. package/src/skia/types/Paragraph/index.ts +6 -0
  215. package/src/skia/types/Skia.ts +3 -0
  216. package/src/skia/types/index.ts +1 -0
  217. package/src/skia/web/JsiSkImage.ts +0 -6
  218. package/src/skia/web/JsiSkParagraph.ts +69 -0
  219. package/src/skia/web/JsiSkParagraphBuilder.ts +99 -0
  220. package/src/skia/web/JsiSkParagraphBuilderFactory.ts +42 -0
  221. package/src/skia/web/JsiSkParagraphStyle.ts +65 -0
  222. package/src/skia/web/JsiSkTextStyle.ts +53 -0
  223. package/src/skia/web/JsiSkia.ts +2 -0
@@ -0,0 +1,59 @@
1
+ import type { SkCanvas } from "../Canvas";
2
+ import type { SkJSIInstance } from "../JsiInstance";
3
+ import type { SkRect } from "../Rect";
4
+
5
+ import type { SkTextDirection } from "./ParagraphStyle";
6
+
7
+ export interface SkRectWithDirection {
8
+ rect: SkRect;
9
+ direction: SkTextDirection;
10
+ }
11
+
12
+ export interface SkParagraph extends SkJSIInstance<"Paragraph"> {
13
+ /**
14
+ * Calculates the position of the the glyphs in the paragraph
15
+ * @param width Max width of the paragraph
16
+ */
17
+ layout(width: number): void;
18
+ /**
19
+ * Paints the paragraph to the provded canvas
20
+ * @param canvas Canvas to paint into
21
+ * @param x X coordinate to paint at
22
+ * @param y Y coordinate to paint at
23
+ */
24
+ paint(canvas: SkCanvas, x: number, y: number): void;
25
+ /**
26
+ * Returns the height of the paragraph. This method requires the layout
27
+ * method to have been called first.
28
+ */
29
+ getHeight(): number;
30
+ /**
31
+ * Returns the max width of the paragraph. This method requires the layout
32
+ * method to have been called first.
33
+ */
34
+ getMaxWidth(): number;
35
+ /**
36
+ * Returns the index of the glyph at the given position. This method requires
37
+ * the layout method to have been called first.
38
+ * @param x X coordinate of the position
39
+ * @param y Y coordinate of the position
40
+ */
41
+ getGlyphPositionAtCoordinate(x: number, y: number): number;
42
+ /**
43
+ * Returns the bounding boxes of the glyphs in the given range. This method
44
+ * requires the layout method to have been called first.
45
+ * @param start Start index of the range
46
+ * @param end End index of the range
47
+ */
48
+ getRectsForRange(start: number, end: number): SkRect[];
49
+ /**
50
+ * Returns the bounding boxes for all lines in the paragraph. This method
51
+ * requires the layout method to have been called first.
52
+ */
53
+ getLineMetrics(): Array<SkRect>;
54
+ /**
55
+ * Returns a list of rects with direction info for the placeholders added
56
+ * to the paragraph.
57
+ */
58
+ getRectsForPlaceholders(): SkRectWithDirection[];
59
+ }
@@ -0,0 +1,96 @@
1
+ import type { SkJSIInstance } from "../JsiInstance";
2
+ import type { SkPaint } from "../Paint";
3
+
4
+ import type { SkParagraph } from "./Paragraph";
5
+ import type { SkParagraphStyle } from "./ParagraphStyle";
6
+ import type { SkTextStyle, TextBaseline } from "./TextStyle";
7
+ import type { SkTypefaceFontProvider } from "./TypefaceFontProvider";
8
+
9
+ export interface ParagraphBuilderFactory {
10
+ /**
11
+ * Creates a new ParagraphBuilder object from custom fonts.
12
+ * @param paragraphStyle Initial paragraph style
13
+ * @param typefaceProvider Typeface provider
14
+ */
15
+ Make(
16
+ paragraphStyle?: SkParagraphStyle,
17
+ typefaceProvider?: SkTypefaceFontProvider
18
+ ): SkParagraphBuilder;
19
+ }
20
+
21
+ export enum PlaceholderAlignment {
22
+ /// Match the baseline of the placeholder with the baseline.
23
+ Baseline = 0,
24
+
25
+ /// Align the bottom edge of the placeholder with the baseline such that the
26
+ /// placeholder sits on top of the baseline.
27
+ AboveBaseline,
28
+
29
+ /// Align the top edge of the placeholder with the baseline specified in
30
+ /// such that the placeholder hangs below the baseline.
31
+ BelowBaseline,
32
+
33
+ /// Align the top edge of the placeholder with the top edge of the font.
34
+ /// When the placeholder is very tall, the extra space will hang from
35
+ /// the top and extend through the bottom of the line.
36
+ Top,
37
+
38
+ /// Align the bottom edge of the placeholder with the top edge of the font.
39
+ /// When the placeholder is very tall, the extra space will rise from
40
+ /// the bottom and extend through the top of the line.
41
+ Bottom,
42
+
43
+ /// Align the middle of the placeholder with the middle of the text. When the
44
+ /// placeholder is very tall, the extra space will grow equally from
45
+ /// the top and bottom of the line.
46
+ Middle,
47
+ }
48
+
49
+ export interface SkParagraphBuilder extends SkJSIInstance<"ParagraphBuilder"> {
50
+ /**
51
+ * Creates a Paragraph object from the builder and the inputs given to the builder.
52
+ */
53
+ build(): SkParagraph;
54
+ /**
55
+ * Restores the builder to its initial empty state.
56
+ */
57
+ reset(): void;
58
+ /**
59
+ * Pushes a text-style to the builder
60
+ * @param style Style to push
61
+ * @param foregroundPaint Foreground paint object
62
+ * @param backgroundPaint Background paint object
63
+ * @returns The builder
64
+ */
65
+ pushStyle: (
66
+ style: SkTextStyle,
67
+ foregroundPaint?: SkPaint | undefined,
68
+ backgroundPaint?: SkPaint | undefined
69
+ ) => SkParagraphBuilder;
70
+ /**
71
+ * Pops the current text style from the builder
72
+ * @returns The builder
73
+ */
74
+ pop: () => SkParagraphBuilder;
75
+ /**
76
+ * Adds text to the builder
77
+ * @param text
78
+ * @returns The builder
79
+ */
80
+ addText: (text: string) => SkParagraphBuilder;
81
+ /**
82
+ * Pushes the information required to leave an open space.
83
+ * @param width
84
+ * @param height
85
+ * @param alignment
86
+ * @param baseline
87
+ * @param offset
88
+ */
89
+ addPlaceholder(
90
+ width?: number,
91
+ height?: number,
92
+ alignment?: PlaceholderAlignment,
93
+ baseline?: TextBaseline,
94
+ offset?: number
95
+ ): SkParagraphBuilder;
96
+ }
@@ -0,0 +1,45 @@
1
+ import type { SkTextFontStyle, SkTextStyle } from "./TextStyle";
2
+
3
+ export enum SkTextDirection {
4
+ RTL = 0,
5
+ LTR = 1,
6
+ }
7
+ export enum SkTextAlign {
8
+ Left = 0,
9
+ Right,
10
+ Center,
11
+ Justify,
12
+ Start,
13
+ End,
14
+ }
15
+
16
+ export interface SkStrutStyle {
17
+ strutEnabled?: boolean;
18
+ fontFamilies?: string[];
19
+ fontStyle?: SkTextFontStyle;
20
+ fontSize?: number;
21
+ heightMultiplier?: number;
22
+ halfLeading?: boolean;
23
+ leading?: number;
24
+ forceStrutHeight?: boolean;
25
+ }
26
+
27
+ export enum SkTextHeightBehavior {
28
+ All = 0x0,
29
+ DisableFirstAscent = 0x1,
30
+ DisableLastDescent = 0x2,
31
+ DisableAll = 0x1 | 0x2,
32
+ }
33
+
34
+ export interface SkParagraphStyle {
35
+ disableHinting?: boolean;
36
+ ellipsis?: string;
37
+ heightMultiplier?: number;
38
+ maxLines?: number;
39
+ replaceTabCharacters?: boolean;
40
+ strutStyle?: SkStrutStyle;
41
+ textAlign?: SkTextAlign;
42
+ textDirection?: SkTextDirection;
43
+ textHeightBehavior?: SkTextHeightBehavior;
44
+ textStyle?: SkTextStyle;
45
+ }
@@ -0,0 +1,70 @@
1
+ import type { SkColor } from "../Color";
2
+ import type { FontSlant, FontWeight, FontWidth } from "../Font";
3
+ import type { SkPoint } from "../Point";
4
+
5
+ export enum TextDecoration {
6
+ NoDecoration = 0x0,
7
+ Underline = 0x1,
8
+ Overline = 0x2,
9
+ LineThrough = 0x4,
10
+ }
11
+
12
+ export enum TextDecorationStyle {
13
+ Solid = 0,
14
+ Double,
15
+ Dotted,
16
+ Dashed,
17
+ Wavy,
18
+ }
19
+
20
+ export interface SkTextShadow {
21
+ color?: SkColor;
22
+ /**
23
+ * 2d array for x and y offset. Defaults to [0, 0]
24
+ */
25
+ offset?: SkPoint;
26
+ blurRadius?: number;
27
+ }
28
+
29
+ export interface SkTextFontFeatures {
30
+ name: string;
31
+ value: number;
32
+ }
33
+
34
+ export interface SkTextFontStyle {
35
+ weight?: FontWeight;
36
+ width?: FontWidth;
37
+ slant?: FontSlant;
38
+ }
39
+
40
+ export interface SkTextFontVariations {
41
+ axis: string;
42
+ value: number;
43
+ }
44
+
45
+ export enum TextBaseline {
46
+ Alphabetic = 0,
47
+ Ideographic,
48
+ }
49
+
50
+ export interface SkTextStyle {
51
+ backgroundColor?: SkColor;
52
+ color?: SkColor;
53
+ decoration?: number;
54
+ decorationColor?: SkColor;
55
+ decorationThickness?: number;
56
+ decorationStyle?: TextDecoration;
57
+ fontFamilies?: string[];
58
+ fontFeatures?: SkTextFontFeatures[];
59
+ fontSize?: number;
60
+ fontStyle?: SkTextFontStyle;
61
+ fontVariations?: SkTextFontVariations[];
62
+ foregroundColor?: SkColor;
63
+ heightMultiplier?: number;
64
+ halfLeading?: boolean;
65
+ letterSpacing?: number;
66
+ locale?: string;
67
+ shadows?: SkTextShadow[];
68
+ textBaseline?: TextBaseline;
69
+ wordSpacing?: number;
70
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./TypefaceFontProvider";
2
+ export * from "./TypefaceFontProviderFactory";
3
+ export * from "./Paragraph";
4
+ export * from "./ParagraphBuilder";
5
+ export * from "./ParagraphStyle";
6
+ export * from "./TextStyle";
@@ -29,6 +29,7 @@ import type { PictureFactory, SkPictureRecorder } from "./Picture";
29
29
  import type { Color, SkColor } from "./Color";
30
30
  import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
31
31
  import type { AnimatedImageFactory } from "./AnimatedImage";
32
+ import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
32
33
 
33
34
  /**
34
35
  * Declares the interface for the native Skia API
@@ -84,4 +85,6 @@ export interface Skia {
84
85
  SVG: SVGFactory;
85
86
  TextBlob: TextBlobFactory;
86
87
  Surface: SurfaceFactory;
88
+ // Paragraph
89
+ ParagraphBuilder: ParagraphBuilderFactory;
87
90
  }
@@ -27,3 +27,4 @@ export * from "./JsiInstance";
27
27
  export * from "./Skia";
28
28
  export * from "./TextBlob";
29
29
  export * from "./Size";
30
+ export * from "./Paragraph";
@@ -127,12 +127,6 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
127
127
 
128
128
  readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo) {
129
129
  const info = this.getImageInfo();
130
- console.log({
131
- alphaType: ckEnum(info.alphaType),
132
- colorType: ckEnum(info.colorType),
133
- realAlphaType: this.CanvasKit.AlphaType.Opaque.value,
134
- realColorType: this.CanvasKit.ColorType.RGBA_8888.value,
135
- });
136
130
  const pxInfo: CKImageInfo = {
137
131
  colorSpace: this.CanvasKit.ColorSpace.SRGB,
138
132
  width: imageInfo?.width ?? info.width,
@@ -0,0 +1,69 @@
1
+ import type { CanvasKit, Paragraph } from "canvaskit-wasm";
2
+
3
+ import type { SkRect, SkRectWithDirection, SkParagraph } from "../types";
4
+
5
+ import { HostObject } from "./Host";
6
+ import type { JsiSkCanvas } from "./JsiSkCanvas";
7
+
8
+ export class JsiSkParagraph
9
+ extends HostObject<Paragraph, "Paragraph">
10
+ implements SkParagraph
11
+ {
12
+ constructor(CanvasKit: CanvasKit, ref: Paragraph) {
13
+ super(CanvasKit, ref, "Paragraph");
14
+ }
15
+
16
+ layout(width: number): void {
17
+ this.ref.layout(width);
18
+ }
19
+ paint(canvas: JsiSkCanvas, x: number, y: number): void {
20
+ canvas.ref.drawParagraph(this.ref, x, y);
21
+ }
22
+ getHeight(): number {
23
+ return this.ref.getHeight();
24
+ }
25
+ getMaxWidth(): number {
26
+ return this.ref.getMaxWidth();
27
+ }
28
+ getGlyphPositionAtCoordinate(x: number, y: number): number {
29
+ return this.ref.getGlyphPositionAtCoordinate(x, y).pos;
30
+ }
31
+ getRectsForPlaceholders(): SkRectWithDirection[] {
32
+ return this.ref.getRectsForPlaceholders().map(({ rect, dir }) => ({
33
+ rect: {
34
+ x: rect.at(0)!,
35
+ y: rect.at(1)!,
36
+ width: rect.at(2)!,
37
+ height: rect.at(3)!,
38
+ },
39
+ direction: dir.value,
40
+ }));
41
+ }
42
+ getRectsForRange(start: number, end: number): SkRect[] {
43
+ return this.ref
44
+ .getRectsForRange(
45
+ start,
46
+ end,
47
+ { value: 0 } /** kTight */,
48
+ { value: 0 } /** kTight */
49
+ )
50
+ .map(({ rect }) => ({
51
+ x: rect[0],
52
+ y: rect[1],
53
+ width: rect[2],
54
+ height: rect[3],
55
+ }));
56
+ }
57
+ getLineMetrics(): SkRect[] {
58
+ return this.ref.getLineMetrics().map((r, index) => ({
59
+ x: r.left,
60
+ y: index * r.height,
61
+ width: r.width,
62
+ height: r.height,
63
+ }));
64
+ }
65
+
66
+ dispose() {
67
+ this.ref.delete();
68
+ }
69
+ }
@@ -0,0 +1,99 @@
1
+ import type {
2
+ CanvasKit,
3
+ InputColor,
4
+ Paint,
5
+ ParagraphBuilder,
6
+ TextStyle,
7
+ } from "canvaskit-wasm";
8
+
9
+ import type {
10
+ SkParagraphBuilder,
11
+ SkParagraph,
12
+ SkTextStyle,
13
+ SkPaint,
14
+ } from "../types";
15
+ import { PlaceholderAlignment, TextBaseline } from "../types";
16
+
17
+ import { HostObject } from "./Host";
18
+ import { JsiSkParagraph } from "./JsiSkParagraph";
19
+ import { JsiSkTextStyle } from "./JsiSkTextStyle";
20
+ import { JsiSkPaint } from "./JsiSkPaint";
21
+
22
+ export class JsiSkParagraphBuilder
23
+ extends HostObject<ParagraphBuilder, "ParagraphBuilder">
24
+ implements SkParagraphBuilder
25
+ {
26
+ constructor(CanvasKit: CanvasKit, ref: ParagraphBuilder) {
27
+ super(CanvasKit, ref, "ParagraphBuilder");
28
+ }
29
+
30
+ addPlaceholder(
31
+ width: number | undefined = 0,
32
+ height: number | undefined = 0,
33
+ alignment: PlaceholderAlignment | undefined = PlaceholderAlignment.Baseline,
34
+ baseline: TextBaseline | undefined = TextBaseline.Alphabetic,
35
+ offset: number | undefined = 0
36
+ ): SkParagraphBuilder {
37
+ this.ref.addPlaceholder(
38
+ width,
39
+ height,
40
+ { value: alignment },
41
+ { value: baseline },
42
+ offset
43
+ );
44
+ return this;
45
+ }
46
+ addText(text: string): SkParagraphBuilder {
47
+ this.ref.addText(text);
48
+ return this;
49
+ }
50
+
51
+ build(): SkParagraph {
52
+ return new JsiSkParagraph(this.CanvasKit, this.ref.build());
53
+ }
54
+
55
+ reset(): void {
56
+ this.ref.reset();
57
+ }
58
+
59
+ pushStyle(
60
+ style: SkTextStyle,
61
+ foregroundPaint?: SkPaint | undefined,
62
+ backgroundPaint?: SkPaint | undefined
63
+ ): SkParagraphBuilder {
64
+ const textStyle: TextStyle = JsiSkTextStyle.toTextStyle(style);
65
+ if (foregroundPaint || backgroundPaint) {
66
+ // Due the canvaskit API not exposing textStyle methods,
67
+ // we set the default paint color to black for the foreground
68
+ // and transparent for the background
69
+ const fg: Paint = foregroundPaint
70
+ ? JsiSkPaint.fromValue(foregroundPaint)
71
+ : this.makePaint(textStyle.color ?? Float32Array.of(0, 0, 0, 1));
72
+ const bg: Paint = backgroundPaint
73
+ ? JsiSkPaint.fromValue(backgroundPaint)
74
+ : this.makePaint(
75
+ textStyle.backgroundColor ?? Float32Array.of(0, 0, 0, 0)
76
+ );
77
+ this.ref.pushPaintStyle(new this.CanvasKit.TextStyle(textStyle), fg, bg);
78
+ } else {
79
+ this.ref.pushStyle(new this.CanvasKit.TextStyle(textStyle));
80
+ }
81
+
82
+ return this;
83
+ }
84
+
85
+ pop(): SkParagraphBuilder {
86
+ this.ref.pop();
87
+ return this;
88
+ }
89
+
90
+ dispose() {
91
+ this.ref.delete();
92
+ }
93
+
94
+ private makePaint(color: InputColor) {
95
+ const paint = new this.CanvasKit.Paint();
96
+ paint.setColor(color);
97
+ return paint;
98
+ }
99
+ }
@@ -0,0 +1,42 @@
1
+ import type { CanvasKit } from "canvaskit-wasm";
2
+
3
+ import type {
4
+ ParagraphBuilderFactory,
5
+ SkParagraphStyle,
6
+ SkTypefaceFontProvider,
7
+ } from "../types";
8
+
9
+ import { Host } from "./Host";
10
+ import { JsiSkParagraphBuilder } from "./JsiSkParagraphBuilder";
11
+ import { JsiSkParagraphStyle } from "./JsiSkParagraphStyle";
12
+ import { JsiSkTypeface } from "./JsiSkTypeface";
13
+
14
+ export class JsiSkParagraphBuilderFactory
15
+ extends Host
16
+ implements ParagraphBuilderFactory
17
+ {
18
+ constructor(CanvasKit: CanvasKit) {
19
+ super(CanvasKit);
20
+ }
21
+
22
+ Make(
23
+ paragraphStyle: SkParagraphStyle,
24
+ typefaceProvider?: SkTypefaceFontProvider
25
+ ) {
26
+ const style = new this.CanvasKit.ParagraphStyle(
27
+ JsiSkParagraphStyle.toParagraphStyle(this.CanvasKit, paragraphStyle ?? {})
28
+ );
29
+ if (typefaceProvider === undefined) {
30
+ throw new Error(
31
+ "SkTypefaceFontProvider is required on React Native Web."
32
+ );
33
+ }
34
+ return new JsiSkParagraphBuilder(
35
+ this.CanvasKit,
36
+ this.CanvasKit.ParagraphBuilder.MakeFromFontProvider(
37
+ style,
38
+ JsiSkTypeface.fromValue(typefaceProvider)
39
+ )
40
+ );
41
+ }
42
+ }
@@ -0,0 +1,65 @@
1
+ import type { CanvasKit, ParagraphStyle } from "canvaskit-wasm";
2
+
3
+ import { SkTextDirection, type SkParagraphStyle } from "../types";
4
+
5
+ export class JsiSkParagraphStyle {
6
+ static toParagraphStyle(
7
+ ck: CanvasKit,
8
+ value: SkParagraphStyle
9
+ ): ParagraphStyle {
10
+ // Seems like we need to provide the textStyle.color value, otherwise
11
+ // the constructor crashes.
12
+ const ps = new ck.ParagraphStyle({ textStyle: { color: ck.BLACK } });
13
+
14
+ ps.disableHinting = value.disableHinting ?? ps.disableHinting;
15
+ ps.ellipsis = value.ellipsis ?? ps.ellipsis;
16
+ ps.heightMultiplier = value.heightMultiplier ?? ps.heightMultiplier;
17
+ ps.maxLines = value.maxLines ?? ps.maxLines;
18
+ ps.replaceTabCharacters =
19
+ value.replaceTabCharacters ?? ps.replaceTabCharacters;
20
+ ps.textAlign =
21
+ value.textAlign !== undefined
22
+ ? { value: value.textAlign }
23
+ : undefined ?? ps.textAlign;
24
+ ps.textDirection =
25
+ value.textDirection !== undefined
26
+ ? { value: value.textDirection === SkTextDirection.LTR ? 1 : 0 }
27
+ : ps.textDirection;
28
+ ps.textHeightBehavior =
29
+ value.textHeightBehavior !== undefined
30
+ ? { value: value.textHeightBehavior }
31
+ : ps.textHeightBehavior;
32
+
33
+ ps.strutStyle = ps.strutStyle ?? {};
34
+ ps.strutStyle.fontFamilies =
35
+ value.strutStyle?.fontFamilies ?? ps.strutStyle.fontFamilies;
36
+ ps.strutStyle.fontSize =
37
+ value.strutStyle?.fontSize ?? ps.strutStyle.fontSize;
38
+ ps.strutStyle.heightMultiplier =
39
+ value.strutStyle?.heightMultiplier ?? ps.strutStyle.heightMultiplier;
40
+ ps.strutStyle.leading = value.strutStyle?.leading ?? ps.strutStyle.leading;
41
+ ps.strutStyle.forceStrutHeight =
42
+ value.strutStyle?.forceStrutHeight ?? ps.strutStyle.forceStrutHeight;
43
+
44
+ ps.strutStyle.fontStyle = ps.strutStyle.fontStyle ?? {};
45
+
46
+ ps.strutStyle.fontStyle.slant =
47
+ value.strutStyle?.fontStyle?.slant !== undefined
48
+ ? { value: value.strutStyle.fontStyle.slant }
49
+ : ps.strutStyle.fontStyle.slant;
50
+ ps.strutStyle.fontStyle.width =
51
+ value.strutStyle?.fontStyle?.width !== undefined
52
+ ? { value: value.strutStyle.fontStyle.width }
53
+ : ps.strutStyle.fontStyle.width;
54
+ ps.strutStyle.fontStyle.weight =
55
+ value.strutStyle?.fontStyle?.weight !== undefined
56
+ ? { value: value.strutStyle.fontStyle.weight }
57
+ : ps.strutStyle.fontStyle.weight;
58
+ ps.strutStyle.halfLeading =
59
+ value.strutStyle?.halfLeading ?? ps.strutStyle.halfLeading;
60
+ ps.strutStyle.strutEnabled =
61
+ value.strutStyle?.strutEnabled ?? ps.strutStyle.strutEnabled;
62
+
63
+ return ps;
64
+ }
65
+ }
@@ -0,0 +1,53 @@
1
+ import type { TextStyle } from "canvaskit-wasm";
2
+
3
+ import type { SkTextStyle } from "../types";
4
+
5
+ export class JsiSkTextStyle {
6
+ static toTextStyle(value: SkTextStyle): TextStyle {
7
+ return {
8
+ backgroundColor: value.backgroundColor,
9
+ color: value.color,
10
+ decoration: value.decoration,
11
+ decorationColor: value.decorationColor,
12
+ decorationStyle: value.decorationStyle
13
+ ? { value: value.decorationStyle }
14
+ : undefined,
15
+ decorationThickness: value.decorationThickness,
16
+ fontFamilies: value.fontFamilies,
17
+ fontSize: value.fontSize,
18
+ fontStyle: value.fontStyle
19
+ ? {
20
+ slant: value.fontStyle.slant
21
+ ? { value: value.fontStyle.slant }
22
+ : undefined,
23
+ weight: value.fontStyle.weight
24
+ ? { value: value.fontStyle.weight }
25
+ : undefined,
26
+ width: value.fontStyle.width
27
+ ? { value: value.fontStyle.width }
28
+ : undefined,
29
+ }
30
+ : undefined,
31
+ fontFeatures: value.fontFeatures,
32
+ foregroundColor: value.foregroundColor,
33
+ fontVariations: value.fontVariations,
34
+ halfLeading: value.halfLeading,
35
+ heightMultiplier: value.heightMultiplier,
36
+ letterSpacing: value.letterSpacing,
37
+ locale: value.locale,
38
+ shadows: value.shadows
39
+ ? value.shadows.map((shadow) => ({
40
+ blurRadius: shadow.blurRadius,
41
+ color: shadow.color,
42
+ offset: shadow.offset
43
+ ? [shadow.offset.x, shadow.offset.y]
44
+ : undefined,
45
+ }))
46
+ : undefined,
47
+ textBaseline: value.textBaseline
48
+ ? { value: value.textBaseline }
49
+ : undefined,
50
+ wordSpacing: value.wordSpacing,
51
+ };
52
+ }
53
+ }
@@ -40,6 +40,7 @@ import { JsiSkTypeface } from "./JsiSkTypeface";
40
40
  import { JsiSkTypefaceFontProviderFactory } from "./JsiSkTypefaceFontProviderFactory";
41
41
  import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
42
42
  import { JsiSkAnimatedImageFactory } from "./JsiSkAnimatedImageFactory";
43
+ import { JsiSkParagraphBuilderFactory } from "./JsiSkParagraphBuilderFactory";
43
44
 
44
45
  export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
45
46
  Point: (x: number, y: number) =>
@@ -108,4 +109,5 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
108
109
  Surface: new JsiSkSurfaceFactory(CanvasKit),
109
110
  TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),
110
111
  FontMgr: new JsiSkFontMgrFactory(CanvasKit),
112
+ ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),
111
113
  });