@octane-xplat/canvas 0.19.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 CHANGED
@@ -1,100 +1,5 @@
1
1
  # `@octane-xplat/canvas`
2
2
 
3
- A GPU/canvas surface for Octane xplat apps: the DOM `<canvas>` on web and
4
- `@nativescript/canvas` on iOS/Android — 2D, WebGL/WebGL2, and
5
- WebGPU/WGSL context kinds behind one `getContext` contract.
3
+ [Documentation](https://octane-xplat.goddardai.org/package-canvas).
6
4
 
7
- ```sh
8
- bun add @octane-xplat/canvas
9
- ```
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](https://octane-xplat.goddardai.org/known-limits). Exercised by
100
- [`CanvasDemo`](https://github.com/octane-xplat/octane-xplat/blob/main/packages/demos/src/CanvasDemo.tsrx) (including a WGSL path).
5
+ [API reference](https://octane-xplat.goddardai.org/api-canvas).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octane-xplat/canvas",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "Canvas/GPU surface for Octane xplat — web <canvas> + @nativescript/canvas (2D, WebGL/WebGL2, WebGPU/WGSL)",
5
5
  "keywords": [
6
6
  "canvas",
@@ -45,29 +45,30 @@
45
45
  "typegen": "tsrx-typegen --target canvas",
46
46
  "prepack": "bun run typegen && tsrx-typegen --pack-check",
47
47
  "test:packed": "node tests/packed-consumer.mjs",
48
- "test:macos-runtime": "node ../../scripts/probe.ts run tests/unsupported.macos.tsrx --target macos --deps @octane-xplat/canvas",
48
+ "test:macos-runtime": "node ../../tools/probe/cli.ts run tests/unsupported.macos.tsrx --target macos --deps @octane-xplat/canvas",
49
49
  "pack:check": "tsrx-typegen --pack-check",
50
- "typecheck": "tsrx-tsc --noEmit -p tsconfig.types.json"
50
+ "typecheck": "tsc --runExternalCode --noEmit -p tsconfig.types.json"
51
51
  },
52
52
  "dependencies": {
53
53
  "@nativescript/canvas": "3.0.0-beta.6",
54
- "@octane-xplat/jsx": "0.19.0"
54
+ "@octane-xplat/jsx": "0.20.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@nativescript-community/octane": "0.2.5",
58
58
  "@nativescript/core": "9.1.3",
59
- "@octane-xplat/macos-renderer": "0.19.0",
59
+ "@octane-xplat/macos-appkit": "0.20.0",
60
60
  "@octanejs/vite-plugin": "0.5.0",
61
61
  "octane": "0.16.3",
62
- "tsrx-typegen": "0.5.0",
63
- "typescript": "5.9.3",
64
- "vite": "8.3.0",
65
- "@tsrx/typescript-plugin": "0.4.11"
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"
66
67
  },
67
68
  "peerDependencies": {
68
69
  "@nativescript-community/octane": ">=0.2.1 <1",
69
70
  "@nativescript/core": ">=9.1.0 <10",
70
- "@octane-xplat/macos-renderer": "0.19.0",
71
+ "@octane-xplat/macos-appkit": "0.20.0",
71
72
  "octane": ">=0.6.3 <1"
72
73
  },
73
74
  "peerDependenciesMeta": {
@@ -77,7 +78,7 @@
77
78
  "@nativescript/core": {
78
79
  "optional": true
79
80
  },
80
- "@octane-xplat/macos-renderer": {
81
+ "@octane-xplat/macos-appkit": {
81
82
  "optional": true
82
83
  }
83
84
  },
@@ -4,22 +4,22 @@ import type { CanvasContextKind, CanvasProps } from './props'
4
4
 
5
5
  /** AppKit mounts a neutral frame. No drawing surface or GPU is created. */
6
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
- })
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
- props.onReady?.({ canvas, context: null })
14
- }, [])
13
+ props.onReady?.({ canvas, context: null })
14
+ }, [])
15
15
 
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
- />
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
+ />
25
25
  }
package/src/Canvas.tsrx CHANGED
@@ -13,20 +13,21 @@ registerElement('nscanvas', NSCanvas)
13
13
  * `ready` event: it fires once the GPU surface exists, which is the
14
14
  * earliest `getContext` may be called. */
15
15
  export function Canvas(props: CanvasProps): unknown @{
16
- const ready = (event: any) => {
17
- const canvas = event.object
18
- props.onReady?.({
19
- canvas,
20
- context: props.context ? canvas.getContext(props.context) : null,
21
- })
22
- }
16
+ const ready = (event: any) => {
17
+ const canvas = event.object
23
18
 
24
- <nscanvas
25
- id={props.id}
26
- className={props.className}
27
- style={props.style}
28
- width={props.width as any}
29
- height={props.height as any}
30
- onReady={ready}
31
- />
19
+ props.onReady?.({
20
+ canvas,
21
+ context: props.context ? canvas.getContext(props.context) : null,
22
+ })
23
+ }
24
+
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
+ />
32
33
  }
