@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.
Files changed (92) hide show
  1. package/build/src/lib/bundler.d.ts +1 -2
  2. package/build/src/lib/bundler.js.map +1 -1
  3. package/build/src/lib/replacement.d.ts +1 -2
  4. package/build/src/lib/replacement.js.map +1 -1
  5. package/build/src/lib/template.d.ts +13 -14
  6. package/build/src/lib/template.js +102 -37
  7. package/build/src/lib/template.js.map +1 -1
  8. package/build/src/lib/types/2d.d.ts +4 -5
  9. package/build/src/lib/types/boundingBox.d.ts +19 -0
  10. package/build/src/lib/types/boundingBox.js +3 -0
  11. package/build/src/lib/types/boundingBox.js.map +1 -0
  12. package/build/src/lib/types/containers.d.ts +13 -27
  13. package/build/src/lib/types/containers.js +3 -2
  14. package/build/src/lib/types/containers.js.map +1 -1
  15. package/build/src/lib/types/css.d.ts +4 -1
  16. package/build/src/lib/types/css.js +6 -3
  17. package/build/src/lib/types/css.js.map +1 -1
  18. package/build/src/lib/types/image.d.ts +17 -38
  19. package/build/src/lib/types/image.js +8 -2
  20. package/build/src/lib/types/image.js.map +1 -1
  21. package/build/src/lib/types/index.d.ts +3 -2
  22. package/build/src/lib/types/index.js +3 -2
  23. package/build/src/lib/types/index.js.map +1 -1
  24. package/build/src/lib/types/layer.d.ts +15 -0
  25. package/build/src/lib/types/layer.js +3 -0
  26. package/build/src/lib/types/layer.js.map +1 -0
  27. package/build/src/lib/types/position.d.ts +21 -0
  28. package/build/src/lib/types/position.js +42 -0
  29. package/build/src/lib/types/position.js.map +1 -0
  30. package/build/src/lib/types/scale.d.ts +9 -1
  31. package/build/src/lib/types/scale.js +2 -0
  32. package/build/src/lib/types/scale.js.map +1 -1
  33. package/build/src/lib/types/size.d.ts +4 -0
  34. package/build/src/lib/types/size.js +3 -0
  35. package/build/src/lib/types/size.js.map +1 -0
  36. package/build/src/lib/types/text.d.ts +29 -33
  37. package/build/src/lib/types/text.js +13 -4
  38. package/build/src/lib/types/text.js.map +1 -1
  39. package/build/src/lib/utils/buildFontString.d.ts +2 -2
  40. package/build/src/lib/utils/buildFontString.js.map +1 -1
  41. package/build/src/lib/utils/canvasToImage.d.ts +1 -1
  42. package/build/src/lib/utils/container.d.ts +4 -4
  43. package/build/src/lib/utils/container.js +52 -46
  44. package/build/src/lib/utils/container.js.map +1 -1
  45. package/build/src/lib/utils/drawBoundingBox.d.ts +1 -2
  46. package/build/src/lib/utils/drawBoundingBox.js +7 -47
  47. package/build/src/lib/utils/drawBoundingBox.js.map +1 -1
  48. package/build/src/lib/utils/htmlToImage.d.ts +3 -0
  49. package/build/src/lib/utils/htmlToImage.js +36 -0
  50. package/build/src/lib/utils/htmlToImage.js.map +1 -0
  51. package/build/src/lib/utils/index.d.ts +2 -1
  52. package/build/src/lib/utils/index.js +2 -1
  53. package/build/src/lib/utils/index.js.map +1 -1
  54. package/build/src/lib/utils/placeImage.d.ts +10 -5
  55. package/build/src/lib/utils/placeImage.js +25 -36
  56. package/build/src/lib/utils/placeImage.js.map +1 -1
  57. package/build/src/lib/utils/renderText.d.ts +3 -2
  58. package/build/src/lib/utils/renderText.js +12 -39
  59. package/build/src/lib/utils/renderText.js.map +1 -1
  60. package/build/src/lib/utils/toPx.d.ts +3 -0
  61. package/build/src/lib/utils/toPx.js +12 -0
  62. package/build/src/lib/utils/toPx.js.map +1 -0
  63. package/build/src/lib/utils/vNodeToImage.d.ts +4 -0
  64. package/build/src/lib/utils/vNodeToImage.js +36 -0
  65. package/build/src/lib/utils/vNodeToImage.js.map +1 -0
  66. package/build/src/test.js +55 -69
  67. package/build/src/test.js.map +1 -1
  68. package/package.json +6 -3
  69. package/roadmap.md +0 -1
  70. package/src/lib/bundler.ts +1 -2
  71. package/src/lib/replacement.ts +1 -2
  72. package/src/lib/template.ts +190 -68
  73. package/src/lib/types/boundingBox.ts +28 -0
  74. package/src/lib/types/containers.ts +55 -60
  75. package/src/lib/types/css.ts +32 -1
  76. package/src/lib/types/image.ts +32 -57
  77. package/src/lib/types/index.ts +3 -2
  78. package/src/lib/types/layer.ts +18 -0
  79. package/src/lib/types/scale.ts +11 -0
  80. package/src/lib/types/size.ts +4 -0
  81. package/src/lib/types/text.ts +47 -56
  82. package/src/lib/utils/buildFontString.ts +2 -2
  83. package/src/lib/utils/container.ts +118 -57
  84. package/src/lib/utils/drawBoundingBox.ts +19 -16
  85. package/src/lib/utils/htmlToImage.ts +24 -0
  86. package/src/lib/utils/index.ts +2 -1
  87. package/src/lib/utils/placeImage.ts +55 -58
  88. package/src/lib/utils/renderText.ts +19 -43
  89. package/src/lib/utils/toPx.ts +11 -0
  90. package/src/lib/types/2d.ts +0 -11
  91. package/src/lib/types/omitArgument.ts +0 -17
  92. 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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=layer.js.map
