img-auto-parallax 0.1.0 → 0.1.2

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/cli.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import process from "node:process";
3
3
  import { parseArgs } from "node:util";
4
- import { r as precompute } from "./node-Cgcvci4U.mjs";
4
+ import { r as precompute } from "./node-DOo42478.mjs";
5
5
  // src/cli.ts
6
6
  /**
7
- * img-auto-parallax precompute <patterns...> [--model name] [--resolution n|full] [--suffix s] [--force]
7
+ * img-auto-parallax precompute <patterns...> [--model name] [--resolution n|full] [--map-size model|full] [--levels n] [--suffix s] [--force]
8
8
  */
9
9
  const HELP = `Usage: img-auto-parallax precompute <patterns...> [options]
10
10
 
@@ -12,7 +12,10 @@ Generate depth maps (photo.jpg -> photo.depth.png) for <img-auto-parallax src-de
12
12
 
13
13
  Options:
14
14
  --model <name> depth-anything (default) | midas | fastdepth
15
- --resolution <px> model input long side (default 518), or "full" (slow; output is 1:1 regardless)
15
+ --resolution <px> model input long side (default 518), or "full" (slow, usually softer)
16
+ --map-size <size> model (default): the model's output size, small; the browser
17
+ upsamples it along the photo's edges. full: 1:1 with the photo
18
+ --levels <n> gray levels in the map, 2-256 (default 128; fewer is smaller)
16
19
  --suffix <suffix> output suffix (default .depth.png)
17
20
  --force regenerate even when up to date
18
21
  -h, --help show this help
@@ -21,11 +24,13 @@ async function main() {
21
24
  const { values, positionals } = parseArgs({
22
25
  allowPositionals: true,
23
26
  options: {
24
- model: { type: "string" },
25
- resolution: { type: "string" },
26
- suffix: { type: "string" },
27
- force: { type: "boolean" },
28
- help: {
27
+ "model": { type: "string" },
28
+ "resolution": { type: "string" },
29
+ "map-size": { type: "string" },
30
+ "levels": { type: "string" },
31
+ "suffix": { type: "string" },
32
+ "force": { type: "boolean" },
33
+ "help": {
29
34
  type: "boolean",
30
35
  short: "h"
31
36
  }
@@ -41,6 +46,8 @@ async function main() {
41
46
  const result = await precompute(patterns, {
42
47
  model: values.model,
43
48
  resolution: values.resolution && values.resolution !== "full" ? Number(values.resolution) : void 0,
49
+ mapSize: values["map-size"] === "full" ? "full" : void 0,
50
+ levels: values.levels ? Number(values.levels) : void 0,
44
51
  suffix: values.suffix,
45
52
  force: values.force,
46
53
  onProgress: ({ output, status, index, total }) => {
package/dist/define.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as defineImgAutoParallax } from "./src-CLDV9piW.mjs";
1
+ import { n as defineImgAutoParallax } from "./src-BiTfnOJ8.mjs";
2
2
  // src/define.ts
3
3
  defineImgAutoParallax();
@@ -0,0 +1,292 @@
1
+ import "vgpu";
2
+ /** Describes an ONNX depth model the runtime can drive. */
3
+ interface DepthModelSpec {
4
+ /** Location of the `.onnx` file. */
5
+ url: string | URL;
6
+ /** Graph input name (NCHW float32). */
7
+ inputName: string;
8
+ /** Graph output name (float32, `[1, H, W]` or `[1, 1, H, W]`). */
9
+ outputName: string;
10
+ /**
11
+ * Input sizes are rounded to a multiple of this (the ViT patch size for
12
+ * Depth Anything). Ignored when `fixedSize` is set.
13
+ */
14
+ multiple?: number;
15
+ /** Fixed `[width, height]` input. When omitted, the input follows each image's aspect ratio. */
16
+ fixedSize?: readonly [number, number];
17
+ /** How RGB is normalised before inference: ImageNet mean/std, or plain 0–1. */
18
+ normalization: 'imagenet' | 'unit';
19
+ /**
20
+ * How to read the output. `relative`: larger values are nearer (inverse
21
+ * depth, auto-ranged per image). `metric`: metres, mapped with a log scale.
22
+ */
23
+ output: {
24
+ kind: 'relative';
25
+ } | {
26
+ kind: 'metric';
27
+ near: number;
28
+ far: number;
29
+ };
30
+ /** Needs the WebGPU `shader-f16` feature (fp16 weights). */
31
+ requiresF16?: boolean;
32
+ /** Used instead when `requiresF16` is set and the GPU lacks `shader-f16`. */
33
+ fallback?: DepthModelSpec;
34
+ /** Human-readable name, for pickers and logs. */
35
+ label?: string;
36
+ /** Download size in bytes, when known. */
37
+ bytes?: number;
38
+ }
39
+ type DepthModelPreset = 'depth-anything' | 'midas' | 'fastdepth';
40
+ /**
41
+ * The built-in models. Bundlers that understand `new URL(…, import.meta.url)`
42
+ * (Vite, webpack 5, Rollup) emit the bundled files as assets automatically.
43
+ */
44
+ declare const MODEL_PRESETS: Record<DepthModelPreset, DepthModelSpec>;
45
+ declare const DEFAULT_MODEL: DepthModelPreset;
46
+ /**
47
+ * Register a custom model under a name, so elements can pick it with
48
+ * `model="name"`. Re-registering a name replaces it for future estimates.
49
+ */
50
+ declare function registerModel(name: string, spec: DepthModelSpec): void;
51
+ /** Names usable in the `model` attribute: the presets and registered models. */
52
+ declare function listModels(): string[];
53
+ /** A preset or registered name, or a full spec. */
54
+ type DepthModelOption = DepthModelPreset | (string & {}) | DepthModelSpec;
55
+ /** True on devices without a hovering pointer that expose orientation events. */
56
+ declare function prefersGyro(): boolean;
57
+ /** Called when `getGyroPermission()` changes, e.g. after a grant or once readings arrive. */
58
+ declare function onGyroPermissionChange(listener: (permission: GyroPermission) => void): () => void;
59
+ /**
60
+ * Gyro access on this device:
61
+ * - `unavailable`: no orientation events (most desktops)
62
+ * - `prompt`: the browser asks first (iOS Safari); call `requestGyroPermission()` from a tap
63
+ * - `granted` / `denied`: the answer, for this page load
64
+ * - `not-required`: events flow without asking (Android, most others)
65
+ */
66
+ type GyroPermission = 'unavailable' | 'prompt' | 'granted' | 'denied' | 'not-required';
67
+ declare function getGyroPermission(): GyroPermission;
68
+ /**
69
+ * Ask for gyro access. Must run inside a user gesture (a tap or click handler),
70
+ * or iOS rejects it. Elements start following the tilt as soon as it is granted.
71
+ */
72
+ declare function requestGyroPermission(): Promise<GyroPermission>;
73
+ interface ModelProgress {
74
+ /** URL of the model being downloaded. */
75
+ url: string;
76
+ /** Bytes downloaded so far. */
77
+ loaded: number;
78
+ /** Total bytes, when the server reports it. */
79
+ total?: number;
80
+ }
81
+ interface ImgAutoParallaxConfig {
82
+ /**
83
+ * Default model for elements without a `model` attribute:
84
+ * `'depth-anything'` (default), `'midas'`, `'fastdepth'`, a registered name, or a spec.
85
+ */
86
+ model: DepthModelOption;
87
+ /** Override where ONNX Runtime loads its `.wasm` files from. Only read before the first load. */
88
+ wasmPaths?: string;
89
+ /** Model download progress. */
90
+ onProgress?: (progress: ModelProgress) => void;
91
+ }
92
+ /**
93
+ * Configure the shared runtime. Can be called at any time; changing `model`
94
+ * re-estimates every element that has no `model` attribute of its own.
95
+ */
96
+ declare function configure(options: Partial<ImgAutoParallaxConfig>): void;
97
+ /** Synchronous check: does this browser expose WebGPU at all? */
98
+ declare function hasWebGpu(): boolean;
99
+ /** Resolves `true` once the given (or default) model runs on this device, `false` if it cannot. */
100
+ declare function isSupported(model?: DepthModelOption): Promise<boolean>;
101
+ /** Start downloading a model and creating its GPU session ahead of time. */
102
+ declare function preload(model?: DepthModelOption): Promise<void>;
103
+ /**
104
+ * - `static` plain image: disabled, or out of view (GPU resources released)
105
+ * - `loading` estimating depth for the current image (or loading the model)
106
+ * - `ready` parallax active
107
+ * - `unsupported` no WebGPU, or the model failed to load: plain image
108
+ * - `error` this image could not be used (e.g. cross-origin without CORS): plain image
109
+ */
110
+ type ParallaxState = 'static' | 'loading' | 'ready' | 'unsupported' | 'error';
111
+ /**
112
+ * What drives the parallax:
113
+ * - `self-hover`: the pointer over this image
114
+ * - `page-hover`: the pointer anywhere on the page, relative to this image
115
+ * - `gyro`: device tilt
116
+ * - `both`: self-hover and gyro
117
+ * - `manual`: only `setPointer()`
118
+ * - `auto` (default): gyro on touch devices, self-hover elsewhere
119
+ *
120
+ * Combine them with spaces, e.g. `trigger="page-hover gyro"`.
121
+ */
122
+ type ParallaxTrigger = 'auto' | 'self-hover' | 'page-hover' | 'gyro' | 'both' | 'manual' | (string & {});
123
+ /** Motion when nobody is interacting. */
124
+ type ParallaxIdle = 'none' | 'sway';
125
+ /** What the canvas shows: the photo, or the estimated depth (near = bright). */
126
+ type ParallaxView = 'image' | 'depth';
127
+ /**
128
+ * What the element draws:
129
+ * - `image` (default): the photo with depth parallax
130
+ * - `foreground`: only what is nearer than `cutoff`, transparent elsewhere
131
+ * - `flat`: the whole photo moving rigidly with a `foreground` copy, as the plate behind it
132
+ * - `background`: only what is farther than `cutoff`, the foreground filled in from
133
+ * around it, moving at its own depth so a `foreground` copy slides over it
134
+ */
135
+ type ParallaxLayer = 'image' | 'foreground' | 'flat' | 'background';
136
+ /**
137
+ * The parallax options of `<img-auto-parallax>`, as its camelCase properties.
138
+ * Each is also an attribute in kebab-case (`focusDepth` → `focus-depth`).
139
+ * Everything is optional; leaving one out uses the default (see `DEFAULTS`).
140
+ */
141
+ interface ParallaxOptions {
142
+ /** Plain image when true: no model, no GPU work. */
143
+ disabled?: boolean;
144
+ /**
145
+ * A precompiled depth map (grayscale, near = bright, any size), e.g. from
146
+ * `img-auto-parallax precompute`. When set, no model or ONNX Runtime is loaded.
147
+ */
148
+ srcDepth?: string | null;
149
+ /** Model for this element: a preset or a `registerModel()` name. Defaults to `configure({ model })`. */
150
+ model?: DepthModelPreset | (string & {}) | null;
151
+ /** Maximum displacement as a fraction of the image height (0–0.3, default 0.03). */
152
+ strength?: number;
153
+ /** Nearness of the plane that stays still: 0 = background, 1 = foreground (default 0.5). */
154
+ focusDepth?: number;
155
+ /** Easing time constant in ms; 0 follows the input immediately (default 150). */
156
+ smoothing?: number;
157
+ /** Long side of the depth model input in px; higher is sharper and slower (default 518). */
158
+ resolution?: number;
159
+ /** What drives the effect (default `auto`). */
160
+ trigger?: ParallaxTrigger;
161
+ /** Reverse the direction of motion. */
162
+ invert?: boolean;
163
+ /** Motion while nobody interacts (default `none`). */
164
+ idle?: ParallaxIdle;
165
+ /** `depth` shows the estimated depth map instead of the photo (default `image`). */
166
+ view?: ParallaxView;
167
+ /** Depth of field (0–1, default 0 = off). Focus follows the pointer; at rest it falls back to `focusDepth`. */
168
+ defocus?: number;
169
+ /** Bring the whole image back into focus while the pointer is not over it. */
170
+ refocus?: boolean;
171
+ /** Which part of the photo to draw (default `image`); stack layers for a lock-screen depth effect. */
172
+ layer?: ParallaxLayer;
173
+ /** Nearness threshold between `layer="foreground"` and `layer="background"` (0–1, default 0.6). */
174
+ cutoff?: number;
175
+ }
176
+ /** `detail` of the `parallax-error` event. */
177
+ interface ParallaxErrorDetail {
178
+ /** The state the element fell back to. */
179
+ state: 'unsupported' | 'error';
180
+ error: unknown;
181
+ }
182
+ /** Events `<img-auto-parallax>` dispatches, besides the standard ones. */
183
+ interface ImgAutoParallaxEventMap extends HTMLElementEventMap {
184
+ /** Depth is ready and the effect is live. */
185
+ 'parallax-ready': Event;
186
+ /** Fell back to a plain image. */
187
+ 'parallax-error': CustomEvent<ParallaxErrorDetail>;
188
+ }
189
+ declare const DEFAULTS: {
190
+ strength: number;
191
+ focusDepth: number;
192
+ smoothing: number;
193
+ resolution: number;
194
+ trigger: ParallaxTrigger;
195
+ idle: ParallaxIdle;
196
+ view: ParallaxView;
197
+ defocus: number;
198
+ layer: ParallaxLayer;
199
+ cutoff: number;
200
+ };
201
+ interface ImgAutoParallaxElement {
202
+ addEventListener: (<K extends keyof ImgAutoParallaxEventMap>(type: K, listener: (this: ImgAutoParallaxElement, event: ImgAutoParallaxEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions) => void) & ((type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void);
203
+ removeEventListener: (<K extends keyof ImgAutoParallaxEventMap>(type: K, listener: (this: ImgAutoParallaxElement, event: ImgAutoParallaxEventMap[K]) => unknown, options?: boolean | EventListenerOptions) => void) & ((type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void);
204
+ }
205
+ /**
206
+ * `<img-auto-parallax>`: an `<img>` that estimates depth on the GPU and
207
+ * shifts its layers with the pointer or device tilt. Falls back to the plain
208
+ * image when disabled, without WebGPU, or when the image cannot be read.
209
+ */
210
+ declare class ImgAutoParallaxElement extends HTMLElement implements Required<ParallaxOptions> {
211
+ #private;
212
+ static readonly observedAttributes: string[];
213
+ constructor();
214
+ get src(): string;
215
+ set src(value: string);
216
+ get alt(): string;
217
+ set alt(value: string);
218
+ get currentSrc(): string;
219
+ get complete(): boolean;
220
+ get naturalWidth(): number;
221
+ get naturalHeight(): number;
222
+ decode(): Promise<void>;
223
+ /** Plain image when true: no model, no GPU work. */
224
+ get disabled(): boolean;
225
+ set disabled(value: boolean);
226
+ /** Model for this element: `auto`, a preset (`q4f16`, `q4`, `fp16`, `fp32`) or a registered name. Defaults to `configure({ model })`. */
227
+ /**
228
+ * A precompiled depth map (grayscale, near = bright, any size), e.g. from
229
+ * `img-auto-parallax precompute`. When set, no model or ONNX Runtime is loaded.
230
+ */
231
+ get srcDepth(): string | null;
232
+ set srcDepth(value: string | null | undefined);
233
+ get model(): string | null;
234
+ set model(value: string | null);
235
+ /** Maximum displacement as a fraction of the image height (0–0.3, default 0.03). */
236
+ get strength(): number;
237
+ set strength(value: number);
238
+ /** Nearness of the plane that stays still: 0 = background, 1 = foreground (default 0.5). */
239
+ get focusDepth(): number;
240
+ set focusDepth(value: number);
241
+ /** Easing time constant in ms; 0 follows the input immediately (default 150). */
242
+ get smoothing(): number;
243
+ set smoothing(value: number);
244
+ /** Long side of the depth model input in px; higher is sharper and slower (default 518). */
245
+ get resolution(): number;
246
+ set resolution(value: number);
247
+ /** What drives the effect (default `auto`). */
248
+ get trigger(): ParallaxTrigger;
249
+ set trigger(value: ParallaxTrigger);
250
+ /** Reverse the direction of motion. */
251
+ get invert(): boolean;
252
+ set invert(value: boolean);
253
+ /** Motion while nobody interacts (default `none`). */
254
+ get idle(): ParallaxIdle;
255
+ set idle(value: ParallaxIdle);
256
+ /** `depth` shows the estimated depth map instead of the photo (default `image`). */
257
+ get view(): ParallaxView;
258
+ set view(value: ParallaxView);
259
+ /**
260
+ * Depth of field (0–1, default 0 = off). Focus follows whatever is under the
261
+ * pointer (or the idle sway); at rest it falls back to `focus-depth`.
262
+ */
263
+ get defocus(): number;
264
+ set defocus(value: number);
265
+ /** Bring the whole image back into focus while the pointer is not over it (depth of field only while hovering). */
266
+ get refocus(): boolean;
267
+ set refocus(value: boolean);
268
+ /**
269
+ * `foreground` draws only what is nearer than `cutoff`; `flat` draws the whole photo
270
+ * moving in lockstep with it; `background` draws the rest, with the foreground filled
271
+ * in, moving less, so the subject separates from it. Stack `flat` or `background`, your
272
+ * content, then `foreground` to tuck content behind the subject, like a lock-screen depth effect.
273
+ */
274
+ get layer(): ParallaxLayer;
275
+ set layer(value: ParallaxLayer);
276
+ /** Nearness threshold between `layer="foreground"` and `layer="background"` (0–1, default 0.6). */
277
+ get cutoff(): number;
278
+ set cutoff(value: number);
279
+ /** Current lifecycle state; also reflected as the `data-state` attribute. */
280
+ get state(): ParallaxState;
281
+ /**
282
+ * Steer the effect yourself, with `x`/`y` in -1..1. Pass `null` to release
283
+ * control. Works with any trigger; use `trigger="manual"` to ignore others.
284
+ */
285
+ setPointer(x: number | null, y?: number): void;
286
+ /** Re-run depth estimation for the current image, bypassing the shared cache. */
287
+ refresh(): void;
288
+ connectedCallback(): void;
289
+ disconnectedCallback(): void;
290
+ attributeChangedCallback(name: string, old: string | null, value: string | null): void;
291
+ }
292
+ export { DepthModelOption as C, listModels as D, MODEL_PRESETS as E, registerModel as O, DEFAULT_MODEL as S, DepthModelSpec as T, GyroPermission as _, ParallaxIdle as a, prefersGyro as b, ParallaxState as c, ImgAutoParallaxConfig as d, ModelProgress as f, preload as g, isSupported as h, ParallaxErrorDetail as i, ParallaxTrigger as l, hasWebGpu as m, ImgAutoParallaxElement as n, ParallaxLayer as o, configure as p, ImgAutoParallaxEventMap as r, ParallaxOptions as s, DEFAULTS as t, ParallaxView as u, getGyroPermission as v, DepthModelPreset as w, requestGyroPermission as x, onGyroPermissionChange as y };
package/dist/index.d.mts CHANGED
@@ -1,237 +1,4 @@
1
- import "vgpu";
2
- /**
3
- * - `static` plain image: disabled, or out of view (GPU resources released)
4
- * - `loading` estimating depth for the current image (or loading the model)
5
- * - `ready` parallax active
6
- * - `unsupported` no WebGPU, or the model failed to load: plain image
7
- * - `error` this image could not be used (e.g. cross-origin without CORS): plain image
8
- */
9
- type ParallaxState = 'static' | 'loading' | 'ready' | 'unsupported' | 'error';
10
- /**
11
- * What drives the parallax:
12
- * - `self-hover`: the pointer over this image
13
- * - `page-hover`: the pointer anywhere on the page, relative to this image
14
- * - `gyro`: device tilt
15
- * - `both`: self-hover and gyro
16
- * - `manual`: only `setPointer()`
17
- * - `auto` (default): gyro on touch devices, self-hover elsewhere
18
- *
19
- * Combine them with spaces, e.g. `trigger="page-hover gyro"`.
20
- */
21
- type ParallaxTrigger = 'auto' | 'self-hover' | 'page-hover' | 'gyro' | 'both' | 'manual' | (string & {});
22
- /** Motion when nobody is interacting. */
23
- type ParallaxIdle = 'none' | 'sway';
24
- /** What the canvas shows: the photo, or the estimated depth (near = bright). */
25
- type ParallaxView = 'image' | 'depth';
26
- /**
27
- * What the element draws:
28
- * - `image` (default): the photo with depth parallax
29
- * - `foreground`: only what is nearer than `cutoff`, transparent elsewhere
30
- * - `flat`: the whole photo moving rigidly with a `foreground` copy, as the plate behind it
31
- * - `background`: only what is farther than `cutoff`, the foreground filled in from
32
- * around it, moving at its own depth so a `foreground` copy slides over it
33
- */
34
- type ParallaxLayer = 'image' | 'foreground' | 'flat' | 'background';
35
- export declare const DEFAULTS: {
36
- strength: number;
37
- focusDepth: number;
38
- smoothing: number;
39
- resolution: number;
40
- trigger: ParallaxTrigger;
41
- idle: ParallaxIdle;
42
- view: ParallaxView;
43
- defocus: number;
44
- layer: ParallaxLayer;
45
- cutoff: number;
46
- };
47
- /**
48
- * `<img-auto-parallax>`: an `<img>` that estimates depth on the GPU and
49
- * shifts its layers with the pointer or device tilt. Falls back to the plain
50
- * image when disabled, without WebGPU, or when the image cannot be read.
51
- */
52
- export declare class ImgAutoParallaxElement extends HTMLElement {
53
- #private;
54
- static readonly observedAttributes: string[];
55
- constructor();
56
- get src(): string;
57
- set src(value: string);
58
- get alt(): string;
59
- set alt(value: string);
60
- get currentSrc(): string;
61
- get complete(): boolean;
62
- get naturalWidth(): number;
63
- get naturalHeight(): number;
64
- decode(): Promise<void>;
65
- /** Plain image when true: no model, no GPU work. */
66
- get disabled(): boolean;
67
- set disabled(value: boolean);
68
- /** Model for this element: `auto`, a preset (`q4f16`, `q4`, `fp16`, `fp32`) or a registered name. Defaults to `configure({ model })`. */
69
- /**
70
- * A precompiled depth map (grayscale, near = bright, any size), e.g. from
71
- * `img-auto-parallax precompute`. When set, no model or ONNX Runtime is loaded.
72
- */
73
- get srcDepth(): string | null;
74
- set srcDepth(value: string | null | undefined);
75
- get model(): string | null;
76
- set model(value: string | null);
77
- /** Maximum displacement as a fraction of the image height (0–0.3, default 0.03). */
78
- get strength(): number;
79
- set strength(value: number);
80
- /** Nearness of the plane that stays still: 0 = background, 1 = foreground (default 0.5). */
81
- get focusDepth(): number;
82
- set focusDepth(value: number);
83
- /** Easing time constant in ms; 0 follows the input immediately (default 150). */
84
- get smoothing(): number;
85
- set smoothing(value: number);
86
- /** Long side of the depth model input in px; higher is sharper and slower (default 518). */
87
- get resolution(): number;
88
- set resolution(value: number);
89
- /** What drives the effect (default `auto`). */
90
- get trigger(): ParallaxTrigger;
91
- set trigger(value: ParallaxTrigger);
92
- /** Reverse the direction of motion. */
93
- get invert(): boolean;
94
- set invert(value: boolean);
95
- /** Motion while nobody interacts (default `none`). */
96
- get idle(): ParallaxIdle;
97
- set idle(value: ParallaxIdle);
98
- /** `depth` shows the estimated depth map instead of the photo (default `image`). */
99
- get view(): ParallaxView;
100
- set view(value: ParallaxView);
101
- /**
102
- * Depth of field (0–1, default 0 = off). Focus follows whatever is under the
103
- * pointer (or the idle sway); at rest it falls back to `focus-depth`.
104
- */
105
- get defocus(): number;
106
- set defocus(value: number);
107
- /** Bring the whole image back into focus while the pointer is not over it (depth of field only while hovering). */
108
- get refocus(): boolean;
109
- set refocus(value: boolean);
110
- /**
111
- * `foreground` draws only what is nearer than `cutoff`; `flat` draws the whole photo
112
- * moving in lockstep with it; `background` draws the rest, with the foreground filled
113
- * in, moving less, so the subject separates from it. Stack `flat` or `background`, your
114
- * content, then `foreground` to tuck content behind the subject, like a lock-screen depth effect.
115
- */
116
- get layer(): ParallaxLayer;
117
- set layer(value: ParallaxLayer);
118
- /** Nearness threshold between `layer="foreground"` and `layer="background"` (0–1, default 0.6). */
119
- get cutoff(): number;
120
- set cutoff(value: number);
121
- /** Current lifecycle state; also reflected as the `data-state` attribute. */
122
- get state(): ParallaxState;
123
- /**
124
- * Steer the effect yourself, with `x`/`y` in -1..1. Pass `null` to release
125
- * control. Works with any trigger; use `trigger="manual"` to ignore others.
126
- */
127
- setPointer(x: number | null, y?: number): void;
128
- /** Re-run depth estimation for the current image. */
129
- refresh(): void;
130
- connectedCallback(): void;
131
- disconnectedCallback(): void;
132
- attributeChangedCallback(name: string, old: string | null, value: string | null): void;
133
- }
134
- /** True on devices without a hovering pointer that expose orientation events. */
135
- export declare function prefersGyro(): boolean;
136
- /** Called when `getGyroPermission()` changes, e.g. after a grant or once readings arrive. */
137
- export declare function onGyroPermissionChange(listener: (permission: GyroPermission) => void): () => void;
138
- /**
139
- * Gyro access on this device:
140
- * - `unavailable`: no orientation events (most desktops)
141
- * - `prompt`: the browser asks first (iOS Safari); call `requestGyroPermission()` from a tap
142
- * - `granted` / `denied`: the answer, for this page load
143
- * - `not-required`: events flow without asking (Android, most others)
144
- */
145
- type GyroPermission = 'unavailable' | 'prompt' | 'granted' | 'denied' | 'not-required';
146
- export declare function getGyroPermission(): GyroPermission;
147
- /**
148
- * Ask for gyro access. Must run inside a user gesture (a tap or click handler),
149
- * or iOS rejects it. Elements start following the tilt as soon as it is granted.
150
- */
151
- export declare function requestGyroPermission(): Promise<GyroPermission>;
152
- /** Describes an ONNX depth model the runtime can drive. */
153
- interface DepthModelSpec {
154
- /** Location of the `.onnx` file. */
155
- url: string | URL;
156
- /** Graph input name (NCHW float32). */
157
- inputName: string;
158
- /** Graph output name (float32, `[1, H, W]` or `[1, 1, H, W]`). */
159
- outputName: string;
160
- /**
161
- * Input sizes are rounded to a multiple of this (the ViT patch size for
162
- * Depth Anything). Ignored when `fixedSize` is set.
163
- */
164
- multiple?: number;
165
- /** Fixed `[width, height]` input. When omitted, the input follows each image's aspect ratio. */
166
- fixedSize?: readonly [number, number];
167
- /** How RGB is normalised before inference: ImageNet mean/std, or plain 0–1. */
168
- normalization: 'imagenet' | 'unit';
169
- /**
170
- * How to read the output. `relative`: larger values are nearer (inverse
171
- * depth, auto-ranged per image). `metric`: metres, mapped with a log scale.
172
- */
173
- output: {
174
- kind: 'relative';
175
- } | {
176
- kind: 'metric';
177
- near: number;
178
- far: number;
179
- };
180
- /** Needs the WebGPU `shader-f16` feature (fp16 weights). */
181
- requiresF16?: boolean;
182
- /** Used instead when `requiresF16` is set and the GPU lacks `shader-f16`. */
183
- fallback?: DepthModelSpec;
184
- /** Human-readable name, for pickers and logs. */
185
- label?: string;
186
- /** Download size in bytes, when known. */
187
- bytes?: number;
188
- }
189
- type DepthModelPreset = 'depth-anything' | 'midas' | 'fastdepth';
190
- /**
191
- * The built-in models. Bundlers that understand `new URL(…, import.meta.url)`
192
- * (Vite, webpack 5, Rollup) emit the bundled files as assets automatically.
193
- */
194
- export declare const MODEL_PRESETS: Record<DepthModelPreset, DepthModelSpec>;
195
- export declare const DEFAULT_MODEL: DepthModelPreset;
196
- /**
197
- * Register a custom model under a name, so elements can pick it with
198
- * `model="name"`. Re-registering a name replaces it for future estimates.
199
- */
200
- export declare function registerModel(name: string, spec: DepthModelSpec): void;
201
- /** Names usable in the `model` attribute: the presets and registered models. */
202
- export declare function listModels(): string[];
203
- /** A preset or registered name, or a full spec. */
204
- type DepthModelOption = DepthModelPreset | (string & {}) | DepthModelSpec;
205
- interface ModelProgress {
206
- /** URL of the model being downloaded. */
207
- url: string;
208
- /** Bytes downloaded so far. */
209
- loaded: number;
210
- /** Total bytes, when the server reports it. */
211
- total?: number;
212
- }
213
- interface ImgAutoParallaxConfig {
214
- /**
215
- * Default model for elements without a `model` attribute:
216
- * `'depth-anything'` (default), `'midas'`, `'fastdepth'`, a registered name, or a spec.
217
- */
218
- model: DepthModelOption;
219
- /** Override where ONNX Runtime loads its `.wasm` files from. Only read before the first load. */
220
- wasmPaths?: string;
221
- /** Model download progress. */
222
- onProgress?: (progress: ModelProgress) => void;
223
- }
224
- /**
225
- * Configure the shared runtime. Can be called at any time; changing `model`
226
- * re-estimates every element that has no `model` attribute of its own.
227
- */
228
- export declare function configure(options: Partial<ImgAutoParallaxConfig>): void;
229
- /** Synchronous check: does this browser expose WebGPU at all? */
230
- export declare function hasWebGpu(): boolean;
231
- /** Resolves `true` once the given (or default) model runs on this device, `false` if it cannot. */
232
- export declare function isSupported(model?: DepthModelOption): Promise<boolean>;
233
- /** Start downloading a model and creating its GPU session ahead of time. */
234
- export declare function preload(model?: DepthModelOption): Promise<void>;
1
+ import { C as DepthModelOption, D as listModels, E as MODEL_PRESETS, O as registerModel, S as DEFAULT_MODEL, T as DepthModelSpec, _ as GyroPermission, a as ParallaxIdle, b as prefersGyro, c as ParallaxState, d as ImgAutoParallaxConfig, f as ModelProgress, g as preload, h as isSupported, i as ParallaxErrorDetail, l as ParallaxTrigger, m as hasWebGpu, n as ImgAutoParallaxElement, o as ParallaxLayer, p as configure, r as ImgAutoParallaxEventMap, s as ParallaxOptions, t as DEFAULTS, u as ParallaxView, v as getGyroPermission, w as DepthModelPreset, x as requestGyroPermission, y as onGyroPermissionChange } from "./element-C2AqZorC.mjs";
235
2
  export declare const DEFAULT_TAG = "img-auto-parallax";
236
3
  /**
237
4
  * Register the custom element (idempotent). Pass a different tag to avoid
@@ -243,4 +10,4 @@ declare global {
243
10
  'img-auto-parallax': ImgAutoParallaxElement;
244
11
  }
245
12
  }
246
- export type { DepthModelOption, DepthModelPreset, DepthModelSpec, GyroPermission, ImgAutoParallaxConfig, ModelProgress, ParallaxIdle, ParallaxLayer, ParallaxState, ParallaxTrigger, ParallaxView };
13
+ export { DEFAULTS, DEFAULT_MODEL, type DepthModelOption, type DepthModelPreset, type DepthModelSpec, type GyroPermission, type ImgAutoParallaxConfig, ImgAutoParallaxElement, type ImgAutoParallaxEventMap, MODEL_PRESETS, type ModelProgress, type ParallaxErrorDetail, type ParallaxIdle, type ParallaxLayer, type ParallaxOptions, type ParallaxState, type ParallaxTrigger, type ParallaxView, configure, getGyroPermission, hasWebGpu, isSupported, listModels, onGyroPermissionChange, prefersGyro, preload, registerModel, requestGyroPermission };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { r as DEFAULTS, l as DEFAULT_MODEL, t as DEFAULT_TAG, i as ImgAutoParallaxElement, u as MODEL_PRESETS, a as configure, n as defineImgAutoParallax, p as getGyroPermission, o as hasWebGpu, s as isSupported, d as listModels, m as onGyroPermissionChange, h as prefersGyro, c as preload, f as registerModel, g as requestGyroPermission } from "./src-CLDV9piW.mjs";
1
+ export { r as DEFAULTS, l as DEFAULT_MODEL, t as DEFAULT_TAG, i as ImgAutoParallaxElement, u as MODEL_PRESETS, a as configure, n as defineImgAutoParallax, p as getGyroPermission, o as hasWebGpu, s as isSupported, d as listModels, m as onGyroPermissionChange, h as prefersGyro, c as preload, f as registerModel, g as requestGyroPermission } from "./src-BiTfnOJ8.mjs";
@@ -45,11 +45,24 @@ interface DepthMapOptions {
45
45
  model?: DepthModelOption;
46
46
  /**
47
47
  * Long side of the model input in px (default 518, what Depth Anything is
48
- * trained at), or `'full'` for the image's own size up to 2048 px. The output
49
- * map is always 1:1 with the photo either way; `'full'` is ~60× slower, needs
50
- * gigabytes of memory, and usually comes out softer. Ignored by fixed-size models.
48
+ * trained at), or `'full'` for the image's own size up to 2048 px. `'full'` is
49
+ * ~60× slower, needs gigabytes of memory, and usually comes out softer. Ignored
50
+ * by fixed-size models. See `mapSize` for the size of the written map.
51
51
  */
52
52
  resolution?: number | 'full';
53
+ /**
54
+ * Size of the written map. `'model'` (default) keeps the model's own output size: the
55
+ * browser upsamples it along the photo's edges just as it does live, so it looks the
56
+ * same at a fraction of the bytes. `'full'` writes it already upsampled, 1:1 with the
57
+ * photo (up to 2048 px, several times larger), e.g. to inspect or retouch it by hand.
58
+ */
59
+ mapSize?: 'model' | 'full';
60
+ /**
61
+ * Gray levels in the written map (2–256, default 128). Fewer compress better; the
62
+ * browser's edge-aware upsampling smooths the steps, and 128 keeps them below what
63
+ * the parallax shows. 256 keeps full 8-bit precision.
64
+ */
65
+ levels?: number;
53
66
  }
54
67
  interface DepthMap {
55
68
  width: number;