@hellkite/pipkin 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.
- package/build/src/lib/bundler.d.ts +1 -2
- package/build/src/lib/bundler.js.map +1 -1
- package/build/src/lib/replacement.d.ts +1 -2
- package/build/src/lib/replacement.js.map +1 -1
- package/build/src/lib/template.d.ts +13 -14
- package/build/src/lib/template.js +102 -37
- package/build/src/lib/template.js.map +1 -1
- package/build/src/lib/types/2d.d.ts +4 -5
- package/build/src/lib/types/boundingBox.d.ts +19 -0
- package/build/src/lib/types/boundingBox.js +3 -0
- package/build/src/lib/types/boundingBox.js.map +1 -0
- package/build/src/lib/types/containers.d.ts +13 -27
- package/build/src/lib/types/containers.js +3 -2
- package/build/src/lib/types/containers.js.map +1 -1
- package/build/src/lib/types/css.d.ts +4 -1
- package/build/src/lib/types/css.js +6 -3
- package/build/src/lib/types/css.js.map +1 -1
- package/build/src/lib/types/image.d.ts +17 -38
- package/build/src/lib/types/image.js +8 -2
- package/build/src/lib/types/image.js.map +1 -1
- package/build/src/lib/types/index.d.ts +3 -2
- package/build/src/lib/types/index.js +3 -2
- package/build/src/lib/types/index.js.map +1 -1
- package/build/src/lib/types/layer.d.ts +15 -0
- package/build/src/lib/types/layer.js +3 -0
- package/build/src/lib/types/layer.js.map +1 -0
- package/build/src/lib/types/position.d.ts +21 -0
- package/build/src/lib/types/position.js +42 -0
- package/build/src/lib/types/position.js.map +1 -0
- package/build/src/lib/types/scale.d.ts +9 -1
- package/build/src/lib/types/scale.js +2 -0
- package/build/src/lib/types/scale.js.map +1 -1
- package/build/src/lib/types/size.d.ts +4 -0
- package/build/src/lib/types/size.js +3 -0
- package/build/src/lib/types/size.js.map +1 -0
- package/build/src/lib/types/text.d.ts +29 -33
- package/build/src/lib/types/text.js +13 -4
- package/build/src/lib/types/text.js.map +1 -1
- package/build/src/lib/utils/buildFontString.d.ts +2 -2
- package/build/src/lib/utils/buildFontString.js.map +1 -1
- package/build/src/lib/utils/canvasToImage.d.ts +1 -1
- package/build/src/lib/utils/container.d.ts +4 -4
- package/build/src/lib/utils/container.js +52 -46
- package/build/src/lib/utils/container.js.map +1 -1
- package/build/src/lib/utils/drawBoundingBox.d.ts +1 -2
- package/build/src/lib/utils/drawBoundingBox.js +7 -47
- package/build/src/lib/utils/drawBoundingBox.js.map +1 -1
- package/build/src/lib/utils/htmlToImage.d.ts +3 -0
- package/build/src/lib/utils/htmlToImage.js +36 -0
- package/build/src/lib/utils/htmlToImage.js.map +1 -0
- package/build/src/lib/utils/index.d.ts +2 -1
- package/build/src/lib/utils/index.js +2 -1
- package/build/src/lib/utils/index.js.map +1 -1
- package/build/src/lib/utils/placeImage.d.ts +10 -5
- package/build/src/lib/utils/placeImage.js +25 -36
- package/build/src/lib/utils/placeImage.js.map +1 -1
- package/build/src/lib/utils/renderText.d.ts +3 -2
- package/build/src/lib/utils/renderText.js +12 -39
- package/build/src/lib/utils/renderText.js.map +1 -1
- package/build/src/lib/utils/toPx.d.ts +3 -0
- package/build/src/lib/utils/toPx.js +12 -0
- package/build/src/lib/utils/toPx.js.map +1 -0
- package/build/src/lib/utils/vNodeToImage.d.ts +4 -0
- package/build/src/lib/utils/vNodeToImage.js +36 -0
- package/build/src/lib/utils/vNodeToImage.js.map +1 -0
- package/build/src/test.js +55 -69
- package/build/src/test.js.map +1 -1
- package/package.json +6 -3
- package/roadmap.md +0 -1
- package/src/lib/bundler.ts +1 -2
- package/src/lib/replacement.ts +1 -2
- package/src/lib/template.ts +190 -68
- package/src/lib/types/boundingBox.ts +28 -0
- package/src/lib/types/containers.ts +55 -60
- package/src/lib/types/css.ts +32 -1
- package/src/lib/types/image.ts +32 -57
- package/src/lib/types/index.ts +3 -2
- package/src/lib/types/layer.ts +18 -0
- package/src/lib/types/scale.ts +11 -0
- package/src/lib/types/size.ts +4 -0
- package/src/lib/types/text.ts +47 -56
- package/src/lib/utils/buildFontString.ts +2 -2
- package/src/lib/utils/container.ts +118 -57
- package/src/lib/utils/drawBoundingBox.ts +19 -16
- package/src/lib/utils/htmlToImage.ts +24 -0
- package/src/lib/utils/index.ts +2 -1
- package/src/lib/utils/placeImage.ts +55 -58
- package/src/lib/utils/renderText.ts +19 -43
- package/src/lib/utils/toPx.ts +11 -0
- package/src/lib/types/2d.ts +0 -11
- package/src/lib/types/omitArgument.ts +0 -17
- package/src/lib/utils/canvasToImage.ts +0 -19
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { JustifyContent, AlignItems } from "./css";
|
|
2
|
+
export type LayerOptions<EntryType extends Record<string, string>> = {
|
|
3
|
+
/**
|
|
4
|
+
* default `center`
|
|
5
|
+
*/
|
|
6
|
+
justifyContent?: JustifyContent;
|
|
7
|
+
/**
|
|
8
|
+
* default `center`
|
|
9
|
+
*/
|
|
10
|
+
alignItems?: AlignItems;
|
|
11
|
+
/**
|
|
12
|
+
* Decides if a layer should be rendered or not for a certain entry
|
|
13
|
+
*/
|
|
14
|
+
skip?: boolean | ((entry: EntryType) => boolean);
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer.js","sourceRoot":"","sources":["../../../../src/lib/types/layer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BoundingBox, Size } from './2d';
|
|
2
|
+
export type Position = ({
|
|
3
|
+
top: number;
|
|
4
|
+
height: number;
|
|
5
|
+
} | {
|
|
6
|
+
bottom: number;
|
|
7
|
+
height: number;
|
|
8
|
+
} | {
|
|
9
|
+
top: number;
|
|
10
|
+
bottom: number;
|
|
11
|
+
}) & ({
|
|
12
|
+
left: number;
|
|
13
|
+
width: number;
|
|
14
|
+
} | {
|
|
15
|
+
right: number;
|
|
16
|
+
width: number;
|
|
17
|
+
} | {
|
|
18
|
+
left: number;
|
|
19
|
+
right: number;
|
|
20
|
+
});
|
|
21
|
+
export declare const toBoundingBox: (position: Position, backgroundSize: Size) => BoundingBox;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toBoundingBox = void 0;
|
|
4
|
+
const toBoundingBox = (position, backgroundSize) => {
|
|
5
|
+
const box = {
|
|
6
|
+
x: 0,
|
|
7
|
+
y: 0,
|
|
8
|
+
width: 0,
|
|
9
|
+
height: 0,
|
|
10
|
+
};
|
|
11
|
+
if ('height' in position) {
|
|
12
|
+
if ('top' in position) {
|
|
13
|
+
box.y = position.top;
|
|
14
|
+
box.height = position.height;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
box.y = backgroundSize.height - position.bottom - position.height;
|
|
18
|
+
box.height = position.height;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
box.y = position.top;
|
|
23
|
+
box.height = position.bottom - position.top;
|
|
24
|
+
}
|
|
25
|
+
if ('width' in position) {
|
|
26
|
+
if ('left' in position) {
|
|
27
|
+
box.x = position.left;
|
|
28
|
+
box.width = position.width;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
box.x = backgroundSize.width - position.right - position.width;
|
|
32
|
+
box.width = position.width;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
box.x = position.left;
|
|
37
|
+
box.width = position.right - position.left;
|
|
38
|
+
}
|
|
39
|
+
return box;
|
|
40
|
+
};
|
|
41
|
+
exports.toBoundingBox = toBoundingBox;
|
|
42
|
+
//# sourceMappingURL=position.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"position.js","sourceRoot":"","sources":["../../../../src/lib/types/position.ts"],"names":[],"mappings":";;;AA+BO,MAAM,aAAa,GAAG,CACzB,QAAkB,EAClB,cAAoB,EACT,EAAE;IACb,MAAM,GAAG,GAAgB;QACrB,CAAC,EAAE,CAAC;QACJ,CAAC,EAAE,CAAC;QACJ,KAAK,EAAE,CAAC;QACR,MAAM,E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 -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Behavior of the content around a space
|
|
3
|
+
* that is bigger or smaller than necessary
|
|
4
|
+
* -> `none`: no scaling
|
|
5
|
+
* -> `keep-ration`: scale while preserving aspect ration
|
|
6
|
+
* -> `stretch`: scale without preserving aspect ration
|
|
7
|
+
*/
|
|
8
|
+
export type ScaleMode = 'none' | 'keep-ratio' | 'stretch';
|
|
9
|
+
export declare const DEFAULT_SCALE_MODE: ScaleMode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scale.js","sourceRoot":"","sources":["../../../../src/lib/types/scale.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"scale.js","sourceRoot":"","sources":["../../../../src/lib/types/scale.ts"],"names":[],"mappings":";;;AAUa,QAAA,kBAAkB,GAAc,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.js","sourceRoot":"","sources":["../../../../src/lib/types/size.ts"],"names":[],"mappings":""}
|
|
@@ -1,40 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RequiredDeep } from 'type-fest';
|
|
2
|
+
import { LayerOptions } from './layer';
|
|
2
3
|
import { ReplacementMap } from './replacement';
|
|
3
|
-
export type
|
|
4
|
-
key:
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export type TextRef<EntryType> = {
|
|
5
|
+
key: string;
|
|
6
|
+
} | {
|
|
7
|
+
text: string;
|
|
8
|
+
} | {
|
|
9
|
+
textFn: (entry: EntryType) => string;
|
|
7
10
|
};
|
|
8
|
-
export type
|
|
9
|
-
font?: {
|
|
10
|
-
/**
|
|
11
|
-
* Size of font is represented in pixels
|
|
12
|
-
*/
|
|
13
|
-
size?: number;
|
|
14
|
-
/**
|
|
15
|
-
* Either use one supported by canvas
|
|
16
|
-
* or load a custom one before rendering
|
|
17
|
-
*/
|
|
18
|
-
family?: string;
|
|
19
|
-
/**
|
|
20
|
-
* Warning: Not supported by all fonts
|
|
21
|
-
*/
|
|
22
|
-
bold?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Warning: Not supported by all fonts
|
|
25
|
-
*/
|
|
26
|
-
italic?: boolean;
|
|
27
|
-
};
|
|
28
|
-
color?: string;
|
|
29
|
-
replacement?: ReplacementMap;
|
|
11
|
+
export type FontOptions = {
|
|
30
12
|
/**
|
|
31
|
-
*
|
|
13
|
+
* Size of font is represented in pixels
|
|
32
14
|
*/
|
|
33
|
-
|
|
15
|
+
size?: number;
|
|
34
16
|
/**
|
|
35
|
-
*
|
|
17
|
+
* Either use one supported by canvas
|
|
18
|
+
* or load a custom one before rendering
|
|
36
19
|
*/
|
|
37
|
-
|
|
20
|
+
family?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Warning: Not supported by all fonts
|
|
23
|
+
*/
|
|
24
|
+
bold?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Warning: Not supported by all fonts
|
|
27
|
+
*/
|
|
28
|
+
italic?: boolean;
|
|
29
|
+
};
|
|
30
|
+
export type TextLayerOptions<EntryType extends Record<string, string>> = LayerOptions<EntryType> & {
|
|
31
|
+
font?: FontOptions;
|
|
32
|
+
color?: string;
|
|
33
|
+
replacement?: ReplacementMap;
|
|
38
34
|
};
|
|
39
|
-
export
|
|
40
|
-
export declare const DEFAULT_TEXT_LAYER_OPTIONS: TextLayerOptions
|
|
35
|
+
export declare const DEFAULT_FONT: Required<FontOptions>;
|
|
36
|
+
export declare const DEFAULT_TEXT_LAYER_OPTIONS: RequiredDeep<TextLayerOptions<Record<string, string>>>;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_TEXT_LAYER_OPTIONS = void 0;
|
|
4
|
-
|
|
3
|
+
exports.DEFAULT_TEXT_LAYER_OPTIONS = exports.DEFAULT_FONT = void 0;
|
|
4
|
+
exports.DEFAULT_FONT = {
|
|
5
|
+
size: 28,
|
|
6
|
+
family: 'Arial',
|
|
7
|
+
bold: false,
|
|
8
|
+
italic: false,
|
|
9
|
+
};
|
|
5
10
|
exports.DEFAULT_TEXT_LAYER_OPTIONS = {
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
justifyContent: 'center',
|
|
12
|
+
alignItems: 'center',
|
|
13
|
+
font: exports.DEFAULT_FONT,
|
|
14
|
+
color: 'black',
|
|
15
|
+
replacement: {},
|
|
16
|
+
skip: false,
|
|
8
17
|
};
|
|
9
18
|
//# sourceMappingURL=text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../../src/lib/types/text.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../../src/lib/types/text.ts"],"names":[],"mappings":";;;AAuCa,QAAA,YAAY,GAErB;IACA,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,OAAO;IACf,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,KAAK;CAChB,CAAC;AAEW,QAAA,0BAA0B,GAEnC;IACA,cAAc,EAAE,QAAQ;IACxB,UAAU,EAAE,QAAQ;IACpB,IAAI,EAAE,oBAAY;IAClB,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,EAAE;IACf,IAAI,EAAE,KAAK;CACd,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const buildFontString: (font:
|
|
1
|
+
import { FontOptions } from "../types";
|
|
2
|
+
export declare const buildFontString: (font: FontOptions, defaultFontFamily?: string) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFontString.js","sourceRoot":"","sources":["../../../../src/lib/utils/buildFontString.ts"],"names":[],"mappings":";;;AAEO,MAAM,eAAe,GAAG,CAC3B,
|
|
1
|
+
{"version":3,"file":"buildFontString.js","sourceRoot":"","sources":["../../../../src/lib/utils/buildFontString.ts"],"names":[],"mappings":";;;AAEO,MAAM,eAAe,GAAG,CAC3B,IAAiB,EACjB,iBAA0B,EACpB,EAAE;;IACR,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAAE,CAAC;QACb,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,EAAE,CAAC;QACf,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IACD,SAAS,CAAC,IAAI,CAAC,GAAG,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,mCAAI,EAAE,IAAI,CAAC,CAAC;IACxC,SAAS,CAAC,IAAI,CAAC,IAAI,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,mCAAI,iBAAiB,mCAAI,OAAO,GAAG,CAAC,CAAC;IACpE,OAAO,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/B,CAAC,CAAC;AAdW,QAAA,eAAe,mBAc1B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
1
|
+
import { DirectionContainerOptions, PackingFn, GridContainerOptions } from '../types';
|
|
2
|
+
export declare const vboxPackingFn: <EntryType extends Record<string, string>>(options?: DirectionContainerOptions<EntryType>) => PackingFn;
|
|
3
|
+
export declare const hboxPackingFn: <EntryType extends Record<string, string>>(options?: DirectionContainerOptions<EntryType>) => PackingFn;
|
|
4
|
+
export declare const gridPackingFn: <EntryType extends Record<string, string>>(options?: GridContainerOptions<EntryType>) => PackingFn;
|
|
@@ -12,31 +12,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.hboxPackingFn = exports.vboxPackingFn = void 0;
|
|
16
|
-
const containers_1 = require("../types/containers");
|
|
15
|
+
exports.gridPackingFn = exports.hboxPackingFn = exports.vboxPackingFn = void 0;
|
|
17
16
|
const virtual_dom_1 = require("virtual-dom");
|
|
18
|
-
const node_html_to_image_1 = __importDefault(require("node-html-to-image"));
|
|
19
|
-
const jimp_1 = require("jimp");
|
|
20
17
|
const types_1 = require("../types");
|
|
21
|
-
const
|
|
18
|
+
const toPx_1 = require("./toPx");
|
|
19
|
+
const lodash_merge_1 = __importDefault(require("lodash.merge"));
|
|
20
|
+
const htmlToImage_1 = require("./htmlToImage");
|
|
21
|
+
const lodash_chunk_1 = __importDefault(require("lodash.chunk"));
|
|
22
|
+
const vboxPackingFn = (options) => (box, background, images) => directionalPackingFn({
|
|
22
23
|
isVertical: true,
|
|
23
|
-
background,
|
|
24
|
+
backgroundSize: background,
|
|
24
25
|
images,
|
|
25
|
-
|
|
26
|
+
box,
|
|
26
27
|
options,
|
|
27
28
|
});
|
|
28
29
|
exports.vboxPackingFn = vboxPackingFn;
|
|
29
|
-
const hboxPackingFn = (
|
|
30
|
+
const hboxPackingFn = (options) => (box, background, images) => directionalPackingFn({
|
|
30
31
|
isVertical: false,
|
|
31
|
-
background,
|
|
32
|
+
backgroundSize: background,
|
|
32
33
|
images,
|
|
33
|
-
|
|
34
|
+
box,
|
|
34
35
|
options,
|
|
35
36
|
});
|
|
36
37
|
exports.hboxPackingFn = hboxPackingFn;
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const objectFit = SCALE_MODE_TO_OBJECT_FIT[
|
|
38
|
+
const gridPackingFn = (options) => (box, background, images) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const mergedOptions = (0, lodash_merge_1.default)({}, types_1.DEFAULT_GRID_CONTAINER_OPTIONS, options);
|
|
40
|
+
const objectFit = types_1.SCALE_MODE_TO_OBJECT_FIT[mergedOptions.scale];
|
|
40
41
|
const children = yield Promise.all(images.map((image) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
42
|
const imageBase64 = yield image.getBase64('image/png');
|
|
42
43
|
return (0, virtual_dom_1.h)('img', {
|
|
@@ -51,40 +52,45 @@ const directionalPackingFn = (_a) => __awaiter(void 0, [_a], void 0, function* (
|
|
|
51
52
|
src: imageBase64,
|
|
52
53
|
}, []);
|
|
53
54
|
})));
|
|
55
|
+
const items = [];
|
|
56
|
+
for (const subset of (0, lodash_chunk_1.default)(children)) {
|
|
57
|
+
items.push((0, virtual_dom_1.h)('div', {
|
|
58
|
+
style: {
|
|
59
|
+
display: 'flex',
|
|
60
|
+
flexDirection: 'row',
|
|
61
|
+
overflow: 'hidden',
|
|
62
|
+
gap: (0, toPx_1.toPx)(mergedOptions.gap),
|
|
63
|
+
justifyContent: mergedOptions.justifyContent,
|
|
64
|
+
alignItems: mergedOptions.alignItems,
|
|
65
|
+
},
|
|
66
|
+
}, subset));
|
|
67
|
+
}
|
|
54
68
|
const document = (0, virtual_dom_1.h)('div', {
|
|
55
|
-
style: {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
html: rootNode.toString(),
|
|
74
|
-
transparent: true,
|
|
75
|
-
type: 'png',
|
|
76
|
-
puppeteerArgs: {
|
|
77
|
-
defaultViewport: {
|
|
78
|
-
width: background.width,
|
|
79
|
-
height: background.height,
|
|
69
|
+
style: Object.assign({ display: 'grid', gridTemplateColumns: `repeat(${mergedOptions.size}, 1fr)`, position: 'absolute', gap: (0, toPx_1.toPx)(mergedOptions.gap) }, (0, toPx_1.boundingBoxToPx)(box)),
|
|
70
|
+
}, items);
|
|
71
|
+
return (0, htmlToImage_1.htmlToImage)(document, background);
|
|
72
|
+
});
|
|
73
|
+
exports.gridPackingFn = gridPackingFn;
|
|
74
|
+
const directionalPackingFn = (_a) => __awaiter(void 0, [_a], void 0, function* ({ isVertical, backgroundSize: background, images, box, options, }) {
|
|
75
|
+
const mergedOptions = (0, lodash_merge_1.default)({}, types_1.DEFAULT_DIRECTION_CONTAINER_OPTIONS, options);
|
|
76
|
+
const objectFit = types_1.SCALE_MODE_TO_OBJECT_FIT[mergedOptions.scale];
|
|
77
|
+
const children = yield Promise.all(images.map((image) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
const imageBase64 = yield image.getBase64('image/png');
|
|
79
|
+
return (0, virtual_dom_1.h)('img', {
|
|
80
|
+
style: {
|
|
81
|
+
objectFit,
|
|
82
|
+
flex: '1 1 auto',
|
|
83
|
+
minWidth: 0,
|
|
84
|
+
minHeight: 0,
|
|
85
|
+
maxWidth: '100%',
|
|
86
|
+
maxHeight: '100%',
|
|
80
87
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
src: imageBase64,
|
|
89
|
+
}, []);
|
|
90
|
+
})));
|
|
91
|
+
const document = (0, virtual_dom_1.h)('div', {
|
|
92
|
+
style: Object.assign({ display: 'flex', position: 'absolute', scale: 1, flexDirection: `${isVertical ? 'column' : 'row'}${mergedOptions.reversed ? '-reversed' : ''}`, gap: (0, toPx_1.toPx)(mergedOptions.gap), justifyContent: mergedOptions.justifyContent, alignItems: mergedOptions.alignItems }, (0, toPx_1.boundingBoxToPx)(box)),
|
|
93
|
+
}, children);
|
|
94
|
+
return (0, htmlToImage_1.htmlToImage)(document, background);
|
|
84
95
|
});
|
|
85
|
-
const SCALE_MODE_TO_OBJECT_FIT = {
|
|
86
|
-
'keep-ratio': 'contain',
|
|
87
|
-
stretch: 'fill',
|
|
88
|
-
none: 'none',
|
|
89
|
-
};
|
|
90
96
|
//# sourceMappingURL=container.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../../../src/lib/utils/container.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../../../src/lib/utils/container.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAgC;AAChC,oCAUkB;AAClB,iCAA+C;AAC/C,gEAAiC;AACjC,+CAA4C;AAC5C,gEAAiC;AAE1B,MAAM,aAAa,GACtB,CACI,OAA8C,EACrC,EAAE,CACf,CAAC,GAAgB,EAAE,UAAqB,EAAE,MAAwB,EAAE,EAAE,CAClE,oBAAoB,CAAC;IACjB,UAAU,EAAE,IAAI;IAChB,cAAc,EAAE,UAAU;IAC1B,MAAM;IACN,GAAG;IACH,OAAO;CACV,CAAC,CAAC;AAXE,QAAA,aAAa,iBAWf;AAEJ,MAAM,aAAa,GACtB,CACI,OAA8C,EACrC,EAAE,CACf,CAAC,GAAgB,EAAE,UAAqB,EAAE,MAAwB,EAAE,EAAE,CAClE,oBAAoB,CAAC;IACjB,UAAU,EAAE,KAAK;IACjB,cAAc,EAAE,UAAU;IAC1B,MAAM;IACN,GAAG;IACH,OAAO;CACV,CAAC,CAAC;AAXE,QAAA,aAAa,iBAWf;AAEJ,MAAM,aAAa,GACtB,CACI,OAAyC,EAChC,EAAE,CACf,CACI,GAAgB,EAChB,UAAqB,EACrB,MAAwB,EAC1B,EAAE;IACA,MAAM,aAAa,GAAG,IAAA,sBAAK,EACvB,EAAE,EACF,sCAA8B,EAC9B,OAAO,CACV,CAAC;IACF,MAAM,SAAS,GAAG,gCAAwB,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAEhE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAC9B,MAAM,CAAC,GAAG,CAAC,CAAM,KAAK,EAAC,EAAE;QACrB,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QACvD,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A,CAAC"}
|
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -43,21 +10,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
43
10
|
};
|
|
44
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
12
|
exports.drawBoundingBox = void 0;
|
|
46
|
-
const
|
|
47
|
-
const
|
|
13
|
+
const virtual_dom_1 = require("virtual-dom");
|
|
14
|
+
const htmlToImage_1 = require("./htmlToImage");
|
|
15
|
+
const toPx_1 = require("./toPx");
|
|
48
16
|
const drawBoundingBox = (box, imageSize) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
width: box.width,
|
|
54
|
-
height: box.height,
|
|
55
|
-
stroke: 'red',
|
|
56
|
-
strokeWidth: 2,
|
|
57
|
-
fill: 'transparent',
|
|
58
|
-
});
|
|
59
|
-
fabricCanvas.add(boundingBox);
|
|
60
|
-
return (0, canvasToImage_1.canvasToImage)(fabricCanvas);
|
|
17
|
+
const document = (0, virtual_dom_1.h)('div', {
|
|
18
|
+
style: Object.assign({ position: 'absolute', border: '2px solid red', background: 'transparent', boxSizing: 'border-box' }, (0, toPx_1.boundingBoxToPx)(box)),
|
|
19
|
+
}, []);
|
|
20
|
+
return (0, htmlToImage_1.htmlToImage)(document, imageSize);
|
|
61
21
|
});
|
|
62
22
|
exports.drawBoundingBox = drawBoundingBox;
|
|
63
23
|
//# sourceMappingURL=drawBoundingBox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drawBoundingBox.js","sourceRoot":"","sources":["../../../../src/lib/utils/drawBoundingBox.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"drawBoundingBox.js","sourceRoot":"","sources":["../../../../src/lib/utils/drawBoundingBox.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAgC;AAChC,+CAA4C;AAC5C,iCAAyC;AAGlC,MAAM,eAAe,GAAG,CAC3B,GAAgB,EAChB,SAAe,EACG,EAAE;IACpB,MAAM,QAAQ,GAAG,IAAA,eAAC,EACd,KAAK,EACL;QACI,KAAK,kBACD,QAAQ,EAAE,UAAU,EACpB,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,aAAa,EACzB,SAAS,EAAE,YAAY,IACpB,IAAA,sBAAe,EAAC,GAAG,CAAC,CAC1B;KACJ,EACD,EAAE,CACL,CAAC;IAEF,OAAO,IAAA,yBAAW,EAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAC5C,CAAC,CAAA,CAAC;AAnBW,QAAA,eAAe,mBAmB1B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.htmlToImage = void 0;
|
|
16
|
+
const virtual_dom_1 = require("virtual-dom");
|
|
17
|
+
const node_html_to_image_1 = __importDefault(require("node-html-to-image"));
|
|
18
|
+
const jimp_1 = require("jimp");
|
|
19
|
+
const htmlToImage = (document, backgroundSize) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const html = (0, virtual_dom_1.create)(document).toString();
|
|
21
|
+
const image = yield (0, node_html_to_image_1.default)({
|
|
22
|
+
html,
|
|
23
|
+
transparent: true,
|
|
24
|
+
type: 'png',
|
|
25
|
+
puppeteerArgs: {
|
|
26
|
+
defaultViewport: {
|
|
27
|
+
width: backgroundSize.width,
|
|
28
|
+
height: backgroundSize.height,
|
|
29
|
+
deviceScaleFactor: 1,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return jimp_1.Jimp.read(image);
|
|
34
|
+
});
|
|
35
|
+
exports.htmlToImage = htmlToImage;
|
|
36
|
+
//# sourceMappingURL=htmlToImage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlToImage.js","sourceRoot":"","sources":["../../../../src/lib/utils/htmlToImage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAA6D;AAC7D,4EAAiD;AACjD,+BAA4B;AAGrB,MAAM,WAAW,GAAG,CACvB,QAAe,EACf,cAAoB,EACF,EAAE;IACpB,MAAM,IAAI,GAAG,IAAA,oBAAa,EAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChD,MAAM,KAAK,GAAG,MAAM,IAAA,4BAAe,EAAC;QAChC,IAAI;QACJ,WAAW,EAAE,IAAI;QACjB,IAAI,EAAE,KAAK;QACX,aAAa,EAAE;YACX,eAAe,EAAE;gBACb,KAAK,EAAE,cAAc,CAAC,KAAK;gBAC3B,MAAM,EAAE,cAAc,CAAC,MAAM;gBAC7B,iBAAiB,EAAE,CAAC;aACvB;SACJ;KACJ,CAAC,CAAC;IACH,OAAO,WAAI,CAAC,IAAI,CAAC,KAAe,CAAuB,CAAC;AAC5D,CAAC,CAAA,CAAC;AAlBW,QAAA,WAAW,eAkBtB"}
|
|
@@ -15,9 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./buildFontString"), exports);
|
|
18
|
-
__exportStar(require("./canvasToImage"), exports);
|
|
19
18
|
__exportStar(require("./container"), exports);
|
|
20
19
|
__exportStar(require("./drawBoundingBox"), exports);
|
|
21
20
|
__exportStar(require("./placeImage"), exports);
|
|
22
21
|
__exportStar(require("./renderText"), exports);
|
|
22
|
+
__exportStar(require("./htmlToImage"), exports);
|
|
23
|
+
__exportStar(require("./toPx"), exports);
|
|
23
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,8CAA4B;AAC5B,oDAAkC;AAClC,+CAA6B;AAC7B,+CAA6B;AAC7B,gDAA8B;AAC9B,yCAAuB"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { ImageType,
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ImageLayerOptions, ImageType, BoundingBox } from '../types';
|
|
2
|
+
import { RequiredDeep } from 'type-fest';
|
|
3
|
+
type PlaceImageProps<EntryType extends Record<string, string>> = {
|
|
4
4
|
image: ImageType;
|
|
5
|
-
|
|
5
|
+
box: BoundingBox;
|
|
6
|
+
backgroundSize: {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
options: RequiredDeep<ImageLayerOptions<EntryType>>;
|
|
6
11
|
};
|
|
7
|
-
export declare
|
|
12
|
+
export declare const placeImage: <EntryType extends Record<string, string>>({ image, box, backgroundSize, options, }: PlaceImageProps<EntryType>) => Promise<ImageType>;
|
|
8
13
|
export {};
|