@@ -6,38 +6,40 @@ import type { CanvasProps } from './props'
6
6
  /** Canvas — a plain <canvas>. `onReady` fires at mount with the element
7
7
  * and the resolved context. */
8
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)
12
- propsRef.current = props
13
- const canvasRef = useMemo(
14
- () => (el: HTMLCanvasElement | null) => {
15
- if (!el) {
16
- return
17
- }
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)
18
12
 
19
- propsRef.current.onReady?.({
20
- canvas: el,
21
- context: propsRef.current.context ? el.getContext(propsRef.current.context) : null,
22
- })
23
- },
24
- [],
25
- )
13
+ propsRef.current = props
26
14
 
27
- <canvas
28
- id={props.id}
29
- className={props.className}
30
- style={
31
- typeof props.style === 'string'
32
- ? props.style
33
- : {
34
- width: typeof props.width === 'string' ? props.width : undefined,
35
- height: typeof props.height === 'string' ? props.height : undefined,
36
- ...props.style,
37
- }
38
- }
39
- width={typeof props.width === 'number' ? props.width : undefined}
40
- height={typeof props.height === 'number' ? props.height : undefined}
41
- ref={canvasRef}
42
- />
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
+ />
43
45
  }
package/src/gpu.macos.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** AppKit has no Canvas WebGPU backend. Returns null before device acquisition.
2
2
  * Typed `any` to match the other platforms' getGPU signature. */
3
3
  export function getGPU(): any {
4
- return null
4
+ return null
5
5
  }
package/src/gpu.ts CHANGED
@@ -5,5 +5,5 @@ import { GPU } from '@nativescript/canvas'
5
5
  * `getPreferredCanvasFormat()`. Typed `any` deliberately — the shim and the
6
6
  * real navigator.gpu differ structurally beyond that shared surface. */
7
7
  export function getGPU(): any {
8
- return new GPU()
8
+ return new GPU()
9
9
  }
package/src/gpu.web.ts CHANGED
@@ -4,5 +4,5 @@
4
4
  * `getPreferredCanvasFormat()`. Typed `any` deliberately — the shim and the
5
5
  * real navigator.gpu differ structurally beyond that shared surface. */
6
6
  export function getGPU(): any {
7
- return (globalThis.navigator as any)?.gpu ?? null
7
+ return (globalThis.navigator as any)?.gpu ?? null
8
8
  }
package/src/props.ts CHANGED
@@ -7,37 +7,37 @@ export type CanvasContextKind = '2d' | 'webgl' | 'webgl2' | 'webgpu' | 'bitmapre
7
7
 
8
8
  /** Payload passed to onReady once the canvas element exists. */
9
9
  export interface CanvasReady {
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
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
18
18
  }
19
19
 
20
20
  /** Props for the `<Canvas>` element. */
21
21
  export interface CanvasProps {
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
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
43
43
  }
@@ -2,14 +2,8 @@
2
2
  "version": 1,
3
3
  "files": [
4
4
  "Canvas.d.ts",
5
- "Canvas.macos.d.ts",
6
- "Canvas.web.d.ts",
7
5
  "gpu.d.ts",
8
- "gpu.macos.d.ts",
9
- "gpu.web.d.ts",
10
6
  "index.d.ts",
11
- "index.macos.d.ts",
12
- "index.web.d.ts",
13
7
  "props.d.ts"
14
8
  ]
15
9
  }
@@ -1,3 +0,0 @@
1
- import type { CanvasProps } from './props.js';
2
- /** AppKit mounts a neutral frame. No drawing surface or GPU is created. */
3
- export declare function Canvas(props: CanvasProps): unknown;
@@ -1,6 +0,0 @@
1
- /** @jsxImportSource @octane-xplat/jsx/dom */
2
- import type { JSX } from 'octane/jsx-runtime';
3
- import type { CanvasProps } from './props.js';
4
- /** Canvas — a plain <canvas>. `onReady` fires at mount with the element
5
- * and the resolved context. */
6
- export declare function Canvas(props: CanvasProps): JSX.Element;
@@ -1,3 +0,0 @@
1
- /** AppKit has no Canvas WebGPU backend. Returns null before device acquisition.
2
- * Typed `any` to match the other platforms' getGPU signature. */
3
- export declare function getGPU(): any;
@@ -1,6 +0,0 @@
1
- /** getGPU — returns the WebGPU entry point (`navigator.gpu`) or null when
2
- * WebGPU is unavailable (insecure context, unsupported browser). The
3
- * returned object is spec-shaped: `requestAdapter()` +
4
- * `getPreferredCanvasFormat()`. Typed `any` deliberately — the shim and the
5
- * real navigator.gpu differ structurally beyond that shared surface. */
6
- export declare function getGPU(): any;
@@ -1,3 +0,0 @@
1
- export { Canvas } from './Canvas.macos.js';
2
- export { getGPU } from './gpu.macos.js';
3
- export type { CanvasProps, CanvasContextKind, CanvasReady } from './props.js';
@@ -1,3 +0,0 @@
1
- export { Canvas } from './Canvas.web.js';
2
- export { getGPU } from './gpu.web.js';
3
- export type { CanvasProps, CanvasContextKind, CanvasReady } from './props.js';