react-native-webgpu 0.8.4 → 0.8.5
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/lib/commonjs/WebGPUViewNativeComponent.web.js +6 -49
- package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -1
- package/lib/module/WebGPUViewNativeComponent.web.js +5 -48
- package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -1
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/WebGPUViewNativeComponent.web.ts +4 -60
|
@@ -4,43 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = WebGPUViewNativeComponent;
|
|
7
|
-
var _react =
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _utils = require("./utils");
|
|
10
|
-
function
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
-
function debounce(func, wait, immediate = false) {
|
|
13
|
-
let timeout;
|
|
14
|
-
return function debounced(...args) {
|
|
15
|
-
const context = this;
|
|
16
|
-
const callNow = immediate && !timeout;
|
|
17
|
-
if (timeout) {
|
|
18
|
-
clearTimeout(timeout);
|
|
19
|
-
}
|
|
20
|
-
timeout = setTimeout(() => {
|
|
21
|
-
timeout = undefined;
|
|
22
|
-
if (!immediate) {
|
|
23
|
-
func.apply(context, args);
|
|
24
|
-
}
|
|
25
|
-
}, wait);
|
|
26
|
-
if (callNow) {
|
|
27
|
-
func.apply(context, args);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function resizeCanvas(canvas) {
|
|
32
|
-
if (!canvas) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const dpr = window.devicePixelRatio || 1;
|
|
36
|
-
const {
|
|
37
|
-
height,
|
|
38
|
-
width
|
|
39
|
-
} = canvas.getBoundingClientRect();
|
|
40
|
-
canvas.setAttribute("height", (height * dpr).toString());
|
|
41
|
-
canvas.setAttribute("width", (width * dpr).toString());
|
|
42
|
-
}
|
|
43
|
-
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
44
11
|
// eslint-disable-next-line import/no-default-export
|
|
45
12
|
function WebGPUViewNativeComponent(props) {
|
|
46
13
|
const {
|
|
@@ -49,14 +16,10 @@ function WebGPUViewNativeComponent(props) {
|
|
|
49
16
|
transparent,
|
|
50
17
|
...rest
|
|
51
18
|
} = props;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return () => {
|
|
57
|
-
window.removeEventListener("resize", onResize);
|
|
58
|
-
};
|
|
59
|
-
}, []);
|
|
19
|
+
|
|
20
|
+
// MakeWebGPUCanvasContext sets the initial drawing-buffer size. Subsequent
|
|
21
|
+
// resizes belong to the renderer so it can recreate depth/MSAA attachments
|
|
22
|
+
// together; changing canvas.width/height here would invalidate its textures.
|
|
60
23
|
return /*#__PURE__*/_react.default.createElement("canvas", {
|
|
61
24
|
...rest,
|
|
62
25
|
id: (0, _utils.contextIdToId)(contextId),
|
|
@@ -67,12 +30,6 @@ function WebGPUViewNativeComponent(props) {
|
|
|
67
30
|
backgroundColor: "white"
|
|
68
31
|
} : {}),
|
|
69
32
|
...(typeof style === "object" ? style : {})
|
|
70
|
-
},
|
|
71
|
-
ref: ref => {
|
|
72
|
-
canvasElm.current = ref;
|
|
73
|
-
if (ref) {
|
|
74
|
-
resizeCanvas(ref);
|
|
75
|
-
}
|
|
76
33
|
}
|
|
77
34
|
});
|
|
78
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_utils","e","__esModule","default","WebGPUViewNativeComponent","props","contextId","style","transparent","rest","React","createElement","id","contextIdToId","styles","view","flex1","backgroundColor","StyleSheet","create","flex","alignItems","border","boxSizing","display","flexBasis","flexDirection","flexShrink","listStyle","margin","minHeight","minWidth","padding","position","zIndex"],"sourceRoot":"../../src","sources":["WebGPUViewNativeComponent.web.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAIA,IAAAE,MAAA,GAAAF,OAAA;AAAwC,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAOxC;AACe,SAASG,yBAAyBA,CAC/CC,KAAkB,EACC;EACnB,MAAM;IAAEC,SAAS;IAAEC,KAAK;IAAEC,WAAW;IAAE,GAAGC;EAAK,CAAC,GAAGJ,KAAK;;EAExD;EACA;EACA;EACA,oBAAOK,cAAK,CAACC,aAAa,CAAC,QAAQ,EAAE;IACnC,GAAGF,IAAI;IACPG,EAAE,EAAE,IAAAC,oBAAa,EAACP,SAAS,CAAC;IAC5BC,KAAK,EAAE;MACL,GAAGO,MAAM,CAACC,IAAI;MACd,GAAGD,MAAM,CAACE,KAAK;MACf,IAAIR,WAAW,KAAK,KAAK,GAAG;QAAES,eAAe,EAAE;MAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;MAC9D,IAAI,OAAOV,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAG,CAAC,CAAC;IAC5C;EACF,CAAC,CAAC;AACJ;AAEA,MAAMO,MAAM,GAAGI,uBAAU,CAACC,MAAM,CAAC;EAC/BH,KAAK,EAAE;IACLI,IAAI,EAAE;EACR,CAAC;EACDL,IAAI,EAAE;IACJM,UAAU,EAAE,SAAS;IACrBJ,eAAe,EAAE,aAAa;IAC9B;IACA;IACAK,MAAM,EAAE,eAAe;IACvBC,SAAS,EAAE,YAAY;IACvBC,OAAO,EAAE,MAAM;IACfC,SAAS,EAAE,MAAM;IACjBC,aAAa,EAAE,QAAQ;IACvBC,UAAU,EAAE,CAAC;IACbC,SAAS,EAAE,MAAM;IACjBC,MAAM,EAAE,CAAC;IACTC,SAAS,EAAE,CAAC;IACZC,QAAQ,EAAE,CAAC;IACXC,OAAO,EAAE,CAAC;IACVC,QAAQ,EAAE,UAAU;IACpBC,MAAM,EAAE;EACV;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,39 +1,6 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { StyleSheet } from "react-native";
|
|
3
3
|
import { contextIdToId } from "./utils";
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
function debounce(func, wait, immediate = false) {
|
|
6
|
-
let timeout;
|
|
7
|
-
return function debounced(...args) {
|
|
8
|
-
const context = this;
|
|
9
|
-
const callNow = immediate && !timeout;
|
|
10
|
-
if (timeout) {
|
|
11
|
-
clearTimeout(timeout);
|
|
12
|
-
}
|
|
13
|
-
timeout = setTimeout(() => {
|
|
14
|
-
timeout = undefined;
|
|
15
|
-
if (!immediate) {
|
|
16
|
-
func.apply(context, args);
|
|
17
|
-
}
|
|
18
|
-
}, wait);
|
|
19
|
-
if (callNow) {
|
|
20
|
-
func.apply(context, args);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function resizeCanvas(canvas) {
|
|
25
|
-
if (!canvas) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const dpr = window.devicePixelRatio || 1;
|
|
29
|
-
const {
|
|
30
|
-
height,
|
|
31
|
-
width
|
|
32
|
-
} = canvas.getBoundingClientRect();
|
|
33
|
-
canvas.setAttribute("height", (height * dpr).toString());
|
|
34
|
-
canvas.setAttribute("width", (width * dpr).toString());
|
|
35
|
-
}
|
|
36
|
-
|
|
37
4
|
// eslint-disable-next-line import/no-default-export
|
|
38
5
|
export default function WebGPUViewNativeComponent(props) {
|
|
39
6
|
const {
|
|
@@ -42,14 +9,10 @@ export default function WebGPUViewNativeComponent(props) {
|
|
|
42
9
|
transparent,
|
|
43
10
|
...rest
|
|
44
11
|
} = props;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return () => {
|
|
50
|
-
window.removeEventListener("resize", onResize);
|
|
51
|
-
};
|
|
52
|
-
}, []);
|
|
12
|
+
|
|
13
|
+
// MakeWebGPUCanvasContext sets the initial drawing-buffer size. Subsequent
|
|
14
|
+
// resizes belong to the renderer so it can recreate depth/MSAA attachments
|
|
15
|
+
// together; changing canvas.width/height here would invalidate its textures.
|
|
53
16
|
return /*#__PURE__*/React.createElement("canvas", {
|
|
54
17
|
...rest,
|
|
55
18
|
id: contextIdToId(contextId),
|
|
@@ -60,12 +23,6 @@ export default function WebGPUViewNativeComponent(props) {
|
|
|
60
23
|
backgroundColor: "white"
|
|
61
24
|
} : {}),
|
|
62
25
|
...(typeof style === "object" ? style : {})
|
|
63
|
-
},
|
|
64
|
-
ref: ref => {
|
|
65
|
-
canvasElm.current = ref;
|
|
66
|
-
if (ref) {
|
|
67
|
-
resizeCanvas(ref);
|
|
68
|
-
}
|
|
69
26
|
}
|
|
70
27
|
});
|
|
71
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","
|
|
1
|
+
{"version":3,"names":["React","StyleSheet","contextIdToId","WebGPUViewNativeComponent","props","contextId","style","transparent","rest","createElement","id","styles","view","flex1","backgroundColor","create","flex","alignItems","border","boxSizing","display","flexBasis","flexDirection","flexShrink","listStyle","margin","minHeight","minWidth","padding","position","zIndex"],"sourceRoot":"../../src","sources":["WebGPUViewNativeComponent.web.ts"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,UAAU,QAAQ,cAAc;AAIzC,SAASC,aAAa,QAAQ,SAAS;AAOvC;AACA,eAAe,SAASC,yBAAyBA,CAC/CC,KAAkB,EACC;EACnB,MAAM;IAAEC,SAAS;IAAEC,KAAK;IAAEC,WAAW;IAAE,GAAGC;EAAK,CAAC,GAAGJ,KAAK;;EAExD;EACA;EACA;EACA,oBAAOJ,KAAK,CAACS,aAAa,CAAC,QAAQ,EAAE;IACnC,GAAGD,IAAI;IACPE,EAAE,EAAER,aAAa,CAACG,SAAS,CAAC;IAC5BC,KAAK,EAAE;MACL,GAAGK,MAAM,CAACC,IAAI;MACd,GAAGD,MAAM,CAACE,KAAK;MACf,IAAIN,WAAW,KAAK,KAAK,GAAG;QAAEO,eAAe,EAAE;MAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;MAC9D,IAAI,OAAOR,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAG,CAAC,CAAC;IAC5C;EACF,CAAC,CAAC;AACJ;AAEA,MAAMK,MAAM,GAAGV,UAAU,CAACc,MAAM,CAAC;EAC/BF,KAAK,EAAE;IACLG,IAAI,EAAE;EACR,CAAC;EACDJ,IAAI,EAAE;IACJK,UAAU,EAAE,SAAS;IACrBH,eAAe,EAAE,aAAa;IAC9B;IACA;IACAI,MAAM,EAAE,eAAe;IACvBC,SAAS,EAAE,YAAY;IACvBC,OAAO,EAAE,MAAM;IACfC,SAAS,EAAE,MAAM;IACjBC,aAAa,EAAE,QAAQ;IACvBC,UAAU,EAAE,CAAC;IACbC,SAAS,EAAE,MAAM;IACjBC,MAAM,EAAE,CAAC;IACTC,SAAS,EAAE,CAAC;IACZC,QAAQ,EAAE,CAAC;IACXC,OAAO,EAAE,CAAC;IACVC,QAAQ,EAAE,UAAU;IACpBC,MAAM,EAAE;EACV;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../commonjs/WebGPUViewNativeComponent.web.js"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../commonjs/WebGPUViewNativeComponent.web.js"],"names":[],"mappings":";;AAWA,4DAuBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../module/WebGPUViewNativeComponent.web.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../module/WebGPUViewNativeComponent.web.js"],"names":[],"mappings":"AAIA,gHAuBC;kBA3BiB,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.web.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAI9C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,KAAK,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB;AAGD,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,KAAK,EAAE,WAAW,GACjB,KAAK,CAAC,GAAG,CAAC,OAAO,CAgBnB"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { StyleSheet } from "react-native";
|
|
3
3
|
import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
|
|
4
4
|
import type { ViewProps } from "react-native";
|
|
@@ -10,65 +10,15 @@ export interface NativeProps extends ViewProps {
|
|
|
10
10
|
transparent: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
function debounce<T extends (...args: any[]) => void>(
|
|
15
|
-
func: T,
|
|
16
|
-
wait: number,
|
|
17
|
-
immediate = false,
|
|
18
|
-
) {
|
|
19
|
-
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
20
|
-
return function debounced(
|
|
21
|
-
this: ThisParameterType<T>,
|
|
22
|
-
...args: Parameters<T>
|
|
23
|
-
) {
|
|
24
|
-
const context = this;
|
|
25
|
-
const callNow = immediate && !timeout;
|
|
26
|
-
if (timeout) {
|
|
27
|
-
clearTimeout(timeout);
|
|
28
|
-
}
|
|
29
|
-
timeout = setTimeout(() => {
|
|
30
|
-
timeout = undefined;
|
|
31
|
-
if (!immediate) {
|
|
32
|
-
func.apply(context, args);
|
|
33
|
-
}
|
|
34
|
-
}, wait);
|
|
35
|
-
if (callNow) {
|
|
36
|
-
func.apply(context, args);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function resizeCanvas(canvas: HTMLCanvasElement | null) {
|
|
42
|
-
if (!canvas) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const dpr = window.devicePixelRatio || 1;
|
|
47
|
-
|
|
48
|
-
const { height, width } = canvas.getBoundingClientRect();
|
|
49
|
-
canvas.setAttribute("height", (height * dpr).toString());
|
|
50
|
-
canvas.setAttribute("width", (width * dpr).toString());
|
|
51
|
-
}
|
|
52
|
-
|
|
53
13
|
// eslint-disable-next-line import/no-default-export
|
|
54
14
|
export default function WebGPUViewNativeComponent(
|
|
55
15
|
props: NativeProps,
|
|
56
16
|
): React.JSX.Element {
|
|
57
17
|
const { contextId, style, transparent, ...rest } = props;
|
|
58
18
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const onResize = debounce(
|
|
63
|
-
() => resizeCanvas(canvasElm.current ?? null),
|
|
64
|
-
100,
|
|
65
|
-
);
|
|
66
|
-
window.addEventListener("resize", onResize);
|
|
67
|
-
return () => {
|
|
68
|
-
window.removeEventListener("resize", onResize);
|
|
69
|
-
};
|
|
70
|
-
}, []);
|
|
71
|
-
|
|
19
|
+
// MakeWebGPUCanvasContext sets the initial drawing-buffer size. Subsequent
|
|
20
|
+
// resizes belong to the renderer so it can recreate depth/MSAA attachments
|
|
21
|
+
// together; changing canvas.width/height here would invalidate its textures.
|
|
72
22
|
return React.createElement("canvas", {
|
|
73
23
|
...rest,
|
|
74
24
|
id: contextIdToId(contextId),
|
|
@@ -78,12 +28,6 @@ export default function WebGPUViewNativeComponent(
|
|
|
78
28
|
...(transparent === false ? { backgroundColor: "white" } : {}),
|
|
79
29
|
...(typeof style === "object" ? style : {}),
|
|
80
30
|
},
|
|
81
|
-
ref: (ref: HTMLCanvasElement) => {
|
|
82
|
-
canvasElm.current = ref;
|
|
83
|
-
if (ref) {
|
|
84
|
-
resizeCanvas(ref);
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
31
|
});
|
|
88
32
|
}
|
|
89
33
|
|