@shopify/react-native-skia 0.1.207 → 0.1.209

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 (131) hide show
  1. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +19 -12
  2. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +1 -1
  3. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomView.java +1 -1
  4. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +1 -1
  5. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +1 -1
  6. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +2 -0
  7. package/cpp/api/JsiSkColorFilter.h +1 -1
  8. package/cpp/api/JsiSkContourMeasure.h +1 -1
  9. package/cpp/api/JsiSkContourMeasureIter.h +1 -1
  10. package/cpp/api/JsiSkData.h +1 -1
  11. package/cpp/api/JsiSkFont.h +1 -1
  12. package/cpp/api/JsiSkFontMgr.h +2 -2
  13. package/cpp/api/JsiSkFontStyle.h +11 -5
  14. package/cpp/api/JsiSkImage.h +1 -1
  15. package/cpp/api/JsiSkImageFilter.h +1 -1
  16. package/cpp/api/JsiSkMaskFilter.h +1 -1
  17. package/cpp/api/JsiSkMatrix.h +1 -1
  18. package/cpp/api/JsiSkPaint.h +8 -1
  19. package/cpp/api/JsiSkPath.h +11 -8
  20. package/cpp/api/JsiSkPathEffect.h +1 -1
  21. package/cpp/api/JsiSkPicture.h +1 -1
  22. package/cpp/api/JsiSkPictureRecorder.h +1 -1
  23. package/cpp/api/JsiSkRuntimeEffect.h +1 -1
  24. package/cpp/api/JsiSkSVG.h +1 -1
  25. package/cpp/api/JsiSkShader.h +1 -1
  26. package/cpp/api/JsiSkSurface.h +1 -1
  27. package/cpp/api/JsiSkTextBlob.h +1 -1
  28. package/cpp/api/JsiSkTypeFaceFontProvider.h +4 -2
  29. package/cpp/api/JsiSkTypeface.h +24 -2
  30. package/cpp/api/JsiSkVertices.h +1 -1
  31. package/cpp/rnskia/dom/base/JsiDomRenderNode.h +1 -1
  32. package/cpp/rnskia/dom/nodes/JsiPaintNode.h +4 -0
  33. package/cpp/rnskia/dom/props/FontProp.h +3 -1
  34. package/cpp/rnskia/dom/props/PaintProps.h +3 -0
  35. package/lib/commonjs/dom/nodes/PaintContext.d.ts +1 -0
  36. package/lib/commonjs/dom/nodes/PaintContext.js.map +1 -1
  37. package/lib/commonjs/dom/nodes/PaintNode.js +6 -1
  38. package/lib/commonjs/dom/nodes/PaintNode.js.map +1 -1
  39. package/lib/commonjs/dom/nodes/RenderNode.js +1 -1
  40. package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
  41. package/lib/commonjs/dom/nodes/drawings/Text.d.ts +3 -3
  42. package/lib/commonjs/dom/nodes/drawings/Text.js +26 -4
  43. package/lib/commonjs/dom/nodes/drawings/Text.js.map +1 -1
  44. package/lib/commonjs/dom/types/Common.d.ts +1 -0
  45. package/lib/commonjs/dom/types/Common.js.map +1 -1
  46. package/lib/commonjs/dom/types/DrawingContext.js +15 -0
  47. package/lib/commonjs/dom/types/DrawingContext.js.map +1 -1
  48. package/lib/commonjs/dom/types/Drawings.d.ts +1 -1
  49. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  50. package/lib/commonjs/external/reanimated/moduleWrapper.js +1 -1
  51. package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -1
  52. package/lib/commonjs/skia/types/Font/FontMgr.d.ts +1 -1
  53. package/lib/commonjs/skia/types/Font/FontMgr.js.map +1 -1
  54. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +12 -11
  55. package/lib/commonjs/skia/types/Image/ImageFactory.js +12 -11
  56. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  57. package/lib/commonjs/skia/types/Paint/Paint.d.ts +5 -0
  58. package/lib/commonjs/skia/types/Paint/Paint.js.map +1 -1
  59. package/lib/commonjs/skia/types/Typeface/Typeface.d.ts +10 -1
  60. package/lib/commonjs/skia/types/Typeface/Typeface.js.map +1 -1
  61. package/lib/commonjs/skia/web/JsiSkPaint.d.ts +1 -0
  62. package/lib/commonjs/skia/web/JsiSkPaint.js +4 -0
  63. package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
  64. package/lib/commonjs/skia/web/JsiSkPath.d.ts +1 -1
  65. package/lib/commonjs/skia/web/JsiSkPath.js +10 -1
  66. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  67. package/lib/commonjs/skia/web/JsiSkTypeface.d.ts +1 -0
  68. package/lib/commonjs/skia/web/JsiSkTypeface.js +4 -0
  69. package/lib/commonjs/skia/web/JsiSkTypeface.js.map +1 -1
  70. package/lib/module/dom/nodes/PaintContext.d.ts +1 -0
  71. package/lib/module/dom/nodes/PaintContext.js.map +1 -1
  72. package/lib/module/dom/nodes/PaintNode.js +6 -1
  73. package/lib/module/dom/nodes/PaintNode.js.map +1 -1
  74. package/lib/module/dom/nodes/RenderNode.js +1 -1
  75. package/lib/module/dom/nodes/RenderNode.js.map +1 -1
  76. package/lib/module/dom/nodes/drawings/Text.d.ts +3 -3
  77. package/lib/module/dom/nodes/drawings/Text.js +26 -4
  78. package/lib/module/dom/nodes/drawings/Text.js.map +1 -1
  79. package/lib/module/dom/types/Common.d.ts +1 -0
  80. package/lib/module/dom/types/Common.js.map +1 -1
  81. package/lib/module/dom/types/DrawingContext.js +15 -0
  82. package/lib/module/dom/types/DrawingContext.js.map +1 -1
  83. package/lib/module/dom/types/Drawings.d.ts +1 -1
  84. package/lib/module/dom/types/Drawings.js.map +1 -1
  85. package/lib/module/external/reanimated/moduleWrapper.js +1 -1
  86. package/lib/module/external/reanimated/moduleWrapper.js.map +1 -1
  87. package/lib/module/skia/types/Font/FontMgr.d.ts +1 -1
  88. package/lib/module/skia/types/Font/FontMgr.js.map +1 -1
  89. package/lib/module/skia/types/Image/ImageFactory.d.ts +12 -11
  90. package/lib/module/skia/types/Image/ImageFactory.js +12 -11
  91. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  92. package/lib/module/skia/types/Paint/Paint.d.ts +5 -0
  93. package/lib/module/skia/types/Paint/Paint.js.map +1 -1
  94. package/lib/module/skia/types/Typeface/Typeface.d.ts +10 -1
  95. package/lib/module/skia/types/Typeface/Typeface.js.map +1 -1
  96. package/lib/module/skia/web/JsiSkPaint.d.ts +1 -0
  97. package/lib/module/skia/web/JsiSkPaint.js +4 -0
  98. package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
  99. package/lib/module/skia/web/JsiSkPath.d.ts +1 -1
  100. package/lib/module/skia/web/JsiSkPath.js +11 -1
  101. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  102. package/lib/module/skia/web/JsiSkTypeface.d.ts +1 -0
  103. package/lib/module/skia/web/JsiSkTypeface.js +4 -0
  104. package/lib/module/skia/web/JsiSkTypeface.js.map +1 -1
  105. package/lib/typescript/src/dom/nodes/PaintContext.d.ts +1 -0
  106. package/lib/typescript/src/dom/nodes/drawings/Text.d.ts +3 -3
  107. package/lib/typescript/src/dom/types/Common.d.ts +1 -0
  108. package/lib/typescript/src/dom/types/Drawings.d.ts +1 -1
  109. package/lib/typescript/src/skia/types/Font/FontMgr.d.ts +1 -1
  110. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +12 -11
  111. package/lib/typescript/src/skia/types/Paint/Paint.d.ts +5 -0
  112. package/lib/typescript/src/skia/types/Typeface/Typeface.d.ts +10 -1
  113. package/lib/typescript/src/skia/web/JsiSkPaint.d.ts +1 -0
  114. package/lib/typescript/src/skia/web/JsiSkPath.d.ts +1 -1
  115. package/lib/typescript/src/skia/web/JsiSkTypeface.d.ts +1 -0
  116. package/package.json +2 -2
  117. package/src/dom/nodes/PaintContext.ts +1 -0
  118. package/src/dom/nodes/PaintNode.ts +4 -0
  119. package/src/dom/nodes/RenderNode.ts +1 -0
  120. package/src/dom/nodes/drawings/Text.ts +31 -5
  121. package/src/dom/types/Common.ts +1 -0
  122. package/src/dom/types/DrawingContext.ts +13 -0
  123. package/src/dom/types/Drawings.ts +1 -1
  124. package/src/external/reanimated/moduleWrapper.ts +1 -1
  125. package/src/skia/types/Font/FontMgr.ts +1 -1
  126. package/src/skia/types/Image/ImageFactory.ts +1 -0
  127. package/src/skia/types/Paint/Paint.ts +6 -0
  128. package/src/skia/types/Typeface/Typeface.ts +10 -1
  129. package/src/skia/web/JsiSkPaint.ts +4 -0
  130. package/src/skia/web/JsiSkPath.ts +8 -1
  131. package/src/skia/web/JsiSkTypeface.ts +4 -0
