@shopify/react-native-skia 1.11.9 → 2.0.0-next.1

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 (116) hide show
  1. package/android/build.gradle +1 -1
  2. package/lib/commonjs/Platform/Platform.web.js +1 -0
  3. package/lib/commonjs/Platform/Platform.web.js.map +1 -1
  4. package/lib/commonjs/external/reanimated/textures.js +4 -3
  5. package/lib/commonjs/external/reanimated/textures.js.map +1 -1
  6. package/lib/commonjs/headless/index.d.ts +1 -1
  7. package/lib/commonjs/headless/index.js +2 -2
  8. package/lib/commonjs/headless/index.js.map +1 -1
  9. package/lib/commonjs/renderer/Canvas.d.ts +3 -3
  10. package/lib/commonjs/renderer/Canvas.js +12 -31
  11. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  12. package/lib/commonjs/renderer/Offscreen.d.ts +2 -2
  13. package/lib/commonjs/renderer/Offscreen.js +4 -4
  14. package/lib/commonjs/renderer/Offscreen.js.map +1 -1
  15. package/lib/commonjs/renderer/__tests__/setup.d.ts +6 -5
  16. package/lib/commonjs/sksg/Container.d.ts +3 -1
  17. package/lib/commonjs/sksg/Container.js +7 -1
  18. package/lib/commonjs/sksg/Container.js.map +1 -1
  19. package/lib/commonjs/sksg/Elements.d.ts +1 -1
  20. package/lib/commonjs/sksg/Elements.js.map +1 -1
  21. package/lib/commonjs/sksg/HostConfig.d.ts +2 -2
  22. package/lib/commonjs/sksg/HostConfig.js +36 -6
  23. package/lib/commonjs/sksg/HostConfig.js.map +1 -1
  24. package/lib/commonjs/sksg/Reconciler.d.ts +3 -2
  25. package/lib/commonjs/sksg/Reconciler.js +15 -6
  26. package/lib/commonjs/sksg/Reconciler.js.map +1 -1
  27. package/lib/module/Platform/Platform.web.js +1 -0
  28. package/lib/module/Platform/Platform.web.js.map +1 -1
  29. package/lib/module/external/reanimated/textures.js +5 -4
  30. package/lib/module/external/reanimated/textures.js.map +1 -1
  31. package/lib/module/headless/index.d.ts +1 -1
  32. package/lib/module/headless/index.js +2 -2
  33. package/lib/module/headless/index.js.map +1 -1
  34. package/lib/module/renderer/Canvas.d.ts +3 -3
  35. package/lib/module/renderer/Canvas.js +11 -31
  36. package/lib/module/renderer/Canvas.js.map +1 -1
  37. package/lib/module/renderer/Offscreen.d.ts +2 -2
  38. package/lib/module/renderer/Offscreen.js +4 -4
  39. package/lib/module/renderer/Offscreen.js.map +1 -1
  40. package/lib/module/renderer/__tests__/setup.d.ts +6 -5
  41. package/lib/module/sksg/Container.d.ts +3 -1
  42. package/lib/module/sksg/Container.js +7 -1
  43. package/lib/module/sksg/Container.js.map +1 -1
  44. package/lib/module/sksg/Elements.d.ts +1 -1
  45. package/lib/module/sksg/Elements.js.map +1 -1
  46. package/lib/module/sksg/HostConfig.d.ts +2 -2
  47. package/lib/module/sksg/HostConfig.js +36 -7
  48. package/lib/module/sksg/HostConfig.js.map +1 -1
  49. package/lib/module/sksg/Reconciler.d.ts +3 -2
  50. package/lib/module/sksg/Reconciler.js +15 -6
  51. package/lib/module/sksg/Reconciler.js.map +1 -1
  52. package/lib/typescript/lib/commonjs/headless/index.d.ts +1 -1
  53. package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +9 -1
  54. package/lib/typescript/lib/commonjs/renderer/Offscreen.d.ts +2 -2
  55. package/lib/typescript/lib/commonjs/sksg/Container.d.ts +3 -0
  56. package/lib/typescript/lib/commonjs/sksg/HostConfig.d.ts +21 -4
  57. package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +9 -2
  58. package/lib/typescript/lib/module/Platform/Platform.web.d.ts +1 -1
  59. package/lib/typescript/lib/module/headless/index.d.ts +1 -1
  60. package/lib/typescript/lib/module/mock/index.d.ts +22 -11
  61. package/lib/typescript/lib/module/renderer/Canvas.d.ts +10 -2
  62. package/lib/typescript/lib/module/renderer/Offscreen.d.ts +2 -2
  63. package/lib/typescript/lib/module/sksg/Container.d.ts +3 -0
  64. package/lib/typescript/lib/module/sksg/HostConfig.d.ts +20 -4
  65. package/lib/typescript/lib/module/sksg/Reconciler.d.ts +9 -2
  66. package/lib/typescript/lib/module/views/SkiaPictureView.d.ts +1 -1
  67. package/lib/typescript/src/headless/index.d.ts +1 -1
  68. package/lib/typescript/src/renderer/Canvas.d.ts +3 -3
  69. package/lib/typescript/src/renderer/Offscreen.d.ts +2 -2
  70. package/lib/typescript/src/renderer/__tests__/setup.d.ts +6 -5
  71. package/lib/typescript/src/sksg/Container.d.ts +3 -1
  72. package/lib/typescript/src/sksg/Elements.d.ts +1 -1
  73. package/lib/typescript/src/sksg/HostConfig.d.ts +2 -2
  74. package/lib/typescript/src/sksg/Reconciler.d.ts +3 -2
  75. package/package.json +11 -10
  76. package/src/Platform/Platform.web.tsx +2 -1
  77. package/src/__tests__/snapshots/screens/snapshot2-android-ci.png +0 -0
  78. package/src/__tests__/snapshots/screens/snapshot3-android-ci.png +0 -0
  79. package/src/external/reanimated/textures.tsx +5 -4
  80. package/src/headless/index.ts +2 -2
  81. package/src/renderer/Canvas.tsx +57 -80
  82. package/src/renderer/Offscreen.tsx +4 -4
  83. package/src/renderer/__tests__/Data.spec.tsx +9 -10
  84. package/src/renderer/__tests__/Drawings.spec.tsx +11 -11
  85. package/src/renderer/__tests__/FitBox.spec.tsx +10 -10
  86. package/src/renderer/__tests__/Glyphs.spec.tsx +2 -2
  87. package/src/renderer/__tests__/Image.spec.tsx +2 -2
  88. package/src/renderer/__tests__/Paths.spec.tsx +8 -8
  89. package/src/renderer/__tests__/Picture.spec.tsx +10 -12
  90. package/src/renderer/__tests__/Simple.spec.tsx +6 -6
  91. package/src/renderer/__tests__/Surfaces.spec.tsx +2 -2
  92. package/src/renderer/__tests__/Text.spec.tsx +12 -12
  93. package/src/renderer/__tests__/Transform.spec.tsx +8 -8
  94. package/src/renderer/__tests__/documentation/Group.spec.tsx +12 -12
  95. package/src/renderer/__tests__/documentation/getting-started/HelloWorld.spec.tsx +2 -2
  96. package/src/renderer/__tests__/documentation/paint/Overview.spec.tsx +8 -8
  97. package/src/renderer/__tests__/documentation/shapes/Box.spec.tsx +4 -4
  98. package/src/renderer/__tests__/e2e/Atlas.spec.tsx +3 -3
  99. package/src/renderer/__tests__/e2e/Offscreen.spec.tsx +1 -1
  100. package/src/renderer/__tests__/examples/BlendModes.spec.tsx +4 -4
  101. package/src/renderer/__tests__/setup.tsx +17 -13
  102. package/src/sksg/Container.ts +9 -1
  103. package/src/sksg/Elements.tsx +1 -1
  104. package/src/sksg/HostConfig.ts +37 -7
  105. package/src/sksg/Reconciler.ts +16 -6
  106. package/src/sksg/__tests__/Simple.spec.tsx +8 -8
  107. package/lib/commonjs/sksg/HostConfig2.d.ts +0 -19
  108. package/lib/commonjs/sksg/HostConfig2.js +0 -159
  109. package/lib/commonjs/sksg/HostConfig2.js.map +0 -1
  110. package/lib/module/sksg/HostConfig2.d.ts +0 -19
  111. package/lib/module/sksg/HostConfig2.js +0 -152
  112. package/lib/module/sksg/HostConfig2.js.map +0 -1
  113. package/lib/typescript/lib/commonjs/sksg/HostConfig2.d.ts +0 -44
  114. package/lib/typescript/lib/module/sksg/HostConfig2.d.ts +0 -43
  115. package/lib/typescript/src/sksg/HostConfig2.d.ts +0 -19
  116. package/src/sksg/HostConfig2.ts +0 -247
