UNPKG

@haxtheweb/haxcms-nodejs

Version:

HAXcms single and multisite nodejs server, api, and administration

10 lines 2.2 kB
/** @license Copyright (c) 2017 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt */ import"./boot.js";function newSplice(e,t,n){return{index:e,removed:t,addedCount:n}}function calcSplices(e,t,n,r,l,u){let i,c=0,o=0,s=Math.min(n-t,u-l);if(0==t&&0==l&&(c=function sharedPrefix(e,t,n){for(let r=0;r<n;r++)if(!equals(e[r],t[r]))return r;return n}(e,r,s)),n==e.length&&u==r.length&&(o=function sharedSuffix(e,t,n){let r=e.length,l=t.length,u=0;for(;u<n&&equals(e[--r],t[--l]);)u++;return u}(e,r,s-c)),l+=c,u-=o,(n-=o)-(t+=c)==0&&u-l==0)return[];if(t==n){for(i=newSplice(t,[],0);l<u;)i.removed.push(r[l++]);return[i]}if(l==u)return[newSplice(t,[],n-t)];let a=function spliceOperationsFromEditDistances(e){let t=e.length-1,n=e[0].length-1,r=e[t][n],l=[];for(;t>0||n>0;){if(0==t){l.push(2),n--;continue}if(0==n){l.push(3),t--;continue}let u,i=e[t-1][n-1],c=e[t-1][n],o=e[t][n-1];u=c<o?c<i?c:i:o<i?o:i,u==i?(i==r?l.push(0):(l.push(1),r=i),t--,n--):u==c?(l.push(3),t--,r=c):(l.push(2),n--,r=o)}return l.reverse(),l}(function calcEditDistances(e,t,n,r,l,u){let i=u-l+1,c=n-t+1,o=new Array(i);for(let e=0;e<i;e++)o[e]=new Array(c),o[e][0]=e;for(let e=0;e<c;e++)o[0][e]=e;for(let n=1;n<i;n++)for(let u=1;u<c;u++)if(equals(e[t+u-1],r[l+n-1]))o[n][u]=o[n-1][u-1];else{let e=o[n-1][u]+1,t=o[n][u-1]+1;o[n][u]=e<t?e:t}return o}(e,t,n,r,l,u));i=void 0;let f=[],h=t,p=l;for(let e=0;e<a.length;e++)switch(a[e]){case 0:i&&(f.push(i),i=void 0),h++,p++;break;case 1:i||(i=newSplice(h,[],0)),i.addedCount++,h++,i.removed.push(r[p]),p++;break;case 2:i||(i=newSplice(h,[],0)),i.addedCount++,h++;break;case 3:i||(i=newSplice(h,[],0)),i.removed.push(r[p]),p++}return i&&f.push(i),f}export function calculateSplices(e,t){return calcSplices(e,0,e.length,t,0,t.length)}function equals(e,t){return e===t}