@octane-xplat/canvas 0.18.0 → 0.20.0
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 +2 -97
- package/package.json +85 -79
- package/src/Canvas.macos.tsrx +20 -12
- package/src/Canvas.tsrx +22 -28
- package/src/Canvas.web.tsrx +39 -33
- package/src/gpu.macos.ts +3 -2
- package/src/gpu.ts +3 -2
- package/src/gpu.web.ts +3 -2
- package/src/props.ts +36 -24
- package/types/generated/.tsrx-typegen-manifest.json +9 -0
- package/types/generated/Canvas.d.ts +5 -0
- package/types/generated/gpu.d.ts +5 -0
- package/types/generated/index.d.ts +3 -0
- package/types/{props.d.ts → generated/props.d.ts} +13 -2
- package/LICENSE +0 -21
- package/types/index.d.ts +0 -14
package/README.md
CHANGED
|
@@ -1,100 +1,5 @@
|
|
|
1
1
|
# `@octane-xplat/canvas`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
pnpm add @octane-xplat/canvas
|
|
5
|
-
```
|
|
3
|
+
[Documentation](https://octane-xplat.goddardai.org/package-canvas).
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
`@nativescript/canvas` on iOS/Android — 2D, WebGL/WebGL2, and
|
|
9
|
-
WebGPU/WGSL context kinds behind one `getContext` contract.
|
|
10
|
-
|
|
11
|
-
```tsx
|
|
12
|
-
import { Canvas } from '@octane-xplat/canvas'
|
|
13
|
-
|
|
14
|
-
export function Drawing() {
|
|
15
|
-
return (
|
|
16
|
-
<Canvas
|
|
17
|
-
context="2d"
|
|
18
|
-
width={640}
|
|
19
|
-
height={480}
|
|
20
|
-
onReady={({ context }) => {
|
|
21
|
-
if (!context) return
|
|
22
|
-
context.fillStyle = '#2563eb'
|
|
23
|
-
context.fillRect(0, 0, 80, 80)
|
|
24
|
-
}}
|
|
25
|
-
/>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Pass `context` to have the leaf resolve it before `onReady`, or omit it and
|
|
31
|
-
call `getContext` yourself — one kind per canvas, decided on first call.
|
|
32
|
-
`onReady` fires after mount on web and on the plugin's `ready` event on
|
|
33
|
-
iOS/Android (earlier `getContext` calls can return null). For WebGPU,
|
|
34
|
-
`getGPU()` normalizes adapter/device acquisition across targets.
|
|
35
|
-
|
|
36
|
-
```tsx
|
|
37
|
-
import { Canvas, getGPU } from '@octane-xplat/canvas'
|
|
38
|
-
|
|
39
|
-
export function DeferredCanvas() {
|
|
40
|
-
return (
|
|
41
|
-
<Canvas
|
|
42
|
-
onReady={({ canvas }) => {
|
|
43
|
-
const context = canvas.getContext('2d')
|
|
44
|
-
if (context) context.fillRect(0, 0, 20, 20)
|
|
45
|
-
}}
|
|
46
|
-
/>
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
const gpu = getGPU()
|
|
50
|
-
const adapter = await gpu?.requestAdapter()
|
|
51
|
-
const device = await adapter?.requestDevice()
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Keep a fallback when drawing is unavailable
|
|
55
|
-
|
|
56
|
-
Native macOS/AppKit imports and mounts safely, but drawing is unsupported.
|
|
57
|
-
`onReady` reports `context: null` after a neutral frame mounts; it does not
|
|
58
|
-
announce a drawing surface. Its unavailable `canvas` handle returns `null`
|
|
59
|
-
from `getContext()` for every kind, including `2d`, `webgl`, `webgl2`,
|
|
60
|
-
`webgpu`, and `bitmaprenderer`. `getGPU()` also returns `null`, so no adapter
|
|
61
|
-
or device can be acquired. Check these results before drawing and keep your
|
|
62
|
-
own static fallback. For example, put this component in your app:
|
|
63
|
-
|
|
64
|
-
```tsx
|
|
65
|
-
import { Canvas, getGPU } from '@octane-xplat/canvas'
|
|
66
|
-
import { Text, View } from '@octane-xplat/ui'
|
|
67
|
-
import { useState } from 'octane'
|
|
68
|
-
|
|
69
|
-
export function DrawingWithFallback() {
|
|
70
|
-
const [drawn, setDrawn] = useState(false)
|
|
71
|
-
return (
|
|
72
|
-
<View>
|
|
73
|
-
{!drawn && <Text>Blue square illustration</Text>}
|
|
74
|
-
<Canvas
|
|
75
|
-
context="2d"
|
|
76
|
-
width={80}
|
|
77
|
-
height={80}
|
|
78
|
-
onReady={({ canvas, context }) => {
|
|
79
|
-
const drawing = context ?? canvas.getContext('2d')
|
|
80
|
-
if (!drawing) return
|
|
81
|
-
drawing.fillStyle = '#2563eb'
|
|
82
|
-
drawing.fillRect(0, 0, 80, 80)
|
|
83
|
-
setDrawn(true)
|
|
84
|
-
}}
|
|
85
|
-
/>
|
|
86
|
-
</View>
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// AppKit returns null here, before adapter/device acquisition.
|
|
91
|
-
const gpu = getGPU()
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
The AppKit backend for 2D, WebGL, and WebGPU remains deferred until a concrete
|
|
95
|
-
consumer needs one and the implementation is approved. Native desktop shader
|
|
96
|
-
effects remain unsupported. A DOM webview uses the separate web implementation.
|
|
97
|
-
|
|
98
|
-
Per-target limits are recorded in
|
|
99
|
-
[known limits](../../docs/testing/known-limits.md). Exercised by
|
|
100
|
-
[`CanvasDemo`](../demos/src/CanvasDemo.tsrx) (including a WGSL path).
|
|
5
|
+
[API reference](https://octane-xplat.goddardai.org/api-canvas).
|
package/package.json
CHANGED
|
@@ -1,80 +1,86 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
2
|
+
"name": "@octane-xplat/canvas",
|
|
3
|
+
"version": "0.20.0",
|
|
4
|
+
"description": "Canvas/GPU surface for Octane xplat — web <canvas> + @nativescript/canvas (2D, WebGL/WebGL2, WebGPU/WGSL)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"canvas",
|
|
7
|
+
"cross-platform",
|
|
8
|
+
"gpu",
|
|
9
|
+
"graphics",
|
|
10
|
+
"nativescript",
|
|
11
|
+
"octane",
|
|
12
|
+
"webgl",
|
|
13
|
+
"webgl2",
|
|
14
|
+
"webgpu",
|
|
15
|
+
"wgsl",
|
|
16
|
+
"xplat"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/canvas",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/octane-xplat/octane-xplat",
|
|
23
|
+
"directory": "packages/canvas"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"types/generated",
|
|
27
|
+
"src",
|
|
28
|
+
"!src/**/*.test.*",
|
|
29
|
+
"!src/**/*.spec.*"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./types/generated/index.d.ts",
|
|
35
|
+
"web": "./src/index.web.ts",
|
|
36
|
+
"macos": "./src/index.macos.ts",
|
|
37
|
+
"native": "./src/index.ts",
|
|
38
|
+
"default": "./src/index.ts"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"typegen": "tsrx-typegen --target canvas",
|
|
46
|
+
"prepack": "bun run typegen && tsrx-typegen --pack-check",
|
|
47
|
+
"test:packed": "node tests/packed-consumer.mjs",
|
|
48
|
+
"test:macos-runtime": "node ../../tools/probe/cli.ts run tests/unsupported.macos.tsrx --target macos --deps @octane-xplat/canvas",
|
|
49
|
+
"pack:check": "tsrx-typegen --pack-check",
|
|
50
|
+
"typecheck": "tsc --runExternalCode --noEmit -p tsconfig.types.json"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@nativescript/canvas": "3.0.0-beta.6",
|
|
54
|
+
"@octane-xplat/jsx": "0.20.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@nativescript-community/octane": "0.2.5",
|
|
58
|
+
"@nativescript/core": "9.1.3",
|
|
59
|
+
"@octane-xplat/macos-appkit": "0.20.0",
|
|
60
|
+
"@octanejs/vite-plugin": "0.5.0",
|
|
61
|
+
"octane": "0.16.3",
|
|
62
|
+
"tsrx-typegen": "0.6.1",
|
|
63
|
+
"typescript": "7.1.0-beta",
|
|
64
|
+
"vite": "8.3.6",
|
|
65
|
+
"@tsrx/content-mapper": "0.1.2",
|
|
66
|
+
"@octane-xplat/cli": "0.20.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
70
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
71
|
+
"@octane-xplat/macos-appkit": "0.20.0",
|
|
72
|
+
"octane": ">=0.6.3 <1"
|
|
73
|
+
},
|
|
74
|
+
"peerDependenciesMeta": {
|
|
75
|
+
"@nativescript-community/octane": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"@nativescript/core": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"@octane-xplat/macos-appkit": {
|
|
82
|
+
"optional": true
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"types": "./types/generated/index.d.ts"
|
|
86
|
+
}
|
package/src/Canvas.macos.tsrx
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
/** @jsxImportSource @octane-xplat/
|
|
2
|
-
import { useEffect } from 'octane'
|
|
3
|
-
import type { CanvasContextKind, CanvasProps } from './props'
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
|
+
import { useEffect } from 'octane'
|
|
3
|
+
import type { CanvasContextKind, CanvasProps } from './props'
|
|
4
4
|
|
|
5
5
|
/** AppKit mounts a neutral frame. No drawing surface or GPU is created. */
|
|
6
|
-
export function Canvas(props: CanvasProps) @{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export function Canvas(props: CanvasProps): unknown @{
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
// Preserve deferred acquisition without pretending this is a native view.
|
|
9
|
+
const canvas = Object.freeze({
|
|
10
|
+
getContext: (_kind: CanvasContextKind, _options?: any): null => null,
|
|
11
|
+
})
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
props.onReady?.({ canvas, context: null })
|
|
14
|
+
}, [])
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
<masonview
|
|
17
|
+
id={props.id}
|
|
18
|
+
className={props.className}
|
|
19
|
+
style={
|
|
20
|
+
typeof props.style === 'string'
|
|
21
|
+
? props.style
|
|
22
|
+
: { display: 'grid', width: props.width, height: props.height, ...props.style }
|
|
23
|
+
}
|
|
24
|
+
/>
|
|
17
25
|
}
|
package/src/Canvas.tsrx
CHANGED
|
@@ -1,39 +1,33 @@
|
|
|
1
|
-
/** @jsxImportSource @
|
|
2
|
-
import { registerElement } from '@nativescript-community/octane'
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import type { CanvasProps } from './props';
|
|
6
|
-
|
|
7
|
-
declare module '@nativescript-community/octane/intrinsics' {
|
|
8
|
-
interface NativeScriptElements {
|
|
9
|
-
nscanvas: Attributes<typeof NSCanvas>;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
|
+
import { registerElement } from '@nativescript-community/octane'
|
|
3
|
+
import { Canvas as NSCanvas } from '@nativescript/canvas'
|
|
4
|
+
import type { CanvasProps } from './props'
|
|
12
5
|
|
|
13
6
|
// @nativescript/canvas — Skia + wgpu core exposing the DOM Canvas API
|
|
14
7
|
// (2d, webgl, webgl2, webgpu) on iOS + Android. Element name is `nscanvas`
|
|
15
8
|
// rather than `canvas` because `canvas` is DOM vocabulary in the
|
|
16
9
|
// element-vocabulary lint.
|
|
17
|
-
registerElement('nscanvas', NSCanvas)
|
|
10
|
+
registerElement('nscanvas', NSCanvas)
|
|
18
11
|
|
|
19
12
|
/** Canvas — DOM Canvas API surface on native. `onReady` wraps the plugin's
|
|
20
13
|
* `ready` event: it fires once the GPU surface exists, which is the
|
|
21
14
|
* earliest `getContext` may be called. */
|
|
22
|
-
export function Canvas(props: CanvasProps) @{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
export function Canvas(props: CanvasProps): unknown @{
|
|
16
|
+
const ready = (event: any) => {
|
|
17
|
+
const canvas = event.object
|
|
18
|
+
|
|
19
|
+
props.onReady?.({
|
|
20
|
+
canvas,
|
|
21
|
+
context: props.context ? canvas.getContext(props.context) : null,
|
|
22
|
+
})
|
|
23
|
+
}
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
<nscanvas
|
|
26
|
+
id={props.id}
|
|
27
|
+
className={props.className}
|
|
28
|
+
style={props.style}
|
|
29
|
+
width={props.width as any}
|
|
30
|
+
height={props.height as any}
|
|
31
|
+
onReady={ready}
|
|
32
|
+
/>
|
|
39
33
|
}
|
package/src/Canvas.web.tsrx
CHANGED
|
@@ -1,39 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx/dom */
|
|
2
|
+
import type { JSX } from 'octane/jsx-runtime'
|
|
3
|
+
import { useMemo, useRef } from 'octane'
|
|
4
|
+
import type { CanvasProps } from './props'
|
|
3
5
|
|
|
4
6
|
/** Canvas — a plain <canvas>. `onReady` fires at mount with the element
|
|
5
7
|
* and the resolved context. */
|
|
6
|
-
export function Canvas(props: CanvasProps) @{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
propsRef.current = props;
|
|
11
|
-
const canvasRef = useMemo(
|
|
12
|
-
() => (el: HTMLCanvasElement | null) => {
|
|
13
|
-
if (!el) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
8
|
+
export function Canvas(props: CanvasProps): JSX.Element @{
|
|
9
|
+
// Keep the element callback referentially stable — a fresh closure each
|
|
10
|
+
// render makes the web renderer detach/reattach it, refiring onReady.
|
|
11
|
+
const propsRef = useRef(props)
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
canvas: el,
|
|
19
|
-
context: propsRef.current.context
|
|
20
|
-
? el.getContext(propsRef.current.context)
|
|
21
|
-
: null,
|
|
22
|
-
});
|
|
23
|
-
},
|
|
24
|
-
[],
|
|
25
|
-
);
|
|
13
|
+
propsRef.current = props
|
|
26
14
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
const canvasRef = useMemo(
|
|
16
|
+
() => (el: HTMLCanvasElement | null) => {
|
|
17
|
+
if (!el) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
propsRef.current.onReady?.({
|
|
22
|
+
canvas: el,
|
|
23
|
+
context: propsRef.current.context ? el.getContext(propsRef.current.context) : null,
|
|
24
|
+
})
|
|
25
|
+
},
|
|
26
|
+
[],
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
<canvas
|
|
30
|
+
id={props.id}
|
|
31
|
+
className={props.className}
|
|
32
|
+
style={
|
|
33
|
+
typeof props.style === 'string'
|
|
34
|
+
? props.style
|
|
35
|
+
: {
|
|
36
|
+
width: typeof props.width === 'string' ? props.width : undefined,
|
|
37
|
+
height: typeof props.height === 'string' ? props.height : undefined,
|
|
38
|
+
...props.style,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
width={typeof props.width === 'number' ? props.width : undefined}
|
|
42
|
+
height={typeof props.height === 'number' ? props.height : undefined}
|
|
43
|
+
ref={canvasRef}
|
|
44
|
+
/>
|
|
39
45
|
}
|
package/src/gpu.macos.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/** AppKit has no Canvas WebGPU backend. Returns null before device acquisition.
|
|
1
|
+
/** AppKit has no Canvas WebGPU backend. Returns null before device acquisition.
|
|
2
|
+
* Typed `any` to match the other platforms' getGPU signature. */
|
|
2
3
|
export function getGPU(): any {
|
|
3
|
-
|
|
4
|
+
return null
|
|
4
5
|
}
|
package/src/gpu.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { GPU } from '@nativescript/canvas'
|
|
|
2
2
|
|
|
3
3
|
/** getGPU — returns the plugin's GPU shim (wgpu over Metal/Vulkan). Same
|
|
4
4
|
* spec-shaped surface as web's `navigator.gpu`: `requestAdapter()` +
|
|
5
|
-
* `getPreferredCanvasFormat()`.
|
|
5
|
+
* `getPreferredCanvasFormat()`. Typed `any` deliberately — the shim and the
|
|
6
|
+
* real navigator.gpu differ structurally beyond that shared surface. */
|
|
6
7
|
export function getGPU(): any {
|
|
7
|
-
|
|
8
|
+
return new GPU()
|
|
8
9
|
}
|
package/src/gpu.web.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/** getGPU — returns the WebGPU entry point (`navigator.gpu`) or null when
|
|
2
2
|
* WebGPU is unavailable (insecure context, unsupported browser). The
|
|
3
3
|
* returned object is spec-shaped: `requestAdapter()` +
|
|
4
|
-
* `getPreferredCanvasFormat()`.
|
|
4
|
+
* `getPreferredCanvasFormat()`. Typed `any` deliberately — the shim and the
|
|
5
|
+
* real navigator.gpu differ structurally beyond that shared surface. */
|
|
5
6
|
export function getGPU(): any {
|
|
6
|
-
|
|
7
|
+
return (globalThis.navigator as any)?.gpu ?? null
|
|
7
8
|
}
|
package/src/props.ts
CHANGED
|
@@ -1,31 +1,43 @@
|
|
|
1
|
+
import type { ClassValue, CSSProperties } from 'octane/jsx-runtime'
|
|
2
|
+
|
|
3
|
+
/** Canvas context kinds; availability is per platform — 'webgpu' resolves
|
|
4
|
+
* through the plugin shim on mobile and `navigator.gpu` on web,
|
|
5
|
+
* 'bitmaprenderer' is web-only, and AppKit resolves no kind at all. */
|
|
1
6
|
export type CanvasContextKind = '2d' | 'webgl' | 'webgl2' | 'webgpu' | 'bitmaprenderer'
|
|
2
7
|
|
|
8
|
+
/** Payload passed to onReady once the canvas element exists. */
|
|
3
9
|
export interface CanvasReady {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/** HTMLCanvasElement on web, the plugin's Canvas view on iOS/Android.
|
|
11
|
+
* AppKit supplies an unavailable handle whose `getContext()` always
|
|
12
|
+
* returns null; it is not a native drawing surface. */
|
|
13
|
+
canvas: any
|
|
14
|
+
/** The resolved context for the `context` prop, or null when that
|
|
15
|
+
* kind is unsupported/unavailable. WebGPU still needs a device —
|
|
16
|
+
* `getGPU()` normalizes adapter/device acquisition. */
|
|
17
|
+
context: any
|
|
12
18
|
}
|
|
13
19
|
|
|
20
|
+
/** Props for the `<Canvas>` element. */
|
|
14
21
|
export interface CanvasProps {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
/** clsx-style class list applied to the canvas element. */
|
|
23
|
+
className?: ClassValue
|
|
24
|
+
/** Inline style: CSS text or a camelCase style object. */
|
|
25
|
+
style?: string | CSSProperties
|
|
26
|
+
/** Element id passed through to the host element. */
|
|
27
|
+
id?: string
|
|
28
|
+
/** Context kind resolved before `onReady` fires. Omit to defer
|
|
29
|
+
* `getContext` to user code (only one kind per canvas — call once). */
|
|
30
|
+
context?: CanvasContextKind
|
|
31
|
+
/** Web: after mount. iOS/Android: the plugin's `ready` event (earlier
|
|
32
|
+
* `getContext` calls can return null). AppKit: after the neutral frame
|
|
33
|
+
* mounts, with context null. This callback does not guarantee drawing
|
|
34
|
+
* or GPU readiness; check context or call canvas.getContext first. */
|
|
35
|
+
onReady?: (ready: CanvasReady) => void
|
|
36
|
+
/** Numeric values map to the element's width/height — on web that is
|
|
37
|
+
* the canvas *drawing buffer* size (pair with style for display
|
|
38
|
+
* size), on native dip size. */
|
|
39
|
+
width?: string | number
|
|
40
|
+
/** Same contract as `width`: numbers set the drawing-buffer height on web
|
|
41
|
+
* and dip height on native. */
|
|
42
|
+
height?: string | number
|
|
31
43
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CanvasProps } from './props.js';
|
|
2
|
+
/** Canvas — DOM Canvas API surface on native. `onReady` wraps the plugin's
|
|
3
|
+
* `ready` event: it fires once the GPU surface exists, which is the
|
|
4
|
+
* earliest `getContext` may be called. */
|
|
5
|
+
export declare function Canvas(props: CanvasProps): unknown;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** getGPU — returns the plugin's GPU shim (wgpu over Metal/Vulkan). Same
|
|
2
|
+
* spec-shaped surface as web's `navigator.gpu`: `requestAdapter()` +
|
|
3
|
+
* `getPreferredCanvasFormat()`. Typed `any` deliberately — the shim and the
|
|
4
|
+
* real navigator.gpu differ structurally beyond that shared surface. */
|
|
5
|
+
export declare function getGPU(): any;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { ClassValue, CSSProperties } from 'octane/jsx-runtime';
|
|
2
|
+
/** Canvas context kinds; availability is per platform — 'webgpu' resolves
|
|
3
|
+
* through the plugin shim on mobile and `navigator.gpu` on web,
|
|
4
|
+
* 'bitmaprenderer' is web-only, and AppKit resolves no kind at all. */
|
|
1
5
|
export type CanvasContextKind = '2d' | 'webgl' | 'webgl2' | 'webgpu' | 'bitmaprenderer';
|
|
6
|
+
/** Payload passed to onReady once the canvas element exists. */
|
|
2
7
|
export interface CanvasReady {
|
|
3
8
|
/** HTMLCanvasElement on web, the plugin's Canvas view on iOS/Android.
|
|
4
9
|
* AppKit supplies an unavailable handle whose `getContext()` always
|
|
@@ -9,9 +14,13 @@ export interface CanvasReady {
|
|
|
9
14
|
* `getGPU()` normalizes adapter/device acquisition. */
|
|
10
15
|
context: any;
|
|
11
16
|
}
|
|
17
|
+
/** Props for the `<Canvas>` element. */
|
|
12
18
|
export interface CanvasProps {
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
/** clsx-style class list applied to the canvas element. */
|
|
20
|
+
className?: ClassValue;
|
|
21
|
+
/** Inline style: CSS text or a camelCase style object. */
|
|
22
|
+
style?: string | CSSProperties;
|
|
23
|
+
/** Element id passed through to the host element. */
|
|
15
24
|
id?: string;
|
|
16
25
|
/** Context kind resolved before `onReady` fires. Omit to defer
|
|
17
26
|
* `getContext` to user code (only one kind per canvas — call once). */
|
|
@@ -25,5 +34,7 @@ export interface CanvasProps {
|
|
|
25
34
|
* the canvas *drawing buffer* size (pair with style for display
|
|
26
35
|
* size), on native dip size. */
|
|
27
36
|
width?: string | number;
|
|
37
|
+
/** Same contract as `width`: numbers set the drawing-buffer height on web
|
|
38
|
+
* and dip height on native. */
|
|
28
39
|
height?: string | number;
|
|
29
40
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Alec Larson
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
package/types/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// Boundary types for @octane-xplat/canvas — the mechanical wrapper over
|
|
2
|
-
// props.ts (tsrx-tsc can't emit .tsrx declarations; see ui/types/index.d.ts
|
|
3
|
-
// for the same pattern).
|
|
4
|
-
import type { UniversalComponent } from 'octane/universal'
|
|
5
|
-
import type { CanvasProps } from './props.js'
|
|
6
|
-
|
|
7
|
-
export declare const Canvas: UniversalComponent<CanvasProps>
|
|
8
|
-
|
|
9
|
-
/** Returns the WebGPU entry point — `navigator.gpu` on web, the plugin's
|
|
10
|
-
* GPU shim on iOS/Android — or null where WebGPU is unavailable.
|
|
11
|
-
* Native AppKit always returns null. */
|
|
12
|
-
export declare function getGPU(): any
|
|
13
|
-
|
|
14
|
-
export type { CanvasProps, CanvasContextKind, CanvasReady } from './props.js'
|