@@ -12,10 +12,10 @@ import {
12
12
  import { height, drawOnNode, width, loadImage, importSkia } from "../setup";
13
13
 
14
14
  describe("Test blend modes", () => {
15
- it("Should nicely blend the product color to the image", () => {
15
+ it("Should nicely blend the product color to the image", async () => {
16
16
  const image = loadImage("skia/__tests__/assets/product.png");
17
17
  const rect = { x: 0, y: 0, width, height };
18
- const surface = drawOnNode(
18
+ const surface = await drawOnNode(
19
19
  <Mask mask={<Image image={image} rect={rect} />}>
20
20
  <Image image={image} rect={rect}>
21
21
  <BlendColor color="lightgreen" mode="hue" />
@@ -24,12 +24,12 @@ describe("Test blend modes", () => {
24
24
  );
25
25
  processResult(surface, "snapshots/demos/product.png");
26
26
  });
27
- it("Should nicely blend the product color to the image using a runtime effect", () => {
27
+ it("Should nicely blend the product color to the image using a runtime effect", async () => {
28
28
  const { Skia } = importSkia();
29
29
  const image = loadImage("skia/__tests__/assets/product.png");
30
30
  const rect = { x: 0, y: 0, width, height };
31
31
  const source = Skia.RuntimeEffect.Make(blender)!;
32
- const surface = drawOnNode(
32
+ const surface = await drawOnNode(
33
33
  <Rect rect={rect}>
34
34
  <Shader
35
35
  source={source}
@@ -176,14 +176,14 @@ export const width = 256 * PIXEL_RATIO;
176
176
  export const height = 256 * PIXEL_RATIO;
177
177
  export const center = { x: width / 2, y: height / 2 };
178
178
 
179
- export const drawOnNode = (element: ReactNode) => {
180
- const { surface: ckSurface, draw, root } = mountCanvas(element);
181
- draw();
179
+ export const drawOnNode = async (element: ReactNode) => {
180
+ const { surface: ckSurface, draw, root } = await mountCanvas(element);
181
+ await draw();
182
182
  root.unmount();
183
183
  return ckSurface;
184
184
  };
185
185
 
186
- export const mountCanvas = (element: ReactNode) => {
186
+ export const mountCanvas = async (element: ReactNode) => {
187
187
  const Skia = global.SkiaApi;
188
188
  expect(Skia).toBeDefined();
189
189
  const ckSurface = Skia.Surface.MakeOffscreen(width, height)!;
@@ -191,18 +191,22 @@ export const mountCanvas = (element: ReactNode) => {
191
191
  const canvas = ckSurface.getCanvas();
192
192
 
193
193
  const root = new SkiaSGRoot(Skia);
194
- root.render(element);
195
194
  return {
196
195
  surface: ckSurface,
197
196
  root,
198
- draw: () => {
197
+ render: async () => {
198
+ await root.render(element);
199
+ },
200
+ draw: async () => {
201
+ await root.render(element);
199
202
  root.drawOnCanvas(canvas);
200
203
  },
201
204
  };
202
205
  };
203
206
 
204
- export const serialize = (element: ReactNode) => {
205
- const { root } = mountCanvas(element);
207
+ export const serialize = async (element: ReactNode) => {
208
+ const { root, render } = await mountCanvas(element);
209
+ await render();
206
210
  const serialized = serializeNode(root.sg);
207
211
  return JSON.stringify(serialized);
208
212
  };
@@ -379,11 +383,11 @@ class LocalSurface implements TestingSurface {
379
383
  return Promise.resolve(ckSurface.makeImageSnapshot());
380
384
  }
381
385
 
382
- draw(node: ReactNode): Promise<SkImage> {
383
- const { surface: ckSurface, draw } = mountCanvas(
386
+ async draw(node: ReactNode): Promise<SkImage> {
387
+ const { surface: ckSurface, draw } = await mountCanvas(
384
388
  <Group transform={[{ scale: PIXEL_RATIO }]}>{node}</Group>
385
389
  );
386
- draw();
390
+ await draw();
387
391
  return Promise.resolve(ckSurface.makeImageSnapshot());
388
392
  }
389
393
 
@@ -440,8 +444,8 @@ return surface.makeImageSnapshot().encodeToBase64();
440
444
  return image;
441
445
  }
442
446
 
443
- draw(node: ReactNode) {
444
- return this.handleImageResponse(serialize(node));
447
+ async draw(node: ReactNode) {
448
+ return this.handleImageResponse(await serialize(node));
445
449
  }
446
450
 
447
451
  screen(screen: string) {
@@ -40,12 +40,20 @@ const nativeDrawOnscreen = (nativeId: number, recorder: JsiRecorder) => {
40
40
  };
41
41
 
42
42
  export abstract class Container {
43
- public root: Node[] = [];
43
+ private _root: Node[] = [];
44
44
  protected recording: Recording | null = null;
45
45
  protected unmounted = false;
46
46
 
47
47
  constructor(protected Skia: Skia, protected nativeId: number) {}
48
48
 
49
+ get root() {
50
+ return this._root;
51
+ }
52
+
53
+ set root(value: Node[]) {
54
+ this._root = value;
55
+ }
56
+
49
57
  unmount() {
50
58
  this.unmounted = true;
51
59
  }
@@ -54,7 +54,7 @@ import type {
54
54
  } from "../dom/types";
55
55
  import type { SkiaProps } from "../renderer";
56
56
 
57
- declare global {
57
+ declare module "react" {
58
58
  // eslint-disable-next-line @typescript-eslint/no-namespace
59
59
  namespace JSX {
60
60
  interface IntrinsicElements {
@@ -1,4 +1,5 @@
1
1
  /*global NodeJS*/
2
+ import { createContext } from "react";
2
3
  import type { Fiber, HostConfig } from "react-reconciler";
3
4
  import { DefaultEventPriority } from "react-reconciler/constants";
4
5
 
@@ -8,6 +9,9 @@ import { shallowEq } from "../renderer/typeddash";
8
9
  import type { Node } from "./Node";
9
10
  import type { Container } from "./Container";
10
11
 
12
+ type EventPriority = number;
13
+ const NoEventPriority = 0;
14
+
11
15
  const DEBUG = false;
12
16
  export const debug = (...args: Parameters<typeof console.log>) => {
13
17
  if (DEBUG) {
@@ -22,7 +26,7 @@ type TextInstance = Node;
22
26
  type SuspenseInstance = Instance;
23
27
  type HydratableInstance = Instance;
24
28
  type PublicInstance = Instance;
25
- type HostContext = null;
29
+ type HostContext = object;
26
30
  type UpdatePayload = Container;
27
31
  type ChildSet = Node[];
28
32
  type TimeoutHandle = NodeJS.Timeout;
@@ -43,6 +47,7 @@ type SkiaHostConfig = HostConfig<
43
47
  TimeoutHandle,
44
48
  NoTimeout
45
49
  >;
50
+ let currentUpdatePriority: EventPriority = NoEventPriority;
46
51
 
47
52
  export const sksgHostConfig: SkiaHostConfig = {
48
53
  /**
@@ -59,12 +64,12 @@ export const sksgHostConfig: SkiaHostConfig = {
59
64
 
60
65
  getRootHostContext: (_rootContainerInstance: Container) => {
61
66
  debug("getRootHostContext");
62
- return null;
67
+ return {};
63
68
  },
64
69
 
65
70
  getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {
66
71
  debug("getChildHostContext");
67
- return null;
72
+ return {};
68
73
  },
69
74
 
70
75
  shouldSetTextContent(_type, _props) {
@@ -125,9 +130,8 @@ export const sksgHostConfig: SkiaHostConfig = {
125
130
  return null;
126
131
  },
127
132
 
128
- resetAfterCommit(container) {
133
+ resetAfterCommit(_container) {
129
134
  debug("resetAfterCommit");
130
- container.redraw();
131
135
  },
132
136
 
133
137
  getPublicInstance(node: Instance) {
@@ -169,16 +173,15 @@ export const sksgHostConfig: SkiaHostConfig = {
169
173
 
170
174
  cloneInstance(
171
175
  instance,
172
- _updatePayload,
173
176
  _type,
174
177
  _oldProps,
175
178
  newProps,
179
+ _updatePayload,
176
180
  _internalInstanceHandle,
177
181
  keepChildren: boolean,
178
182
  _recyclableInstance: null | Instance
179
183
  ) {
180
184
  debug("cloneInstance");
181
-
182
185
  return {
183
186
  type: instance.type,
184
187
  props: newProps,
@@ -234,4 +237,31 @@ export const sksgHostConfig: SkiaHostConfig = {
234
237
  getInstanceFromScope: function (_scopeInstance): Instance | null {
235
238
  throw new Error("Function not implemented.");
236
239
  },
240
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
241
+ // @ts-expect-error
242
+ shouldAttemptEagerTransition: () => false,
243
+ trackSchedulerEvent: () => {},
244
+ resolveEventType: () => null,
245
+ resolveEventTimeStamp: () => -1.1,
246
+ requestPostPaintCallback() {},
247
+ maySuspendCommit: () => false,
248
+ preloadInstance: () => true, // true indicates already loaded
249
+ startSuspendingCommit() {},
250
+ suspendInstance() {},
251
+ waitForCommitToBeReady: () => null,
252
+ NotPendingTransition: null,
253
+ HostTransitionContext: createContext(null),
254
+ setCurrentUpdatePriority(newPriority: number) {
255
+ currentUpdatePriority = newPriority;
256
+ },
257
+ getCurrentUpdatePriority() {
258
+ return currentUpdatePriority;
259
+ },
260
+ resolveUpdatePriority() {
261
+ if (currentUpdatePriority !== NoEventPriority) {
262
+ return currentUpdatePriority;
263
+ }
264
+ return DefaultEventPriority;
265
+ },
266
+ resetFormInstance() {},
237
267
  };
@@ -41,13 +41,20 @@ export class SkiaSGRoot {
41
41
  return { type: NodeType.Group, props: {}, children, isDeclaration: false };
42
42
  }
43
43
 
44
- render(element: ReactNode) {
45
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- skiaReconciler.updateContainer(element as any, this.root, null, () => {
47
- debug("updateContainer");
44
+ private updateContainer(element: ReactNode) {
45
+ return new Promise((resolve) => {
46
+ skiaReconciler.updateContainer(element, this.root, null, () => {
47
+ debug("updateContainer");
48
+ resolve(true);
49
+ });
48
50
  });
49
51
  }
50
52
 
53
+ async render(element: ReactNode) {
54
+ await this.updateContainer(element);
55
+ this.container.redraw();
56
+ }
57
+
51
58
  drawOnCanvas(canvas: SkCanvas) {
52
59
  this.container.drawOnCanvas(canvas);
53
60
  }
@@ -61,8 +68,11 @@ export class SkiaSGRoot {
61
68
 
62
69
  unmount() {
63
70
  this.container.unmount();
64
- skiaReconciler.updateContainer(null, this.root, null, () => {
65
- debug("unmountContainer");
71
+ return new Promise((resolve) => {
72
+ skiaReconciler.updateContainer(null, this.root, null, () => {
73
+ debug("unmountContainer");
74
+ resolve(true);
75
+ });
66
76
  });
67
77
  }
68
78
  }
@@ -39,10 +39,10 @@ const Ring = ({ index, progress, width, center }: RingProps) => {
39
39
  };
40
40
 
41
41
  describe("Simple", () => {
42
- it("should have a simple render (1)", () => {
42
+ it("should have a simple render (1)", async () => {
43
43
  const { Skia } = importSkia();
44
44
  const root = new SkiaSGRoot(Skia);
45
- root.render(<skCircle r={128} color="cyan" />);
45
+ await root.render(<skCircle r={128} color="cyan" />);
46
46
  const surface = Skia.Surface.Make(768, 768)!;
47
47
  expect(surface).toBeDefined();
48
48
  const canvas = surface.getCanvas();
@@ -52,10 +52,10 @@ describe("Simple", () => {
52
52
  expect(image).toBeDefined();
53
53
  checkImage(image, "snapshots/sksg/simple.png");
54
54
  });
55
- it("should have a simple render (2)", () => {
55
+ it("should have a simple render (2)", async () => {
56
56
  const { Skia } = importSkia();
57
57
  const root = new SkiaSGRoot(Skia);
58
- root.render(
58
+ await root.render(
59
59
  <>
60
60
  <skFill color="magenta" />
61
61
  <skCircle r={128} cx={768 / 2} cy={768 / 2} color="cyan" />
@@ -70,7 +70,7 @@ describe("Simple", () => {
70
70
  expect(image).toBeDefined();
71
71
  checkImage(image, "snapshots/sksg/simple2.png");
72
72
  });
73
- it("simple demo", () => {
73
+ it("simple demo", async () => {
74
74
  const { Skia } = importSkia();
75
75
  const root = new SkiaSGRoot(Skia);
76
76
  const width = 768;
@@ -78,7 +78,7 @@ describe("Simple", () => {
78
78
  const center = { x: width / 2, y: height / 2 };
79
79
  const progress = 0.5;
80
80
  const transform = (() => [{ rotate: mix(progress, -Math.PI, 0) }])();
81
- root.render(
81
+ await root.render(
82
82
  <>
83
83
  <skFill color="rgb(36,43,56)" />
84
84
  <skGroup blendMode="screen" origin={center} transform={transform}>
@@ -108,7 +108,7 @@ describe("Simple", () => {
108
108
  checkImage(image, "snapshots/sksg/breathe.png");
109
109
  });
110
110
 
111
- it("simple demo (2)", () => {
111
+ it("simple demo (2)", async () => {
112
112
  const { Skia } = importSkia();
113
113
  const root = new SkiaSGRoot(Skia);
114
114
  const width = 768;
@@ -116,7 +116,7 @@ describe("Simple", () => {
116
116
  const center = { x: width / 2, y: height / 2 };
117
117
  const progress = 0;
118
118
  const transform = (() => [{ rotate: mix(progress, -Math.PI, 0) }])();
119
- root.render(
119
+ await root.render(
120
120
  <>
121
121
  <skFill color="rgb(36,43,56)" />
122
122
  <skGroup blendMode="screen" origin={center} transform={transform}>
@@ -1,19 +0,0 @@
1
- import type { HostConfig } from "react-reconciler";
2
- import type { NodeType } from "../dom/types";
3
- import type { Container } from "./Container";
4
- import type { Node } from "./Node";
5
- export declare const debug: (message?: any, ...optionalParams: any[]) => void;
6
- type Instance = Node<unknown>;
7
- type Props = object;
8
- type TextInstance = Node<unknown>;
9
- type SuspenseInstance = Instance;
10
- type HydratableInstance = Instance;
11
- type PublicInstance = Instance;
12
- type HostContext = null;
13
- type UpdatePayload = Container;
14
- type ChildSet = unknown;
15
- type TimeoutHandle = NodeJS.Timeout;
16
- type NoTimeout = -1;
17
- type SkiaHostConfig = HostConfig<NodeType, Props, Container, Instance, TextInstance, SuspenseInstance, HydratableInstance, PublicInstance, HostContext, UpdatePayload, ChildSet, TimeoutHandle, NoTimeout>;
18
- export declare const sksgHostConfig: SkiaHostConfig;
19
- export {};
@@ -1,159 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.sksgHostConfig = exports.debug = void 0;
7
- var _constants = require("react-reconciler/constants");
8
- var _typeddash = require("../renderer/typeddash");
9
- /*global NodeJS*/
10
-
11
- const DEBUG = false;
12
- const debug = (...args) => {
13
- if (DEBUG) {
14
- console.log(...args);
15
- }
16
- };
17
- exports.debug = debug;
18
- const appendNode = (parent, child) => {
19
- parent.children.push(child);
20
- };
21
- const removeNode = (parent, child) => {
22
- parent.children.splice(parent.children.indexOf(child), 1);
23
- };
24
- const insertBefore = (parent, child, before) => {
25
- parent.children.splice(parent.children.indexOf(before), 0, child);
26
- };
27
- const sksgHostConfig = exports.sksgHostConfig = {
28
- /**
29
- * This function is used by the reconciler in order to calculate current time for prioritising work.
30
- */
31
- supportsMutation: true,
32
- isPrimaryRenderer: false,
33
- supportsPersistence: false,
34
- supportsHydration: false,
35
- //supportsMicrotask: true,
36
-
37
- scheduleTimeout: setTimeout,
38
- cancelTimeout: clearTimeout,
39
- noTimeout: -1,
40
- appendChildToContainer(container, child) {
41
- debug("appendChildToContainer");
42
- container.root.push(child);
43
- },
44
- appendChild(parent, child) {
45
- debug("appendChild", parent, child);
46
- appendNode(parent, child);
47
- },
48
- getRootHostContext: _rootContainerInstance => {
49
- debug("getRootHostContext");
50
- return null;
51
- },
52
- getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {
53
- debug("getChildHostContext");
54
- return null;
55
- },
56
- shouldSetTextContent(_type, _props) {
57
- return false;
58
- },
59
- createTextInstance(_text, _rootContainerInstance, _hostContext, _internalInstanceHandle) {
60
- debug("createTextInstance");
61
- // return SpanNode({}, text) as SkNode;
62
- throw new Error("Text nodes are not supported yet");
63
- },
64
- createInstance(type, propsWithChildren, _container, _hostContext, _internalInstanceHandle) {
65
- debug("createInstance", type);
66
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
- const {
68
- children,
69
- ...props
70
- } = propsWithChildren;
71
- debug("createInstance", type);
72
- const instance = {
73
- type,
74
- props,
75
- children: []
76
- };
77
- return instance;
78
- },
79
- appendInitialChild(parentInstance, child) {
80
- debug("appendInitialChild");
81
- appendNode(parentInstance, child);
82
- },
83
- finalizeInitialChildren(parentInstance, _type, _props, _rootContainerInstance, _hostContext) {
84
- debug("finalizeInitialChildren", parentInstance);
85
- return false;
86
- },
87
- commitMount() {
88
- // if finalizeInitialChildren = true
89
- debug("commitMount");
90
- },
91
- prepareForCommit(_containerInfo) {
92
- debug("prepareForCommit");
93
- return null;
94
- },
95
- resetAfterCommit(container) {
96
- debug("resetAfterCommit");
97
- container.redraw();
98
- },
99
- getPublicInstance(node) {
100
- debug("getPublicInstance");
101
- return node;
102
- },
103
- prepareUpdate: (_instance, type, oldProps, newProps, rootContainerInstance, _hostContext) => {
104
- debug("prepareUpdate");
105
- const propsAreEqual = (0, _typeddash.shallowEq)(oldProps, newProps);
106
- if (propsAreEqual) {
107
- return null;
108
- }
109
- debug("update ", type);
110
- return rootContainerInstance;
111
- },
112
- commitUpdate(instance, _updatePayload, type, prevProps, nextProps, _internalHandle) {
113
- debug("commitUpdate: ", type);
114
- if ((0, _typeddash.shallowEq)(prevProps, nextProps)) {
115
- return;
116
- }
117
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
- const {
119
- children,
120
- ...props
121
- } = nextProps;
122
- instance.props = props;
123
- },
124
- commitTextUpdate: (_textInstance, _oldText, _newText) => {
125
- // textInstance.instance = newText;
126
- },
127
- clearContainer: container => {
128
- debug("clearContainer");
129
- container.root = [];
130
- },
131
- preparePortalMount: () => {
132
- debug("preparePortalMount");
133
- },
134
- removeChild: (parent, child) => {
135
- removeNode(parent, child);
136
- },
137
- removeChildFromContainer: (container, child) => {
138
- container.root.splice(container.root.indexOf(child), 1);
139
- },
140
- insertInContainerBefore: (container, child, before) => {
141
- container.root.splice(container.root.indexOf(before), 0, child);
142
- },
143
- insertBefore: (parent, child, before) => {
144
- insertBefore(parent, child, before);
145
- },
146
- // see https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
147
- getCurrentEventPriority: () => _constants.DefaultEventPriority,
148
- beforeActiveInstanceBlur: () => {},
149
- afterActiveInstanceBlur: () => {},
150
- detachDeletedInstance: () => {},
151
- getInstanceFromNode: function (_node) {
152
- return null;
153
- },
154
- prepareScopeUpdate: function (_scopeInstance, _instance) {},
155
- getInstanceFromScope: function (_scopeInstance) {
156
- return null;
157
- }
158
- };
159
- //# sourceMappingURL=HostConfig2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_constants","require","_typeddash","DEBUG","debug","args","console","log","exports","appendNode","parent","child","children","push","removeNode","splice","indexOf","insertBefore","before","sksgHostConfig","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","container","root","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","type","propsWithChildren","_container","props","instance","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","resetAfterCommit","redraw","getPublicInstance","node","prepareUpdate","_instance","oldProps","newProps","rootContainerInstance","propsAreEqual","shallowEq","commitUpdate","_updatePayload","prevProps","nextProps","_internalHandle","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","preparePortalMount","removeChild","removeChildFromContainer","insertInContainerBefore","getCurrentEventPriority","DefaultEventPriority","beforeActiveInstanceBlur","afterActiveInstanceBlur","detachDeletedInstance","getInstanceFromNode","_node","prepareScopeUpdate","_scopeInstance","getInstanceFromScope"],"sources":["HostConfig2.ts"],"sourcesContent":["/*global NodeJS*/\nimport type { Fiber, HostConfig } from \"react-reconciler\";\nimport { DefaultEventPriority } from \"react-reconciler/constants\";\n\nimport type { NodeType } from \"../dom/types\";\nimport { shallowEq } from \"../renderer/typeddash\";\n\nimport type { Container } from \"./Container\";\nimport type { Node } from \"./Node\";\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ntype Instance = Node<unknown>;\n\ntype Props = object;\ntype TextInstance = Node<unknown>;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = Container;\ntype ChildSet = unknown;\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\n\nconst appendNode = (parent: Node<unknown>, child: Node<unknown>) => {\n parent.children.push(child);\n};\n\nconst removeNode = (parent: Node<unknown>, child: Node<unknown>) => {\n parent.children.splice(parent.children.indexOf(child), 1);\n};\n\nconst insertBefore = (\n parent: Node<unknown>,\n child: Node<unknown>,\n before: Node<unknown>\n) => {\n parent.children.splice(parent.children.indexOf(before), 0, child);\n};\n\nexport const sksgHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n supportsMutation: true,\n isPrimaryRenderer: false,\n supportsPersistence: false,\n supportsHydration: false,\n //supportsMicrotask: true,\n\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n appendChildToContainer(container, child) {\n debug(\"appendChildToContainer\");\n container.root.push(child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Container) => {\n debug(\"getRootHostContext\");\n return null;\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return null;\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n propsWithChildren,\n _container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { children, ...props } = propsWithChildren as any;\n debug(\"createInstance\", type);\n const instance = {\n type,\n props,\n children: [],\n };\n return instance;\n },\n\n appendInitialChild(parentInstance, child) {\n debug(\"appendInitialChild\");\n appendNode(parentInstance, child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_containerInfo) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n prepareUpdate: (\n _instance,\n type,\n oldProps,\n newProps,\n rootContainerInstance,\n _hostContext\n ) => {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual) {\n return null;\n }\n debug(\"update \", type);\n return rootContainerInstance;\n },\n\n commitUpdate(\n instance,\n _updatePayload,\n type,\n prevProps,\n nextProps,\n _internalHandle\n ) {\n debug(\"commitUpdate: \", type);\n if (shallowEq(prevProps, nextProps)) {\n return;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { children, ...props } = nextProps as any;\n instance.props = props;\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (container) => {\n debug(\"clearContainer\");\n container.root = [];\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (container, child) => {\n container.root.splice(container.root.indexOf(child), 1);\n },\n\n insertInContainerBefore: (container, child, before) => {\n container.root.splice(container.root.indexOf(before), 0, child);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n\n // see https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874\n getCurrentEventPriority: () => DefaultEventPriority,\n beforeActiveInstanceBlur: () => {},\n afterActiveInstanceBlur: () => {},\n detachDeletedInstance: () => {},\n\n getInstanceFromNode: function (_node): Fiber | null | undefined {\n return null;\n },\n prepareScopeUpdate: function (_scopeInstance, _instance): void {},\n getInstanceFromScope: function (_scopeInstance): Instance | null {\n return null;\n },\n};\n"],"mappings":";;;;;;AAEA,IAAAA,UAAA,GAAAC,OAAA;AAGA,IAAAC,UAAA,GAAAD,OAAA;AALA;;AAUA,MAAME,KAAK,GAAG,KAAK;AACZ,MAAMC,KAAK,GAAGA,CAAC,GAAGC,IAAoC,KAAK;EAChE,IAAIF,KAAK,EAAE;IACTG,OAAO,CAACC,GAAG,CAAC,GAAGF,IAAI,CAAC;EACtB;AACF,CAAC;AAACG,OAAA,CAAAJ,KAAA,GAAAA,KAAA;AA+BF,MAAMK,UAAU,GAAGA,CAACC,MAAqB,EAAEC,KAAoB,KAAK;EAClED,MAAM,CAACE,QAAQ,CAACC,IAAI,CAACF,KAAK,CAAC;AAC7B,CAAC;AAED,MAAMG,UAAU,GAAGA,CAACJ,MAAqB,EAAEC,KAAoB,KAAK;EAClED,MAAM,CAACE,QAAQ,CAACG,MAAM,CAACL,MAAM,CAACE,QAAQ,CAACI,OAAO,CAACL,KAAK,CAAC,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,MAAMM,YAAY,GAAGA,CACnBP,MAAqB,EACrBC,KAAoB,EACpBO,MAAqB,KAClB;EACHR,MAAM,CAACE,QAAQ,CAACG,MAAM,CAACL,MAAM,CAACE,QAAQ,CAACI,OAAO,CAACE,MAAM,CAAC,EAAE,CAAC,EAAEP,KAAK,CAAC;AACnE,CAAC;AAEM,MAAMQ,cAA8B,GAAAX,OAAA,CAAAW,cAAA,GAAG;EAC5C;AACF;AACA;EACEC,gBAAgB,EAAE,IAAI;EACtBC,iBAAiB,EAAE,KAAK;EACxBC,mBAAmB,EAAE,KAAK;EAC1BC,iBAAiB,EAAE,KAAK;EACxB;;EAEAC,eAAe,EAAEC,U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AAuB,EAAEA,CAAA,KAAM,CAAC,CAAC;EACjCC,qBAAqB,EAAEA,CAAA,KAAM,CAAC,CAAC;EAE/BC,mBAAmB,EAAE,SAAAA,CAAUC,KAAK,EAA4B;IAC9D,OAAO,IAAI;EACb,CAAC;EACDC,kBAAkB,EAAE,SAAAA,CAAUC,cAAc,EAAE5B,SAAS,EAAQ,CAAC,CAAC;EACjE6B,oBAAoB,EAAE,SAAAA,CAAUD,cAAc,EAAmB;IAC/D,OAAO,IAAI;EACb;AACF,CAAC","ignoreList":[]}
@@ -1,19 +0,0 @@
1
- import type { HostConfig } from "react-reconciler";
2
- import type { NodeType } from "../dom/types";
3
- import type { Container } from "./Container";
4
- import type { Node } from "./Node";
5
- export declare const debug: (message?: any, ...optionalParams: any[]) => void;
6
- type Instance = Node<unknown>;
7
- type Props = object;
8
- type TextInstance = Node<unknown>;
9
- type SuspenseInstance = Instance;
10
- type HydratableInstance = Instance;
11
- type PublicInstance = Instance;
12
- type HostContext = null;
13
- type UpdatePayload = Container;
14
- type ChildSet = unknown;
15
- type TimeoutHandle = NodeJS.Timeout;
16
- type NoTimeout = -1;
17
- type SkiaHostConfig = HostConfig<NodeType, Props, Container, Instance, TextInstance, SuspenseInstance, HydratableInstance, PublicInstance, HostContext, UpdatePayload, ChildSet, TimeoutHandle, NoTimeout>;
18
- export declare const sksgHostConfig: SkiaHostConfig;
19
- export {};