@octane-xplat/canvas 0.8.0 → 0.10.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 ADDED
@@ -0,0 +1,56 @@
1
+ # `@octane-xplat/canvas`
2
+
3
+ ```sh
4
+ pnpm add @octane-xplat/canvas
5
+ ```
6
+
7
+ A GPU/canvas surface for Octane xplat apps: the DOM `<canvas>` on web and
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
+ native (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
+ Per-target limits are recorded in
55
+ [known limits](../../docs/verify/known-limits.md). Exercised by
56
+ [`CanvasDemo`](../demos/src/CanvasDemo.tsrx) (including a WGSL path).
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 1,
3
- "buildId": "5e0f5c59-ea8a-4253-90b4-f17f9d7f30d5",
3
+ "buildId": "266c5beb-953a-44be-a98f-964cada3fb26",
4
4
  "mode": "production",
5
5
  "capabilities": {
6
6
  "independentHydration": false
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 1,
3
- "buildId": "a5853361-5a4d-40e8-8fab-5c4ecf162294",
3
+ "buildId": "03fdb1cd-295a-4650-8734-16e8c367bd74",
4
4
  "mode": "production",
5
5
  "capabilities": {
6
6
  "independentHydration": false
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@octane-xplat/canvas",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Canvas/GPU surface for Octane xplat — web <canvas> + @nativescript/canvas (2D, WebGL/WebGL2, WebGPU/WGSL)",
5
5
  "keywords": [
6
- "octane",
7
- "xplat",
8
- "cross-platform",
9
6
  "canvas",
7
+ "cross-platform",
8
+ "gpu",
9
+ "graphics",
10
+ "nativescript",
11
+ "octane",
10
12
  "webgl",
11
13
  "webgl2",
12
14
  "webgpu",
13
15
  "wgsl",
14
- "gpu",
15
- "graphics",
16
- "nativescript"
16
+ "xplat"
17
17
  ],
18
- "license": "MIT",
19
18
  "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/canvas",
19
+ "license": "MIT",
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "git+https://github.com/octane-xplat/octane-xplat.git",
22
+ "url": "https://github.com/octane-xplat/octane-xplat",
23
23
  "directory": "packages/canvas"
24
24
  },
25
25
  "files": [
@@ -47,7 +47,7 @@
47
47
  "@nativescript/core": "9.1.2",
48
48
  "@octanejs/vite-plugin": "0.1.61",
49
49
  "octane": "0.6.3",
50
- "tsrx-typegen": "0.2.0",
50
+ "tsrx-typegen": "0.2.2",
51
51
  "typescript": "5.9.3",
52
52
  "vite": "8.3.0"
53
53
  },
package/src/gpu.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { GPU } from '@nativescript/canvas';
1
+ 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
5
  * `getPreferredCanvasFormat()`. */
6
6
  export function getGPU(): any {
7
- return new GPU();
7
+ return new GPU()
8
8
  }
package/src/gpu.web.ts CHANGED
@@ -3,5 +3,5 @@
3
3
  * returned object is spec-shaped: `requestAdapter()` +
4
4
  * `getPreferredCanvasFormat()`. */
5
5
  export function getGPU(): any {
6
- return (globalThis.navigator as any)?.gpu ?? null;
6
+ return (globalThis.navigator as any)?.gpu ?? null
7
7
  }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Platform barrels — explicit .tsrx leaf imports (moduleSuffixes don't
2
2
  // reach .tsrx; same convention as @octane-xplat/ui index.*.ts).
3
- export { Canvas } from './Canvas.tsrx';
4
- export { getGPU } from './gpu';
5
- export type { CanvasProps, CanvasContextKind, CanvasReady } from './props';
3
+ export { Canvas } from './Canvas.tsrx'
4
+ export { getGPU } from './gpu'
5
+ export type { CanvasProps, CanvasContextKind, CanvasReady } from './props'
package/src/index.web.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Platform barrels — explicit .tsrx leaf imports (moduleSuffixes don't
2
2
  // reach .tsrx; same convention as @octane-xplat/ui index.*.ts).
3
- export { Canvas } from './Canvas.web.tsrx';
4
- export { getGPU } from './gpu.web';
5
- export type { CanvasProps, CanvasContextKind, CanvasReady } from './props';
3
+ export { Canvas } from './Canvas.web.tsrx'
4
+ export { getGPU } from './gpu.web'
5
+ export type { CanvasProps, CanvasContextKind, CanvasReady } from './props'
package/src/props.ts CHANGED
@@ -1,33 +1,28 @@
1
- export type CanvasContextKind =
2
- | '2d'
3
- | 'webgl'
4
- | 'webgl2'
5
- | 'webgpu'
6
- | 'bitmaprenderer';
1
+ export type CanvasContextKind = '2d' | 'webgl' | 'webgl2' | 'webgpu' | 'bitmaprenderer'
7
2
 
8
3
  export interface CanvasReady {
9
4
  /** HTMLCanvasElement on web, the plugin's Canvas view on native —
10
5
  * both expose `getContext()`. */
11
- canvas: any;
6
+ canvas: any
12
7
  /** The resolved context for the `context` prop, or null when that
13
8
  * kind is unsupported/unavailable. WebGPU still needs a device —
14
9
  * `getGPU()` normalizes adapter/device acquisition. */
15
- context: any;
10
+ context: any
16
11
  }
17
12
 
18
13
  export interface CanvasProps {
19
- className?: any;
20
- style?: any;
21
- id?: string;
14
+ className?: any
15
+ style?: any
16
+ id?: string
22
17
  /** Context kind resolved before `onReady` fires. Omit to defer
23
18
  * `getContext` to user code (only one kind per canvas — call once). */
24
- context?: CanvasContextKind;
19
+ context?: CanvasContextKind
25
20
  /** Web: after mount. Native: the plugin's `ready` event (fires when the
26
21
  * GPU surface exists — earlier `getContext` calls can return null). */
27
- onReady?: (ready: CanvasReady) => void;
22
+ onReady?: (ready: CanvasReady) => void
28
23
  /** Numeric values map to the element's width/height — on web that is
29
24
  * the canvas *drawing buffer* size (pair with style for display
30
25
  * size), on native dip size. */
31
- width?: string | number;
32
- height?: string | number;
26
+ width?: string | number
27
+ height?: string | number
33
28
  }