Files
il/resources/public/js/cljs-runtime/module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$svg$buildSVGPath.js
2026-07-01 22:38:29 -06:00

193 lines
8.8 KiB
JavaScript

shadow$provide.module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$svg$buildSVGPath = function(global, require, module, exports) {
function buildSVGPath(path, precision = 2, flatten = !1) {
if (path.instructions.some(inst => COMPLEX_ACTIONS.has(inst.action))) {
return buildFromShapePrimitives(path, precision, flatten);
}
const parts = [];
let hasCurrent = !1;
for (let i = 0; i < path.instructions.length; i++) {
const inst = path.instructions[i], d = inst.data;
switch(inst.action) {
case "moveTo":
parts.push(`M${pt(d[0], d[1], null, precision)}`);
hasCurrent = !0;
break;
case "lineTo":
parts.push(`L${pt(d[0], d[1], null, precision)}`);
hasCurrent = !0;
break;
case "quadraticCurveTo":
parts.push(`Q${pt(d[0], d[1], null, precision)} ${pt(d[2], d[3], null, precision)}`);
hasCurrent = !0;
break;
case "bezierCurveTo":
parts.push(`C${pt(d[0], d[1], null, precision)} ${pt(d[2], d[3], null, precision)} ${pt(d[4], d[5], null, precision)}`);
hasCurrent = !0;
break;
case "arcToSvg":
parts.push(`A${n(d[0], precision)} ${n(d[1], precision)} ${n(d[2], precision)} ${d[3]} ${d[4]} ${pt(d[5], d[6], null, precision)}`);
hasCurrent = !0;
break;
case "closePath":
parts.push("Z");
hasCurrent = !1;
break;
case "arc":
parts.push(buildArc(d[0], d[1], d[2], d[3], d[4], !!d[5], hasCurrent, precision, flatten));
hasCurrent = !isFullCircle(d[3], d[4], !!d[5]);
break;
case "rect":
parts.push(buildRect(d[0], d[1], d[2], d[3], d[4], precision));
hasCurrent = !1;
break;
case "circle":
parts.push(buildEllipseArc(d[0], d[1], d[2], d[2], d[3], precision, flatten));
hasCurrent = !1;
break;
case "ellipse":
parts.push(buildEllipseArc(d[0], d[1], d[2], d[3], d[4], precision, flatten));
hasCurrent = !1;
break;
case "roundRect":
parts.push(buildRoundRect(d[0], d[1], d[2], d[3], d[4] ?? 0, d[5], precision, flatten));
hasCurrent = !1;
break;
case "poly":
parts.push(buildPoly(d[0], d[1] ?? !0, d[2], precision));
hasCurrent = !(d[1] ?? !0);
break;
case "addPath":
parts.push(buildAddPath(d[0], d[1], precision, flatten)), hasCurrent = !0;
}
}
return parts.join("");
}
function isFullCircle(startAngle, endAngle, ccw) {
startAngle = endAngle - startAngle;
ccw ? 0 < startAngle && (startAngle -= PI2) : 0 > startAngle && (startAngle += PI2);
return Math.abs(startAngle) >= PI2 - 1e-6;
}
function n(value, precision) {
return parseFloat(value.toFixed(precision)).toString();
}
function pt(x, y, matrix, precision) {
if (matrix && !matrix.isIdentity()) {
const ty = matrix.b * x + matrix.d * y + matrix.ty;
return `${n(matrix.a * x + matrix.c * y + matrix.tx, precision)} ${n(ty, precision)}`;
}
return `${n(x, precision)} ${n(y, precision)}`;
}
function buildArc(cx, cy, radius, startAngle, endAngle, ccw, hasCurrent, precision, flatten = !1) {
var sweep = endAngle - startAngle;
ccw ? 0 < sweep && (sweep -= PI2) : 0 > sweep && (sweep += PI2);
if (Math.abs(sweep) >= PI2 - 1e-6) {
return buildEllipseArc(cx, cy, radius, radius, null, precision, flatten);
}
if (flatten) {
ccw = [];
for (flatten = 0; 32 >= flatten; flatten++) {
var a = startAngle + flatten / 32 * sweep;
endAngle = cy + radius * Math.sin(a);
ccw.push(`${0 === flatten ? hasCurrent ? "L" : "M" : "L"}${n(cx + radius * Math.cos(a), precision)} ${n(endAngle, precision)}`);
}
return ccw.join("");
}
flatten = cy + radius * Math.sin(startAngle);
a = cx + radius * Math.cos(endAngle);
cy += radius * Math.sin(endAngle);
sweep = Math.abs(sweep) > Math.PI ? 1 : 0;
ccw = ccw ? 0 : 1;
return `${hasCurrent ? "L" : "M"}${n(cx + radius * Math.cos(startAngle), precision)} ${n(flatten, precision)}A${n(radius, precision)} ${n(radius, precision)} 0 ${sweep} ${ccw} ${n(a, precision)} ${n(cy, precision)}`;
}
function buildEllipseArc(cx, cy, rx, ry, matrixArg, precision, flatten = !1) {
matrixArg = matrixArg && !matrixArg.isIdentity() ? matrixArg : null;
if (!matrixArg && !flatten) {
return `M${n(cx - rx, precision)} ${n(cy, precision)}A${n(rx, precision)} ${n(ry, precision)} 0 1 1 ${n(cx + rx, precision)} ${n(cy, precision)}A${n(rx, precision)} ${n(ry, precision)} 0 1 1 ${n(cx - rx, precision)} ${n(cy, precision)}Z`;
}
flatten = [];
for (let i = 0; 64 > i; i++) {
const a = i / 64 * PI2;
flatten.push(`${0 === i ? "M" : "L"}${pt(cx + rx * Math.cos(a), cy + ry * Math.sin(a), matrixArg, precision)}`);
}
flatten.push("Z");
return flatten.join("");
}
function buildRect(x, y, w, h, matrix, precision) {
return `M${pt(x, y, matrix, precision)}L${pt(x + w, y, matrix, precision)}L${pt(x + w, y + h, matrix, precision)}L${pt(x, y + h, matrix, precision)}Z`;
}
function buildRoundRect(x, y, w, h, r, matrixArg, precision, flatten = !1) {
matrixArg = matrixArg && !matrixArg.isIdentity() ? matrixArg : null;
if (0 >= r) {
return buildRect(x, y, w, h, matrixArg, precision);
}
r = Math.min(r, Math.min(w, h) / 2);
if (matrixArg || flatten) {
flatten = [];
x = [[x + w - r, y + r, -Math.PI / 2], [x + w - r, y + h - r, 0], [x + r, y + h - r, Math.PI / 2], [x + r, y + r, Math.PI]];
y = !0;
for (w = 0; w < x.length; w++) {
const [cx, cy, start] = x[w];
for (h = 0; 8 >= h; h++) {
const a = start + h / 8 * (Math.PI / 2);
flatten.push(`${y ? "M" : "L"}${pt(cx + r * Math.cos(a), cy + r * Math.sin(a), matrixArg, precision)}`);
y = !1;
}
}
flatten.push("Z");
return flatten.join("");
}
return `M${n(x + r, precision)} ${n(y, precision)}L${n(x + w - r, precision)} ${n(y, precision)}A${n(r, precision)} ${n(r, precision)} 0 0 1 ${n(x + w, precision)} ${n(y + r, precision)}L${n(x + w, precision)} ${n(y + h - r, precision)}A${n(r, precision)} ${n(r, precision)} 0 0 1 ${n(x + w - r, precision)} ${n(y + h, precision)}L${n(x + r, precision)} ${n(y + h, precision)}A${n(r, precision)} ${n(r, precision)} 0 0 1 ${n(x, precision)} ${n(y + h - r, precision)}L${n(x, precision)} ${n(y + r,
precision)}A${n(r, precision)} ${n(r, precision)} 0 0 1 ${n(x + r, precision)} ${n(y, precision)}Z`;
}
function buildPoly(points, close, matrix, precision) {
if (0 === points.length) {
return "";
}
const parts = [];
if ("number" === typeof points[0]) {
parts.push(`M${pt(points[0], points[1], matrix, precision)}`);
for (var i = 2; i < points.length; i += 2) {
parts.push(`L${pt(points[i], points[i + 1], matrix, precision)}`);
}
} else {
for (parts.push(`M${pt(points[0].x, points[0].y, matrix, precision)}`), i = 1; i < points.length; i++) {
parts.push(`L${pt(points[i].x, points[i].y, matrix, precision)}`);
}
}
close && parts.push("Z");
return parts.join("");
}
function buildAddPath(inner, matrix, precision, flatten) {
return !matrix || matrix.isIdentity() ? buildSVGPath(inner, precision, flatten) : buildSVGPath(inner.clone(!0).transform(matrix), precision, flatten);
}
function buildFromShapePrimitives(path, precision, flatten) {
var shapePrimitives = path.shapePath.shapePrimitives;
path = [];
for (const primitive of shapePrimitives) {
var shape = primitive.shape;
shapePrimitives = primitive.transform;
switch(shape.type) {
case "polygon":
path.push(buildPoly(shape.points, shape.closePath, shapePrimitives, precision));
break;
case "circle":
path.push(buildEllipseArc(shape.x, shape.y, shape.radius, shape.radius, shapePrimitives, precision, flatten));
break;
case "ellipse":
path.push(buildEllipseArc(shape.x, shape.y, shape.halfWidth, shape.halfHeight, shapePrimitives, precision, flatten));
break;
case "rectangle":
path.push(buildRect(shape.x, shape.y, shape.width, shape.height, shapePrimitives, precision));
break;
case "roundedRectangle":
path.push(buildRoundRect(shape.x, shape.y, shape.width, shape.height, shape.radius, shapePrimitives, precision, flatten));
}
}
return path.join("");
}
const PI2 = 2 * Math.PI, COMPLEX_ACTIONS = new Set("regularPoly roundPoly roundShape filletRect chamferRect arcTo".split(" "));
exports.buildSVGPath = buildSVGPath;
};
//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$svg$buildSVGPath.js.map