@shopify/react-native-skia
Version:
High-performance React Native Graphics using Skia
79 lines • 2.83 kB
JavaScript
import { CommandType, isGroup } from "./Core";
const CommandTypeNames = {
[]: "Group",
[]: "SavePaint",
[]: "RestorePaint",
[]: "SaveCTM",
[]: "RestoreCTM",
[]: "PushColorFilter",
[]: "PushBlurMaskFilter",
[]: "PushImageFilter",
[]: "PushPathEffect",
[]: "PushShader",
[]: "ComposeColorFilter",
[]: "ComposeImageFilter",
[]: "ComposePathEffect",
[]: "MaterializePaint",
[]: "SaveBackdropFilter",
[]: "SaveLayer",
[]: "RestorePaintDeclaration",
[]: "DrawBox",
[]: "DrawImage",
[]: "DrawCircle",
[]: "DrawPaint",
[]: "DrawPoints",
[]: "DrawPath",
[]: "DrawRect",
[]: "DrawRRect",
[]: "DrawOval",
[]: "DrawLine",
[]: "DrawPatch",
[]: "DrawVertices",
[]: "DrawDiffRect",
[]: "DrawText",
[]: "DrawTextPath",
[]: "DrawTextBlob",
[]: "DrawGlyphs",
[]: "DrawPicture",
[]: "DrawImageSVG",
[]: "DrawParagraph",
[]: "DrawAtlas",
[]: "DrawSkottie"
};
const serializeProps = props => {
try {
return JSON.stringify(props, (key, value) => {
if (key === "children") {
return undefined;
}
if (typeof value === "bigint") {
return value.toString();
}
return value;
});
} catch (e) {
return `"Error serializing props: ${e}"`;
}
};
export const debugTree = (commands, indent = 0) => {
let result = "[\n";
const prefix = " ".repeat(indent + 2);
commands.forEach((cmd, index) => {
const type = CommandTypeNames[cmd.type] || "Unknown";
result += `${prefix}{ "type": "${type}"`;
if ("props" in cmd) {
result += `, "props": ${serializeProps(cmd.props)}`;
}
if (isGroup(cmd)) {
result += `, "children": ${debugTree(cmd.children, indent + 2)}`;
}
result += " }";
if (index < commands.length - 1) {
result += ",";
}
result += "\n";
});
result += " ".repeat(indent) + "]";
return result;
};
//# sourceMappingURL=Debug.js.map