@hellkite/pipkin 0.5.1 → 0.6.1
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/template.d.ts +11 -8
- package/build/src/lib/template.js +54 -22
- package/build/src/lib/template.js.map +1 -1
- package/build/src/lib/types/containers.d.ts +11 -22
- package/build/src/lib/types/containers.js +3 -1
- package/build/src/lib/types/containers.js.map +1 -1
- package/build/src/lib/types/image.d.ts +5 -12
- package/build/src/lib/types/image.js +2 -0
- package/build/src/lib/types/image.js.map +1 -1
- package/build/src/lib/types/index.d.ts +1 -0
- package/build/src/lib/types/index.js +1 -0
- 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/text.d.ts +23 -27
- 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/container.d.ts +4 -3
- package/build/src/lib/utils/container.js +41 -4
- package/build/src/lib/utils/container.js.map +1 -1
- package/build/src/lib/utils/drawBoundingBox.js.map +1 -1
- package/build/src/lib/utils/htmlToImage.js +1 -1
- package/build/src/lib/utils/htmlToImage.js.map +1 -1
- package/build/src/lib/utils/placeImage.d.ts +4 -3
- package/build/src/lib/utils/placeImage.js +22 -28
- package/build/src/lib/utils/placeImage.js.map +1 -1
- package/build/src/lib/utils/renderText.d.ts +2 -1
- package/build/src/lib/utils/renderText.js +21 -12
- package/build/src/lib/utils/renderText.js.map +1 -1
- package/build/src/test.js +14 -5
- package/build/src/test.js.map +1 -1
- package/package.json +4 -1
- package/roadmap.md +6 -4
- package/src/lib/template.ts +137 -32
- package/src/lib/types/containers.ts +52 -46
- package/src/lib/types/image.ts +21 -29
- package/src/lib/types/index.ts +1 -0
- package/src/lib/types/layer.ts +18 -0
- package/src/lib/types/text.ts +44 -49
- package/src/lib/utils/buildFontString.ts +2 -2
- package/src/lib/utils/container.ts +102 -9
- package/src/lib/utils/drawBoundingBox.ts +12 -9
- package/src/lib/utils/htmlToImage.ts +1 -1
- package/src/lib/utils/placeImage.ts +8 -10
- package/src/lib/utils/renderText.ts +33 -21
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
|
-
import { DirectionContainerOptions, ImageLayerOptions, ImageRef, ImageType, PackingFn, BoundingBox, RenderOptions, TextLayerOptions, TextRef } from './types';
|
|
2
|
+
import { DirectionContainerOptions, ImageLayerOptions, ImageRef, ImageType, PackingFn, BoundingBox, RenderOptions, TextLayerOptions, TextRef, GridContainerOptions, ContainerOptions } from './types';
|
|
3
3
|
type RequiredTemplateOptions = {
|
|
4
4
|
height: number;
|
|
5
5
|
width: number;
|
|
@@ -13,9 +13,10 @@ export type TemplateOptions = RequiredTemplateOptions & OptionalTemplateOptions;
|
|
|
13
13
|
export type LayerFnContext = {
|
|
14
14
|
debugMode: boolean;
|
|
15
15
|
};
|
|
16
|
-
export type LayerFn<EntryType> = (entry: EntryType, context: LayerFnContext) => Promise<ImageType>;
|
|
16
|
+
export type LayerFn<EntryType> = (entry: EntryType, context: LayerFnContext) => Promise<ImageType | undefined>;
|
|
17
17
|
export type TemplateLayerFn<EntryType extends Record<string, string>> = (template: Template<EntryType>) => Template<EntryType>;
|
|
18
18
|
export declare class Template<EntryType extends Record<string, string>> {
|
|
19
|
+
private readonly fonts;
|
|
19
20
|
private readonly layers;
|
|
20
21
|
private readonly background;
|
|
21
22
|
private debugMode;
|
|
@@ -28,12 +29,13 @@ export declare class Template<EntryType extends Record<string, string>> {
|
|
|
28
29
|
private get backgroundSize();
|
|
29
30
|
layer(fn: LayerFn<EntryType>): this;
|
|
30
31
|
template: (fn: TemplateLayerFn<EntryType>) => this;
|
|
31
|
-
container: (imagesFn: (entry: EntryType) => Promise<Array<ImageType>>, packingFn: PackingFn) => this;
|
|
32
|
-
hbox: (imagesFn: (entry: EntryType) => Promise<Array<ImageType>>, box: BoundingBox, options?: DirectionContainerOptions) => this;
|
|
33
|
-
vbox: (imagesFn: (entry: EntryType) => Promise<Array<ImageType>>, box: BoundingBox, options?: DirectionContainerOptions) => this;
|
|
34
|
-
|
|
32
|
+
container: (imagesFn: (entry: EntryType) => Promise<Array<ImageType>>, box: BoundingBox, packingFn: PackingFn, options?: ContainerOptions<EntryType>) => this;
|
|
33
|
+
hbox: (imagesFn: (entry: EntryType) => Promise<Array<ImageType>>, box: BoundingBox, options?: DirectionContainerOptions<EntryType>) => this;
|
|
34
|
+
vbox: (imagesFn: (entry: EntryType) => Promise<Array<ImageType>>, box: BoundingBox, options?: DirectionContainerOptions<EntryType>) => this;
|
|
35
|
+
grid: (imagesFn: (entry: EntryType) => Promise<Array<ImageType>>, box: BoundingBox, options?: GridContainerOptions<EntryType>) => this;
|
|
36
|
+
image: (ref: ImageRef<EntryType>, box: BoundingBox, options: ImageLayerOptions<EntryType>) => this;
|
|
35
37
|
loadImage: (imagePath: string | Buffer) => Promise<ImageType>;
|
|
36
|
-
text: (ref: TextRef<EntryType>, box: BoundingBox, options?: TextLayerOptions) => this;
|
|
38
|
+
text: (ref: TextRef<EntryType>, box: BoundingBox, options?: TextLayerOptions<EntryType>) => this;
|
|
37
39
|
font(path: fs.PathLike, name: string): this;
|
|
38
40
|
debug(): this;
|
|
39
41
|
private renderLayers;
|
|
@@ -41,6 +43,7 @@ export declare class Template<EntryType extends Record<string, string>> {
|
|
|
41
43
|
renderAll(entries: Array<EntryType>, options?: RenderOptions<EntryType>): Promise<Array<ImageType>>;
|
|
42
44
|
fromCsv(path: string, options?: RenderOptions<EntryType>): Promise<Array<ImageType>>;
|
|
43
45
|
private pathFromImageRef;
|
|
44
|
-
private
|
|
46
|
+
private textFromTextRef;
|
|
47
|
+
private shouldSkipLayerForEntry;
|
|
45
48
|
}
|
|
46
49
|
export {};
|
|
@@ -51,9 +51,10 @@ const papaparse_1 = require("papaparse");
|
|
|
51
51
|
const jimp_1 = require("jimp");
|
|
52
52
|
const lodash_camelcase_1 = __importDefault(require("lodash.camelcase"));
|
|
53
53
|
const lodash_concat_1 = __importDefault(require("lodash.concat"));
|
|
54
|
-
const canvas_1 = require("canvas");
|
|
55
54
|
const path_1 = __importDefault(require("path"));
|
|
56
55
|
const utils_1 = require("./utils");
|
|
56
|
+
const types_1 = require("./types");
|
|
57
|
+
const lodash_merge_1 = __importDefault(require("lodash.merge"));
|
|
57
58
|
const DEFAULT_TEMPLATE_OPTIONS = {
|
|
58
59
|
height: 1050,
|
|
59
60
|
width: 750,
|
|
@@ -62,26 +63,41 @@ const DEFAULT_TEMPLATE_OPTIONS = {
|
|
|
62
63
|
class Template {
|
|
63
64
|
// disallow constructor initialization
|
|
64
65
|
constructor(options) {
|
|
66
|
+
this.fonts = {};
|
|
65
67
|
this.layers = [];
|
|
66
68
|
this.debugMode = false;
|
|
67
69
|
this.template = (fn) => this.layer(entry => {
|
|
68
70
|
const template = fn(this.shadowTemplate());
|
|
69
71
|
return template.render(entry);
|
|
70
72
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
this.container = (imagesFn, box, packingFn, options) => this.layer((entry_1, _a) => __awaiter(this, [entry_1, _a], void 0, function* (entry, { debugMode }) {
|
|
74
|
+
const mergedOptions = (0, lodash_merge_1.default)({}, types_1.DEFAULT_CONTAINER_OPTIONS, options);
|
|
75
|
+
if (this.shouldSkipLayerForEntry(entry, mergedOptions)) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
73
78
|
const images = yield imagesFn(entry);
|
|
74
|
-
|
|
79
|
+
const result = yield packingFn(box, this.shadowBackground(), images);
|
|
80
|
+
// debug mode
|
|
81
|
+
if (debugMode) {
|
|
82
|
+
const debugImage = yield (0, utils_1.drawBoundingBox)(box, this.backgroundSize);
|
|
83
|
+
return debugImage.composite(result);
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
75
86
|
}));
|
|
76
|
-
this.hbox = (imagesFn, box, options) => this.container(imagesFn, (0, utils_1.hboxPackingFn)(
|
|
77
|
-
this.vbox = (imagesFn, box, options) => this.container(imagesFn, (0, utils_1.vboxPackingFn)(
|
|
87
|
+
this.hbox = (imagesFn, box, options) => this.container(imagesFn, box, (0, utils_1.hboxPackingFn)(options), options);
|
|
88
|
+
this.vbox = (imagesFn, box, options) => this.container(imagesFn, box, (0, utils_1.vboxPackingFn)(options), options);
|
|
89
|
+
this.grid = (imagesFn, box, options) => this.container(imagesFn, box, (0, utils_1.gridPackingFn)(options), options);
|
|
78
90
|
this.image = (ref, box, options) => this.layer((entry_1, _a) => __awaiter(this, [entry_1, _a], void 0, function* (entry, { debugMode }) {
|
|
79
|
-
const
|
|
91
|
+
const mergedOptions = (0, lodash_merge_1.default)({}, types_1.DEFAULT_IMAGE_LAYER_OPTIONS, { assetsPath: this.defaultAssetsPath }, options);
|
|
92
|
+
if (this.shouldSkipLayerForEntry(entry, mergedOptions)) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const image = yield this.pathFromImageRef(entry, ref, mergedOptions);
|
|
80
96
|
const result = yield (0, utils_1.placeImage)({
|
|
81
97
|
image,
|
|
82
98
|
box,
|
|
83
99
|
backgroundSize: this.backgroundSize,
|
|
84
|
-
options,
|
|
100
|
+
options: mergedOptions,
|
|
85
101
|
});
|
|
86
102
|
// debug mode
|
|
87
103
|
if (debugMode) {
|
|
@@ -95,17 +111,27 @@ class Template {
|
|
|
95
111
|
return image;
|
|
96
112
|
});
|
|
97
113
|
this.text = (ref, box, options) => this.layer((entry_1, _a) => __awaiter(this, [entry_1, _a], void 0, function* (entry, { debugMode }) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
114
|
+
const mergedOptions = (0, lodash_merge_1.default)({}, types_1.DEFAULT_TEXT_LAYER_OPTIONS, {
|
|
115
|
+
font: {
|
|
116
|
+
family: this.defaultFontFamily,
|
|
117
|
+
},
|
|
118
|
+
}, options);
|
|
119
|
+
if (this.shouldSkipLayerForEntry(entry, mergedOptions)) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
const text = this.textFromTextRef(entry, ref);
|
|
123
|
+
const result = yield (0, utils_1.renderText)(text, box, this.backgroundSize, mergedOptions, this.fonts);
|
|
124
|
+
// debug mode
|
|
125
|
+
if (debugMode) {
|
|
126
|
+
const debugImage = yield (0, utils_1.drawBoundingBox)(box, this.backgroundSize);
|
|
127
|
+
return debugImage.composite(result);
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
102
130
|
}));
|
|
103
131
|
this.pathFromImageRef = (entry, ref, options) => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
var _a;
|
|
105
|
-
const assetsPath = (_a = options === null || options === void 0 ? void 0 : options.assetsPath) !== null && _a !== void 0 ? _a : this.defaultAssetsPath;
|
|
106
132
|
const pathSegments = [];
|
|
107
|
-
if (assetsPath) {
|
|
108
|
-
pathSegments.push(assetsPath);
|
|
133
|
+
if (options.assetsPath) {
|
|
134
|
+
pathSegments.push(options.assetsPath);
|
|
109
135
|
}
|
|
110
136
|
if ('buffer' in ref) {
|
|
111
137
|
return this.loadImage(ref.buffer);
|
|
@@ -128,7 +154,7 @@ class Template {
|
|
|
128
154
|
throw new Error('Unknown ImageRef variant');
|
|
129
155
|
}
|
|
130
156
|
});
|
|
131
|
-
this.
|
|
157
|
+
this.textFromTextRef = (entry, ref) => {
|
|
132
158
|
if ('key' in ref) {
|
|
133
159
|
return entry[ref.key];
|
|
134
160
|
}
|
|
@@ -142,6 +168,13 @@ class Template {
|
|
|
142
168
|
throw new Error('Unknown TextRef variant');
|
|
143
169
|
}
|
|
144
170
|
};
|
|
171
|
+
this.shouldSkipLayerForEntry = (entry, options) => {
|
|
172
|
+
var _a;
|
|
173
|
+
if (typeof options.skip === 'function') {
|
|
174
|
+
return options.skip(entry);
|
|
175
|
+
}
|
|
176
|
+
return (_a = options.skip) !== null && _a !== void 0 ? _a : false;
|
|
177
|
+
};
|
|
145
178
|
this.background = new jimp_1.Jimp({
|
|
146
179
|
height: options.height,
|
|
147
180
|
width: options.width,
|
|
@@ -176,9 +209,8 @@ class Template {
|
|
|
176
209
|
return this;
|
|
177
210
|
}
|
|
178
211
|
font(path, name) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
212
|
+
// TODO: pass font weight and font style as well
|
|
213
|
+
this.fonts[name] = fs.readFileSync(path.toString()).toString('base64');
|
|
182
214
|
return this;
|
|
183
215
|
}
|
|
184
216
|
debug() {
|
|
@@ -187,9 +219,10 @@ class Template {
|
|
|
187
219
|
}
|
|
188
220
|
renderLayers(entry) {
|
|
189
221
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
|
|
222
|
+
const results = yield Promise.all(this.layers.map(layerFn => layerFn(entry, {
|
|
191
223
|
debugMode: this.debugMode,
|
|
192
224
|
})));
|
|
225
|
+
return results.filter(result => !!result);
|
|
193
226
|
});
|
|
194
227
|
}
|
|
195
228
|
render(entry, options) {
|
|
@@ -239,5 +272,4 @@ class Template {
|
|
|
239
272
|
}
|
|
240
273
|
}
|
|
241
274
|
exports.Template = Template;
|
|
242
|
-
// TODO: Ledger of actions applied to the image like a logging feed
|
|
243
275
|
//# sourceMappingURL=template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../src/lib/template.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,yCAA8C;AAC9C,+BAAuC;AACvC,wEAAyC;AACzC,kEAAmC;
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../src/lib/template.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,yCAA8C;AAC9C,+BAAuC;AACvC,wE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OAAO,CAAC;oBACX,KAAK;oBACL,yCAAyC;oBACzC,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,CACvC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CACnC;iBACJ,CAAC,CAAC;YACP,CAAC,CAAC,CACL,CACR,CACJ,CAAC;YACF,OAAO,IAAA,uBAAM,EAAC,GAAG,OAAO,CAAC,CAAC;QAC9B,CAAC;KAAA;IAEK,OAAO,CACT,IAAY,EACZ,OAAkC;;YAElC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACnC,IAAI,CAAC;oBACD,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;oBAClD,MAAM,UAAU,GAAG,IAAA,iBAAQ,EAAY,WAAW,EAAE;wBAChD,MAAM,EAAE,IAAI;wBACZ,cAAc,EAAE,IAAI;wBACpB,eAAe,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAC/B,IAAA,0BAAS,EAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,SAAS,KAAK,EAAE,CAAC;qBAC5C,CAAC,CAAC;oBACH,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;gBACtD,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACX,MAAM,CAAC,GAAG,CAAC,CAAC;gBAChB,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC;KAAA;CAqDJ;AAjVD,4BAiVC"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequiredDeep } from 'type-fest';
|
|
2
|
+
import { BoundingBox } from './boundingBox';
|
|
2
3
|
import { ImageType } from './image';
|
|
3
4
|
import { ScaleMode } from './scale';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Setting a non-default value for justify will cause the alignment to be ignored.
|
|
7
|
-
*
|
|
8
|
-
* Defaults to `normal`
|
|
9
|
-
*/
|
|
10
|
-
justifyContent?: JustifyContent;
|
|
5
|
+
import { LayerOptions } from './layer';
|
|
6
|
+
export type ContainerOptions<EntryType extends Record<string, string>> = LayerOptions<EntryType> & {
|
|
11
7
|
/**
|
|
12
8
|
* This is treated as a minimum length of an unit of space
|
|
13
9
|
* between two items, but it can grow larger than it
|
|
@@ -15,26 +11,18 @@ export type ContainerOptions = {
|
|
|
15
11
|
* Defaults to 0
|
|
16
12
|
*/
|
|
17
13
|
gap?: number;
|
|
18
|
-
/**
|
|
19
|
-
* Defines how the items should be placed
|
|
20
|
-
* across the secondary direction of the container
|
|
21
|
-
*
|
|
22
|
-
* Defaults to `center`
|
|
23
|
-
*/
|
|
24
|
-
alignItems?: AlignItems;
|
|
25
14
|
/**
|
|
26
15
|
* Defaults to `none`
|
|
27
16
|
*/
|
|
28
17
|
scale?: ScaleMode;
|
|
29
18
|
};
|
|
30
|
-
export declare const DEFAULT_CONTAINER_OPTIONS:
|
|
31
|
-
export type DirectionContainerOptions = ContainerOptions & {
|
|
19
|
+
export declare const DEFAULT_CONTAINER_OPTIONS: RequiredDeep<ContainerOptions<Record<string, string>>>;
|
|
20
|
+
export type DirectionContainerOptions<EntryType extends Record<string, string>> = ContainerOptions<EntryType> & {
|
|
32
21
|
reversed?: boolean;
|
|
33
22
|
};
|
|
34
|
-
export declare const DEFAULT_DIRECTION_CONTAINER_OPTIONS:
|
|
35
|
-
export type GridContainerOptions = ContainerOptions & {
|
|
36
|
-
|
|
37
|
-
cols?: number;
|
|
23
|
+
export declare const DEFAULT_DIRECTION_CONTAINER_OPTIONS: RequiredDeep<DirectionContainerOptions<Record<string, string>>>;
|
|
24
|
+
export type GridContainerOptions<EntryType extends Record<string, string>> = ContainerOptions<EntryType> & {
|
|
25
|
+
size?: number;
|
|
38
26
|
/**
|
|
39
27
|
* Defines what is considered the main direction of the container.
|
|
40
28
|
* -> `rows` - the items would be placed to fill each row before starting the next
|
|
@@ -44,4 +32,5 @@ export type GridContainerOptions = ContainerOptions & {
|
|
|
44
32
|
*/
|
|
45
33
|
direction?: 'rows' | 'cols';
|
|
46
34
|
};
|
|
47
|
-
export
|
|
35
|
+
export declare const DEFAULT_GRID_CONTAINER_OPTIONS: RequiredDeep<GridContainerOptions<Record<string, string>>>;
|
|
36
|
+
export type PackingFn = (box: BoundingBox, background: ImageType, images: Array<ImageType>) => Promise<ImageType>;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_DIRECTION_CONTAINER_OPTIONS = exports.DEFAULT_CONTAINER_OPTIONS = void 0;
|
|
3
|
+
exports.DEFAULT_GRID_CONTAINER_OPTIONS = exports.DEFAULT_DIRECTION_CONTAINER_OPTIONS = exports.DEFAULT_CONTAINER_OPTIONS = void 0;
|
|
4
4
|
exports.DEFAULT_CONTAINER_OPTIONS = {
|
|
5
5
|
gap: 0,
|
|
6
6
|
justifyContent: 'normal',
|
|
7
7
|
alignItems: 'center',
|
|
8
8
|
scale: 'none',
|
|
9
|
+
skip: false,
|
|
9
10
|
};
|
|
10
11
|
exports.DEFAULT_DIRECTION_CONTAINER_OPTIONS = Object.assign(Object.assign({}, exports.DEFAULT_CONTAINER_OPTIONS), { reversed: false });
|
|
12
|
+
exports.DEFAULT_GRID_CONTAINER_OPTIONS = Object.assign(Object.assign({}, exports.DEFAULT_CONTAINER_OPTIONS), { size: 3, direction: 'rows' });
|
|
11
13
|
//# sourceMappingURL=containers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"containers.js","sourceRoot":"","sources":["../../../../src/lib/types/containers.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"containers.js","sourceRoot":"","sources":["../../../../src/lib/types/containers.ts"],"names":[],"mappings":";;;AAsBa,QAAA,yBAAyB,GAElC;IACA,GAAG,EAAE,CAAC;IACN,cAAc,EAAE,QAAQ;IACxB,UAAU,EAAE,QAAQ;IACpB,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,KAAK;CACd,CAAC;AAQW,QAAA,mCAAmC,mCAGzC,iCAAyB,KAC5B,QAAQ,EAAE,KAAK,IACjB;AAgBW,QAAA,8BAA8B,mCAGpC,iCAAyB,KAC5B,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,MAAM,IACnB"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { JimpInstance } from 'jimp';
|
|
2
2
|
import { ScaleMode } from './scale';
|
|
3
|
-
import {
|
|
3
|
+
import { LayerOptions } from './layer';
|
|
4
|
+
import { RequiredDeep } from 'type-fest';
|
|
4
5
|
export type ImageType = JimpInstance;
|
|
5
|
-
export type ImageRef<EntryType
|
|
6
|
+
export type ImageRef<EntryType extends Record<string, string>> = {
|
|
6
7
|
buffer: Buffer;
|
|
7
8
|
} | {
|
|
8
9
|
path: string;
|
|
@@ -13,24 +14,16 @@ export type ImageRef<EntryType> = {
|
|
|
13
14
|
} | {
|
|
14
15
|
pathFn: (entry: EntryType) => string;
|
|
15
16
|
};
|
|
16
|
-
export type ImageLayerOptions = {
|
|
17
|
+
export type ImageLayerOptions<EntryType extends Record<string, string>> = LayerOptions<EntryType> & {
|
|
17
18
|
/**
|
|
18
19
|
* Base path for the assets. Overrides the more global property of the template `defaultAssetsPath`.
|
|
19
20
|
*/
|
|
20
21
|
assetsPath?: string;
|
|
21
|
-
/**
|
|
22
|
-
* default `center`
|
|
23
|
-
*/
|
|
24
|
-
justifyContent?: JustifyContent;
|
|
25
|
-
/**
|
|
26
|
-
* default `center`
|
|
27
|
-
*/
|
|
28
|
-
alignItems?: AlignItems;
|
|
29
22
|
/**
|
|
30
23
|
* Defaults to `none`
|
|
31
24
|
*/
|
|
32
25
|
scale?: ScaleMode;
|
|
33
26
|
};
|
|
34
|
-
export declare const DEFAULT_IMAGE_LAYER_OPTIONS:
|
|
27
|
+
export declare const DEFAULT_IMAGE_LAYER_OPTIONS: RequiredDeep<ImageLayerOptions<Record<string, string>>>;
|
|
35
28
|
export type Alignment = 'start' | 'center' | 'end';
|
|
36
29
|
export declare const DEFAULT_IMAGE_ALIGNMENT: Alignment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../../src/lib/types/image.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../../src/lib/types/image.ts"],"names":[],"mappings":";;;AA8Ba,QAAA,2BAA2B,GAA4D;IAChG,cAAc,EAAE,QAAQ;IACxB,UAAU,EAAE,QAAQ;IACpB,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,KAAK;IACX,UAAU,EAAE,EAAE;CACjB,CAAC;AAIW,QAAA,uBAAuB,GAAc,QAAQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,+CAA6B;AAC7B,0CAAwB;AACxB,2CAAyB;AACzB,gDAA8B;AAC9B,0CAAwB;AACxB,yCAAuB;AACvB,gDAA8B;AAC9B,wCAAsB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,+CAA6B;AAC7B,0CAAwB;AACxB,2CAAyB;AACzB,gDAA8B;AAC9B,0CAAwB;AACxB,yCAAuB;AACvB,gDAA8B;AAC9B,wCAAsB;AACtB,0CAAwB"}
|
|
@@ -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":""}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { RequiredDeep } from 'type-fest';
|
|
2
|
+
import { LayerOptions } from './layer';
|
|
1
3
|
import { ReplacementMap } from './replacement';
|
|
2
4
|
export type TextRef<EntryType> = {
|
|
3
5
|
key: string;
|
|
@@ -6,35 +8,29 @@ export type TextRef<EntryType> = {
|
|
|
6
8
|
} | {
|
|
7
9
|
textFn: (entry: EntryType) => string;
|
|
8
10
|
};
|
|
9
|
-
export type
|
|
10
|
-
font?: {
|
|
11
|
-
/**
|
|
12
|
-
* Size of font is represented in pixels
|
|
13
|
-
*/
|
|
14
|
-
size?: number;
|
|
15
|
-
/**
|
|
16
|
-
* Either use one supported by canvas
|
|
17
|
-
* or load a custom one before rendering
|
|
18
|
-
*/
|
|
19
|
-
family?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Warning: Not supported by all fonts
|
|
22
|
-
*/
|
|
23
|
-
bold?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Warning: Not supported by all fonts
|
|
26
|
-
*/
|
|
27
|
-
italic?: boolean;
|
|
28
|
-
};
|
|
29
|
-
color?: string;
|
|
30
|
-
replacement?: ReplacementMap;
|
|
11
|
+
export type FontOptions = {
|
|
31
12
|
/**
|
|
32
|
-
*
|
|
13
|
+
* Size of font is represented in pixels
|
|
33
14
|
*/
|
|
34
|
-
|
|
15
|
+
size?: number;
|
|
35
16
|
/**
|
|
36
|
-
*
|
|
17
|
+
* Either use one supported by canvas
|
|
18
|
+
* or load a custom one before rendering
|
|
37
19
|
*/
|
|
38
|
-
|
|
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;
|
|
39
34
|
};
|
|
40
|
-
export declare const
|
|
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,3 +1,4 @@
|
|
|
1
|
-
import { DirectionContainerOptions, PackingFn,
|
|
2
|
-
export declare const vboxPackingFn:
|
|
3
|
-
export declare const hboxPackingFn:
|
|
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,13 +12,14 @@ 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;
|
|
15
|
+
exports.gridPackingFn = exports.hboxPackingFn = exports.vboxPackingFn = void 0;
|
|
16
16
|
const virtual_dom_1 = require("virtual-dom");
|
|
17
17
|
const types_1 = require("../types");
|
|
18
18
|
const toPx_1 = require("./toPx");
|
|
19
19
|
const lodash_merge_1 = __importDefault(require("lodash.merge"));
|
|
20
20
|
const htmlToImage_1 = require("./htmlToImage");
|
|
21
|
-
const
|
|
21
|
+
const lodash_chunk_1 = __importDefault(require("lodash.chunk"));
|
|
22
|
+
const vboxPackingFn = (options) => (box, background, images) => directionalPackingFn({
|
|
22
23
|
isVertical: true,
|
|
23
24
|
backgroundSize: background,
|
|
24
25
|
images,
|
|
@@ -26,7 +27,7 @@ const vboxPackingFn = (box, options) => (background, images) => directionalPacki
|
|
|
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
32
|
backgroundSize: background,
|
|
32
33
|
images,
|
|
@@ -34,8 +35,44 @@ const hboxPackingFn = (box, options) => (background, images) => directionalPacki
|
|
|
34
35
|
options,
|
|
35
36
|
});
|
|
36
37
|
exports.hboxPackingFn = hboxPackingFn;
|
|
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];
|
|
41
|
+
const children = yield Promise.all(images.map((image) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const imageBase64 = yield image.getBase64('image/png');
|
|
43
|
+
return (0, virtual_dom_1.h)('img', {
|
|
44
|
+
style: {
|
|
45
|
+
objectFit,
|
|
46
|
+
flex: '1 1 auto',
|
|
47
|
+
minWidth: 0,
|
|
48
|
+
minHeight: 0,
|
|
49
|
+
maxWidth: '100%',
|
|
50
|
+
maxHeight: '100%',
|
|
51
|
+
},
|
|
52
|
+
src: imageBase64,
|
|
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
|
+
}
|
|
68
|
+
const document = (0, virtual_dom_1.h)('div', {
|
|
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;
|
|
37
74
|
const directionalPackingFn = (_a) => __awaiter(void 0, [_a], void 0, function* ({ isVertical, backgroundSize: background, images, box, options, }) {
|
|
38
|
-
const mergedOptions = (0, lodash_merge_1.default)(types_1.DEFAULT_DIRECTION_CONTAINER_OPTIONS, options);
|
|
75
|
+
const mergedOptions = (0, lodash_merge_1.default)({}, types_1.DEFAULT_DIRECTION_CONTAINER_OPTIONS, options);
|
|
39
76
|
const objectFit = types_1.SCALE_MODE_TO_OBJECT_FIT[mergedOptions.scale];
|
|
40
77
|
const children = yield Promise.all(images.map((image) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
78
|
const imageBase64 = yield image.getBase64('image/png');
|
|
@@ -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/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,"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"}
|