react-native-wgpu 0.3.2 → 0.4.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.
- package/README.md +7 -5
- package/lib/commonjs/Canvas.js +14 -6
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/WebGPUViewNativeComponent.web.js +99 -0
- package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -0
- package/lib/commonjs/WebPolyfillGPUModule.js +40 -0
- package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -0
- package/lib/commonjs/hooks.js +3 -2
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/index.js +4 -208
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/main/index.js +227 -0
- package/lib/commonjs/main/index.js.map +1 -0
- package/lib/commonjs/main/index.web.js +51 -0
- package/lib/commonjs/main/index.web.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils.js +11 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/Canvas.js +12 -5
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/WebGPUViewNativeComponent.web.js +93 -0
- package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -0
- package/lib/module/WebPolyfillGPUModule.js +38 -0
- package/lib/module/WebPolyfillGPUModule.js.map +1 -0
- package/lib/module/hooks.js +1 -1
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js +3 -160
- package/lib/module/index.js.map +1 -1
- package/lib/module/main/index.js +168 -0
- package/lib/module/main/index.js.map +1 -0
- package/lib/module/main/index.web.js +8 -0
- package/lib/module/main/index.web.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils.js +5 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/lib/commonjs/Canvas.d.ts +1 -2
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts +5 -0
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/hooks.d.ts +5 -6
- package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/index.d.ts +0 -1
- package/lib/typescript/lib/commonjs/main/index.d.ts +3 -0
- package/lib/typescript/lib/commonjs/main/index.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/main/index.web.d.ts +2 -0
- package/lib/typescript/lib/commonjs/main/index.web.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/types.d.ts +1 -0
- package/lib/typescript/lib/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/utils.d.ts +3 -0
- package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -0
- package/lib/typescript/lib/module/Canvas.d.ts +2 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts +2 -0
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/lib/module/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/lib/module/WebPolyfillGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/module/hooks.d.ts +4 -3
- package/lib/typescript/lib/module/hooks.d.ts.map +1 -1
- package/lib/typescript/lib/module/index.d.ts +1 -5
- package/lib/typescript/lib/module/main/index.d.ts +6 -0
- package/lib/typescript/lib/module/main/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/main/index.web.d.ts +5 -0
- package/lib/typescript/lib/module/main/index.web.d.ts.map +1 -0
- package/lib/typescript/lib/module/types.d.ts +1 -0
- package/lib/typescript/lib/module/types.d.ts.map +1 -0
- package/lib/typescript/lib/module/utils.d.ts +2 -0
- package/lib/typescript/lib/module/utils.d.ts.map +1 -0
- package/lib/typescript/src/Canvas.d.ts +3 -2
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +118 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/src/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/src/WebPolyfillGPUModule.d.ts.map +1 -0
- package/lib/typescript/src/hooks.d.ts +5 -4
- package/lib/typescript/src/hooks.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +16 -5
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/main/index.d.ts +6 -0
- package/lib/typescript/src/main/index.d.ts.map +1 -0
- package/lib/typescript/src/main/index.web.d.ts +6 -0
- package/lib/typescript/src/main/index.web.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +19 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +2 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/Canvas.tsx +18 -5
- package/src/WebGPUViewNativeComponent.ts +1 -1
- package/src/WebGPUViewNativeComponent.web.ts +108 -0
- package/src/WebPolyfillGPUModule.ts +53 -0
- package/src/hooks.tsx +2 -2
- package/src/index.tsx +25 -196
- package/src/main/index.tsx +204 -0
- package/src/main/index.web.tsx +8 -0
- package/src/types.ts +20 -0
- package/src/utils.ts +4 -0
- package/lib/commonjs/WebGPUView.js +0 -2
- package/lib/commonjs/WebGPUView.js.map +0 -1
- package/lib/module/WebGPUView.js +0 -2
- package/lib/module/WebGPUView.js.map +0 -1
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts +0 -1
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts.map +0 -1
- package/lib/typescript/lib/module/WebGPUView.d.ts +0 -1
- package/lib/typescript/lib/module/WebGPUView.d.ts.map +0 -1
- package/lib/typescript/src/WebGPUView.d.ts +0 -1
- package/lib/typescript/src/WebGPUView.d.ts.map +0 -1
- package/src/WebGPUView.tsx +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebGPUViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,
|
|
1
|
+
{"version":3,"file":"WebGPUViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,KAAK,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB;;AAGD,wBAAiE"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
|
|
2
|
+
import type { ViewProps } from "react-native";
|
|
3
|
+
export interface NativeProps extends ViewProps {
|
|
4
|
+
contextId: Int32;
|
|
5
|
+
transparent: boolean;
|
|
6
|
+
}
|
|
7
|
+
export default function WebGPUViewNativeComponent(props: NativeProps): import("react").ReactElement<{
|
|
8
|
+
style: (import("react-native").StyleProp<import("react-native").ViewStyle> | {
|
|
9
|
+
flex: number;
|
|
10
|
+
} | {
|
|
11
|
+
alignItems: "stretch";
|
|
12
|
+
backgroundColor: string;
|
|
13
|
+
border: string;
|
|
14
|
+
boxSizing: "border-box";
|
|
15
|
+
display: "flex";
|
|
16
|
+
flexBasis: "auto";
|
|
17
|
+
flexDirection: "column";
|
|
18
|
+
flexShrink: number;
|
|
19
|
+
listStyle: string;
|
|
20
|
+
margin: number;
|
|
21
|
+
minHeight: number;
|
|
22
|
+
minWidth: number;
|
|
23
|
+
padding: number;
|
|
24
|
+
position: "relative";
|
|
25
|
+
zIndex: number;
|
|
26
|
+
})[];
|
|
27
|
+
id: string;
|
|
28
|
+
ref: (ref: HTMLCanvasElement) => void;
|
|
29
|
+
children?: React.ReactNode | undefined;
|
|
30
|
+
hitSlop?: null | import("react-native").Insets | number | undefined;
|
|
31
|
+
needsOffscreenAlphaCompositing?: boolean | undefined;
|
|
32
|
+
onLayout?: ((event: import("react-native").LayoutChangeEvent) => void) | undefined;
|
|
33
|
+
pointerEvents?: "box-none" | "none" | "box-only" | "auto" | undefined;
|
|
34
|
+
removeClippedSubviews?: boolean | undefined;
|
|
35
|
+
testID?: string | undefined;
|
|
36
|
+
nativeID?: string | undefined;
|
|
37
|
+
collapsable?: boolean | undefined;
|
|
38
|
+
collapsableChildren?: boolean | undefined;
|
|
39
|
+
onBlur?: ((e: import("react-native").BlurEvent) => void) | null | undefined;
|
|
40
|
+
onFocus?: ((e: import("react-native").FocusEvent) => void) | null | undefined;
|
|
41
|
+
renderToHardwareTextureAndroid?: boolean | undefined;
|
|
42
|
+
focusable?: boolean | undefined;
|
|
43
|
+
tabIndex?: 0 | -1 | undefined;
|
|
44
|
+
shouldRasterizeIOS?: boolean | undefined;
|
|
45
|
+
isTVSelectable?: boolean | undefined;
|
|
46
|
+
hasTVPreferredFocus?: boolean | undefined;
|
|
47
|
+
tvParallaxShiftDistanceX?: number | undefined;
|
|
48
|
+
tvParallaxShiftDistanceY?: number | undefined;
|
|
49
|
+
tvParallaxTiltAngle?: number | undefined;
|
|
50
|
+
tvParallaxMagnification?: number | undefined;
|
|
51
|
+
onStartShouldSetResponder?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
52
|
+
onMoveShouldSetResponder?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
53
|
+
onResponderEnd?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
54
|
+
onResponderGrant?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
55
|
+
onResponderReject?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
56
|
+
onResponderMove?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
57
|
+
onResponderRelease?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
58
|
+
onResponderStart?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
59
|
+
onResponderTerminationRequest?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
60
|
+
onResponderTerminate?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
61
|
+
onStartShouldSetResponderCapture?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
62
|
+
onMoveShouldSetResponderCapture?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
63
|
+
onTouchStart?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
64
|
+
onTouchMove?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
65
|
+
onTouchEnd?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
66
|
+
onTouchCancel?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
67
|
+
onTouchEndCapture?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
68
|
+
onPointerEnter?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
69
|
+
onPointerEnterCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
70
|
+
onPointerLeave?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
71
|
+
onPointerLeaveCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
72
|
+
onPointerMove?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
73
|
+
onPointerMoveCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
74
|
+
onPointerCancel?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
75
|
+
onPointerCancelCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
76
|
+
onPointerDown?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
77
|
+
onPointerDownCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
78
|
+
onPointerUp?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
79
|
+
onPointerUpCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
80
|
+
accessible?: boolean | undefined;
|
|
81
|
+
accessibilityActions?: ReadonlyArray<import("react-native").AccessibilityActionInfo> | undefined;
|
|
82
|
+
accessibilityLabel?: string | undefined;
|
|
83
|
+
'aria-label'?: string | undefined;
|
|
84
|
+
accessibilityRole?: import("react-native").AccessibilityRole | undefined;
|
|
85
|
+
accessibilityState?: import("react-native").AccessibilityState | undefined;
|
|
86
|
+
'aria-busy'?: boolean | undefined;
|
|
87
|
+
'aria-checked'?: boolean | "mixed" | undefined;
|
|
88
|
+
'aria-disabled'?: boolean | undefined;
|
|
89
|
+
'aria-expanded'?: boolean | undefined;
|
|
90
|
+
'aria-selected'?: boolean | undefined;
|
|
91
|
+
accessibilityHint?: string | undefined;
|
|
92
|
+
accessibilityValue?: import("react-native").AccessibilityValue | undefined;
|
|
93
|
+
'aria-valuemax'?: import("react-native").AccessibilityValue["max"] | undefined;
|
|
94
|
+
'aria-valuemin'?: import("react-native").AccessibilityValue["min"] | undefined;
|
|
95
|
+
'aria-valuenow'?: import("react-native").AccessibilityValue["now"] | undefined;
|
|
96
|
+
'aria-valuetext'?: import("react-native").AccessibilityValue["text"] | undefined;
|
|
97
|
+
onAccessibilityAction?: ((event: import("react-native").AccessibilityActionEvent) => void) | undefined;
|
|
98
|
+
importantForAccessibility?: ("auto" | "yes" | "no" | "no-hide-descendants") | undefined;
|
|
99
|
+
'aria-hidden'?: boolean | undefined;
|
|
100
|
+
'aria-modal'?: boolean | undefined;
|
|
101
|
+
role?: import("react-native").Role | undefined;
|
|
102
|
+
accessibilityLabelledBy?: string | string[] | undefined;
|
|
103
|
+
'aria-labelledby'?: string | undefined;
|
|
104
|
+
accessibilityLiveRegion?: "none" | "polite" | "assertive" | undefined;
|
|
105
|
+
'aria-live'?: ("polite" | "assertive" | "off") | undefined;
|
|
106
|
+
screenReaderFocusable?: boolean | undefined;
|
|
107
|
+
accessibilityElementsHidden?: boolean | undefined;
|
|
108
|
+
accessibilityViewIsModal?: boolean | undefined;
|
|
109
|
+
onAccessibilityEscape?: (() => void) | undefined;
|
|
110
|
+
onAccessibilityTap?: (() => void) | undefined;
|
|
111
|
+
onMagicTap?: (() => void) | undefined;
|
|
112
|
+
accessibilityIgnoresInvertColors?: boolean | undefined;
|
|
113
|
+
accessibilityLanguage?: string | undefined;
|
|
114
|
+
accessibilityShowsLargeContentViewer?: boolean | undefined;
|
|
115
|
+
accessibilityLargeContentTitle?: string | undefined;
|
|
116
|
+
accessibilityRespondsToUserInteraction?: boolean | undefined;
|
|
117
|
+
}, string | import("react").JSXElementConstructor<any>>;
|
|
118
|
+
//# sourceMappingURL=WebGPUViewNativeComponent.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.web.ts"],"names":[],"mappings":"AAGA,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;AA2CD,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,KAAK,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;eAsBrD,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wDAO/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebPolyfillGPUModule.d.ts","sourceRoot":"","sources":["../../../src/WebPolyfillGPUModule.ts"],"names":[],"mappings":""}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import type { ReactNode } from "react";
|
|
2
3
|
import type { CanvasRef, NativeCanvas } from "./Canvas";
|
|
3
4
|
export declare const warnIfNotHardwareAccelerated: (adapter: GPUAdapter) => void;
|
|
@@ -5,19 +6,19 @@ interface DeviceContext {
|
|
|
5
6
|
device: GPUDevice | null;
|
|
6
7
|
adapter: GPUAdapter | null;
|
|
7
8
|
}
|
|
8
|
-
declare const DeviceContext:
|
|
9
|
+
declare const DeviceContext: React.Context<DeviceContext | null>;
|
|
9
10
|
interface DeviceProviderProps {
|
|
10
11
|
children?: ReactNode | ReactNode[];
|
|
11
12
|
adapterOptions?: GPURequestAdapterOptions;
|
|
12
13
|
deviceDescriptor?: GPUDeviceDescriptor;
|
|
13
14
|
}
|
|
14
|
-
export declare const GPUDeviceProvider: ({ children, adapterOptions, deviceDescriptor, }: DeviceProviderProps) =>
|
|
15
|
+
export declare const GPUDeviceProvider: ({ children, adapterOptions, deviceDescriptor, }: DeviceProviderProps) => React.JSX.Element | null;
|
|
15
16
|
export declare const useSurface: () => {
|
|
16
|
-
ref:
|
|
17
|
+
ref: React.RefObject<CanvasRef>;
|
|
17
18
|
surface: NativeCanvas | null;
|
|
18
19
|
};
|
|
19
20
|
export declare const useMainDevice: () => DeviceContext;
|
|
20
|
-
export declare const useCanvasRef: () =>
|
|
21
|
+
export declare const useCanvasRef: () => React.RefObject<CanvasRef>;
|
|
21
22
|
export declare const useDevice: (adapterOptions?: GPURequestAdapterOptions, deviceDescriptor?: GPUDeviceDescriptor) => {
|
|
22
23
|
adapter: GPUAdapter | null;
|
|
23
24
|
device: GPUDevice | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,4BAA4B,GAAI,SAAS,UAAU,SAQ/D,CAAC;AAEF,UAAU,aAAa;IACrB,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;CAC5B;AAED,QAAA,MAAM,aAAa,qCAA4C,CAAC;AAEhE,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;IACnC,cAAc,CAAC,EAAE,wBAAwB,CAAC;IAC1C,gBAAgB,CAAC,EAAE,mBAAmB,CAAC;CACxC;AAED,eAAO,MAAM,iBAAiB,GAAI,iDAI/B,mBAAmB,6BAQrB,CAAC;AAEF,eAAO,MAAM,UAAU;;;CAQtB,CAAC;AAEF,eAAO,MAAM,aAAa,qBAMzB,CAAC;AAEF,eAAO,MAAM,YAAY,kCAAgC,CAAC;AAE1D,eAAO,MAAM,SAAS,GACpB,iBAAiB,wBAAwB,EACzC,mBAAmB,mBAAmB;;;CAqBvC,CAAC"}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
export * from "./
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { NativeCanvas, RNCanvasContext } from "./types";
|
|
2
|
+
export * from "./main";
|
|
3
|
+
declare global {
|
|
4
|
+
interface Navigator {
|
|
5
|
+
gpu: GPU;
|
|
6
|
+
}
|
|
7
|
+
var navigator: Navigator;
|
|
8
|
+
var RNWebGPU: {
|
|
9
|
+
gpu: GPU;
|
|
10
|
+
fabric: boolean;
|
|
11
|
+
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
12
|
+
MakeWebGPUCanvasContext: (contextId: number, width: number, height: number) => RNCanvasContext;
|
|
13
|
+
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
14
|
+
createImageBitmap: typeof createImageBitmap;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
6
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE7D,cAAc,QAAQ,CAAC;AAEvB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,SAAS;QACjB,GAAG,EAAE,GAAG,CAAC;KACV;IAED,IAAI,SAAS,EAAE,SAAS,CAAC;IAEzB,IAAI,QAAQ,EAAE;QACZ,GAAG,EAAE,GAAG,CAAC;QACT,MAAM,EAAE,OAAO,CAAC;QAChB,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,YAAY,CAAC;QACtD,uBAAuB,EAAE,CACvB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,KACX,eAAe,CAAC;QACrB,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,eAAe,GAAG,WAAW,KAAK,MAAM,CAAC;QACvE,iBAAiB,EAAE,OAAO,iBAAiB,CAAC;KAC7C,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/main/index.tsx"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC;AAEzB,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../src/main/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type SurfacePointer = bigint;
|
|
2
|
+
export interface NativeCanvas {
|
|
3
|
+
surface: SurfacePointer;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
clientWidth: number;
|
|
7
|
+
clientHeight: number;
|
|
8
|
+
}
|
|
9
|
+
export type RNCanvasContext = GPUCanvasContext & {
|
|
10
|
+
present: () => void;
|
|
11
|
+
};
|
|
12
|
+
export interface CanvasRef {
|
|
13
|
+
getContextId: () => number;
|
|
14
|
+
getContext(contextName: "webgpu"): RNCanvasContext | null;
|
|
15
|
+
getNativeSurface: () => NativeCanvas;
|
|
16
|
+
whenReady: (callback: () => void) => void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG;IAC/C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,UAAU,CAAC,WAAW,EAAE,QAAQ,GAAG,eAAe,GAAG,IAAI,CAAC;IAC1D,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;CAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AACA,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,UAE9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-wgpu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "React Native WebGPU",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"react": "19.1.0",
|
|
82
82
|
"react-native": "0.81.4",
|
|
83
83
|
"react-native-builder-bob": "^0.23.2",
|
|
84
|
+
"react-native-web": "^0.21.2",
|
|
84
85
|
"rimraf": "^5.0.7",
|
|
85
86
|
"seedrandom": "^3.0.5",
|
|
86
87
|
"teapot": "^1.0.0",
|
package/src/Canvas.tsx
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useImperativeHandle,
|
|
4
|
+
useRef,
|
|
5
|
+
useState,
|
|
6
|
+
} from "react";
|
|
1
7
|
import type { ViewProps } from "react-native";
|
|
2
|
-
import { View } from "react-native";
|
|
3
|
-
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
|
8
|
+
import { Platform, View } from "react-native";
|
|
4
9
|
|
|
5
10
|
import WebGPUNativeView from "./WebGPUViewNativeComponent";
|
|
6
11
|
|
|
@@ -62,9 +67,16 @@ export const Canvas = forwardRef<
|
|
|
62
67
|
if (!viewRef.current) {
|
|
63
68
|
throw new Error("[WebGPU] Cannot get context before mount");
|
|
64
69
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
let size;
|
|
71
|
+
if (Platform.OS === "web") {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
|
+
// @ts-expect-error
|
|
74
|
+
size = viewRef.current.getBoundingClientRect();
|
|
75
|
+
} else {
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
77
|
+
// @ts-expect-error
|
|
78
|
+
size = viewRef.current.unstable_getBoundingClientRect();
|
|
79
|
+
}
|
|
68
80
|
return RNWebGPU.MakeWebGPUCanvasContext(
|
|
69
81
|
contextId,
|
|
70
82
|
size.width,
|
|
@@ -72,6 +84,7 @@ export const Canvas = forwardRef<
|
|
|
72
84
|
);
|
|
73
85
|
},
|
|
74
86
|
}));
|
|
87
|
+
|
|
75
88
|
return (
|
|
76
89
|
<View collapsable={false} ref={viewRef} {...props}>
|
|
77
90
|
<WebGPUNativeView
|
|
@@ -2,7 +2,7 @@ import { codegenNativeComponent } from "react-native";
|
|
|
2
2
|
import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
|
|
3
3
|
import type { ViewProps } from "react-native";
|
|
4
4
|
|
|
5
|
-
interface NativeProps extends ViewProps {
|
|
5
|
+
export interface NativeProps extends ViewProps {
|
|
6
6
|
contextId: Int32;
|
|
7
7
|
transparent: boolean;
|
|
8
8
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { StyleSheet } from "react-native";
|
|
3
|
+
import { unstable_createElement as unstableCreateElement } from "react-native-web";
|
|
4
|
+
import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
|
|
5
|
+
import type { ViewProps } from "react-native";
|
|
6
|
+
|
|
7
|
+
import { contextIdToId } from "./utils";
|
|
8
|
+
|
|
9
|
+
export interface NativeProps extends ViewProps {
|
|
10
|
+
contextId: Int32;
|
|
11
|
+
transparent: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
function debounce<T extends (...args: any[]) => void>(
|
|
16
|
+
func: T,
|
|
17
|
+
wait: number,
|
|
18
|
+
immediate = false,
|
|
19
|
+
) {
|
|
20
|
+
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
21
|
+
return function debounced(
|
|
22
|
+
this: ThisParameterType<T>,
|
|
23
|
+
...args: Parameters<T>
|
|
24
|
+
) {
|
|
25
|
+
const context = this;
|
|
26
|
+
const callNow = immediate && !timeout;
|
|
27
|
+
if (timeout) {
|
|
28
|
+
clearTimeout(timeout);
|
|
29
|
+
}
|
|
30
|
+
timeout = setTimeout(() => {
|
|
31
|
+
timeout = undefined;
|
|
32
|
+
if (!immediate) {
|
|
33
|
+
func.apply(context, args);
|
|
34
|
+
}
|
|
35
|
+
}, wait);
|
|
36
|
+
if (callNow) {
|
|
37
|
+
func.apply(context, args);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function resizeCanvas(canvas?: HTMLCanvasElement) {
|
|
43
|
+
if (!canvas) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const dpr = window.devicePixelRatio || 1;
|
|
48
|
+
|
|
49
|
+
const { height, width } = canvas.getBoundingClientRect();
|
|
50
|
+
canvas.setAttribute("height", (height * dpr).toString());
|
|
51
|
+
canvas.setAttribute("width", (width * dpr).toString());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// eslint-disable-next-line import/no-default-export
|
|
55
|
+
export default function WebGPUViewNativeComponent(props: NativeProps) {
|
|
56
|
+
const { contextId, style, transparent, ...rest } = props;
|
|
57
|
+
|
|
58
|
+
const canvasElm = useRef<HTMLCanvasElement>();
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const onResize = debounce(() => resizeCanvas(canvasElm.current), 100);
|
|
62
|
+
window.addEventListener("resize", onResize);
|
|
63
|
+
return () => {
|
|
64
|
+
window.removeEventListener("resize", onResize);
|
|
65
|
+
};
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
return unstableCreateElement("canvas", {
|
|
69
|
+
...rest,
|
|
70
|
+
style: [
|
|
71
|
+
styles.view,
|
|
72
|
+
styles.flex1,
|
|
73
|
+
transparent === false && { backgroundColor: "white" }, // Canvas elements are transparent by default on the web
|
|
74
|
+
style,
|
|
75
|
+
],
|
|
76
|
+
id: contextIdToId(contextId),
|
|
77
|
+
ref: (ref: HTMLCanvasElement) => {
|
|
78
|
+
canvasElm.current = ref;
|
|
79
|
+
if (ref) {
|
|
80
|
+
resizeCanvas(ref);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const styles = StyleSheet.create({
|
|
87
|
+
flex1: {
|
|
88
|
+
flex: 1,
|
|
89
|
+
},
|
|
90
|
+
view: {
|
|
91
|
+
alignItems: "stretch",
|
|
92
|
+
backgroundColor: "transparent",
|
|
93
|
+
// @ts-expect-error - not a valid RN style, but it's valid for web
|
|
94
|
+
border: "0 solid black",
|
|
95
|
+
boxSizing: "border-box",
|
|
96
|
+
display: "flex",
|
|
97
|
+
flexBasis: "auto",
|
|
98
|
+
flexDirection: "column",
|
|
99
|
+
flexShrink: 0,
|
|
100
|
+
listStyle: "none",
|
|
101
|
+
margin: 0,
|
|
102
|
+
minHeight: 0,
|
|
103
|
+
minWidth: 0,
|
|
104
|
+
padding: 0,
|
|
105
|
+
position: "relative",
|
|
106
|
+
zIndex: 0,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { contextIdToId } from "./utils";
|
|
2
|
+
|
|
3
|
+
const fabric = true;
|
|
4
|
+
|
|
5
|
+
function getNativeSurface(contextId: number) {
|
|
6
|
+
const canvas = document.getElementById(
|
|
7
|
+
contextIdToId(contextId),
|
|
8
|
+
) as HTMLCanvasElement;
|
|
9
|
+
|
|
10
|
+
const { height, width } = canvas.getBoundingClientRect()!;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
surface: BigInt(contextId),
|
|
14
|
+
height,
|
|
15
|
+
width,
|
|
16
|
+
clientHeight: height,
|
|
17
|
+
clientWidth: width,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function makeWebGPUCanvasContext(
|
|
22
|
+
contextId: number,
|
|
23
|
+
width: number,
|
|
24
|
+
height: number,
|
|
25
|
+
) {
|
|
26
|
+
const canvas = document.getElementById(
|
|
27
|
+
contextIdToId(contextId),
|
|
28
|
+
) as HTMLCanvasElement;
|
|
29
|
+
|
|
30
|
+
const dpr = window.devicePixelRatio || 1;
|
|
31
|
+
const pixelWidth = (width * dpr).toString();
|
|
32
|
+
const pixelHeight = (height * dpr).toString();
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
canvas.getAttribute("width") !== pixelWidth ||
|
|
36
|
+
canvas.getAttribute("height") !== pixelHeight
|
|
37
|
+
) {
|
|
38
|
+
canvas.setAttribute("width", pixelWidth);
|
|
39
|
+
canvas.setAttribute("height", pixelHeight);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const context = canvas.getContext("webgpu")!;
|
|
43
|
+
return Object.assign(context, {
|
|
44
|
+
present: () => {},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// @ts-expect-error - polyfill for RNWebGPU native module
|
|
49
|
+
window.RNWebGPU = {
|
|
50
|
+
getNativeSurface,
|
|
51
|
+
MakeWebGPUCanvasContext: makeWebGPUCanvasContext,
|
|
52
|
+
fabric,
|
|
53
|
+
};
|
package/src/hooks.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import React, {
|
|
3
2
|
createContext,
|
|
4
3
|
useContext,
|
|
5
4
|
useEffect,
|
|
@@ -7,6 +6,7 @@ import {
|
|
|
7
6
|
useRef,
|
|
8
7
|
useState,
|
|
9
8
|
} from "react";
|
|
9
|
+
import type { ReactNode } from "react";
|
|
10
10
|
|
|
11
11
|
import type { CanvasRef, NativeCanvas } from "./Canvas";
|
|
12
12
|
|