apexify.js 4.9.28 → 5.0.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.
- package/README.md +727 -456
- package/dist/cjs/Canvas/ApexPainter.d.ts +96 -145
- package/dist/cjs/Canvas/ApexPainter.d.ts.map +1 -1
- package/dist/cjs/Canvas/ApexPainter.js +1416 -420
- package/dist/cjs/Canvas/ApexPainter.js.map +1 -1
- package/dist/cjs/Canvas/utils/Charts/charts.d.ts +7 -2
- package/dist/cjs/Canvas/utils/Charts/charts.d.ts.map +1 -1
- package/dist/cjs/Canvas/utils/Charts/charts.js +3 -1
- package/dist/cjs/Canvas/utils/Charts/charts.js.map +1 -1
- package/dist/cjs/Canvas/utils/Custom/advancedLines.d.ts +75 -0
- package/dist/cjs/Canvas/utils/Custom/advancedLines.d.ts.map +1 -0
- package/dist/cjs/Canvas/utils/Custom/advancedLines.js +263 -0
- package/dist/cjs/Canvas/utils/Custom/advancedLines.js.map +1 -0
- package/dist/cjs/Canvas/utils/Custom/customLines.d.ts +2 -1
- package/dist/cjs/Canvas/utils/Custom/customLines.d.ts.map +1 -1
- package/dist/cjs/Canvas/utils/Custom/customLines.js +73 -6
- package/dist/cjs/Canvas/utils/Custom/customLines.js.map +1 -1
- package/dist/cjs/Canvas/utils/General/batchOperations.d.ts +17 -0
- package/dist/cjs/Canvas/utils/General/batchOperations.d.ts.map +1 -0
- package/dist/cjs/Canvas/utils/General/batchOperations.js +88 -0
- package/dist/cjs/Canvas/utils/General/batchOperations.js.map +1 -0
- package/dist/cjs/Canvas/utils/General/general functions.d.ts +25 -3
- package/dist/cjs/Canvas/utils/General/general functions.d.ts.map +1 -1
- package/dist/cjs/Canvas/utils/General/general functions.js +37 -9
- package/dist/cjs/Canvas/utils/General/general functions.js.map +1 -1
- package/dist/cjs/Canvas/utils/General/imageCompression.d.ts +19 -0
- package/dist/cjs/Canvas/utils/General/imageCompression.d.ts.map +1 -0
- package/dist/cjs/Canvas/utils/General/imageCompression.js +262 -0
- package/dist/cjs/Canvas/utils/General/imageCompression.js.map +1 -0
- package/dist/cjs/Canvas/utils/General/imageStitching.d.ts +20 -0
- package/dist/cjs/Canvas/utils/General/imageStitching.d.ts.map +1 -0
- package/dist/cjs/Canvas/utils/General/imageStitching.js +227 -0
- package/dist/cjs/Canvas/utils/General/imageStitching.js.map +1 -0
- package/dist/cjs/Canvas/utils/Image/imageEffects.d.ts +37 -0
- package/dist/cjs/Canvas/utils/Image/imageEffects.d.ts.map +1 -0
- package/dist/cjs/Canvas/utils/Image/imageEffects.js +128 -0
- package/dist/cjs/Canvas/utils/Image/imageEffects.js.map +1 -0
- package/dist/cjs/Canvas/utils/Image/imageMasking.d.ts +67 -0
- package/dist/cjs/Canvas/utils/Image/imageMasking.d.ts.map +1 -0
- package/dist/cjs/Canvas/utils/Image/imageMasking.js +276 -0
- package/dist/cjs/Canvas/utils/Image/imageMasking.js.map +1 -0
- package/dist/cjs/Canvas/utils/Image/imageProperties.d.ts.map +1 -1
- package/dist/cjs/Canvas/utils/Image/imageProperties.js +181 -2
- package/dist/cjs/Canvas/utils/Image/imageProperties.js.map +1 -1
- package/dist/cjs/Canvas/utils/Patterns/enhancedPatternRenderer.d.ts.map +1 -1
- package/dist/cjs/Canvas/utils/Patterns/enhancedPatternRenderer.js +16 -8
- package/dist/cjs/Canvas/utils/Patterns/enhancedPatternRenderer.js.map +1 -1
- package/dist/cjs/Canvas/utils/Texts/enhancedTextRenderer.d.ts +33 -0
- package/dist/cjs/Canvas/utils/Texts/enhancedTextRenderer.d.ts.map +1 -1
- package/dist/cjs/Canvas/utils/Texts/enhancedTextRenderer.js +237 -32
- package/dist/cjs/Canvas/utils/Texts/enhancedTextRenderer.js.map +1 -1
- package/dist/cjs/Canvas/utils/Texts/textPathRenderer.d.ts +17 -0
- package/dist/cjs/Canvas/utils/Texts/textPathRenderer.d.ts.map +1 -0
- package/dist/cjs/Canvas/utils/Texts/textPathRenderer.js +233 -0
- package/dist/cjs/Canvas/utils/Texts/textPathRenderer.js.map +1 -0
- package/dist/cjs/Canvas/utils/types.d.ts +171 -10
- package/dist/cjs/Canvas/utils/types.d.ts.map +1 -1
- package/dist/cjs/Canvas/utils/types.js.map +1 -1
- package/dist/cjs/Canvas/utils/utils.d.ts +9 -2
- package/dist/cjs/Canvas/utils/utils.d.ts.map +1 -1
- package/dist/cjs/Canvas/utils/utils.js +32 -1
- package/dist/cjs/Canvas/utils/utils.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/Canvas/ApexPainter.d.ts +96 -145
- package/dist/esm/Canvas/ApexPainter.d.ts.map +1 -1
- package/dist/esm/Canvas/ApexPainter.js +1416 -420
- package/dist/esm/Canvas/ApexPainter.js.map +1 -1
- package/dist/esm/Canvas/utils/Charts/charts.d.ts +7 -2
- package/dist/esm/Canvas/utils/Charts/charts.d.ts.map +1 -1
- package/dist/esm/Canvas/utils/Charts/charts.js +3 -1
- package/dist/esm/Canvas/utils/Charts/charts.js.map +1 -1
- package/dist/esm/Canvas/utils/Custom/advancedLines.d.ts +75 -0
- package/dist/esm/Canvas/utils/Custom/advancedLines.d.ts.map +1 -0
- package/dist/esm/Canvas/utils/Custom/advancedLines.js +263 -0
- package/dist/esm/Canvas/utils/Custom/advancedLines.js.map +1 -0
- package/dist/esm/Canvas/utils/Custom/customLines.d.ts +2 -1
- package/dist/esm/Canvas/utils/Custom/customLines.d.ts.map +1 -1
- package/dist/esm/Canvas/utils/Custom/customLines.js +73 -6
- package/dist/esm/Canvas/utils/Custom/customLines.js.map +1 -1
- package/dist/esm/Canvas/utils/General/batchOperations.d.ts +17 -0
- package/dist/esm/Canvas/utils/General/batchOperations.d.ts.map +1 -0
- package/dist/esm/Canvas/utils/General/batchOperations.js +88 -0
- package/dist/esm/Canvas/utils/General/batchOperations.js.map +1 -0
- package/dist/esm/Canvas/utils/General/general functions.d.ts +25 -3
- package/dist/esm/Canvas/utils/General/general functions.d.ts.map +1 -1
- package/dist/esm/Canvas/utils/General/general functions.js +37 -9
- package/dist/esm/Canvas/utils/General/general functions.js.map +1 -1
- package/dist/esm/Canvas/utils/General/imageCompression.d.ts +19 -0
- package/dist/esm/Canvas/utils/General/imageCompression.d.ts.map +1 -0
- package/dist/esm/Canvas/utils/General/imageCompression.js +262 -0
- package/dist/esm/Canvas/utils/General/imageCompression.js.map +1 -0
- package/dist/esm/Canvas/utils/General/imageStitching.d.ts +20 -0
- package/dist/esm/Canvas/utils/General/imageStitching.d.ts.map +1 -0
- package/dist/esm/Canvas/utils/General/imageStitching.js +227 -0
- package/dist/esm/Canvas/utils/General/imageStitching.js.map +1 -0
- package/dist/esm/Canvas/utils/Image/imageEffects.d.ts +37 -0
- package/dist/esm/Canvas/utils/Image/imageEffects.d.ts.map +1 -0
- package/dist/esm/Canvas/utils/Image/imageEffects.js +128 -0
- package/dist/esm/Canvas/utils/Image/imageEffects.js.map +1 -0
- package/dist/esm/Canvas/utils/Image/imageMasking.d.ts +67 -0
- package/dist/esm/Canvas/utils/Image/imageMasking.d.ts.map +1 -0
- package/dist/esm/Canvas/utils/Image/imageMasking.js +276 -0
- package/dist/esm/Canvas/utils/Image/imageMasking.js.map +1 -0
- package/dist/esm/Canvas/utils/Image/imageProperties.d.ts.map +1 -1
- package/dist/esm/Canvas/utils/Image/imageProperties.js +181 -2
- package/dist/esm/Canvas/utils/Image/imageProperties.js.map +1 -1
- package/dist/esm/Canvas/utils/Patterns/enhancedPatternRenderer.d.ts.map +1 -1
- package/dist/esm/Canvas/utils/Patterns/enhancedPatternRenderer.js +16 -8
- package/dist/esm/Canvas/utils/Patterns/enhancedPatternRenderer.js.map +1 -1
- package/dist/esm/Canvas/utils/Texts/enhancedTextRenderer.d.ts +33 -0
- package/dist/esm/Canvas/utils/Texts/enhancedTextRenderer.d.ts.map +1 -1
- package/dist/esm/Canvas/utils/Texts/enhancedTextRenderer.js +237 -32
- package/dist/esm/Canvas/utils/Texts/enhancedTextRenderer.js.map +1 -1
- package/dist/esm/Canvas/utils/Texts/textPathRenderer.d.ts +17 -0
- package/dist/esm/Canvas/utils/Texts/textPathRenderer.d.ts.map +1 -0
- package/dist/esm/Canvas/utils/Texts/textPathRenderer.js +233 -0
- package/dist/esm/Canvas/utils/Texts/textPathRenderer.js.map +1 -0
- package/dist/esm/Canvas/utils/types.d.ts +171 -10
- package/dist/esm/Canvas/utils/types.d.ts.map +1 -1
- package/dist/esm/Canvas/utils/types.js.map +1 -1
- package/dist/esm/Canvas/utils/utils.d.ts +9 -2
- package/dist/esm/Canvas/utils/utils.d.ts.map +1 -1
- package/dist/esm/Canvas/utils/utils.js +32 -1
- package/dist/esm/Canvas/utils/utils.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/Canvas/ApexPainter.ts +1309 -267
- package/lib/Canvas/utils/Charts/charts.ts +16 -7
- package/lib/Canvas/utils/Custom/advancedLines.ts +335 -0
- package/lib/Canvas/utils/Custom/customLines.ts +84 -9
- package/lib/Canvas/utils/General/batchOperations.ts +103 -0
- package/lib/Canvas/utils/General/general functions.ts +85 -41
- package/lib/Canvas/utils/General/imageCompression.ts +316 -0
- package/lib/Canvas/utils/General/imageStitching.ts +252 -0
- package/lib/Canvas/utils/Image/imageEffects.ts +175 -0
- package/lib/Canvas/utils/Image/imageMasking.ts +335 -0
- package/lib/Canvas/utils/Image/imageProperties.ts +207 -2
- package/lib/Canvas/utils/Patterns/enhancedPatternRenderer.ts +455 -444
- package/lib/Canvas/utils/Texts/enhancedTextRenderer.ts +274 -36
- package/lib/Canvas/utils/Texts/textPathRenderer.ts +320 -0
- package/lib/Canvas/utils/types.ts +173 -10
- package/lib/Canvas/utils/utils.ts +49 -2
- package/package.json +69 -34
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { SKRSContext2D } from '@napi-rs/canvas';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Renders text along a path
|
|
5
|
+
* @param ctx - Canvas 2D context
|
|
6
|
+
* @param text - Text to render
|
|
7
|
+
* @param pathConfig - Path configuration
|
|
8
|
+
* @param offset - Distance from path
|
|
9
|
+
*/
|
|
10
|
+
export function renderTextOnPath(
|
|
11
|
+
ctx: SKRSContext2D,
|
|
12
|
+
text: string,
|
|
13
|
+
pathConfig: {
|
|
14
|
+
type: 'line' | 'arc' | 'bezier' | 'quadratic';
|
|
15
|
+
points: Array<{ x: number; y: number }>;
|
|
16
|
+
offset?: number;
|
|
17
|
+
},
|
|
18
|
+
offset: number = 0
|
|
19
|
+
): void {
|
|
20
|
+
const path = createPath(ctx, pathConfig);
|
|
21
|
+
const pathLength = getPathLength(path, pathConfig);
|
|
22
|
+
|
|
23
|
+
ctx.save();
|
|
24
|
+
|
|
25
|
+
// Measure text to distribute along path
|
|
26
|
+
const metrics = ctx.measureText(text);
|
|
27
|
+
const textWidth = metrics.width;
|
|
28
|
+
const charWidth = textWidth / text.length;
|
|
29
|
+
|
|
30
|
+
let currentDistance = 0;
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < text.length; i++) {
|
|
33
|
+
const char = text[i];
|
|
34
|
+
const charDistance = currentDistance + charWidth / 2;
|
|
35
|
+
|
|
36
|
+
if (charDistance <= pathLength) {
|
|
37
|
+
const point = getPointOnPath(path, pathConfig, charDistance);
|
|
38
|
+
const angle = getAngleOnPath(path, pathConfig, charDistance);
|
|
39
|
+
|
|
40
|
+
ctx.save();
|
|
41
|
+
ctx.translate(point.x, point.y);
|
|
42
|
+
ctx.rotate(angle);
|
|
43
|
+
ctx.fillText(char, 0, offset);
|
|
44
|
+
ctx.restore();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
currentDistance += charWidth;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
ctx.restore();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Creates a path based on configuration
|
|
55
|
+
*/
|
|
56
|
+
function createPath(
|
|
57
|
+
ctx: SKRSContext2D,
|
|
58
|
+
pathConfig: {
|
|
59
|
+
type: 'line' | 'arc' | 'bezier' | 'quadratic';
|
|
60
|
+
points: Array<{ x: number; y: number }>;
|
|
61
|
+
}
|
|
62
|
+
): Path2D {
|
|
63
|
+
const path = new Path2D();
|
|
64
|
+
|
|
65
|
+
switch (pathConfig.type) {
|
|
66
|
+
case 'line':
|
|
67
|
+
if (pathConfig.points.length >= 2) {
|
|
68
|
+
path.moveTo(pathConfig.points[0].x, pathConfig.points[0].y);
|
|
69
|
+
for (let i = 1; i < pathConfig.points.length; i++) {
|
|
70
|
+
path.lineTo(pathConfig.points[i].x, pathConfig.points[i].y);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case 'arc':
|
|
76
|
+
if (pathConfig.points.length >= 3) {
|
|
77
|
+
const center = pathConfig.points[0];
|
|
78
|
+
const start = pathConfig.points[1];
|
|
79
|
+
const end = pathConfig.points[2];
|
|
80
|
+
const radius = Math.sqrt(
|
|
81
|
+
Math.pow(start.x - center.x, 2) + Math.pow(start.y - center.y, 2)
|
|
82
|
+
);
|
|
83
|
+
const startAngle = Math.atan2(start.y - center.y, start.x - center.x);
|
|
84
|
+
const endAngle = Math.atan2(end.y - center.y, end.x - center.x);
|
|
85
|
+
path.arc(center.x, center.y, radius, startAngle, endAngle);
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
|
|
89
|
+
case 'bezier':
|
|
90
|
+
if (pathConfig.points.length >= 4) {
|
|
91
|
+
path.moveTo(pathConfig.points[0].x, pathConfig.points[0].y);
|
|
92
|
+
for (let i = 1; i < pathConfig.points.length - 2; i += 3) {
|
|
93
|
+
if (i + 2 < pathConfig.points.length) {
|
|
94
|
+
path.bezierCurveTo(
|
|
95
|
+
pathConfig.points[i].x, pathConfig.points[i].y,
|
|
96
|
+
pathConfig.points[i + 1].x, pathConfig.points[i + 1].y,
|
|
97
|
+
pathConfig.points[i + 2].x, pathConfig.points[i + 2].y
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
|
|
104
|
+
case 'quadratic':
|
|
105
|
+
if (pathConfig.points.length >= 3) {
|
|
106
|
+
path.moveTo(pathConfig.points[0].x, pathConfig.points[0].y);
|
|
107
|
+
for (let i = 1; i < pathConfig.points.length - 1; i += 2) {
|
|
108
|
+
if (i + 1 < pathConfig.points.length) {
|
|
109
|
+
path.quadraticCurveTo(
|
|
110
|
+
pathConfig.points[i].x, pathConfig.points[i].y,
|
|
111
|
+
pathConfig.points[i + 1].x, pathConfig.points[i + 1].y
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return path;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Gets approximate path length
|
|
124
|
+
*/
|
|
125
|
+
function getPathLength(
|
|
126
|
+
path: Path2D,
|
|
127
|
+
pathConfig: {
|
|
128
|
+
type: 'line' | 'arc' | 'bezier' | 'quadratic';
|
|
129
|
+
points: Array<{ x: number; y: number }>;
|
|
130
|
+
}
|
|
131
|
+
): number {
|
|
132
|
+
let length = 0;
|
|
133
|
+
|
|
134
|
+
switch (pathConfig.type) {
|
|
135
|
+
case 'line':
|
|
136
|
+
for (let i = 0; i < pathConfig.points.length - 1; i++) {
|
|
137
|
+
const dx = pathConfig.points[i + 1].x - pathConfig.points[i].x;
|
|
138
|
+
const dy = pathConfig.points[i + 1].y - pathConfig.points[i].y;
|
|
139
|
+
length += Math.sqrt(dx * dx + dy * dy);
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
|
|
143
|
+
case 'arc':
|
|
144
|
+
if (pathConfig.points.length >= 3) {
|
|
145
|
+
const center = pathConfig.points[0];
|
|
146
|
+
const start = pathConfig.points[1];
|
|
147
|
+
const end = pathConfig.points[2];
|
|
148
|
+
const radius = Math.sqrt(
|
|
149
|
+
Math.pow(start.x - center.x, 2) + Math.pow(start.y - center.y, 2)
|
|
150
|
+
);
|
|
151
|
+
const startAngle = Math.atan2(start.y - center.y, start.x - center.x);
|
|
152
|
+
const endAngle = Math.atan2(end.y - center.y, end.x - center.x);
|
|
153
|
+
let angle = endAngle - startAngle;
|
|
154
|
+
if (angle < 0) angle += Math.PI * 2;
|
|
155
|
+
length = radius * angle;
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
|
|
159
|
+
case 'bezier':
|
|
160
|
+
case 'quadratic':
|
|
161
|
+
// Approximate by sampling points along the curve
|
|
162
|
+
const samples = 100;
|
|
163
|
+
let prevPoint = pathConfig.points[0];
|
|
164
|
+
for (let i = 1; i <= samples; i++) {
|
|
165
|
+
const t = i / samples;
|
|
166
|
+
const point = getPointOnPath(path, pathConfig, t * 1000); // Approximate
|
|
167
|
+
const dx = point.x - prevPoint.x;
|
|
168
|
+
const dy = point.y - prevPoint.y;
|
|
169
|
+
length += Math.sqrt(dx * dx + dy * dy);
|
|
170
|
+
prevPoint = point;
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return length;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Gets a point on the path at a given distance
|
|
180
|
+
*/
|
|
181
|
+
function getPointOnPath(
|
|
182
|
+
path: Path2D,
|
|
183
|
+
pathConfig: {
|
|
184
|
+
type: 'line' | 'arc' | 'bezier' | 'quadratic';
|
|
185
|
+
points: Array<{ x: number; y: number }>;
|
|
186
|
+
},
|
|
187
|
+
distance: number
|
|
188
|
+
): { x: number; y: number } {
|
|
189
|
+
const pathLength = getPathLength(path, pathConfig);
|
|
190
|
+
const t = Math.min(1, distance / pathLength);
|
|
191
|
+
|
|
192
|
+
switch (pathConfig.type) {
|
|
193
|
+
case 'line':
|
|
194
|
+
return getPointOnLine(pathConfig.points, t);
|
|
195
|
+
|
|
196
|
+
case 'arc':
|
|
197
|
+
return getPointOnArc(pathConfig.points, t);
|
|
198
|
+
|
|
199
|
+
case 'bezier':
|
|
200
|
+
return getPointOnBezier(pathConfig.points, t);
|
|
201
|
+
|
|
202
|
+
case 'quadratic':
|
|
203
|
+
return getPointOnQuadratic(pathConfig.points, t);
|
|
204
|
+
|
|
205
|
+
default:
|
|
206
|
+
return { x: 0, y: 0 };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Gets angle on path at a given distance
|
|
212
|
+
*/
|
|
213
|
+
function getAngleOnPath(
|
|
214
|
+
path: Path2D,
|
|
215
|
+
pathConfig: {
|
|
216
|
+
type: 'line' | 'arc' | 'bezier' | 'quadratic';
|
|
217
|
+
points: Array<{ x: number; y: number }>;
|
|
218
|
+
},
|
|
219
|
+
distance: number
|
|
220
|
+
): number {
|
|
221
|
+
const pathLength = getPathLength(path, pathConfig);
|
|
222
|
+
const t = Math.min(1, distance / pathLength);
|
|
223
|
+
const epsilon = 0.01;
|
|
224
|
+
const t2 = Math.min(1, (distance + epsilon) / pathLength);
|
|
225
|
+
|
|
226
|
+
const p1 = getPointOnPath(path, pathConfig, distance);
|
|
227
|
+
const p2 = getPointOnPath(path, pathConfig, distance + epsilon);
|
|
228
|
+
|
|
229
|
+
return Math.atan2(p2.y - p1.y, p2.x - p1.x);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function getPointOnLine(points: Array<{ x: number; y: number }>, t: number): { x: number; y: number } {
|
|
233
|
+
if (points.length < 2) return { x: 0, y: 0 };
|
|
234
|
+
|
|
235
|
+
const totalLength = points.reduce((sum, p, i) => {
|
|
236
|
+
if (i === 0) return 0;
|
|
237
|
+
const dx = p.x - points[i - 1].x;
|
|
238
|
+
const dy = p.y - points[i - 1].y;
|
|
239
|
+
return sum + Math.sqrt(dx * dx + dy * dy);
|
|
240
|
+
}, 0);
|
|
241
|
+
|
|
242
|
+
let currentLength = 0;
|
|
243
|
+
const targetLength = totalLength * t;
|
|
244
|
+
|
|
245
|
+
for (let i = 1; i < points.length; i++) {
|
|
246
|
+
const dx = points[i].x - points[i - 1].x;
|
|
247
|
+
const dy = points[i].y - points[i - 1].y;
|
|
248
|
+
const segmentLength = Math.sqrt(dx * dx + dy * dy);
|
|
249
|
+
|
|
250
|
+
if (currentLength + segmentLength >= targetLength) {
|
|
251
|
+
const segmentT = (targetLength - currentLength) / segmentLength;
|
|
252
|
+
return {
|
|
253
|
+
x: points[i - 1].x + dx * segmentT,
|
|
254
|
+
y: points[i - 1].y + dy * segmentT
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
currentLength += segmentLength;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return points[points.length - 1];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function getPointOnArc(points: Array<{ x: number; y: number }>, t: number): { x: number; y: number } {
|
|
265
|
+
if (points.length < 3) return { x: 0, y: 0 };
|
|
266
|
+
|
|
267
|
+
const center = points[0];
|
|
268
|
+
const start = points[1];
|
|
269
|
+
const end = points[2];
|
|
270
|
+
const radius = Math.sqrt(
|
|
271
|
+
Math.pow(start.x - center.x, 2) + Math.pow(start.y - center.y, 2)
|
|
272
|
+
);
|
|
273
|
+
const startAngle = Math.atan2(start.y - center.y, start.x - center.x);
|
|
274
|
+
const endAngle = Math.atan2(end.y - center.y, end.x - center.x);
|
|
275
|
+
let angle = startAngle + (endAngle - startAngle) * t;
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
x: center.x + Math.cos(angle) * radius,
|
|
279
|
+
y: center.y + Math.sin(angle) * radius
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function getPointOnBezier(points: Array<{ x: number; y: number }>, t: number): { x: number; y: number } {
|
|
284
|
+
if (points.length < 4) return { x: 0, y: 0 };
|
|
285
|
+
|
|
286
|
+
// Use first bezier curve
|
|
287
|
+
const p0 = points[0];
|
|
288
|
+
const p1 = points[1];
|
|
289
|
+
const p2 = points[2];
|
|
290
|
+
const p3 = points[3];
|
|
291
|
+
|
|
292
|
+
const mt = 1 - t;
|
|
293
|
+
const mt2 = mt * mt;
|
|
294
|
+
const mt3 = mt2 * mt;
|
|
295
|
+
const t2 = t * t;
|
|
296
|
+
const t3 = t2 * t;
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
x: mt3 * p0.x + 3 * mt2 * t * p1.x + 3 * mt * t2 * p2.x + t3 * p3.x,
|
|
300
|
+
y: mt3 * p0.y + 3 * mt2 * t * p1.y + 3 * mt * t2 * p2.y + t3 * p3.y
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function getPointOnQuadratic(points: Array<{ x: number; y: number }>, t: number): { x: number; y: number } {
|
|
305
|
+
if (points.length < 3) return { x: 0, y: 0 };
|
|
306
|
+
|
|
307
|
+
const p0 = points[0];
|
|
308
|
+
const p1 = points[1];
|
|
309
|
+
const p2 = points[2];
|
|
310
|
+
|
|
311
|
+
const mt = 1 - t;
|
|
312
|
+
const mt2 = mt * mt;
|
|
313
|
+
const t2 = t * t;
|
|
314
|
+
|
|
315
|
+
return {
|
|
316
|
+
x: mt2 * p0.x + 2 * mt * t * p1.x + t2 * p2.x,
|
|
317
|
+
y: mt2 * p0.y + 2 * mt * t * p1.y + t2 * p2.y
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
@@ -23,7 +23,8 @@ export interface StrokeOptions {
|
|
|
23
23
|
blur?: number; // px
|
|
24
24
|
opacity?: number; // 0..1
|
|
25
25
|
borderRadius?: number | 'circular';
|
|
26
|
-
borderPosition?:
|
|
26
|
+
borderPosition?: borderPosition;
|
|
27
|
+
style?: 'solid' | 'dashed' | 'dotted' | 'groove' | 'ridge' | 'double';
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export interface ShadowOptions {
|
|
@@ -86,6 +87,15 @@ export interface CanvasConfig {
|
|
|
86
87
|
fit?: 'fill' | 'contain' | 'cover';
|
|
87
88
|
align?: 'center' | 'top' | 'bottom' | 'left' | 'right'
|
|
88
89
|
| 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
90
|
+
filters?: ImageFilter[]; // NEW: Apply filters to background image
|
|
91
|
+
opacity?: number; // NEW: Background image opacity
|
|
92
|
+
};
|
|
93
|
+
videoBg?: {
|
|
94
|
+
source: string;
|
|
95
|
+
frame?: number; // Extract specific frame (default: 0)
|
|
96
|
+
loop?: boolean; // Loop video (default: false)
|
|
97
|
+
autoplay?: boolean; // Autoplay (default: false)
|
|
98
|
+
opacity?: number; // Video opacity (default: 1)
|
|
89
99
|
};
|
|
90
100
|
|
|
91
101
|
colorBg?: string;
|
|
@@ -123,6 +133,7 @@ export interface CanvasConfig {
|
|
|
123
133
|
borderRadius?: number | "circular";
|
|
124
134
|
borderPosition?: borderPosition;
|
|
125
135
|
gradient?: gradient;
|
|
136
|
+
style?: 'solid' | 'dashed' | 'dotted' | 'groove' | 'ridge' | 'double';
|
|
126
137
|
};
|
|
127
138
|
shadow?: {
|
|
128
139
|
color?: string;
|
|
@@ -197,6 +208,35 @@ export interface ImageProperties {
|
|
|
197
208
|
|
|
198
209
|
// image filters
|
|
199
210
|
filters?: ImageFilter[];
|
|
211
|
+
filterIntensity?: number; // Global filter intensity multiplier (default: 1)
|
|
212
|
+
filterOrder?: 'pre' | 'post'; // Apply before or after transformations (default: 'post')
|
|
213
|
+
|
|
214
|
+
// image masking
|
|
215
|
+
mask?: {
|
|
216
|
+
source: string | Buffer; // Mask image
|
|
217
|
+
mode?: 'alpha' | 'luminance' | 'inverse'; // Mask mode (default: 'alpha')
|
|
218
|
+
};
|
|
219
|
+
clipPath?: Array<{ x: number; y: number }>; // Custom clipping path polygon
|
|
220
|
+
|
|
221
|
+
// image distortion/transform
|
|
222
|
+
distortion?: {
|
|
223
|
+
type: 'perspective' | 'warp' | 'bulge' | 'pinch';
|
|
224
|
+
points?: Array<{ x: number; y: number }>; // Control points for perspective/warp
|
|
225
|
+
intensity?: number; // Intensity for bulge/pinch (default: 0.5)
|
|
226
|
+
};
|
|
227
|
+
meshWarp?: {
|
|
228
|
+
gridX?: number; // Grid divisions X (default: 10)
|
|
229
|
+
gridY?: number; // Grid divisions Y (default: 10)
|
|
230
|
+
controlPoints?: Array<Array<{ x: number; y: number }>>; // Control point grid
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// image effects stack
|
|
234
|
+
effects?: {
|
|
235
|
+
vignette?: { intensity: number; size: number }; // Vignette effect (0-1, 0-1)
|
|
236
|
+
lensFlare?: { x: number; y: number; intensity: number }; // Lens flare position and intensity
|
|
237
|
+
chromaticAberration?: { intensity: number }; // Chromatic aberration (0-1)
|
|
238
|
+
filmGrain?: { intensity: number }; // Film grain effect (0-1)
|
|
239
|
+
};
|
|
200
240
|
|
|
201
241
|
// shape properties (when source is a shape)
|
|
202
242
|
shape?: ShapeProperties;
|
|
@@ -236,14 +276,27 @@ export interface TextProperties {
|
|
|
236
276
|
y: number;
|
|
237
277
|
|
|
238
278
|
// === FONT MANAGEMENT ===
|
|
239
|
-
/**
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
279
|
+
/** Font configuration object */
|
|
280
|
+
font?: {
|
|
281
|
+
/** Font size in pixels (default: 16) */
|
|
282
|
+
size?: number;
|
|
283
|
+
/** Font family name (e.g., 'Arial', 'Helvetica', 'Times New Roman') */
|
|
284
|
+
family?: string;
|
|
285
|
+
/** Custom font name (used with fontPath) */
|
|
286
|
+
name?: string;
|
|
287
|
+
/** Path to custom font file (.ttf, .otf, .woff, etc.) */
|
|
288
|
+
path?: string;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// === LEGACY FONT PROPERTIES (for backward compatibility) ===
|
|
292
|
+
/** @deprecated Use font.size instead */
|
|
244
293
|
fontSize?: number;
|
|
245
|
-
/**
|
|
294
|
+
/** @deprecated Use font.family instead */
|
|
246
295
|
fontFamily?: string;
|
|
296
|
+
/** @deprecated Use font.name instead */
|
|
297
|
+
fontName?: string;
|
|
298
|
+
/** @deprecated Use font.path instead */
|
|
299
|
+
fontPath?: string;
|
|
247
300
|
|
|
248
301
|
// === TEXT DECORATION ===
|
|
249
302
|
/** Make text bold */
|
|
@@ -251,15 +304,38 @@ export interface TextProperties {
|
|
|
251
304
|
/** Make text italic */
|
|
252
305
|
italic?: boolean;
|
|
253
306
|
/** Add underline decoration */
|
|
254
|
-
underline?: boolean
|
|
307
|
+
underline?: boolean | {
|
|
308
|
+
/** Underline color */
|
|
309
|
+
color?: string;
|
|
310
|
+
/** Underline gradient (overrides color) */
|
|
311
|
+
gradient?: gradient;
|
|
312
|
+
/** Underline width (default: 1px) */
|
|
313
|
+
width?: number;
|
|
314
|
+
};
|
|
255
315
|
/** Add overline decoration */
|
|
256
|
-
overline?: boolean
|
|
316
|
+
overline?: boolean | {
|
|
317
|
+
/** Overline color */
|
|
318
|
+
color?: string;
|
|
319
|
+
/** Overline gradient (overrides color) */
|
|
320
|
+
gradient?: gradient;
|
|
321
|
+
/** Overline width (default: 1px) */
|
|
322
|
+
width?: number;
|
|
323
|
+
};
|
|
257
324
|
/** Add strikethrough decoration */
|
|
258
|
-
strikethrough?: boolean
|
|
325
|
+
strikethrough?: boolean | {
|
|
326
|
+
/** Strikethrough color */
|
|
327
|
+
color?: string;
|
|
328
|
+
/** Strikethrough gradient (overrides color) */
|
|
329
|
+
gradient?: gradient;
|
|
330
|
+
/** Strikethrough width (default: 1px) */
|
|
331
|
+
width?: number;
|
|
332
|
+
};
|
|
259
333
|
/** Highlight text with background color */
|
|
260
334
|
highlight?: {
|
|
261
335
|
/** Highlight color (hex, rgb, rgba, hsl, etc.) */
|
|
262
336
|
color?: string;
|
|
337
|
+
/** Highlight gradient (overrides color) */
|
|
338
|
+
gradient?: gradient;
|
|
263
339
|
/** Highlight opacity (0-1, default: 0.3) */
|
|
264
340
|
opacity?: number;
|
|
265
341
|
};
|
|
@@ -295,6 +371,8 @@ export interface TextProperties {
|
|
|
295
371
|
glow?: {
|
|
296
372
|
/** Glow color */
|
|
297
373
|
color?: string;
|
|
374
|
+
/** Glow gradient (overrides color) */
|
|
375
|
+
gradient?: gradient;
|
|
298
376
|
/** Glow intensity/blur radius */
|
|
299
377
|
intensity?: number;
|
|
300
378
|
/** Glow opacity (0-1) */
|
|
@@ -323,11 +401,23 @@ export interface TextProperties {
|
|
|
323
401
|
gradient?: gradient;
|
|
324
402
|
/** Stroke opacity (0-1) */
|
|
325
403
|
opacity?: number;
|
|
404
|
+
/** Stroke style */
|
|
405
|
+
style?: 'solid' | 'dashed' | 'dotted' | 'groove' | 'ridge' | 'double';
|
|
326
406
|
};
|
|
327
407
|
|
|
328
408
|
// === TRANSFORMATIONS ===
|
|
329
409
|
/** Text rotation in degrees */
|
|
330
410
|
rotation?: number;
|
|
411
|
+
|
|
412
|
+
// === TEXT PATH/CURVE FOLLOWING ===
|
|
413
|
+
/** Path for text to follow */
|
|
414
|
+
path?: {
|
|
415
|
+
type: 'line' | 'arc' | 'bezier' | 'quadratic';
|
|
416
|
+
points: Array<{ x: number; y: number }>;
|
|
417
|
+
offset?: number; // Distance from path (default: 0)
|
|
418
|
+
};
|
|
419
|
+
/** Render text along path */
|
|
420
|
+
textOnPath?: boolean;
|
|
331
421
|
}
|
|
332
422
|
|
|
333
423
|
/**
|
|
@@ -405,6 +495,27 @@ export interface CustomOptions {
|
|
|
405
495
|
x: number;
|
|
406
496
|
y: number;
|
|
407
497
|
};
|
|
498
|
+
// Advanced path options
|
|
499
|
+
path?: {
|
|
500
|
+
type: 'smooth' | 'bezier' | 'catmull-rom';
|
|
501
|
+
tension?: number; // For smooth/catmull-rom (default: 0.5)
|
|
502
|
+
closed?: boolean; // Close the path (default: false)
|
|
503
|
+
};
|
|
504
|
+
// Arrow markers
|
|
505
|
+
arrow?: {
|
|
506
|
+
start?: boolean; // Arrow at start (default: false)
|
|
507
|
+
end?: boolean; // Arrow at end (default: false)
|
|
508
|
+
size?: number; // Arrow size (default: 10)
|
|
509
|
+
style?: 'filled' | 'outline'; // Arrow style (default: 'filled')
|
|
510
|
+
color?: string; // Arrow color (default: line color)
|
|
511
|
+
};
|
|
512
|
+
// Path markers
|
|
513
|
+
markers?: Array<{
|
|
514
|
+
position: number; // 0-1 along path
|
|
515
|
+
shape: 'circle' | 'square' | 'diamond' | 'arrow';
|
|
516
|
+
size: number;
|
|
517
|
+
color: string;
|
|
518
|
+
}>;
|
|
408
519
|
lineStyle?: {
|
|
409
520
|
width?: number;
|
|
410
521
|
color?: string;
|
|
@@ -417,6 +528,13 @@ export interface CustomOptions {
|
|
|
417
528
|
dashArray?: number[];
|
|
418
529
|
offset?: number;
|
|
419
530
|
};
|
|
531
|
+
// Line patterns
|
|
532
|
+
pattern?: {
|
|
533
|
+
type: 'dots' | 'dashes' | 'custom';
|
|
534
|
+
segments?: number[]; // For custom pattern
|
|
535
|
+
offset?: number; // Pattern offset
|
|
536
|
+
};
|
|
537
|
+
texture?: string | Buffer; // Texture image for line
|
|
420
538
|
stroke?: {
|
|
421
539
|
color?: string;
|
|
422
540
|
gradient?: gradient;
|
|
@@ -723,6 +841,51 @@ export interface GradientConfig{
|
|
|
723
841
|
}
|
|
724
842
|
|
|
725
843
|
|
|
844
|
+
// Batch operation types
|
|
845
|
+
export interface BatchOperation {
|
|
846
|
+
type: 'canvas' | 'image' | 'text' | 'chart';
|
|
847
|
+
config: any;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
export interface ChainOperation {
|
|
851
|
+
method: string;
|
|
852
|
+
args: any[];
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// Image stitching options
|
|
856
|
+
export interface StitchOptions {
|
|
857
|
+
direction?: 'horizontal' | 'vertical' | 'grid';
|
|
858
|
+
overlap?: number; // Percentage overlap for auto-alignment (0-100)
|
|
859
|
+
blend?: boolean; // Blend overlapping areas (default: false)
|
|
860
|
+
spacing?: number; // Spacing between images in pixels (default: 0)
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// Collage layout options
|
|
864
|
+
export interface CollageLayout {
|
|
865
|
+
type: 'grid' | 'masonry' | 'carousel' | 'custom';
|
|
866
|
+
columns?: number;
|
|
867
|
+
rows?: number;
|
|
868
|
+
spacing?: number;
|
|
869
|
+
background?: string;
|
|
870
|
+
borderRadius?: number;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
// Image compression options
|
|
874
|
+
export interface CompressionOptions {
|
|
875
|
+
quality?: number; // 0-100 (default: 90)
|
|
876
|
+
format?: 'jpeg' | 'webp' | 'avif';
|
|
877
|
+
maxWidth?: number;
|
|
878
|
+
maxHeight?: number;
|
|
879
|
+
progressive?: boolean; // For JPEG (default: false)
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// Color palette extraction options
|
|
883
|
+
export interface PaletteOptions {
|
|
884
|
+
count?: number; // Number of colors (default: 10)
|
|
885
|
+
method?: 'kmeans' | 'median-cut' | 'octree';
|
|
886
|
+
format?: 'hex' | 'rgb' | 'hsl';
|
|
887
|
+
}
|
|
888
|
+
|
|
726
889
|
export interface ExtractFramesOptions {
|
|
727
890
|
interval: number;
|
|
728
891
|
outputFormat?: 'jpg' | 'png';
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
import { OutputFormat, CanvasConfig, ImageProperties, TextObject, TextProperties, GIFOptions, GIFResults, CustomOptions, cropOptions, GradientConfig, Frame, PatternOptions, ExtractFramesOptions, ResizeOptions, CropOptions, MaskOptions, BlendOptions, ShapeType, ShapeProperties, ImageFilter } from "./types";
|
|
13
|
+
import { OutputFormat, CanvasConfig, ImageProperties, TextObject, TextProperties, GIFOptions, GIFResults, CustomOptions, cropOptions, GradientConfig, Frame, PatternOptions, ExtractFramesOptions, ResizeOptions, CropOptions, MaskOptions, BlendOptions, ShapeType, ShapeProperties, ImageFilter, barChart_1, PieChartData, LineChartConfig, BatchOperation, ChainOperation, StitchOptions, CollageLayout, CompressionOptions, PaletteOptions } from "./types";
|
|
14
14
|
import { drawBackgroundColor, drawBackgroundGradient, customBackground, applyCanvasZoom, drawPattern, applyNoise } from "./Background/bg";
|
|
15
15
|
import { buildPath, applyRotation, createGradientFill, fitInto, loadImageCached, applyStroke, drawBoxBackground, applyShadow } from './Image/imageProperties'
|
|
16
16
|
import { applyImageFilters } from './Image/imageFilters'
|
|
@@ -21,6 +21,13 @@ import { customLines } from "./Custom/customLines";
|
|
|
21
21
|
import { verticalBarChart, pieChart, lineChart } from './Charts/charts'
|
|
22
22
|
import { url, arrayBuffer, base64, dataURL, blob } from "./General/conversion";
|
|
23
23
|
import { drawShape, isShapeSource, createShapePath } from "./Shapes/shapes";
|
|
24
|
+
import { applyImageMask, applyClipPath, applyPerspectiveDistortion, applyBulgeDistortion, applyMeshWarp } from "./Image/imageMasking";
|
|
25
|
+
import { applyVignette, applyLensFlare, applyChromaticAberration, applyFilmGrain } from "./Image/imageEffects";
|
|
26
|
+
import { renderTextOnPath } from "./Texts/textPathRenderer";
|
|
27
|
+
import { drawArrow, drawMarker, createSmoothPath, createCatmullRomPath, applyLinePattern, applyLineTexture, getPointOnLinePath } from "./Custom/advancedLines";
|
|
28
|
+
import { batchOperations, chainOperations } from "./General/batchOperations";
|
|
29
|
+
import { stitchImages, createCollage } from "./General/imageStitching";
|
|
30
|
+
import { compressImage, extractPalette } from "./General/imageCompression";
|
|
24
31
|
|
|
25
32
|
export {
|
|
26
33
|
url,
|
|
@@ -81,5 +88,45 @@ export {
|
|
|
81
88
|
isShapeSource,
|
|
82
89
|
createShapePath,
|
|
83
90
|
applyImageFilters,
|
|
84
|
-
applySimpleProfessionalFilters
|
|
91
|
+
applySimpleProfessionalFilters,
|
|
92
|
+
barChart_1,
|
|
93
|
+
PieChartData,
|
|
94
|
+
LineChartConfig,
|
|
95
|
+
// New image masking and distortion
|
|
96
|
+
applyImageMask,
|
|
97
|
+
applyClipPath,
|
|
98
|
+
applyPerspectiveDistortion,
|
|
99
|
+
applyBulgeDistortion,
|
|
100
|
+
applyMeshWarp,
|
|
101
|
+
// New image effects
|
|
102
|
+
applyVignette,
|
|
103
|
+
applyLensFlare,
|
|
104
|
+
applyChromaticAberration,
|
|
105
|
+
applyFilmGrain,
|
|
106
|
+
// New text path rendering
|
|
107
|
+
renderTextOnPath,
|
|
108
|
+
// New custom lines features
|
|
109
|
+
drawArrow,
|
|
110
|
+
drawMarker,
|
|
111
|
+
createSmoothPath,
|
|
112
|
+
createCatmullRomPath,
|
|
113
|
+
applyLinePattern,
|
|
114
|
+
applyLineTexture,
|
|
115
|
+
getPointOnLinePath,
|
|
116
|
+
// Batch operations
|
|
117
|
+
batchOperations,
|
|
118
|
+
chainOperations,
|
|
119
|
+
// Image stitching and collage
|
|
120
|
+
stitchImages,
|
|
121
|
+
createCollage,
|
|
122
|
+
// Image compression and palette
|
|
123
|
+
compressImage,
|
|
124
|
+
extractPalette,
|
|
125
|
+
// New types
|
|
126
|
+
BatchOperation,
|
|
127
|
+
ChainOperation,
|
|
128
|
+
StitchOptions,
|
|
129
|
+
CollageLayout,
|
|
130
|
+
CompressionOptions,
|
|
131
|
+
PaletteOptions
|
|
85
132
|
};
|