@objectifthunes/three-book 0.5.0 → 0.5.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.
@@ -11,6 +11,13 @@ export interface LoadedImage {
11
11
  /** Object URL created by URL.createObjectURL — revoke when no longer needed. */
12
12
  objectUrl: string;
13
13
  }
14
+ /** Custom image position and size in canvas pixels. */
15
+ export interface ImageRect {
16
+ x: number;
17
+ y: number;
18
+ width: number;
19
+ height: number;
20
+ }
14
21
  /** Pixels per world unit — used to compute canvas size from page dimensions. */
15
22
  export declare const PX_PER_UNIT = 256;
16
23
  /**
@@ -22,6 +29,12 @@ export declare const PX_PER_UNIT = 256;
22
29
  * - `'cover'` — scales uniformly to fill, cropping the overflow
23
30
  */
24
31
  export declare function drawImageWithFit(ctx: CanvasRenderingContext2D, image: HTMLImageElement, x: number, y: number, width: number, height: number, fit: ImageFitMode): void;
32
+ /**
33
+ * Computes the default image rectangle for a given fit mode and canvas size.
34
+ * Returns the position and dimensions (in canvas pixels) that `drawImageWithFit`
35
+ * would use. Useful for initialising `ImageRect` before the user adjusts it.
36
+ */
37
+ export declare function computeDefaultImageRect(image: HTMLImageElement, canvasWidth: number, canvasHeight: number, fitMode: ImageFitMode, fullBleed: boolean): ImageRect;
25
38
  /**
26
39
  * Creates a `THREE.CanvasTexture` suitable for use as a book page.
27
40
  *
@@ -29,10 +42,11 @@ export declare function drawImageWithFit(ctx: CanvasRenderingContext2D, image: H
29
42
  * aspect ratio (256 px per world unit). Otherwise defaults to 512×512.
30
43
  *
31
44
  * - Fills the background with `color`.
32
- * - If `image` is provided, draws it using `fitMode` and `fullBleed`.
45
+ * - If `image` is provided, draws it using `fitMode` and `fullBleed`,
46
+ * or at the exact `imageRect` position if supplied.
33
47
  * - Otherwise, renders `label` as centred text (useful for debugging).
34
48
  */
35
- export declare function createPageTexture(color: string, label: string, image: HTMLImageElement | null, fitMode: ImageFitMode, fullBleed: boolean, pageWidth?: number, pageHeight?: number): THREE.Texture;
49
+ export declare function createPageTexture(color: string, label: string, image: HTMLImageElement | null, fitMode: ImageFitMode, fullBleed: boolean, pageWidth?: number, pageHeight?: number, imageRect?: ImageRect | null): THREE.Texture;
36
50
  /**
37
51
  * Loads a `File` into an `HTMLImageElement` and returns both the element
38
52
  * and the object URL it was decoded from.
@@ -1 +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,C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S,GAAG,IAAI,GAC3B,KAAK,CAAC,OAAO,CA+Bf;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,31 +1,30 @@
1
- {
2
- "name": "@objectifthunes/three-book",
3
- "version": "0.5.0",
4
- "type": "module",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "import": "./dist/index.js",
10
- "types": "./dist/index.d.ts"
11
- }
12
- },
13
- "files": [
14
- "dist"
15
- ],
16
- "scripts": {
17
- "build": "vite build && tsc --emitDeclarationOnly",
18
- "typecheck": "tsc --noEmit",
19
- "prepack": "pnpm run build"
20
- },
21
- "peerDependencies": {
22
- "three": ">=0.150.0"
23
- },
24
- "devDependencies": {
25
- "three": "^0.172.0",
26
- "@types/three": "^0.172.0",
27
- "typescript": "^5.7.0",
28
- "vite": "^6.0.0",
29
- "vite-plugin-dts": "^4.0.0"
30
- }
31
- }
1
+ {
2
+ "name": "@objectifthunes/three-book",
3
+ "version": "0.5.2",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "peerDependencies": {
17
+ "three": ">=0.150.0"
18
+ },
19
+ "devDependencies": {
20
+ "three": "^0.172.0",
21
+ "@types/three": "^0.172.0",
22
+ "typescript": "^5.7.0",
23
+ "vite": "^6.0.0",
24
+ "vite-plugin-dts": "^4.0.0"
25
+ },
26
+ "scripts": {
27
+ "build": "vite build && tsc --emitDeclarationOnly",
28
+ "typecheck": "tsc --noEmit"
29
+ }
30
+ }