apexify.js 4.2.10 → 4.3.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/dist/ai/utils.d.ts +2 -2
- package/dist/ai/utils.d.ts.map +1 -1
- package/dist/ai/utils.js +2 -1
- package/dist/ai/utils.js.map +1 -1
- package/dist/canvas/ApexPainter.d.ts.map +1 -1
- package/dist/canvas/ApexPainter.js +9 -3
- package/dist/canvas/ApexPainter.js.map +1 -1
- package/dist/canvas/utils/imageProperties.d.ts +5 -3
- package/dist/canvas/utils/imageProperties.d.ts.map +1 -1
- package/dist/canvas/utils/imageProperties.js +34 -19
- package/dist/canvas/utils/imageProperties.js.map +1 -1
- package/dist/canvas/utils/textProperties.d.ts +1 -0
- package/dist/canvas/utils/textProperties.d.ts.map +1 -1
- package/dist/canvas/utils/textProperties.js +58 -39
- package/dist/canvas/utils/textProperties.js.map +1 -1
- package/dist/canvas/utils/types.d.ts +30 -0
- package/dist/canvas/utils/types.d.ts.map +1 -1
- package/dist/canvas/utils/types.js.map +1 -1
- package/dist/index.d.ts +21 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +2 -9
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -2
- package/dist/utils.js.map +1 -1
- package/lib/ai/utils.ts +2 -1
- package/lib/canvas/ApexPainter.ts +10 -3
- package/lib/canvas/utils/imageProperties.ts +95 -79
- package/lib/canvas/utils/textProperties.ts +86 -57
- package/lib/canvas/utils/types.ts +27 -3
- package/lib/index.ts +8 -2
- package/lib/utils.ts +2 -3
- package/package.json +1 -1
|
@@ -7,9 +7,10 @@ import { TextObject } from "./types";
|
|
|
7
7
|
*/
|
|
8
8
|
export function drawText(ctx: any, textOptions: TextObject, size: any) {
|
|
9
9
|
ctx.save();
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
// Apply rotation if specified
|
|
11
12
|
if (textOptions.rotation && textOptions.rotation !== 0) {
|
|
12
|
-
ctx.translate(textOptions.x || 0, textOptions
|
|
13
|
+
ctx.translate(textOptions.x || 0, textOptions.y || 0);
|
|
13
14
|
ctx.rotate(textOptions.rotation * Math.PI / 180);
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -17,79 +18,75 @@ export function drawText(ctx: any, textOptions: TextObject, size: any) {
|
|
|
17
18
|
ctx.textAlign = textOptions.textAlign || 'left';
|
|
18
19
|
ctx.textBaseline = textOptions.textBaseline || 'alphabetic';
|
|
19
20
|
|
|
21
|
+
// Apply shadow
|
|
20
22
|
if (textOptions.shadow) {
|
|
21
23
|
const { color, offsetX, offsetY, blur, opacity } = textOptions.shadow;
|
|
22
24
|
ctx.shadowColor = color || "transparent";
|
|
23
25
|
ctx.shadowOffsetX = offsetX || 0;
|
|
24
26
|
ctx.shadowOffsetY = offsetY || 0;
|
|
25
27
|
ctx.shadowBlur = blur || 0;
|
|
26
|
-
ctx.globalAlpha = opacity ||
|
|
28
|
+
ctx.globalAlpha = opacity || 1;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
// Apply opacity
|
|
32
|
+
if (textOptions.opacity !== undefined) {
|
|
33
|
+
if (textOptions.opacity > 1 || textOptions.opacity < 0)
|
|
34
|
+
throw new Error("Text opacity Error: the value can't be smaller than 0 or bigger than 1.");
|
|
31
35
|
ctx.globalAlpha = textOptions.opacity;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
const textWidth = ctx.measureText(textOptions.text).width;
|
|
39
|
+
const textHeight = textOptions.fontSize || 16; // Rough estimate for height
|
|
40
|
+
|
|
41
|
+
// Apply gradient fill
|
|
42
|
+
if (textOptions.gradient) {
|
|
43
|
+
const gradientFill = createGradient(
|
|
44
|
+
ctx,
|
|
45
|
+
textOptions.gradient,
|
|
46
|
+
textOptions.x || 0,
|
|
47
|
+
textOptions.y || 0 - textHeight,
|
|
48
|
+
(textOptions.x || 0) + textWidth,
|
|
49
|
+
(textOptions.y || 0)
|
|
50
|
+
);
|
|
51
|
+
console.log("Gradient Fill Created:", gradientFill);
|
|
52
|
+
ctx.fillStyle = gradientFill;
|
|
38
53
|
} else {
|
|
54
|
+
ctx.fillStyle = textOptions.color || 'darkgray';
|
|
55
|
+
}
|
|
39
56
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
textOptions.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
ctx.fillStyle = gradient;
|
|
54
|
-
} else if (textOptions.gradient.type === 'radial') {
|
|
55
|
-
const gradient = ctx.createRadialGradient(
|
|
56
|
-
textOptions.gradient?.startX || 0,
|
|
57
|
-
textOptions.gradient?.startY || 10,
|
|
58
|
-
textOptions.gradient?.startRadius || 0,
|
|
59
|
-
textOptions.gradient?.endX || 20,
|
|
60
|
-
textOptions.gradient?.endY || 30,
|
|
61
|
-
textOptions.gradient?.endRadius || 30
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
textOptions.gradient.colors.forEach(({ stop, color }) => {
|
|
65
|
-
gradient.addColorStop(stop, color);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
ctx.fillStyle = gradient;
|
|
69
|
-
} else {
|
|
70
|
-
throw new Error("Error Gradient: Invalid gradient type. Valid types: `radial` or `linear`.")
|
|
71
|
-
}
|
|
57
|
+
// Apply stroke with gradient
|
|
58
|
+
if (textOptions.outlined || textOptions.stroke) {
|
|
59
|
+
if (textOptions.stroke?.gradient) {
|
|
60
|
+
const gradientStroke = createGradient(
|
|
61
|
+
ctx,
|
|
62
|
+
textOptions.stroke.gradient,
|
|
63
|
+
textOptions.x || 0,
|
|
64
|
+
textOptions.y || 0 - textHeight,
|
|
65
|
+
(textOptions.x || 0) + textWidth,
|
|
66
|
+
(textOptions.y || 0)
|
|
67
|
+
);
|
|
68
|
+
console.log("Gradient Stroke Created:", gradientStroke);
|
|
69
|
+
ctx.strokeStyle = gradientStroke;
|
|
72
70
|
} else {
|
|
73
|
-
ctx.
|
|
71
|
+
ctx.strokeStyle = textOptions.stroke?.color || textOptions.color;
|
|
74
72
|
}
|
|
75
|
-
|
|
73
|
+
ctx.lineWidth = textOptions.stroke?.width || 1;
|
|
74
|
+
ctx.strokeText(textOptions.text, textOptions.x || 0, textOptions.y || 0);
|
|
76
75
|
}
|
|
77
76
|
|
|
77
|
+
// Draw the text
|
|
78
78
|
if (textOptions.maxWidth) {
|
|
79
79
|
WrappedText(ctx, textOptions.text || 'Hello World', textOptions.x || 0, textOptions.y || 0, textOptions.maxWidth, textOptions);
|
|
80
80
|
} else {
|
|
81
|
-
if (textOptions.
|
|
82
|
-
ctx.
|
|
81
|
+
if (!textOptions.rotation) {
|
|
82
|
+
ctx.fillText(textOptions.text, textOptions.x || 0, textOptions.y || 0);
|
|
83
83
|
} else {
|
|
84
|
-
|
|
85
|
-
if (textOptions.rotation) ctx.fillText(textOptions.text, 0, 0);
|
|
86
|
-
|
|
84
|
+
ctx.fillText(textOptions.text, 0, 0);
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
|
|
90
88
|
ctx.restore();
|
|
91
89
|
}
|
|
92
|
-
|
|
93
90
|
/**
|
|
94
91
|
* Draws wrapped text on the canvas context.
|
|
95
92
|
* @param ctx The canvas rendering context.
|
|
@@ -107,11 +104,10 @@ export function WrappedText(ctx: any, text: string, x: number, y: number, maxWid
|
|
|
107
104
|
|
|
108
105
|
ctx.save();
|
|
109
106
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
ctx.
|
|
113
|
-
|
|
114
|
-
ctx.fillStyle = textOptions.color || 'darkgray';
|
|
107
|
+
ctx.fillStyle = textOptions.color || 'darkgray';
|
|
108
|
+
if (textOptions.outlined || textOptions.stroke) {
|
|
109
|
+
ctx.strokeStyle = textOptions.stroke?.color || textOptions.color;
|
|
110
|
+
ctx.lineWidth = textOptions.stroke?.width || 1;
|
|
115
111
|
}
|
|
116
112
|
|
|
117
113
|
if (textOptions.rotation && textOptions.rotation !== 0) {
|
|
@@ -128,7 +124,7 @@ export function WrappedText(ctx: any, text: string, x: number, y: number, maxWid
|
|
|
128
124
|
|
|
129
125
|
if (testWidth > maxWidth && n > 0) {
|
|
130
126
|
const adjustedY = y + lineHeight;
|
|
131
|
-
if (textOptions.outlined) {
|
|
127
|
+
if (textOptions.outlined || textOptions.stroke) {
|
|
132
128
|
ctx.strokeText(currentLine.trim(), x, adjustedY);
|
|
133
129
|
} else {
|
|
134
130
|
ctx.fillText(currentLine.trim(), x, adjustedY);
|
|
@@ -141,11 +137,44 @@ export function WrappedText(ctx: any, text: string, x: number, y: number, maxWid
|
|
|
141
137
|
}
|
|
142
138
|
|
|
143
139
|
const adjustedY = y + lineHeight;
|
|
144
|
-
if (textOptions.outlined) {
|
|
140
|
+
if (textOptions.outlined || textOptions.stroke) {
|
|
145
141
|
ctx.strokeText(currentLine.trim(), x, adjustedY);
|
|
146
142
|
} else {
|
|
147
143
|
ctx.fillText(currentLine.trim(), x, adjustedY);
|
|
148
144
|
}
|
|
149
145
|
|
|
150
146
|
ctx.restore();
|
|
151
|
-
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function createGradient(ctx: any, gradientOptions: any, startX: number, startY: number, endX: number, endY: number) {
|
|
150
|
+
if (!gradientOptions || !gradientOptions.type || !gradientOptions.colors) {
|
|
151
|
+
throw new Error("Invalid gradient options. Provide a valid object with type and colors properties.");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!Array.isArray(gradientOptions.colors)) {
|
|
155
|
+
throw new Error("Invalid gradient options. The colors property should be an array of color stops.");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let gradient;
|
|
159
|
+
if (gradientOptions.type === "linear") {
|
|
160
|
+
gradient = ctx.createLinearGradient(startX, startY, endX, endY);
|
|
161
|
+
} else if (gradientOptions.type === "radial") {
|
|
162
|
+
gradient = ctx.createRadialGradient(
|
|
163
|
+
gradientOptions.startX || startX,
|
|
164
|
+
gradientOptions.startY || startY,
|
|
165
|
+
gradientOptions.startRadius || 0,
|
|
166
|
+
gradientOptions.endX || endX,
|
|
167
|
+
gradientOptions.endY || endY,
|
|
168
|
+
gradientOptions.endRadius || 0
|
|
169
|
+
);
|
|
170
|
+
} else {
|
|
171
|
+
throw new Error('Unsupported gradient type. Use "linear" or "radial".');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
for (const colorStop of gradientOptions.colors) {
|
|
175
|
+
console.log(`Adding color stop: ${colorStop.stop} ${colorStop.color}`);
|
|
176
|
+
gradient.addColorStop(colorStop.stop, colorStop.color);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return gradient;
|
|
180
|
+
}
|
|
@@ -88,6 +88,7 @@ export interface ImageProperties {
|
|
|
88
88
|
y?: number;
|
|
89
89
|
isFilled?: boolean;
|
|
90
90
|
color?: string;
|
|
91
|
+
opacity?: number;
|
|
91
92
|
gradient?: {
|
|
92
93
|
type?: 'linear' | 'radial';
|
|
93
94
|
startX?: number;
|
|
@@ -99,12 +100,24 @@ export interface ImageProperties {
|
|
|
99
100
|
colors?: { stop?: number; color?: string }[];
|
|
100
101
|
};
|
|
101
102
|
rotation?: number;
|
|
102
|
-
borderRadius?: number | "circular"
|
|
103
|
+
borderRadius?: number | "circular";
|
|
104
|
+
borderPosition?: 'all' | 'top' | 'left' | 'right' | 'bottom';
|
|
103
105
|
stroke?: {
|
|
104
106
|
color?: string;
|
|
105
107
|
width?: number;
|
|
106
108
|
position?: number;
|
|
107
|
-
borderRadius?: number | "circular"
|
|
109
|
+
borderRadius?: number | "circular";
|
|
110
|
+
borderPosition?: 'all' | 'top' | 'left' | 'right' | 'bottom';
|
|
111
|
+
gradient?: {
|
|
112
|
+
type: 'linear' | 'radial';
|
|
113
|
+
startX?: number;
|
|
114
|
+
startY?: number;
|
|
115
|
+
endX?: number;
|
|
116
|
+
endY?: number;
|
|
117
|
+
startRadius?: number;
|
|
118
|
+
endRadius?: number;
|
|
119
|
+
colors: { stop: number; color: string }[];
|
|
120
|
+
};
|
|
108
121
|
};
|
|
109
122
|
shadow?: {
|
|
110
123
|
color?: string;
|
|
@@ -112,7 +125,8 @@ export interface ImageProperties {
|
|
|
112
125
|
offsetY?: number;
|
|
113
126
|
blur?: number;
|
|
114
127
|
opacity?: number;
|
|
115
|
-
borderRadius?: number | "circular"
|
|
128
|
+
borderRadius?: number | "circular",
|
|
129
|
+
borderPosition?: 'all' | 'top' | 'left' | 'right' | 'bottom';
|
|
116
130
|
};
|
|
117
131
|
};
|
|
118
132
|
|
|
@@ -153,6 +167,16 @@ export interface TextObject {
|
|
|
153
167
|
stroke?: {
|
|
154
168
|
color?: string;
|
|
155
169
|
width?: number;
|
|
170
|
+
gradient?: {
|
|
171
|
+
type: 'linear' | 'radial';
|
|
172
|
+
startX?: number;
|
|
173
|
+
startY?: number;
|
|
174
|
+
endX?: number;
|
|
175
|
+
endY?: number;
|
|
176
|
+
startRadius?: number;
|
|
177
|
+
endRadius?: number;
|
|
178
|
+
colors: { stop: number; color: string }[];
|
|
179
|
+
}
|
|
156
180
|
};
|
|
157
181
|
rotation?: number;
|
|
158
182
|
opacity?: number;
|
package/lib/index.ts
CHANGED
|
@@ -28,9 +28,15 @@ fetch("https://registry.npmjs.com/-/v1/search?text=apexify.js")
|
|
|
28
28
|
})
|
|
29
29
|
.catch(function(error: any) {});
|
|
30
30
|
|
|
31
|
-
import { ApexAI, ApexChat, ApexImagine, ApexPainter } from "./utils";
|
|
31
|
+
import { ApexAI, ApexChat, ApexImagine, ApexPainter, ApexListener } from "./utils";
|
|
32
32
|
import { validOptions } from "./ai/functions/validOptions";
|
|
33
33
|
export * from './canvas/utils/utils';
|
|
34
34
|
export * from './canvas/utils/types';
|
|
35
35
|
|
|
36
|
-
export { ApexPainter, ApexAI, ApexImagine, ApexChat, validOptions };
|
|
36
|
+
export { ApexPainter, ApexAI, ApexImagine, ApexChat, validOptions, ApexListener };
|
|
37
|
+
|
|
38
|
+
const Apexify = {
|
|
39
|
+
ApexPainter, ApexAI, ApexImagine, ApexChat, validOptions, ApexListener
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default Apexify;
|
package/lib/utils.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ApexPainter } from "./canvas/ApexPainter";
|
|
2
2
|
import { ApexAI } from "./ai/ApexAI";
|
|
3
|
-
import { ApexChat, ApexImagine } from "./ai/utils";
|
|
3
|
+
import { ApexChat, ApexImagine, ApexListener } from "./ai/utils";
|
|
4
4
|
|
|
5
|
-
export { ApexPainter, ApexAI, ApexImagine, ApexChat };
|
|
6
|
-
export default { ApexPainter, ApexAI, ApexImagine, ApexChat };
|
|
5
|
+
export { ApexPainter, ApexAI, ApexImagine, ApexChat, ApexListener };
|
|
7
6
|
|
|
8
7
|
|