🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

@kizahasi/ot-string

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kizahasi/ot-string - npm Package Compare versions

Comparing version

to
0.2.1

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("diff-match-patch"),t=require("@kizahasi/result");function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return o(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,c,l,s,d=(function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",o=r.asyncIterator||"@@asyncIterator",a=r.toStringTag||"@@toStringTag";function u(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=Object.create((t&&t.prototype instanceof d?t:d).prototype),o=new L(r||[]);return i._invoke=function(e,t,n){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return{value:void 0,done:!0}}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var u=m(a,n);if(u){if(u===s)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=l(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===s)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(e,n,o),i}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var s={};function d(){}function f(){}function v(){}var h={};h[i]=function(){return this};var p=Object.getPrototypeOf,y=p&&p(p(k([])));y&&y!==t&&n.call(y,i)&&(h=y);var g=v.prototype=d.prototype=Object.create(h);function w(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function b(e,t){var r;this._invoke=function(i,o){function a(){return new t((function(r,a){!function r(i,o,a,u){var c=l(e[i],e,o);if("throw"!==c.type){var s=c.arg,d=s.value;return d&&"object"==typeof d&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,a,u)}),(function(e){r("throw",e,a,u)})):t.resolve(d).then((function(e){s.value=e,a(s)}),(function(e){return r("throw",e,a,u)}))}u(c.arg)}(i,o,r,a)}))}return r=r?r.then(a,a):a()}}function m(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,m(e,t),"throw"===t.method))return s;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var r=l(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,s;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,s):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,s)}function x(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function E(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function L(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(x,this),this.reset(!0)}function k(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,o=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:R}}function R(){return{value:void 0,done:!0}}return f.prototype=g.constructor=v,v.constructor=f,f.displayName=u(v,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===f||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,u(e,a,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},w(b.prototype),b.prototype[o]=function(){return this},e.AsyncIterator=b,e.async=function(t,n,r,i,o){void 0===o&&(o=Promise);var a=new b(c(t,n,r,i),o);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},w(g),u(g,a,"Generator"),g[i]=function(){return this},g.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=k,L.prototype={constructor:L,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,s):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),s},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),E(n),s}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;E(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),s}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(s={exports:{}}),s.exports),f=function(e){return{hasValue:!0,value:e}},v=function(){function e(e){if(this.source=e,!Number.isInteger(e))throw new Error("not integer");if(e<1)throw new Error("less than 1")}return e.add=function(t,n){return new e(t.value+n.value)},e.tryCreate=function(t){if(Number.isInteger(t)&&!(t<1))return new e(t)},r(e,[{key:"value",get:function(){return this.source}},{key:"successor",get:function(){return new e(this.source+1)}}],[{key:"one",get:function(){return new e(1)}}]),e}(),h=function(){function e(e){if(this.source=e,""===e)throw new Error("empty string")}return e.prototype.concat=function(t){return new e(this.value+t.value)},e.tryCreate=function(t){if(""!==t)return new e(t)},r(e,[{key:"value",get:function(){return this.source}},{key:"length",get:function(){return new v(this.source.length)}}]),e}(),p="insert",y="delete",g="i",w="d",b="r",m=function(e){var t=e.source,n=e.mapInsert,r=e.mapDelete;switch(t.type){case p:return{type:p,insert:n(t.insert)};case y:return{type:y,delete:r(t.delete)};case"replace":return{type:"replace",insert:n(t.insert),delete:r(t.delete)}}},x=function(e,t,n){switch(e.type){case p:return{type:p,insert:n(e.insert,t)};case y:return{type:"replace",insert:t,delete:e.delete};case"replace":return{type:"replace",insert:n(e.insert,t),delete:e.delete}}},E=function(e,t,n){switch(e.type){case p:return{type:"replace",insert:e.insert,delete:t};case y:return{type:y,delete:n(e.delete,t)};case"replace":return{type:"replace",insert:e.insert,delete:n(e.delete,t)}}},L=function(e){switch(e.type){case p:return{type:y,delete:e.insert};case y:return{type:p,insert:e.delete};case"replace":return{type:"replace",insert:e.delete,delete:e.insert}}},k="retain",R=function(e,t){return e.reduce((function(e,n){switch(n.type){case k:return e+n.retain.value;default:return e+function(e,t){return void 0===e.delete?0:t.getDeleteLength(e.delete).value}(n,t)}}),0)},I=function(e){var t=e.source,n=e.mapInsert,r=e.mapDelete;return{headEdit:void 0===t.headEdit?t.headEdit:m({source:t.headEdit,mapInsert:n,mapDelete:r}),body:t.body.map((function(e){return function(e){var t=e.source;return i({},t,{secondEdit:m({source:t.secondEdit,mapInsert:e.mapInsert,mapDelete:e.mapDelete})})}({source:e,mapInsert:n,mapDelete:r})})),tailRetain:t.tailRetain}},D=function(){function e(e,t){var n,r;this.factory=e,this.headEdit=null,this.body=[],this.tailRetain=0,null!=t&&(this.headEdit=null!=(n=t.headEdit)?n:null,this.body=[].concat(t.body),this.tailRetain=null!=(r=t.tailRetain)?r:0)}var t=e.prototype;return t.retain=function(e){this.tailRetain=0!==this.tailRetain?v.add(this.tailRetain,e):e},t.insert=function(e){if(0!==this.tailRetain)return this.body.push({firstRetain:this.tailRetain,secondEdit:{type:p,insert:e}}),void(this.tailRetain=0);if(0===this.body.length)this.headEdit=null!=this.headEdit?x(this.headEdit,e,this.factory.concatInsert):{type:p,insert:e,delete:void 0};else{var t=this.body[this.body.length-1];this.body[this.body.length-1]=i({},t,{secondEdit:x(t.secondEdit,e,this.factory.concatInsert)})}},t.delete=function(e){if(0!==this.tailRetain)return this.body.push({firstRetain:this.tailRetain,secondEdit:{type:y,delete:e}}),void(this.tailRetain=0);if(0===this.body.length)this.headEdit=null!=this.headEdit?E(this.headEdit,e,this.factory.concatDelete):{type:y,insert:void 0,delete:e};else{var t=this.body[this.body.length-1];this.body[this.body.length-1]=i({},t,{secondEdit:E(t.secondEdit,e,this.factory.concatDelete)})}},t.edit=function(e){void 0!==e.delete&&this.delete(e.delete),void 0!==e.insert&&this.insert(e.insert)},t.onArrayElement=function(e){switch(e.type){case k:return void this.retain(e.retain);case"edit":this.edit(e.edit)}},t.onUnit=function(e){e.type!==k?this.edit(e):this.retain(e.retain)},t.build=function(){var e;return{headEdit:null!=(e=this.headEdit)?e:void 0,body:[].concat(this.body),tailRetain:0===this.tailRetain?void 0:this.tailRetain}},t.toIterable=d.mark((function e(){var t,n,r,i;return d.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==(t=this.build()).headEdit){e.next=4;break}return e.next=4,{type:"edit",edit:t.headEdit};case 4:n=a(t.body);case 5:if((r=n()).done){e.next=13;break}return i=r.value,e.next=9,{type:k,retain:i.firstRetain};case 9:return e.next=11,{type:"edit",edit:i.secondEdit};case 11:e.next=5;break;case 13:if(null==t.tailRetain){e.next=16;break}return e.next=16,{type:k,retain:t.tailRetain};case 16:case"end":return e.stop()}}),e,this)})),t.toUnits=d.mark((function e(){var t,n,r;return d.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=a(this.toIterable());case 1:if((n=t()).done){e.next=15;break}if((r=n.value).type!==k){e.next=7;break}return e.next=6,{type:k,retain:r.retain};case 6:return e.abrupt("continue",13);case 7:if(void 0===r.edit.delete){e.next=10;break}return e.next=10,{type:y,delete:r.edit.delete};case 10:if(void 0===r.edit.insert){e.next=13;break}return e.next=13,{type:p,insert:r.edit.insert};case 13:e.next=1;break;case 15:case"end":return e.stop()}}),e,this)})),e}(),S=function(e){var t=e.source,n=e.start,r=e.count,i=e.replacement;if(t.length<n+r)return null;var o=t.substring(n,n+r);return{newValue:t.substring(0,n)+i+t.substring(n+r),deleted:o}},O=function(e){var n=e.state,r=e.action,i=e.getDeleteLength,o=e.restoreOption,u=e.mapping,c=function(e,t){return e.reduce((function(e,n){switch(n.type){case k:return e+n.retain.value;default:return e+(void 0===n.edit.delete?0:t(n.edit.delete).value)}}),0)}(r,i);if(n.length<c)return t.Result.error({type:"stateTooShort"});if(n.length>c)return t.Result.error({type:"stateTooLong"});for(var l,s=n,d=0,f=null==o?void 0:new D(o.factory),v=a(r);!(l=v()).done;){var p=l.value;switch(p.type){case k:d+=p.retain.value,null==f||f.retain(p.retain);break;case"edit":var y,g,w=null!=(y=null==(g=p.edit.insert)?void 0:g.value)?y:"",b=S({source:s,start:d,count:null==p.edit.delete?0:i(p.edit.delete).value,replacement:w});if(null==b)return t.Result.error({type:"stateTooShort"});if(null!=p.edit.delete){var m=new h(b.deleted),x=u({expected:p.edit.delete,actual:m});if(!x.hasValue)return t.Result.error({type:"deleteStringNotMatch",startCharIndex:d,expected:p.edit.delete,actual:m});null==f||f.delete(x.value)}void 0!==p.edit.insert&&(null==f||f.insert(p.edit.insert)),s=b.newValue,d+=w.length}}return t.Result.ok({newState:s,restored:null==f?void 0:f.build()})},T=function(e){var n=e.first,r=e.second,i=e.factory,o=e.splitDelete,a=e.splitInsert,u=function(e,t){return e.reduce((function(e,n){switch(n.type){case k:return e+n.retain.value;default:return e+function(e,t){return void 0===e.insert?0:t.getInsertLength(e.insert).value}(n,t)}}),0)}(n,i),c=R(r,i);if(u<c)return t.Result.error({type:"secondTooLong"});if(u>c)return t.Result.error({type:"secondTooShort"});for(var l=[].concat(n),s=[].concat(r),d=void 0,f=void 0,h=new D(i);;)if(void 0===d&&(d=l.shift()),void 0===f&&(f=s.shift()),void 0!==d)if(void 0!==f)if(d.type!==y)if(f.type!==p){if(d.type===k){if(f.type===k){if(d.retain.value<f.retain.value){h.retain(d.retain),f={type:k,retain:new v(f.retain.value-d.retain.value)},d=void 0;continue}if(d.retain.value===f.retain.value){h.retain(d.retain),d=f=void 0;continue}h.retain(f.retain),d={type:k,retain:new v(d.retain.value-f.retain.value)},f=void 0;continue}if(f.type===y){var g=i.getDeleteLength(f.delete);if(d.retain.value<g.value){var w=o(f.delete,d.retain),b=w[1];h.delete(w[0]),f={type:y,delete:b},d=void 0;continue}if(d.retain.value===g.value){h.delete(f.delete),d=f=void 0;continue}h.delete(f.delete),d={type:k,retain:new v(d.retain.value-g.value)},f=void 0;continue}throw new Error("This should not happen.")}if(f.type!==k){var m=i.getInsertLength(d.insert),x=i.getDeleteLength(f.delete);if(m.value<x.value){var E=o(f.delete,m);d=void 0,f={type:y,delete:E[1]}}else if(m.value!==x.value){var L=a(d.insert,x);d={type:p,insert:L[1]},f=void 0}else d=f=void 0}else{var I=i.getInsertLength(d.insert);if(I.value<f.retain.value){h.insert(d.insert),f={type:k,retain:new v(f.retain.value-I.value)},d=void 0;continue}if(I.value===f.retain.value){h.insert(d.insert),d=f=void 0;continue}var S=a(d.insert,f.retain),O=S[1];h.insert(S[0]),d={type:p,insert:O},f=void 0}}else h.insert(f.insert),f=void 0;else h.delete(d.delete),d=void 0;else h.onUnit(d),d=void 0;else{if(void 0===f)return t.Result.ok(h.build());h.onUnit(f),f=void 0}},U=function(e){var n=e.first,r=e.second,i=e.factory,o=e.splitDelete,a=R(n,i),u=R(r,i);if(a<u)return t.Result.error({type:"secondTooLong"});if(a>u)return t.Result.error({type:"secondTooShort"});for(var c=[].concat(n),l=[].concat(r),s=void 0,d=void 0,f=new D(i),h=new D(i);;)if(void 0===s&&(s=c.shift()),void 0===d&&(d=l.shift()),void 0!==s)if(void 0!==d)if(s.type!==p)if(d.type!==p)if(s.type!==k)if(d.type!==k){var g=i.getDeleteLength(s.delete),w=i.getDeleteLength(d.delete);if(g.value<w.value){var b=o(d.delete,g);s=void 0,d={type:y,delete:b[1]}}else if(g.value!==w.value){var m=o(s.delete,w);s={type:y,delete:m[1]},d=void 0}else s=void 0,d=void 0}else{var x=i.getDeleteLength(s.delete);if(d.retain.value<x.value){var E=o(s.delete,d.retain),L=E[1];f.delete(E[0]),s={type:y,delete:L},d=void 0;continue}if(d.retain.value===x.value){f.delete(s.delete),s=void 0,d=void 0;continue}f.delete(s.delete),s=void 0,d={type:k,retain:new v(d.retain.value-x.value)}}else{if(d.type===k){if(s.retain.value<d.retain.value){f.retain(s.retain),h.retain(s.retain),d={type:k,retain:new v(d.retain.value-s.retain.value)},s=void 0;continue}if(s.retain.value===d.retain.value){f.retain(s.retain),h.retain(s.retain),s=d=void 0;continue}f.retain(d.retain),h.retain(d.retain),s={type:k,retain:new v(s.retain.value-d.retain.value)},d=void 0;continue}var I=i.getDeleteLength(d.delete);if(s.retain.value<I.value){var S=o(d.delete,s.retain),O=S[1];h.delete(S[0]),s=void 0,d={type:y,delete:O};continue}if(s.retain.value===I.value){h.delete(d.delete),s=void 0,d=void 0;continue}h.delete(d.delete),s={type:k,retain:new v(s.retain.value-I.value)},d=void 0}else f.retain(i.getInsertLength(d.insert)),h.insert(d.insert),d=void 0;else f.insert(s.insert),h.retain(i.getInsertLength(s.insert)),s=void 0;else f.onUnit(s),s.type===p&&h.retain(i.getInsertLength(s.insert)),s=void 0;else{if(void 0===d)return t.Result.ok({firstPrime:f.build(),secondPrime:h.build()});d.type===p&&f.retain(i.getInsertLength(d.insert)),h.onUnit(d),d=void 0}},_=function(e){return{headEdit:void 0===e.headEdit?e.headEdit:L(e.headEdit),body:e.body.map((function(e){return function(e){return i({},e,{secondEdit:L(e.secondEdit)})}(e)})),tailRetain:e.tailRetain}},j={getInsertLength:function(e){return e.length},getDeleteLength:function(e){return e},concatInsert:function(e,t){return e.concat(t)},concatDelete:function(e,t){return v.add(e,t)}},N={getInsertLength:function(e){return e},getDeleteLength:function(e){return e.length},concatInsert:function(e,t){return v.add(e,t)},concatDelete:function(e,t){return e.concat(t)}},C={getInsertLength:function(e){return e.length},getDeleteLength:function(e){return e.length},concatInsert:function(e,t){return e.concat(t)},concatDelete:function(e,t){return e.concat(t)}};(u=exports.TextTwoWayOperation||(exports.TextTwoWayOperation={})).diff=function(t){var n=t.first,r=t.second,i=new D(C);return(new e.diff_match_patch).diff_main(n,r).forEach((function(e){var t=e[1];switch(e[0]){case-1:i.delete(new h(t));break;case 0:i.retain(new v(t.length));break;case 1:i.insert(new h(t))}})),i.build()},u.serverTransform=function(e){var t=e.second;return U({first:[].concat(new D(C,e.first).toUnits()),second:[].concat(new D(C,t).toUnits()),factory:C,splitDelete:function(e,t){return[new h(e.value.substring(0,t.value)),new h(e.value.substring(t.value))]}})},u.toUnit=function(e){return[].concat(new D(C,e).toUnits()).map((function(e){switch(e.type){case p:return{t:g,i:e.insert.value};case y:return{t:w,d:e.delete.value};case k:return{t:b,r:e.retain.value}}}))},u.ofUnit=function(e){for(var t,n=new D(C),r=a(e);!(t=r()).done;){var i=t.value;if(null!=i)switch(i.t){case b:var o=v.tryCreate(i.r);if(null==o)continue;n.retain(o);break;case g:var u=h.tryCreate(i.i);if(null==u)continue;n.insert(u);break;case w:var c=h.tryCreate(i.d);if(null==c)continue;n.delete(c)}}return n.build()},u.toUpOperation=function(e){return I({source:e,mapInsert:function(e){return e},mapDelete:function(e){return e.length}})},u.toDownOperation=function(e){return I({source:e,mapInsert:function(e){return e.length},mapDelete:function(e){return e}})},(c=exports.TextUpOperation||(exports.TextUpOperation={})).apply=function(e){var n=O({state:e.prevState,action:[].concat(new D(j,e.action).toIterable()),getDeleteLength:function(e){return e},mapping:function(){return f(void 0)}});return n.isError?n:t.Result.ok(n.value.newState)},c.applyAndRestore=function(e){var n=O({state:e.prevState,action:[].concat(new D(j,e.action).toIterable()),getDeleteLength:function(e){return e},restoreOption:{factory:C},mapping:function(e){return f(e.actual)}});if(n.isError)return n;if(void 0===n.value.restored)throw new Error("this should not happen");return t.Result.ok({nextState:n.value.newState,restored:n.value.restored})},c.compose=function(e){var t=e.second;return T({first:[].concat(new D(j,e.first).toUnits()),second:[].concat(new D(j,t).toUnits()),factory:j,splitInsert:function(e,t){return[new h(e.value.substring(0,t.value)),new h(e.value.substring(t.value))]},splitDelete:function(e,t){return[t,new v(e.value-t.value)]}})},c.transform=function(e){var t=e.second;return U({first:[].concat(new D(j,e.first).toUnits()),second:[].concat(new D(j,t).toUnits()),factory:j,splitDelete:function(e,t){return[t,new v(e.value-t.value)]}})},c.invert=function(e){return _(e)},c.toUnit=function(e){return[].concat(new D(j,e).toUnits()).map((function(e){switch(e.type){case p:return{t:g,i:e.insert.value};case y:return{t:w,d:e.delete.value};case k:return{t:b,r:e.retain.value}}}))},c.ofUnit=function(e){for(var t,n=new D(j),r=a(e);!(t=r()).done;){var i=t.value;if(null!=i)switch(i.t){case b:var o=v.tryCreate(i.r);if(null==o)continue;n.retain(o);break;case g:var u=h.tryCreate(i.i);if(null==u)continue;n.insert(u);break;case w:var c=v.tryCreate("string"==typeof i.d?i.d.length:i.d);if(null==c)continue;n.delete(c)}}return n.build()},(l=exports.TextDownOperation||(exports.TextDownOperation={})).applyBack=function(e){return exports.TextUpOperation.apply({prevState:e.nextState,action:_(e.action)})},l.applyBackAndRestore=function(e){var n=exports.TextUpOperation.applyAndRestore({prevState:e.nextState,action:_(e.action)});return n.isError?n:t.Result.ok({prevState:n.value.nextState,restored:_(n.value.restored)})},l.compose=function(e){var t=e.second;return T({first:[].concat(new D(N,e.first).toUnits()),second:[].concat(new D(N,t).toUnits()),factory:N,splitInsert:function(e,t){return[t,new v(e.value-t.value)]},splitDelete:function(e,t){return[new h(e.value.substring(0,t.value)),new h(e.value.substring(t.value))]}})},l.invert=function(e){return _(e)},l.toUnit=function(e){return[].concat(new D(N,e).toUnits()).map((function(e){switch(e.type){case p:return{t:g,i:e.insert.value};case y:return{t:w,d:e.delete.value};case k:return{t:b,r:e.retain.value}}}))},l.ofUnit=function(e){for(var t,n=new D(N),r=a(e);!(t=r()).done;){var i=t.value;if(null!=i)switch(i.t){case b:var o=v.tryCreate(i.r);if(null==o)continue;n.retain(o);break;case g:var u=v.tryCreate("string"==typeof i.i?i.i.length:i.i);if(null==u)continue;n.insert(u);break;case w:var c=h.tryCreate(i.d);if(null==c)continue;n.delete(c)}}return n.build()},l.diff=function(t){var n=t.first,r=t.second,i=new D(N);return(new e.diff_match_patch).diff_main(n,r).forEach((function(e){var t=e[1];switch(e[0]){case-1:i.delete(new h(t));break;case 0:i.retain(new v(t.length));break;case 1:i.insert(new v(t.length))}})),i.build()},exports.NonEmptyString=h,exports.PositiveInt=v,exports.d=w,exports.delete$=y,exports.deleteStringNotMatch="deleteStringNotMatch",exports.edit="edit",exports.i=g,exports.insert$=p,exports.retain=k,exports.stateTooLong="stateTooLong",exports.stateTooShort="stateTooShort";
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("diff-match-patch"),t=require("@kizahasi/result");function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function n(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function a(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return o(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,l,s,c,d=(function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var i=Object.create((t&&t.prototype instanceof d?t:d).prototype),o=new L(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var u=b(a,r);if(u){if(u===c)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var l=s(e,t,r);if("normal"===l.type){if(n=r.done?"completed":"suspendedYield",l.arg===c)continue;return{value:l.arg,done:r.done}}"throw"===l.type&&(n="completed",r.method="throw",r.arg=l.arg)}}}(e,r,o),i}function s(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=l;var c={};function d(){}function f(){}function v(){}var h={};h[i]=function(){return this};var p=Object.getPrototypeOf,y=p&&p(p(k([])));y&&y!==t&&r.call(y,i)&&(h=y);var g=v.prototype=d.prototype=Object.create(h);function w(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function m(e,t){var n;this._invoke=function(i,o){function a(){return new t((function(n,a){!function n(i,o,a,u){var l=s(e[i],e,o);if("throw"!==l.type){var c=l.arg,d=c.value;return d&&"object"==typeof d&&r.call(d,"__await")?t.resolve(d.__await).then((function(e){n("next",e,a,u)}),(function(e){n("throw",e,a,u)})):t.resolve(d).then((function(e){c.value=e,a(c)}),(function(e){return n("throw",e,a,u)}))}u(l.arg)}(i,o,n,a)}))}return n=n?n.then(a,a):a()}}function b(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,b(e,t),"throw"===t.method))return c;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return c}var n=s(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,c;var i=n.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,c):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,c)}function x(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function E(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function L(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(x,this),this.reset(!0)}function k(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:R}}function R(){return{value:void 0,done:!0}}return f.prototype=g.constructor=v,v.constructor=f,f.displayName=u(v,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===f||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,u(e,a,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},w(m.prototype),m.prototype[o]=function(){return this},e.AsyncIterator=m,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var a=new m(l(t,r,n,i),o);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},w(g),u(g,a,"Generator"),g[i]=function(){return this},g.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=k,L.prototype={constructor:L,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var u=r.call(o,"catchLoc"),l=r.call(o,"finallyLoc");if(u&&l){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,c):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),c},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),E(r),c}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;E(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),c}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(c={exports:{}}),c.exports),f=function(e){return{hasValue:!0,value:e}},v=function(){function e(e){if(this.source=e,!Number.isInteger(e))throw new Error("not integer");if(e<1)throw new Error("less than 1")}return e.add=function(t,r){return new e(t.value+r.value)},e.tryCreate=function(t){if(Number.isInteger(t)&&!(t<1))return new e(t)},n(e,[{key:"value",get:function(){return this.source}},{key:"successor",get:function(){return new e(this.source+1)}}],[{key:"one",get:function(){return new e(1)}}]),e}(),h=function(){function e(e){if(this.source=e,""===e)throw new Error("empty string")}return e.prototype.concat=function(t){return new e(this.value+t.value)},e.tryCreate=function(t){if(""!==t)return new e(t)},n(e,[{key:"value",get:function(){return this.source}},{key:"length",get:function(){return new v(this.source.length)}}]),e}(),p="insert",y="delete",g="i",w="d",m="r",b=function(e){var t=e.source,r=e.mapInsert,n=e.mapDelete;switch(t.type){case p:return{type:p,insert:r(t.insert)};case y:return{type:y,delete:n(t.delete)};case"replace":return{type:"replace",insert:r(t.insert),delete:n(t.delete)}}},x=function(e,t,r){switch(e.type){case p:return{type:p,insert:r(e.insert,t)};case y:return{type:"replace",insert:t,delete:e.delete};case"replace":return{type:"replace",insert:r(e.insert,t),delete:e.delete}}},E=function(e,t,r){switch(e.type){case p:return{type:"replace",insert:e.insert,delete:t};case y:return{type:y,delete:r(e.delete,t)};case"replace":return{type:"replace",insert:e.insert,delete:r(e.delete,t)}}},L=function(e){switch(e.type){case p:return{type:y,delete:e.insert};case y:return{type:p,insert:e.delete};case"replace":return{type:"replace",insert:e.delete,delete:e.insert}}},k="retain",R=function(e,t){return e.reduce((function(e,r){switch(r.type){case k:return e+r.retain.value;default:return e+function(e,t){return void 0===e.delete?0:t.getDeleteLength(e.delete).value}(r,t)}}),0)},I=function(e){var t=e.source,r=e.mapInsert,n=e.mapDelete;return{headEdit:void 0===t.headEdit?t.headEdit:b({source:t.headEdit,mapInsert:r,mapDelete:n}),body:t.body.map((function(e){return function(e){var t=e.source;return i({},t,{secondEdit:b({source:t.secondEdit,mapInsert:e.mapInsert,mapDelete:e.mapDelete})})}({source:e,mapInsert:r,mapDelete:n})})),tailRetain:t.tailRetain}},D=function(){function e(e,t){var r,n;this.factory=e,this.headEdit=null,this.body=[],this.tailRetain=0,null!=t&&(this.headEdit=null!=(r=t.headEdit)?r:null,this.body=Array.from(t.body),this.tailRetain=null!=(n=t.tailRetain)?n:0)}var t=e.prototype;return t.retain=function(e){this.tailRetain=0!==this.tailRetain?v.add(this.tailRetain,e):e},t.insert=function(e){if(0!==this.tailRetain)return this.body.push({firstRetain:this.tailRetain,secondEdit:{type:p,insert:e}}),void(this.tailRetain=0);if(0===this.body.length)this.headEdit=null!=this.headEdit?x(this.headEdit,e,this.factory.concatInsert):{type:p,insert:e,delete:void 0};else{var t=this.body[this.body.length-1];this.body[this.body.length-1]=i({},t,{secondEdit:x(t.secondEdit,e,this.factory.concatInsert)})}},t.delete=function(e){if(0!==this.tailRetain)return this.body.push({firstRetain:this.tailRetain,secondEdit:{type:y,delete:e}}),void(this.tailRetain=0);if(0===this.body.length)this.headEdit=null!=this.headEdit?E(this.headEdit,e,this.factory.concatDelete):{type:y,insert:void 0,delete:e};else{var t=this.body[this.body.length-1];this.body[this.body.length-1]=i({},t,{secondEdit:E(t.secondEdit,e,this.factory.concatDelete)})}},t.edit=function(e){void 0!==e.delete&&this.delete(e.delete),void 0!==e.insert&&this.insert(e.insert)},t.onArrayElement=function(e){switch(e.type){case k:return void this.retain(e.retain);case"edit":this.edit(e.edit)}},t.onUnit=function(e){e.type!==k?this.edit(e):this.retain(e.retain)},t.build=function(){var e;return{headEdit:null!=(e=this.headEdit)?e:void 0,body:Array.from(this.body),tailRetain:0===this.tailRetain?void 0:this.tailRetain}},t.toIterable=d.mark((function e(){var t,r,n,i;return d.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==(t=this.build()).headEdit){e.next=4;break}return e.next=4,{type:"edit",edit:t.headEdit};case 4:r=a(t.body);case 5:if((n=r()).done){e.next=13;break}return i=n.value,e.next=9,{type:k,retain:i.firstRetain};case 9:return e.next=11,{type:"edit",edit:i.secondEdit};case 11:e.next=5;break;case 13:if(null==t.tailRetain){e.next=16;break}return e.next=16,{type:k,retain:t.tailRetain};case 16:case"end":return e.stop()}}),e,this)})),t.toUnits=d.mark((function e(){var t,r,n;return d.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=a(this.toIterable());case 1:if((r=t()).done){e.next=15;break}if((n=r.value).type!==k){e.next=7;break}return e.next=6,{type:k,retain:n.retain};case 6:return e.abrupt("continue",13);case 7:if(void 0===n.edit.delete){e.next=10;break}return e.next=10,{type:y,delete:n.edit.delete};case 10:if(void 0===n.edit.insert){e.next=13;break}return e.next=13,{type:p,insert:n.edit.insert};case 13:e.next=1;break;case 15:case"end":return e.stop()}}),e,this)})),e}(),S=function(e){var t=e.source,r=e.start,n=e.count,i=e.replacement;if(t.length<r+n)return null;var o=t.substring(r,r+n);return{newValue:t.substring(0,r)+i+t.substring(r+n),deleted:o}},A=function(e){var r=e.state,n=e.action,i=e.getDeleteLength,o=e.restoreOption,u=e.mapping,l=function(e,t){return e.reduce((function(e,r){switch(r.type){case k:return e+r.retain.value;default:return e+(void 0===r.edit.delete?0:t(r.edit.delete).value)}}),0)}(n,i);if(r.length<l)return t.Result.error({type:"stateTooShort"});if(r.length>l)return t.Result.error({type:"stateTooLong"});for(var s,c=r,d=0,f=null==o?void 0:new D(o.factory),v=a(n);!(s=v()).done;){var p=s.value;switch(p.type){case k:d+=p.retain.value,null==f||f.retain(p.retain);break;case"edit":var y,g,w=null!=(y=null==(g=p.edit.insert)?void 0:g.value)?y:"",m=S({source:c,start:d,count:null==p.edit.delete?0:i(p.edit.delete).value,replacement:w});if(null==m)return t.Result.error({type:"stateTooShort"});if(null!=p.edit.delete){var b=new h(m.deleted),x=u({expected:p.edit.delete,actual:b});if(!x.hasValue)return t.Result.error({type:"deleteStringNotMatch",startCharIndex:d,expected:p.edit.delete,actual:b});null==f||f.delete(x.value)}void 0!==p.edit.insert&&(null==f||f.insert(p.edit.insert)),c=m.newValue,d+=w.length}}return t.Result.ok({newState:c,restored:null==f?void 0:f.build()})},O=function(e){var r=e.first,n=e.second,i=e.factory,o=e.splitDelete,a=e.splitInsert,u=function(e,t){return e.reduce((function(e,r){switch(r.type){case k:return e+r.retain.value;default:return e+function(e,t){return void 0===e.insert?0:t.getInsertLength(e.insert).value}(r,t)}}),0)}(r,i),l=R(n,i);if(u<l)return t.Result.error({type:"secondTooLong"});if(u>l)return t.Result.error({type:"secondTooShort"});for(var s=Array.from(r),c=Array.from(n),d=void 0,f=void 0,h=new D(i);;)if(void 0===d&&(d=s.shift()),void 0===f&&(f=c.shift()),void 0!==d)if(void 0!==f)if(d.type!==y)if(f.type!==p){if(d.type===k){if(f.type===k){if(d.retain.value<f.retain.value){h.retain(d.retain),f={type:k,retain:new v(f.retain.value-d.retain.value)},d=void 0;continue}if(d.retain.value===f.retain.value){h.retain(d.retain),d=f=void 0;continue}h.retain(f.retain),d={type:k,retain:new v(d.retain.value-f.retain.value)},f=void 0;continue}if(f.type===y){var g=i.getDeleteLength(f.delete);if(d.retain.value<g.value){var w=o(f.delete,d.retain),m=w[1];h.delete(w[0]),f={type:y,delete:m},d=void 0;continue}if(d.retain.value===g.value){h.delete(f.delete),d=f=void 0;continue}h.delete(f.delete),d={type:k,retain:new v(d.retain.value-g.value)},f=void 0;continue}throw new Error("This should not happen.")}if(f.type!==k){var b=i.getInsertLength(d.insert),x=i.getDeleteLength(f.delete);if(b.value<x.value){var E=o(f.delete,b);d=void 0,f={type:y,delete:E[1]}}else if(b.value!==x.value){var L=a(d.insert,x);d={type:p,insert:L[1]},f=void 0}else d=f=void 0}else{var I=i.getInsertLength(d.insert);if(I.value<f.retain.value){h.insert(d.insert),f={type:k,retain:new v(f.retain.value-I.value)},d=void 0;continue}if(I.value===f.retain.value){h.insert(d.insert),d=f=void 0;continue}var S=a(d.insert,f.retain),A=S[1];h.insert(S[0]),d={type:p,insert:A},f=void 0}}else h.insert(f.insert),f=void 0;else h.delete(d.delete),d=void 0;else h.onUnit(d),d=void 0;else{if(void 0===f)return t.Result.ok(h.build());h.onUnit(f),f=void 0}},T=function(e){var r=e.first,n=e.second,i=e.factory,o=e.splitDelete,a=R(r,i),u=R(n,i);if(a<u)return t.Result.error({type:"secondTooLong"});if(a>u)return t.Result.error({type:"secondTooShort"});for(var l=Array.from(r),s=Array.from(n),c=void 0,d=void 0,f=new D(i),h=new D(i);;)if(void 0===c&&(c=l.shift()),void 0===d&&(d=s.shift()),void 0!==c)if(void 0!==d)if(c.type!==p)if(d.type!==p)if(c.type!==k)if(d.type!==k){var g=i.getDeleteLength(c.delete),w=i.getDeleteLength(d.delete);if(g.value<w.value){var m=o(d.delete,g);c=void 0,d={type:y,delete:m[1]}}else if(g.value!==w.value){var b=o(c.delete,w);c={type:y,delete:b[1]},d=void 0}else c=void 0,d=void 0}else{var x=i.getDeleteLength(c.delete);if(d.retain.value<x.value){var E=o(c.delete,d.retain),L=E[1];f.delete(E[0]),c={type:y,delete:L},d=void 0;continue}if(d.retain.value===x.value){f.delete(c.delete),c=void 0,d=void 0;continue}f.delete(c.delete),c=void 0,d={type:k,retain:new v(d.retain.value-x.value)}}else{if(d.type===k){if(c.retain.value<d.retain.value){f.retain(c.retain),h.retain(c.retain),d={type:k,retain:new v(d.retain.value-c.retain.value)},c=void 0;continue}if(c.retain.value===d.retain.value){f.retain(c.retain),h.retain(c.retain),c=d=void 0;continue}f.retain(d.retain),h.retain(d.retain),c={type:k,retain:new v(c.retain.value-d.retain.value)},d=void 0;continue}var I=i.getDeleteLength(d.delete);if(c.retain.value<I.value){var S=o(d.delete,c.retain),A=S[1];h.delete(S[0]),c=void 0,d={type:y,delete:A};continue}if(c.retain.value===I.value){h.delete(d.delete),c=void 0,d=void 0;continue}h.delete(d.delete),c={type:k,retain:new v(c.retain.value-I.value)},d=void 0}else f.retain(i.getInsertLength(d.insert)),h.insert(d.insert),d=void 0;else f.insert(c.insert),h.retain(i.getInsertLength(c.insert)),c=void 0;else f.onUnit(c),c.type===p&&h.retain(i.getInsertLength(c.insert)),c=void 0;else{if(void 0===d)return t.Result.ok({firstPrime:f.build(),secondPrime:h.build()});d.type===p&&f.retain(i.getInsertLength(d.insert)),h.onUnit(d),d=void 0}},U=function(e){return{headEdit:void 0===e.headEdit?e.headEdit:L(e.headEdit),body:e.body.map((function(e){return function(e){return i({},e,{secondEdit:L(e.secondEdit)})}(e)})),tailRetain:e.tailRetain}},_={getInsertLength:function(e){return e.length},getDeleteLength:function(e){return e},concatInsert:function(e,t){return e.concat(t)},concatDelete:function(e,t){return v.add(e,t)}},j={getInsertLength:function(e){return e},getDeleteLength:function(e){return e.length},concatInsert:function(e,t){return v.add(e,t)},concatDelete:function(e,t){return e.concat(t)}},N={getInsertLength:function(e){return e.length},getDeleteLength:function(e){return e.length},concatInsert:function(e,t){return e.concat(t)},concatDelete:function(e,t){return e.concat(t)}};(u=exports.TextTwoWayOperation||(exports.TextTwoWayOperation={})).diff=function(t){var r=t.first,n=t.second,i=new D(N);return(new e.diff_match_patch).diff_main(r,n).forEach((function(e){var t=e[1];switch(e[0]){case-1:i.delete(new h(t));break;case 0:i.retain(new v(t.length));break;case 1:i.insert(new h(t))}})),i.build()},u.serverTransform=function(e){var t=e.second;return T({first:Array.from(new D(N,e.first).toUnits()),second:Array.from(new D(N,t).toUnits()),factory:N,splitDelete:function(e,t){return[new h(e.value.substring(0,t.value)),new h(e.value.substring(t.value))]}})},u.toUnit=function(e){return Array.from(new D(N,e).toUnits()).map((function(e){switch(e.type){case p:return{t:g,i:e.insert.value};case y:return{t:w,d:e.delete.value};case k:return{t:m,r:e.retain.value}}}))},u.ofUnit=function(e){for(var t,r=new D(N),n=a(e);!(t=n()).done;){var i=t.value;if(null!=i)switch(i.t){case m:var o=v.tryCreate(i.r);if(null==o)continue;r.retain(o);break;case g:var u=h.tryCreate(i.i);if(null==u)continue;r.insert(u);break;case w:var l=h.tryCreate(i.d);if(null==l)continue;r.delete(l)}}return r.build()},u.toUpOperation=function(e){return I({source:e,mapInsert:function(e){return e},mapDelete:function(e){return e.length}})},u.toDownOperation=function(e){return I({source:e,mapInsert:function(e){return e.length},mapDelete:function(e){return e}})},(l=exports.TextUpOperation||(exports.TextUpOperation={})).apply=function(e){var r=A({state:e.prevState,action:Array.from(new D(_,e.action).toIterable()),getDeleteLength:function(e){return e},mapping:function(){return f(void 0)}});return r.isError?r:t.Result.ok(r.value.newState)},l.applyAndRestore=function(e){var r=A({state:e.prevState,action:Array.from(new D(_,e.action).toIterable()),getDeleteLength:function(e){return e},restoreOption:{factory:N},mapping:function(e){return f(e.actual)}});if(r.isError)return r;if(void 0===r.value.restored)throw new Error("this should not happen");return t.Result.ok({nextState:r.value.newState,restored:r.value.restored})},l.compose=function(e){var t=e.second;return O({first:Array.from(new D(_,e.first).toUnits()),second:Array.from(new D(_,t).toUnits()),factory:_,splitInsert:function(e,t){return[new h(e.value.substring(0,t.value)),new h(e.value.substring(t.value))]},splitDelete:function(e,t){return[t,new v(e.value-t.value)]}})},l.transform=function(e){var t=e.second;return T({first:Array.from(new D(_,e.first).toUnits()),second:Array.from(new D(_,t).toUnits()),factory:_,splitDelete:function(e,t){return[t,new v(e.value-t.value)]}})},l.invert=function(e){return U(e)},l.toUnit=function(e){return Array.from(new D(_,e).toUnits()).map((function(e){switch(e.type){case p:return{t:g,i:e.insert.value};case y:return{t:w,d:e.delete.value};case k:return{t:m,r:e.retain.value}}}))},l.ofUnit=function(e){for(var t,r=new D(_),n=a(e);!(t=n()).done;){var i=t.value;if(null!=i)switch(i.t){case m:var o=v.tryCreate(i.r);if(null==o)continue;r.retain(o);break;case g:var u=h.tryCreate(i.i);if(null==u)continue;r.insert(u);break;case w:var l=v.tryCreate("string"==typeof i.d?i.d.length:i.d);if(null==l)continue;r.delete(l)}}return r.build()},(s=exports.TextDownOperation||(exports.TextDownOperation={})).applyBack=function(e){return exports.TextUpOperation.apply({prevState:e.nextState,action:U(e.action)})},s.applyBackAndRestore=function(e){var r=exports.TextUpOperation.applyAndRestore({prevState:e.nextState,action:U(e.action)});return r.isError?r:t.Result.ok({prevState:r.value.nextState,restored:U(r.value.restored)})},s.compose=function(e){var t=e.second;return O({first:Array.from(new D(j,e.first).toUnits()),second:Array.from(new D(j,t).toUnits()),factory:j,splitInsert:function(e,t){return[t,new v(e.value-t.value)]},splitDelete:function(e,t){return[new h(e.value.substring(0,t.value)),new h(e.value.substring(t.value))]}})},s.invert=function(e){return U(e)},s.toUnit=function(e){return Array.from(new D(j,e).toUnits()).map((function(e){switch(e.type){case p:return{t:g,i:e.insert.value};case y:return{t:w,d:e.delete.value};case k:return{t:m,r:e.retain.value}}}))},s.ofUnit=function(e){for(var t,r=new D(j),n=a(e);!(t=n()).done;){var i=t.value;if(null!=i)switch(i.t){case m:var o=v.tryCreate(i.r);if(null==o)continue;r.retain(o);break;case g:var u=v.tryCreate("string"==typeof i.i?i.i.length:i.i);if(null==u)continue;r.insert(u);break;case w:var l=h.tryCreate(i.d);if(null==l)continue;r.delete(l)}}return r.build()},s.diff=function(t){var r=t.first,n=t.second,i=new D(j);return(new e.diff_match_patch).diff_main(r,n).forEach((function(e){var t=e[1];switch(e[0]){case-1:i.delete(new h(t));break;case 0:i.retain(new v(t.length));break;case 1:i.insert(new v(t.length))}})),i.build()},exports.NonEmptyString=h,exports.PositiveInt=v,exports.d=w,exports.delete$=y,exports.deleteStringNotMatch="deleteStringNotMatch",exports.edit="edit",exports.i=g,exports.insert$=p,exports.retain=k,exports.stateTooLong="stateTooLong",exports.stateTooShort="stateTooShort";
//# sourceMappingURL=ot-string.cjs.production.min.js.map
{
"version": "0.2.0",
"version": "0.2.1",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

@@ -394,3 +394,3 @@ import { diff_match_patch } from 'diff-match-patch';

this.headEdit = source.headEdit ?? null;
this.body = [...source.body];
this.body = Array.from(source.body);
this.tailRetain = source.tailRetain ?? 0;

@@ -521,3 +521,3 @@ }

