![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.quebec/private_html/node_modules/svg-pathdata/src/ |
import { encodeSVGPath } from "./SVGPathDataEncoder";
import { SVGPathDataParser } from "./SVGPathDataParser";
import { SVGPathDataTransformer } from "./SVGPathDataTransformer";
import { TransformableSVG } from "./TransformableSVG";
import { SVGCommand } from "./types";
export class SVGPathData extends TransformableSVG {
commands: SVGCommand[];
constructor(content: string | SVGCommand[]) {
super();
if ("string" === typeof content) {
this.commands = SVGPathData.parse(content);
} else {
this.commands = content;
}
}
encode() {
return SVGPathData.encode(this.commands);
}
getBounds() {
const boundsTransform = SVGPathDataTransformer.CALCULATE_BOUNDS();
this.transform(boundsTransform);
return boundsTransform;
}
transform(
transformFunction: (input: SVGCommand) => SVGCommand | SVGCommand[],
) {
const newCommands = [];
for (const command of this.commands) {
const transformedCommand = transformFunction(command);
if (Array.isArray(transformedCommand)) {
newCommands.push(...transformedCommand);
} else {
newCommands.push(transformedCommand);
}
}
this.commands = newCommands;
return this;
}
static encode(commands: SVGCommand[]) {
return encodeSVGPath(commands);
}
static parse(path: string) {
const parser = new SVGPathDataParser();
const commands: SVGCommand[] = [];
parser.parse(path, commands);
parser.finish(commands);
return commands;
}
static readonly CLOSE_PATH: 1 = 1;
static readonly MOVE_TO: 2 = 2;
static readonly HORIZ_LINE_TO: 4 = 4;
static readonly VERT_LINE_TO: 8 = 8;
static readonly LINE_TO: 16 = 16;
static readonly CURVE_TO: 32 = 32;
static readonly SMOOTH_CURVE_TO: 64 = 64;
static readonly QUAD_TO: 128 = 128;
static readonly SMOOTH_QUAD_TO: 256 = 256;
static readonly ARC: 512 = 512;
static readonly LINE_COMMANDS = SVGPathData.LINE_TO | SVGPathData.HORIZ_LINE_TO | SVGPathData.VERT_LINE_TO;
static readonly DRAWING_COMMANDS = SVGPathData.HORIZ_LINE_TO | SVGPathData.VERT_LINE_TO | SVGPathData.LINE_TO |
SVGPathData.CURVE_TO | SVGPathData.SMOOTH_CURVE_TO | SVGPathData.QUAD_TO |
SVGPathData.SMOOTH_QUAD_TO | SVGPathData.ARC;
}
export const COMMAND_ARG_COUNTS = {
[SVGPathData.MOVE_TO]: 2,
[SVGPathData.LINE_TO]: 2,
[SVGPathData.HORIZ_LINE_TO]: 1,
[SVGPathData.VERT_LINE_TO]: 1,
[SVGPathData.CLOSE_PATH]: 0,
[SVGPathData.QUAD_TO]: 4,
[SVGPathData.SMOOTH_QUAD_TO]: 2,
[SVGPathData.CURVE_TO]: 6,
[SVGPathData.SMOOTH_CURVE_TO]: 4,
[SVGPathData.ARC]: 7,
};
export {encodeSVGPath} from "./SVGPathDataEncoder";
export {SVGPathDataParser} from "./SVGPathDataParser";
export {SVGPathDataTransformer} from "./SVGPathDataTransformer";