Initial commit

This commit is contained in:
robert committed 2025-05-30 18:13:30 +08:00
commit e49726988c
5445 files changed
+1089914

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"module": "nodenext",
"moduleResolution": "nodenext"
}
}
+17
View File
@@ -0,0 +1,17 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.cts",
"../src/**/*.tsx",
"../src/**/*.json"
],
"exclude": [
"../**/*.test.ts",
"../src/**/*.mts",
"../src/package.json"
],
"compilerOptions": {
"outDir": "../.tshy-build/commonjs"
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.mts",
"../src/**/*.tsx",
"../src/**/*.json"
],
"exclude": [
"../**/*.test.ts",
"../src/package.json"
],
"compilerOptions": {
"outDir": "../.tshy-build/esm"
}
}
+5
View File
@@ -0,0 +1,5 @@

> @jimp/plugin-contain@1.5.0 build /Users/andrewlisowski/Documents/jimp/plugins/plugin-contain
> tshy
+5
View File
@@ -0,0 +1,5 @@

> @jimp/plugin-contain@1.1.2 lint /Users/andrewlisowski/Documents/jimp/plugins/plugin-contain
> eslint .
+73
View File
@@ -0,0 +1,73 @@
> @jimp/plugin-contain@1.1.1 test:browser /Users/andrewlisowski/Documents/jimp/plugins/plugin-contain
> vitest --config vitest.config.browser.mjs "--watch=false" "--u"
 RUN  v1.4.0 /Users/andrewlisowski/Documents/jimp/plugins/plugin-contain
 Browser runner started at http://localhost:5174/
