lecodes-sdk 2.2.10 → 2.2.11

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/package.json CHANGED
@@ -45,7 +45,7 @@
45
45
  "marcidb-embedded": "^0.15.0",
46
46
  "sharp": "^0.35.2"
47
47
  },
48
- "version": "2.2.10",
48
+ "version": "2.2.11",
49
49
  "files": [
50
50
  "src",
51
51
  "dist",
@@ -18,7 +18,9 @@ import type { f32, f64, i32 } from "./types"
18
18
  declare global {
19
19
  /** @host media @optional */
20
20
  var _creatorMedia: {
21
- /** A player for `src` as an owned Handle (null = the host failed to create one). @custom */
21
+ /** A player for `src` as an owned Handle (null = the host failed to create one). `src` is a url
22
+ * or `"id:<bufferId>"` (a host buffer: a local asset, a File, a FetchResponse), which the host
23
+ * resolves. @custom */
22
24
  createAudio(src: string): Handle | null
23
25
  /** @custom */
24
26
  createVideo(src: string): Handle | null
@@ -115,14 +115,14 @@ export class Canvas extends Recorder {
115
115
  }
116
116
 
117
117
  /** Decode an image source into a standalone `Bitmap` you can blit with `drawImage()` — either an
118
- * `SvgSource(...)` (drawn by the core, painted by the host) or a `FetchResponse` holding already-fetched
119
- * image bytes (decoded; an SVG file is detected). This is async because the web host decodes with the
120
- * browser; `await` it ONCE, then `drawImage(bitmap, …)` is synchronous and the Bitmap is reusable. The
121
- * returned Bitmap owns a native surface at the image's natural pixel size (`pixelRatio` 1), freed
122
- * once nothing references the Bitmap (`destroy()` frees it early). Typical use:
118
+ * `SvgSource(...)` (drawn by the core, painted by the host) or a `FetchResponse` / `File` holding
119
+ * already-fetched image bytes (decoded; an SVG file is detected). This is async because the web host
120
+ * decodes with the browser; `await` it ONCE, then `drawImage(bitmap, …)` is synchronous and the Bitmap
121
+ * is reusable. The returned Bitmap owns a native surface at the image's natural pixel size
122
+ * (`pixelRatio` 1), freed once nothing references the Bitmap (`destroy()` frees it early). Typical use:
123
123
  * const logo = await canvas.loadImage(SvgSource(svg)) // or: await fetch(url) → the response
124
124
  * canvas.drawImage(logo, 0, 0) // sync, blit as often as you like */
125
- loadImage(source: SvgSourceValue | FetchResponse): Promise<Bitmap> {
125
+ loadImage(source: SvgSourceValue | FetchResponse | File): Promise<Bitmap> {
126
126
  // Discriminate without touching FetchResponse internals: only an SvgSource carries `.svg`.
127
127
  const isSvg = typeof (source as SvgSourceValue).svg === "string"
128
128
  const svg = isSvg ? (source as SvgSourceValue).svg : ""
@@ -7,10 +7,14 @@
7
7
  // then; a paused player you stop referencing is released at once. There is nothing to dispose. The
8
8
  // end-of-playback report comes by id through ONE emitter per world; a playing player is pinned so
9
9
  // the report finds it.
10
+ //
11
+ // `src` is a url, or a `File` / `FetchResponse`: those play from the host's buffer store
12
+ // (`"id:<bufferId>"`, the whole bytes in memory, no streaming).
10
13
 
11
14
  import { Emitter } from "../core/events"
12
15
  import { Pins } from "../core/pins"
13
16
  import { Texture } from "../gl/Texture"
17
+ import type { File, FetchResponse } from "./fetch"
14
18
 
15
19
  type MediaEvents = {
16
20
  /** Fired at each loop boundary while `loop` is true. */
@@ -30,6 +34,9 @@ const ensureEmitter = (): void => {
30
34
  emitterInstalled = true
31
35
  m.setEmitter((id) => { players.get(id)?._finished() })
32
36
  }
37
+ /** The wire spelling of a source: a url as is, a buffer (File / FetchResponse) as "id:<bufferId>". */
38
+ const wireSrc = (src?: string | File | FetchResponse): string =>
39
+ src == null ? "" : typeof src === "string" ? src : "id:" + (src as any)._h.id
33
40
 
34
41
  abstract class MediaPlayer extends Emitter<MediaEvents> {
35
42
  /** @internal The player's owned handle (`_h.id` = the host player id; -1 = no host player). */
@@ -92,18 +99,18 @@ abstract class MediaPlayer extends Emitter<MediaEvents> {
92
99
  }
93
100
 
94
101
  export class AudioPlayer extends MediaPlayer {
95
- constructor(src?: string) {
102
+ constructor(src?: string | File | FetchResponse) {
96
103
  super()
97
- this._src = src ?? ""
104
+ this._src = wireSrc(src)
98
105
  ensureEmitter()
99
106
  this._h = media()?.createAudio(this._src) ?? { id: -1 }
100
107
  }
101
108
  }
102
109
 
103
110
  export class VideoPlayer extends MediaPlayer {
104
- constructor(src?: string) {
111
+ constructor(src?: string | File | FetchResponse) {
105
112
  super()
106
- this._src = src ?? ""
113
+ this._src = wireSrc(src)
107
114
  ensureEmitter()
108
115
  this._h = media()?.createVideo(this._src) ?? { id: -1 }
109
116
  }
package/src/version.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  // same manifest). Its MAJOR is the bundle ↔ runtime contract: a bundle's `// sdk:` header line
5
5
  // and a host's embedded version must agree on the major for the host to run the bundle; minor
6
6
  // and patch never gate anything (features are detected, never versioned).
7
- export const SDK_VERSION = "2.2.10"
7
+ export const SDK_VERSION = "2.2.11"
8
8
 
9
9
  /** The major of a semver string, or null when it is not one. */
10
10
  export const sdkMajor = (version: string | null | undefined): number | null => {