@@ -1,4 +1,9 @@
1
- import type { SkRSXform, SkTextBlob, SkPoint } from "../../../skia/types";
1
+ import type {
2
+ SkRSXform,
3
+ SkTextBlob,
4
+ SkPoint,
5
+ SkFont,
6
+ } from "../../../skia/types";
2
7
  import type {
3
8
  DrawingContext,
4
9
  TextBlobProps,
@@ -11,18 +16,39 @@ import type { GlyphsProps } from "../../types/Drawings";
11
16
  import { JsiDrawingNode } from "../DrawingNode";
12
17
  import type { NodeContext } from "../Node";
13
18
 
14
- export class TextNode extends JsiDrawingNode<TextProps, null> {
19
+ export class TextNode extends JsiDrawingNode<TextProps, SkFont | null> {
15
20
  constructor(ctx: NodeContext, props: TextProps) {
16
21
  super(ctx, NodeType.Text, props);
17
22
  }
18
23
 
19
24
  protected deriveProps() {
20
- return null;
25
+ const { font } = this.props;
26
+ if (font === null) {
27
+ return null;
28
+ } else if (font === undefined) {
29
+ console.warn(
30
+ "<Text />: the font property is mandatory on React Native Web"
31
+ );
32
+ return null;
33
+ // return this.Skia.Font(
34
+ // this.Skia.FontMgr.System().matchFamilyStyle("System", {
35
+ // width: 5,
36
+ // weight: 400,
37
+ // slant: 0,
38
+ // }),
39
+ // 14
40
+ // );
41
+ }
42
+ return font;
21
43
  }
22
44
 
23
45
  draw({ canvas, paint }: DrawingContext) {
24
- const { text, x, y, font } = this.props;
25
- if (font) {
46
+ const { text, x, y } = this.props;
47
+ const font = this.derived;
48
+ if (font === undefined) {
49
+ throw new Error("TextNode: font hasn't been derived");
50
+ }
51
+ if (font != null) {
26
52
  canvas.drawText(text, x, y, paint, font);
27
53
  }
28
54
  }
@@ -79,6 +79,7 @@ export interface PaintProps extends ChildrenProps {
79
79
  strokeMiter?: number;
80
80
  opacity?: number;
81
81
  antiAlias?: boolean;
82
+ dither?: boolean;
82
83
  }
83
84
 
84
85
  export interface GroupProps extends PaintProps, TransformProps {
@@ -76,6 +76,7 @@ class ConcatablePaint {
76
76
  _strokeMiter?: number;
77
77
  _opacity = 1;
78
78
  _antiAlias?: boolean;
79
+ _dither?: boolean;
79
80
 
80
81
  _imageFilter?: SkImageFilter;
81
82
  _shader?: SkShader;
@@ -97,6 +98,7 @@ class ConcatablePaint {
97
98
  this.setStrokeMiter(props.strokeMiter);
98
99
  this.setOpacity(props.opacity);
99
100
  this.setAntiAlias(props.antiAlias);
101
+ this.setDither(props.dither);
100
102
  declCtx.save();
101
103
  children.forEach((child) => {
102
104
  if (child instanceof JsiDeclarationNode) {
@@ -215,6 +217,14 @@ class ConcatablePaint {
215
217
  return this._antiAlias;
216
218
  }
217
219
 
220
+ setDither(dither?: boolean) {
221
+ this.setValue("_dither", dither);
222
+ }
223
+
224
+ getDither() {
225
+ return this._dither;
226
+ }
227
+
218
228
  setImageFilter(imageFilter?: SkImageFilter) {
219
229
  this.setValue("_imageFilter", imageFilter);
220
230
  }
@@ -290,6 +300,9 @@ class ConcatablePaint {
290
300
  if (this._antiAlias !== undefined) {
291
301
  paint.setAntiAlias(this._antiAlias);
292
302
  }
303
+ if (this._dither !== undefined) {
304
+ paint.setDither(this._dither);
305
+ }
293
306
  if (this._imageFilter !== undefined) {
294
307
  paint.setImageFilter(this._imageFilter);
295
308
  }
@@ -114,7 +114,7 @@ export interface DiffRectProps extends DrawingNodeProps {
114
114
  }
115
115
 
116
116
  export interface TextProps extends DrawingNodeProps {
117
- font: SkFont | null;
117
+ font?: SkFont | null;
118
118
  text: string;
119
119
  x: number;
120
120
  y: number;
@@ -30,7 +30,7 @@ function throwOnMissingReanimated2() {
30
30
  if (!HAS_REANIMATED2) {
31
31
  throw new Error(
32
32
  "Reanimated was not found, make sure react-native-reanimated package is installed if you want to use \
33
- react-naitve-skia's integration layer API."
33
+ react-native-skia's integration layer API."
34
34
  );
35
35
  }
36
36
  }
@@ -6,5 +6,5 @@ import type { FontStyle } from "./Font";
6
6
  export interface SkFontMgr extends SkJSIInstance<"FontMgr"> {
7
7
  countFamilies(): number;
8
8
  getFamilyName(index: number): string;
9
- matchFamilyStyle(name: string, style: FontStyle): SkTypeface;
9
+ matchFamilyStyle(name?: string, style?: FontStyle): SkTypeface;
10
10
  }
@@ -21,6 +21,7 @@ export enum ColorType {
21
21
  BGRA_1010102, //!< 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word
22
22
  RGB_101010x, //!< pixel with 10 bits each for red, green, blue; in 32-bit word
23
23
  BGR_101010x, //!< pixel with 10 bits each for blue, green, red; in 32-bit word
24
+ BGR_101010x_XR, //!< pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
24
25
  Gray_8, //!< pixel with grayscale level in 8-bit byte
25
26
  RGBA_F16Norm, //!< pixel with half floats in [0,1] for red, green, blue, alpha;
26
27
  // in 64-bit word
@@ -84,6 +84,12 @@ export interface SkPaint extends SkJSIInstance<"Paint"> {
84
84
  */
85
85
  setAntiAlias: (aa: boolean) => void;
86
86
 
87
+ /**
88
+ * Requests, but does not require, to distribute color error.
89
+ * @param dither
90
+ */
91
+ setDither: (dither: boolean) => void;
92
+
87
93
  /**
88
94
  * Sets the blend mode that is, the mode used to combine source color
89
95
  * with destination color.
@@ -1,3 +1,12 @@
1
1
  import type { SkJSIInstance } from "../JsiInstance";
2
2
 
3
- export type SkTypeface = SkJSIInstance<"Typeface">;
3
+ export interface SkTypeface extends SkJSIInstance<"Typeface"> {
4
+ /**
5
+ * Retrieves the glyph ids for each code point in the provided string. This call is passed to
6
+ * the typeface of this font. Note that glyph IDs are typeface-dependent; different faces
7
+ * may have different ids for the same code point.
8
+ * @param str
9
+ * @param numCodePoints - the number of code points in the string. Defaults to str.length.
10
+ */
11
+ getGlyphIDs(str: string, numCodePoints?: number): number[];
12
+ }
@@ -70,6 +70,10 @@ export class JsiSkPaint extends HostObject<Paint, "Paint"> implements SkPaint {
70
70
  this.ref.setAntiAlias(aa);
71
71
  }
72
72
 
73
+ setDither(dither: boolean) {
74
+ this.ref.setDither(dither);
75
+ }
76
+
73
77
  setBlendMode(blendMode: BlendMode) {
74
78
  this.ref.setBlendMode(ckEnum(blendMode));
75
79
  }
@@ -28,6 +28,8 @@ const CommandCount = {
28
28
  [PathVerb.Close]: 1,
29
29
  };
30
30
 
31
+ const pinT = (t: number) => Math.min(Math.max(t, 0), 1);
32
+
31
33
  export class JsiSkPath extends HostObject<Path, "Path"> implements SkPath {
32
34
  constructor(CanvasKit: CanvasKit, ref: Path) {
33
35
  super(CanvasKit, ref, "Path");
@@ -317,7 +319,12 @@ export class JsiSkPath extends HostObject<Path, "Path"> implements SkPath {
317
319
  return this.ref.toSVGString();
318
320
  }
319
321
 
320
- trim(startT: number, stopT: number, isComplement: boolean) {
322
+ trim(start: number, stop: number, isComplement: boolean) {
323
+ const startT = pinT(start);
324
+ const stopT = pinT(stop);
325
+ if (startT === 0 && stopT === 1) {
326
+ return this;
327
+ }
321
328
  const result = this.ref.trim(startT, stopT, isComplement);
322
329
  return result === null ? result : this;
323
330
  }
@@ -26,6 +26,10 @@ export class JsiSkTypeface
26
26
  return false;
27
27
  }
28
28
 
29
+ getGlyphIDs(str: string, numCodePoints?: number) {
30
+ return Array.from(this.ref.getGlyphIDs(str, numCodePoints));
31
+ }
32
+
29
33
  dispose = () => {
30
34
  this.ref.delete();
31
35
  };