@@ -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,EAAE,CAAC;KACZ,CAAC;IACF,IAAI,QAAQ,IAAI,QAAQ,EAAE,CAAC;QACvB,IAAI,KAAK,IAAI,QAAQ,EAAE,CAAC;YACpB,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC;YACrB,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QACjC,CAAC;aAAM,CAAC;YACJ,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;YAClE,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QACjC,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC;QACrB,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC;IAChD,CAAC;IAED,IAAI,OAAO,IAAI,QAAQ,EAAE,CAAC;QACtB,IAAI,MAAM,IAAI,QAAQ,EAAE,CAAC;YACrB,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC;YACtB,GAAG,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;QAC/B,CAAC;aAAM,CAAC;YACJ,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;YAC/D,GAAG,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;QAC/B,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC;QACtB,GAAG,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC/C,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC,CAAC;AArCW,QAAA,aAAa,iBAqCxB"}
@@ -1 +1,9 @@
1
- export {};
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,3 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SCALE_MODE = void 0;
4
+ exports.DEFAULT_SCALE_MODE = 'none';
3
5
  //# sourceMappingURL=scale.js.map
@@ -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,4 @@
1
+ export type Size = {
2
+ width: number;
3
+ height: number;
4
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=size.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"size.js","sourceRoot":"","sources":["../../../../src/lib/types/size.ts"],"names":[],"mappings":""}
@@ -1,40 +1,36 @@
1
- import { BoundingBox } from './2d';
1
+ import type { RequiredDeep } from 'type-fest';
2
+ import { LayerOptions } from './layer';
2
3
  import { ReplacementMap } from './replacement';