[?25l · All align combinations for contain (18)
· vertical contain aligned to LEFT TOP
· horizontal contain aligned to LEFT TOP
· vertical contain aligned to CENTER TOP
· horizontal contain aligned to CENTER TOP
· vertical contain aligned to RIGHT TOP
· horizontal contain aligned to RIGHT TOP
· vertical contain aligned to LEFT MIDDLE
· horizontal contain aligned to LEFT MIDDLE
· vertical contain aligned to CENTER MIDDLE
· horizontal contain aligned to CENTER MIDDLE
· vertical contain aligned to RIGHT MIDDLE
· horizontal contain aligned to RIGHT MIDDLE
· vertical contain aligned to LEFT BOTTOM
· horizontal contain aligned to LEFT BOTTOM
· vertical contain aligned to CENTER BOTTOM
· horizontal contain aligned to CENTER BOTTOM
· vertical contain aligned to RIGHT BOTTOM
· horizontal contain aligned to RIGHT BOTTOM
[?25l ✓ All align combinations for contain (18)
✓ vertical contain aligned to LEFT TOP
✓ horizontal contain aligned to LEFT TOP
✓ vertical contain aligned to CENTER TOP
✓ horizontal contain aligned to CENTER TOP
✓ vertical contain aligned to RIGHT TOP
✓ horizontal contain aligned to RIGHT TOP
✓ vertical contain aligned to LEFT MIDDLE
✓ horizontal contain aligned to LEFT MIDDLE
✓ vertical contain aligned to CENTER MIDDLE
✓ horizontal contain aligned to CENTER MIDDLE
✓ vertical contain aligned to RIGHT MIDDLE
✓ horizontal contain aligned to RIGHT MIDDLE
✓ vertical contain aligned to LEFT BOTTOM
✓ horizontal contain aligned to LEFT BOTTOM
✓ vertical contain aligned to CENTER BOTTOM
✓ horizontal contain aligned to CENTER BOTTOM
✓ vertical contain aligned to RIGHT BOTTOM
✓ horizontal contain aligned to RIGHT BOTTOM
 ✓ src/index.test.ts (18)
✓ All align combinations for contain (18)
✓ vertical contain aligned to LEFT TOP
✓ horizontal contain aligned to LEFT TOP
✓ vertical contain aligned to CENTER TOP
✓ horizontal contain aligned to CENTER TOP
✓ vertical contain aligned to RIGHT TOP
✓ horizontal contain aligned to RIGHT TOP
✓ vertical contain aligned to LEFT MIDDLE
✓ horizontal contain aligned to LEFT MIDDLE
✓ vertical contain aligned to CENTER MIDDLE
✓ horizontal contain aligned to CENTER MIDDLE
✓ vertical contain aligned to RIGHT MIDDLE
✓ horizontal contain aligned to RIGHT MIDDLE
✓ vertical contain aligned to LEFT BOTTOM
✓ horizontal contain aligned to LEFT BOTTOM
✓ vertical contain aligned to CENTER BOTTOM
✓ horizontal contain aligned to CENTER BOTTOM
✓ vertical contain aligned to RIGHT BOTTOM
✓ horizontal contain aligned to RIGHT BOTTOM
 Test Files  1 passed (1)
 Tests  18 passed (18)
 Start at  00:42:17
 Duration  1.14s (transform 0ms, setup 0ms, collect 267ms, tests 8ms, environment 0ms, prepare 0ms)
[?25h[?25h
+2
View File
@@ -0,0 +1,2 @@

+52
View File
@@ -0,0 +1,52 @@
# v1.1.3 (Mon Sep 02 2024)
#### 🐛 Bug Fix
- Update deps [#1319](https://github.com/jimp-dev/jimp/pull/1319) ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
---
# v1.1.0 (Sun Sep 01 2024)
#### ⚠️ Pushed to `main`
- upgrade tshy ([@hipstersmoothie](https://github.com/hipstersmoothie))
- update more docs ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
---
# v1.0.3 (Sat Aug 31 2024)
#### 🐛 Bug Fix
- Fix build [#1303](https://github.com/jimp-dev/jimp/pull/1303) ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### ⚠️ Pushed to `main`
- add clean script ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
---
# v1.0.2 (Sat Aug 31 2024)
#### ⚠️ Pushed to `main`
- set side effects ([@hipstersmoothie](https://github.com/hipstersmoothie))
- fix versions ([@hipstersmoothie](https://github.com/hipstersmoothie))
- add publish config ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Oliver Moran
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+8
View File
@@ -0,0 +1,8 @@
<div align="center">
<img width="200" height="200"
src="https://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-11/256/crayon.png">
<h1>@jimp/plugin-contain</h1>
<p>Contain an image within a height and width.</p>
</div>
- [contain](http://jimp-dev.github.io/jimp/api/jimp/classes/jimp#contain)
+44
View File
@@ -0,0 +1,44 @@
import { JimpClass } from "@jimp/types";
import { ResizeStrategy } from "@jimp/plugin-resize";
import { z } from "zod";
declare const ContainOptionsSchema: z.ZodObject<{
/** the width to resize the image to */
w: z.ZodNumber;
/** the height to resize the image to */
h: z.ZodNumber;
/** A bitmask for horizontal and vertical alignment */
align: z.ZodOptional<z.ZodNumber>;
/** a scaling method (e.g. Jimp.RESIZE_BEZIER) */
mode: z.ZodOptional<z.ZodNativeEnum<typeof ResizeStrategy>>;
}, "strip", z.ZodTypeAny, {
w: number;
h: number;
align?: number | undefined;
mode?: ResizeStrategy | undefined;
}, {
w: number;
h: number;
align?: number | undefined;
mode?: ResizeStrategy | undefined;
}>;
export type ContainOptions = z.infer<typeof ContainOptionsSchema>;
export declare const methods: {
/**
* Scale the image to the given width and height keeping the aspect ratio. Some parts of the image may be letter boxed.
* @param w the width to resize the image to
* @param h the height to resize the image to
* @param align A bitmask for horizontal and vertical alignment
* @param mode a scaling method (e.g. Jimp.RESIZE_BEZIER)
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.contain({ w: 150, h: 100 });
* ```
*/
contain<I extends JimpClass>(image: I, options: ContainOptions): I;
};
export {};
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,cAAc,EAA4B,MAAM,qBAAqB,CAAC;AAE/E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,oBAAoB;IACxB,uCAAuC;;IAEvC,wCAAwC;;IAExC,sDAAsD;;IAEtD,iDAAiD;;;;;;;;;;;;EAEjD,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;;;OAcG;YACK,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,cAAc;CA6C/D,CAAC"}
+62
View File
@@ -0,0 +1,62 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.methods = void 0;
const core_1 = require("@jimp/core");
const utils_1 = require("@jimp/utils");
const plugin_resize_1 = require("@jimp/plugin-resize");
const plugin_blit_1 = require("@jimp/plugin-blit");
const zod_1 = require("zod");
const ContainOptionsSchema = zod_1.z.object({
/** the width to resize the image to */
w: zod_1.z.number(),
/** the height to resize the image to */
h: zod_1.z.number(),
/** A bitmask for horizontal and vertical alignment */
align: zod_1.z.number().optional(),
/** a scaling method (e.g. Jimp.RESIZE_BEZIER) */
mode: zod_1.z.nativeEnum(plugin_resize_1.ResizeStrategy).optional(),
});
exports.methods = {
/**
* Scale the image to the given width and height keeping the aspect ratio. Some parts of the image may be letter boxed.
* @param w the width to resize the image to
* @param h the height to resize the image to
* @param align A bitmask for horizontal and vertical alignment
* @param mode a scaling method (e.g. Jimp.RESIZE_BEZIER)
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.contain({ w: 150, h: 100 });
* ```
*/
contain(image, options) {
const { w, h, align = core_1.HorizontalAlign.CENTER | core_1.VerticalAlign.MIDDLE, mode, } = ContainOptionsSchema.parse(options);
const hbits = align & ((1 << 3) - 1);
const vbits = align >> 3;
// check if more flags than one is in the bit sets
if (!((hbits !== 0 && !(hbits & (hbits - 1))) ||
(vbits !== 0 && !(vbits & (vbits - 1))))) {
throw new Error("only use one flag per alignment direction");
}
const alignH = hbits >> 1; // 0, 1, 2
const alignV = vbits >> 1; // 0, 1, 2
const f = w / h > image.bitmap.width / image.bitmap.height
? h / image.bitmap.height
: w / image.bitmap.width;
const c = plugin_resize_1.methods.scale((0, utils_1.clone)(image), { f, mode });
image = plugin_resize_1.methods.resize(image, { w, h, mode });
image.scan((_, __, idx) => {
image.bitmap.data.writeUInt32BE(image.background, idx);
});
image = plugin_blit_1.methods.blit(image, {
src: c,
x: ((image.bitmap.width - c.bitmap.width) / 2) * alignH,
y: ((image.bitmap.height - c.bitmap.height) / 2) * alignV,
});
return image;
},
};
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,qCAA4D;AAC5D,uCAAoC;AACpC,uDAA+E;AAC/E,mDAA2D;AAC3D,6BAAwB;AAExB,MAAM,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;IACpC,uCAAuC;IACvC,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE;IACb,wCAAwC;IACxC,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE;IACb,sDAAsD;IACtD,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,iDAAiD;IACjD,IAAI,EAAE,OAAC,CAAC,UAAU,CAAC,8BAAc,CAAC,CAAC,QAAQ,EAAE;CAC9C,CAAC,CAAC;AAIU,QAAA,OAAO,GAAG;IACrB;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAsB,KAAQ,EAAE,OAAuB;QAC5D,MAAM,EACJ,CAAC,EACD,CAAC,EACD,KAAK,GAAG,sBAAe,CAAC,MAAM,GAAG,oBAAa,CAAC,MAAM,EACrD,IAAI,GACL,GAAG,oBAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAExC,MAAM,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,KAAK,IAAI,CAAC,CAAC;QAEzB,kDAAkD;QAClD,IACE,CAAC,CACC,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;YACvC,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CACxC,EACD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;QAED,MAAM,MAAM,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU;QACrC,MAAM,MAAM,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU;QAErC,MAAM,CAAC,GACL,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM;YAC9C,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM;YACzB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;QAE7B,MAAM,CAAC,GAAG,uBAAa,CAAC,KAAK,CAAC,IAAA,aAAK,EAAC,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAEzD,KAAK,GAAG,uBAAa,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAEpD,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;YACxB,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QAEH,KAAK,GAAG,qBAAW,CAAC,IAAI,CAAC,KAAK,EAAE;YAC9B,GAAG,EAAE,CAAC;YACN,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM;YACvD,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM;SAC1D,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
+44
View File
@@ -0,0 +1,44 @@
import { JimpClass } from "@jimp/types";
import { ResizeStrategy } from "@jimp/plugin-resize";
import { z } from "zod";
declare const ContainOptionsSchema: z.ZodObject<{
/** the width to resize the image to */
w: z.ZodNumber;
/** the height to resize the image to */
h: z.ZodNumber;
/** A bitmask for horizontal and vertical alignment */
align: z.ZodOptional<z.ZodNumber>;
/** a scaling method (e.g. Jimp.RESIZE_BEZIER) */
mode: z.ZodOptional<z.ZodNativeEnum<typeof ResizeStrategy>>;
}, "strip", z.ZodTypeAny, {
w: number;
h: number;
align?: number | undefined;
mode?: ResizeStrategy | undefined;
}, {
w: number;
h: number;
align?: number | undefined;
mode?: ResizeStrategy | undefined;
}>;
export type ContainOptions = z.infer<typeof ContainOptionsSchema>;
export declare const methods: {
/**
* Scale the image to the given width and height keeping the aspect ratio. Some parts of the image may be letter boxed.
* @param w the width to resize the image to
* @param h the height to resize the image to
* @param align A bitmask for horizontal and vertical alignment
* @param mode a scaling method (e.g. Jimp.RESIZE_BEZIER)
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.contain({ w: 150, h: 100 });
* ```
*/
contain<I extends JimpClass>(image: I, options: ContainOptions): I;
};
export {};
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,cAAc,EAA4B,MAAM,qBAAqB,CAAC;AAE/E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,oBAAoB;IACxB,uCAAuC;;IAEvC,wCAAwC;;IAExC,sDAAsD;;IAEtD,iDAAiD;;;;;;;;;;;;EAEjD,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;;;OAcG;YACK,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,cAAc;CA6C/D,CAAC"}
+59
View File
@@ -0,0 +1,59 @@
import { HorizontalAlign, VerticalAlign } from "@jimp/core";
import { clone } from "@jimp/utils";
import { ResizeStrategy, methods as resizeMethods } from "@jimp/plugin-resize";
import { methods as blitMethods } from "@jimp/plugin-blit";
import { z } from "zod";
const ContainOptionsSchema = z.object({
/** the width to resize the image to */
w: z.number(),
/** the height to resize the image to */
h: z.number(),
/** A bitmask for horizontal and vertical alignment */
align: z.number().optional(),
/** a scaling method (e.g. Jimp.RESIZE_BEZIER) */
mode: z.nativeEnum(ResizeStrategy).optional(),
});
export const methods = {
/**
* Scale the image to the given width and height keeping the aspect ratio. Some parts of the image may be letter boxed.
* @param w the width to resize the image to
* @param h the height to resize the image to
* @param align A bitmask for horizontal and vertical alignment
* @param mode a scaling method (e.g. Jimp.RESIZE_BEZIER)
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.contain({ w: 150, h: 100 });
* ```
*/
contain(image, options) {
const { w, h, align = HorizontalAlign.CENTER | VerticalAlign.MIDDLE, mode, } = ContainOptionsSchema.parse(options);
const hbits = align & ((1 << 3) - 1);
const vbits = align >> 3;
// check if more flags than one is in the bit sets
if (!((hbits !== 0 && !(hbits & (hbits - 1))) ||
(vbits !== 0 && !(vbits & (vbits - 1))))) {
throw new Error("only use one flag per alignment direction");
}
const alignH = hbits >> 1; // 0, 1, 2
const alignV = vbits >> 1; // 0, 1, 2
const f = w / h > image.bitmap.width / image.bitmap.height
? h / image.bitmap.height
: w / image.bitmap.width;
const c = resizeMethods.scale(clone(image), { f, mode });
image = resizeMethods.resize(image, { w, h, mode });
image.scan((_, __, idx) => {
image.bitmap.data.writeUInt32BE(image.background, idx);
});
image = blitMethods.blit(image, {
src: c,
x: ((image.bitmap.width - c.bitmap.width) / 2) * alignH,
y: ((image.bitmap.height - c.bitmap.height) / 2) * alignV,
});
return image;
},
};
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"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"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "module"
}
+2
View File
@@ -0,0 +1,2 @@
import shared from "@jimp/config-eslint/base.js";
export default [...shared];
+69
View File
@@ -0,0 +1,69 @@
{
"name": "@jimp/plugin-contain",
"version": "1.6.0",
"repository": "jimp-dev/jimp",
"engines": {
"node": ">=18"
},
"scripts": {
"lint": "eslint .",
"test": "vitest",
"test:browser": "vitest --config vitest.config.browser.mjs",
"build": "tshy",
"dev": "tshy --watch",
"clean": "rm -rf node_modules .tshy .tshy-build dist .turbo"
},
"author": "Andrew Lisowski <lisowski54@gmail.com>",
"license": "MIT",
"dependencies": {
"@jimp/core": "1.6.0",
"@jimp/plugin-blit": "1.6.0",
"@jimp/plugin-resize": "1.6.0",
"@jimp/types": "1.6.0",
"@jimp/utils": "1.6.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@jimp/config-eslint": "1.6.0",
"@jimp/config-typescript": "1.6.0",
"@jimp/config-vitest": "1.6.0",
"@jimp/test-utils": "1.6.0",
"@vitest/browser": "^2.0.5",
"eslint": "^9.9.1",
"tshy": "^3.0.2",
"typescript": "^5.5.4",
"vite-plugin-node-polyfills": "^0.22.0",
"vitest": "^2.0.5"
},
"tshy": {
"exclude": [
"**/*.test.ts"
],
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"type": "module",
"publishConfig": {
"access": "public"
},
"sideEffects": false,
"module": "./dist/esm/index.js",
"gitHead": "c88abe6046dccbdb6e4f5f00c3dd403c81d83515"
}
+361
View File
@@ -0,0 +1,361 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`All align combinations for contain > horizontal contain aligned to CENTER BOTTOM 1`] = `
Visualization:
▴▴▴▸▸▸
▴▴▴▸▸▸
▾▾▾◆◆◆
▾▾▾◆◆◆
Data:
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for contain > horizontal contain aligned to CENTER MIDDLE 1`] = `
Visualization:
▴▴▴▸▸▸
▴▴▴▸▸▸
▾▾▾◆◆◆
▾▾▾◆◆◆
Data:
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > horizontal contain aligned to CENTER TOP 1`] = `
Visualization:
▴▴▴▸▸▸
▴▴▴▸▸▸
▾▾▾◆◆◆
▾▾▾◆◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > horizontal contain aligned to LEFT BOTTOM 1`] = `
Visualization:
▴▴▴▸▸▸
▴▴▴▸▸▸
▾▾▾◆◆◆
▾▾▾◆◆◆
Data:
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for contain > horizontal contain aligned to LEFT MIDDLE 1`] = `
Visualization:
▴▴▴▸▸▸
▴▴▴▸▸▸
▾▾▾◆◆◆
▾▾▾◆◆◆
Data:
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > horizontal contain aligned to LEFT TOP 1`] = `
Visualization:
▴▴▴▸▸▸
▴▴▴▸▸▸
▾▾▾◆◆◆
▾▾▾◆◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > horizontal contain aligned to RIGHT BOTTOM 1`] = `
Visualization:
▴▴▴▸▸▸
▴▴▴▸▸▸
▾▾▾◆◆◆
▾▾▾◆◆◆
Data:
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for contain > horizontal contain aligned to RIGHT MIDDLE 1`] = `
Visualization:
▴▴▴▸▸▸
▴▴▴▸▸▸
▾▾▾◆◆◆
▾▾▾◆◆◆
Data:
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > horizontal contain aligned to RIGHT TOP 1`] = `
Visualization:
▴▴▴▸▸▸
▴▴▴▸▸▸
▾▾▾◆◆◆
▾▾▾◆◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > vertical contain aligned to CENTER BOTTOM 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > vertical contain aligned to CENTER MIDDLE 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > vertical contain aligned to CENTER TOP 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰
00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > vertical contain aligned to LEFT BOTTOM 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > vertical contain aligned to LEFT MIDDLE 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > vertical contain aligned to LEFT TOP 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ 00-00-00⁰⁰ 00-00-00⁰⁰
`;
exports[`All align combinations for contain > vertical contain aligned to RIGHT BOTTOM 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
00-00-00⁰⁰ 00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for contain > vertical contain aligned to RIGHT MIDDLE 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
00-00-00⁰⁰ 00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for contain > vertical contain aligned to RIGHT TOP 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
00-00-00⁰⁰ 00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-00⁰⁰ 00-00-00⁰⁰ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
+75
View File
@@ -0,0 +1,75 @@
import { expect, test, describe } from "vitest";
import { makeTestImage } from "@jimp/test-utils";
import { HorizontalAlign, VerticalAlign, createJimp } from "@jimp/core";
import { methods } from "./index.js";
const jimp = createJimp({ plugins: [methods] });
describe("All align combinations for contain", () => {
const vertical = jimp.fromBitmap(
makeTestImage(
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
),
);
// stores the Jimp instances of the JGD images above.
const horizontal = jimp.fromBitmap(
makeTestImage(
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▾▾▾▾▾▾◆◆◆◆◆◆",
"▾▾▾▾▾▾◆◆◆◆◆◆",
"▾▾▾▾▾▾◆◆◆◆◆◆",
"▾▾▾▾▾▾◆◆◆◆◆◆",
),
);
const tests: Array<
[keyof typeof HorizontalAlign, keyof typeof VerticalAlign]
> = [
["LEFT", "TOP"],
["CENTER", "TOP"],
["RIGHT", "TOP"],
["LEFT", "MIDDLE"],
["CENTER", "MIDDLE"],
["RIGHT", "MIDDLE"],
["LEFT", "BOTTOM"],
["CENTER", "BOTTOM"],
["RIGHT", "BOTTOM"],
];
tests.forEach(([horizontalAlign, verticalAlign]) => {
const align = horizontalAlign + " " + verticalAlign;
const alignValue =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(HorizontalAlign as any)[horizontalAlign] |
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(VerticalAlign as any)[verticalAlign];
test("vertical contain aligned to " + align, () => {
expect(
vertical.clone().contain({ w: 6, h: 6, align: alignValue }),
).toMatchSnapshot();
});
test("horizontal contain aligned to " + align, () => {
expect(
horizontal.clone().contain({ w: 6, h: 6, align: alignValue }),
).toMatchSnapshot();
});
});
});
+82
View File
@@ -0,0 +1,82 @@
import { JimpClass } from "@jimp/types";
import { HorizontalAlign, VerticalAlign } from "@jimp/core";
import { clone } from "@jimp/utils";
import { ResizeStrategy, methods as resizeMethods } from "@jimp/plugin-resize";
import { methods as blitMethods } from "@jimp/plugin-blit";
import { z } from "zod";
const ContainOptionsSchema = z.object({
/** the width to resize the image to */
w: z.number(),
/** the height to resize the image to */
h: z.number(),
/** A bitmask for horizontal and vertical alignment */
align: z.number().optional(),
/** a scaling method (e.g. Jimp.RESIZE_BEZIER) */
mode: z.nativeEnum(ResizeStrategy).optional(),
});
export type ContainOptions = z.infer<typeof ContainOptionsSchema>;
export const methods = {
/**
* Scale the image to the given width and height keeping the aspect ratio. Some parts of the image may be letter boxed.
* @param w the width to resize the image to
* @param h the height to resize the image to
* @param align A bitmask for horizontal and vertical alignment
* @param mode a scaling method (e.g. Jimp.RESIZE_BEZIER)
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.contain({ w: 150, h: 100 });
* ```
*/
contain<I extends JimpClass>(image: I, options: ContainOptions) {
const {
w,
h,
align = HorizontalAlign.CENTER | VerticalAlign.MIDDLE,
mode,
} = ContainOptionsSchema.parse(options);
const hbits = align & ((1 << 3) - 1);
const vbits = align >> 3;
// check if more flags than one is in the bit sets
if (
!(
(hbits !== 0 && !(hbits & (hbits - 1))) ||
(vbits !== 0 && !(vbits & (vbits - 1)))
)
) {
throw new Error("only use one flag per alignment direction");
}
const alignH = hbits >> 1; // 0, 1, 2
const alignV = vbits >> 1; // 0, 1, 2
const f =
w / h > image.bitmap.width / image.bitmap.height
? h / image.bitmap.height
: w / image.bitmap.width;
const c = resizeMethods.scale(clone(image), { f, mode });
image = resizeMethods.resize(image, { w, h, mode });
image.scan((_, __, idx) => {
image.bitmap.data.writeUInt32BE(image.background, idx);
});
image = blitMethods.blit(image, {
src: c,
x: ((image.bitmap.width - c.bitmap.width) / 2) * alignH,
y: ((image.bitmap.height - c.bitmap.height) / 2) * alignV,
});
return image;
},
};
+6
View File
@@ -0,0 +1,6 @@
{
"extends": "@jimp/config-typescript/base.json",
"compilerOptions": {
"outDir": "dist"
}
}
+3
View File
@@ -0,0 +1,3 @@
import config from "@jimp/config-vitest/browser";
export default config;