@hellkite/pipkin 0.1.0

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.
Files changed (53) hide show
  1. package/.editorconfig +8 -0
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.json +15 -0
  4. package/.nvmrc +1 -0
  5. package/.prettierrc.js +4 -0
  6. package/LICENSE +21 -0
  7. package/README.md +3 -0
  8. package/build/src/index.d.ts +1 -0
  9. package/build/src/index.js +65 -0
  10. package/build/src/index.js.map +1 -0
  11. package/build/src/lib/template.d.ts +44 -0
  12. package/build/src/lib/template.js +226 -0
  13. package/build/src/lib/template.js.map +1 -0
  14. package/build/src/lib/types/2d.d.ts +10 -0
  15. package/build/src/lib/types/2d.js +8 -0
  16. package/build/src/lib/types/2d.js.map +1 -0
  17. package/build/src/lib/types/image.d.ts +44 -0
  18. package/build/src/lib/types/image.js +6 -0
  19. package/build/src/lib/types/image.js.map +1 -0
  20. package/build/src/lib/types/render.d.ts +14 -0
  21. package/build/src/lib/types/render.js +3 -0
  22. package/build/src/lib/types/render.js.map +1 -0
  23. package/build/src/lib/types/scale.d.ts +1 -0
  24. package/build/src/lib/types/scale.js +3 -0
  25. package/build/src/lib/types/scale.js.map +1 -0
  26. package/build/src/lib/types/text.d.ts +31 -0
  27. package/build/src/lib/types/text.js +7 -0
  28. package/build/src/lib/types/text.js.map +1 -0
  29. package/build/src/lib/utils/buildFontString.d.ts +2 -0
  30. package/build/src/lib/utils/buildFontString.js +18 -0
  31. package/build/src/lib/utils/buildFontString.js.map +1 -0
  32. package/build/src/lib/utils/canvasToImage.d.ts +3 -0
  33. package/build/src/lib/utils/canvasToImage.js +28 -0
  34. package/build/src/lib/utils/canvasToImage.js.map +1 -0
  35. package/build/src/lib/utils/drawBoundingBox.d.ts +3 -0
  36. package/build/src/lib/utils/drawBoundingBox.js +63 -0
  37. package/build/src/lib/utils/drawBoundingBox.js.map +1 -0
  38. package/build/src/lib/utils/placeImage.d.ts +2 -0
  39. package/build/src/lib/utils/placeImage.js +59 -0
  40. package/build/src/lib/utils/placeImage.js.map +1 -0
  41. package/package.json +34 -0
  42. package/src/index.ts +80 -0
  43. package/src/lib/template.ts +293 -0
  44. package/src/lib/types/2d.ts +13 -0
  45. package/src/lib/types/image.ts +56 -0
  46. package/src/lib/types/render.ts +17 -0
  47. package/src/lib/types/scale.ts +0 -0
  48. package/src/lib/types/text.ts +45 -0
  49. package/src/lib/utils/buildFontString.ts +17 -0
  50. package/src/lib/utils/canvasToImage.ts +19 -0
  51. package/src/lib/utils/drawBoundingBox.ts +22 -0
  52. package/src/lib/utils/placeImage.ts +77 -0
  53. package/tsconfig.json +16 -0