headEdit: this.headEdit ?? undefined,
body: [...this.body],
body: Array.from(this.body),
tailRetain: this.tailRetain === 0 ? undefined : this.tailRetain,

@@ -747,4 +747,4 @@ };

const first = [...$first];
const second = [...$second];
const first = Array.from($first);
const second = Array.from($second);
let firstShift: TextOperationUnit<TInsert, TDelete> | undefined = undefined;

@@ -964,4 +964,4 @@ let secondShift:

const first = [...$first];
const second = [...$second];
const first = Array.from($first);
const second = Array.from($second);
let firstShift: TextOperationUnit<TInsert, TDelete> | undefined = undefined;

@@ -1268,8 +1268,8 @@ let secondShift:

return transformCore({
first: [
...new TextOperationBuilder(twoWayFactory, first).toUnits(),
],
second: [
...new TextOperationBuilder(twoWayFactory, second).toUnits(),
],
first: Array.from(
new TextOperationBuilder(twoWayFactory, first).toUnits()
),
second: Array.from(
new TextOperationBuilder(twoWayFactory, second).toUnits()
),
factory: twoWayFactory,

@@ -1286,5 +1286,5 @@ splitDelete: (target, deleteCount) => [

export const toUnit = (source: Operation): OperationUnit[] => {
return [
...new TextOperationBuilder(twoWayFactory, source).toUnits(),
].map(unit => {
return Array.from(
new TextOperationBuilder(twoWayFactory, source).toUnits()
).map(unit => {
switch (unit.type) {

@@ -1401,5 +1401,5 @@ case insert$:

state: prevState,
action: [
...new TextOperationBuilder(upFactory, action).toIterable(),
],
action: Array.from(
new TextOperationBuilder(upFactory, action).toIterable()
),
getDeleteLength: del => del,

@@ -1426,5 +1426,5 @@ mapping: () => OptionModule.some(undefined),

state: prevState,
action: [
...new TextOperationBuilder(upFactory, action).toIterable(),
],
action: Array.from(
new TextOperationBuilder(upFactory, action).toIterable()
),
getDeleteLength: del => del,

@@ -1456,4 +1456,8 @@ restoreOption: {

return composeCore({
first: [...new TextOperationBuilder(upFactory, first).toUnits()],
second: [...new TextOperationBuilder(upFactory, second).toUnits()],
first: Array.from(
new TextOperationBuilder(upFactory, first).toUnits()
),
second: Array.from(
new TextOperationBuilder(upFactory, second).toUnits()
),
factory: upFactory,

@@ -1482,4 +1486,8 @@ splitInsert: (str, index) => [

return transformCore({
first: [...new TextOperationBuilder(upFactory, first).toUnits()],
second: [...new TextOperationBuilder(upFactory, second).toUnits()],
first: Array.from(
new TextOperationBuilder(upFactory, first).toUnits()
),
second: Array.from(
new TextOperationBuilder(upFactory, second).toUnits()
),
factory: upFactory,

@@ -1498,23 +1506,23 @@ splitDelete: (target, deleteCount) => [

export const toUnit = (source: Operation): OperationUnit[] => {
return [...new TextOperationBuilder(upFactory, source).toUnits()].map(
unit => {
switch (unit.type) {
case insert$:
return {
t: i,
i: unit.insert.value,
} as const;
case delete$:
return {
t: d,
d: unit.delete.value,
} as const;
case retain:
return {
t: r,
r: unit.retain.value,
} as const;
}
return Array.from(
new TextOperationBuilder(upFactory, source).toUnits()
).map(unit => {
switch (unit.type) {
case insert$:
return {
t: i,
i: unit.insert.value,
} as const;
case delete$:
return {
t: d,
d: unit.delete.value,
} as const;
case retain:
return {
t: r,
r: unit.retain.value,
} as const;
}
);
});
};

@@ -1630,6 +1638,8 @@

return composeCore({
first: [...new TextOperationBuilder(downFactory, first).toUnits()],
second: [
...new TextOperationBuilder(downFactory, second).toUnits(),
],
first: Array.from(
new TextOperationBuilder(downFactory, first).toUnits()
),
second: Array.from(
new TextOperationBuilder(downFactory, second).toUnits()
),
factory: downFactory,

@@ -1652,23 +1662,23 @@ splitInsert: (target, deleteCount) => [

export const toUnit = (source: Operation): OperationUnit[] => {
return [...new TextOperationBuilder(downFactory, source).toUnits()].map(
unit => {
switch (unit.type) {
case insert$:
return {
t: i,
i: unit.insert.value,
} as const;
case delete$:
return {
t: d,
d: unit.delete.value,
} as const;
case retain:
return {
t: r,
r: unit.retain.value,
} as const;
}
return Array.from(
new TextOperationBuilder(downFactory, source).toUnits()
).map(unit => {
switch (unit.type) {
case insert$:
return {
t: i,
i: unit.insert.value,
} as const;
case delete$:
return {
t: d,
d: unit.delete.value,
} as const;
case retain:
return {
t: r,
r: unit.retain.value,
} as const;
}
);
});
};

@@ -1675,0 +1685,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet