@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
55 lines (53 loc) • 1.93 kB
JavaScript
// src/functions/ExportUtility.ts
function createExportableElement(element) {
try {
let elementString = JSON.stringify(element);
return JSON.parse(elementString);
} catch (e) {
console.error("[Pixi'VN] Error creating exportable element", e);
throw new Error("[Pixi'VN] Error creating exportable element");
}
}
// src/functions/DiffUtility.ts
function restoreDeepDiffChanges(data, differences) {
let result = createExportableElement(data);
differences.forEach((diff) => {
let dataToEdit = result;
if (diff.path && diff.path.length > 0) {
diff.path.forEach((path, index) => {
if (diff.path && index === diff.path.length - 1) {
if (diff.kind === "E" || diff.kind === "D") {
dataToEdit[path] = diff.lhs;
} else if (diff.kind === "N") {
if (Number.isInteger(path)) {
if (Array.isArray(dataToEdit)) {
dataToEdit.splice(path, 1);
}
} else if (typeof path === "string") {
delete dataToEdit[path];
}
} else if (diff.kind === "A") {
let index2 = diff.index;
if (diff.item.kind === "N") {
dataToEdit[path].splice(index2, 1);
} else if (diff.item.kind === "E" || diff.item.kind === "D") {
dataToEdit[path][index2] = diff.item.lhs;
} else if (diff.item.kind === "A") {
console.warn("[Pixi'VN] Nested array found, skipping diff", diff);
} else {
console.warn("[Pixi'VN] No array found, skipping diff", diff);
}
}
} else {
dataToEdit = dataToEdit[path];
}
});
} else {
console.warn("[Pixi'VN] No path found, skipping diff", diff);
}
});
return result;
}
export { restoreDeepDiffChanges };
//# sourceMappingURL=DiffUtility.mjs.map
//# sourceMappingURL=DiffUtility.mjs.map