diff --git a/eslint.config.mjs b/eslint.config.mjs index 569186c30..7b3535813 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -158,7 +158,6 @@ export default [ '**/dist/**', 'src/realtime/share.uncompressed.js', // added when serving 'src/wasm/**/*.js', - 'modules/pcui-diff.ts', 'modules/editor-api/test', 'modules/editor-api/types' ] diff --git a/modules/pcui-diff.ts b/modules/pcui-diff.ts deleted file mode 100644 index ca20e22f6..000000000 --- a/modules/pcui-diff.ts +++ /dev/null @@ -1,8 +0,0 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.diff=e():t.diff=e()}(window,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(t,e){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}(function(){var e;e=function(t){var e;return e=n(t),null==t?"null":"object"===e&&t.constructor===Array?"array":e},t.exports={extendedTypeOf:e}}).call(this)},function(t,e,n){"use strict";function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o=Array.prototype.forEach.bind([]);t.exports=function(t){var e;if(!t)return!1;if("function"===(e=r(t)))return!0;if("object"!==e)return!1;try{return o(t),!0}catch(t){if(t instanceof TypeError)return!1;throw t}}},function(t,e,n){function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}(function(){var e,o,i,u,c,l,f,s,a,p,h,y,g,d,b={}.hasOwnProperty;e=n(4).SequenceMatcher,a=n(0).extendedTypeOf,i=n(14).colorize,h=function(t){return"object"!==r(t)||null===t},g=function(t,e,n){var r,o,i,u,c,l,f,a,p;for(o in null==n&&(n={}),c={},l=0,t)b.call(t,o)&&(a=t[o],o in e||(c[o+"__deleted"]=a,l-=30));for(o in e)b.call(e,o)&&(p=e[o],o in t||(c[o+"__added"]=p,l-=30));for(o in t)b.call(t,o)&&(a=t[o],o in e&&(l+=20,p=e[o],f=(i=s(a,p,n))[0],(r=i[1])&&(c[o]=r),l+=Math.min(20,Math.max(-10,f/5))));return 0===Object.keys(c).length?(l=(u=[100*Math.max(Object.keys(t).length,.5),void 0])[0],c=u[1]):l=Math.max(0,l),[l,c]},p=function(t,e,n){var r,o,i,u,c,f;for(u in r=null,c=0,n)b.call(n,u)&&(o=n[u],"__next"!==u&&(i=Math.abs(c-e),a(t)===a(o)&&(f=l(t,o),(!r||f>r.score||f===r.score&&i40&&null==e[r.key]?(e[r.key]=i,f.push(r.key)):(l="__$!SCALAR"+e.__next++,e[l]=i,f.push(l));return f},y=function(t,e){return"string"==typeof t&&t in e},u=function(t,e){return y(t,e)?e[t]:t},o=function(t,n,r){var o,i,l,f,s,a,p,h,g,b,m,v,w,S,O,j,x,_,k,E,q,T,A,M,P,D,z,B,R,F,N,C,U,I,J,$,L,H,G,Q;for(null==r&&(r={}),G=d(t,E={__next:1}),Q=d(n,q={__next:E.__next},E),L=[],H=0,o=!0,v=0,S=(k=new e(null,G,Q).getOpcodes()).length;vR;l=P<=R?++w:--w){if(a=G[l],y(a,E)){if(!y(a,q))throw new AssertionError("internal bug: isScalarized(item, originals1) != isScalarized(item, originals2) for item "+JSON.stringify(a));p=u(a,E),h=u(a,q),(i=c(p,h,r))?(L.push(["~",i]),o=!1):L.push([" "])}else L.push([" ",a]);H+=10}break;case"delete":for(l=O=F=f,N=s;F<=N?ON;l=F<=N?++O:--O)L.push(["-",u(G[l],E)]),H-=5;break;case"insert":for(g=j=C=b,U=m;C<=U?jU;g=C<=U?++j:--j)L.push(["+",u(Q[g],q)]),H-=5;break;case"replace":if(r.keysOnly)for(l=A=z=f,B=s;z<=B?AB;l=z<=B?++A:--A)(i=c(u(G[l],E),u(Q[l-f+b],q),r))?(L.push(["~",i]),o=!1):L.push([" "]);else{for(l=x=I=f,J=s;I<=J?xJ;l=I<=J?++x:--x)L.push(["-",u(G[l],E)]),H-=5;for(g=T=$=b,D=m;$<=D?TD;g=$<=D?++T:--T)L.push(["+",u(Q[g],q)]),H-=5}}return o||0===k.length?(L=void 0,H=100):H=Math.max(0,H),[H,L]},s=function(t,e,n){var r;if(null==n&&(n={}),(r=a(t))===a(e))switch(r){case"object":return g(t,e,n);case"array":return o(t,e,n)}return n.keysOnly?[100,void 0]:t!==e?[0,{__old:t,__new:e}]:[100,void 0]},c=function(t,e,n){var r;return null==n&&(n={}),(r=s(t,e,n))[0],r[1]},l=function(t,e,n){var r,o;return null==n&&(n={}),o=(r=s(t,e,n))[0],r[1],o},f=function(t,e,n,r){return null==r&&(r={}),i(c(t,e,r),n)},t.exports={diff:c,diffString:f}}).call(this)},function(t,e,n){"use strict";n.r(e);var r=n(2);e.default=r.diff},function(t,e,n){t.exports=n(5)},function(t,e,n){(function(){var t,r,o,i,u,c,l,f,s,a,p,h,y,g,d,b,m,v,w,S,O,j=[].indexOf||function(t){for(var e=0,n=this.length;ec;n=0<=c?++i:--i){if(t[n]e[n])return 1}return r-o},O=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},d=function(t){var e,n;for(e=0,n=t.length;e=200)for(n in c=f(u/100)+1,e)e[n].length>c&&(l[n]=!0,delete e[n]);return this.isbjunk=function(t){return O(i,t)},this.isbpopular=function(t){return O(l,t)}},t.prototype.findLongestMatch=function(t,e,n,r){var o,i,u,c,l,f,s,a,p,h,y,g,d,b,m,v,w,S,j,x,_;for(o=(v=[this.a,this.b,this.b2j,this.isbjunk])[0],i=v[1],u=v[2],a=v[3],c=(w=[t,n,0])[0],l=w[1],f=w[2],h={},s=d=t;t<=e?de;s=t<=e?++d:--d){for(g={},b=0,m=(S=O(u,o[s])?u[o[s]]:[]).length;b=r)break;(y=g[p]=(h[p-1]||0)+1)>f&&(c=(j=[s-y+1,p-y+1,y])[0],l=j[1],f=j[2])}h=g}for(;c>t&&l>n&&!a(i[l-1])&&o[c-1]===i[l-1];)c=(x=[c-1,l-1,f+1])[0],l=x[1],f=x[2];for(;c+ft&&l>n&&a(i[l-1])&&o[c-1]===i[l-1];)c=(_=[c-1,l-1,f+1])[0],l=_[1],f=_[2];for(;c+fl&&(n.push([f,o,p(i,o+t),u,p(c,u+t)]),r.push(n),n=[],o=(b=[a(o,i-t),a(u,c-t)])[0],u=b[1]),n.push([f,o,i,u,c]);return!n.length||1===n.length&&"equal"===n[0][0]||r.push(n),r},t.prototype.ratio=function(){var t,e,n,r;for(t=0,e=0,n=(r=this.getMatchingBlocks()).length;e0&&r++;return m(r,this.a.length+this.b.length)},t.prototype.realQuickRatio=function(){var t,e,n;return n=[this.a.length,this.b.length],m(p(t=n[0],e=n[1]),t+e)},t}(),s=function(t,e,n,o){var i,c,l,f,s,a,p,h,y;if(null==n&&(n=3),null==o&&(o=.6),!(n>0))throw new Error("n must be > 0: ("+n+")");if(!(0<=o&&o<=1))throw new Error("cutoff must be in [0.0, 1.0]: ("+o+")");for(i=[],(c=new u).setSeq2(t),f=0,a=e.length;f=o&&c.quickRatio()>=o&&c.ratio()>=o&&i.push([c.ratio(),l]);for(y=[],s=0,p=(i=r.nlargest(i,n,b)).length;sr;o=n<=r?++i:--i)u.push(t+" "+e[o]);return u},t.prototype._plainReplace=function(t,e,n,r,o,i){var u,l,f,s,a,p,h,y,g,d;for(c(ei;x=o<=i?++A:--A)for(d=r[x],v.setSeq2(d),j=M=e;e<=n?Mn;j=e<=n?++M:--M)(l=t[j])!==d?(v.setSeq1(l),v.realQuickRatio()>h&&v.quickRatio()>h&&v.ratio()>h&&(h=(V=[v.ratio(),j,x])[0],y=V[1],g=V[2])):null===S&&(S=(Q=[j,x])[0],O=Q[1]);if(h=0},S=function(t,e){var n,r;return n=t+1,1===(r=e-t)?""+n:(r||n--,n+","+r)},g=function(t,e,n){var r,o,i,c,l,f,s,a,p,h,y,g,d,b,m,v,w,O,j,x,_,k,E,q,T,A,M,P,D,z,B,R,F,N,C,U,I;for(null==(l=(B=null!=n?n:{}).fromfile)&&(l=""),null==(j=B.tofile)&&(j=""),null==(f=B.fromfiledate)&&(f=""),null==(x=B.tofiledate)&&(x=""),null==B.n&&3,null==(m=B.lineterm)&&(m="\n"),b=[],v=!1,_=0,T=(R=new u(null,t,e).getGroupedOpcodes()).length;_=0&&r.push(n.slice(2));return r},e._arrayCmp=b,e.SequenceMatcher=u,e.getCloseMatches=s,e._countLeading=v,e.Differ=t,e.IS_LINE_JUNK=i,e.IS_CHARACTER_JUNK=o,e._formatRangeUnified=S,e.unifiedDiff=g,e._formatRangeContext=w,e.contextDiff=l,e.ndiff=h,e.restore=y}).call(this)},function(t,e,n){t.exports=n(7)},function(t,e,n){var r,o,i;(function(){var n,u,c,l,f,s,a,p,h,y,g,d,b,m,v;c=Math.floor,y=Math.min,u=function(t,e){return te?1:0},h=function(t,e,n,r,o){var i;if(null==n&&(n=0),null==o&&(o=u),n<0)throw new Error("lo must be non-negative");for(null==r&&(r=t.length);nn;0<=n?e++:e--)f.push(e);return f}.apply(this).reverse()).length;rg;0<=g?++s:--s)d.push(f(t,n));return d},m=function(t,e,n,r){var o,i,c;for(null==r&&(r=u),o=t[n];n>e&&r(o,i=t[c=n-1>>1])<0;)t[n]=i,n=c;return t[n]=o},v=function(t,e,n){var r,o,i,c,l;for(null==n&&(n=u),o=t.length,l=e,i=t[e],r=2*e+1;r - * @license MIT - */ -function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){if(t===e)return 0;for(var n=t.length,r=e.length,o=0,i=Math.min(n,r);o=0;f--)if(s[f]!==a[f])return!1;for(f=s.length-1;f>=0;f--)if(c=s[f],!v(t[c],e[c],n,r))return!1;return!0}(t,e,n,c))}return n?t===e:t==e}function w(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function S(t,e){if(!t||!e)return!1;if("[object RegExp]"==Object.prototype.toString.call(e))return e.test(t);try{if(t instanceof e)return!0}catch(t){}return!Error.isPrototypeOf(e)&&!0===e.call({},t)}function O(t,e,n,r){var o;if("function"!=typeof e)throw new TypeError('"block" argument must be a function');"string"==typeof n&&(r=n,n=null),o=function(t){var e;try{t()}catch(t){e=t}return e}(e),r=(n&&n.name?" ("+n.name+").":".")+(r?" "+r:"."),t&&!o&&b(o,n,"Missing expected exception"+r);var i="string"==typeof r,c=!t&&o&&!n;if((!t&&u.isError(o)&&i&&S(o,n)||c)&&b(o,n,"Got unwanted exception"+r),t&&o&&n&&!S(o,n)||!t&&o)throw o}p.AssertionError=function(t){var e;this.name="AssertionError",this.actual=t.actual,this.expected=t.expected,this.operator=t.operator,t.message?(this.message=t.message,this.generatedMessage=!1):(this.message=g(d((e=this).actual),128)+" "+e.operator+" "+g(d(e.expected),128),this.generatedMessage=!0);var n=t.stackStartFunction||b;if(Error.captureStackTrace)Error.captureStackTrace(this,n);else{var r=new Error;if(r.stack){var o=r.stack,i=y(n),u=o.indexOf("\n"+i);if(u>=0){var c=o.indexOf("\n",u+1);o=o.substring(c+1)}this.stack=o}}},u.inherits(p.AssertionError,Error),p.fail=b,p.ok=m,p.equal=function(t,e,n){t!=e&&b(t,e,n,"==",p.equal)},p.notEqual=function(t,e,n){t==e&&b(t,e,n,"!=",p.notEqual)},p.deepEqual=function(t,e,n){v(t,e,!1)||b(t,e,n,"deepEqual",p.deepEqual)},p.deepStrictEqual=function(t,e,n){v(t,e,!0)||b(t,e,n,"deepStrictEqual",p.deepStrictEqual)},p.notDeepEqual=function(t,e,n){v(t,e,!1)&&b(t,e,n,"notDeepEqual",p.notDeepEqual)},p.notDeepStrictEqual=function t(e,n,r){v(e,n,!0)&&b(e,n,r,"notDeepStrictEqual",t)},p.strictEqual=function(t,e,n){t!==e&&b(t,e,n,"===",p.strictEqual)},p.notStrictEqual=function(t,e,n){t===e&&b(t,e,n,"!==",p.notStrictEqual)},p.throws=function(t,e,n){O(!0,t,e,n)},p.doesNotThrow=function(t,e,n){O(!1,t,e,n)},p.ifError=function(t){if(t)throw t};var j=Object.keys||function(t){var e=[];for(var n in t)c.call(t,n)&&e.push(n);return e}}).call(this,n(9))},function(t,e){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"===("undefined"==typeof window?"undefined":n(window))&&(r=window)}t.exports=r},function(t,e,n){(function(t){function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o=Object.getOwnPropertyDescriptors||function(t){for(var e=Object.keys(t),n={},r=0;r=o)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return t}})),c=r[n];n=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),g(n)?r.showHidden=n:n&&e._extend(r,n),v(r.showHidden)&&(r.showHidden=!1),v(r.depth)&&(r.depth=2),v(r.colors)&&(r.colors=!1),v(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=f),a(r,t,r.depth)}function f(t,e){var n=l.styles[e];return n?"["+l.colors[n][0]+"m"+t+"["+l.colors[n][1]+"m":t}function s(t,e){return t}function a(t,n,r){if(t.customInspect&&n&&x(n.inspect)&&n.inspect!==e.inspect&&(!n.constructor||n.constructor.prototype!==n)){var o=n.inspect(r,t);return m(o)||(o=a(t,o,r)),o}var i=function(t,e){if(v(e))return t.stylize("undefined","undefined");if(m(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}if(b(e))return t.stylize(""+e,"number");if(g(e))return t.stylize(""+e,"boolean");if(d(e))return t.stylize("null","null")}(t,n);if(i)return i;var u=Object.keys(n),c=function(t){var e={};return t.forEach((function(t,n){e[t]=!0})),e}(u);if(t.showHidden&&(u=Object.getOwnPropertyNames(n)),j(n)&&(u.indexOf("message")>=0||u.indexOf("description")>=0))return p(n);if(0===u.length){if(x(n)){var l=n.name?": "+n.name:"";return t.stylize("[Function"+l+"]","special")}if(w(n))return t.stylize(RegExp.prototype.toString.call(n),"regexp");if(O(n))return t.stylize(Date.prototype.toString.call(n),"date");if(j(n))return p(n)}var f,s="",S=!1,_=["{","}"];(y(n)&&(S=!0,_=["[","]"]),x(n))&&(s=" [Function"+(n.name?": "+n.name:"")+"]");return w(n)&&(s=" "+RegExp.prototype.toString.call(n)),O(n)&&(s=" "+Date.prototype.toUTCString.call(n)),j(n)&&(s=" "+p(n)),0!==u.length||S&&0!=n.length?r<0?w(n)?t.stylize(RegExp.prototype.toString.call(n),"regexp"):t.stylize("[Object]","special"):(t.seen.push(n),f=S?function(t,e,n,r,o){for(var i=[],u=0,c=e.length;u=0&&0,t+e.replace(/\u001b\[\d\d?m/g,"").length+1}),0)>60)return n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1];return n[0]+e+" "+t.join(", ")+" "+n[1]}(f,s,_)):_[0]+s+_[1]}function p(t){return"["+Error.prototype.toString.call(t)+"]"}function h(t,e,n,r,o,i){var u,c,l;if((l=Object.getOwnPropertyDescriptor(e,o)||{value:e[o]}).get?c=l.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):l.set&&(c=t.stylize("[Setter]","special")),T(r,o)||(u="["+o+"]"),c||(t.seen.indexOf(l.value)<0?(c=d(n)?a(t,l.value,null):a(t,l.value,n-1)).indexOf("\n")>-1&&(c=i?c.split("\n").map((function(t){return" "+t})).join("\n").substr(2):"\n"+c.split("\n").map((function(t){return" "+t})).join("\n")):c=t.stylize("[Circular]","special")),v(u)){if(i&&o.match(/^\d+$/))return c;(u=JSON.stringify(""+o)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(u=u.substr(1,u.length-2),u=t.stylize(u,"name")):(u=u.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),u=t.stylize(u,"string"))}return u+": "+c}function y(t){return Array.isArray(t)}function g(t){return"boolean"==typeof t}function d(t){return null===t}function b(t){return"number"==typeof t}function m(t){return"string"==typeof t}function v(t){return void 0===t}function w(t){return S(t)&&"[object RegExp]"===_(t)}function S(t){return"object"===r(t)&&null!==t}function O(t){return S(t)&&"[object Date]"===_(t)}function j(t){return S(t)&&("[object Error]"===_(t)||t instanceof Error)}function x(t){return"function"==typeof t}function _(t){return Object.prototype.toString.call(t)}function k(t){return t<10?"0"+t.toString(10):t.toString(10)}e.debuglog=function(n){if(v(u)&&(u=t.env.NODE_DEBUG||""),n=n.toUpperCase(),!c[n])if(new RegExp("\\b"+n+"\\b","i").test(u)){var r=t.pid;c[n]=function(){var t=e.format.apply(e,arguments);console.error("%s %d: %s",n,r,t)}}else c[n]=function(){};return c[n]},e.inspect=l,l.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},l.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},e.isArray=y,e.isBoolean=g,e.isNull=d,e.isNullOrUndefined=function(t){return null==t},e.isNumber=b,e.isString=m,e.isSymbol=function(t){return"symbol"===r(t)},e.isUndefined=v,e.isRegExp=w,e.isObject=S,e.isDate=O,e.isError=j,e.isFunction=x,e.isPrimitive=function(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"===r(t)||void 0===t},e.isBuffer=n(12);var E=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function q(){var t=new Date,e=[k(t.getHours()),k(t.getMinutes()),k(t.getSeconds())].join(":");return[t.getDate(),E[t.getMonth()],e].join(" ")}function T(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.log=function(){console.log("%s - %s",q(),e.format.apply(e,arguments))},e.inherits=n(13),e._extend=function(t,e){if(!e||!S(e))return t;for(var n=Object.keys(e),r=n.length;r--;)t[n[r]]=e[n[r]];return t};var A="undefined"!=typeof Symbol?Symbol("util.promisify.custom"):void 0;function M(t,e){if(!t){var n=new Error("Promise was rejected with a falsy value");n.reason=t,t=n}return e(t)}e.promisify=function(t){if("function"!=typeof t)throw new TypeError('The "original" argument must be of type Function');if(A&&t[A]){var e;if("function"!=typeof(e=t[A]))throw new TypeError('The "util.promisify.custom" argument must be of type Function');return Object.defineProperty(e,A,{value:e,enumerable:!1,writable:!1,configurable:!0}),e}function e(){for(var e,n,r=new Promise((function(t,r){e=t,n=r})),o=[],i=0;i1)for(var n=1;n=30&&n[0]<38||t._bgBright&&n[0]>=40&&n[0]<48)&&(n=[n[0]+60,n[1]]),r(n,e)}),e)}),i);return t.style=[],t[this]},t.exports=c((function(t){return t}),l(i,(function(t,e){return{get:u.bind(e),enumerable:!0}})))},function(t,e,n){"use strict";var r=n(17);t.exports=function(t,e){var n={};return r(t,(function(r,o){n[o]=e.call(this,r,o,t)}),arguments[2]),n}},function(t,e,n){"use strict";t.exports=n(18)("forEach")},function(t,e,n){"use strict";var r=Function.prototype.call,o=Object.keys,i=n(1),u=n(19),c=n(20);t.exports=function(t){return function(e,n){var l,f=arguments[2],s=arguments[3];return c(e),u(n),l=o(e),s&&l.sort(i(s)?s:void 0),l[t]((function(t,o){return r.call(n,f,e[t],t,e,o)}))}}},function(t,e,n){"use strict";var r=n(1);t.exports=function(t){if(!r(t))throw new TypeError(t+" is not a function");return t}},function(t,e,n){"use strict";t.exports=function(t){if(null==t)throw new TypeError("Cannot use null or undefined");return t}}])})); \ No newline at end of file diff --git a/rollup.config.mjs b/rollup.config.mjs index 85f913372..8a623a338 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -286,20 +286,6 @@ const WORKER_TARGETS = fs.readdirSync('src/workers').map((file) => { }); const MODULE_TARGETS = [ - { - input: 'modules/pcui-diff.ts', - output: { - file: 'dist/js/pcui-diff.js', - format: 'esm' - }, - plugins: [ - swc({ - swc: { - minify: production - } - }) - ] - }, { input: 'modules/texture-convert/src/index.ts', output: { diff --git a/src/common/diff.ts b/src/common/diff.ts new file mode 100644 index 000000000..c4f666100 --- /dev/null +++ b/src/common/diff.ts @@ -0,0 +1,190 @@ +/** + * Deep diff for JSON-compatible values. + * + * Reimplementation of the `json-diff` npm package (https://github.com/andreyvit/json-diff). + * The original file was a minified webpack UMD bundle of that library; this is a clean + * TypeScript replacement covering only the functionality actually used by the editor. + * + * Diff format: + * - Objects: `{ key__added: val, key__deleted: val, key: nestedDiff }` + * - Scalars: `{ __old: val, __new: val }` + * - Arrays: `[op, value?][]` where op is `" "`, `"+"`, `"-"` + * - No difference: `undefined` + */ + +type JsonValue = any; + +interface DiffOptions { + /** When true, only report structural changes (added/deleted keys), ignore value changes. */ + keysOnly?: boolean; +} + +/** + * Extended typeof that distinguishes arrays and null from plain objects. + * + * @param value - The value to inspect. + */ +function extendedTypeOf(value: JsonValue): string { + if (value == null) { + return 'null'; + } + if (typeof value === 'object' && Array.isArray(value)) { + return 'array'; + } + return typeof value; +} + +/** + * Recursively diff two values. Returns `[score, diff]`. + * + * The score is used internally for ranking (e.g. during array element matching in the + * original json-diff); only the diff portion is exposed to consumers. + * + * @param oldVal - The original value. + * @param newVal - The new value. + * @param options - Diff options. + */ +function diffValue(oldVal: JsonValue, newVal: JsonValue, options: DiffOptions): [number, JsonValue] { + const oldType = extendedTypeOf(oldVal); + const newType = extendedTypeOf(newVal); + + if (oldType === newType) { + switch (oldType) { + case 'object': + return objectDiff(oldVal, newVal, options); + case 'array': + return arrayDiff(oldVal, newVal, options); + } + } + + // Scalar comparison or type mismatch + if (options.keysOnly) { + return [100, undefined]; + } + if (oldVal !== newVal) { + return [0, { __old: oldVal, __new: newVal }]; + } + return [100, undefined]; +} + +/** + * Diff two plain objects. Produces `key__added`, `key__deleted` entries for + * structural changes and recursively diffs shared keys. + * + * @param oldObj - The original object. + * @param newObj - The new object. + * @param options - Diff options. + */ +function objectDiff( + oldObj: Record, + newObj: Record, + options: DiffOptions +): [number, JsonValue] { + const result: Record = {}; + let score = 0; + + // Detect deleted keys (present in old, absent in new) + for (const key of Object.keys(oldObj)) { + if (!(key in newObj)) { + result[`${key}__deleted`] = oldObj[key]; + score -= 30; + } + } + + // Detect added keys (present in new, absent in old) + for (const key of Object.keys(newObj)) { + if (!(key in oldObj)) { + result[`${key}__added`] = newObj[key]; + score -= 30; + } + } + + // Recursively diff shared keys + for (const key of Object.keys(oldObj)) { + if (key in newObj) { + score += 20; + const [childScore, childDiff] = diffValue(oldObj[key], newObj[key], options); + if (childDiff) { + result[key] = childDiff; + } + score += Math.min(20, Math.max(-10, childScore / 5)); + } + } + + if (Object.keys(result).length === 0) { + // No changes detected + return [100 * Math.max(Object.keys(oldObj).length, 0.5), undefined]; + } + + return [Math.max(0, score), result]; +} + +/** + * Diff two arrays using index-based comparison. + * + * Note: the original json-diff used Python's SequenceMatcher (via the `difflib` port) for + * optimal element alignment. This simplified version compares by index position, which is + * sufficient for the editor's use case (object-keyed data, not reorderable arrays). + * + * Output format: array of `[op]` or `[op, value]` tuples where op is `" "`, `"+"`, or `"-"`. + * + * @param oldArr - The original array. + * @param newArr - The new array. + * @param options - Diff options. + */ +function arrayDiff(oldArr: JsonValue[], newArr: JsonValue[], options: DiffOptions): [number, JsonValue] { + const result: [string, JsonValue?][] = []; + let score = 0; + let allEqual = true; + + const minLen = Math.min(oldArr.length, newArr.length); + + for (let i = 0; i < minLen; i++) { + const [, childDiff] = diffValue(oldArr[i], newArr[i], options); + if (childDiff) { + if (options.keysOnly) { + result.push(['~', childDiff]); + } else { + result.push(['-', oldArr[i]]); + result.push(['+', newArr[i]]); + score -= 10; + } + allEqual = false; + } else { + result.push([' ']); + score += 10; + } + } + + // Extra elements in old array (deleted) + for (let i = minLen; i < oldArr.length; i++) { + result.push(['-', oldArr[i]]); + score -= 5; + allEqual = false; + } + + // Extra elements in new array (added) + for (let i = minLen; i < newArr.length; i++) { + result.push(['+', newArr[i]]); + score -= 5; + allEqual = false; + } + + if (allEqual) { + return [100, undefined]; + } + + return [Math.max(0, score), result]; +} + +/** + * Compute a deep diff between two JSON-compatible values. + * + * @param oldVal - The original value. + * @param newVal - The new value. + * @param options - Optional. Pass `{ keysOnly: true }` to ignore scalar value changes. + * @returns A diff object describing the changes, or `undefined` if the values are equal. + */ +export function diff(oldVal: JsonValue, newVal: JsonValue, options: DiffOptions = {}): JsonValue { + return diffValue(oldVal, newVal, options)[1]; +} diff --git a/src/editor/inspector/assets/animstategraph-view.ts b/src/editor/inspector/assets/animstategraph-view.ts index d245e1bff..4eabeed0a 100644 --- a/src/editor/inspector/assets/animstategraph-view.ts +++ b/src/editor/inspector/assets/animstategraph-view.ts @@ -1,6 +1,8 @@ import { default as PCUIGraph } from '@playcanvas/pcui-graph'; import { ANIM_INTERRUPTION_NONE } from 'playcanvas'; +import { diff } from '@/common/diff'; + import { AnimstategraphState } from './animstategraph-state'; const GRAPH_ACTIONS = { @@ -453,8 +455,7 @@ class AnimstategraphView { _handleIncomingUpdates(path, newValue, oldValue) { if (!this._suppressGraphDataEvents) { if (path === 'data') { - // FIXME: window.diff comes from pcui/diff.js - const updates = window.diff.default(oldValue, newValue); + const updates = diff(oldValue, newValue); if (updates.states) { Object.keys(updates.states).forEach((stateKey) => { if (stateKey.includes('__added')) { diff --git a/tsconfig.json b/tsconfig.json index c8e2b043b..387b92b9e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,7 +25,6 @@ ], "exclude": [ "src/wasm", - "modules/pcui-diff.ts", "modules/editor-api" ] } \ No newline at end of file diff --git a/types.d.ts b/types.d.ts index c0a9beda8..68bf50778 100644 --- a/types.d.ts +++ b/types.d.ts @@ -42,11 +42,6 @@ declare interface Array { } declare interface Window { - // diff (injected into HTML) - diff: { - default: (t: any, e: any, n: any) => any; - }; - // global variables config: typeof config; editor: typeof editor;