object-diagram-js-differ 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).odDiff=e()}(this,(function(){"use strict";const t=Object.prototype.toString,e=Object.prototype.hasOwnProperty;function n(e){return"[object Array]"===t.call(e)}function i(t,n){return e.call(t,n)}function r(t,e){let r,l;if(void 0===t)return;const f=n(t)?o:s;for(let n in t)if(i(t,n)&&(r=t[n],l=e(r,f(n)),!1===l))return r}function s(t){return t}function o(t){return Number(t)}class l{constructor(t){this.selfOptions=t||{},this.pipes={}}options(t){return t&&(this.selfOptions=t),this.selfOptions}pipe(t,e){let n=e;if("string"==typeof t){if(void 0===n)return this.pipes[t];this.pipes[t]=n}if(t&&t.name){if(n=t,n.processor===this)return n;this.pipes[n.name]=n}return n.processor=this,n}process(t,e){let n=t;n.options=this.options();let i,r=e||t.pipe||"default";for(;r;)void 0!==n.nextAfterChildren&&(n.next=n.nextAfterChildren,n.nextAfterChildren=null),"string"==typeof r&&(r=this.pipe(r)),r.process(n),i=r,r=null,n&&n.next&&(n=n.next,r=n.pipe||i);return n.hasResult?n.result:void 0}}class f{constructor(t){this.name=t,this.filters=[]}process(t){if(!this.processor)throw new Error("add this pipe to a processor before using it");const e=this.debug,n=this.filters.length,i=t;for(let t=0;t<n;t++){const n=this.filters[t];if(e&&this.log(`filter: ${n.filterName}`),n(i),"object"==typeof i&&i.exiting){i.exiting=!1;break}}!i.next&&this.resultCheck&&this.resultCheck(i)}log(t){console.log(`[jsondiffpatch] ${this.name} pipe, ${t}`)}append(...t){return this.filters.push(...t),this}prepend(...t){return this.filters.unshift(...t),this}indexOf(t){if(!t)throw new Error("a filter name is required");for(let e=0;e<this.filters.length;e++){if(this.filters[e].filterName===t)return e}throw new Error(`filter not found: ${t}`)}list(){return this.filters.map((t=>t.filterName))}after(t,...e){const n=this.indexOf(t);return this.filters.splice(n+1,0,...e),this}before(t,...e){const n=this.indexOf(t);return this.filters.splice(n,0,...e),this}replace(t,...e){const n=this.indexOf(t);return this.filters.splice(n,1,...e),this}remove(t){const e=this.indexOf(t);return this.filters.splice(e,1),this}clear(){return this.filters.length=0,this}shouldHaveResult(t){if(!1!==t){if(!this.resultCheck)return this.resultCheck=t=>{if(!t.hasResult){console.log(t);const e=new Error(`${this.name} failed`);throw e.noResult=!0,e}},this}else this.resultCheck=null}}class c{setResult(t){return this.result=t,this.hasResult=!0,this}exit(){return this.exiting=!0,this}push(t,e){return t.parent=this,void 0!==e&&(t.childName=e),t.root=this.root||this,t.options=t.options||this.options,this.children?(this.children[this.children.length-1].next=t,this.children.push(t)):(this.children=[t],this.nextAfterChildren=this.next||null,this.next=t),t.next=this,this}}function h(t){if("object"!=typeof t)return t;if(null===t)return null;if(Array.isArray(t))return t.map(h);if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return function(t){const e=/^\/(.*)\/([gimyu]*)$/.exec(t.toString());return new RegExp(e[1],e[2])}(t);const e={};for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=h(t[n]));return e}class u extends c{constructor(t,e){super(),this.left=t,this.right=e,this.pipe="diff"}setResult(t){if(this.options.cloneDiffValues&&"object"==typeof t){const e="function"==typeof this.options.cloneDiffValues?this.options.cloneDiffValues:h;"object"==typeof t[0]&&(t[0]=e(t[0])),"object"==typeof t[1]&&(t[1]=e(t[1]))}return super.setResult(t)}}class a extends c{constructor(t,e){super(),this.left=t,this.delta=e,this.pipe="patch"}}class d extends c{constructor(t){super(),this.delta=t,this.pipe="reverse"}}const p=function(t){if(t.left!==t.right)if(void 0!==t.left)if(void 0!==t.right){if("function"==typeof t.left||"function"==typeof t.right)throw new Error("functions are not supported");t.leftType=null===t.left?"null":typeof t.left,t.rightType=null===t.right?"null":typeof t.right,t.leftType===t.rightType&&"boolean"!==t.leftType&&"number"!==t.leftType?("object"===t.leftType&&(t.leftIsArray=Array.isArray(t.left)),"object"===t.rightType&&(t.rightIsArray=Array.isArray(t.right)),t.leftIsArray===t.rightIsArray?t.left instanceof RegExp&&(t.right instanceof RegExp?t.setResult([t.left.toString(),t.right.toString()]).exit():t.setResult([t.left,t.right]).exit()):t.setResult([t.left,t.right]).exit()):t.setResult([t.left,t.right]).exit()}else t.setResult([t.left,0,0]).exit();else{if("function"==typeof t.right)throw new Error("functions are not supported");t.setResult([t.right]).exit()}else t.setResult(void 0).exit()};p.filterName="trivial";const g=function(t){if(void 0===t.delta)return void t.setResult(t.left).exit();if(t.nested=!Array.isArray(t.delta),t.nested)return;const e=t.delta;if(1!==e.length)if(2!==e.length)3===e.length&&0===e[2]&&t.setResult(void 0).exit();else{if(t.left instanceof RegExp){const n=/^\/(.*)\/([gimyu]+)$/.exec(e[1]);if(n)return void t.setResult(new RegExp(n[1],n[2])).exit()}t.setResult(e[1]).exit()}else t.setResult(e[0]).exit()};g.filterName="trivial";const y=function(t){if(void 0===t.delta)return void t.setResult(t.delta).exit();if(t.nested=!Array.isArray(t.delta),t.nested)return;const e=t.delta;1!==e.length?2!==e.length?3===e.length&&0===e[2]&&t.setResult([e[0]]).exit():t.setResult([e[1],e[0]]).exit():t.setResult([e[0],0,0]).exit()};y.filterName="trivial";const x=t=>{if(!t||!t.children)return;const e=t.children.length;let n,i=t.result;for(let r=0;r<e;r++)n=t.children[r],void 0!==n.result&&(i=i||{},i[n.childName]=n.result);i&&t.leftIsArray&&(i._t="a"),t.setResult(i).exit()};x.filterName="collectChildren";const m=t=>{if(t.leftIsArray||"object"!==t.leftType)return;const e=t.left,n=t.right;let i,r;const s=t.options.propertyFilter;for(i in e)Object.prototype.hasOwnProperty.call(e,i)&&(s&&!s(i,t)||(r=new u(e[i],n[i]),t.push(r,i)));for(i in n)Object.prototype.hasOwnProperty.call(n,i)&&(s&&!s(i,t)||void 0===e[i]&&(r=new u(void 0,n[i]),t.push(r,i)));t.children&&0!==t.children.length?t.exit():t.setResult(void 0).exit()};m.filterName="objects";const v=function(t){if(!t.nested)return;const e=t.delta;if(e._t)return;const n=e;let i,r;for(i in n)r=new a(t.left[i],n[i]),t.push(r,i);t.exit()};v.filterName="objects";const R=function(t){if(!t||!t.children)return;if(t.delta._t)return;const e=t.left,n=t.children.length;let i;for(let r=0;r<n;r++){i=t.children[r];const n=i.childName;Object.prototype.hasOwnProperty.call(t.left,n)&&void 0===i.result?delete e[n]:e[n]!==i.result&&(e[n]=i.result)}t.setResult(e).exit()};R.filterName="collectChildren";const w=function(t){if(!t.nested)return;if(t.delta._t)return;const e=t.delta;let n,i;for(n in e)i=new d(e[n]),t.push(i,n);t.exit()};w.filterName="objects";const _=t=>{if(!t||!t.children)return;if(t.delta._t)return;const e=t.children.length;let n;const i={};for(let r=0;r<e;r++){n=t.children[r];const e=n.childName;i[e]!==n.result&&(i[e]=n.result)}t.setResult(i).exit()};_.filterName="collectChildren";const b=function(t,e,n,i){return t[n]===e[i]};var N=function(t,e,n,i){const r=i||{},s=function(t,e,n,i){const r=t.length,s=e.length;let o,l;const f=new Array(r+1);for(o=0;o<r+1;o++)for(f[o]=new Array(s+1),l=0;l<s+1;l++)f[o][l]=0;for(f.match=n,o=1;o<r+1;o++)for(l=1;l<s+1;l++)n(t,e,o-1,l-1,i)?f[o][l]=f[o-1][l-1]+1:f[o][l]=Math.max(f[o-1][l],f[o][l-1]);return f}(t,e,n||b,r);return function(t,e,n,i){let r=e.length,s=n.length;const o={sequence:[],indices1:[],indices2:[]};for(;0!==r&&0!==s;)t.match(e,n,r-1,s-1,i)?(o.sequence.unshift(e[r-1]),o.indices1.unshift(r-1),o.indices2.unshift(s-1),--r,--s):t[r][s-1]>t[r-1][s]?--s:--r;return o}(s,t,e,r)};function j(t,e,n,i,r){const s=t[n],o=e[i];if(s===o)return!0;if("object"!=typeof s||"object"!=typeof o)return!1;const l=r.objectHash;if(!l)return r.matchByPosition&&n===i;r.hashCache1=r.hashCache1||[];let f=r.hashCache1[n];if(void 0===f&&(r.hashCache1[n]=f=l(s,n)),void 0===f)return!1;r.hashCache2=r.hashCache2||[];let c=r.hashCache2[i];return void 0===c&&(r.hashCache2[i]=c=l(o,i)),void 0!==c&&f===c}const A=function(t){if(!t.leftIsArray)return;const e={objectHash:t.options&&t.options.objectHash,matchByPosition:t.options&&t.options.matchByPosition};let n,i,r,s=0,o=0;const l=t.left,f=t.right,c=l.length,h=f.length;let a,d;for(c>0&&h>0&&!e.objectHash&&"boolean"!=typeof e.matchByPosition&&(e.matchByPosition=!function(t,e,n,i){for(let r=0;r<n;r++){const n=t[r];for(let t=0;t<i;t++){const i=e[t];if(r!==t&&n===i)return!0}}}(l,f,c,h));s<c&&s<h&&j(l,f,s,s,e);)n=s,a=new u(l[n],f[n]),t.push(a,n),s++;for(;o+s<c&&o+s<h&&j(l,f,c-1-o,h-1-o,e);)i=c-1-o,r=h-1-o,a=new u(l[i],f[r]),t.push(a,r),o++;if(s+o===c){if(c===h)return void t.setResult(void 0).exit();for(d=d||{_t:"a"},n=s;n<h-o;n++)d[n]=[f[n]];return void t.setResult(d).exit()}if(s+o===h){for(d=d||{_t:"a"},n=s;n<c-o;n++)d[`_${n}`]=[l[n],0,0];return void t.setResult(d).exit()}delete e.hashCache1,delete e.hashCache2;const p=l.slice(s,c-o),g=f.slice(s,h-o),y=N(p,g,j,e),x=[];for(d=d||{_t:"a"},n=s;n<c-o;n++)y.indices1.indexOf(n-s)<0&&(d[`_${n}`]=[l[n],0,0],x.push(n));let m=!0;t.options&&t.options.arrays&&!1===t.options.arrays.detectMove&&(m=!1);let v=!1;t.options&&t.options.arrays&&t.options.arrays.includeValueOnMove&&(v=!0);const R=x.length;for(n=s;n<h-o;n++){const o=y.indices2.indexOf(n-s);if(o<0){let o=!1;if(m&&R>0)for(let c=0;c<R;c++)if(i=x[c],j(p,g,i-s,n-s,e)){d[`_${i}`].splice(1,2,n,3),v||(d[`_${i}`][0]=""),r=n,a=new u(l[i],f[r]),t.push(a,r),x.splice(c,1),o=!0;break}o||(d[n]=[f[n]])}else i=y.indices1[o]+s,r=y.indices2[o]+s,a=new u(l[i],f[r]),t.push(a,r)}t.setResult(d).exit()};A.filterName="arrays";const C={numerically:(t,e)=>t-e,numericallyBy:t=>(e,n)=>e[t]-n[t]},O=function(t){if(!t.nested)return;const e=t.delta;if("a"!==e._t)return;let n,i;const r=e,s=t.left;let o=[],l=[];const f=[];for(n in r)if("_t"!==n)if("_"===n[0]){const t=n;if(0!==r[t][2]&&3!==r[t][2])throw new Error(`only removal or move can be applied at original array indices, invalid diff type: ${r[t][2]}`);o.push(parseInt(n.slice(1),10))}else{const t=n;1===r[t].length?l.push({index:parseInt(t,10),value:r[t][0]}):f.push({index:parseInt(t,10),delta:r[t]})}for(o=o.sort(C.numerically),n=o.length-1;n>=0;n--){i=o[n];const t=r[`_${i}`],e=s.splice(i,1)[0];3===t[2]&&l.push({index:t[1],value:e})}l=l.sort(C.numericallyBy("index"));const c=l.length;for(n=0;n<c;n++){const t=l[n];s.splice(t.index,0,t.value)}const h=f.length;let u;if(h>0)for(n=0;n<h;n++){const e=f[n];u=new a(s[e.index],e.delta),t.push(u,e.index)}t.children?t.exit():t.setResult(s).exit()};O.filterName="arrays";const T=function(t){if(!t||!t.children)return;if("a"!==t.delta._t)return;const e=t.left,n=t.children.length;let i;for(let r=0;r<n;r++){i=t.children[r];e[i.childName]=i.result}t.setResult(e).exit()};T.filterName="arraysCollectChildren";const $=function(t){if(!t.nested){const e=t.delta;if(3===e[2]){const n=e;t.newName=`_${n[1]}`,t.setResult([n[0],parseInt(t.childName.substring(1),10),3]).exit()}return}const e=t.delta;if("a"!==e._t)return;const n=e;let i,r;for(i in n)"_t"!==i&&(r=new d(n[i]),t.push(r,i));t.exit()};$.filterName="arrays";const I=(t,e,n)=>{if("string"==typeof e&&"_"===e[0])return parseInt(e.substring(1),10);if(Array.isArray(n)&&0===n[2])return`_${e}`;let i=+e;for(const n in t){const r=t[n];if(Array.isArray(r))if(3===r[2]){const t=parseInt(n.substring(1),10),s=r[1];if(s===+e)return t;t<=i&&s>i?i++:t>=i&&s<i&&i--}else if(0===r[2]){parseInt(n.substring(1),10)<=i&&i++}else 1===r.length&&parseInt(n,10)<=i&&i--}return i},D=t=>{if(!t||!t.children)return;const e=t.delta;if("a"!==e._t)return;const n=e,i=t.children.length;let r;const s={_t:"a"};for(let e=0;e<i;e++){r=t.children[e];let i=r.newName;void 0===i&&(i=I(n,r.childName,r.result)),s[i]!==r.result&&(s[i]=r.result)}t.setResult(s).exit()};D.filterName="arraysCollectChildren";const E=function(t){t.left instanceof Date?(t.right instanceof Date?t.left.getTime()!==t.right.getTime()?t.setResult([t.left,t.right]):t.setResult(void 0):t.setResult([t.left,t.right]),t.exit()):t.right instanceof Date&&t.setResult([t.left,t.right]).exit()};E.filterName="dates";let P=null;function k(t,e){var n;if(!P){let i;if(!(null===(n=null==t?void 0:t.textDiff)||void 0===n?void 0:n.diffMatchPatch)){if(!e)return null;const t=new Error("The diff-match-patch library was not provided. Pass the library in through the options or use the `jsondiffpatch/with-text-diffs` entry-point.");throw t.diff_match_patch_not_found=!0,t}i=new t.textDiff.diffMatchPatch,P={diff:function(t,e){return i.patch_toText(i.patch_make(t,e))},patch:function(t,e){const n=i.patch_apply(i.patch_fromText(e),t);for(let t=0;t<n[1].length;t++)if(!n[1][t]){new Error("text patch failed").textPatchFailed=!0}return n[0]}}}return P}const H=function(t){if("string"!==t.leftType)return;const e=t.left,n=t.right,i=t.options&&t.options.textDiff&&t.options.textDiff.minLength||60;if(e.length<i||n.length<i)return void t.setResult([e,n]).exit();const r=k(t.options);if(!r)return void t.setResult([e,n]).exit();const s=r.diff;t.setResult([s(e,n),0,2]).exit()};H.filterName="texts";const B=function(t){if(t.nested)return;const e=t.delta;if(2!==e[2])return;const n=e,i=k(t.options,!0).patch;t.setResult(i(t.left,n[0])).exit()};B.filterName="texts";const V=function(t){let e,n,i,r,s=null;const o=/^@@ +-(\d+),(\d+) +\+(\d+),(\d+) +@@$/;let l;const f=t.split("\n");for(e=0,n=f.length;e<n;e++){i=f[e];const t=i.slice(0,1);"@"===t?(s=o.exec(i),l=e,f[l]="@@ -"+s[3]+","+s[4]+" +"+s[1]+","+s[2]+" @@"):"+"===t?(f[e]="-"+f[e].slice(1),"+"===f[e-1].slice(0,1)&&(r=f[e],f[e]=f[e-1],f[e-1]=r)):"-"===t&&(f[e]="+"+f[e].slice(1))}return f.join("\n")},M=function(t){if(t.nested)return;const e=t.delta;if(2!==e[2])return;const n=e;t.setResult([V(n[0]),0,2]).exit()};M.filterName="texts";class S{constructor(t){this.processor=new l(t),this.processor.pipe(new f("diff").append(x,p,E,H,m,A).shouldHaveResult()),this.processor.pipe(new f("patch").append(R,T,g,B,v,O).shouldHaveResult()),this.processor.pipe(new f("reverse").append(_,D,y,M,w,$).shouldHaveResult())}options(t){return this.processor.options(t)}diff(t,e){return this.processor.process(new u(t,e))}patch(t,e){return this.processor.process(new a(t,e))}reverse(t){return this.processor.process(new d(t))}unpatch(t,e){return this.patch(t,this.reverse(e))}clone(t){return h(t)}}function q(t){const e=function(t,e){return e.some((function(e){return function(t,e){return t.$instanceOf(e)}(t,e)}))}(t,["od:OdBoard","od:Object","od:Link"]);if(e)return{element:t,property:""}}function F(){this._layoutChanged={},this._changed={},this._removed={},this._added={}}function L(){}return F.prototype.removed=function(t,e,n,i){let r;(r=q(n))?this._removed[r.element.id]||(this._removed[r.element.id]=n):(r=q(t))&&this.changed(r.element,r.property+e+"["+i+"]",null,n)},F.prototype.changed=function(t,e,n,i){let r;if(r=q(t)){let s=this._changed[r.element.id];s||(s=this._changed[r.element.id]={model:t,attrs:{}}),void 0===i&&void 0===n||(s.attrs[e]={oldValue:i,newValue:n})}},F.prototype.added=function(t,e,n,i){let r;(r=q(n))?this._added[r.element.id]||(this._added[r.element.id]=n):(r=q(t))&&this.changed(r.element,r.property+e+"["+i+"]",n,null)},F.prototype.moved=function(t,e,n,i){},L.prototype.createDiff=function(t,e){return new S({objectHash:function(t){return t.id||JSON.stringify(t)},propertyFilter:function(t,e){return"$instanceOf"!==t}}).diff(t,e)},L.prototype.diff=function(t,e,i){i=i||new F;return function t(e,s){r(e,(function(e,o){var l,f,c;"a"!==e._t&&n(e)&&n(e[0])&&(l=e[0],f=function(t,n,i){return t[(3===e.length?"_":"")+i]=[n],t},c={_t:"a"},r(l,(function(t,e){c=f(c,t,e)})),e=c),"a"===e._t?r(e,(function(e,r){if("_t"===r)return;const l=/^_/.test(r),f=!l&&n(e),c=l&&""===e[0];r=parseInt(l?r.slice(1):r,10),f||l&&!c?i[l?"removed":"added"](s,o,e[0],r):c?i.moved(s,o,e[1],e[2]):t(e,s[o][r])})):n(e)?i.changed(s,o,e[0],e[1]):(i.changed(s,o),t(e,s[o]))}))}(this.createDiff(t,e),e),i},function(t,e,n){return(new L).diff(t,e,n)}}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).odDiff=e()}(this,(function(){"use strict";const t=Object.prototype.toString,e=Object.prototype.hasOwnProperty;function i(e){return"[object Array]"===t.call(e)}function n(t,i){return!(null==t)&&e.call(t,i)}function r(t,e){let r,l;if(void 0===t)return;const c=i(t)?o:s;for(let i in t)if(n(t,i)&&(r=t[i],l=e(r,c(i)),!1===l))return r}function s(t){return t}function o(t){return Number(t)}function l(t){if("object"!=typeof t)return t;if(null===t)return null;if(Array.isArray(t))return t.map(l);if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return function(t){var e;const i=/^\/(.*)\/([gimyu]*)$/.exec(t.toString());if(!i)throw new Error("Invalid RegExp");return new RegExp(null!==(e=i[1])&&void 0!==e?e:"",i[2])}(t);const e={};for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=l(t[i]));return e}class c{setResult(t){return this.result=t,this.hasResult=!0,this}exit(){return this.exiting=!0,this}push(t,e){var i;return t.parent=this,void 0!==e&&(t.childName=e),t.root=this.root||this,t.options=t.options||this.options,this.children?(!function(t,e){if(0===t.length)throw new Error("Expected a non-empty array")}(this.children),(i=this.children,i[i.length-1]).next=t,this.children.push(t)):(this.children=[t],this.nextAfterChildren=this.next||null,this.next=t),t.next=this,this}}class f extends c{constructor(t,e){super(),this.left=t,this.right=e,this.pipe="diff"}prepareDeltaResult(t){var e,i,n,r;if("object"==typeof t&&((null===(e=this.options)||void 0===e?void 0:e.omitRemovedValues)&&Array.isArray(t)&&t.length>1&&(2===t.length||0===t[2]||3===t[2])&&(t[0]=0),null===(i=this.options)||void 0===i?void 0:i.cloneDiffValues)){const e="function"==typeof(null===(n=this.options)||void 0===n?void 0:n.cloneDiffValues)?null===(r=this.options)||void 0===r?void 0:r.cloneDiffValues:l;"object"==typeof t[0]&&(t[0]=e(t[0])),"object"==typeof t[1]&&(t[1]=e(t[1]))}return t}setResult(t){return this.prepareDeltaResult(t),super.setResult(t)}}class u extends c{constructor(t,e){super(),this.left=t,this.delta=e,this.pipe="patch"}}class h extends c{constructor(t){super(),this.delta=t,this.pipe="reverse"}}class a{constructor(t){this.name=t,this.filters=[]}process(t){if(!this.processor)throw new Error("add this pipe to a processor before using it");const e=this.debug,i=this.filters.length,n=t;for(let t=0;t<i;t++){const i=this.filters[t];if(i&&(e&&this.log(`filter: ${i.filterName}`),i(n),"object"==typeof n&&n.exiting)){n.exiting=!1;break}}!n.next&&this.resultCheck&&this.resultCheck(n)}log(t){console.log(`[jsondiffpatch] ${this.name} pipe, ${t}`)}append(...t){return this.filters.push(...t),this}prepend(...t){return this.filters.unshift(...t),this}indexOf(t){if(!t)throw new Error("a filter name is required");for(let e=0;e<this.filters.length;e++){const i=this.filters[e];if((null==i?void 0:i.filterName)===t)return e}throw new Error(`filter not found: ${t}`)}list(){return this.filters.map((t=>t.filterName))}after(t,...e){const i=this.indexOf(t);return this.filters.splice(i+1,0,...e),this}before(t,...e){const i=this.indexOf(t);return this.filters.splice(i,0,...e),this}replace(t,...e){const i=this.indexOf(t);return this.filters.splice(i,1,...e),this}remove(t){const e=this.indexOf(t);return this.filters.splice(e,1),this}clear(){return this.filters.length=0,this}shouldHaveResult(t){return!1===t?(this.resultCheck=null,this):(this.resultCheck||(this.resultCheck=t=>{if(!t.hasResult){console.log(t);const e=new Error(`${this.name} failed`);throw e.noResult=!0,e}}),this)}}class d{constructor(t){this.selfOptions=t||{},this.pipes={}}options(t){return t&&(this.selfOptions=t),this.selfOptions}pipe(t,e){let i=e;if("string"==typeof t){if(void 0===i)return this.pipes[t];this.pipes[t]=i}if(t&&t.name){if(i=t,i.processor===this)return i;this.pipes[i.name]=i}if(!i)throw new Error(`pipe is not defined: ${t}`);return i.processor=this,i}process(t,e){let i=t;i.options=this.options();let n,r=e||t.pipe||"default";for(;r;)void 0!==i.nextAfterChildren&&(i.next=i.nextAfterChildren,i.nextAfterChildren=null),"string"==typeof r&&(r=this.pipe(r)),r.process(i),n=r,r=null,i&&i.next&&(i=i.next,r=i.pipe||n);return i.hasResult?i.result:void 0}}const p=(t,e,i,n)=>t[i]===e[n];var v=(t,e,i,n)=>{const r=n||{},s=((t,e,i,n)=>{var r,s,o;const l=t.length,c=e.length;let f,u;const h=new Array(l+1);for(f=0;f<l+1;f++){const t=new Array(c+1);for(u=0;u<c+1;u++)t[u]=0;h[f]=t}for(h.match=i,f=1;f<l+1;f++){const l=h[f];if(void 0===l)throw new Error("LCS matrix row is undefined");const a=h[f-1];if(void 0===a)throw new Error("LCS matrix row is undefined");for(u=1;u<c+1;u++)i(t,e,f-1,u-1,n)?l[u]=(null!==(r=a[u-1])&&void 0!==r?r:0)+1:l[u]=Math.max(null!==(s=a[u])&&void 0!==s?s:0,null!==(o=l[u-1])&&void 0!==o?o:0)}return h})(t,e,i||p,r);return((t,e,i,n)=>{let r=e.length,s=i.length;const o={sequence:[],indices1:[],indices2:[]};for(;0!==r&&0!==s;){if(void 0===t.match)throw new Error("LCS matrix match function is undefined");if(t.match(e,i,r-1,s-1,n))o.sequence.unshift(e[r-1]),o.indices1.unshift(r-1),o.indices2.unshift(s-1),--r,--s;else{const e=t[r];if(void 0===e)throw new Error("LCS matrix row is undefined");const i=e[s-1];if(void 0===i)throw new Error("LCS matrix value is undefined");const n=t[r-1];if(void 0===n)throw new Error("LCS matrix row is undefined");const o=n[s];if(void 0===o)throw new Error("LCS matrix value is undefined");i>o?--s:--r}}return o})(s,t,e,r)};function y(t,e,i,n,r){const s=t[i],o=e[n];if(s===o)return!0;if("object"!=typeof s||"object"!=typeof o)return!1;const l=r.objectHash;if(!l)return r.matchByPosition&&i===n;r.hashCache1=r.hashCache1||[];let c=r.hashCache1[i];if(void 0===c&&(r.hashCache1[i]=c=l(s,i)),void 0===c)return!1;r.hashCache2=r.hashCache2||[];let f=r.hashCache2[n];return void 0===f&&(r.hashCache2[n]=f=l(o,n)),void 0!==f&&c===f}const g=function(t){var e,i,n,r,s;if(!t.leftIsArray)return;const o={objectHash:null===(e=t.options)||void 0===e?void 0:e.objectHash,matchByPosition:null===(i=t.options)||void 0===i?void 0:i.matchByPosition};let l,c,u,h=0,a=0;const d=t.left,p=t.right,g=d.length,m=p.length;let x,w;for(g>0&&m>0&&!o.objectHash&&"boolean"!=typeof o.matchByPosition&&(o.matchByPosition=!function(t,e,i,n){for(let r=0;r<i;r++){const i=t[r];for(let t=0;t<n;t++){const n=e[t];if(r!==t&&i===n)return!0}}return!1}(d,p,g,m));h<g&&h<m&&y(d,p,h,h,o);)l=h,x=new f(d[l],p[l]),t.push(x,l),h++;for(;a+h<g&&a+h<m&&y(d,p,g-1-a,m-1-a,o);)c=g-1-a,u=m-1-a,x=new f(d[c],p[u]),t.push(x,u),a++;if(h+a===g){if(g===m)return void t.setResult(void 0).exit();for(w=w||{_t:"a"},l=h;l<m-a;l++)w[l]=[p[l]],t.prepareDeltaResult(w[l]);return void t.setResult(w).exit()}if(h+a===m){for(w=w||{_t:"a"},l=h;l<g-a;l++){const e=`_${l}`;w[e]=[d[l],0,0],t.prepareDeltaResult(w[e])}return void t.setResult(w).exit()}o.hashCache1=void 0,o.hashCache2=void 0;const R=d.slice(h,g-a),b=p.slice(h,m-a),_=v(R,b,y,o),N=[];for(w=w||{_t:"a"},l=h;l<g-a;l++)if(_.indices1.indexOf(l-h)<0){const e=`_${l}`;w[e]=[d[l],0,0],t.prepareDeltaResult(w[e]),N.push(l)}let C=!0;(null===(n=t.options)||void 0===n?void 0:n.arrays)&&!1===t.options.arrays.detectMove&&(C=!1);let A=!1;(null===(s=null===(r=t.options)||void 0===r?void 0:r.arrays)||void 0===s?void 0:s.includeValueOnMove)&&(A=!0);const E=N.length;for(l=h;l<m-a;l++){const e=_.indices2.indexOf(l-h);if(e<0){let e=!1;if(C&&E>0)for(let i=0;i<E;i++){c=N[i];const n=void 0===c?void 0:w[`_${c}`];if(void 0!==c&&n&&y(R,b,c-h,l-h,o)){n.splice(1,2,l,3),n.splice(1,2,l,3),A||(n[0]=""),u=l,x=new f(d[c],p[u]),t.push(x,u),N.splice(i,1),e=!0;break}}e||(w[l]=[p[l]],t.prepareDeltaResult(w[l]))}else{if(void 0===_.indices1[e])throw new Error(`Invalid indexOnArray2: ${e}, seq.indices1: ${_.indices1}`);if(c=_.indices1[e]+h,void 0===_.indices2[e])throw new Error(`Invalid indexOnArray2: ${e}, seq.indices2: ${_.indices2}`);u=_.indices2[e]+h,x=new f(d[c],p[u]),t.push(x,u)}}t.setResult(w).exit()};g.filterName="arrays";const m={numerically:(t,e)=>t-e,numericallyBy:t=>(e,i)=>e[t]-i[t]},x=function(t){var e;if(!t.nested)return;const i=t.delta;if("a"!==i._t)return;let n,r;const s=i,o=t.left;let l=[],c=[];const f=[];for(n in s)if("_t"!==n)if("_"===n[0]){const t=n;if(void 0===s[t]||0!==s[t][2]&&3!==s[t][2])throw new Error(`only removal or move can be applied at original array indices, invalid diff type: ${null===(e=s[t])||void 0===e?void 0:e[2]}`);l.push(Number.parseInt(n.slice(1),10))}else{const t=n;1===s[t].length?c.push({index:Number.parseInt(t,10),value:s[t][0]}):f.push({index:Number.parseInt(t,10),delta:s[t]})}for(l=l.sort(m.numerically),n=l.length-1;n>=0;n--){if(r=l[n],void 0===r)continue;const t=s[`_${r}`],e=o.splice(r,1)[0];3===(null==t?void 0:t[2])&&c.push({index:t[1],value:e})}c=c.sort(m.numericallyBy("index"));const h=c.length;for(n=0;n<h;n++){const t=c[n];void 0!==t&&o.splice(t.index,0,t.value)}const a=f.length;if(a>0)for(n=0;n<a;n++){const e=f[n];if(void 0===e)continue;const i=new u(o[e.index],e.delta);t.push(i,e.index)}t.children?t.exit():t.setResult(o).exit()};x.filterName="arrays";const w=function(t){if(!t||!t.children)return;if("a"!==t.delta._t)return;const e=t.left,i=t.children.length;for(let n=0;n<i;n++){const i=t.children[n];if(void 0===i)continue;e[i.childName]=i.result}t.setResult(e).exit()};w.filterName="arraysCollectChildren";const R=function(t){if(!t.nested){const e=t.delta;if(3===e[2]){const i=e;t.newName=`_${i[1]}`,t.setResult([i[0],Number.parseInt(t.childName.substring(1),10),3]).exit()}return}const e=t.delta;if("a"!==e._t)return;const i=e;for(const e in i){if("_t"===e)continue;const n=new h(i[e]);t.push(n,e)}t.exit()};R.filterName="arrays";const b=(t,e,i)=>{if("string"==typeof e&&"_"===e[0])return Number.parseInt(e.substring(1),10);if(Array.isArray(i)&&0===i[2])return`_${e}`;let n=+e;for(const i in t){const r=t[i];if(Array.isArray(r))if(3===r[2]){const t=Number.parseInt(i.substring(1),10),s=r[1];if(s===+e)return t;t<=n&&s>n?n++:t>=n&&s<n&&n--}else if(0===r[2]){Number.parseInt(i.substring(1),10)<=n&&n++}else 1===r.length&&Number.parseInt(i,10)<=n&&n--}return n},_=t=>{if(!t||!t.children)return;const e=t.delta;if("a"!==e._t)return;const i=e,n=t.children.length,r={_t:"a"};for(let e=0;e<n;e++){const n=t.children[e];if(void 0===n)continue;let s=n.newName;if(void 0===s){if(void 0===n.childName)throw new Error("child.childName is undefined");s=b(i,n.childName,n.result)}r[s]!==n.result&&(r[s]=n.result)}t.setResult(r).exit()};_.filterName="arraysCollectChildren";const N=function(t){t.left instanceof Date?(t.right instanceof Date?t.left.getTime()!==t.right.getTime()?t.setResult([t.left,t.right]):t.setResult(void 0):t.setResult([t.left,t.right]),t.exit()):t.right instanceof Date&&t.setResult([t.left,t.right]).exit()};N.filterName="dates";const C=t=>{if(!t||!t.children)return;const e=t.children.length;let i=t.result;for(let n=0;n<e;n++){const e=t.children[n];if(void 0!==e&&void 0!==e.result){if(i=i||{},void 0===e.childName)throw new Error("diff child.childName is undefined");i[e.childName]=e.result}}i&&t.leftIsArray&&(i._t="a"),t.setResult(i).exit()};C.filterName="collectChildren";const A=t=>{var e;if(t.leftIsArray||"object"!==t.leftType)return;const i=t.left,n=t.right,r=null===(e=t.options)||void 0===e?void 0:e.propertyFilter;for(const e in i){if(!Object.prototype.hasOwnProperty.call(i,e))continue;if(r&&!r(e,t))continue;const s=new f(i[e],n[e]);t.push(s,e)}for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)&&(!r||r(e,t))&&void 0===i[e]){const i=new f(void 0,n[e]);t.push(i,e)}t.children&&0!==t.children.length?t.exit():t.setResult(void 0).exit()};A.filterName="objects";const E=function(t){if(!t.nested)return;const e=t.delta;if(e._t)return;const i=e;for(const e in i){const n=new u(t.left[e],i[e]);t.push(n,e)}t.exit()};E.filterName="objects";const j=function(t){if(!t||!t.children)return;if(t.delta._t)return;const e=t.left,i=t.children.length;for(let n=0;n<i;n++){const i=t.children[n];if(void 0===i)continue;const r=i.childName;Object.prototype.hasOwnProperty.call(t.left,r)&&void 0===i.result?delete e[r]:e[r]!==i.result&&(e[r]=i.result)}t.setResult(e).exit()};j.filterName="collectChildren";const O=function(t){if(!t.nested)return;if(t.delta._t)return;const e=t.delta;for(const i in e){const n=new h(e[i]);t.push(n,i)}t.exit()};O.filterName="objects";const $=t=>{if(!t||!t.children)return;if(t.delta._t)return;const e=t.children.length,i={};for(let n=0;n<e;n++){const e=t.children[n];if(void 0===e)continue;const r=e.childName;i[r]!==e.result&&(i[r]=e.result)}t.setResult(i).exit()};$.filterName="collectChildren";let D=null;function I(t,e){var i;if(!D){let n;if(!(null===(i=null==t?void 0:t.textDiff)||void 0===i?void 0:i.diffMatchPatch)){if(!e)return null;const t=new Error("The diff-match-patch library was not provided. Pass the library in through the options or use the `jsondiffpatch/with-text-diffs` entry-point.");throw t.diff_match_patch_not_found=!0,t}n=new t.textDiff.diffMatchPatch,D={diff:(t,e)=>n.patch_toText(n.patch_make(t,e)),patch:(t,e)=>{const i=n.patch_apply(n.patch_fromText(e),t);for(const t of i[1])if(!t){const t=new Error("text patch failed");throw t.textPatchFailed=!0,t}return i[0]}}}return D}const T=function(t){var e,i;if("string"!==t.leftType)return;const n=t.left,r=t.right,s=(null===(i=null===(e=t.options)||void 0===e?void 0:e.textDiff)||void 0===i?void 0:i.minLength)||60;if(n.length<s||r.length<s)return void t.setResult([n,r]).exit();const o=I(t.options);if(!o)return void t.setResult([n,r]).exit();const l=o.diff;t.setResult([l(n,r),0,2]).exit()};T.filterName="texts";const P=function(t){if(t.nested)return;const e=t.delta;if(2!==e[2])return;const i=e,n=I(t.options,!0).patch;t.setResult(n(t.left,i[0])).exit()};P.filterName="texts";const S=t=>{var e,i,n;const r=/^@@ +-(\d+),(\d+) +\+(\d+),(\d+) +@@$/,s=t.split("\n");for(let t=0;t<s.length;t++){const o=s[t];if(void 0===o)continue;const l=o.slice(0,1);if("@"===l){const e=r.exec(o);if(null!==e){s[t]=`@@ -${e[3]},${e[4]} +${e[1]},${e[2]} @@`}}else if("+"===l){if(s[t]=`-${null===(e=s[t])||void 0===e?void 0:e.slice(1)}`,"+"===(null===(i=s[t-1])||void 0===i?void 0:i.slice(0,1))){const e=s[t];s[t]=s[t-1],s[t-1]=e}}else"-"===l&&(s[t]=`+${null===(n=s[t])||void 0===n?void 0:n.slice(1)}`)}return s.join("\n")},k=function(t){if(t.nested)return;const e=t.delta;if(2!==e[2])return;const i=e;t.setResult([S(i[0]),0,2]).exit()};k.filterName="texts";const H=function(t){if(t.left!==t.right)if(void 0!==t.left)if(void 0!==t.right){if("function"==typeof t.left||"function"==typeof t.right)throw new Error("functions are not supported");t.leftType=null===t.left?"null":typeof t.left,t.rightType=null===t.right?"null":typeof t.right,t.leftType===t.rightType&&"boolean"!==t.leftType&&"number"!==t.leftType?("object"===t.leftType&&(t.leftIsArray=Array.isArray(t.left)),"object"===t.rightType&&(t.rightIsArray=Array.isArray(t.right)),t.leftIsArray===t.rightIsArray?t.left instanceof RegExp&&(t.right instanceof RegExp?t.setResult([t.left.toString(),t.right.toString()]).exit():t.setResult([t.left,t.right]).exit()):t.setResult([t.left,t.right]).exit()):t.setResult([t.left,t.right]).exit()}else t.setResult([t.left,0,0]).exit();else{if("function"==typeof t.right)throw new Error("functions are not supported");t.setResult([t.right]).exit()}else t.setResult(void 0).exit()};H.filterName="trivial";const L=function(t){if(void 0===t.delta)return void t.setResult(t.left).exit();if(t.nested=!Array.isArray(t.delta),t.nested)return;const e=t.delta;if(1!==e.length)if(2!==e.length)3===e.length&&0===e[2]&&t.setResult(void 0).exit();else{if(t.left instanceof RegExp){const i=/^\/(.*)\/([gimyu]+)$/.exec(e[1]);if(null==i?void 0:i[1])return void t.setResult(new RegExp(i[1],i[2])).exit()}t.setResult(e[1]).exit()}else t.setResult(e[0]).exit()};L.filterName="trivial";const B=function(t){if(void 0===t.delta)return void t.setResult(t.delta).exit();if(t.nested=!Array.isArray(t.delta),t.nested)return;const e=t.delta;1!==e.length?2!==e.length?3===e.length&&0===e[2]&&t.setResult([e[0]]).exit():t.setResult([e[1],e[0]]).exit():t.setResult([e[0],0,0]).exit()};B.filterName="trivial";class V{constructor(t){this.processor=new d(t),this.processor.pipe(new a("diff").append(C,H,N,T,A,g).shouldHaveResult()),this.processor.pipe(new a("patch").append(j,w,L,P,E,x).shouldHaveResult()),this.processor.pipe(new a("reverse").append($,_,B,k,O,R).shouldHaveResult())}options(t){return this.processor.options(t)}diff(t,e){return this.processor.process(new f(t,e))}patch(t,e){return this.processor.process(new u(t,e))}reverse(t){return this.processor.process(new h(t))}unpatch(t,e){return this.patch(t,this.reverse(e))}clone(t){return l(t)}}function q(t){const e=function(t,e){return e.some((function(e){return function(t,e){return t.$instanceOf(e)}(t,e)}))}(t,["od:OdBoard","od:Object","od:Link"]);if(e)return{element:t,property:""}}function M(){this._layoutChanged={},this._changed={},this._removed={},this._added={}}function F(){}return M.prototype.removed=function(t,e,i,n){let r;(r=q(i))?this._removed[r.element.id]||(this._removed[r.element.id]=i):(r=q(t))&&this.changed(r.element,r.property+e+"["+n+"]",null,i)},M.prototype.changed=function(t,e,i,n){let r;if(r=q(t)){let s=this._changed[r.element.id];s||(s=this._changed[r.element.id]={model:t,attrs:{}}),void 0===n&&void 0===i||(s.attrs[e]={oldValue:n,newValue:i})}},M.prototype.added=function(t,e,i,n){let r;(r=q(i))?this._added[r.element.id]||(this._added[r.element.id]=i):(r=q(t))&&this.changed(r.element,r.property+e+"["+n+"]",i,null)},M.prototype.moved=function(t,e,i,n){},F.prototype.createDiff=function(t,e){return new V({objectHash:function(t){return t.id||JSON.stringify(t)},propertyFilter:function(t,e){return"$instanceOf"!==t}}).diff(t,e)},F.prototype.diff=function(t,e,n){n=n||new M;return function t(e,s){r(e,(function(e,o){var l,c,f;"a"!==e._t&&i(e)&&i(e[0])&&(l=e[0],c=function(t,i,n){return t[(3===e.length?"_":"")+n]=[i],t},f={_t:"a"},r(l,(function(t,e){f=c(f,t,e)})),e=f),"a"===e._t?r(e,(function(e,r){if("_t"===r)return;const l=/^_/.test(r),c=!l&&i(e),f=l&&""===e[0];r=parseInt(l?r.slice(1):r,10),c||l&&!f?n[l?"removed":"added"](s,o,e[0],r):f?n.moved(s,o,e[1],e[2]):t(e,s[o][r])})):i(e)?n.changed(s,o,e[0],e[1]):(n.changed(s,o),t(e,s[o]))}))}(this.createDiff(t,e),e),n},function(t,e,i){return(new F).diff(t,e,i)}}));
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "object-diagram-js-differ",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A semantic diffing utility for object diagram files",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"all": "run-s lint test",
|
|
6
|
+
"all": "run-s lint test build",
|
|
7
7
|
"lint": "eslint .",
|
|
8
8
|
"lintFix": "eslint . --fix",
|
|
9
9
|
"test": "jasmine",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"sideEffects": false,
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"object-diagram-moddle": "^1.0.
|
|
37
|
+
"object-diagram-moddle": "^1.0.2",
|
|
38
38
|
"eslint": "^8.57.0",
|
|
39
39
|
"eslint-plugin-bpmn-io": "^1.0.0",
|
|
40
40
|
"npm-run-all": "^4.1.5",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"jasmine": "^5.1.0",
|
|
43
43
|
"@babel/eslint-parser": "^7.24.1",
|
|
44
44
|
"@babel/plugin-syntax-import-assertions": "^7.24.1",
|
|
45
|
-
"rollup": "^4.
|
|
45
|
+
"rollup": "^4.50.2",
|
|
46
46
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
47
47
|
"@rollup/plugin-terser": "^0.4.4"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"jsondiffpatch": "^0.
|
|
51
|
-
"min-dash": "^4.2.
|
|
50
|
+
"jsondiffpatch": "^0.7.3",
|
|
51
|
+
"min-dash": "^4.2.3"
|
|
52
52
|
},
|
|
53
53
|
"files": [
|
|
54
54
|
"dist"
|