3
- export type TextLayerProps<EntryType> = {
4
- key: keyof EntryType;
5
- position: TextPosition;
6
- options?: TextLayerOptions;
4
+ export type TextRef<EntryType> = {
5
+ key: string;
6
+ } | {
7
+ text: string;
8
+ } | {
9
+ textFn: (entry: EntryType) => string;
7
10
  };
8
- export type TextLayerOptions = {
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
- * default `center`
13
+ * Size of font is represented in pixels
32
14
  */
33
- xAlign?: 'left' | 'center' | 'right' | 'justify' | 'justify-left' | 'justify-center' | 'justify-right';
15
+ size?: number;
34
16
  /**
35
- * default `center`
17
+ * Either use one supported by canvas
18
+ * or load a custom one before rendering
36
19
  */
37
- yAlign?: 'left' | 'center' | 'right' | 'justify' | 'justify-left' | 'justify-center' | 'justify-right';
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 type TextPosition = BoundingBox;
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
- // TODO: all required
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
- xAlign: 'center',
7
- yAlign: 'center',
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":";;;AA8DA,qBAAqB;AACR,QAAA,0BAA0B,GAAqB;IACxD,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;CACnB,CAAC"}
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 { TextLayerOptions } from "../types/text";
2
- export declare const buildFontString: (font: TextLayerOptions["font"], defaultFontFamily?: string) => string;
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,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,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
+ {"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,3 @@
1
- import { ImageType } from '../types/image';
2
1
  import * as fabric from 'fabric/node';
2
+ import { ImageType } from '../types';
3
3
  export declare const canvasToImage: (canvas: fabric.Canvas) => Promise<ImageType>;
@@ -1,4 +1,4 @@
1
- import { BoundingBox } from '../types/2d';
2
- import { DirectionContainerOptions, PackingFn } from '../types/containers';
3
- export declare const vboxPackingFn: (position: BoundingBox, options?: DirectionContainerOptions) => PackingFn;
4
- export declare const hboxPackingFn: (position: BoundingBox, options?: DirectionContainerOptions) => PackingFn;
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 vboxPackingFn = (position, options) => (background, images) => directionalPackingFn({
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
- position,
26
+ box,
26
27
  options,
27
28
  });
28
29
  exports.vboxPackingFn = vboxPackingFn;
29
- const hboxPackingFn = (position, options) => (background, images) => directionalPackingFn({
30
+ const hboxPackingFn = (options) => (box, background, images) => directionalPackingFn({
30
31
  isVertical: false,
31
- background,
32
+ backgroundSize: background,
32
33
  images,
33
- position,
34
+ box,
34
35
  options,
35
36
  });
36
37
  exports.hboxPackingFn = hboxPackingFn;
37
- const directionalPackingFn = (_a) => __awaiter(void 0, [_a], void 0, function* ({ isVertical, background, images, position, options, }) {
38
- var _b, _c, _d, _e;
39
- const objectFit = SCALE_MODE_TO_OBJECT_FIT[(_b = options === null || options === void 0 ? void 0 : options.scale) !== null && _b !== void 0 ? _b : 'none'];
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
- display: 'flex',
57
- position: 'absolute',
58
- scale: 1,
59
- flexDirection: `${isVertical ? 'column' : 'row'}${(options === null || options === void 0 ? void 0 : options.reversed) ? '-reversed' : ''}`,
60
- gap: (0, types_1.toPx)((_c = options === null || options === void 0 ? void 0 : options.gap) !== null && _c !== void 0 ? _c : 0),
61
- // TODO: merge options and defaults
62
- justifyContent: (_d = options === null || options === void 0 ? void 0 : options.justifyContent) !== null && _d !== void 0 ? _d : containers_1.DEFAULT_DIRECTION_CONTAINER_OPTIONS.justifyContent,
63
- alignItems: (_e = options === null || options === void 0 ? void 0 : options.alignItems) !== null && _e !== void 0 ? _e : containers_1.DEFAULT_DIRECTION_CONTAINER_OPTIONS.alignItems,
64
- top: (0, types_1.toPx)(position.y),
65
- left: (0, types_1.toPx)(position.x),
66
- height: (0, types_1.toPx)(position.height),
67
- width: (0, types_1.toPx)(position.width),
68
- },
69
- }, children);
70
- const rootNode = (0, virtual_dom_1.create)(document);
71
- // TODO: extract this in a dif function
72
- const image = yield (0, node_html_to_image_1.default)({
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
- return jimp_1.Jimp.read(image);
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":";;;;;;;;;;;;;;;AACA,oDAK6B;AAE7B,6CAAgE;AAChE,4EAAiD;AACjD,+BAA4B;AAC5B,oCAAgC;AAEzB,MAAM,aAAa,GACtB,CAAC,QAAqB,EAAE,OAAmC,EAAa,EAAE,CAC1E,CAAC,UAAqB,EAAE,MAAwB,EAAE,EAAE,CAChD,oBAAoB,CAAC;IACjB,UAAU,EAAE,IAAI;IAChB,UAAU;IACV,MAAM;IACN,QAAQ;IACR,OAAO;CACV,CAAC,CAAC;AATE,QAAA,aAAa,iBASf;AAEJ,MAAM,aAAa,GACtB,CAAC,QAAqB,EAAE,OAAmC,EAAa,EAAE,CAC1E,CAAC,UAAqB,EAAE,MAAwB,EAAE,EAAE,CAChD,oBAAoB,CAAC;IACjB,UAAU,EAAE,KAAK;IACjB,UAAU;IACV,MAAM;IACN,QAAQ;IACR,OAAO;CACV,CAAC,CAAC;AATE,QAAA,aAAa,iBASf;AAEX,MAAM,oBAAoB,GAAG,KAYN,EAAE,4CAZW,EAChC,UAAU,EACV,UAAU,EACV,MAAM,EACN,QAAQ,EACR,OAAO,GAOV;;IACG,MAAM,SAAS,GAAG,wBAAwB,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,mCAAI,MAAM,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAG,MAAM,OAAO,CA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eAAC,EACd,KAAK,EACL;QACI,KAAK,kBACD,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,UAAU,EACpB,KAAK,EAAE,CAAC,EAER,aAAa,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,EAC7F,GAAG,EAAE,IAAA,WAAI,EAAC,aAAa,CAAC,GAAG,CAAC,EAC5B,cAAc,EAAE,aAAa,CAAC,cAAc,EAC5C,UAAU,EAAE,aAAa,CAAC,UAAU,IAEjC,IAAA,sBAAe,EAAC,GAAG,CAAC,CAC1B;KACJ,EACD,QAAQ,CACX,CAAC;IAEF,OAAO,IAAA,yBAAW,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAC7C,CAAC,CAAA,CAAC"}
@@ -1,3 +1,2 @@
1
- import { BoundingBox, Size } from '../types/2d';
2
- import { ImageType } from '../types/image';
1
+ import { ImageType, Size, BoundingBox } from '../types';
3
2
  export declare const drawBoundingBox: (box: BoundingBox, imageSize: Size) => Promise<ImageType>;
@@ -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 canvasToImage_1 = require("./canvasToImage");
47
- const fabric = __importStar(require("fabric/node"));
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 fabricCanvas = new fabric.Canvas(undefined, imageSize);
50
- const boundingBox = new fabric.Rect({
51
- left: box.x,
52
- top: box.y,
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAgD;AAEhD,oDAAsC;AAG/B,MAAM,eAAe,GAAG,CAC3B,GAAgB,EAChB,SAAe,EACG,EAAE;IACpB,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC7D,MAAM,WAAW,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC;QAChC,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,GAAG,EAAE,GAAG,CAAC,CAAC;QACV,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,CAAC;QACd,IAAI,EAAE,aAAa;KACtB,CAAC,CAAC;IACH,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC9B,OAAO,IAAA,6BAAa,EAAC,YAAY,CAAC,CAAC;AACvC,CAAC,CAAA,CAAC;AAhBW,QAAA,eAAe,mBAgB1B"}
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,3 @@
1
+ import { VNode } from 'virtual-dom';
2
+ import { ImageType, Size } from '../types';
3
+ export declare const htmlToImage: (document: VNode, backgroundSize: Size) => Promise<ImageType>;
@@ -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"}
@@ -1,6 +1,7 @@
1
1
  export * from './buildFontString';
2
- export * from './canvasToImage';
3
2
  export * from './container';
4
3
  export * from './drawBoundingBox';
5
4
  export * from './placeImage';
6
5
  export * from './renderText';
6
+ export * from './htmlToImage';
7
+ export * from './toPx';
@@ -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,kDAAgC;AAChC,8CAA4B;AAC5B,oDAAkC;AAClC,+CAA6B;AAC7B,+CAA6B"}
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, ImagePosition } from '../types/image';
2
- type PlaceImageProps = {
3
- background: ImageType;
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
- position: ImagePosition;
5
+ box: BoundingBox;
6
+ backgroundSize: {
7
+ width: number;
8
+ height: number;
9
+ };
10
+ options: RequiredDeep<ImageLayerOptions<EntryType>>;
6
11
  };
7
- export declare function placeImage({ background, image, position }: PlaceImageProps): Promise<ImageType>;
12
+ export declare const placeImage: <EntryType extends Record<string, string>>({ image, box, backgroundSize, options, }: PlaceImageProps<EntryType>) => Promise<ImageType>;
8
13
  export {};