xpict 0.0.3 → 0.1.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.
Files changed (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -1
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.js +33 -0
  5. package/dist/layers/circle-layer.d.ts +15 -0
  6. package/dist/layers/circle-layer.js +37 -0
  7. package/dist/layers/group-layer.d.ts +14 -0
  8. package/dist/layers/group-layer.js +29 -0
  9. package/dist/layers/image-layer.d.ts +16 -0
  10. package/dist/layers/image-layer.js +28 -0
  11. package/dist/layers/index.d.ts +8 -0
  12. package/dist/layers/index.js +24 -0
  13. package/dist/layers/layer.d.ts +7 -0
  14. package/dist/layers/layer.js +12 -0
  15. package/dist/layers/line-layer.d.ts +21 -0
  16. package/dist/layers/line-layer.js +40 -0
  17. package/dist/layers/rectangle-layer.d.ts +16 -0
  18. package/dist/layers/rectangle-layer.js +53 -0
  19. package/dist/layers/repeat-layer.d.ts +15 -0
  20. package/dist/layers/repeat-layer.js +32 -0
  21. package/dist/layers/text-layer.d.ts +30 -0
  22. package/dist/layers/text-layer.js +68 -0
  23. package/dist/render-context.d.ts +6 -0
  24. package/dist/render-context.js +2 -0
  25. package/dist/template.d.ts +21 -0
  26. package/dist/template.js +48 -0
  27. package/dist/utils/commit-frame.d.ts +2 -0
  28. package/dist/utils/commit-frame.js +18 -0
  29. package/dist/utils/font-config.d.ts +11 -0
  30. package/dist/utils/font-config.js +11 -0
  31. package/dist/utils/resolve-axis.d.ts +3 -0
  32. package/dist/utils/resolve-axis.js +9 -0
  33. package/package.json +30 -72
  34. package/dev-scripts/generate-exports.cjs +0 -57
  35. package/dev-scripts/index.ts +0 -149
  36. package/dev-scripts/prepare-package-json.js +0 -31
  37. package/dist/cjs/actions.js +0 -232
  38. package/dist/cjs/constants.js +0 -26
  39. package/dist/cjs/index.js +0 -77
  40. package/dist/cjs/package.json +0 -1
  41. package/dist/cjs/utils/clone-image.util.ts.js +0 -12
  42. package/dist/cjs/utils/color.util.js +0 -21
  43. package/dist/cjs/utils/create-image.util.js +0 -18
  44. package/dist/cjs/utils/index.js +0 -14
  45. package/dist/cjs/utils/open-image.util.js +0 -10
  46. package/dist/esm/actions.js +0 -214
  47. package/dist/esm/constants.js +0 -20
  48. package/dist/esm/index.js +0 -71
  49. package/dist/esm/package.json +0 -1
  50. package/dist/esm/utils/clone-image.util.ts.js +0 -7
  51. package/dist/esm/utils/color.util.js +0 -17
  52. package/dist/esm/utils/create-image.util.js +0 -13
  53. package/dist/esm/utils/index.js +0 -4
  54. package/dist/esm/utils/open-image.util.js +0 -5
  55. package/dist/tsconfig.cjs.tsbuildinfo +0 -1
  56. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  57. package/dist/tsconfig.types.tsbuildinfo +0 -1
  58. package/dist/types/actions.d.ts +0 -77
  59. package/dist/types/constants.d.ts +0 -19
  60. package/dist/types/index.d.ts +0 -31
  61. package/dist/types/utils/clone-image.util.ts.d.ts +0 -4
  62. package/dist/types/utils/color.util.d.ts +0 -4
  63. package/dist/types/utils/create-image.util.d.ts +0 -12
  64. package/dist/types/utils/index.d.ts +0 -4
  65. package/dist/types/utils/open-image.util.d.ts +0 -3
  66. package/fonts/Curse Casual.ttf +0 -0
  67. package/fonts/Poppins-Black.ttf +0 -0
  68. package/fonts/Poppins-BlackItalic.ttf +0 -0
  69. package/fonts/Poppins-Bold.ttf +0 -0
  70. package/fonts/Poppins-BoldItalic.ttf +0 -0
  71. package/fonts/Poppins-ExtraBold.ttf +0 -0
  72. package/fonts/Poppins-ExtraBoldItalic.ttf +0 -0
  73. package/fonts/Poppins-ExtraLight.ttf +0 -0
  74. package/fonts/Poppins-ExtraLightItalic.ttf +0 -0
  75. package/fonts/Poppins-Italic.ttf +0 -0
  76. package/fonts/Poppins-Light.ttf +0 -0
  77. package/fonts/Poppins-LightItalic.ttf +0 -0
  78. package/fonts/Poppins-Medium.ttf +0 -0
  79. package/fonts/Poppins-MediumItalic.ttf +0 -0
  80. package/fonts/Poppins-Regular.ttf +0 -0
  81. package/fonts/Poppins-SemiBold.ttf +0 -0
  82. package/fonts/Poppins-SemiBoldItalic.ttf +0 -0
  83. package/fonts/Poppins-Thin.ttf +0 -0
  84. package/fonts/Poppins-ThinItalic.ttf +0 -0
  85. package/src/actions.ts +0 -390
  86. package/src/constants.ts +0 -30
  87. package/src/index.ts +0 -124
  88. package/src/utils/clone-image.util.ts.ts +0 -11
  89. package/src/utils/color.util.ts +0 -25
  90. package/src/utils/create-image.util.ts +0 -34
  91. package/src/utils/index.ts +0 -11
  92. package/src/utils/open-image.util.ts +0 -9
  93. package/tsconfig.cjs.json +0 -7
  94. package/tsconfig.esm.json +0 -7
  95. package/tsconfig.json +0 -15
  96. package/tsconfig.types.json +0 -8
package/dist/esm/index.js DELETED
@@ -1,71 +0,0 @@
1
- import { defautltTemplateAcitonType } from "./constants";
2
- import cloneImage from "./utils/clone-image.util.ts";
3
- function extractActions(actions) {
4
- const actionsLayersProccess = [];
5
- const actionsAfterLayersProccess = [];
6
- if (!actions) {
7
- actions = [];
8
- }
9
- for (const action of actions) {
10
- const actionType = typeof action === "function" ? defautltTemplateAcitonType : action.type;
11
- const actionFunc = typeof action === "function" ? action : action.func;
12
- if (actionType === "beforeLayersProccess") {
13
- actionsLayersProccess.push(actionFunc);
14
- }
15
- else {
16
- actionsAfterLayersProccess.push(actionFunc);
17
- }
18
- }
19
- return {
20
- before: actionsLayersProccess,
21
- after: actionsAfterLayersProccess
22
- };
23
- }
24
- async function processImageTemplate(template) {
25
- const actions = extractActions(template.actions);
26
- let image = template.image;
27
- for (const action of actions.before) {
28
- const imageResult = await action(image);
29
- image = await cloneImage(imageResult);
30
- }
31
- if (template.layers) {
32
- const layerImages = [];
33
- for (const layer of template.layers) {
34
- const currentImage = await processImageTemplate(layer.template);
35
- const currentImageBuffer = await currentImage.png().toBuffer();
36
- layerImages.push({
37
- input: currentImageBuffer,
38
- top: layer.y,
39
- left: layer.x
40
- });
41
- }
42
- image = image.composite(layerImages);
43
- }
44
- for (const action of actions.after) {
45
- const imageResult = await action(image);
46
- image = await cloneImage(imageResult);
47
- }
48
- return image;
49
- }
50
- function extendImageTemplate(template, extendTemplate) {
51
- const actions = [];
52
- const layers = [];
53
- if (template.layers) {
54
- layers.push(...template.layers);
55
- }
56
- if (extendTemplate.layers) {
57
- layers.push(...extendTemplate.layers);
58
- }
59
- if (template.actions) {
60
- actions.push(...template.actions);
61
- }
62
- if (extendTemplate.actions) {
63
- actions.push(...extendTemplate.actions);
64
- }
65
- return {
66
- image: template.image,
67
- actions: actions,
68
- layers: layers
69
- };
70
- }
71
- export { processImageTemplate, extendImageTemplate };
@@ -1 +0,0 @@
1
- {"type": "module"}
@@ -1,7 +0,0 @@
1
- import sharp from "sharp";
2
- async function cloneImage(image) {
3
- const imageBuffer = await image.toBuffer();
4
- const clonedImage = sharp(imageBuffer);
5
- return clonedImage;
6
- }
7
- export default cloneImage;
@@ -1,17 +0,0 @@
1
- function componentToHex(component) {
2
- const hex = component.toString(16);
3
- return hex.padStart(2, "0");
4
- }
5
- function rgb(red, green, blue) {
6
- return `#${componentToHex(red)}${componentToHex(green)}${componentToHex(blue)}`;
7
- }
8
- function rgba(red, green, blue, alpha) {
9
- const alphaHex = componentToHex(Math.round(alpha * 255));
10
- return `#${componentToHex(red)}${componentToHex(green)}${componentToHex(blue)}${alphaHex}`;
11
- }
12
- function hex(value) {
13
- const hexadecimalValue = value.toString(16);
14
- const fromatedHexadecimal = `#${hexadecimalValue.padStart(6, "0")}`;
15
- return fromatedHexadecimal;
16
- }
17
- export { rgb, rgba, hex };
@@ -1,13 +0,0 @@
1
- import sharp from "sharp";
2
- import { createImageDefaultOptions } from "../constants";
3
- function createImage({ width, height, fill = createImageDefaultOptions.fill, channels = createImageDefaultOptions.chnannels, format = createImageDefaultOptions.format, }) {
4
- return sharp({
5
- create: {
6
- width: width,
7
- height: height,
8
- channels: channels,
9
- background: fill,
10
- },
11
- })[format]();
12
- }
13
- export default createImage;
@@ -1,4 +0,0 @@
1
- import createImage from "./create-image.util";
2
- import { rgb, rgba, hex } from "./color.util";
3
- import openImage from "./open-image.util";
4
- export { createImage, openImage, rgba, rgb, hex };
@@ -1,5 +0,0 @@
1
- import sharp from "sharp";
2
- function openImage(filePath) {
3
- return sharp(filePath);
4
- }
5
- export default openImage;
@@ -1 +0,0 @@
1
- {"root":["../src/actions.ts","../src/constants.ts","../src/index.ts","../src/utils/clone-image.util.ts.ts","../src/utils/color.util.ts","../src/utils/create-image.util.ts","../src/utils/index.ts","../src/utils/open-image.util.ts"],"version":"5.6.2"}
@@ -1 +0,0 @@
1
- {"root":["../src/actions.ts","../src/constants.ts","../src/index.ts","../src/utils/clone-image.util.ts.ts","../src/utils/color.util.ts","../src/utils/create-image.util.ts","../src/utils/index.ts","../src/utils/open-image.util.ts"],"version":"5.6.2"}
@@ -1 +0,0 @@
1
- {"root":["../src/actions.ts","../src/constants.ts","../src/index.ts","../src/utils/clone-image.util.ts.ts","../src/utils/color.util.ts","../src/utils/create-image.util.ts","../src/utils/index.ts","../src/utils/open-image.util.ts"],"version":"5.6.2"}
@@ -1,77 +0,0 @@
1
- import sharp from "sharp";
2
- import { Image } from ".";
3
- declare function toGrayScale(grayscale?: boolean): (image: Image) => sharp.Sharp;
4
- export type CropImageOptions = sharp.Region;
5
- declare function cropImage(options: CropImageOptions): (image: Image) => sharp.Sharp;
6
- export type ResizeImageOptions = {
7
- width: number;
8
- height: number;
9
- fit: keyof sharp.FitEnum;
10
- };
11
- declare function resizeImage({ width, height, fit }: ResizeImageOptions): (image: Image) => sharp.Sharp;
12
- declare function rotateImage(angle: number): (image: Image) => sharp.Sharp;
13
- declare function blurImage(sigma?: number): (image: Image) => sharp.Sharp;
14
- declare function modulateSaturation(saturation: number): (image: Image) => sharp.Sharp;
15
- declare function modulateBrightness(brightness: number): (image: Image) => sharp.Sharp;
16
- declare function invertColors(): (image: Image) => sharp.Sharp;
17
- export type AddBorderOptions = {
18
- size: number;
19
- color?: string;
20
- };
21
- declare function addBorder({ size, color }: AddBorderOptions): (image: Image) => sharp.Sharp;
22
- declare function adjustContrast(contrast: number): (image: Image) => sharp.Sharp;
23
- declare function modulateOpacity(opacity: number): (image: Image) => sharp.Sharp;
24
- declare function flipImage(): (image: Image) => sharp.Sharp;
25
- declare function flopImage(): (image: Image) => sharp.Sharp;
26
- export type FontOptions = {
27
- size: number;
28
- color?: string;
29
- name?: string;
30
- filePath?: string;
31
- };
32
- export type TextAnchor = "top-left" | "top-center" | "top-right" | "middle-left" | "middle-center" | "middle-right" | "bottom-left" | "bottom-center" | "bottom-right";
33
- export type Stroke = {
34
- fill: string;
35
- width: number;
36
- };
37
- export type InsertTextOptions = {
38
- text: string;
39
- font: FontOptions;
40
- x: number;
41
- y: number;
42
- backgroundColor?: string;
43
- anchor?: TextAnchor;
44
- stroke?: Stroke;
45
- rotation?: number;
46
- };
47
- export type AnchorOffsets = Record<TextAnchor, {
48
- x: number;
49
- y: number;
50
- }>;
51
- declare function insertText({ text, font, x, y, backgroundColor, anchor, stroke, rotation }: InsertTextOptions): (image: Image) => Promise<sharp.Sharp>;
52
- export type InsertCircleOptions = {
53
- x: number;
54
- y: number;
55
- radius: number;
56
- fill: string;
57
- };
58
- declare function insertCircle({ x, y, radius, fill }: InsertCircleOptions): (image: Image) => Promise<sharp.Sharp>;
59
- export type InsertRectangleOptions = {
60
- x: number;
61
- y: number;
62
- width: number;
63
- height: number;
64
- fill: string;
65
- borderRadius?: number;
66
- };
67
- declare function insertRectangle({ x, y, width, height, fill, borderRadius }: InsertRectangleOptions): (image: Image) => Promise<sharp.Sharp>;
68
- export type InsertLineOptions = {
69
- x1: number;
70
- y1: number;
71
- x2: number;
72
- y2: number;
73
- color: string;
74
- width: number;
75
- };
76
- declare function insertLine({ x1, y1, x2, y2, color, width }: InsertLineOptions): (image: Image) => Promise<sharp.Sharp>;
77
- export { toGrayScale, cropImage, resizeImage, rotateImage, blurImage, modulateSaturation, modulateBrightness, invertColors, addBorder, adjustContrast, modulateOpacity, flipImage, flopImage, insertText, insertCircle, insertRectangle, insertLine };
@@ -1,19 +0,0 @@
1
- declare const colors: {
2
- black: string;
3
- white: string;
4
- };
5
- declare const defautltTemplateAcitonType = "beforeLayersProccess";
6
- declare const createImageDefaultOptions: {
7
- chnannels: number;
8
- fill: string;
9
- format: string;
10
- };
11
- declare const insertTextDefaultOptions: {
12
- font: {
13
- name: string;
14
- };
15
- anchor: string;
16
- backgroundColor: string;
17
- rotation: number;
18
- };
19
- export { colors, defautltTemplateAcitonType, createImageDefaultOptions, insertTextDefaultOptions };
@@ -1,31 +0,0 @@
1
- import sharp, { Sharp } from "sharp";
2
- export type Image = Sharp;
3
- export type ImageTemplateLayer = {
4
- x: number;
5
- y: number;
6
- template: ImageTemplate;
7
- };
8
- export type ImageTemplateActionFunction = (image: Image) => Image | Promise<Image>;
9
- export type ImageTemplateAction = ImageTemplateActionFunction | {
10
- type: "beforeLayersProccess" | "afterLayersProccess";
11
- func: ImageTemplateActionFunction;
12
- };
13
- export type ImageTemplate = {
14
- image: Image;
15
- actions?: ImageTemplateAction[];
16
- layers?: ImageTemplateLayer[];
17
- };
18
- export type ExtractActionsResult = {
19
- before: ImageTemplateActionFunction[];
20
- after: ImageTemplateActionFunction[];
21
- };
22
- declare function processImageTemplate(template: ImageTemplate): Promise<Image>;
23
- declare function extendImageTemplate(template: ImageTemplate, extendTemplate: Omit<ImageTemplate, "image">): {
24
- image: sharp.Sharp;
25
- actions: (ImageTemplateActionFunction | {
26
- type: "beforeLayersProccess" | "afterLayersProccess";
27
- func: ImageTemplateActionFunction;
28
- })[];
29
- layers: ImageTemplateLayer[];
30
- };
31
- export { processImageTemplate, extendImageTemplate };
@@ -1,4 +0,0 @@
1
- import sharp from "sharp";
2
- import { Image } from "..";
3
- declare function cloneImage(image: Image): Promise<sharp.Sharp>;
4
- export default cloneImage;
@@ -1,4 +0,0 @@
1
- declare function rgb(red: number, green: number, blue: number): string;
2
- declare function rgba(red: number, green: number, blue: number, alpha: number): string;
3
- declare function hex(value: number): string;
4
- export { rgb, rgba, hex };
@@ -1,12 +0,0 @@
1
- import sharp from "sharp";
2
- export type ImageChannels = 3 | 4;
3
- export type ImageFormat = "png" | "jpeg" | "webp" | "avif" | "gif";
4
- export type CreateImageOptions = {
5
- width: number;
6
- height: number;
7
- fill?: sharp.Color;
8
- channels?: ImageChannels;
9
- format?: ImageFormat;
10
- };
11
- declare function createImage({ width, height, fill, channels, format, }: CreateImageOptions): sharp.Sharp;
12
- export default createImage;
@@ -1,4 +0,0 @@
1
- import createImage from "./create-image.util";
2
- import { rgb, rgba, hex } from "./color.util";
3
- import openImage from "./open-image.util";
4
- export { createImage, openImage, rgba, rgb, hex };
@@ -1,3 +0,0 @@
1
- import { Image } from "..";
2
- declare function openImage(filePath: string): Image;
3
- export default openImage;
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file