@objectifthunes/three-book 0.1.5 → 0.2.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.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Texture helpers for building book page content from canvas or images.
3
+ * All utilities are browser-only (require document / URL APIs).
4
+ */
5
+ import * as THREE from 'three';
6
+ /** How an image is scaled to fit a rectangular area. */
7
+ export type ImageFitMode = 'contain' | 'cover' | 'fill';
8
+ /** Resolved image ready to be passed to createPageTexture. */
9
+ export interface LoadedImage {
10
+ image: HTMLImageElement;
11
+ /** Object URL created by URL.createObjectURL — revoke when no longer needed. */
12
+ objectUrl: string;
13
+ }
14
+ /** Pixels per world unit — used to compute canvas size from page dimensions. */
15
+ export declare const PX_PER_UNIT = 256;
16
+ /**
17
+ * Draws `image` into a 2D canvas context within the rectangle
18
+ * (x, y, width, height) using the given fit mode.
19
+ *
20
+ * - `'fill'` — stretches to fill exactly, ignoring aspect ratio
21
+ * - `'contain'` — scales uniformly to fit inside, letterboxed
22
+ * - `'cover'` — scales uniformly to fill, cropping the overflow
23
+ */
24
+ export declare function drawImageWithFit(ctx: CanvasRenderingContext2D, image: HTMLImageElement, x: number, y: number, width: number, height: number, fit: ImageFitMode): void;
25
+ /**
26
+ * Creates a `THREE.CanvasTexture` suitable for use as a book page.
27
+ *
28
+ * When `pageWidth` and `pageHeight` are given the canvas matches the page
29
+ * aspect ratio (256 px per world unit). Otherwise defaults to 512×512.
30
+ *
31
+ * - Fills the background with `color`.
32
+ * - If `image` is provided, draws it using `fitMode` and `fullBleed`.
33
+ * - Otherwise, renders `label` as centred text (useful for debugging).
34
+ */
35
+ export declare function createPageTexture(color: string, label: string, image: HTMLImageElement | null, fitMode: ImageFitMode, fullBleed: boolean, pageWidth?: number, pageHeight?: number): THREE.Texture;
36
+ /**
37
+ * Loads a `File` into an `HTMLImageElement` and returns both the element
38
+ * and the object URL it was decoded from.
39
+ *
40
+ * The caller is responsible for calling `URL.revokeObjectURL(result.objectUrl)`
41
+ * when the image is no longer needed.
42
+ *
43
+ * Returns `null` if `file` is null/undefined or if decoding fails.
44
+ */
45
+ export declare function loadImage(file: File | null | undefined): Promise<LoadedImage | null>;
46
+ //# sourceMappingURL=textureUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textureUtils.d.ts","sourceRoot":"","sources":["../src/textureUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,wDAAwD;AACxD,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAExD,8DAA8D;AAC9D,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,gBAAgB,CAAC;IACxB,gFAAgF;IAChF,SAAS,EAAE,MAAM,CAAC;CACnB;AAID,gFAAgF;AAChF,eAAO,MAAM,WAAW,MAAM,CAAC;AAI/B;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,gBAAgB,EACvB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,YAAY,GAChB,IAAI,CAkBN;AAID;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,gBAAgB,GAAG,IAAI,EAC9B,OAAO,EAAE,YAAY,EACrB,SAAS,EAAE,OAAO,EAClB,SAAS,CAAC,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,KAAK,CAAC,OAAO,CA2Bf;AAID;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAmB1F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@objectifthunes/three-book",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",