package/.editorconfig ADDED
@@ -0,0 +1,8 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 4
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ insert_final_newline = true
package/.eslintignore ADDED
@@ -0,0 +1 @@
1
+ build/
package/.eslintrc.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "./node_modules/gts/",
3
+ "rules": {
4
+ "node/no-unpublished-import": "off",
5
+ "@typescript-eslint/no-unused-vars": [
6
+ "warn",
7
+ {
8
+ "argsIgnorePattern": "^_",
9
+ "varsIgnorePattern": "^_",
10
+ "caughtErrorsIgnorePattern": "^_"
11
+ }
12
+ ],
13
+ "object-curly-spacing": ["error", "always"]
14
+ }
15
+ }
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v18.16.0
package/.prettierrc.js ADDED
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ ...require('gts/.prettierrc.json'),
3
+ bracketSpacing: true,
4
+ };
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Hellkite
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # pipkin
2
+
3
+ Card generation framework for TCGs or Boardgames
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const template_1 = require("./lib/template");
13
+ const _2d_1 = require("./lib/types/2d");
14
+ (() => __awaiter(void 0, void 0, void 0, function* () {
15
+ const result = yield template_1.Template.new({
16
+ defaultFontFamily: 'branela',
17
+ defaultAssetsPath: 'assets',
18
+ })
19
+ .textLayer('title', {
20
+ start: (0, _2d_1.toPoint)(25, 25),
21
+ size: (0, _2d_1.toSize)(700, 700),
22
+ textAlign: 'center',
23
+ }, {
24
+ font: {
25
+ size: 48,
26
+ family: 'blackflag',
27
+ },
28
+ })
29
+ .font('assets/BlackFlag.ttf', 'blackflag')
30
+ .textLayer('subtitle', {
31
+ start: (0, _2d_1.toPoint)(25, 125),
32
+ size: (0, _2d_1.toSize)(700, 700),
33
+ textAlign: 'center',
34
+ }, {
35
+ font: {
36
+ size: 38,
37
+ },
38
+ color: 'purple',
39
+ })
40
+ .font('assets/branela.otf', 'branela')
41
+ .imageLayer('title', {
42
+ start: (0, _2d_1.toPoint)(25, 225),
43
+ size: (0, _2d_1.toSize)(700, 700),
44
+ scale: 'stretch',
45
+ }, {
46
+ assetsPath: 'assets',
47
+ pathFn: (title) => `${title.toLowerCase()}.png`,
48
+ })
49
+ .textLayer('effect', {
50
+ start: (0, _2d_1.toPoint)(125, 950),
51
+ size: (0, _2d_1.toSize)(500, 150),
52
+ textAlign: 'center',
53
+ }, {
54
+ font: {
55
+ size: 32,
56
+ },
57
+ })
58
+ .fromCsv('assets/data.csv', {
59
+ duplication: {
60
+ countField: 'copies',
61
+ },
62
+ });
63
+ yield Promise.all(result.map((r, index) => r.write(`assets/test-${index + 1}.png`)));
64
+ }))();
65
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6CAA0C;AAC1C,wCAAiD;AASjD,CAAC,GAAS,EAAE;IACR,MAAM,MAAM,GAAG,MAAM,mBAAQ,CAAC,GAAG,CAAe;QAC5C,iBAAiB,EAAE,SAAS;QAC5B,iBAAiB,EAAE,QAAQ;KAC9B,CAAC;SACG,SAAS,CACN,OAAO,EACP;QACI,KAAK,EAAE,IAAA,aAAO,EAAC,EAAE,EAAE,EAAE,CAAC;QACtB,IAAI,EAAE,IAAA,YAAM,EAAC,GA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C,CAAC,KAAK,CAAC,eAAe,KAAK,GAAG,CAAC,MAAM,CAAC,CAAC,CACpE,CAAC;AACN,CAAC,CAAA,CAAC,EAAE,CAAC"}
@@ -0,0 +1,44 @@
1
+ import * as fs from 'fs';
2
+ import { ImageType, ImagePosition, ImageLayerOptions } from './types/image';
3
+ import { TextPosition, TextLayerOptions } from './types/text';
4
+ import { RenderOptions } from './types/render';
5
+ type RequiredTemplateOptions = {
6
+ height: number;
7
+ width: number;
8
+ color: number;
9
+ };
10
+ type OptionalTemplateOptions = {
11
+ defaultFontFamily?: string;
12
+ defaultAssetsPath?: string;
13
+ };
14
+ export type TemplateOptions = RequiredTemplateOptions & OptionalTemplateOptions;
15
+ export type LayerFnContext = {
16
+ width: number;
17
+ height: number;
18
+ debugMode: boolean;
19
+ };
20
+ export type LayerFn<EntryType> = (entry: EntryType, context: LayerFnContext) => Promise<ImageType>;
21
+ export type TemplateLayerFn<EntryType extends Record<string, string>> = (template: Template<EntryType>) => Template<EntryType>;
22
+ export declare class Template<EntryType extends Record<string, string>> {
23
+ private readonly layers;
24
+ private readonly background;
25
+ private debugMode;
26
+ private defaultFontFamily?;
27
+ private defaultAssetsPath?;
28
+ private constructor();
29
+ static new<EntryType extends Record<string, string>>(options?: Partial<TemplateOptions>): Template<EntryType>;
30
+ private shadowTemplate;
31
+ private shadowBackground;
32
+ layer(fn: LayerFn<EntryType>): this;
33
+ templateLayer: (fn: TemplateLayerFn<EntryType>) => this;
34
+ imageLayer: (key: keyof EntryType, position: ImagePosition, options?: ImageLayerOptions) => this;
35
+ staticImageLayer: (path: string, position: ImagePosition, options?: ImageLayerOptions) => this;
36
+ textLayer: (key: keyof EntryType, position: TextPosition, options?: TextLayerOptions) => this;
37
+ font(path: fs.PathLike, name: string): this;
38
+ debug(): this;
39
+ renderLayers(entry: EntryType): Promise<Array<ImageType>>;
40
+ render(entry: EntryType, options?: RenderOptions<EntryType>): Promise<ImageType>;
41
+ renderAll(entries: Array<EntryType>, options?: RenderOptions<EntryType>): Promise<Array<ImageType>>;
42
+ fromCsv(path: string, options?: RenderOptions<EntryType>): Promise<Array<ImageType>>;
43
+ }
44
+ export {};
@@ -0,0 +1,226 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.Template = void 0;
49
+ const fs = __importStar(require("fs"));
50
+ const papaparse_1 = require("papaparse");
51
+ const jimp_1 = require("jimp");
52
+ const lodash_camelcase_1 = __importDefault(require("lodash.camelcase"));
53
+ const placeImage_1 = require("./utils/placeImage");
54
+ const drawBoundingBox_1 = require("./utils/drawBoundingBox");
55
+ const text_1 = require("./types/text");
56
+ const lodash_concat_1 = __importDefault(require("lodash.concat"));
57
+ const fabric = __importStar(require("fabric/node"));
58
+ const canvasToImage_1 = require("./utils/canvasToImage");
59
+ const canvas_1 = require("canvas");
60
+ const DEFAULT_TEMPLATE_OPTIONS = {
61
+ height: 1050,
62
+ width: 750,
63
+ color: (0, jimp_1.rgbaToInt)(255, 255, 255, 255),
64
+ };
65
+ class Template {
66
+ // disallow constructor initialization
67
+ constructor(options) {
68
+ this.layers = [];
69
+ this.debugMode = false;
70
+ this.templateLayer = (fn) => this.layer(entry => {
71
+ const template = fn(this.shadowTemplate());
72
+ return template.render(entry);
73
+ });
74
+ this.imageLayer = (key, position, options) => this.layer((entry_1, _a) => __awaiter(this, [entry_1, _a], void 0, function* (entry, { debugMode, width, height }) {
75
+ const imagePath = (options === null || options === void 0 ? void 0 : options.pathFn)
76
+ ? options.pathFn(entry[key])
77
+ : entry[key];
78
+ const result = yield (0, placeImage_1.placeImage)(this.shadowBackground(), imagePath, position, options, this.defaultAssetsPath);
79
+ // debug mode
80
+ if (debugMode) {
81
+ const debugImage = yield (0, drawBoundingBox_1.drawBoundingBox)(position, {
82
+ width,
83
+ height,
84
+ });
85
+ return debugImage.composite(result);
86
+ }
87
+ return result;
88
+ }));
89
+ this.staticImageLayer = (path, position, options) => this.layer((_1, _a) => __awaiter(this, [_1, _a], void 0, function* (_, { debugMode, width, height }) {
90
+ const result = yield (0, placeImage_1.placeImage)(this.shadowBackground(), path, position, options, this.defaultAssetsPath);
91
+ // debug mode
92
+ if (debugMode) {
93
+ const debugImage = yield (0, drawBoundingBox_1.drawBoundingBox)(position, {
94
+ width,
95
+ height,
96
+ });
97
+ return debugImage.composite(result);
98
+ }
99
+ return result;
100
+ }));
101
+ this.textLayer = (key, position, options) => this.layer((entry_1, _a) => __awaiter(this, [entry_1, _a], void 0, function* (entry, { debugMode, width, height }) {
102
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
103
+ const text = entry[key];
104
+ // render text
105
+ const canvas = new fabric.Canvas(null, { width, height });
106
+ const textObject = new fabric.Textbox(text, {
107
+ left: position.start.x,
108
+ top: position.start.y,
109
+ width: position.size.width,
110
+ height: position.size.height,
111
+ fontSize: (_c = (_b = options === null || options === void 0 ? void 0 : options.font) === null || _b === void 0 ? void 0 : _b.size) !== null && _c !== void 0 ? _c : 16,
112
+ fontFamily: (_f = (_e = (_d = options === null || options === void 0 ? void 0 : options.font) === null || _d === void 0 ? void 0 : _d.family) !== null && _e !== void 0 ? _e : this.defaultFontFamily) !== null && _f !== void 0 ? _f : 'Arial',
113
+ fontWeight: ((_g = options === null || options === void 0 ? void 0 : options.font) === null || _g === void 0 ? void 0 : _g.bold) ? 'bold' : 'normal',
114
+ fontStyle: ((_h = options === null || options === void 0 ? void 0 : options.font) === null || _h === void 0 ? void 0 : _h.italic) ? 'italic' : 'normal',
115
+ fill: (_j = options === null || options === void 0 ? void 0 : options.color) !== null && _j !== void 0 ? _j : 'black',
116
+ textAlign: (_k = position.textAlign) !== null && _k !== void 0 ? _k : text_1.DEFAULT_TEXT_ALIGNMENT_PROPS.textAlign,
117
+ splitByGrapheme: true, // word wrapping
118
+ });
119
+ canvas.add(textObject);
120
+ // debug mode
121
+ if (debugMode) {
122
+ const boundingBox = textObject.getBoundingRect();
123
+ const debugRect = new fabric.Rect({
124
+ left: boundingBox.left,
125
+ top: boundingBox.top,
126
+ width: boundingBox.width,
127
+ height: boundingBox.height,
128
+ stroke: 'red',
129
+ strokeWidth: 2,
130
+ fill: 'transparent',
131
+ });
132
+ canvas.add(debugRect);
133
+ }
134
+ return (0, canvasToImage_1.canvasToImage)(canvas);
135
+ }));
136
+ this.background = new jimp_1.Jimp({
137
+ height: options.height,
138
+ width: options.width,
139
+ color: options.color,
140
+ });
141
+ this.defaultFontFamily = options.defaultFontFamily;
142
+ this.defaultAssetsPath = options.defaultAssetsPath;
143
+ }
144
+ static new(options) {
145
+ return new Template(Object.assign(Object.assign({}, DEFAULT_TEMPLATE_OPTIONS), options));
146
+ }
147
+ shadowTemplate() {
148
+ return Template.new({
149
+ height: this.background.height,
150
+ width: this.background.width,
151
+ });
152
+ }
153
+ shadowBackground() {
154
+ return new jimp_1.Jimp({
155
+ width: this.background.width,
156
+ height: this.background.height,
157
+ });
158
+ }
159
+ layer(fn) {
160
+ this.layers.push(fn);
161
+ return this;
162
+ }
163
+ font(path, name) {
164
+ (0, canvas_1.registerFont)(path.toString(), {
165
+ family: name,
166
+ });
167
+ return this;
168
+ }
169
+ debug() {
170
+ this.debugMode = true;
171
+ return this;
172
+ }
173
+ renderLayers(entry) {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ return Promise.all(this.layers.map(layerFn => layerFn(entry, {
176
+ debugMode: this.debugMode,
177
+ width: this.background.width,
178
+ height: this.background.height,
179
+ })));
180
+ });
181
+ }
182
+ render(entry, options) {
183
+ return __awaiter(this, void 0, void 0, function* () {
184
+ const renderedLayers = yield this.renderLayers(entry);
185
+ return renderedLayers.reduce((acc, layerRender) => acc.composite(layerRender), this.background.clone());
186
+ });
187
+ }
188
+ renderAll(entries, options) {
189
+ return __awaiter(this, void 0, void 0, function* () {
190
+ const results = yield Promise.all(entries.map(entry => new Promise(resolve => this.render(entry, options).then(image => {
191
+ var _a;
192
+ if (!(options === null || options === void 0 ? void 0 : options.duplication)) {
193
+ return resolve([image]);
194
+ }
195
+ const copies = parseInt(entry[options.duplication.countField]);
196
+ if (Number.isNaN(copies)) {
197
+ return resolve([image]);
198
+ }
199
+ const deepCopy = (_a = options.duplication.deepCopy) !== null && _a !== void 0 ? _a : false;
200
+ return resolve(Array.from({ length: copies }, () => deepCopy ? image.clone() : image));
201
+ }))));
202
+ return (0, lodash_concat_1.default)(...results);
203
+ });
204
+ }
205
+ fromCsv(path, options) {
206
+ return __awaiter(this, void 0, void 0, function* () {
207
+ return new Promise((resolve, reject) => {
208
+ try {
209
+ const fileContent = fs.readFileSync(path, 'utf8');
210
+ const parsedData = (0, papaparse_1.parse)(fileContent, {
211
+ header: true,
212
+ skipEmptyLines: true,
213
+ transformHeader: (header, index) => (0, lodash_camelcase_1.default)(header !== null && header !== void 0 ? header : `header${index}`),
214
+ });
215
+ resolve(this.renderAll(parsedData.data, options));
216
+ }
217
+ catch (err) {
218
+ reject(err);
219
+ }
220
+ });
221
+ });
222
+ }
223
+ }
224
+ exports.Template = Template;
225
+ // TODO: Ledger of actions applied to the image like a logging feed
226
+ //# sourceMappingURL=template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../../../src/lib/template.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,yCAA8C;AAC9C,+BAAuC;AACvC,wEAAyC;AACzC,mDAAgD;AAChD,6DAA0D;AAE1D,uCAIsB;AAEtB,kEAAmC;AACnC,oDAAsC;AACtC,yDAAsD;AACtD,mCAAsC;AAetC,MAAM,wBAAwB,GAA4B;IACtD,MAAM,EAAE,IAAI;IACZ,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,IAAA,gBAAS,EAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;CACvC,CAAC;AAiBF,MAAa,QAAQ;IAOjB,sCAAsC;IACtC,YAAoB,OAAwB;QAP3B,WAAM,GAAyB,EAAE,C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AAM,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,CAChC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CACnC,CACJ,CAAC;YACN,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;CACJ;AA9OD,4BA8OC;AAED,mEAAmE"}
@@ -0,0 +1,10 @@
1
+ export type Point = {
2
+ x: number;
3
+ y: number;
4
+ };
5
+ export type Size = {
6
+ width: number;
7
+ height: number;
8
+ };
9
+ export declare const toPoint: (x: number, y: number) => Point;
10
+ export declare const toSize: (w: number, h: number) => Size;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toSize = exports.toPoint = void 0;
4
+ const toPoint = (x, y) => ({ x, y });
5
+ exports.toPoint = toPoint;
6
+ const toSize = (w, h) => ({ width: w, height: h });
7
+ exports.toSize = toSize;
8
+ //# sourceMappingURL=2d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"2d.js","sourceRoot":"","sources":["../../../../src/lib/types/2d.ts"],"names":[],"mappings":";;;AAUO,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,CAAS,EAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAAtD,QAAA,OAAO,WAA+C;AAE5D,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,CAAS,EAAQ,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;AAAnE,QAAA,MAAM,UAA6D"}
@@ -0,0 +1,44 @@
1
+ import { JimpInstance } from 'jimp';
2
+ import { Point, Size } from './2d';
3
+ export type ImageType = JimpInstance;
4
+ export type ImageLayerOptions = {
5
+ assetsPath?: string;
6
+ pathFn?: (path: string) => string;
7
+ };
8
+ export type ImagePosition = ImageAlignmentProps & ScaleProps & BoundingBox;
9
+ export type BoundingBox = {
10
+ start: Point;
11
+ size: Size;
12
+ };
13
+ export type ImageAlignmentProps = {
14
+ /**
15
+ * Overridden by xAlignment and/or yAlignment if provided.
16
+ * default `center`
17
+ */
18
+ alignment?: ImageAlignment;
19
+ /**
20
+ * default `center`
21
+ */
22
+ xAlignment?: ImageAlignment;
23
+ /**
24
+ * default `center`
25
+ */
26
+ yAlignment?: ImageAlignment;
27
+ };
28
+ export type ImageAlignment = 'start' | 'center' | 'end';
29
+ export declare const DEFAULT_IMAGE_ALIGNMENT: ImageAlignment;
30
+ /**
31
+ * Could be extended with 'x-stretch' and 'y-stretch'
32
+ */
33
+ export type ScaleMode = 'none' | 'keep-ratio' | 'stretch';
34
+ export declare const DEFAULT_SCALE_MODE: ScaleMode;
35
+ export type ScaleProps = {
36
+ /**
37
+ * Behavior of the content around a space
38
+ * that is bigger or smaller than necessary
39
+ * - `none`: no scaling
40
+ * - `keep-ration`: scale while preserving aspect ration
41
+ * - `stretch`: scale without preserving aspect ration
42
+ */
43
+ scale?: ScaleMode;
44
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SCALE_MODE = exports.DEFAULT_IMAGE_ALIGNMENT = void 0;
4
+ exports.DEFAULT_IMAGE_ALIGNMENT = 'center';
5
+ exports.DEFAULT_SCALE_MODE = 'none';
6
+ //# sourceMappingURL=image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.js","sourceRoot":"","sources":["../../../../src/lib/types/image.ts"],"names":[],"mappings":";;;AAqCa,QAAA,uBAAuB,GAAmB,QAAQ,CAAC;AAOnD,QAAA,kBAAkB,GAAc,MAAM,CAAC"}
@@ -0,0 +1,14 @@
1
+ export type RenderOptions<EntryType extends Record<string, string>> = {
2
+ duplication?: DuplicationOptions<EntryType>;
3
+ };
4
+ export type DuplicationOptions<EntryType extends Record<string, string>> = {
5
+ /**
6
+ * Field used for determining how many copies of this entry should be.
7
+ */
8
+ countField: keyof EntryType;
9
+ /**
10
+ * Return the copies are complete clones, instead of same reference.
11
+ * default false
12
+ */
13
+ deepCopy?: boolean;
14
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../../../../src/lib/types/render.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=scale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale.js","sourceRoot":"","sources":["../../../../src/lib/types/scale.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ import { BoundingBox } from './image';
2
+ export type TextLayerOptions = {
3
+ font?: {
4
+ /**
5
+ * Size of font is represented in pixels
6
+ */
7
+ size?: number;
8
+ /**
9
+ * Either use one supported by canvas
10
+ * or load a custom one before rendering
11
+ */
12
+ family?: string;
13
+ /**
14
+ * Warning: Not supported by all fonts
15
+ */
16
+ bold?: boolean;
17
+ /**
18
+ * Warning: Not supported by all fonts
19
+ */
20
+ italic?: boolean;
21
+ };
22
+ color?: string;
23
+ };
24
+ export type TextPosition = TextAlignmentProps & BoundingBox;
25
+ export type TextAlignmentProps = {
26
+ /**
27
+ * default `center`
28
+ */
29
+ textAlign?: 'left' | 'center' | 'right' | 'justify' | 'justify-left' | 'justify-center' | 'justify-right';
30
+ };
31
+ export declare const DEFAULT_TEXT_ALIGNMENT_PROPS: Required<TextAlignmentProps>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_TEXT_ALIGNMENT_PROPS = void 0;
4
+ exports.DEFAULT_TEXT_ALIGNMENT_PROPS = {
5
+ textAlign: 'center',
6
+ };
7
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../../src/lib/types/text.ts"],"names":[],"mappings":";;;AA0Ca,QAAA,4BAA4B,GAAiC;IACtE,SAAS,EAAE,QAAQ;CACtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { TextLayerOptions } from "../types/text";
2
+ export declare const buildFontString: (font: TextLayerOptions["font"], defaultFontFamily?: string) => string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildFontString = void 0;
4
+ const buildFontString = (font, defaultFontFamily) => {
5
+ var _a, _b, _c;
6
+ const fragments = [];
7
+ if (font === null || font === void 0 ? void 0 : font.bold) {
8
+ fragments.push('bold');
9
+ }
10
+ if (font === null || font === void 0 ? void 0 : font.italic) {
11
+ fragments.push('italic');
12
+ }
13
+ fragments.push(`${(_a = font === null || font === void 0 ? void 0 : font.size) !== null && _a !== void 0 ? _a : 16}px`);
14
+ fragments.push((_c = (_b = font === null || font === void 0 ? void 0 : font.family) !== null && _b !== void 0 ? _b : defaultFontFamily) !== null && _c !== void 0 ? _c : 'Arial');
15
+ return fragments.join(' ');
16
+ };
17
+ exports.buildFontString = buildFontString;
18
+ //# sourceMappingURL=buildFontString.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildFontString.js","sourceRoot":"","sources":["../../../../src/lib/utils/buildFontString.ts"],"names":[],"mappings":";;;AAEO,MAAM,eAAe,GAAG,CAC3B,IAA8B,EAC9B,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,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,mCAAI,iBAAiB,mCAAI,OAAO,CAAC,CAAC;IAC7D,OAAO,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/B,CAAC,CAAC;AAdW,QAAA,eAAe,mBAc1B"}
@@ -0,0 +1,3 @@
1
+ import { ImageType } from '../types/image';
2
+ import * as fabric from 'fabric/node';
3
+ export declare const canvasToImage: (canvas: fabric.Canvas) => Promise<ImageType>;
@@ -0,0 +1,28 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.canvasToImage = void 0;
13
+ const jimp_1 = require("jimp");
14
+ const canvasToImage = (canvas) => __awaiter(void 0, void 0, void 0, function* () {
15
+ const dataUrl = canvas.toDataURL({
16
+ format: 'png',
17
+ quality: 1,
18
+ multiplier: 1,
19
+ });
20
+ const image = yield jimp_1.Jimp.read(Buffer.from(dataUrl.split(',')[1], 'base64'));
21
+ return jimp_1.Jimp.fromBitmap({
22
+ data: image.bitmap.data,
23
+ width: image.bitmap.width,
24
+ height: image.bitmap.height
25
+ });
26
+ });
27
+ exports.canvasToImage = canvasToImage;
28
+ //# sourceMappingURL=canvasToImage.js.map