@nuxt/devtools
Version:
<a href="https://devtools.nuxt.com"><img width="1200" alt="Nuxt DevTools" src="https://github-production-user-asset-6210df.s3.amazonaws.com/904724/261577617-a10567bd-ad33-48cc-9bda-9e37dbe1929f.png"></a> <br>
9 lines (8 loc) • 8.97 kB
JavaScript
import{_ as P}from"./CdlRa3-_.js";import{d as Q,a as U,r as X,aq as Y,cp as j,o as W,h as S,f as b}from"./Bysyzw-g.js";function g(){}g.prototype={diff:function(e,r){var t,u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},o=u.callback;typeof u=="function"&&(o=u,u={});var i=this;function f(v){return v=i.postProcess(v,u),o?(setTimeout(function(){o(v)},0),!0):v}e=this.castInput(e,u),r=this.castInput(r,u),e=this.removeEmpty(this.tokenize(e,u)),r=this.removeEmpty(this.tokenize(r,u));var l=r.length,s=e.length,a=1,c=l+s;u.maxEditLength!=null&&(c=Math.min(c,u.maxEditLength));var p=(t=u.timeout)!==null&&t!==void 0?t:1/0,d=Date.now()+p,m=[{oldPos:-1,lastComponent:void 0}],h=this.extractCommon(m[0],r,e,0,u);if(m[0].oldPos+1>=s&&h+1>=l)return f(F(i,m[0].lastComponent,r,e,i.useLongestToken));var y=-1/0,T=1/0;function z(){for(var v=Math.max(y,-a);v<=Math.min(T,a);v+=2){var C=void 0,w=m[v-1],E=m[v+1];w&&(m[v-1]=void 0);var q=!1;if(E){var M=E.oldPos-v;q=E&&0<=M&&M<l}var B=w&&w.oldPos+1<s;if(!q&&!B){m[v]=void 0;continue}if(!B||q&&w.oldPos<E.oldPos?C=i.addToPath(E,!0,!1,0,u):C=i.addToPath(w,!1,!0,1,u),h=i.extractCommon(C,r,e,v,u),C.oldPos+1>=s&&h+1>=l)return f(F(i,C.lastComponent,r,e,i.useLongestToken));m[v]=C,C.oldPos+1>=s&&(T=Math.min(T,v-1)),h+1>=l&&(y=Math.max(y,v+1))}a++}if(o)(function v(){setTimeout(function(){if(a>c||Date.now()>d)return o();z()||v()},0)})();else for(;a<=c&&Date.now()<=d;){var x=z();if(x)return x}},addToPath:function(e,r,t,u,o){var i=e.lastComponent;return i&&!o.oneChangePerToken&&i.added===r&&i.removed===t?{oldPos:e.oldPos+u,lastComponent:{count:i.count+1,added:r,removed:t,previousComponent:i.previousComponent}}:{oldPos:e.oldPos+u,lastComponent:{count:1,added:r,removed:t,previousComponent:i}}},extractCommon:function(e,r,t,u,o){for(var i=r.length,f=t.length,l=e.oldPos,s=l-u,a=0;s+1<i&&l+1<f&&this.equals(t[l+1],r[s+1],o);)s++,l++,a++,o.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return a&&!o.oneChangePerToken&&(e.lastComponent={count:a,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=l,s},equals:function(e,r,t){return t.comparator?t.comparator(e,r):e===r||t.ignoreCase&&e.toLowerCase()===r.toLowerCase()},removeEmpty:function(e){for(var r=[],t=0;t<e.length;t++)e[t]&&r.push(e[t]);return r},castInput:function(e){return e},tokenize:function(e){return Array.from(e)},join:function(e){return e.join("")},postProcess:function(e){return e}};function F(n,e,r,t,u){for(var o=[],i;e;)o.push(e),i=e.previousComponent,delete e.previousComponent,e=i;o.reverse();for(var f=0,l=o.length,s=0,a=0;f<l;f++){var c=o[f];if(c.removed)c.value=n.join(t.slice(a,a+c.count)),a+=c.count;else{if(!c.added&&u){var p=r.slice(s,s+c.count);p=p.map(function(d,m){var h=t[a+m];return h.length>d.length?h:d}),c.value=n.join(p)}else c.value=n.join(r.slice(s,s+c.count));s+=c.count,c.added||(a+=c.count)}}return o}function V(n,e){var r;for(r=0;r<n.length&&r<e.length;r++)if(n[r]!=e[r])return n.slice(0,r);return n.slice(0,r)}function Z(n,e){var r;if(!n||!e||n[n.length-1]!=e[e.length-1])return"";for(r=0;r<n.length&&r<e.length;r++)if(n[n.length-(r+1)]!=e[e.length-(r+1)])return n.slice(-r);return n.slice(-r)}function _(n,e,r){if(n.slice(0,e.length)!=e)throw Error("string ".concat(JSON.stringify(n)," doesn't start with prefix ").concat(JSON.stringify(e),"; this is a bug"));return r+n.slice(e.length)}function N(n,e,r){if(!e)return n+r;if(n.slice(-e.length)!=e)throw Error("string ".concat(JSON.stringify(n)," doesn't end with suffix ").concat(JSON.stringify(e),"; this is a bug"));return n.slice(0,-e.length)+r}function L(n,e){return _(n,e,"")}function I(n,e){return N(n,e,"")}function G(n,e){return e.slice(0,K(n,e))}function K(n,e){var r=0;n.length>e.length&&(r=n.length-e.length);var t=e.length;n.length<e.length&&(t=n.length);var u=Array(t),o=0;u[0]=0;for(var i=1;i<t;i++){for(e[i]==e[o]?u[i]=u[o]:u[i]=o;o>0&&e[i]!=e[o];)o=u[o];e[i]==e[o]&&o++}o=0;for(var f=r;f<n.length;f++){for(;o>0&&n[f]!=e[o];)o=u[o];n[f]==e[o]&&o++}return o}var O="a-zA-Z0-9_\\u{C0}-\\u{FF}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}",ee=new RegExp("[".concat(O,"]+|\\s+|[^").concat(O,"]"),"ug"),$=new g;$.equals=function(n,e,r){return r.ignoreCase&&(n=n.toLowerCase(),e=e.toLowerCase()),n.trim()===e.trim()};$.tokenize=function(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r;if(e.intlSegmenter){if(e.intlSegmenter.resolvedOptions().granularity!="word")throw new Error('The segmenter passed must have a granularity of "word"');r=Array.from(e.intlSegmenter.segment(n),function(o){return o.segment})}else r=n.match(ee)||[];var t=[],u=null;return r.forEach(function(o){/\s/.test(o)?u==null?t.push(o):t.push(t.pop()+o):/\s/.test(u)?t[t.length-1]==u?t.push(t.pop()+o):t.push(u+o):t.push(o),u=o}),t};$.join=function(n){return n.map(function(e,r){return r==0?e:e.replace(/^\s+/,"")}).join("")};$.postProcess=function(n,e){if(!n||e.oneChangePerToken)return n;var r=null,t=null,u=null;return n.forEach(function(o){o.added?t=o:o.removed?u=o:((t||u)&&H(r,u,t,o),r=o,t=null,u=null)}),(t||u)&&H(r,u,t,null),n};function H(n,e,r,t){if(e&&r){var u=e.value.match(/^\s*/)[0],o=e.value.match(/\s*$/)[0],i=r.value.match(/^\s*/)[0],f=r.value.match(/\s*$/)[0];if(n){var l=V(u,i);n.value=N(n.value,i,l),e.value=L(e.value,l),r.value=L(r.value,l)}if(t){var s=Z(o,f);t.value=_(t.value,f,s),e.value=I(e.value,s),r.value=I(r.value,s)}}else if(r)n&&(r.value=r.value.replace(/^\s*/,"")),t&&(t.value=t.value.replace(/^\s*/,""));else if(n&&t){var a=t.value.match(/^\s*/)[0],c=e.value.match(/^\s*/)[0],p=e.value.match(/\s*$/)[0],d=V(a,c);e.value=L(e.value,d);var m=Z(L(a,d),p);e.value=I(e.value,m),t.value=_(t.value,a,m),n.value=N(n.value,a,a.slice(0,a.length-m.length))}else if(t){var h=t.value.match(/^\s*/)[0],y=e.value.match(/\s*$/)[0],T=G(y,h);e.value=I(e.value,T)}else if(n){var z=n.value.match(/\s*$/)[0],x=e.value.match(/^\s*/)[0],v=G(z,x);e.value=L(e.value,v)}}var ne=new g;ne.tokenize=function(n){var e=new RegExp("(\\r?\\n)|[".concat(O,"]+|[^\\S\\n\\r]+|[^").concat(O,"]"),"ug");return n.match(e)||[]};var k=new g;k.tokenize=function(n,e){e.stripTrailingCr&&(n=n.replace(/\r\n/g,`
`));var r=[],t=n.split(/(\n|\r\n)/);t[t.length-1]||t.pop();for(var u=0;u<t.length;u++){var o=t[u];u%2&&!e.newlineIsToken?r[r.length-1]+=o:r.push(o)}return r};k.equals=function(n,e,r){return r.ignoreWhitespace?((!r.newlineIsToken||!n.includes(`
`))&&(n=n.trim()),(!r.newlineIsToken||!e.includes(`
`))&&(e=e.trim())):r.ignoreNewlineAtEof&&!r.newlineIsToken&&(n.endsWith(`
`)&&(n=n.slice(0,-1)),e.endsWith(`
`)&&(e=e.slice(0,-1))),g.prototype.equals.call(this,n,e,r)};function re(n,e,r){return k.diff(n,e,r)}var oe=new g;oe.tokenize=function(n){return n.split(/(\S.+?[.!?])(?=\s+|$)/)};var te=new g;te.tokenize=function(n){return n.split(/([{}:;,]|\s+)/)};function R(n){"@babel/helpers - typeof";return R=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},R(n)}var D=new g;D.useLongestToken=!0;D.tokenize=k.tokenize;D.castInput=function(n,e){var r=e.undefinedReplacement,t=e.stringifyReplacer,u=t===void 0?function(o,i){return typeof i>"u"?r:i}:t;return typeof n=="string"?n:JSON.stringify(A(n,null,null,u),u," ")};D.equals=function(n,e,r){return g.prototype.equals.call(D,n.replace(/,([\r\n])/g,"$1"),e.replace(/,([\r\n])/g,"$1"),r)};function A(n,e,r,t,u){e=e||[],r=r||[],t&&(n=t(u,n));var o;for(o=0;o<e.length;o+=1)if(e[o]===n)return r[o];var i;if(Object.prototype.toString.call(n)==="[object Array]"){for(e.push(n),i=new Array(n.length),r.push(i),o=0;o<n.length;o+=1)i[o]=A(n[o],e,r,t,u);return e.pop(),r.pop(),i}if(n&&n.toJSON&&(n=n.toJSON()),R(n)==="object"&&n!==null){e.push(n),i={},r.push(i);var f=[],l;for(l in n)Object.prototype.hasOwnProperty.call(n,l)&&f.push(l);for(f.sort(),o=0;o<f.length;o+=1)l=f[o],i[l]=A(n[l],e,r,t,l);e.pop(),r.pop()}else i=n;return i}var J=new g;J.tokenize=function(n){return n.slice()};J.join=J.removeEmpty=function(n){return n};const le=Q({__name:"CodeDiff",props:{from:{},to:{},lang:{}},setup(n){const e=n;function r(f,l){const s=re(f.trim(),l.trim()),a=[],c=[],p=[];for(const d of s){const m=d.value.trimEnd().split(`
`);for(const h of m)d.added?(a.push(p.length),p.push(h)):(d.removed&&c.push(p.length),p.push(h))}return{added:a,removed:c,result:p.join(`
`)}}const t=U(()=>r(e.from,e.to));function u(f){let l=0;return f.replace(/class="shiki/,'class="shiki diff').replace(/class="line"/g,s=>(l++,t.value.added.includes(l-1)?'class="line line-added"':t.value.removed.includes(l-1)?'class="line line-removed"':s))}const o=X();Y(i);function i(){const f=j(o);f&&f.querySelector(".line-added,.line-removed")?.scrollIntoView()}return(f,l)=>{const s=P;return W(),S(s,{ref_key:"elRef",ref:o,code:b(t).result,lang:f.lang,"transform-rendered":u,onLoaded:i},null,8,["code","lang"])}}});export{le as _};