UNPKG

@technik-sde/prosemirror-recreate-transform

Version:

Create a set of steps transforming one prosemirror json document to another

1 lines 96.9 kB
!function webpackUniversalModuleDefinition(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.recreateTransform=e():t.recreateTransform=e()}(global,(function(){return function(t){var e={};function __webpack_require__(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,__webpack_require__),r.l=!0,r.exports}return __webpack_require__.m=t,__webpack_require__.c=e,__webpack_require__.d=function(t,e,n){__webpack_require__.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},__webpack_require__.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},__webpack_require__.t=function(t,e){if(1&e&&(t=__webpack_require__(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(__webpack_require__.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)__webpack_require__.d(n,r,function(e){return t[e]}.bind(null,r));return n},__webpack_require__.n=function(t){var e=t&&t.__esModule?function getDefault(){return t.default}:function getModuleExports(){return t};return __webpack_require__.d(e,"a",e),e},__webpack_require__.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=3)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(1),o=n(4),i=n(6);function createTest(t,e){var n=r.Pointer.fromJSON(e).evaluate(t);if(void 0!==n)return{op:"test",path:e,value:n.value}}e.applyPatch=function applyPatch(t,e){return e.map((function(e){return o.apply(t,e)}))},e.createPatch=function createPatch(t,e,n){var o=new r.Pointer;return(n?function wrapVoidableDiff(t){return function wrappedDiff(e,n,r){var o=t(e,n,r);return Array.isArray(o)?o:i.diffAny(e,n,r,wrappedDiff)}}(n):i.diffAny)(t,e,o)},e.createTests=function createTests(t,e){var n=new Array;return e.filter(i.isDestructive).forEach((function(e){var r=createTest(t,e.path);if(r&&n.push(r),"from"in e){var o=createTest(t,e.from);o&&n.push(o)}})),n}},function(t,e,n){"use strict";function unescape(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function escape(t){return t.replace(/~/g,"~0").replace(/\//g,"~1")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function Pointer(t){void 0===t&&(t=[""]),this.tokens=t}return Pointer.fromJSON=function(t){var e=t.split("/").map(unescape);if(""!==e[0])throw new Error("Invalid JSON Pointer: "+t);return new Pointer(e)},Pointer.prototype.toString=function(){return this.tokens.map(escape).join("/")},Pointer.prototype.evaluate=function(t){for(var e=null,n="",r=t,o=1,i=this.tokens.length;o<i;o++)r=((e=r)||{})[n=this.tokens[o]];return{parent:e,key:n,value:r}},Pointer.prototype.get=function(t){return this.evaluate(t).value},Pointer.prototype.set=function(t,e){for(var n=t,r=1,o=this.tokens.length-1,i=this.tokens[r];r<o;r++)n=(n||{})[i];n&&(n[this.tokens[this.tokens.length-1]]=e)},Pointer.prototype.push=function(t){this.tokens.push(t)},Pointer.prototype.add=function(t){return new Pointer(this.tokens.concat(String(t)))},Pointer}();e.Pointer=r},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=Object.prototype.hasOwnProperty;function objectType(t){return void 0===t?"undefined":null===t?"null":Array.isArray(t)?"array":typeof t}function compare(t,e){if(t===e)return!0;var n=objectType(t),o=objectType(e);return"array"==n&&"array"==o?function compareArrays(t,e){var n=t.length;if(n!==e.length)return!1;for(var r=0;r<n;r++)if(!compare(t[r],e[r]))return!1;return!0}(t,e):"object"==n&&"object"==o&&function compareObjects(t,e){var n=Object.keys(t),o=Object.keys(e),i=n.length;if(i!==o.length)return!1;for(var s=0;s<i;s++){var a=n[s];if(!r.call(e,a)||!compare(t[a],e[a]))return!1}return!0}(t,e)}e.objectType=objectType,e.compare=compare},function(t,e,n){t.exports=n(7)},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function __(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)});Object.defineProperty(e,"__esModule",{value:!0});var i=n(1),s=n(5),a=n(2),p=function(t){function MissingError(e){var n=t.call(this,"Value required at path: "+e)||this;return n.path=e,n.name="MissingError",n}return o(MissingError,t),MissingError}(Error);e.MissingError=p;var c=function(t){function TestError(e,n){var r=t.call(this,"Test failed: "+e+" != "+n)||this;return r.actual=e,r.expected=n,r.name="TestError",r.actual=e,r.expected=n,r}return o(TestError,t),TestError}(Error);function _add(t,e,n){if(Array.isArray(t))if("-"==e)t.push(n);else{var r=parseInt(e,10);t.splice(r,0,n)}else t[e]=n}function _remove(t,e){if(Array.isArray(t)){var n=parseInt(e,10);t.splice(n,1)}else delete t[e]}function add(t,e){var n=i.Pointer.fromJSON(e.path).evaluate(t);return void 0===n.parent?new p(e.path):(_add(n.parent,n.key,s.clone(e.value)),null)}function remove(t,e){var n=i.Pointer.fromJSON(e.path).evaluate(t);return void 0===n.value?new p(e.path):(_remove(n.parent,n.key),null)}function replace(t,e){var n=i.Pointer.fromJSON(e.path).evaluate(t);if(null===n.parent)return new p(e.path);if(Array.isArray(n.parent)){if(parseInt(n.key,10)>=n.parent.length)return new p(e.path)}else if(void 0===n.value)return new p(e.path);return n.parent[n.key]=e.value,null}function move(t,e){var n=i.Pointer.fromJSON(e.from).evaluate(t);if(void 0===n.value)return new p(e.from);var r=i.Pointer.fromJSON(e.path).evaluate(t);return void 0===r.parent?new p(e.path):(_remove(n.parent,n.key),_add(r.parent,r.key,n.value),null)}function copy(t,e){var n=i.Pointer.fromJSON(e.from).evaluate(t);if(void 0===n.value)return new p(e.from);var r=i.Pointer.fromJSON(e.path).evaluate(t);return void 0===r.parent?new p(e.path):(_add(r.parent,r.key,s.clone(n.value)),null)}function test(t,e){var n=i.Pointer.fromJSON(e.path).evaluate(t);return a.compare(n.value,e.value)?null:new c(n.value,e.value)}e.TestError=c,e.add=add,e.remove=remove,e.replace=replace,e.move=move,e.copy=copy,e.test=test;var h=function(t){function InvalidOperationError(e){var n=t.call(this,"Invalid operation: "+e.op)||this;return n.operation=e,n.name="InvalidOperationError",n}return o(InvalidOperationError,t),InvalidOperationError}(Error);e.InvalidOperationError=h,e.apply=function apply(t,e){switch(e.op){case"add":return add(t,e);case"remove":return remove(t,e);case"replace":return replace(t,e);case"move":return move(t,e);case"copy":return copy(t,e);case"test":return test(t,e)}return new h(e)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=Object.prototype.hasOwnProperty;e.clone=function clone(t){if(null==t||"object"!=typeof t)return t;if(t.constructor==Array){for(var e=t.length,n=new Array(e),o=0;o<e;o++)n[o]=clone(t[o]);return n}var i={};for(var s in t)r.call(t,s)&&(i[s]=clone(t[s]));return i}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(2),o=Object.prototype.hasOwnProperty;function subtract(t,e){var n={};for(var r in t)o.call(t,r)&&void 0!==t[r]&&(n[r]=1);for(var i in e)o.call(e,i)&&void 0!==e[i]&&delete n[i];return Object.keys(n)}function intersection(t){for(var e=t.length,n={},r=0;r<e;r++){var i=t[r];for(var s in i)o.call(i,s)&&void 0!==i[s]&&(n[s]=(n[s]||0)+1)}for(var s in n)n[s]<e&&delete n[s];return Object.keys(n)}function appendArrayOperation(t,e){return{operations:t.operations.concat(e),cost:t.cost+1}}function diffArrays(t,e,n,o){void 0===o&&(o=diffAny);var i={"0,0":{operations:[],cost:0}};var s=isNaN(t.length)||t.length<=0?0:t.length,a=isNaN(e.length)||e.length<=0?0:e.length;return function dist(n,o){var s=n+","+o,a=i[s];if(void 0===a){if(n>0&&o>0&&r.compare(t[n-1],e[o-1]))a=dist(n-1,o-1);else{var p=[];if(n>0){var c=dist(n-1,o),h={op:"remove",index:n-1};p.push(appendArrayOperation(c,h))}if(o>0){var f=dist(n,o-1),u={op:"add",index:n-1,value:e[o-1]};p.push(appendArrayOperation(f,u))}if(n>0&&o>0){var l=dist(n-1,o-1),d={op:"replace",index:n-1,original:t[n-1],value:e[o-1]};p.push(appendArrayOperation(l,d))}a=p.sort((function(t,e){return t.cost-e.cost}))[0]}i[s]=a}return a}(s,a).operations.reduce((function(t,e){var r=t[0],i=t[1];if(function isArrayAdd(t){return"add"===t.op}(e)){var a=e.index+1+i,p=a<s+i?String(a):"-",c={op:e.op,path:n.add(p).toString(),value:e.value};return[r.concat(c),i+1]}if(function isArrayRemove(t){return"remove"===t.op}(e)){c={op:e.op,path:n.add(String(e.index+i)).toString()};return[r.concat(c),i-1]}var h=n.add(String(e.index+i)),f=o(e.original,e.value,h);return[r.concat.apply(r,f),i]}),[[],0])[0]}function diffObjects(t,e,n,r){void 0===r&&(r=diffAny);var o=[];return subtract(t,e).forEach((function(t){o.push({op:"remove",path:n.add(t).toString()})})),subtract(e,t).forEach((function(t){o.push({op:"add",path:n.add(t).toString(),value:e[t]})})),intersection([t,e]).forEach((function(i){o.push.apply(o,r(t[i],e[i],n.add(i)))})),o}function diffValues(t,e,n){return r.compare(t,e)?[]:[{op:"replace",path:n.toString(),value:e}]}function diffAny(t,e,n,o){void 0===o&&(o=diffAny);var i=r.objectType(t),s=r.objectType(e);return"array"==i&&"array"==s?diffArrays(t,e,n,o):"object"==i&&"object"==s?diffObjects(t,e,n,o):diffValues(t,e,n)}e.isDestructive=function isDestructive(t){var e=t.op;return"remove"===e||"replace"===e||"copy"===e||"move"===e},e.subtract=subtract,e.intersection=intersection,e.diffArrays=diffArrays,e.diffObjects=diffObjects,e.diffValues=diffValues,e.diffAny=diffAny},function(t,e,n){"use strict";function OrderedMap(t){this.content=t}n.r(e),n.d(e,"recreateTransform",(function(){return recreateTransform})),n.d(e,"RecreateTransform",(function(){return recreateTransform_RecreateTransform})),OrderedMap.prototype={constructor:OrderedMap,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return-1==e?void 0:this.content[e+1]},update:function(t,e,n){var r=n&&n!=t?this.remove(n):this,o=r.find(t),i=r.content.slice();return-1==o?i.push(n||t,e):(i[o+1]=e,n&&(i[o]=n)),new OrderedMap(i)},remove:function(t){var e=this.find(t);if(-1==e)return this;var n=this.content.slice();return n.splice(e,2),new OrderedMap(n)},addToStart:function(t,e){return new OrderedMap([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new OrderedMap(n)},addBefore:function(t,e,n){var r=this.remove(e),o=r.content.slice(),i=r.find(t);return o.splice(-1==i?o.length:i,0,e,n),new OrderedMap(o)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){return(t=OrderedMap.from(t)).size?new OrderedMap(t.content.concat(this.subtract(t).content)):this},append:function(t){return(t=OrderedMap.from(t)).size?new OrderedMap(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=OrderedMap.from(t);for(var n=0;n<t.content.length;n+=2)e=e.remove(t.content[n]);return e},get size(){return this.content.length>>1}},OrderedMap.from=function(t){if(t instanceof OrderedMap)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new OrderedMap(e)};var r=OrderedMap;var o=function Fragment(t,e){if(this.content=t,this.size=e||0,null==e)for(var n=0;n<t.length;n++)this.size+=t[n].nodeSize},i={firstChild:{configurable:!0},lastChild:{configurable:!0},childCount:{configurable:!0}};o.prototype.nodesBetween=function nodesBetween(t,e,n,r,o){void 0===r&&(r=0);for(var i=0,s=0;s<e;i++){var a=this.content[i],p=s+a.nodeSize;if(p>t&&!1!==n(a,r+s,o,i)&&a.content.size){var c=s+1;a.nodesBetween(Math.max(0,t-c),Math.min(a.content.size,e-c),n,r+c)}s=p}},o.prototype.descendants=function descendants(t){this.nodesBetween(0,this.size,t)},o.prototype.textBetween=function textBetween(t,e,n,r){var o="",i=!0;return this.nodesBetween(t,e,(function(s,a){s.isText?(o+=s.text.slice(Math.max(t,a)-a,e-a),i=!n):s.isLeaf&&r?(o+=r,i=!n):!i&&s.isBlock&&(o+=n,i=!0)}),0),o},o.prototype.append=function append(t){if(!t.size)return this;if(!this.size)return t;var e=this.lastChild,n=t.firstChild,r=this.content.slice(),i=0;for(e.isText&&e.sameMarkup(n)&&(r[r.length-1]=e.withText(e.text+n.text),i=1);i<t.content.length;i++)r.push(t.content[i]);return new o(r,this.size+t.size)},o.prototype.cut=function cut(t,e){if(null==e&&(e=this.size),0==t&&e==this.size)return this;var n=[],r=0;if(e>t)for(var i=0,s=0;s<e;i++){var a=this.content[i],p=s+a.nodeSize;p>t&&((s<t||p>e)&&(a=a.isText?a.cut(Math.max(0,t-s),Math.min(a.text.length,e-s)):a.cut(Math.max(0,t-s-1),Math.min(a.content.size,e-s-1))),n.push(a),r+=a.nodeSize),s=p}return new o(n,r)},o.prototype.cutByIndex=function cutByIndex(t,e){return t==e?o.empty:0==t&&e==this.content.length?this:new o(this.content.slice(t,e))},o.prototype.replaceChild=function replaceChild(t,e){var n=this.content[t];if(n==e)return this;var r=this.content.slice(),i=this.size+e.nodeSize-n.nodeSize;return r[t]=e,new o(r,i)},o.prototype.addToStart=function addToStart(t){return new o([t].concat(this.content),this.size+t.nodeSize)},o.prototype.addToEnd=function addToEnd(t){return new o(this.content.concat(t),this.size+t.nodeSize)},o.prototype.eq=function eq(t){if(this.content.length!=t.content.length)return!1;for(var e=0;e<this.content.length;e++)if(!this.content[e].eq(t.content[e]))return!1;return!0},i.firstChild.get=function(){return this.content.length?this.content[0]:null},i.lastChild.get=function(){return this.content.length?this.content[this.content.length-1]:null},i.childCount.get=function(){return this.content.length},o.prototype.child=function child(t){var e=this.content[t];if(!e)throw new RangeError("Index "+t+" out of range for "+this);return e},o.prototype.maybeChild=function maybeChild(t){return this.content[t]},o.prototype.forEach=function forEach(t){for(var e=0,n=0;e<this.content.length;e++){var r=this.content[e];t(r,n,e),n+=r.nodeSize}},o.prototype.findDiffStart=function findDiffStart$1(t,e){return void 0===e&&(e=0),function findDiffStart(t,e,n){for(var r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;var o=t.child(r),i=e.child(r);if(o!=i){if(!o.sameMarkup(i))return n;if(o.isText&&o.text!=i.text){for(var s=0;o.text[s]==i.text[s];s++)n++;return n}if(o.content.size||i.content.size){var a=findDiffStart(o.content,i.content,n+1);if(null!=a)return a}n+=o.nodeSize}else n+=o.nodeSize}}(this,t,e)},o.prototype.findDiffEnd=function findDiffEnd$1(t,e,n){return void 0===e&&(e=this.size),void 0===n&&(n=t.size),function findDiffEnd(t,e,n,r){for(var o=t.childCount,i=e.childCount;;){if(0==o||0==i)return o==i?null:{a:n,b:r};var s=t.child(--o),a=e.child(--i),p=s.nodeSize;if(s!=a){if(!s.sameMarkup(a))return{a:n,b:r};if(s.isText&&s.text!=a.text){for(var c=0,h=Math.min(s.text.length,a.text.length);c<h&&s.text[s.text.length-c-1]==a.text[a.text.length-c-1];)c++,n--,r--;return{a:n,b:r}}if(s.content.size||a.content.size){var f=findDiffEnd(s.content,a.content,n-1,r-1);if(f)return f}n-=p,r-=p}else n-=p,r-=p}}(this,t,e,n)},o.prototype.findIndex=function findIndex(t,e){if(void 0===e&&(e=-1),0==t)return retIndex(0,t);if(t==this.size)return retIndex(this.content.length,t);if(t>this.size||t<0)throw new RangeError("Position "+t+" outside of fragment ("+this+")");for(var n=0,r=0;;n++){var o=r+this.child(n).nodeSize;if(o>=t)return o==t||e>0?retIndex(n+1,o):retIndex(n,r);r=o}},o.prototype.toString=function toString(){return"<"+this.toStringInner()+">"},o.prototype.toStringInner=function toStringInner(){return this.content.join(", ")},o.prototype.toJSON=function toJSON(){return this.content.length?this.content.map((function(t){return t.toJSON()})):null},o.fromJSON=function fromJSON(t,e){if(!e)return o.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return new o(e.map(t.nodeFromJSON))},o.fromArray=function fromArray(t){if(!t.length)return o.empty;for(var e,n=0,r=0;r<t.length;r++){var i=t[r];n+=i.nodeSize,r&&i.isText&&t[r-1].sameMarkup(i)?(e||(e=t.slice(0,r)),e[e.length-1]=i.withText(e[e.length-1].text+i.text)):e&&e.push(i)}return new o(e||t,n)},o.from=function from(t){if(!t)return o.empty;if(t instanceof o)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new o([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))},Object.defineProperties(o.prototype,i);var s={index:0,offset:0};function retIndex(t,e){return s.index=t,s.offset=e,s}function compareDeep(t,e){if(t===e)return!0;if(!t||"object"!=typeof t||!e||"object"!=typeof e)return!1;var n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(var r=0;r<t.length;r++)if(!compareDeep(t[r],e[r]))return!1}else{for(var o in t)if(!(o in e)||!compareDeep(t[o],e[o]))return!1;for(var i in e)if(!(i in t))return!1}return!0}o.empty=new o([],0);var a=function Mark(t,e){this.type=t,this.attrs=e};function ReplaceError(t){var e=Error.call(this,t);return e.__proto__=ReplaceError.prototype,e}a.prototype.addToSet=function addToSet(t){for(var e,n=!1,r=0;r<t.length;r++){var o=t[r];if(this.eq(o))return t;if(this.type.excludes(o.type))e||(e=t.slice(0,r));else{if(o.type.excludes(this.type))return t;!n&&o.type.rank>this.type.rank&&(e||(e=t.slice(0,r)),e.push(this),n=!0),e&&e.push(o)}}return e||(e=t.slice()),n||e.push(this),e},a.prototype.removeFromSet=function removeFromSet(t){for(var e=0;e<t.length;e++)if(this.eq(t[e]))return t.slice(0,e).concat(t.slice(e+1));return t},a.prototype.isInSet=function isInSet(t){for(var e=0;e<t.length;e++)if(this.eq(t[e]))return!0;return!1},a.prototype.eq=function eq(t){return this==t||this.type==t.type&&compareDeep(this.attrs,t.attrs)},a.prototype.toJSON=function toJSON(){var t={type:this.type.name};for(var e in this.attrs){t.attrs=this.attrs;break}return t},a.fromJSON=function fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Mark.fromJSON");var n=t.marks[e.type];if(!n)throw new RangeError("There is no mark type "+e.type+" in this schema");return n.create(e.attrs)},a.sameSet=function sameSet(t,e){if(t==e)return!0;if(t.length!=e.length)return!1;for(var n=0;n<t.length;n++)if(!t[n].eq(e[n]))return!1;return!0},a.setFrom=function setFrom(t){if(!t||0==t.length)return a.none;if(t instanceof a)return[t];var e=t.slice();return e.sort((function(t,e){return t.type.rank-e.type.rank})),e},a.none=[],ReplaceError.prototype=Object.create(Error.prototype),ReplaceError.prototype.constructor=ReplaceError,ReplaceError.prototype.name="ReplaceError";var p=function Slice(t,e,n){this.content=t,this.openStart=e,this.openEnd=n},c={size:{configurable:!0}};function replace(t,e,n){if(n.openStart>t.depth)throw new ReplaceError("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new ReplaceError("Inconsistent open depths");return function replaceOuter(t,e,n,r){var i=t.index(r),s=t.node(r);if(i==e.index(r)&&r<t.depth-n.openStart){var a=replaceOuter(t,e,n,r+1);return s.copy(s.content.replaceChild(i,a))}if(n.content.size){if(n.openStart||n.openEnd||t.depth!=r||e.depth!=r){var p=function prepareSliceForReplace(t,e){for(var n=e.depth-t.openStart,r=e.node(n).copy(t.content),i=n-1;i>=0;i--)r=e.node(i).copy(o.from(r));return{start:r.resolveNoCache(t.openStart+n),end:r.resolveNoCache(r.content.size-t.openEnd-n)}}(n,t),c=p.start,h=p.end;return index_es_close(s,function replaceThreeWay(t,e,n,r,i){var s=t.depth>i&&joinable(t,e,i+1),a=r.depth>i&&joinable(n,r,i+1),p=[];addRange(null,t,i,p),s&&a&&e.index(i)==n.index(i)?(checkJoin(s,a),addNode(index_es_close(s,replaceThreeWay(t,e,n,r,i+1)),p)):(s&&addNode(index_es_close(s,replaceTwoWay(t,e,i+1)),p),addRange(e,n,i,p),a&&addNode(index_es_close(a,replaceTwoWay(n,r,i+1)),p));return addRange(r,null,i,p),new o(p)}(t,c,h,e,r))}var f=t.parent,u=f.content;return index_es_close(f,u.cut(0,t.parentOffset).append(n.content).append(u.cut(e.parentOffset)))}return index_es_close(s,replaceTwoWay(t,e,r))}(t,e,n,0)}function checkJoin(t,e){if(!e.type.compatibleContent(t.type))throw new ReplaceError("Cannot join "+e.type.name+" onto "+t.type.name)}function joinable(t,e,n){var r=t.node(n);return checkJoin(r,e.node(n)),r}function addNode(t,e){var n=e.length-1;n>=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function addRange(t,e,n,r){var o=(e||t).node(n),i=0,s=e?e.index(n):o.childCount;t&&(i=t.index(n),t.depth>n?i++:t.textOffset&&(addNode(t.nodeAfter,r),i++));for(var a=i;a<s;a++)addNode(o.child(a),r);e&&e.depth==n&&e.textOffset&&addNode(e.nodeBefore,r)}function index_es_close(t,e){if(!t.type.validContent(e))throw new ReplaceError("Invalid content for node "+t.type.name);return t.copy(e)}function replaceTwoWay(t,e,n){var r=[];(addRange(null,t,n,r),t.depth>n)&&addNode(index_es_close(joinable(t,e,n+1),replaceTwoWay(t,e,n+1)),r);return addRange(e,null,n,r),new o(r)}c.size.get=function(){return this.content.size-this.openStart-this.openEnd},p.prototype.insertAt=function insertAt(t,e){var n=function insertInto(t,e,n,r){var o=t.findIndex(e),i=o.index,s=o.offset,a=t.maybeChild(i);if(s==e||a.isText)return r&&!r.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));var p=insertInto(a.content,e-s-1,n);return p&&t.replaceChild(i,a.copy(p))}(this.content,t+this.openStart,e,null);return n&&new p(n,this.openStart,this.openEnd)},p.prototype.removeBetween=function removeBetween(t,e){return new p(function removeRange(t,e,n){var r=t.findIndex(e),o=r.index,i=r.offset,s=t.maybeChild(o),a=t.findIndex(n),p=a.index,c=a.offset;if(i==e||s.isText){if(c!=n&&!t.child(p).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(o!=p)throw new RangeError("Removing non-flat range");return t.replaceChild(o,s.copy(removeRange(s.content,e-i-1,n-i-1)))}(this.content,t+this.openStart,e+this.openStart),this.openStart,this.openEnd)},p.prototype.eq=function eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd},p.prototype.toString=function toString(){return this.content+"("+this.openStart+","+this.openEnd+")"},p.prototype.toJSON=function toJSON(){if(!this.content.size)return null;var t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t},p.fromJSON=function fromJSON(t,e){if(!e)return p.empty;var n=e.openStart||0,r=e.openEnd||0;if("number"!=typeof n||"number"!=typeof r)throw new RangeError("Invalid input for Slice.fromJSON");return new p(o.fromJSON(t,e.content),e.openStart||0,e.openEnd||0)},p.maxOpen=function maxOpen(t,e){void 0===e&&(e=!0);for(var n=0,r=0,o=t.firstChild;o&&!o.isLeaf&&(e||!o.type.spec.isolating);o=o.firstChild)n++;for(var i=t.lastChild;i&&!i.isLeaf&&(e||!i.type.spec.isolating);i=i.lastChild)r++;return new p(t,n,r)},Object.defineProperties(p.prototype,c),p.empty=new p(o.empty,0,0);var h=function ResolvedPos(t,e,n){this.pos=t,this.path=e,this.depth=e.length/3-1,this.parentOffset=n},f={parent:{configurable:!0},doc:{configurable:!0},textOffset:{configurable:!0},nodeAfter:{configurable:!0},nodeBefore:{configurable:!0}};h.prototype.resolveDepth=function resolveDepth(t){return null==t?this.depth:t<0?this.depth+t:t},f.parent.get=function(){return this.node(this.depth)},f.doc.get=function(){return this.node(0)},h.prototype.node=function node(t){return this.path[3*this.resolveDepth(t)]},h.prototype.index=function index(t){return this.path[3*this.resolveDepth(t)+1]},h.prototype.indexAfter=function indexAfter(t){return t=this.resolveDepth(t),this.index(t)+(t!=this.depth||this.textOffset?1:0)},h.prototype.start=function start(t){return 0==(t=this.resolveDepth(t))?0:this.path[3*t-1]+1},h.prototype.end=function end(t){return t=this.resolveDepth(t),this.start(t)+this.node(t).content.size},h.prototype.before=function before(t){if(!(t=this.resolveDepth(t)))throw new RangeError("There is no position before the top-level node");return t==this.depth+1?this.pos:this.path[3*t-1]},h.prototype.after=function after(t){if(!(t=this.resolveDepth(t)))throw new RangeError("There is no position after the top-level node");return t==this.depth+1?this.pos:this.path[3*t-1]+this.path[3*t].nodeSize},f.textOffset.get=function(){return this.pos-this.path[this.path.length-1]},f.nodeAfter.get=function(){var t=this.parent,e=this.index(this.depth);if(e==t.childCount)return null;var n=this.pos-this.path[this.path.length-1],r=t.child(e);return n?t.child(e).cut(n):r},f.nodeBefore.get=function(){var t=this.index(this.depth),e=this.pos-this.path[this.path.length-1];return e?this.parent.child(t).cut(0,e):0==t?null:this.parent.child(t-1)},h.prototype.marks=function marks(){var t=this.parent,e=this.index();if(0==t.content.size)return a.none;if(this.textOffset)return t.child(e).marks;var n=t.maybeChild(e-1),r=t.maybeChild(e);if(!n){var o=n;n=r,r=o}for(var marks=n.marks,i=0;i<marks.length;i++)!1!==marks[i].type.spec.inclusive||r&&marks[i].isInSet(r.marks)||(marks=marks[i--].removeFromSet(marks));return marks},h.prototype.marksAcross=function marksAcross(t){var e=this.parent.maybeChild(this.index());if(!e||!e.isInline)return null;for(var n=e.marks,r=t.parent.maybeChild(t.index()),o=0;o<n.length;o++)!1!==n[o].type.spec.inclusive||r&&n[o].isInSet(r.marks)||(n=n[o--].removeFromSet(n));return n},h.prototype.sharedDepth=function sharedDepth(t){for(var e=this.depth;e>0;e--)if(this.start(e)<=t&&this.end(e)>=t)return e;return 0},h.prototype.blockRange=function blockRange(t,e){if(void 0===t&&(t=this),t.pos<this.pos)return t.blockRange(this);for(var n=this.depth-(this.parent.inlineContent||this.pos==t.pos?1:0);n>=0;n--)if(t.pos<=this.end(n)&&(!e||e(this.node(n))))return new m(this,t,n)},h.prototype.sameParent=function sameParent(t){return this.pos-this.parentOffset==t.pos-t.parentOffset},h.prototype.max=function max(t){return t.pos>this.pos?t:this},h.prototype.min=function min(t){return t.pos<this.pos?t:this},h.prototype.toString=function toString(){for(var t="",e=1;e<=this.depth;e++)t+=(t?"/":"")+this.node(e).type.name+"_"+this.index(e-1);return t+":"+this.parentOffset},h.resolve=function resolve(t,e){if(!(e>=0&&e<=t.content.size))throw new RangeError("Position "+e+" out of range");for(var n=[],r=0,o=e,i=t;;){var s=i.content.findIndex(o),a=s.index,p=s.offset,c=o-p;if(n.push(i,a,r+p),!c)break;if((i=i.child(a)).isText)break;o=c-1,r+=p+1}return new h(e,n,o)},h.resolveCached=function resolveCached(t,e){for(var n=0;n<u.length;n++){var r=u[n];if(r.pos==e&&r.doc==t)return r}var o=u[l]=h.resolve(t,e);return l=(l+1)%d,o},Object.defineProperties(h.prototype,f);var u=[],l=0,d=12,m=function NodeRange(t,e,n){this.$from=t,this.$to=e,this.depth=n},v={start:{configurable:!0},end:{configurable:!0},parent:{configurable:!0},startIndex:{configurable:!0},endIndex:{configurable:!0}};v.start.get=function(){return this.$from.before(this.depth+1)},v.end.get=function(){return this.$to.after(this.depth+1)},v.parent.get=function(){return this.$from.node(this.depth)},v.startIndex.get=function(){return this.$from.index(this.depth)},v.endIndex.get=function(){return this.$to.indexAfter(this.depth)},Object.defineProperties(m.prototype,v);var y=Object.create(null),g=function Node(t,e,n,r){this.type=t,this.attrs=e,this.content=n||o.empty,this.marks=r||a.none},S={nodeSize:{configurable:!0},childCount:{configurable:!0},textContent:{configurable:!0},firstChild:{configurable:!0},lastChild:{configurable:!0},isBlock:{configurable:!0},isTextblock:{configurable:!0},inlineContent:{configurable:!0},isInline:{configurable:!0},isText:{configurable:!0},isLeaf:{configurable:!0},isAtom:{configurable:!0}};S.nodeSize.get=function(){return this.isLeaf?1:2+this.content.size},S.childCount.get=function(){return this.content.childCount},g.prototype.child=function child(t){return this.content.child(t)},g.prototype.maybeChild=function maybeChild(t){return this.content.maybeChild(t)},g.prototype.forEach=function forEach(t){this.content.forEach(t)},g.prototype.nodesBetween=function nodesBetween(t,e,n,r){void 0===r&&(r=0),this.content.nodesBetween(t,e,n,r,this)},g.prototype.descendants=function descendants(t){this.nodesBetween(0,this.content.size,t)},S.textContent.get=function(){return this.textBetween(0,this.content.size,"")},g.prototype.textBetween=function textBetween(t,e,n,r){return this.content.textBetween(t,e,n,r)},S.firstChild.get=function(){return this.content.firstChild},S.lastChild.get=function(){return this.content.lastChild},g.prototype.eq=function eq(t){return this==t||this.sameMarkup(t)&&this.content.eq(t.content)},g.prototype.sameMarkup=function sameMarkup(t){return this.hasMarkup(t.type,t.attrs,t.marks)},g.prototype.hasMarkup=function hasMarkup(t,e,n){return this.type==t&&compareDeep(this.attrs,e||t.defaultAttrs||y)&&a.sameSet(this.marks,n||a.none)},g.prototype.copy=function copy(t){return void 0===t&&(t=null),t==this.content?this:new this.constructor(this.type,this.attrs,t,this.marks)},g.prototype.mark=function mark(t){return t==this.marks?this:new this.constructor(this.type,this.attrs,this.content,t)},g.prototype.cut=function cut(t,e){return 0==t&&e==this.content.size?this:this.copy(this.content.cut(t,e))},g.prototype.slice=function slice(t,e,n){if(void 0===e&&(e=this.content.size),void 0===n&&(n=!1),t==e)return p.empty;var r=this.resolve(t),o=this.resolve(e),i=n?0:r.sharedDepth(e),s=r.start(i),a=r.node(i).content.cut(r.pos-s,o.pos-s);return new p(a,r.depth-i,o.depth-i)},g.prototype.replace=function replace$1(t,e,n){return replace(this.resolve(t),this.resolve(e),n)},g.prototype.nodeAt=function nodeAt(t){for(var e=this;;){var n=e.content.findIndex(t),r=n.index,o=n.offset;if(!(e=e.maybeChild(r)))return null;if(o==t||e.isText)return e;t-=o+1}},g.prototype.childAfter=function childAfter(t){var e=this.content.findIndex(t),n=e.index,r=e.offset;return{node:this.content.maybeChild(n),index:n,offset:r}},g.prototype.childBefore=function childBefore(t){if(0==t)return{node:null,index:0,offset:0};var e=this.content.findIndex(t),n=e.index,r=e.offset;if(r<t)return{node:this.content.child(n),index:n,offset:r};var o=this.content.child(n-1);return{node:o,index:n-1,offset:r-o.nodeSize}},g.prototype.resolve=function resolve(t){return h.resolveCached(this,t)},g.prototype.resolveNoCache=function resolveNoCache(t){return h.resolve(this,t)},g.prototype.rangeHasMark=function rangeHasMark(t,e,n){var r=!1;return e>t&&this.nodesBetween(t,e,(function(t){return n.isInSet(t.marks)&&(r=!0),!r})),r},S.isBlock.get=function(){return this.type.isBlock},S.isTextblock.get=function(){return this.type.isTextblock},S.inlineContent.get=function(){return this.type.inlineContent},S.isInline.get=function(){return this.type.isInline},S.isText.get=function(){return this.type.isText},S.isLeaf.get=function(){return this.type.isLeaf},S.isAtom.get=function(){return this.type.isAtom},g.prototype.toString=function toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);var t=this.type.name;return this.content.size&&(t+="("+this.content.toStringInner()+")"),wrapMarks(this.marks,t)},g.prototype.contentMatchAt=function contentMatchAt(t){var e=this.type.contentMatch.matchFragment(this.content,0,t);if(!e)throw new Error("Called contentMatchAt on a node with invalid content");return e},g.prototype.canReplace=function canReplace(t,e,n,r,i){void 0===n&&(n=o.empty),void 0===r&&(r=0),void 0===i&&(i=n.childCount);var s=this.contentMatchAt(t).matchFragment(n,r,i),a=s&&s.matchFragment(this.content,e);if(!a||!a.validEnd)return!1;for(var p=r;p<i;p++)if(!this.type.allowsMarks(n.child(p).marks))return!1;return!0},g.prototype.canReplaceWith=function canReplaceWith(t,e,n,r){if(r&&!this.type.allowsMarks(r))return!1;var o=this.contentMatchAt(t).matchType(n),i=o&&o.matchFragment(this.content,e);return!!i&&i.validEnd},g.prototype.canAppend=function canAppend(t){return t.content.size?this.canReplace(this.childCount,this.childCount,t.content):this.type.compatibleContent(t.type)},g.prototype.check=function check(){if(!this.type.validContent(this.content))throw new RangeError("Invalid content for node "+this.type.name+": "+this.content.toString().slice(0,50));this.content.forEach((function(t){return t.check()}))},g.prototype.toJSON=function toJSON(){var t={type:this.type.name};for(var e in this.attrs){t.attrs=this.attrs;break}return this.content.size&&(t.content=this.content.toJSON()),this.marks.length&&(t.marks=this.marks.map((function(t){return t.toJSON()}))),t},g.fromJSON=function fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Node.fromJSON");var n=null;if(e.marks){if(!Array.isArray(e.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=e.marks.map(t.markFromJSON)}if("text"==e.type){if("string"!=typeof e.text)throw new RangeError("Invalid text node in JSON");return t.text(e.text,n)}var r=o.fromJSON(t,e.content);return t.nodeType(e.type).create(e.attrs,r,n)},Object.defineProperties(g.prototype,S);var x=function(t){function TextNode(e,n,r,o){if(t.call(this,e,n,null,o),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}t&&(TextNode.__proto__=t),TextNode.prototype=Object.create(t&&t.prototype),TextNode.prototype.constructor=TextNode;var e={textContent:{configurable:!0},nodeSize:{configurable:!0}};return TextNode.prototype.toString=function toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):wrapMarks(this.marks,JSON.stringify(this.text))},e.textContent.get=function(){return this.text},TextNode.prototype.textBetween=function textBetween(t,e){return this.text.slice(t,e)},e.nodeSize.get=function(){return this.text.length},TextNode.prototype.mark=function mark(t){return t==this.marks?this:new TextNode(this.type,this.attrs,this.text,t)},TextNode.prototype.withText=function withText(t){return t==this.text?this:new TextNode(this.type,this.attrs,t,this.marks)},TextNode.prototype.cut=function cut(t,e){return void 0===t&&(t=0),void 0===e&&(e=this.text.length),0==t&&e==this.text.length?this:this.withText(this.text.slice(t,e))},TextNode.prototype.eq=function eq(t){return this.sameMarkup(t)&&this.text==t.text},TextNode.prototype.toJSON=function toJSON(){var e=t.prototype.toJSON.call(this);return e.text=this.text,e},Object.defineProperties(TextNode.prototype,e),TextNode}(g);function wrapMarks(t,e){for(var n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}var k=function ContentMatch(t){this.validEnd=t,this.next=[],this.wrapCache=[]},w={inlineContent:{configurable:!0},defaultType:{configurable:!0},edgeCount:{configurable:!0}};k.parse=function parse(t,e){var n=new b(t,e);if(null==n.next)return k.empty;var r=parseExpr(n);n.next&&n.err("Unexpected trailing text");var o=function dfa(t){var e=Object.create(null);return function explore(n){var r=[];n.forEach((function(e){t[e].forEach((function(e){var n=e.term,o=e.to;if(n){var i=r.indexOf(n),s=i>-1&&r[i+1];nullFrom(t,o).forEach((function(t){s||r.push(n,s=[]),-1==s.indexOf(t)&&s.push(t)}))}}))}));for(var o=e[n.join(",")]=new k(n.indexOf(t.length-1)>-1),i=0;i<r.length;i+=2){var s=r[i+1].sort(cmp);o.next.push(r[i],e[s.join(",")]||explore(s))}return o}(nullFrom(t,0))}(function nfa(t){var e=[[]];return connect(function compile(t,e){if("choice"==t.type)return t.exprs.reduce((function(t,n){return t.concat(compile(n,e))}),[]);if("seq"==t.type)for(var n=0;;n++){var r=compile(t.exprs[n],e);if(n==t.exprs.length-1)return r;connect(r,e=node())}else{if("star"==t.type){var o=node();return edge(e,o),connect(compile(t.expr,o),o),[edge(o)]}if("plus"==t.type){var i=node();return connect(compile(t.expr,e),i),connect(compile(t.expr,i),i),[edge(i)]}if("opt"==t.type)return[edge(e)].concat(compile(t.expr,e));if("range"==t.type){for(var s=e,a=0;a<t.min;a++){var p=node();connect(compile(t.expr,s),p),s=p}if(-1==t.max)connect(compile(t.expr,s),s);else for(var c=t.min;c<t.max;c++){var h=node();edge(s,h),connect(compile(t.expr,s),h),s=h}return[edge(s)]}if("name"==t.type)return[edge(e,null,t.value)]}}(t,0),node()),e;function node(){return e.push([])-1}function edge(t,n,r){var o={term:r,to:n};return e[t].push(o),o}function connect(t,e){t.forEach((function(t){return t.to=e}))}}(r));return function checkForDeadEnds(t,e){for(var n=0,r=[t];n<r.length;n++){for(var o=r[n],i=!o.validEnd,s=[],a=0;a<o.next.length;a+=2){var p=o.next[a],c=o.next[a+1];s.push(p.name),!i||p.isText||p.hasRequiredAttrs()||(i=!1),-1==r.indexOf(c)&&r.push(c)}i&&e.err("Only non-generatable nodes ("+s.join(", ")+") in a required position")}}(o,n),o},k.prototype.matchType=function matchType(t){for(var e=0;e<this.next.length;e+=2)if(this.next[e]==t)return this.next[e+1];return null},k.prototype.matchFragment=function matchFragment(t,e,n){void 0===e&&(e=0),void 0===n&&(n=t.childCount);for(var r=this,o=e;r&&o<n;o++)r=r.matchType(t.child(o).type);return r},w.inlineContent.get=function(){var t=this.next[0];return!!t&&t.isInline},w.defaultType.get=function(){for(var t=0;t<this.next.length;t+=2){var e=this.next[t];if(!e.isText&&!e.hasRequiredAttrs())return e}},k.prototype.compatible=function compatible(t){for(var e=0;e<this.next.length;e+=2)for(var n=0;n<t.next.length;n+=2)if(this.next[e]==t.next[n])return!0;return!1},k.prototype.fillBefore=function fillBefore(t,e,n){void 0===e&&(e=!1),void 0===n&&(n=0);var r=[this];return function search(i,s){var a=i.matchFragment(t,n);if(a&&(!e||a.validEnd))return o.from(s.map((function(t){return t.createAndFill()})));for(var p=0;p<i.next.length;p+=2){var c=i.next[p],h=i.next[p+1];if(!c.isText&&!c.hasRequiredAttrs()&&-1==r.indexOf(h)){r.push(h);var f=search(h,s.concat(c));if(f)return f}}}(this,[])},k.prototype.findWrapping=function findWrapping(t){for(var e=0;e<this.wrapCache.length;e+=2)if(this.wrapCache[e]==t)return this.wrapCache[e+1];var n=this.computeWrapping(t);return this.wrapCache.push(t,n),n},k.prototype.computeWrapping=function computeWrapping(t){for(var e=Object.create(null),n=[{match:this,type:null,via:null}];n.length;){var r=n.shift(),o=r.match;if(o.matchType(t)){for(var i=[],s=r;s.type;s=s.via)i.push(s.type);return i.reverse()}for(var a=0;a<o.next.length;a+=2){var p=o.next[a];p.isLeaf||p.hasRequiredAttrs()||p.name in e||r.type&&!o.next[a+1].validEnd||(n.push({match:p.contentMatch,type:p,via:r}),e[p.name]=!0)}}},w.edgeCount.get=function(){return this.next.length>>1},k.prototype.edge=function edge(t){var e=t<<1;if(e>=this.next.length)throw new RangeError("There's no "+t+"th edge in this content match");return{type:this.next[e],next:this.next[e+1]}},k.prototype.toString=function toString(){var t=[];return function scan(e){t.push(e);for(var n=1;n<e.next.length;n+=2)-1==t.indexOf(e.next[n])&&scan(e.next[n])}(this),t.map((function(e,n){for(var r=n+(e.validEnd?"*":" ")+" ",o=0;o<e.next.length;o+=2)r+=(o?", ":"")+e.next[o].name+"->"+t.indexOf(e.next[o+1]);return r})).join("\n")},Object.defineProperties(k.prototype,w),k.empty=new k(!0);var b=function TokenStream(t,e){this.string=t,this.nodeTypes=e,this.inline=null,this.pos=0,this.tokens=t.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.unshift()},O={next:{configurable:!0}};function parseExpr(t){var e=[];do{e.push(parseExprSeq(t))}while(t.eat("|"));return 1==e.length?e[0]:{type:"choice",exprs:e}}function parseExprSeq(t){var e=[];do{e.push(parseExprSubscript(t))}while(t.next&&")"!=t.next&&"|"!=t.next);return 1==e.length?e[0]:{type:"seq",exprs:e}}function parseExprSubscript(t){for(var e=function parseExprAtom(t){if(t.eat("(")){var e=parseExpr(t);return t.eat(")")||t.err("Missing closing paren"),e}if(!/\W/.test(t.next)){var n=function resolveName(t,e){var n=t.nodeTypes,r=n[e];if(r)return[r];var o=[];for(var i in n){var s=n[i];s.groups.indexOf(e)>-1&&o.push(s)}0==o.length&&t.err("No node type or group '"+e+"' found");return o}(t,t.next).map((function(e){return null==t.inline?t.inline=e.isInline:t.inline!=e.isInline&&t.err("Mixing inline and block content"),{type:"name",value:e}}));return t.pos++,1==n.length?n[0]:{type:"choice",exprs:n}}t.err("Unexpected token '"+t.next+"'")}(t);;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else{if(!t.eat("{"))break;e=parseExprRange(t,e)}return e}function parseNum(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");var e=Number(t.next);return t.pos++,e}function parseExprRange(t,e){var n=parseNum(t),r=n;return t.eat(",")&&(r="}"!=t.next?parseNum(t):-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function cmp(t,e){return e-t}function nullFrom(t,e){var n=[];return function scan(e){var r=t[e];if(1==r.length&&!r[0].term)return scan(r[0].to);n.push(e);for(var o=0;o<r.length;o++){var i=r[o],s=i.term,a=i.to;s||-1!=n.indexOf(a)||scan(a)}}(e),n.sort(cmp)}function defaultAttrs(t){var e=Object.create(null);for(var n in t){var r=t[n];if(!r.hasDefault)return null;e[n]=r.default}return e}function computeAttrs(t,e){var n=Object.create(null);for(var r in t){var o=e&&e[r];if(void 0===o){var i=t[r];if(!i.hasDefault)throw new RangeError("No value supplied for attribute "+r);o=i.default}n[r]=o}return n}function initAttrs(t){var e=Object.create(null);if(t)for(var n in t)e[n]=new E(t[n]);return e}O.next.get=function(){return this.tokens[this.pos]},b.prototype.eat=function eat(t){return this.next==t&&(this.pos++||!0)},b.prototype.err=function err(t){throw new SyntaxError(t+" (in content expression '"+this.string+"')")},Object.defineProperties(b.prototype,O);var M=function NodeType(t,e,n){this.name=t,this.schema=e,this.spec=n,this.groups=n.group?n.group.split(" "):[],this.attrs=initAttrs(n.attrs),this.defaultAttrs=defaultAttrs(this.attrs),this.contentMatch=null,this.markSet=null,this.inlineContent=null,this.isBlock=!(n.inline||"text"==t),this.isText="text"==t},N={isInline:{configurable:!0},isTextblock:{configurable:!0},isLeaf:{configurable:!0},isAtom:{configurable:!0}};N.isInline.get=function(){return!this.isBlock},N.isTextblock.get=function(){return this.isBlock&&this.inlineContent},N.isLeaf.get=function(){return this.contentMatch==k.empty},N.isAtom.get=function(){return this.isLeaf||this.spec.atom},M.prototype.hasRequiredAttrs=function hasRequiredAttrs(){for(var t in this.attrs)if(this.attrs[t].isRequired)return!0;return!1},M.prototype.compatibleContent=function compatibleContent(t){return this==t||this.contentMatch.compatible(t.contentMatch)},M.prototype.computeAttrs=function computeAttrs$1(t){return!t&&this.defaultAttrs?this.defaultAttrs:computeAttrs(this.attrs,t)},M.prototype.create=function create(t,e,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new g(this,this.computeAttrs(t),o.from(e),a.setFrom(n))},M.prototype.createChecked=function createChecked(t,e,n){if(e=o.from(e),!this.validContent(e))throw new RangeError("Invalid content for node "+this.name);return new g(this,this.computeAttrs(t),e,a.setFrom(n))},M.prototype.createAndFill=function createAndFill(t,e,n){if(t=this.computeAttrs(t),(e=o.from(e)).size){var r=this.contentMatch.fillBefore(e);if(!r)return null;e=r.append(e)}var i=this.contentMatch.matchFragment(e).fillBefore(o.empty,!0);return i?new g(this,t,e.append(i),a.setFrom(n)):null},M.prototype.validContent=function validContent(t){var e=this.contentMatch.matchFragment(t);if(!e||!e.validEnd)return!1;for(var n=0;n<t.childCount;n++)if(!this.allowsMarks(t.child(n).marks))return!1;return!0},M.prototype.allowsMarkType=function allowsMarkType(t){return null==this.markSet||this.markSet.indexOf(t)>-1},M.prototype.allowsMarks=function allowsMarks(t){if(null==this.markSet)return!0;for(var e=0;e<t.length;e++)if(!this.allowsMarkType(t[e].type))return!1;return!0},M.prototype.allowedMarks=function allowedMarks(t){if(null==this.markSet)return t;for(var e,n=0;n<t.length;n++)this.allowsMarkType(t[n].type)?e&&e.push(t[n]):e||(e=t.slice(0,n));return e?e.length?e:a.empty:t},M.compile=function compile(t,e){var n=Object.create(null);t.forEach((function(t,r){return n[t]=new M(t,e,r)}));var r=e.spec.topNode||"doc";if(!n[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(var o in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n},Object.defineProperties(M.prototype,N);var E=function Attribute(t){this.hasDefault=Object.prototype.hasOwnProperty.call(t,"default"),this.default=t.default},T={isRequired:{configurable:!0}};T.isRequired.get=function(){return!this.hasDefault},Object.defineProperties(E.prototype,T);var C=function MarkType(t,e,n,r){this.name=t,this.schema=n,this.spec=r,this.attrs=initAttrs(r.attrs),this.rank=e,this.excluded=null;var o=defaultAttrs(this.attrs);this.instance=o&&new a(this,o)};C.prototype.create=function create(t){return!t&&this.instance?this.instance:new a(this,computeAttrs(this.attrs,t))},C.compile=function compile(t,e){var n=Object.create(null),r=0;return t.forEach((function(t,o){return n[t]=new C(t,r++,e,o)})),n},C.prototype.removeFromSet=function removeFromSet(t){for(var e=0;e<t.length;e++)if(t[e].type==this)return t.slice(0,e).concat(t.slice(e+1));return t},C.prototype.isInSet=function isInSet(t){for(var e=0;e<t.length;e++)if(t[e].type==this)return t[e]},C.prototype.excludes=function excludes(t){return this.excluded.indexOf(t)>-1};var R=function Schema(t){for(var e in this.spec={},t)this.spec[e]=t[e];this.spec.nodes=r.from(t.nodes),this.spec.marks=r.from(t.marks),this.nodes=M.compile(this.spec.nodes,this),this.marks=C.compile(this.spec.marks,this);var n=Object.create(null);for(var o in this.nodes){if(o in this.marks)throw new RangeError(o+" can not be both a node and a mark");var i=this.nodes[o],s=i.spec.content||"",a=i.spec.marks;i.contentMatch=n[s]||(n[s]=k.parse(s,this.nodes)),i.inlineContent=i.contentMatch.inlineContent,i.markSet="_"==a?null:a?gatherMarks(this,a.split(" ")):""!=a&&i.inlineContent?null:[]}for(var p in this.marks){var c=this.marks[p],h=c.spec.excludes;c.excluded=null==h?[c]:""==h?[]:gatherMarks(this,h.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached=Object.create(null),this.cached.wrappings=Object.create(null)};function gatherMarks(t,e){for(var n=[],r=0;r<e.length;r++){var o=e[r],i=t.marks[o],s=i;if(i)n.push(i);else for(var a in t.marks){var p=t.marks[a];("_"==o||p.spec.group&&p.spec.group.split(" ").indexOf(o)>-1)&&n.push(s=p)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}R.prototype.node=function node(t,e,n,r){if("string"==typeof t)t=this.nodeType(t);else{if(!(t instanceof M))throw new RangeError("Invalid node type: "+t);if(t.schema!=this)throw new RangeError("Node type from different schema used ("+t.name+")")}return t.createChecked(e,n,r)},R.prototype.text=function text(t,e){var n=this.nodes.text;return new x(n,n.defaultAttrs,t,a.setFrom(e))},R.prototype.mark=function mark(t,e){return"string"==typeof t&&(t=this.marks[t]),t.create(e)},R.prototype.nodeFromJSON=function nodeFromJSON(t){return g.fromJSON(this,t)},R.prototype.markFromJSON=function markFromJSON(t){return a.fromJSON(this,t)},R.prototype.nodeType=function nodeType(t){var e=this.nodes[t];if(!e)throw new RangeError("Unknown node type: "+t);return e};var _=function DOMParser(t,e){var n=this;this.schema=t,this.rules=e,this.tags=[],this.styles=[],e.forEach((function(t){t.tag?n.tags.push(t):t.style&&n.styles.push(t)}))};_.prototype.parse=function parse(t,e){void 0===e&&(e={});var n=new P(this,e,!1);return n.addAll(t,null,e.from,e.to),n.finish()},_.prototype.parseSlice=function parseSlice(t,e){void 0===e&&(e={});var n=new P(this,e,!0);return n.addAll(t,null,e.from,e.to),p.maxOpen(n.finish())},_.prototype.matchTag=function matchTag(t,e){for(var n=0;n<this.tags.length;n++){var r=this.tags[n];if(matches(t,r.tag)&&(void 0===r.namespace||t.namespaceURI==r.namespace)&&(!r.context||e.matchesContext(r.context))){if(r.getAttrs){var o=r.getAttrs(t);if(!1===o)continue;r.attrs=o}return r}}},_.prototype.matchStyle=function matchStyle(t,e,n){for(var r=0;r<this.styles.length;r++){var o=this.styles[r];if(!(0!=o.style.indexOf(t)||o.context&&!n.matchesContext(o.context)||o.style.length>t.length&&(61!=o.style.charCodeAt(t.length)||o.style.slice(t.length+1)!=e))){if(o.getAttrs){var i=o.getAttrs(e);if(!1===i)continue;o.attrs=i}return o}}},_.schemaRules=function schemaRules(t){var e=[];function insert(t){for(var n=null==t.priority?50:t.priority,r=0;r<e.length;r++){var o=e[r];if((null==o.priority?50:o.priority)<n)break}e.splice(r,0,t)}var loop=function(e){var n=t.marks[e].spec.parseDOM;n&&n.forEach((function(t){insert(t=copy(t)),t.mark=e}))};for(var n in t.marks)loop(n);var r;for(var o in t.nodes)r=void 0,(r=t.nodes[o].spec.parseDOM)&&r.forEach((function(t){insert(t=copy(t)),t.node=o}));return e},_.fromSchema=function fromSchema(t){return t.cached.domParser||(t.cached.domParser=new _(t,_.schemaRules(t)))};var A={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},z={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},J={ol:!0,ul:!0};function wsOptionsFor(t){return(t?1:0)|("full"===t?2:0)}var I=function NodeContext(t,e,n,r,o,i,s){this.type=t,this.attrs=e,this.solid=o,this.match=i||(4&s?null:t.contentMatch),this.options=s,this.content=[],this.marks=n,this.activeMarks=a.none,this.pendingMarks=r};I.prototype.findWrapping=function findWrapping(t){if(!this.match){if(!this.type)return[];var e=this.type.contentMatch.fillBefore(o.from(t));if(!e){var n,r=this.type.contentMatch;return(n=r.findWra