@shopify/react-native-skia 2.2.9 → 2.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cpp/api/JsiSkParagraph.h +24 -23
- package/cpp/api/recorder/DrawingCtx.h +2 -2
- package/cpp/api/recorder/JsiRecorder.h +3 -4
- package/cpp/api/recorder/Shaders.h +3 -2
- package/cpp/rnskia/RNSkJsiViewApi.h +19 -10
- package/lib/commonjs/renderer/Canvas.d.ts +1 -0
- package/lib/commonjs/renderer/Canvas.js +18 -1
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/sksg/Container.d.ts +1 -1
- package/lib/commonjs/sksg/Container.js +2 -2
- package/lib/commonjs/sksg/Container.js.map +1 -1
- package/lib/commonjs/sksg/Container.native.js +2 -5
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/commonjs/sksg/Container.web.d.ts +2 -3
- package/lib/commonjs/sksg/Container.web.js +7 -14
- package/lib/commonjs/sksg/Container.web.js.map +1 -1
- package/lib/commonjs/sksg/StaticContainer.d.ts +2 -4
- package/lib/commonjs/sksg/StaticContainer.js +1 -8
- package/lib/commonjs/sksg/StaticContainer.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +3 -3
- package/lib/commonjs/specs/NativeSkiaModule.web.js +1 -0
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -2
- package/lib/commonjs/views/SkiaPictureView.web.d.ts +10 -6
- package/lib/commonjs/views/SkiaPictureView.web.js +253 -20
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +1 -0
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +1 -0
- package/lib/module/renderer/Canvas.js +19 -2
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/sksg/Container.d.ts +1 -1
- package/lib/module/sksg/Container.js +2 -2
- package/lib/module/sksg/Container.js.map +1 -1
- package/lib/module/sksg/Container.native.js +2 -5
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/module/sksg/Container.web.d.ts +2 -3
- package/lib/module/sksg/Container.web.js +7 -14
- package/lib/module/sksg/Container.web.js.map +1 -1
- package/lib/module/sksg/StaticContainer.d.ts +2 -4
- package/lib/module/sksg/StaticContainer.js +1 -8
- package/lib/module/sksg/StaticContainer.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.d.ts +3 -3
- package/lib/module/specs/NativeSkiaModule.web.js +1 -0
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -2
- package/lib/module/views/SkiaPictureView.web.d.ts +10 -6
- package/lib/module/views/SkiaPictureView.web.js +251 -18
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/module/views/types.d.ts +1 -0
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.web.d.ts +2 -3
- package/lib/typescript/lib/commonjs/sksg/StaticContainer.d.ts +1 -2
- package/lib/typescript/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +11 -1
- package/lib/typescript/lib/commonjs/views/SkiaPictureView.web.d.ts +1 -6
- package/lib/typescript/lib/module/sksg/Container.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Container.web.d.ts +2 -3
- package/lib/typescript/lib/module/sksg/StaticContainer.d.ts +1 -2
- package/lib/typescript/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -2
- package/lib/typescript/lib/module/views/SkiaPictureView.web.d.ts +2 -6
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -0
- package/lib/typescript/src/sksg/Container.d.ts +1 -1
- package/lib/typescript/src/sksg/Container.web.d.ts +2 -3
- package/lib/typescript/src/sksg/StaticContainer.d.ts +2 -4
- package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +3 -3
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -2
- package/lib/typescript/src/views/SkiaPictureView.web.d.ts +10 -6
- package/lib/typescript/src/views/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/renderer/Canvas.tsx +18 -0
- package/src/renderer/__tests__/e2e/ParagraphMethods.spec.tsx +115 -110
- package/src/sksg/Container.native.ts +2 -9
- package/src/sksg/Container.ts +2 -2
- package/src/sksg/Container.web.ts +7 -25
- package/src/sksg/StaticContainer.ts +2 -17
- package/src/specs/NativeSkiaModule.web.ts +5 -4
- package/src/views/SkiaPictureView.web.tsx +312 -18
- package/src/views/types.ts +4 -0
- package/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -40
- package/lib/commonjs/views/SkiaBaseWebView.js +0 -143
- package/lib/commonjs/views/SkiaBaseWebView.js.map +0 -1
- package/lib/module/views/SkiaBaseWebView.d.ts +0 -40
- package/lib/module/views/SkiaBaseWebView.js +0 -136
- package/lib/module/views/SkiaBaseWebView.js.map +0 -1
- package/lib/typescript/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -39
- package/lib/typescript/lib/module/views/SkiaBaseWebView.d.ts +0 -36
- package/lib/typescript/src/views/SkiaBaseWebView.d.ts +0 -40
- package/src/views/SkiaBaseWebView.tsx +0 -140
@@ -1,5 +1,4 @@
|
|
1
|
-
import type {
|
2
|
-
import type { Skia, SkCanvas, SkSize } from "../skia/types";
|
1
|
+
import type { Skia, SkCanvas } from "../skia/types";
|
3
2
|
import type { Node } from "./Node";
|
4
3
|
import type { Recording } from "./Recorder/Recorder";
|
5
4
|
import "../views/api";
|
@@ -18,7 +17,6 @@ export declare abstract class Container {
|
|
18
17
|
}
|
19
18
|
export declare class StaticContainer extends Container {
|
20
19
|
private nativeId;
|
21
|
-
|
22
|
-
constructor(Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize> | undefined);
|
20
|
+
constructor(Skia: Skia, nativeId: number);
|
23
21
|
redraw(): void;
|
24
22
|
}
|
@@ -34,10 +34,9 @@ export class Container {
|
|
34
34
|
}
|
35
35
|
}
|
36
36
|
export class StaticContainer extends Container {
|
37
|
-
constructor(Skia, nativeId
|
37
|
+
constructor(Skia, nativeId) {
|
38
38
|
super(Skia);
|
39
39
|
this.nativeId = nativeId;
|
40
|
-
this.onSize = onSize;
|
41
40
|
}
|
42
41
|
redraw() {
|
43
42
|
const recorder = new Recorder();
|
@@ -45,12 +44,6 @@ export class StaticContainer extends Container {
|
|
45
44
|
this.recording = recorder.getRecording();
|
46
45
|
const isOnScreen = this.nativeId !== -1;
|
47
46
|
if (isOnScreen) {
|
48
|
-
if (this.onSize) {
|
49
|
-
const size = SkiaViewApi.size(this.nativeId);
|
50
|
-
if (size.width !== this.onSize.value.width || size.height !== this.onSize.value.height) {
|
51
|
-
this.onSize.value = size;
|
52
|
-
}
|
53
|
-
}
|
54
47
|
const rec = this.Skia.PictureRecorder();
|
55
48
|
const canvas = rec.beginRecording();
|
56
49
|
this.drawOnCanvas(canvas);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Recorder","visit","replay","createDrawingContext","Container","constructor","Skia","_defineProperty","root","_root","value","mount","unmounted","unmount","drawOnCanvas","canvas","recording","Error","ctx","paintPool","commands","StaticContainer","nativeId","
|
1
|
+
{"version":3,"names":["Recorder","visit","replay","createDrawingContext","Container","constructor","Skia","_defineProperty","root","_root","value","mount","unmounted","unmount","drawOnCanvas","canvas","recording","Error","ctx","paintPool","commands","StaticContainer","nativeId","redraw","recorder","getRecording","isOnScreen","rec","PictureRecorder","beginRecording","picture","finishRecordingAsPicture","SkiaViewApi","setJsiProperty"],"sources":["StaticContainer.ts"],"sourcesContent":["import type { Skia, SkCanvas } from \"../skia/types\";\n\nimport type { Node } from \"./Node\";\nimport type { Recording } from \"./Recorder/Recorder\";\nimport { Recorder } from \"./Recorder/Recorder\";\nimport { visit } from \"./Recorder/Visitor\";\nimport { replay } from \"./Recorder/Player\";\nimport { createDrawingContext } from \"./Recorder/DrawingContext\";\n\nimport \"../views/api\";\n\nexport abstract class Container {\n private _root: Node[] = [];\n protected recording: Recording | null = null;\n protected unmounted = false;\n\n constructor(protected Skia: Skia) {}\n\n get root() {\n return this._root;\n }\n\n set root(value: Node[]) {\n this._root = value;\n }\n\n mount() {\n this.unmounted = false;\n }\n\n unmount() {\n this.unmounted = true;\n }\n\n drawOnCanvas(canvas: SkCanvas) {\n if (!this.recording) {\n throw new Error(\"No recording to draw\");\n }\n const ctx = createDrawingContext(\n this.Skia,\n this.recording.paintPool,\n canvas\n );\n replay(ctx, this.recording.commands);\n }\n\n abstract redraw(): void;\n}\n\nexport class StaticContainer extends Container {\n constructor(Skia: Skia, private nativeId: number) {\n super(Skia);\n }\n\n redraw() {\n const recorder = new Recorder();\n visit(recorder, this.root);\n this.recording = recorder.getRecording();\n const isOnScreen = this.nativeId !== -1;\n if (isOnScreen) {\n const rec = this.Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n this.drawOnCanvas(canvas);\n const picture = rec.finishRecordingAsPicture();\n SkiaViewApi.setJsiProperty(this.nativeId, \"picture\", picture);\n }\n }\n}\n"],"mappings":";;;AAIA,SAASA,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhE,OAAO,cAAc;AAErB,OAAO,MAAeC,SAAS,CAAC;EAK9BC,WAAWA,CAAWC,IAAU,EAAE;IAAA,KAAZA,IAAU,GAAVA,IAAU;IAAAC,eAAA,gBAJR,EAAE;IAAAA,eAAA,oBACc,IAAI;IAAAA,eAAA,oBACtB,KAAK;EAEQ;EAEnC,IAAIC,IAAIA,CAAA,EAAG;IACT,OAAO,IAAI,CAACC,KAAK;EACnB;EAEA,IAAID,IAAIA,CAACE,KAAa,EAAE;IACtB,IAAI,CAACD,KAA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EAAEQ,OAAO,CAAC;IAC/D;EACF;AACF","ignoreList":[]}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import type { SkPicture } from "../skia/types";
|
2
2
|
import type { ISkiaViewApi } from "../views/types";
|
3
|
-
import type {
|
3
|
+
import type { SkiaPictureViewHandle } from "../views/SkiaPictureView.web";
|
4
4
|
export type ISkiaViewApiWeb = ISkiaViewApi & {
|
5
|
-
views: Record<string,
|
5
|
+
views: Record<string, SkiaPictureViewHandle>;
|
6
6
|
deferedPictures: Record<string, SkPicture>;
|
7
|
-
registerView(nativeId: string, view:
|
7
|
+
registerView(nativeId: string, view: SkiaPictureViewHandle): void;
|
8
8
|
};
|
9
9
|
declare const _default: {};
|
10
10
|
export default _default;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["global","SkiaViewApi","views","deferedPictures","web","registerView","nativeId","view","setPicture","setJsiProperty","name","value","size","getSize","width","height","requestRedraw","redraw","makeImageSnapshot","rect","makeImageSnapshotAsync","Promise","resolve","reject","result","Error"],"sources":["NativeSkiaModule.web.ts"],"sourcesContent":["/* eslint-disable import/no-anonymous-default-export */\nimport type { SkPicture, SkRect } from \"../skia/types\";\nimport type { ISkiaViewApi } from \"../views/types\";\nimport type {
|
1
|
+
{"version":3,"names":["global","SkiaViewApi","views","deferedPictures","deferedOnSize","web","registerView","nativeId","view","setPicture","setJsiProperty","name","value","size","getSize","width","height","requestRedraw","redraw","makeImageSnapshot","rect","makeImageSnapshotAsync","Promise","resolve","reject","result","Error"],"sources":["NativeSkiaModule.web.ts"],"sourcesContent":["/* eslint-disable import/no-anonymous-default-export */\nimport type { SkPicture, SkRect } from \"../skia/types\";\nimport type { ISkiaViewApi } from \"../views/types\";\nimport type { SkiaPictureViewHandle } from \"../views/SkiaPictureView.web\";\n\nexport type ISkiaViewApiWeb = ISkiaViewApi & {\n views: Record<string, SkiaPictureViewHandle>;\n deferedPictures: Record<string, SkPicture>;\n registerView(nativeId: string, view: SkiaPictureViewHandle): void;\n};\n\nglobal.SkiaViewApi = {\n views: {},\n deferedPictures: {},\n deferedOnSize: {},\n web: true,\n registerView(nativeId: string, view: SkiaPictureViewHandle) {\n // Maybe a picture for this view was already set\n if (this.deferedPictures[nativeId]) {\n view.setPicture(this.deferedPictures[nativeId] as SkPicture);\n }\n this.views[nativeId] = view;\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setJsiProperty(nativeId: number, name: string, value: any) {\n if (name === \"picture\") {\n if (!this.views[`${nativeId}`]) {\n this.deferedPictures[`${nativeId}`] = value;\n } else {\n this.views[`${nativeId}`].setPicture(value);\n }\n }\n },\n size(nativeId: number) {\n if (this.views[`${nativeId}`]) {\n return this.views[`${nativeId}`].getSize();\n } else {\n return { width: 0, height: 0 };\n }\n },\n requestRedraw(nativeId: number) {\n this.views[`${nativeId}`].redraw();\n },\n makeImageSnapshot(nativeId: number, rect?: SkRect) {\n return this.views[`${nativeId}`].makeImageSnapshot(rect);\n },\n makeImageSnapshotAsync(nativeId: number, rect?: SkRect) {\n return new Promise((resolve, reject) => {\n const result = this.views[`${nativeId}`].makeImageSnapshot(rect);\n if (result) {\n resolve(result);\n } else {\n reject(new Error(\"Failed to make image snapshot\"));\n }\n });\n },\n} as ISkiaViewApiWeb;\n\n// eslint-disable-next-line import/no-default-export\nexport default {};\n"],"mappings":"AAAA;;AAWAA,MAAM,CAACC,WAAW,GAAG;EACnBC,KAAK,EAAE,CAAC,CAAC;EACTC,eAAe,EAAE,CAAC,CAAC;EACnBC,aAAa,EAAE,CAAC,CAAC;EACjBC,GAAG,EAAE,IAAI;EACTC,YAAYA,CAACC,QAAgB,EAAEC,IAA2B,EAAE;IAC1D;IACA,IAAI,IAAI,CAACL,eAAe,CAACI,QAAQ,CAAC,EAAE;MAClCC,IAAI,CAACC,UAAU,CAAC,IAAI,CAACN,eAAe,CAACI,QAAQ,CAAc,CAAC;IAC9D;IACA,IAAI,CAACL,KAAK,CAACK,QAAQ,CAAC,GAAGC,IAAI;EAC7B,CAA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jB,CAAC,MAAM;QACLD,MAAM,CAAC,IAAIE,KAAK,CAAC,+BAA+B,CAAC,CAAC;MACpD;IACF,CAAC,CAAC;EACJ;AACF,CAAoB;;AAEpB;AACA,eAAe,CAAC,CAAC","ignoreList":[]}
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import type { ViewProps } from "react-native";
|
2
|
-
import { SkiaPictureView } from "../views/SkiaPictureView.web";
|
3
2
|
export interface NativeProps extends ViewProps {
|
4
3
|
debug?: boolean;
|
5
4
|
opaque?: boolean;
|
6
5
|
nativeID: string;
|
7
6
|
}
|
8
|
-
declare const SkiaPictureViewNativeComponent: ({ nativeID, debug, opaque, onLayout, ...viewProps }: NativeProps) => import("react").
|
7
|
+
declare const SkiaPictureViewNativeComponent: ({ nativeID, debug, opaque, onLayout, ...viewProps }: NativeProps) => import("react").FunctionComponentElement<import("..").SkiaPictureViewNativeProps & import("react").RefAttributes<import("../views/SkiaPictureView.web").SkiaPictureViewHandle>>;
|
9
8
|
export default SkiaPictureViewNativeComponent;
|
@@ -1,9 +1,13 @@
|
|
1
|
-
import
|
1
|
+
import React from "react";
|
2
|
+
import type { SkRect, SkPicture, SkImage } from "../skia/types";
|
2
3
|
import type { SkiaPictureViewNativeProps } from "./types";
|
3
|
-
|
4
|
-
export declare class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewNativeProps> {
|
5
|
-
private picture;
|
6
|
-
constructor(props: SkiaPictureViewNativeProps);
|
4
|
+
export interface SkiaPictureViewHandle {
|
7
5
|
setPicture(picture: SkPicture): void;
|
8
|
-
|
6
|
+
getSize(): {
|
7
|
+
width: number;
|
8
|
+
height: number;
|
9
|
+
};
|
10
|
+
redraw(): void;
|
11
|
+
makeImageSnapshot(rect?: SkRect): SkImage | null;
|
9
12
|
}
|
13
|
+
export declare const SkiaPictureView: React.ForwardRefExoticComponent<SkiaPictureViewNativeProps & React.RefAttributes<SkiaPictureViewHandle>>;
|
@@ -1,29 +1,262 @@
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
1
2
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
2
3
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
3
4
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
/* global HTMLCanvasElement */
|
6
|
+
import React, { useRef, useEffect, useCallback, useImperativeHandle, forwardRef } from "react";
|
7
|
+
import { JsiSkSurface } from "../skia/web/JsiSkSurface";
|
8
|
+
import { Platform } from "../Platform";
|
9
|
+
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
10
|
+
class WebGLRenderer {
|
11
|
+
constructor(canvas, pd) {
|
12
|
+
this.canvas = canvas;
|
13
|
+
this.pd = pd;
|
14
|
+
_defineProperty(this, "surface", null);
|
15
|
+
this.onResize();
|
16
|
+
}
|
17
|
+
makeImageSnapshot(picture, rect) {
|
18
|
+
if (!this.surface) {
|
19
|
+
return null;
|
20
|
+
}
|
21
|
+
const canvas = this.surface.getCanvas();
|
22
|
+
canvas.clear(CanvasKit.TRANSPARENT);
|
23
|
+
this.draw(picture);
|
24
|
+
this.surface.ref.flush();
|
25
|
+
return this.surface.makeImageSnapshot(rect);
|
26
|
+
}
|
27
|
+
onResize() {
|
9
28
|
const {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
29
|
+
canvas,
|
30
|
+
pd
|
31
|
+
} = this;
|
32
|
+
canvas.width = canvas.clientWidth * pd;
|
33
|
+
canvas.height = canvas.clientHeight * pd;
|
34
|
+
const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);
|
35
|
+
const ctx = canvas.getContext("webgl2");
|
36
|
+
if (ctx) {
|
37
|
+
ctx.drawingBufferColorSpace = "display-p3";
|
38
|
+
}
|
39
|
+
if (!surface) {
|
40
|
+
throw new Error("Could not create surface");
|
41
|
+
}
|
42
|
+
this.surface = new JsiSkSurface(CanvasKit, surface);
|
43
|
+
}
|
44
|
+
draw(picture) {
|
45
|
+
if (this.surface) {
|
46
|
+
const canvas = this.surface.getCanvas();
|
47
|
+
canvas.clear(Float32Array.of(0, 0, 0, 0));
|
48
|
+
canvas.save();
|
49
|
+
canvas.scale(pd, pd);
|
50
|
+
canvas.drawPicture(picture);
|
51
|
+
canvas.restore();
|
52
|
+
this.surface.ref.flush();
|
53
|
+
}
|
54
|
+
}
|
55
|
+
dispose() {
|
56
|
+
if (this.surface) {
|
57
|
+
var _this$canvas;
|
58
|
+
(_this$canvas = this.canvas) === null || _this$canvas === void 0 || (_this$canvas = _this$canvas.getContext("webgl2")) === null || _this$canvas === void 0 || (_this$canvas = _this$canvas.getExtension("WEBGL_lose_context")) === null || _this$canvas === void 0 || _this$canvas.loseContext();
|
59
|
+
this.surface.ref.delete();
|
60
|
+
this.surface = null;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
class StaticWebGLRenderer {
|
65
|
+
constructor(canvas, pd) {
|
66
|
+
this.canvas = canvas;
|
67
|
+
this.pd = pd;
|
68
|
+
_defineProperty(this, "cachedImage", null);
|
69
|
+
}
|
70
|
+
onResize() {
|
71
|
+
this.cachedImage = null;
|
72
|
+
}
|
73
|
+
renderPictureToSurface(picture) {
|
74
|
+
const tempCanvas = new OffscreenCanvas(this.canvas.clientWidth * this.pd, this.canvas.clientHeight * this.pd);
|
75
|
+
let surface = null;
|
76
|
+
try {
|
77
|
+
const webglSurface = CanvasKit.MakeWebGLCanvasSurface(tempCanvas);
|
78
|
+
const ctx = tempCanvas.getContext("webgl2");
|
79
|
+
if (ctx) {
|
80
|
+
ctx.drawingBufferColorSpace = "display-p3";
|
81
|
+
}
|
82
|
+
if (!webglSurface) {
|
83
|
+
throw new Error("Could not create WebGL surface");
|
84
|
+
}
|
85
|
+
surface = new JsiSkSurface(CanvasKit, webglSurface);
|
86
|
+
const skiaCanvas = surface.getCanvas();
|
87
|
+
skiaCanvas.clear(Float32Array.of(0, 0, 0, 0));
|
88
|
+
skiaCanvas.save();
|
89
|
+
skiaCanvas.scale(this.pd, this.pd);
|
90
|
+
skiaCanvas.drawPicture(picture);
|
91
|
+
skiaCanvas.restore();
|
92
|
+
surface.ref.flush();
|
93
|
+
return {
|
94
|
+
surface,
|
95
|
+
tempCanvas
|
96
|
+
};
|
97
|
+
} catch (error) {
|
98
|
+
if (surface) {
|
99
|
+
surface.ref.delete();
|
100
|
+
}
|
101
|
+
this.cleanupWebGLContext(tempCanvas);
|
102
|
+
return null;
|
14
103
|
}
|
15
|
-
global.SkiaViewApi.registerView(nativeID, this);
|
16
104
|
}
|
17
|
-
|
18
|
-
|
19
|
-
|
105
|
+
cleanupWebGLContext(tempCanvas) {
|
106
|
+
const ctx = tempCanvas.getContext("webgl2");
|
107
|
+
if (ctx) {
|
108
|
+
const loseContext = ctx.getExtension("WEBGL_lose_context");
|
109
|
+
if (loseContext) {
|
110
|
+
loseContext.loseContext();
|
111
|
+
}
|
112
|
+
}
|
20
113
|
}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
114
|
+
draw(picture) {
|
115
|
+
const renderResult = this.renderPictureToSurface(picture);
|
116
|
+
if (!renderResult) {
|
117
|
+
return;
|
118
|
+
}
|
119
|
+
const {
|
120
|
+
tempCanvas
|
121
|
+
} = renderResult;
|
122
|
+
const ctx2d = this.canvas.getContext("2d");
|
123
|
+
if (!ctx2d) {
|
124
|
+
throw new Error("Could not get 2D context");
|
26
125
|
}
|
126
|
+
|
127
|
+
// Set canvas dimensions to match pixel density
|
128
|
+
this.canvas.width = this.canvas.clientWidth * this.pd;
|
129
|
+
this.canvas.height = this.canvas.clientHeight * this.pd;
|
130
|
+
|
131
|
+
// Draw the tempCanvas scaled down to the display size
|
132
|
+
ctx2d.drawImage(tempCanvas, 0, 0, tempCanvas.width, tempCanvas.height, 0, 0, this.canvas.clientWidth * this.pd, this.canvas.clientHeight * this.pd);
|
133
|
+
this.cleanupWebGLContext(tempCanvas);
|
134
|
+
}
|
135
|
+
makeImageSnapshot(picture, rect) {
|
136
|
+
if (!this.cachedImage) {
|
137
|
+
const renderResult = this.renderPictureToSurface(picture);
|
138
|
+
if (!renderResult) {
|
139
|
+
return null;
|
140
|
+
}
|
141
|
+
const {
|
142
|
+
surface,
|
143
|
+
tempCanvas
|
144
|
+
} = renderResult;
|
145
|
+
try {
|
146
|
+
this.cachedImage = surface.makeImageSnapshot(rect);
|
147
|
+
} catch (error) {
|
148
|
+
console.error("Error creating image snapshot:", error);
|
149
|
+
} finally {
|
150
|
+
surface.ref.delete();
|
151
|
+
this.cleanupWebGLContext(tempCanvas);
|
152
|
+
}
|
153
|
+
}
|
154
|
+
return this.cachedImage;
|
155
|
+
}
|
156
|
+
dispose() {
|
157
|
+
var _this$cachedImage;
|
158
|
+
(_this$cachedImage = this.cachedImage) === null || _this$cachedImage === void 0 || _this$cachedImage.dispose();
|
159
|
+
this.cachedImage = null;
|
27
160
|
}
|
28
161
|
}
|
162
|
+
const pd = Platform.PixelRatio;
|
163
|
+
export const SkiaPictureView = /*#__PURE__*/forwardRef((props, ref) => {
|
164
|
+
const canvasRef = useRef(null);
|
165
|
+
const renderer = useRef(null);
|
166
|
+
const redrawRequestsRef = useRef(0);
|
167
|
+
const requestIdRef = useRef(0);
|
168
|
+
const pictureRef = useRef(null);
|
169
|
+
const {
|
170
|
+
picture,
|
171
|
+
onLayout
|
172
|
+
} = props;
|
173
|
+
const redraw = useCallback(() => {
|
174
|
+
redrawRequestsRef.current++;
|
175
|
+
}, []);
|
176
|
+
const getSize = useCallback(() => {
|
177
|
+
var _canvasRef$current, _canvasRef$current2;
|
178
|
+
return {
|
179
|
+
width: ((_canvasRef$current = canvasRef.current) === null || _canvasRef$current === void 0 ? void 0 : _canvasRef$current.clientWidth) || 0,
|
180
|
+
height: ((_canvasRef$current2 = canvasRef.current) === null || _canvasRef$current2 === void 0 ? void 0 : _canvasRef$current2.clientHeight) || 0
|
181
|
+
};
|
182
|
+
}, []);
|
183
|
+
const setPicture = useCallback(newPicture => {
|
184
|
+
pictureRef.current = newPicture;
|
185
|
+
redraw();
|
186
|
+
}, [redraw]);
|
187
|
+
const makeImageSnapshot = useCallback(rect => {
|
188
|
+
if (renderer.current && pictureRef.current) {
|
189
|
+
return renderer.current.makeImageSnapshot(pictureRef.current, rect);
|
190
|
+
}
|
191
|
+
return null;
|
192
|
+
}, []);
|
193
|
+
const tick = useCallback(() => {
|
194
|
+
if (redrawRequestsRef.current > 0) {
|
195
|
+
redrawRequestsRef.current = 0;
|
196
|
+
if (renderer.current && pictureRef.current) {
|
197
|
+
renderer.current.draw(pictureRef.current);
|
198
|
+
}
|
199
|
+
}
|
200
|
+
requestIdRef.current = requestAnimationFrame(tick);
|
201
|
+
}, []);
|
202
|
+
const onLayoutEvent = useCallback(evt => {
|
203
|
+
const canvas = canvasRef.current;
|
204
|
+
if (canvas) {
|
205
|
+
renderer.current = props.__destroyWebGLContextAfterRender === true ? new StaticWebGLRenderer(canvas, pd) : new WebGLRenderer(canvas, pd);
|
206
|
+
if (pictureRef.current) {
|
207
|
+
renderer.current.draw(pictureRef.current);
|
208
|
+
}
|
209
|
+
}
|
210
|
+
if (onLayout) {
|
211
|
+
onLayout(evt);
|
212
|
+
}
|
213
|
+
}, [onLayout, props.__destroyWebGLContextAfterRender]);
|
214
|
+
useImperativeHandle(ref, () => ({
|
215
|
+
setPicture,
|
216
|
+
getSize,
|
217
|
+
redraw,
|
218
|
+
makeImageSnapshot
|
219
|
+
}), [setPicture, getSize, redraw, makeImageSnapshot]);
|
220
|
+
useEffect(() => {
|
221
|
+
var _props$nativeID;
|
222
|
+
const nativeID = (_props$nativeID = props.nativeID) !== null && _props$nativeID !== void 0 ? _props$nativeID : `${SkiaViewNativeId.current++}`;
|
223
|
+
global.SkiaViewApi.registerView(nativeID, {
|
224
|
+
setPicture,
|
225
|
+
getSize,
|
226
|
+
redraw,
|
227
|
+
makeImageSnapshot
|
228
|
+
});
|
229
|
+
if (props.picture) {
|
230
|
+
setPicture(props.picture);
|
231
|
+
}
|
232
|
+
}, [setPicture, getSize, redraw, makeImageSnapshot, props]);
|
233
|
+
useEffect(() => {
|
234
|
+
tick();
|
235
|
+
return () => {
|
236
|
+
cancelAnimationFrame(requestIdRef.current);
|
237
|
+
if (renderer.current) {
|
238
|
+
renderer.current.dispose();
|
239
|
+
renderer.current = null;
|
240
|
+
}
|
241
|
+
};
|
242
|
+
}, [tick]);
|
243
|
+
useEffect(() => {
|
244
|
+
if (renderer.current && pictureRef.current) {
|
245
|
+
renderer.current.draw(pictureRef.current);
|
246
|
+
}
|
247
|
+
}, [picture, redraw]);
|
248
|
+
const {
|
249
|
+
debug = false,
|
250
|
+
...viewProps
|
251
|
+
} = props;
|
252
|
+
return /*#__PURE__*/React.createElement(Platform.View, _extends({}, viewProps, {
|
253
|
+
onLayout: onLayoutEvent
|
254
|
+
}), /*#__PURE__*/React.createElement("canvas", {
|
255
|
+
ref: canvasRef,
|
256
|
+
style: {
|
257
|
+
display: "flex",
|
258
|
+
flex: 1
|
259
|
+
}
|
260
|
+
}));
|
261
|
+
});
|
29
262
|
//# sourceMappingURL=SkiaPictureView.web.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["SkiaBaseWebView","SkiaPictureView","constructor","props","_defineProperty","nativeID","Error","global","SkiaViewApi","registerView","setPicture","picture","redraw","renderInCanvas","canvas","drawPicture"],"sources":["SkiaPictureView.web.tsx"],"sourcesContent":["import type { SkCanvas, SkPicture } from \"../skia/types\";\nimport type { ISkiaViewApiWeb } from \"../specs/NativeSkiaModule.web\";\n\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaBaseWebView } from \"./SkiaBaseWebView\";\n\nexport class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewNativeProps> {\n private picture: SkPicture | null = null;\n\n constructor(props: SkiaPictureViewNativeProps) {\n super(props);\n const { nativeID } = props;\n if (!nativeID) {\n throw new Error(\"SkiaPictureView requires a nativeID prop\");\n }\n (global.SkiaViewApi as ISkiaViewApiWeb).registerView(nativeID, this);\n }\n\n public setPicture(picture: SkPicture) {\n this.picture = picture;\n this.redraw();\n }\n\n protected renderInCanvas(canvas: SkCanvas): void {\n if (this.props.picture) {\n canvas.drawPicture(this.props.picture);\n } else if (this.picture) {\n canvas.drawPicture(this.picture);\n }\n }\n}\n"],"mappings":";;;AAIA,SAASA,eAAe,QAAQ,mBAAmB;AAEnD,OAAO,MAAMC,eAAe,SAASD,eAAe,CAA6B;EAG/EE,WAAWA,CAACC,KAAiC,EAAE;IAC7C,KAAK,CAACA,KAAK,CAAC;IAACC,eAAA,kBAHqB,IAAI;IAItC,MAAM;MAAEC;IAAS,CAAC,GAAGF,KAAK;IAC1B,IAAI,CAACE,QAAQ,EAAE;MACb,MAAM,IAAIC,KAAK,CAAC,0CAA0C,CAAC;IAC7D;IACCC,MAAM,CAACC,WAAW,CAAqBC,YAAY,CAACJ,QAAQ,EAAE,IAAI,CAAC;EACtE;EAEOK,UAAUA,CAACC,OAAkB,EAAE;IACpC,IAAI,CAACA,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,MAAM,CAAC,CAAC;EACf;EAEUC,cAAcA,CAACC,MAAgB,EAAQ;IAC/C,IAAI,IAAI,CAACX,KAAK,CAACQ,OAAO,EAAE;MACtBG,MAAM,CAACC,WAAW,CAAC,IAAI,CAACZ,KAAK,CAACQ,OAAO,CAAC;IACxC,CAAC,MAAM,IAAI,IAAI,CAACA,OAAO,EAAE;MACvBG,MAAM,CAACC,WAAW,CAAC,IAAI,CAACJ,OAAO,CAAC;IAClC;EACF;AACF","ignoreList":[]}
|
1
|
+
{"version":3,"names":["React","useRef","useEffect","useCallback","useImperativeHandle","forwardRef","JsiSkSurface","Platform","SkiaViewNativeId","WebGLRenderer","constructor","canvas","pd","_defineProperty","onResize","makeImageSnapshot","picture","rect","surface","getCanvas","clear","CanvasKit","TRANSPARENT","draw","ref","flush","width","clientWidth","height","clientHeight","MakeWebGLCanvasSurface","ctx","getContext","drawingBufferColorSpace","Error","Float32Array","of","save","scale","drawPicture","restore","dispose","_this$canvas","getExtension","loseContext","delete","StaticWebGLRenderer","cachedImage","renderPictureToSurface","tempCanvas","OffscreenCanvas","webglSurface","skiaCanvas","error","cleanupWebGLContext","renderResult","ctx2d","drawImage","console","_this$cachedImage","PixelRatio","SkiaPictureView","props","canvasRef","renderer","redrawRequestsRef","requestIdRef","pictureRef","onLayout","redraw","current","getSize","_canvasRef$current","_canvasRef$current2","setPicture","newPicture","tick","requestAnimationFrame","onLayoutEvent","evt","__destroyWebGLContextAfterRender","_props$nativeID","nativeID","global","SkiaViewApi","registerView","cancelAnimationFrame","debug","viewProps","createElement","View","_extends","style","display","flex"],"sources":["SkiaPictureView.web.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React, {\n useRef,\n useEffect,\n useCallback,\n useImperativeHandle,\n forwardRef,\n} from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport type { SkRect, SkPicture, SkImage } from \"../skia/types\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\nimport { Platform } from \"../Platform\";\nimport type { ISkiaViewApiWeb } from \"../specs/NativeSkiaModule.web\";\n\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\ninterface Renderer {\n onResize(): void;\n draw(picture: SkPicture): void;\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null;\n dispose(): void;\n}\n\nclass WebGLRenderer implements Renderer {\n private surface: JsiSkSurface | null = null;\n\n constructor(private canvas: HTMLCanvasElement, private pd: number) {\n this.onResize();\n }\n\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null {\n if (!this.surface) {\n return null;\n }\n const canvas = this.surface.getCanvas();\n canvas!.clear(CanvasKit.TRANSPARENT);\n this.draw(picture);\n this.surface.ref.flush();\n return this.surface.makeImageSnapshot(rect);\n }\n\n onResize() {\n const { canvas, pd } = this;\n canvas.width = canvas.clientWidth * pd;\n canvas.height = canvas.clientHeight * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);\n const ctx = canvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this.surface = new JsiSkSurface(CanvasKit, surface);\n }\n\n draw(picture: SkPicture) {\n if (this.surface) {\n const canvas = this.surface.getCanvas();\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(pd, pd);\n canvas.drawPicture(picture);\n canvas.restore();\n this.surface.ref.flush();\n }\n }\n\n dispose(): void {\n if (this.surface) {\n this.canvas\n ?.getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\n this.surface.ref.delete();\n this.surface = null;\n }\n }\n}\n\nclass StaticWebGLRenderer implements Renderer {\n private cachedImage: SkImage | null = null;\n\n constructor(private canvas: HTMLCanvasElement, private pd: number) {}\n\n onResize(): void {\n this.cachedImage = null;\n }\n\n private renderPictureToSurface(\n picture: SkPicture\n ): { surface: JsiSkSurface; tempCanvas: OffscreenCanvas } | null {\n const tempCanvas = new OffscreenCanvas(\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n let surface: JsiSkSurface | null = null;\n\n try {\n const webglSurface = CanvasKit.MakeWebGLCanvasSurface(tempCanvas);\n const ctx = tempCanvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n\n if (!webglSurface) {\n throw new Error(\"Could not create WebGL surface\");\n }\n\n surface = new JsiSkSurface(CanvasKit, webglSurface);\n\n const skiaCanvas = surface.getCanvas();\n skiaCanvas.clear(Float32Array.of(0, 0, 0, 0));\n skiaCanvas.save();\n skiaCanvas.scale(this.pd, this.pd);\n skiaCanvas.drawPicture(picture);\n skiaCanvas.restore();\n surface.ref.flush();\n\n return { surface, tempCanvas };\n } catch (error) {\n if (surface) {\n surface.ref.delete();\n }\n this.cleanupWebGLContext(tempCanvas);\n return null;\n }\n }\n\n private cleanupWebGLContext(tempCanvas: OffscreenCanvas): void {\n const ctx = tempCanvas.getContext(\"webgl2\");\n if (ctx) {\n const loseContext = ctx.getExtension(\"WEBGL_lose_context\");\n if (loseContext) {\n loseContext.loseContext();\n }\n }\n }\n\n draw(picture: SkPicture): void {\n const renderResult = this.renderPictureToSurface(picture);\n if (!renderResult) {\n return;\n }\n const { tempCanvas } = renderResult;\n const ctx2d = this.canvas.getContext(\"2d\");\n if (!ctx2d) {\n throw new Error(\"Could not get 2D context\");\n }\n\n // Set canvas dimensions to match pixel density\n this.canvas.width = this.canvas.clientWidth * this.pd;\n this.canvas.height = this.canvas.clientHeight * this.pd;\n\n // Draw the tempCanvas scaled down to the display size\n ctx2d.drawImage(\n tempCanvas,\n 0,\n 0,\n tempCanvas.width,\n tempCanvas.height,\n 0,\n 0,\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n this.cleanupWebGLContext(tempCanvas);\n }\n\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null {\n if (!this.cachedImage) {\n const renderResult = this.renderPictureToSurface(picture);\n if (!renderResult) {\n return null;\n }\n\n const { surface, tempCanvas } = renderResult;\n\n try {\n this.cachedImage = surface.makeImageSnapshot(rect);\n } catch (error) {\n console.error(\"Error creating image snapshot:\", error);\n } finally {\n surface.ref.delete();\n this.cleanupWebGLContext(tempCanvas);\n }\n }\n\n return this.cachedImage;\n }\n\n dispose(): void {\n this.cachedImage?.dispose();\n this.cachedImage = null;\n }\n}\n\nconst pd = Platform.PixelRatio;\n\nexport interface SkiaPictureViewHandle {\n setPicture(picture: SkPicture): void;\n getSize(): { width: number; height: number };\n redraw(): void;\n makeImageSnapshot(rect?: SkRect): SkImage | null;\n}\n\nexport const SkiaPictureView = forwardRef<\n SkiaPictureViewHandle,\n SkiaPictureViewNativeProps\n>((props, ref) => {\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n const renderer = useRef<Renderer | null>(null);\n const redrawRequestsRef = useRef(0);\n const requestIdRef = useRef(0);\n const pictureRef = useRef<SkPicture | null>(null);\n\n const { picture, onLayout } = props;\n\n const redraw = useCallback(() => {\n redrawRequestsRef.current++;\n }, []);\n\n const getSize = useCallback(() => {\n return {\n width: canvasRef.current?.clientWidth || 0,\n height: canvasRef.current?.clientHeight || 0,\n };\n }, []);\n\n const setPicture = useCallback(\n (newPicture: SkPicture) => {\n pictureRef.current = newPicture;\n redraw();\n },\n [redraw]\n );\n\n const makeImageSnapshot = useCallback((rect?: SkRect) => {\n if (renderer.current && pictureRef.current) {\n return renderer.current.makeImageSnapshot(pictureRef.current, rect);\n }\n return null;\n }, []);\n\n const tick = useCallback(() => {\n if (redrawRequestsRef.current > 0) {\n redrawRequestsRef.current = 0;\n if (renderer.current && pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }\n requestIdRef.current = requestAnimationFrame(tick);\n }, []);\n\n const onLayoutEvent = useCallback(\n (evt: LayoutChangeEvent) => {\n const canvas = canvasRef.current;\n if (canvas) {\n renderer.current =\n props.__destroyWebGLContextAfterRender === true\n ? new StaticWebGLRenderer(canvas, pd)\n : new WebGLRenderer(canvas, pd);\n if (pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }\n if (onLayout) {\n onLayout(evt);\n }\n },\n [onLayout, props.__destroyWebGLContextAfterRender]\n );\n\n useImperativeHandle(\n ref,\n () => ({\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n }),\n [setPicture, getSize, redraw, makeImageSnapshot]\n );\n\n useEffect(() => {\n const nativeID = props.nativeID ?? `${SkiaViewNativeId.current++}`;\n (global.SkiaViewApi as ISkiaViewApiWeb).registerView(nativeID, {\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n } as SkiaPictureViewHandle);\n if (props.picture) {\n setPicture(props.picture);\n }\n }, [setPicture, getSize, redraw, makeImageSnapshot, props]);\n\n useEffect(() => {\n tick();\n return () => {\n cancelAnimationFrame(requestIdRef.current);\n if (renderer.current) {\n renderer.current.dispose();\n renderer.current = null;\n }\n };\n }, [tick]);\n\n useEffect(() => {\n if (renderer.current && pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }, [picture, redraw]);\n\n const { debug = false, ...viewProps } = props;\n return (\n <Platform.View {...viewProps} onLayout={onLayoutEvent}>\n <canvas ref={canvasRef} style={{ display: \"flex\", flex: 1 }} />\n </Platform.View>\n );\n});\n"],"mappings":";;;;AAAA;AACA,OAAOA,KAAK,IACVC,MAAM,EACNC,SAAS,EACTC,WAAW,EACXC,mBAAmB,EACnBC,UAAU,QACL,OAAO;AAId,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,QAAQ,QAAQ,aAAa;AAItC,SAASC,gBAAgB,QAAQ,oBAAoB;AASrD,MAAMC,aAAa,CAAqB;EAGtCC,WAAWA,CAASC,MAAyB,EAAUC,EAAU,EAAE;IAAA,KAA/CD,MAAyB,GAAzBA,MAAyB;IAAA,KAAUC,EAAU,GAAVA,EAAU;IAAAC,eAAA,kBAF1B,IAAI;IAGzC,IAAI,CAACC,QAAQ,CAAC,CAAC;EACjB;EAEAC,iBAAiBA,CAACC,OAAkB,EAAEC,IAAa,EAAkB;IACnE,IAAI,CAAC,IAAI,CAACC,OAAO,EAAE;MACjB,OAAO,IAAI;IACb;IACA,MAAMP,MAAM,GAAG,IAAI,CAACO,OAAO,CAACC,SAAS,CAA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AAO,IAAIH,UAAU,CAACG,OAAO,EAAE;MAC1CN,QAAQ,CAACM,OAAO,CAAC/C,IAAI,CAAC4C,UAAU,CAACG,OAAO,CAAC;IAC3C;EACF,CAAC,EAAE,CAACtD,OAAO,EAAEqD,MAAM,CAAC,CAAC;EAErB,MAAM;IAAEkB,KAAK,GAAG,KAAK;IAAE,GAAGC;EAAU,CAAC,GAAG1B,KAAK;EAC7C,oBACE9D,KAAA,CAAAyF,aAAA,CAAClF,QAAQ,CAACmF,IAAI,EAAAC,QAAA,KAAKH,SAAS;IAAEpB,QAAQ,EAAEU;EAAc,iBACpD9E,KAAA,CAAAyF,aAAA;IAAQjE,GAAG,EAAEuC,SAAU;IAAC6B,KAAK,EAAE;MAAEC,OAAO,EAAE,MAAM;MAAEC,IAAI,EAAE;IAAE;EAAE,CAAE,CACjD,CAAC;AAEpB,CAAC,CAAC","ignoreList":[]}
|
@@ -26,6 +26,7 @@ export interface SkiaBaseViewProps extends ViewProps {
|
|
26
26
|
*/
|
27
27
|
onSize?: SharedValue<SkSize>;
|
28
28
|
opaque?: boolean;
|
29
|
+
__destroyWebGLContextAfterRender?: boolean;
|
29
30
|
}
|
30
31
|
export interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {
|
31
32
|
picture?: SkPicture;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type { Node } from \"../dom/types\";\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n debug?: boolean;\n opaque?: boolean;\n};\n\nexport interface ISkiaViewApi {\n web?: boolean;\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;\n size: (nativeId: number) => SkSize;\n}\n\nexport interface SkiaBaseViewProps extends ViewProps {\n /**\n * When set to true the view will display information about the\n * average time it takes to render.\n */\n debug?: boolean;\n /**\n * Pass an animated value to the onSize property to get updates when\n * the Skia view is resized.\n */\n onSize?: SharedValue<SkSize>;\n\n opaque?: boolean;\n}\n\nexport interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {\n picture?: SkPicture;\n}\n\nexport interface SkiaDomViewNativeProps extends SkiaBaseViewProps {\n root?: Node<unknown>;\n}\n"],"mappings":"","ignoreList":[]}
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type { Node } from \"../dom/types\";\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n debug?: boolean;\n opaque?: boolean;\n};\n\nexport interface ISkiaViewApi {\n web?: boolean;\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;\n size: (nativeId: number) => SkSize;\n}\n\nexport interface SkiaBaseViewProps extends ViewProps {\n /**\n * When set to true the view will display information about the\n * average time it takes to render.\n */\n debug?: boolean;\n /**\n * Pass an animated value to the onSize property to get updates when\n * the Skia view is resized.\n */\n onSize?: SharedValue<SkSize>;\n\n opaque?: boolean;\n\n // On web, only 16 WebGL contextes are allowed. If the drawing is non-animated, set\n // __destroyWebGLContextAfterRender to true to release the context after each draw.\n __destroyWebGLContextAfterRender?: boolean;\n}\n\nexport interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {\n picture?: SkPicture;\n}\n\nexport interface SkiaDomViewNativeProps extends SkiaBaseViewProps {\n root?: Node<unknown>;\n}\n"],"mappings":"","ignoreList":[]}
|
@@ -1,3 +1,3 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
|
-
export function createContainer(Skia: any, nativeId: any,
|
2
|
+
export function createContainer(Skia: any, nativeId: any, _onSize: any): _StaticContainer.StaticContainer;
|
3
3
|
import _StaticContainer = require("./StaticContainer");
|
@@ -1,10 +1,9 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
|
-
export function createContainer(Skia: any, nativeId: any,
|
2
|
+
export function createContainer(Skia: any, nativeId: any, _onSize: any): _StaticContainer.StaticContainer | ReanimatedContainer;
|
3
3
|
import _StaticContainer = require("./StaticContainer");
|
4
4
|
declare class ReanimatedContainer extends _StaticContainer.Container {
|
5
|
-
constructor(Skia: any, nativeId: any
|
5
|
+
constructor(Skia: any, nativeId: any);
|
6
6
|
nativeId: any;
|
7
|
-
onSize: any;
|
8
7
|
redraw(): void;
|
9
8
|
recording: {
|
10
9
|
commands: any;
|
@@ -11,9 +11,8 @@ export class Container {
|
|
11
11
|
drawOnCanvas(canvas: any): void;
|
12
12
|
}
|
13
13
|
export class StaticContainer extends Container {
|
14
|
-
constructor(Skia: any, nativeId: any
|
14
|
+
constructor(Skia: any, nativeId: any);
|
15
15
|
nativeId: any;
|
16
|
-
onSize: any;
|
17
16
|
redraw(): void;
|
18
17
|
recording: {
|
19
18
|
commands: any;
|
@@ -6,5 +6,15 @@ declare function SkiaPictureViewNativeComponent({ nativeID, debug, opaque, onLay
|
|
6
6
|
debug: any;
|
7
7
|
opaque: any;
|
8
8
|
onLayout: any;
|
9
|
-
}): _react.
|
9
|
+
}): _react.CElement<{
|
10
|
+
nativeID: any;
|
11
|
+
debug: any;
|
12
|
+
opaque: any;
|
13
|
+
onLayout: any;
|
14
|
+
}, _react.Component<{
|
15
|
+
nativeID: any;
|
16
|
+
debug: any;
|
17
|
+
opaque: any;
|
18
|
+
onLayout: any;
|
19
|
+
}, any, any>>;
|
10
20
|
import _react = require("react");
|
@@ -1,7 +1,2 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
|
-
export
|
3
|
-
setPicture(picture: any): void;
|
4
|
-
picture: any;
|
5
|
-
renderInCanvas(canvas: any): void;
|
6
|
-
}
|
7
|
-
import _SkiaBaseWebView = require("./SkiaBaseWebView");
|
2
|
+
export const SkiaPictureView: any;
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export function createContainer(Skia: any, nativeId: any,
|
1
|
+
export function createContainer(Skia: any, nativeId: any, _onSize: any): StaticContainer;
|
2
2
|
import { StaticContainer } from "./StaticContainer";
|
@@ -1,9 +1,8 @@
|
|
1
|
-
export function createContainer(Skia: any, nativeId: any,
|
1
|
+
export function createContainer(Skia: any, nativeId: any, _onSize: any): StaticContainer | ReanimatedContainer;
|
2
2
|
import { StaticContainer } from "./StaticContainer";
|
3
3
|
declare class ReanimatedContainer extends Container {
|
4
|
-
constructor(Skia: any, nativeId: any
|
4
|
+
constructor(Skia: any, nativeId: any);
|
5
5
|
nativeId: any;
|
6
|
-
onSize: any;
|
7
6
|
redraw(): void;
|
8
7
|
recording: {
|
9
8
|
commands: any;
|
@@ -10,9 +10,8 @@ export class Container {
|
|
10
10
|
drawOnCanvas(canvas: any): void;
|
11
11
|
}
|
12
12
|
export class StaticContainer extends Container {
|
13
|
-
constructor(Skia: any, nativeId: any
|
13
|
+
constructor(Skia: any, nativeId: any);
|
14
14
|
nativeId: any;
|
15
|
-
onSize: any;
|
16
15
|
redraw(): void;
|
17
16
|
recording: {
|
18
17
|
commands: any;
|
@@ -5,5 +5,4 @@ declare function SkiaPictureViewNativeComponent({ nativeID, debug, opaque, onLay
|
|
5
5
|
debug: any;
|
6
6
|
opaque: any;
|
7
7
|
onLayout: any;
|
8
|
-
}): import("react").
|
9
|
-
import { SkiaPictureView } from "../views/SkiaPictureView.web";
|
8
|
+
}): import("react").DetailedReactHTMLElement<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
|
@@ -1,6 +1,2 @@
|
|
1
|
-
export
|
2
|
-
|
3
|
-
picture: any;
|
4
|
-
renderInCanvas(canvas: any): void;
|
5
|
-
}
|
6
|
-
import { SkiaBaseWebView } from "./SkiaBaseWebView";
|
1
|
+
export const SkiaPictureView: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
|
2
|
+
import React from "react";
|
@@ -23,5 +23,6 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
|
23
23
|
onSize?: SharedValue<SkSize>;
|
24
24
|
colorSpace?: "p3" | "srgb";
|
25
25
|
ref?: React.Ref<CanvasRef>;
|
26
|
+
__destroyWebGLContextAfterRender?: boolean;
|
26
27
|
}
|
27
28
|
export declare const Canvas: ({ debug, opaque, children, onSize, colorSpace, ref, onLayout, ...viewProps }: CanvasProps) => React.JSX.Element;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import type { SharedValue } from "react-native-reanimated";
|
2
2
|
import type { Skia, SkSize } from "../skia/types";
|
3
3
|
import { StaticContainer } from "./StaticContainer";
|
4
|
-
export declare const createContainer: (Skia: Skia, nativeId: number,
|
4
|
+
export declare const createContainer: (Skia: Skia, nativeId: number, _onSize?: SharedValue<SkSize>) => StaticContainer;
|
@@ -5,10 +5,9 @@ import "../skia/NativeSetup";
|
|
5
5
|
import "../views/api";
|
6
6
|
declare class ReanimatedContainer extends Container {
|
7
7
|
private nativeId;
|
8
|
-
private onSize?;
|
9
8
|
private mapperId;
|
10
|
-
constructor(Skia: Skia, nativeId: number
|
9
|
+
constructor(Skia: Skia, nativeId: number);
|
11
10
|
redraw(): void;
|
12
11
|
}
|
13
|
-
export declare const createContainer: (Skia: Skia, nativeId: number,
|
12
|
+
export declare const createContainer: (Skia: Skia, nativeId: number, _onSize?: SharedValue<SkSize>) => StaticContainer | ReanimatedContainer;
|
14
13
|
export {};
|