@shopify/react-native-skia 1.3.6 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +14 -7
  2. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +1 -2
  3. package/cpp/api/JsiSkTypefaceFontProvider.h +14 -4
  4. package/lib/commonjs/dom/nodes/Node.d.ts +2 -3
  5. package/lib/commonjs/dom/nodes/Node.js +1 -2
  6. package/lib/commonjs/dom/nodes/Node.js.map +1 -1
  7. package/lib/commonjs/dom/nodes/PaintNode.js +1 -1
  8. package/lib/commonjs/dom/nodes/PaintNode.js.map +1 -1
  9. package/lib/commonjs/dom/nodes/drawings/Box.js +1 -1
  10. package/lib/commonjs/dom/nodes/drawings/Box.js.map +1 -1
  11. package/lib/commonjs/dom/nodes/paint/BlendNode.js +1 -1
  12. package/lib/commonjs/dom/nodes/paint/BlendNode.js.map +1 -1
  13. package/lib/commonjs/dom/nodes/paint/ColorFilters.js +1 -1
  14. package/lib/commonjs/dom/nodes/paint/ColorFilters.js.map +1 -1
  15. package/lib/commonjs/dom/nodes/paint/ImageFilters.js +1 -1
  16. package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
  17. package/lib/commonjs/dom/nodes/paint/MaskFilters.js +1 -1
  18. package/lib/commonjs/dom/nodes/paint/MaskFilters.js.map +1 -1
  19. package/lib/commonjs/dom/nodes/paint/PathEffects.js +1 -1
  20. package/lib/commonjs/dom/nodes/paint/PathEffects.js.map +1 -1
  21. package/lib/commonjs/dom/nodes/paint/Shaders.js +1 -1
  22. package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
  23. package/lib/commonjs/dom/types/Node.d.ts +1 -2
  24. package/lib/commonjs/dom/types/Node.js.map +1 -1
  25. package/lib/commonjs/dom/types/NodeType.d.ts +0 -9
  26. package/lib/commonjs/dom/types/NodeType.js +1 -11
  27. package/lib/commonjs/dom/types/NodeType.js.map +1 -1
  28. package/lib/commonjs/external/reanimated/useVideo.js +0 -2
  29. package/lib/commonjs/external/reanimated/useVideo.js.map +1 -1
  30. package/lib/commonjs/external/reanimated/useVideoLoading.js +6 -4
  31. package/lib/commonjs/external/reanimated/useVideoLoading.js.map +1 -1
  32. package/lib/commonjs/skia/core/SVG.web.d.ts +2 -0
  33. package/lib/commonjs/skia/core/SVG.web.js +22 -0
  34. package/lib/commonjs/skia/core/SVG.web.js.map +1 -0
  35. package/lib/commonjs/skia/types/Font/FontMgr.d.ts +1 -1
  36. package/lib/commonjs/skia/types/Font/FontMgr.js.map +1 -1
  37. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js +1 -1
  38. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  39. package/lib/commonjs/skia/web/JsiSkCanvas.d.ts +1 -1
  40. package/lib/commonjs/skia/web/JsiSkCanvas.js +3 -2
  41. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  42. package/lib/commonjs/skia/web/JsiSkSVG.d.ts +9 -0
  43. package/lib/commonjs/skia/web/JsiSkSVG.js +28 -0
  44. package/lib/commonjs/skia/web/JsiSkSVG.js.map +1 -0
  45. package/lib/commonjs/skia/web/JsiSkSVGFactory.d.ts +4 -3
  46. package/lib/commonjs/skia/web/JsiSkSVGFactory.js +40 -4
  47. package/lib/commonjs/skia/web/JsiSkSVGFactory.js.map +1 -1
  48. package/lib/module/dom/nodes/Node.d.ts +2 -3
  49. package/lib/module/dom/nodes/Node.js +1 -2
  50. package/lib/module/dom/nodes/Node.js.map +1 -1
  51. package/lib/module/dom/nodes/PaintNode.js +2 -2
  52. package/lib/module/dom/nodes/PaintNode.js.map +1 -1
  53. package/lib/module/dom/nodes/drawings/Box.js +2 -2
  54. package/lib/module/dom/nodes/drawings/Box.js.map +1 -1
  55. package/lib/module/dom/nodes/paint/BlendNode.js +2 -2
  56. package/lib/module/dom/nodes/paint/BlendNode.js.map +1 -1
  57. package/lib/module/dom/nodes/paint/ColorFilters.js +2 -2
  58. package/lib/module/dom/nodes/paint/ColorFilters.js.map +1 -1
  59. package/lib/module/dom/nodes/paint/ImageFilters.js +2 -2
  60. package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
  61. package/lib/module/dom/nodes/paint/MaskFilters.js +2 -2
  62. package/lib/module/dom/nodes/paint/MaskFilters.js.map +1 -1
  63. package/lib/module/dom/nodes/paint/PathEffects.js +2 -2
  64. package/lib/module/dom/nodes/paint/PathEffects.js.map +1 -1
  65. package/lib/module/dom/nodes/paint/Shaders.js +2 -2
  66. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  67. package/lib/module/dom/types/Node.d.ts +1 -2
  68. package/lib/module/dom/types/Node.js.map +1 -1
  69. package/lib/module/dom/types/NodeType.d.ts +0 -9
  70. package/lib/module/dom/types/NodeType.js +0 -10
  71. package/lib/module/dom/types/NodeType.js.map +1 -1
  72. package/lib/module/external/reanimated/useVideo.js +0 -2
  73. package/lib/module/external/reanimated/useVideo.js.map +1 -1
  74. package/lib/module/external/reanimated/useVideoLoading.js +7 -5
  75. package/lib/module/external/reanimated/useVideoLoading.js.map +1 -1
  76. package/lib/module/skia/core/SVG.web.d.ts +2 -0
  77. package/lib/module/skia/core/SVG.web.js +15 -0
  78. package/lib/module/skia/core/SVG.web.js.map +1 -0
  79. package/lib/module/skia/types/Font/FontMgr.d.ts +1 -1
  80. package/lib/module/skia/types/Font/FontMgr.js.map +1 -1
  81. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js +1 -1
  82. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  83. package/lib/module/skia/web/JsiSkCanvas.d.ts +1 -1
  84. package/lib/module/skia/web/JsiSkCanvas.js +3 -2
  85. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  86. package/lib/module/skia/web/JsiSkSVG.d.ts +9 -0
  87. package/lib/module/skia/web/JsiSkSVG.js +21 -0
  88. package/lib/module/skia/web/JsiSkSVG.js.map +1 -0
  89. package/lib/module/skia/web/JsiSkSVGFactory.d.ts +4 -3
  90. package/lib/module/skia/web/JsiSkSVGFactory.js +41 -5
  91. package/lib/module/skia/web/JsiSkSVGFactory.js.map +1 -1
  92. package/lib/typescript/src/dom/nodes/Node.d.ts +2 -3
  93. package/lib/typescript/src/dom/types/Node.d.ts +1 -2
  94. package/lib/typescript/src/dom/types/NodeType.d.ts +0 -9
  95. package/lib/typescript/src/skia/core/SVG.web.d.ts +2 -0
  96. package/lib/typescript/src/skia/types/Font/FontMgr.d.ts +1 -1
  97. package/lib/typescript/src/skia/web/JsiSkCanvas.d.ts +1 -1
  98. package/lib/typescript/src/skia/web/JsiSkSVG.d.ts +9 -0
  99. package/lib/typescript/src/skia/web/JsiSkSVGFactory.d.ts +4 -3
  100. package/package.json +2 -2
  101. package/src/dom/nodes/Node.ts +2 -12
  102. package/src/dom/nodes/PaintNode.ts +2 -2
  103. package/src/dom/nodes/drawings/Box.ts +2 -2
  104. package/src/dom/nodes/paint/BlendNode.ts +2 -2
  105. package/src/dom/nodes/paint/ColorFilters.ts +2 -2
  106. package/src/dom/nodes/paint/ImageFilters.ts +2 -2
  107. package/src/dom/nodes/paint/MaskFilters.ts +2 -2
  108. package/src/dom/nodes/paint/PathEffects.ts +2 -2
  109. package/src/dom/nodes/paint/Shaders.ts +2 -2
  110. package/src/dom/types/Node.ts +2 -2
  111. package/src/dom/types/NodeType.ts +0 -10
  112. package/src/external/reanimated/useVideo.ts +0 -2
  113. package/src/external/reanimated/useVideoLoading.ts +11 -8
  114. package/src/skia/core/SVG.web.ts +29 -0
  115. package/src/skia/types/Font/FontMgr.ts +1 -1
  116. package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +1 -1
  117. package/src/skia/web/JsiSkCanvas.ts +6 -2
  118. package/src/skia/web/JsiSkSVG.ts +27 -0
  119. package/src/skia/web/JsiSkSVGFactory.ts +47 -6
