xpict 0.1.0 → 0.1.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/dist/layers/image-layer.d.ts +1 -1
- package/dist/layers/image-layer.js +6 -4
- package/dist/template.d.ts +7 -2
- package/dist/template.js +20 -14
- package/package.json +1 -1
|
@@ -12,5 +12,5 @@ export type ImageLayerOptions<Data> = {
|
|
|
12
12
|
export declare class ImageLayer<Data> extends Layer<Data> {
|
|
13
13
|
private options;
|
|
14
14
|
constructor(options: ImageLayerOptions<Data>);
|
|
15
|
-
render(ctx: RenderContext, data: Data): Promise<void>;
|
|
15
|
+
render(ctx: RenderContext, data: Data, index?: number): Promise<void>;
|
|
16
16
|
}
|
|
@@ -12,14 +12,16 @@ class ImageLayer extends layer_1.Layer {
|
|
|
12
12
|
super(options.when);
|
|
13
13
|
this.options = options;
|
|
14
14
|
}
|
|
15
|
-
async render(ctx, data) {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
15
|
+
async render(ctx, data, index = 0) {
|
|
16
|
+
const localX = (0, resolve_axis_1.resolveAxis)(this.options.x, data, index);
|
|
17
|
+
const localY = (0, resolve_axis_1.resolveAxis)(this.options.y, data, index);
|
|
18
|
+
const x = ctx.offsetX + localX;
|
|
19
|
+
const y = ctx.offsetY + localY;
|
|
18
20
|
const img = await (0, sharp_1.default)(this.options.src(data))
|
|
19
21
|
.resize(this.options.width, this.options.height)
|
|
20
22
|
.toBuffer();
|
|
21
23
|
ctx.image = ctx.image.composite([
|
|
22
|
-
{ input: img, left:
|
|
24
|
+
{ input: img, left: x, top: y }
|
|
23
25
|
]);
|
|
24
26
|
}
|
|
25
27
|
}
|
package/dist/template.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color } from "sharp";
|
|
1
|
+
import sharp, { Color } from "sharp";
|
|
2
2
|
import { Layer } from "./layers/layer";
|
|
3
3
|
export type TemplateConfig = {
|
|
4
4
|
width: number;
|
|
@@ -6,11 +6,16 @@ export type TemplateConfig = {
|
|
|
6
6
|
fill?: Color;
|
|
7
7
|
};
|
|
8
8
|
export type TemplateOptions<Data> = {
|
|
9
|
+
imagePath?: undefined;
|
|
9
10
|
config: TemplateConfig;
|
|
10
11
|
layers: Layer<Data>[];
|
|
12
|
+
} | {
|
|
13
|
+
config?: undefined;
|
|
14
|
+
imagePath: string;
|
|
15
|
+
layers: Layer<Data>[];
|
|
11
16
|
};
|
|
12
17
|
export declare class Template<Data> {
|
|
13
18
|
readonly options: TemplateOptions<Data>;
|
|
14
19
|
constructor(options: TemplateOptions<Data>);
|
|
15
|
-
render(data: Data): Promise<
|
|
20
|
+
render(data: Data): Promise<sharp.Sharp>;
|
|
16
21
|
}
|
package/dist/template.js
CHANGED
|
@@ -11,20 +11,26 @@ class Template {
|
|
|
11
11
|
this.options = options;
|
|
12
12
|
}
|
|
13
13
|
async render(data) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
let image;
|
|
15
|
+
if (this.options.config) {
|
|
16
|
+
const { width, height, fill } = this.options.config;
|
|
17
|
+
image = (0, sharp_1.default)({
|
|
18
|
+
create: {
|
|
19
|
+
width: width,
|
|
20
|
+
height: height,
|
|
21
|
+
channels: 4,
|
|
22
|
+
background: fill !== null && fill !== void 0 ? fill : {
|
|
23
|
+
r: 0,
|
|
24
|
+
g: 0,
|
|
25
|
+
b: 0,
|
|
26
|
+
alpha: 0
|
|
27
|
+
}
|
|
25
28
|
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
image = (0, sharp_1.default)(this.options.imagePath);
|
|
33
|
+
}
|
|
28
34
|
const ctx = {
|
|
29
35
|
image: image,
|
|
30
36
|
offsetX: 0,
|
|
@@ -36,7 +42,7 @@ class Template {
|
|
|
36
42
|
await layer.render(ctx, data);
|
|
37
43
|
ctx.image = await (0, commit_frame_1.commitFrame)(ctx.image);
|
|
38
44
|
}
|
|
39
|
-
return ctx.image
|
|
45
|
+
return ctx.image;
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
exports.Template = Template;
|
package/package.json
CHANGED