UNPKG

@drincs/pixi-vn

Version:

Pixi'VN is a npm package that provides various features for creating visual novels.

1 lines 1.47 kB
var a;(i=>(i.log=(o,...s)=>console.log(`[Pixi\u2019VN] ${o}`,...s),i.warn=(o,...s)=>console.warn(`[Pixi\u2019VN] ${o}`,...s),i.error=(o,...s)=>console.error(`[Pixi\u2019VN] ${o}`,...s),i.info=(o,...s)=>console.info(`[Pixi\u2019VN] ${o}`,...s)))(a||={});function l(n){try{if(typeof n>"u")return n;let e=JSON.stringify(n);return JSON.parse(e)}catch(e){throw a.error("Error creating exportable element",n,e),new Error("[Pixi\u2019VN] Error creating exportable element")}}function h(n,e){let r=l(n);return e.length>1&&"type"in e[0]&&(e=e.reverse()),e.forEach(t=>{"type"in t?p(r,t):c(r,t);}),r}function p(n,e){let r=n;e.path&&e.path.length>0?e.path.forEach((t,i)=>{if(e.path&&i===e.path.length-1)switch(e.type){case "CHANGE":case "REMOVE":r[t]=e.oldValue;break;case "CREATE":Array.isArray(r)&&typeof t=="number"?r.splice(t,1):delete r[t];break}else r=r[t];}):a.warn("No path found, skipping diff",e);}function c(n,e){let r=n;e.path&&e.path.length>0?e.path.forEach((t,i)=>{if(e.path&&i===e.path.length-1){if(e.kind==="E"||e.kind==="D")r[t]=e.lhs;else if(e.kind==="N")Number.isInteger(t)?Array.isArray(r)&&r.splice(t,1):typeof t=="string"&&delete r[t];else if(e.kind==="A"){let o=e.index;e.item.kind==="N"?r[t].splice(o,1):e.item.kind==="E"||e.item.kind==="D"?r[t][o]=e.item.lhs:e.item.kind==="A"?a.warn("Nested array found, skipping diff",e):a.warn("No array found, skipping diff",e);}}else r=r[t];}):a.warn("No path found, skipping diff",e);}export{h as restoreDiffChanges};