@@ -1,5 +1,5 @@
1
1
  import type { Skia } from "../../skia/types";
2
- import type { Node, DeclarationNode, NodeType, DeclarationType } from "../types";
2
+ import type { Node, DeclarationNode, NodeType } from "../types";
3
3
  import type { DeclarationContext } from "../types/DeclarationContext";
4
4
  export interface NodeContext {
5
5
  Skia: Skia;
@@ -21,9 +21,8 @@ export declare abstract class JsiNode<P> implements Node<P> {
21
21
  }
22
22
  export type Invalidate = () => void;
23
23
  export declare abstract class JsiDeclarationNode<P> extends JsiNode<P> implements DeclarationNode<P> {
24
- declarationType: DeclarationType;
25
24
  private invalidate;
26
- constructor(ctx: NodeContext, declarationType: DeclarationType, type: NodeType, props: P);
25
+ constructor(ctx: NodeContext, type: NodeType, props: P);
27
26
  abstract decorate(ctx: DeclarationContext): void;
28
27
  protected decorateChildren(ctx: DeclarationContext): void;
29
28
  addChild(child: Node<unknown>): void;
@@ -1,5 +1,5 @@
1
1
  import type { GroupProps } from "./Common";
2
- import type { DeclarationType, NodeType } from "./NodeType";
2
+ import type { NodeType } from "./NodeType";
3
3
  import type { DeclarationContext } from "./DeclarationContext";
4
4
  import type { DrawingContext } from "./DrawingContext";
5
5
  export interface Node<P> {
@@ -14,7 +14,6 @@ export interface Node<P> {
14
14
  }
15
15
  export type Invalidate = () => void;
16
16
  export interface DeclarationNode<P> extends Node<P> {
17
- declarationType: DeclarationType;
18
17
  decorate(ctx: DeclarationContext): void;
19
18
  setInvalidate(invalidate: Invalidate): void;
20
19
  }
@@ -57,12 +57,3 @@ export declare const enum NodeType {
57
57
  Atlas = "skAtlas",
58
58
  Paragraph = "skParagraph"
59
59
  }
60
- export declare const enum DeclarationType {
61
- Paint = 0,
62
- Shader = 1,
63
- ImageFilter = 2,
64
- ColorFilter = 3,
65
- PathEffect = 4,
66
- MaskFilter = 5,
67
- Unknown = 6
68
- }
@@ -0,0 +1,2 @@
1
+ import type { DataSourceParam } from "../types";
2
+ export declare const useSVG: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => import("../types").SkSVG | null;
@@ -4,5 +4,5 @@ import type { FontStyle } from "./Font";
4
4
  export interface SkFontMgr extends SkJSIInstance<"FontMgr"> {
5
5
  countFamilies(): number;
6
6
  getFamilyName(index: number): string;
7
- matchFamilyStyle(name?: string, style?: FontStyle): SkTypeface;
7
+ matchFamilyStyle(name: string, style: FontStyle): SkTypeface;
8
8
  }
@@ -27,7 +27,7 @@ export declare class JsiSkCanvas extends HostObject<Canvas, "Canvas"> implements
27
27
  drawText(str: string, x: number, y: number, paint: SkPaint, font: SkFont): void;
28
28
  drawTextBlob(blob: SkTextBlob, x: number, y: number, paint: SkPaint): void;
29
29
  drawGlyphs(glyphs: number[], positions: SkPoint[], x: number, y: number, font: SkFont, paint: SkPaint): void;
30
- drawSvg(_svgDom: SkSVG, _width?: number, _height?: number): void;
30
+ drawSvg(svg: SkSVG, _width?: number, _height?: number): void;
31
31
  save(): number;
32
32
  saveLayer(paint?: SkPaint, bounds?: SkRect | null, backdrop?: SkImageFilter | null, flags?: SaveLayerFlag): number;
33
33
  restore(): void;
@@ -0,0 +1,9 @@
1
+ import type { CanvasKit } from "canvaskit-wasm";
2
+ import type { SkSVG } from "../types";
3
+ import { HostObject } from "./Host";
4
+ export declare class JsiSkSVG extends HostObject<HTMLImageElement, "SVG"> implements SkSVG {
5
+ constructor(CanvasKit: CanvasKit, ref: HTMLImageElement);
6
+ width(): number;
7
+ height(): number;
8
+ dispose: () => void;
9
+ }
@@ -1,9 +1,10 @@
1
1
  import type { CanvasKit } from "canvaskit-wasm";
2
- import type { SkData, SkSVG } from "../types";
2
+ import type { SkSVG } from "../types";
3
3
  import type { SVGFactory } from "../types/SVG/SVGFactory";
4
4
  import { Host } from "./Host";
5
+ import type { JsiSkData } from "./JsiSkData";
5
6
  export declare class JsiSkSVGFactory extends Host implements SVGFactory {
6
7
  constructor(CanvasKit: CanvasKit);
7
- MakeFromData(_data: SkData): SkSVG | null;
8
- MakeFromString(_str: string): SkSVG | null;
8
+ MakeFromData(data: JsiSkData): SkSVG | null;
9
+ MakeFromString(str: string): SkSVG | null;
9
10
  }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "setup-skia-web": "./scripts/setup-canvaskit.js"
8
8
  },
9
9
  "title": "React Native Skia",
10
- "version": "1.3.6",
10
+ "version": "1.3.8",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "react-native": "src/index.ts",
@@ -108,7 +108,7 @@
108
108
  "react-native-reanimated": "3.6.2",
109
109
  "ts-jest": "29.1.1",
110
110
  "typescript": "5.1.6",
111
- "ws": "8.11.0"
111
+ "ws": "8.17.1"
112
112
  },
113
113
  "dependencies": {
114
114
  "canvaskit-wasm": "0.39.1",
@@ -1,10 +1,5 @@
1
1
  import type { Skia } from "../../skia/types";
2
- import type {
3
- Node,
4
- DeclarationNode,
5
- NodeType,
6
- DeclarationType,
7
- } from "../types";
2
+ import type { Node, DeclarationNode, NodeType } from "../types";
8
3
  import type { DeclarationContext } from "../types/DeclarationContext";
9
4
 
10
5
  export interface NodeContext {
@@ -72,12 +67,7 @@ export abstract class JsiDeclarationNode<P>
72
67
  {
73
68
  private invalidate: Invalidate = () => {};
74
69
 
75
- constructor(
76
- ctx: NodeContext,
77
- public declarationType: DeclarationType,
78
- type: NodeType,
79
- props: P
80
- ) {
70
+ constructor(ctx: NodeContext, type: NodeType, props: P) {
81
71
  super(ctx, type, props);
82
72
  }
83
73
 
@@ -1,6 +1,6 @@
1
1
  import { StrokeCap, StrokeJoin, PaintStyle, BlendMode } from "../../skia/types";
2
2
  import type { DeclarationNode, PaintProps } from "../types";
3
- import { DeclarationType, NodeType } from "../types";
3
+ import { NodeType } from "../types";
4
4
  import type { DeclarationContext } from "../types/DeclarationContext";
5
5
 
6
6
  import { enumKey } from "./datatypes";
@@ -12,7 +12,7 @@ export class PaintNode
12
12
  implements DeclarationNode<PaintProps>
13
13
  {
14
14
  constructor(ctx: NodeContext, props: PaintProps = {}) {
15
- super(ctx, DeclarationType.Paint, NodeType.Paint, props);
15
+ super(ctx, NodeType.Paint, props);
16
16
  }
17
17
 
18
18
  decorate(ctx: DeclarationContext) {
@@ -1,7 +1,7 @@
1
1
  import type { SkRRect, Skia } from "../../../skia/types";
2
2
  import { BlurStyle, ClipOp, isRRect } from "../../../skia/types";
3
3
  import type { DrawingContext } from "../../types";
4
- import { DeclarationType, NodeType } from "../../types";
4
+ import { NodeType } from "../../types";
5
5
  import type { BoxShadowProps, BoxProps } from "../../types/Drawings";
6
6
  import type { NodeContext } from "../Node";
7
7
  import { JsiDeclarationNode } from "../Node";
@@ -38,7 +38,7 @@ const deflate = (
38
38
 
39
39
  export class BoxShadowNode extends JsiDeclarationNode<BoxShadowProps> {
40
40
  constructor(ctx: NodeContext, props: BoxShadowProps) {
41
- super(ctx, DeclarationType.Unknown, NodeType.BoxShadow, props);
41
+ super(ctx, NodeType.BoxShadow, props);
42
42
  }
43
43
 
44
44
  decorate(_ctx: DeclarationContext) {
@@ -1,6 +1,6 @@
1
1
  import type { BlendProps } from "../../types/ImageFilters";
2
2
  import { BlendMode } from "../../../skia/types";
3
- import { DeclarationType, NodeType } from "../../types/NodeType";
3
+ import { NodeType } from "../../types/NodeType";
4
4
  import type { NodeContext } from "../Node";
5
5
  import { JsiDeclarationNode } from "../Node";
6
6
  import { enumKey } from "../datatypes";
@@ -9,7 +9,7 @@ import { composeDeclarations } from "../../types/DeclarationContext";
9
9
 
10
10
  export class BlendNode extends JsiDeclarationNode<BlendProps> {
11
11
  constructor(ctx: NodeContext, props: BlendProps) {
12
- super(ctx, DeclarationType.ImageFilter, NodeType.Blend, props);
12
+ super(ctx, NodeType.Blend, props);
13
13
  }
14
14
 
15
15
  decorate(ctx: DeclarationContext) {
@@ -6,14 +6,14 @@ import type {
6
6
  BlendColorFilterProps,
7
7
  MatrixColorFilterProps,
8
8
  } from "../../types";
9
- import { DeclarationType, NodeType } from "../../types";
9
+ import { NodeType } from "../../types";
10
10
  import { enumKey } from "../datatypes/Enum";
11
11
  import type { LerpColorFilterProps } from "../../types/ColorFilters";
12
12
  import type { DeclarationContext } from "../../types/DeclarationContext";
13
13
 
14
14
  export abstract class ColorFilterDeclaration<P> extends JsiDeclarationNode<P> {
15
15
  constructor(ctx: NodeContext, type: NodeType, props: P) {
16
- super(ctx, DeclarationType.ColorFilter, type, props);
16
+ super(ctx, type, props);
17
17
  }
18
18
 
19
19
  protected composeAndPush(ctx: DeclarationContext, cf1: SkColorFilter) {
@@ -15,7 +15,7 @@ import type {
15
15
  OffsetImageFilterProps,
16
16
  RuntimeShaderImageFilterProps,
17
17
  } from "../../types";
18
- import { DeclarationType, NodeType } from "../../types";
18
+ import { NodeType } from "../../types";
19
19
  import { processRadius, enumKey } from "../datatypes";
20
20
  import type { NodeContext } from "../Node";
21
21
  import { JsiDeclarationNode } from "../Node";
@@ -58,7 +58,7 @@ const MakeInnerShadow = (
58
58
 
59
59
  export abstract class ImageFilterDeclaration<P> extends JsiDeclarationNode<P> {
60
60
  constructor(ctx: NodeContext, type: NodeType, props: P) {
61
- super(ctx, DeclarationType.ImageFilter, type, props);
61
+ super(ctx, type, props);
62
62
  }
63
63
 
64
64
  protected input(ctx: DeclarationContext) {
@@ -2,13 +2,13 @@ import { BlurStyle } from "../../../skia/types";
2
2
  import type { NodeContext } from "../Node";
3
3
  import { JsiDeclarationNode } from "../Node";
4
4
  import type { BlurMaskFilterProps } from "../../types";
5
- import { DeclarationType, NodeType } from "../../types";
5
+ import { NodeType } from "../../types";
6
6
  import { enumKey } from "../datatypes";
7
7
  import type { DeclarationContext } from "../../types/DeclarationContext";
8
8
 
9
9
  export class BlurMaskFilterNode extends JsiDeclarationNode<BlurMaskFilterProps> {
10
10
  constructor(ctx: NodeContext, props: BlurMaskFilterProps) {
11
- super(ctx, DeclarationType.MaskFilter, NodeType.BlurMaskFilter, props);
11
+ super(ctx, NodeType.BlurMaskFilter, props);
12
12
  }
13
13
 
14
14
  decorate(ctx: DeclarationContext) {
@@ -10,7 +10,7 @@ import type {
10
10
  Path1DPathEffectProps,
11
11
  Path2DPathEffectProps,
12
12
  } from "../../types";
13
- import { DeclarationType, NodeType } from "../../types";
13
+ import { NodeType } from "../../types";
14
14
  import { enumKey } from "../datatypes/Enum";
15
15
  import { processPath } from "../datatypes";
16
16
  import type { DeclarationContext } from "../../types/DeclarationContext";
@@ -18,7 +18,7 @@ import { composeDeclarations } from "../../types/DeclarationContext";
18
18
 
19
19
  abstract class PathEffectDeclaration<P> extends JsiDeclarationNode<P> {
20
20
  constructor(ctx: NodeContext, type: NodeType, props: P) {
21
- super(ctx, DeclarationType.PathEffect, type, props);
21
+ super(ctx, type, props);
22
22
  }
23
23
 
24
24
  protected composeAndPush(ctx: DeclarationContext, pe1: SkPathEffect) {
@@ -18,7 +18,7 @@ import type {
18
18
  TurbulenceProps,
19
19
  TwoPointConicalGradientProps,
20
20
  } from "../../types";
21
- import { DeclarationType, NodeType } from "../../types";
21
+ import { NodeType } from "../../types";
22
22
  import {
23
23
  enumKey,
24
24
  fitRects,
@@ -30,7 +30,7 @@ import {
30
30
 
31
31
  export abstract class ShaderDeclaration<P> extends JsiDeclarationNode<P> {
32
32
  constructor(ctx: NodeContext, type: NodeType, props: P) {
33
- super(ctx, DeclarationType.Shader, type, props);
33
+ super(ctx, type, props);
34
34
  }
35
35
  }
36
36
 
@@ -1,5 +1,5 @@
1
1
  import type { GroupProps } from "./Common";
2
- import type { DeclarationType, NodeType } from "./NodeType";
2
+ import type { NodeType } from "./NodeType";
3
3
  import type { DeclarationContext } from "./DeclarationContext";
4
4
  import type { DrawingContext } from "./DrawingContext";
5
5
 
@@ -19,7 +19,7 @@ export interface Node<P> {
19
19
  export type Invalidate = () => void;
20
20
 
21
21
  export interface DeclarationNode<P> extends Node<P> {
22
- declarationType: DeclarationType;
22
+ //declarationType: DeclarationType;
23
23
  decorate(ctx: DeclarationContext): void;
24
24
 
25
25
  setInvalidate(invalidate: Invalidate): void;
@@ -72,13 +72,3 @@ export const enum NodeType {
72
72
  // Paragraph
73
73
  Paragraph = "skParagraph",
74
74
  }
75
-
76
- export const enum DeclarationType {
77
- Paint,
78
- Shader,
79
- ImageFilter,
80
- ColorFilter,
81
- PathEffect,
82
- MaskFilter,
83
- Unknown,
84
- }
@@ -36,7 +36,6 @@ const setFrame = (video: Video, currentFrame: SharedValue<SkImage | null>) => {
36
36
  currentFrame.value.dispose();
37
37
  }
38
38
  currentFrame.value = img;
39
- } else {
40
39
  copyFrameOnAndroid(currentFrame);
41
40
  }
42
41
  };
@@ -99,7 +98,6 @@ export const useVideo = (
99
98
  () => seek.value,
100
99
  (value) => {
101
100
  if (value !== null) {
102
- copyFrameOnAndroid(currentFrame);
103
101
  video?.seek(value);
104
102
  currentTime.value = value;
105
103
  seek.value = null;
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from "react";
1
+ import { useCallback, useEffect, useState } from "react";
2
2
 
3
3
  import type { Video } from "../../skia/types";
4
4
  import { Skia } from "../../skia";
@@ -10,17 +10,20 @@ const runtime = Rea.createWorkletRuntime("video-metadata-runtime");
10
10
  type VideoSource = string | null;
11
11
 
12
12
  export const useVideoLoading = (source: VideoSource) => {
13
- const runOnJS = Rea.runOnJS;
13
+ const { runOnJS } = Rea;
14
14
  const [video, setVideo] = useState<Video | null>(null);
15
- const cb = (src: string) => {
16
- "worklet";
17
- const vid = Skia.Video(src) as Video;
18
- runOnJS(setVideo)(vid);
19
- };
15
+ const cb = useCallback(
16
+ (src: string) => {
17
+ "worklet";
18
+ const vid = Skia.Video(src) as Video;
19
+ runOnJS(setVideo)(vid);
20
+ },
21
+ [runOnJS]
22
+ );
20
23
  useEffect(() => {
21
24
  if (source) {
22
25
  Rea.runOnRuntime(runtime, cb)(source);
23
26
  }
24
- }, [source]);
27
+ }, [cb, source]);
25
28
  return video;
26
29
  };
@@ -0,0 +1,29 @@
1
+ import { Skia } from "../Skia";
2
+ import type { DataSourceParam } from "../types";
3
+
4
+ export const useSVG = (
5
+ source: DataSourceParam,
6
+ onError?: (err: Error) => void
7
+ ) => {
8
+ if (source === null || source === undefined) {
9
+ throw new Error(`Invalid svg data source. Got: ${source}`);
10
+ }
11
+ if (
12
+ typeof source !== "object" ||
13
+ source instanceof Uint8Array ||
14
+ typeof source.default !== "string"
15
+ ) {
16
+ throw new Error(
17
+ `Invalid svg data source. Make sure that the source resolves to a string. Got: ${JSON.stringify(
18
+ source,
19
+ null,
20
+ 2
21
+ )}`
22
+ );
23
+ }
24
+ const svg = Skia.SVG.MakeFromString(source.default);
25
+ if (svg === null && onError !== undefined) {
26
+ onError(new Error("Failed to create SVG from source."));
27
+ }
28
+ return svg;
29
+ };
@@ -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
  }
@@ -25,7 +25,7 @@ export const isNativeBufferWeb = (
25
25
  buffer instanceof HTMLCanvasElement ||
26
26
  buffer instanceof ImageBitmap ||
27
27
  buffer instanceof OffscreenCanvas ||
28
- buffer instanceof VideoFrame ||
28
+ (typeof VideoFrame !== "undefined" && buffer instanceof VideoFrame) ||
29
29
  buffer instanceof HTMLImageElement ||
30
30
  buffer instanceof SVGImageElement ||
31
31
  buffer instanceof CanvasKitWebGLBuffer;
@@ -42,6 +42,7 @@ import { JsiSkMatrix } from "./JsiSkMatrix";
42
42
  import { JsiSkImageFilter } from "./JsiSkImageFilter";
43
43
  import { JsiSkPoint } from "./JsiSkPoint";
44
44
  import { JsiSkRSXform } from "./JsiSkRSXform";
45
+ import type { JsiSkSVG } from "./JsiSkSVG";
45
46
 
46
47
  export class JsiSkCanvas
47
48
  extends HostObject<Canvas, "Canvas">
@@ -302,8 +303,11 @@ export class JsiSkCanvas
302
303
  );
303
304
  }
304
305
 
305
- drawSvg(_svgDom: SkSVG, _width?: number, _height?: number) {
306
- throw new Error("drawSvg is not implemented on React Native Web");
306
+ drawSvg(svg: SkSVG, _width?: number, _height?: number) {
307
+ const image = this.CanvasKit.MakeImageFromCanvasImageSource(
308
+ (svg as JsiSkSVG).ref
309
+ );
310
+ this.ref.drawImage(image, 0, 0);
307
311
  }
308
312
 
309
313
  save() {
@@ -0,0 +1,27 @@
1
+ import type { CanvasKit } from "canvaskit-wasm";
2
+
3
+ import type { SkSVG } from "../types";
4
+
5
+ import { HostObject } from "./Host";
6
+
7
+ export class JsiSkSVG
8
+ extends HostObject<HTMLImageElement, "SVG">
9
+ implements SkSVG
10
+ {
11
+ constructor(CanvasKit: CanvasKit, ref: HTMLImageElement) {
12
+ super(CanvasKit, ref, "SVG");
13
+ }
14
+
15
+ width(): number {
16
+ return this.ref.width;
17
+ }
18
+ height(): number {
19
+ return this.ref.height;
20
+ }
21
+
22
+ dispose = () => {
23
+ if (this.ref.parentNode) {
24
+ this.ref.parentNode.removeChild(this.ref);
25
+ }
26
+ };
27
+ }
@@ -1,20 +1,61 @@
1
1
  import type { CanvasKit } from "canvaskit-wasm";
2
2
 
3
- import type { SkData, SkSVG } from "../types";
3
+ import type { SkSVG } from "../types";
4
4
  import type { SVGFactory } from "../types/SVG/SVGFactory";
5
5
 
6
- import { Host, NotImplementedOnRNWeb } from "./Host";
6
+ import { Host } from "./Host";
7
+ import type { JsiSkData } from "./JsiSkData";
8
+ import { JsiSkSVG } from "./JsiSkSVG";
7
9
 
8
10
  export class JsiSkSVGFactory extends Host implements SVGFactory {
9
11
  constructor(CanvasKit: CanvasKit) {
10
12
  super(CanvasKit);
11
13
  }
12
14
 
13
- MakeFromData(_data: SkData): SkSVG | null {
14
- throw new NotImplementedOnRNWeb();
15
+ MakeFromData(data: JsiSkData): SkSVG | null {
16
+ const decoder = new TextDecoder("utf-8");
17
+ const str = decoder.decode(data.ref);
18
+ return this.MakeFromString(str);
15
19
  }
16
20
 
17
- MakeFromString(_str: string): SkSVG | null {
18
- throw new NotImplementedOnRNWeb();
21
+ MakeFromString(str: string): SkSVG | null {
22
+ const parser = new DOMParser();
23
+ const svgDoc = parser.parseFromString(str, "image/svg+xml");
24
+ const svgElement = svgDoc.documentElement;
25
+
26
+ const attrWidth = svgElement.getAttribute("width");
27
+ const attrHeight = svgElement.getAttribute("height");
28
+ let width = attrWidth ? parseFloat(attrWidth) : null;
29
+ let height = attrHeight ? parseFloat(attrHeight) : null;
30
+
31
+ const svgDataUrl =
32
+ "data:image/svg+xml;charset=utf-8," + encodeURIComponent(str);
33
+ // Create a new HTMLImageElement
34
+ const img = new Image();
35
+ img.src = svgDataUrl;
36
+
37
+ // Optionally set styles or attributes on the image
38
+ img.style.display = "none";
39
+ img.alt = "SVG Image";
40
+ if (!width || !height) {
41
+ const viewBox = svgElement.getAttribute("viewBox");
42
+ if (viewBox) {
43
+ const viewBoxValues = viewBox.split(" ");
44
+ if (viewBoxValues.length === 4) {
45
+ width = width || parseFloat(viewBoxValues[2]);
46
+ height = height || parseFloat(viewBoxValues[3]);
47
+ }
48
+ }
49
+ }
50
+ if (width && height) {
51
+ img.width = width;
52
+ img.height = height;
53
+ }
54
+
55
+ img.onerror = (e) => {
56
+ console.error("SVG failed to load", e);
57
+ };
58
+ document.body.appendChild(img);
59
+ return new JsiSkSVG(this.CanvasKit, img);
19
60
  }
20
61
  }