@hackbuild/avatar-host 0.1.5 → 0.1.7

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/dist/drop.d.ts CHANGED
@@ -8,6 +8,7 @@ export interface EntryLike {
8
8
  readEntries(ok: (batch: EntryLike[]) => void, fail?: (e: unknown) => void): void;
9
9
  };
10
10
  }
11
+ /** The parts of a DataTransfer that `filesFromDrop` reads: entries and files. */
11
12
  export interface DropLike {
12
13
  items?: ArrayLike<{
13
14
  webkitGetAsEntry?(): EntryLike | null;
package/dist/element.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AvatarStage, type StageOptions } from "./stage.js";
2
2
  import type { DroppedFile } from "./source.js";
3
+ /** The `hb-avatar-host` custom element: a stage in the element, and a call to show dropped files. */
3
4
  export interface AvatarHostElement extends HTMLElement {
4
5
  readonly stage: AvatarStage | null;
5
6
  /** Shows dropped or picked files; resolves when the load settles. */
@@ -1,19 +1,23 @@
1
1
  import type { Scene, WebGLRenderer } from "three";
2
2
  import type { EnvironmentPreset } from "@hackbuild/environment";
3
3
  import type { LoadedEnvironment, Resolve } from "@hackbuild/environment/three";
4
+ /** What an environment slot writes to: the scene, the renderer and the call that swaps the shown scene. */
4
5
  export interface EnvironmentTarget {
5
6
  readonly scene: Scene;
6
7
  readonly renderer: WebGLRenderer;
7
8
  /** Swaps the shown scene: disposes the old one, attaches the new one or none. */
8
9
  setEnvironment(env: LoadedEnvironment | null): void;
9
10
  }
11
+ /** A scene preset by id or value, and how its files resolve. */
10
12
  export interface EnvironmentRequest {
11
13
  /** A preset id (studio, room, cafe, outdoors) or a preset. */
12
14
  preset: string | EnvironmentPreset;
13
15
  /** Gives the files the preset needs; the studio needs none. */
14
16
  resolve?: Resolve;
15
17
  }
18
+ /** Loads a scene preset onto a target; the default imports `@hackbuild/environment/three` on first use. */
16
19
  export type EnvironmentLoader = (req: EnvironmentRequest, target: EnvironmentTarget) => Promise<LoadedEnvironment>;
20
+ /** Shows one lit scene at a time on a stage; a later request overtakes one still loading. */
17
21
  export declare class EnvironmentSlot {
18
22
  private readonly target;
19
23
  private readonly load;
@@ -2,6 +2,7 @@ const defaultLoad = async (req, target) => {
2
2
  const { loadEnvironment } = await import("@hackbuild/environment/three");
3
3
  return loadEnvironment(req.preset, target.scene, target.renderer, req.resolve ? { resolve: req.resolve } : {});
4
4
  };
5
+ /** Shows one lit scene at a time on a stage; a later request overtakes one still loading. */
5
6
  export class EnvironmentSlot {
6
7
  target;
7
8
  load;
package/dist/follow.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Box3, type PerspectiveCamera, Vector3 } from "three";
2
+ /** Follow switch, ease rate, dead zone and margin of a `FollowCamera`. */
2
3
  export interface FollowOptions {
3
4
  /** Follow the body; false leaves the camera where the person or the last framing put it. Default true. */
4
5
  follow?: boolean;
@@ -11,6 +12,7 @@ export interface FollowOptions {
11
12
  /** Fit margin over the tight fit. Default 1.12 (vendor). */
12
13
  margin?: number;
13
14
  }
15
+ /** Keeps a body framed: eases toward a new framing with a dead zone, and leaves a distance or pan the person picked alone. */
14
16
  export declare class FollowCamera {
15
17
  readonly camera: PerspectiveCamera;
16
18
  /** The orbit target the camera looks at (OrbitControls.target). */
package/dist/follow.js CHANGED
@@ -5,6 +5,7 @@
5
5
  // put on screen. The camera pulls back as soon as a pose outgrows the view
6
6
  // and comes closer only once it is clearly too far.
7
7
  import { Box3, MathUtils, Vector3 } from "three";
8
+ /** Keeps a body framed: eases toward a new framing with a dead zone, and leaves a distance or pan the person picked alone. */
8
9
  export class FollowCamera {
9
10
  camera;
10
11
  target;
package/dist/host.d.ts CHANGED
@@ -1,7 +1,9 @@
1
+ /** The least a host source carries: its kind and an optional release call. */
1
2
  export interface HostSource {
2
3
  kind: string;
3
4
  release?(): void;
4
5
  }
6
+ /** Loads one kind of source: makes a runtime once, loads sources into it, and may destroy it. */
5
7
  export interface Adapter<S extends HostSource, T, R = unknown> {
6
8
  /** Runtimes are shared by adapters with the same key. Default: the kind. */
7
9
  key?: string;
@@ -9,6 +11,7 @@ export interface Adapter<S extends HostSource, T, R = unknown> {
9
11
  load(runtime: R, source: S): Promise<T>;
10
12
  destroy?(runtime: R): void;
11
13
  }
14
+ /** The adapters by kind, the exclusive switch and the discard call of an `AvatarHost`. */
12
15
  export interface AvatarHostOptions<S extends HostSource, T> {
13
16
  /** By kind. Each adapter carries its own runtime type; the host only passes it back. */
14
17
  adapters: Partial<Record<string, Adapter<S, T, unknown>>>;
@@ -17,6 +20,7 @@ export interface AvatarHostOptions<S extends HostSource, T> {
17
20
  /** Frees a result that lost to a later show and is never shown. */
18
21
  discard?(result: T): void;
19
22
  }
23
+ /** Shows one source at a time through adapters: each show takes a ticket, a load that a later show overtook is discarded, and runtimes are shared or destroyed by key. */
20
24
  export declare class AvatarHost<S extends HostSource, T> {
21
25
  private readonly opts;
22
26
  private readonly slots;
package/dist/host.js CHANGED
@@ -4,6 +4,7 @@
4
4
  // create is forgotten, so the next show tries again. With `exclusive` the
5
5
  // runtimes of other keys are destroyed when the key changes. A source's
6
6
  // `release` runs once, whether its load wins, loses or throws.
7
+ /** Shows one source at a time through adapters: each show takes a ticket, a load that a later show overtook is discarded, and runtimes are shared or destroyed by key. */
7
8
  export class AvatarHost {
8
9
  opts;
9
10
  slots = new Map();
package/dist/load.d.ts CHANGED
@@ -2,6 +2,7 @@ import { LoadingManager } from "three";
2
2
  import { type Avatar, type NormalizeOptions, type RepairOptions, type VrmHook } from "@hackbuild/avatar/three";
3
3
  import type { Adapter } from "./host.js";
4
4
  import type { BodyKind, BodySource } from "./source.js";
5
+ /** The VRM hook, normalize and repair options used when a body loads. */
5
6
  export interface BodyLoadOptions {
6
7
  /** The VRM hook, imported on the first .vrm: `() => import("@hackbuild/avatar/vrm").then((m) => m.vrmHook())`. Without it a VRM loads as plain glTF. */
7
8
  vrm?: () => Promise<VrmHook>;
package/dist/loop.d.ts CHANGED
@@ -1,8 +1,10 @@
1
+ /** Why a stage loop is stopped: hidden, off screen, inactive, covered, context lost or paused. */
1
2
  export type PauseReason = "hidden" | "offscreen" | "inactive" | "covered" | "lost" | "paused";
2
3
  /** The one call of WebGLRenderer the loop needs. */
3
4
  export interface LoopDriver {
4
5
  setAnimationLoop(cb: ((time: number) => void) | null): void;
5
6
  }
7
+ /** The renderer driver, the frame call, the busy test and timing options of a `StageLoop`. */
6
8
  export interface StageLoopOptions {
7
9
  driver: LoopDriver;
8
10
  /** One frame: `dt` in seconds, `time` the loop clock in seconds (the sum of deltas). */
@@ -16,6 +18,7 @@ export interface StageLoopOptions {
16
18
  /** Called when the loop starts or stops, with the reasons that hold. */
17
19
  onState?(running: boolean, reasons: PauseReason[]): void;
18
20
  }
21
+ /** The render loop of a stage: runs frames on the renderer's animation loop and stops while the page is hidden, off screen, covered, lost or paused. */
19
22
  export declare class StageLoop {
20
23
  private readonly opts;
21
24
  /** Frames drawn since the loop was made. */
package/dist/loop.js CHANGED
@@ -6,6 +6,7 @@
6
6
  // after a stop is one fixed step, so time does not jump on resume. Under
7
7
  // reduced motion the loop runs only while something moves (a clip the
8
8
  // person started, the camera under a finger) and otherwise draws on change.
9
+ /** The render loop of a stage: runs frames on the renderer's animation loop and stops while the page is hidden, off screen, covered, lost or paused. */
9
10
  export class StageLoop {
10
11
  opts;
11
12
  /** Frames drawn since the loop was made. */
@@ -1,4 +1,5 @@
1
1
  import { type Avatar } from "@hackbuild/avatar/three";
2
+ /** Body colour, joint colour and height scale of the placeholder body built in code. */
2
3
  export interface PlaceholderOptions {
3
4
  /** Body colour. Default a warm grey. */
4
5
  color?: number;
@@ -8,6 +8,7 @@ import type { ThumbRenderer } from "./thumb-queue.js";
8
8
  export declare const SAMPLES = 24;
9
9
  /** Bones that judge a frame; fingers would outvote them by count. */
10
10
  export declare const MEASURED: readonly HumanBone[];
11
+ /** Image width, height and canvas of a preview. */
11
12
  export interface PortraitOptions {
12
13
  /** Image width in pixels. Default 192. */
13
14
  width?: number;
@@ -33,6 +34,7 @@ export interface ClipThumbJob {
33
34
  /** A pose: show its last frame. */
34
35
  hold?: boolean;
35
36
  }
37
+ /** Image size, clay colour and figure of clip previews. */
36
38
  export interface ClipPortraitOptions extends PortraitOptions {
37
39
  /** Clay colour. Default a warm grey. */
38
40
  color?: string | number;
@@ -56,6 +58,7 @@ export interface AvatarThumbJob {
56
58
  id: string;
57
59
  source: BodySource;
58
60
  }
61
+ /** Image size, canvas and body load options of avatar previews. */
59
62
  export interface AvatarPortraitOptions extends PortraitOptions, BodyLoadOptions {
60
63
  }
61
64
  /** Avatar previews: each character loads, is drawn at rest with its own materials, and is freed. */
package/dist/source.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ /** The model formats a body source can be. */
1
2
  export type BodyKind = "vrm" | "glb" | "gltf" | "fbx";
3
+ /** A model to show: its kind, its file as a URL, bytes or Blob, its name, and how its referenced files resolve. */
2
4
  export interface BodySource {
3
5
  kind: BodyKind;
4
6
  /** The model file: a URL, bytes or a Blob (a dropped File). */
@@ -23,6 +25,7 @@ export declare function kindOf(name: string): BodyKind | null;
23
25
  export declare function sourceFromUrl(url: string, name?: string): BodySource;
24
26
  /** Lower case, forward slashes, no leading ./ and no URL escapes. */
25
27
  export declare function normalizeRef(ref: string): string;
28
+ /** Makes and revokes object URLs; swap it in tests. */
26
29
  export interface UrlFactory {
27
30
  create(b: Blob): string;
28
31
  revoke(url: string): void;
package/dist/stage.d.ts CHANGED
@@ -10,7 +10,9 @@ import { type BodyLoadOptions } from "./load.js";
10
10
  import { type PlaceholderOptions } from "./placeholder.js";
11
11
  import { EnvironmentSlot, type EnvironmentRequest } from "./environment.js";
12
12
  import type { LoadedEnvironment } from "@hackbuild/environment/three";
13
+ /** The line a stage shows when the browser drops its 3D context. */
13
14
  export declare const LOST_COPY = "the 3d view was lost. press to restore.";
15
+ /** Canvas, random source, pixel ratio, background, environment and body load options of an `AvatarStage`. */
14
16
  export interface StageOptions extends BodyLoadOptions {
15
17
  /** A canvas to draw on; by default the stage makes one and appends it to the container. */
16
18
  canvas?: HTMLCanvasElement;
@@ -31,6 +33,7 @@ export interface StageOptions extends BodyLoadOptions {
31
33
  /** A scene to show from the start, as `setEnvironment` takes it. */
32
34
  environment?: EnvironmentRequest | string;
33
35
  }
36
+ /** Frames per second, frame count, draw calls, triangles and buffer size of a stage. */
34
37
  export interface StageStats {
35
38
  /** Frames per second over the last window (measured from the loop clock). */
36
39
  fps: number;
@@ -43,6 +46,7 @@ export interface StageStats {
43
46
  height: number;
44
47
  pixelRatio: number;
45
48
  }
49
+ /** What a stage reports: a body loaded or failed, stats, loop state, and the 3D context lost or restored. */
46
50
  export type StageEvent = {
47
51
  type: "loaded";
48
52
  body: Body;
@@ -69,6 +73,7 @@ export type StageEvent = {
69
73
  type Of<K extends StageEvent["type"]> = Extract<StageEvent, {
70
74
  type: K;
71
75
  }>;
76
+ /** A three.js stage in a container: renderer, camera, orbit controls, follow camera, loop, environment slot and the body it shows. */
72
77
  export declare class AvatarStage {
73
78
  readonly container: HTMLElement;
74
79
  private readonly opts;
package/dist/stage.js CHANGED
@@ -17,9 +17,11 @@ import { FollowCamera } from "./follow.js";
17
17
  import { bodyAdapters } from "./load.js";
18
18
  import { placeholderBody } from "./placeholder.js";
19
19
  import { EnvironmentSlot, stagePixelRatio } from "./environment.js";
20
+ /** The line a stage shows when the browser drops its 3D context. */
20
21
  export const LOST_COPY = "the 3d view was lost. press to restore.";
21
22
  /** Pointer moves count as attention for this long, seconds (vendor). */
22
23
  const POINTER_WINDOW = 2;
24
+ /** A three.js stage in a container: renderer, camera, orbit controls, follow camera, loop, environment slot and the body it shows. */
23
25
  export class AvatarStage {
24
26
  container;
25
27
  opts;
@@ -12,6 +12,7 @@ export interface ThumbRenderer<J> {
12
12
  draw(job: J): Promise<Blob | null>;
13
13
  dispose(): void;
14
14
  }
15
+ /** The renderer factory, the save call, the failure and progress calls of a `ThumbQueue`. */
15
16
  export interface ThumbQueueOptions<J> {
16
17
  /** Builds the renderer, on first need and after a lost context. Null or a throw ends the run. */
17
18
  renderer(): Promise<ThumbRenderer<J> | null>;
@@ -31,6 +32,7 @@ export interface ThumbQueueOptions<J> {
31
32
  /** True while the page is hidden; default reads `document.visibilityState`. */
32
33
  hidden?(): boolean;
33
34
  }
35
+ /** Draws previews one at a time in the background, saves each image and remembers failures, paced so the page stays responsive. */
34
36
  export declare class ThumbQueue<J extends {
35
37
  id: string;
36
38
  }> {
@@ -10,6 +10,7 @@
10
10
  // not rebuild it, and is then disposed. No three.js here: the renderer is
11
11
  // injected, the three.js portraits are in portrait.ts.
12
12
  const reasonOf = (e) => (e instanceof Error ? e.message : String(e));
13
+ /** Draws previews one at a time in the background, saves each image and remembers failures, paced so the page stays responsive. */
13
14
  export class ThumbQueue {
14
15
  opts;
15
16
  state = { active: false, done: 0, total: 0 };
package/dist/thumbs.d.ts CHANGED
@@ -2,9 +2,11 @@ import { type AvatarPortraitOptions, type AvatarThumbJob, type ClipPortraitOptio
2
2
  import { ThumbQueue, type ThumbQueueOptions } from "./thumb-queue.js";
3
3
  export * from "./thumb-queue.js";
4
4
  export * from "./portrait.js";
5
+ /** Queue and portrait options of `clipThumbs`. */
5
6
  export type ClipThumbOptions = Omit<ThumbQueueOptions<ClipThumbJob>, "renderer"> & {
6
7
  portrait?: ClipPortraitOptions;
7
8
  };
9
+ /** Queue and portrait options of `avatarThumbs`. */
8
10
  export type AvatarThumbOptions = Omit<ThumbQueueOptions<AvatarThumbJob>, "renderer"> & {
9
11
  portrait?: AvatarPortraitOptions;
10
12
  };