react-x11 2.31.0 → 2.32.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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/ntk.d.ts +26 -0
  3. package/src/ntk.js +11 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-x11",
3
- "version": "2.31.0",
3
+ "version": "2.32.0",
4
4
  "description": "react renderer with X11 as a target",
5
5
  "main": "./src/index.js",
6
6
  "files": [
package/src/ntk.d.ts CHANGED
@@ -91,6 +91,32 @@ export interface Surface {
91
91
  [Symbol.dispose](): void;
92
92
  }
93
93
  export const Surface: new (app: unknown, options: SurfaceOptions) => Surface;
94
+ /** What `decodeImageBytes` answers: an ntk `Image` of straight RGBA. */
95
+ export interface DecodedImage {
96
+ readonly width: number;
97
+ readonly height: number;
98
+ /** `width × height × 4` bytes, straight (not premultiplied) RGBA. */
99
+ readonly data: Uint8Array;
100
+ }
101
+
102
+ /**
103
+ * Encoded image bytes → an ntk `Image`, through the decoder `<image>` uses:
104
+ * the runtime's own where there is one (`Bun.Image`, off the JavaScript
105
+ * thread, every format it reads), and JavaScript elsewhere — PNG and JPEG
106
+ * synchronously, WebP through a decoder imported the first time a WebP
107
+ * arrives. The format comes from the bytes.
108
+ *
109
+ * An `Image`, or a promise of one wherever the decode is not synchronous;
110
+ * it throws, or rejects, on bytes this runtime cannot decode, saying what to
111
+ * convert them to. The bytes are read after it returns where the answer is
112
+ * a promise, so they must not change until it settles. See
113
+ * [elements.md](../docs/elements.md#formats-and-what-decodes-them) for which
114
+ * runtime decodes what.
115
+ */
116
+ export function decodeImageBytes(
117
+ bytes: Uint8Array,
118
+ ): DecodedImage | Promise<DecodedImage>;
119
+
94
120
  /** `code` values on a failed GL setup — see `<glarea onError>`. */
95
121
  export const GLXError: {
96
122
  NO_EXTENSION: 'GLX_NO_EXTENSION';
package/src/ntk.js CHANGED
@@ -28,6 +28,16 @@
28
28
  // without knowing which backend it was mounted on. This subpath is where a
29
29
  // drawing-adjacent name gets its backend-neutral answer; the X-only names
30
30
  // (`createClient`, `Pixmap`, `Picture`, `XEmbedSocket`) stay X-only.
31
+ //
32
+ // One name is not ntk's at all. `decodeImageBytes` (src/imagedecode.js) is
33
+ // the decoder ladder behind `<image>`'s bytes and files — the runtime's own
34
+ // decoder where there is one, WebP where ntk reads only PNG and JPEG — and
35
+ // an element that draws images of its own (`<Html>`'s `<img>`, a CSS
36
+ // background) decodes through it so that an image shows there exactly when
37
+ // it would show in an `<image>`. It is a name of its own rather than ntk's
38
+ // `decodeImage` answered differently, because that one is synchronous and a
39
+ // caller may read the size off what it returns; this one answers a promise
40
+ // wherever the decode is not.
31
41
  import * as ntk from 'ntk';
32
42
 
33
43
  import { adoptNtk } from './ntkroot.js';
@@ -35,6 +45,7 @@ import { adoptNtk } from './ntkroot.js';
35
45
  export * from 'ntk';
36
46
  export { default } from 'ntk';
37
47
  export { Surface } from './offscreen.js';
48
+ export { decodeImageBytes } from './imagedecode.js';
38
49
 
39
50
  // what src/ntkroot.js would load, already loaded: handed over rather than
40
51
  // imported twice