UNPKG

wed

Version:

Wed is a schema-aware editor for XML documents.

108 lines (106 loc) 249 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.salve=t():e.salve=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=23)}([function(e,t,n){"use strict"; /** * Classes that model RNG patterns. * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */Object.defineProperty(t,"__esModule",{value:!0});n(4).__importStar(n(25));class r{constructor(e,t,n){this.matched=e,this.errors=t,this.refs=n}static fromEndResult(e){return!1===e?new r(!0):new r(!1,e)}combine(e){let t,n;if(this.matched){n=this.refs;const t=e.refs;void 0!==t&&(n=void 0===n?t:n.concat(t))}else{t=this.errors;const n=e.errors;void 0!==n&&(t=void 0===t?n:t.concat(n))}return new r(this.matched,t,n)}}t.InternalFireEventResult=r;class a{constructor(e){this.xmlPath=e}_prepare(e,t){}hasAttrs(){return!1}hasEmptyPattern(){return!1}}t.BasePattern=a;class d extends a{newWalker(){throw new Error("derived classes must override this")}}t.Pattern=d;t.OneSubpattern=class extends d{constructor(e,t){super(e),this.pat=t}_prepare(e,t){const n=this.pat._prepare(e,t);return this._cachedHasAttrs=this.pat.hasAttrs(),this._cachedHasEmptyPattern=this._computeHasEmptyPattern(),n}hasAttrs(){return this._cachedHasAttrs}hasEmptyPattern(){return this._cachedHasEmptyPattern}};t.TwoSubpatterns=class extends d{constructor(e,t,n){super(e),this.patA=t,this.patB=n}_prepare(e,t){const n=this.patA._prepare(e,t),r=this.patB._prepare(e,t);return this._cachedHasAttrs=this.patA.hasAttrs()||this.patB.hasAttrs(),this._cachedHasEmptyPattern=this._computeHasEmptyPattern(),void 0!==n?void 0===r?n:n.concat(r):r}hasAttrs(){return this._cachedHasAttrs}hasEmptyPattern(){return this._cachedHasEmptyPattern}};t.Event=class{constructor(...e){const t=1===e.length&&e[0]instanceof Array?e[0]:e;this.params=t,this.isAttributeEvent="attributeName"===this.params[0]||"attributeValue"===this.params[0]||"attributeNameAndValue"===this.params[0]}toString(){return`Event: ${this.params.join(", ")}`}},t.isAttributeEvent=function(e){return"attributeName"===e||"attributeValue"===e||"attributeNameAndValue"===e},t.eventsToTreeString=function(e){const t=e instanceof Set?Array.from(e):e,n=new Map;return t.forEach(e=>{const t=e.params;let r=n;const a=t.length-1;for(let n=0;n<t.length;++n){const e=t[n].toString();if(n===a)r.set(e,!1);else{let t=r.get(e);void 0===t&&(t=new Map,r.set(e,t)),r=t}}}),function e(t,n){let r="";const a=Array.from(t.keys());a.sort();for(const d of a){const a=t.get(d);!1!==a?(r+=`${n}${d}:\n`,r+=e(a,`${n} `)):r+=`${n}${d}\n`}return r}(n,"")}},function(e,t,n){"use strict"; /** * This module contains classes for a conversion parser. * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */Object.defineProperty(t,"__esModule",{value:!0});const r=n(16),a=n(9),d=n(18),u=n(7),s=n(5);class i{get parent(){return this._parent}set parent(e){this.setParent(e)}setParent(e){this._parent=e}remove(){const e=this.parent;void 0!==e&&e.removeChild(this)}replaceWith(e){const t=this.parent;if(void 0===t)throw new Error("no parent");t.replaceChildWith(this,e)}}t.Node=i;const o=Object.create(null);class c extends i{constructor(e,t,n,r,a,d=[]){super(),this.children=d,this.kind="element",this.prefix=e,this.local=t,this.uri=n,this.ns=r,this.attributes=a;for(const u of d)u.parent=this}static fromSax(e,t){return new c(e.prefix,e.local,e.uri,e.ns,e.attributes,t)}static makeElement(e){return new c("",e,"",o,Object.create(null))}setParent(e){this._path=void 0,this._parent=e}resolve(e){return"xml"===e?d.XML1_NAMESPACE:"xmlns"===e?d.XMLNS_NAMESPACE:this._resolve(e)}_resolve(e){const t=this.ns[e];return void 0!==t?t:void 0===this.parent?void 0:this.parent._resolve(e)}get text(){return this.children.map(e=>e.text).join("")}get path(){return void 0===this._path&&(this._path=this.makePath()),this._path}makePath(){let e=`${void 0!==this.parent?this.parent.path:""}/${this.local}`;const t=this.getAttribute("name");if(void 0!==t)e+=`[@name='${t}']`;else if("element"===this.local||"attribute"===this.local){const t=this.children[0];f(t)&&"name"===t.local&&(e+=`[@name='${t.text}']`)}return e}removeChild(e){this.children.splice(this.indexOfChild(e),1)[0].parent=void 0}removeChildAt(e){this.children.splice(e,1)[0].parent=void 0}replaceChildWith(e,t){this.replaceChildAt(this.indexOfChild(e),t)}replaceChildAt(e,t){const n=this.children[e];void 0!==t.parent&&t.parent.removeChild(t),this.children[e]=t,n.parent=void 0,t.parent=this}appendChild(e){void 0!==e.parent&&e.parent.removeChild(e),e.parent=this,this.children.push(e)}appendChildren(e){for(const t of e)void 0!==t.parent&&t.parent.removeChild(t),t.parent=this;this.children.push(...e)}prependChild(e){void 0!==e.parent&&e.parent.removeChild(e),e.parent=this,this.children.unshift(e)}insertAt(e,t){for(const n of t)void 0!==n.parent&&n.parent.removeChild(n),n.parent=this;this.children.splice(e,0,...t)}empty(){const e=this.children.splice(0,this.children.length);for(const t of e)t.parent=void 0}grabChildren(e){const t=e.children.splice(0,e.children.length);this.children.push(...t);for(const n of t)n.parent=this}replaceContent(e){const t=this.children.splice(0,this.children.length,...e);for(const n of t)n.parent=void 0;for(const n of e)n.parent=this}indexOfChild(e){const t=e.parent;if(t!==this)throw new Error("the child is not a child of this");const n=t.children.indexOf(e);if(-1===n)throw new Error("child not among children");return n}setAttribute(e,t){if(e.includes(":"))throw new Error("we don't support namespaces on this function");this.attributes[e]={name:e,prefix:"",local:e,uri:"",value:t}}setXMLNS(e){this.attributes.xmlns={name:"xmlns",prefix:"",uri:d.XMLNS_NAMESPACE,value:e,local:"xmlns"}}removeAttribute(e){delete this.attributes[e]}getAttribute(e){const t=this.attributes[e];return void 0!==t?t.value:void 0}getRawAttributes(){return this.attributes}mustGetAttribute(e){const t=this.getAttribute(e);if(void 0===t)throw new Error(`no attribute named ${e}`);return t}clone(){const e=Object.assign(Object.create(null),this.attributes);for(const t of Object.keys(e))e[t]=Object.assign({},e[t]);return new c(this.prefix,this.local,this.uri,this.ns,e,this.children.map(e=>e.clone()))}}t.Element=c;class l extends i{constructor(e){super(),this.text=e,this.kind="text"}clone(){return new l(this.text)}}function f(e){return"element"===e.kind}t.Text=l,t.isElement=f,t.isText=function(e){return"text"===e.kind};class h{constructor(e){this.saxesParser=e}resolveName(e,t=!1){const n=e.indexOf(":");let r,d;if(-1===n){if(t)return new a.EName("",e);r="",d=e}else if(r=e.substring(0,n),(d=e.substring(n+1)).includes(":"))throw new Error("invalid name passed to resolveName");const u=this.saxesParser.resolve(r);return void 0!==u?new a.EName(u,d):""===r?new a.EName("",d):void 0}clone(){throw new Error("cannot clone a SaxesNameResolver")}}t.Validator=class{constructor(e,t){this.errors=[],this.walker=e.newWalker(new h(t))}fireEvent(e,t){const n=this.walker.fireEvent(e,t);n&&this.errors.push(...n)}onopentag(e){const{attributes:t}=e,n=[e.uri,e.local];for(const r of Object.keys(t)){const{uri:e,prefix:a,local:d,value:u}=t[r];"xmlns"!==r&&"xmlns"!==a&&n.push(e,d,u)}this.fireEvent("startTagAndAttributes",n)}onclosetag(e){this.fireEvent("endTag",[e.uri,e.local])}ontext(e){this.fireEvent("text",[e])}};class m{onopentag(){}onclosetag(){}ontext(){}}class p{constructor(e,t=new m){this.saxesParser=e,this.validator=t,this.drop=0,e.onopentag=this.onopentag.bind(this),e.onclosetag=this.onclosetag.bind(this),e.ontext=this.ontext.bind(this),this.stack=[{node:void 0,children:[]}]}get root(){return this.stack[0].children.filter(f)[0]}onopentag(e){this.validator.onopentag(e),e.uri===s.RELAXNG_URI&&0===this.drop?this.stack.push({node:e,children:[]}):this.drop++}onclosetag(e){if(this.validator.onclosetag(e),0!==this.drop)return void this.drop--;const{node:t,children:n}=this.stack.pop();this.stack[this.stack.length-1].children.push(c.fromSax(t,n))}ontext(e){this.validator.ontext(e),0===this.drop&&this.stack[this.stack.length-1].children.push(new l(e))}}t.BasicParser=p;class b extends p{onopentag(e){if("http://relaxng.org/ns/structure/1.0"!==e.uri)throw new Error(`node in unexpected namespace: ${e.uri}`);super.onopentag(e)}ontext(e){if(this.stack.length<=1||0!==this.drop)return;const t=this.stack[this.stack.length-1].node.local;("param"===t||"value"===t||""!==e.trim())&&super.ontext(e)}}t.parseSimplifiedSchema=function(e,t){const n=new b(new r.SaxesParser({xmlns:!0,position:!1,fileName:e}));return n.saxesParser.write(t).close(),n.root};class g extends Error{constructor(){super(),u.fixPrototype(this,g)}}class w{constructor(e){this.saxesParser=e,e.onopentag=this.onopentag.bind(this)}onopentag(e){if("http://relaxng.org/ns/structure/1.0"===e.uri&&("include"===e.local||"externalRef"===e.local))throw new g}}t.dependsOnExternalFile=function(e){const t=new w(new r.SaxesParser({xmlns:!0,position:!1}));let n=!1;try{t.saxesParser.write(e).close()}catch(e){if(!(e instanceof g))throw e;n=!0}return n}},function(e,t,n){"use strict"; /** * Validation errors. * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */Object.defineProperty(t,"__esModule",{value:!0});class r{constructor(e){this.msg=e}toString(){return this.toStringWithNames(this.getNames())}getNames(){return[]}toStringWithNames(e){return this.msg}equals(e){return this===e||this.toString()===e.toString()}}t.ValidationError=r;class a extends r{constructor(e,t){super(e),this.name=t}getNames(){return[this.name]}toStringWithNames(e){return`${this.msg}: ${e[0].toString()}`}}t.SingleNameError=a;t.AttributeNameError=class extends a{};t.AttributeValueError=class extends a{};t.ElementNameError=class extends a{};t.ChoiceError=class extends r{constructor(e,t){super(""),this.namesA=e,this.namesB=t}getNames(){return this.namesA.concat(this.namesB)}toStringWithNames(e){const t=e.slice(0,this.namesA.length),n=e.slice(this.namesA.length);return`must choose either ${t.join(", ")} or ${n.join(", ")}`}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=n(7);class a extends Error{constructor(e){super();const t=new Error(e);this.name="SchemaValidationError",this.stack=t.stack,this.message=t.message,r.fixPrototype(this,a)}}t.SchemaValidationError=a;const d=Object.create(null);t.getAvailableValidators=function(){return Object.keys(d)},t.isValidatorAvailable=function(e){return void 0!==d[e]},t.registerValidator=function(e,t){d[e]=t},t.makeValidator=function(e,t){const n=d[e];if(void 0===n)throw new Error(`unknown validator name: ${e}`);return new n(t)}},function(e,t,n){"use strict";n.r(t),n.d(t,"__extends",function(){return a}),n.d(t,"__assign",function(){return d}),n.d(t,"__rest",function(){return u}),n.d(t,"__decorate",function(){return s}),n.d(t,"__param",function(){return i}),n.d(t,"__metadata",function(){return o}),n.d(t,"__awaiter",function(){return c}),n.d(t,"__generator",function(){return l}),n.d(t,"__exportStar",function(){return f}),n.d(t,"__values",function(){return h}),n.d(t,"__read",function(){return m}),n.d(t,"__spread",function(){return p}),n.d(t,"__await",function(){return b}),n.d(t,"__asyncGenerator",function(){return g}),n.d(t,"__asyncDelegator",function(){return w}),n.d(t,"__asyncValues",function(){return v}),n.d(t,"__makeTemplateObject",function(){return y}),n.d(t,"__importStar",function(){return x}),n.d(t,"__importDefault",function(){return E}); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function a(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var d=function(){return(d=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function u(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(r=Object.getOwnPropertySymbols(e);a<r.length;a++)t.indexOf(r[a])<0&&(n[r[a]]=e[r[a]])}return n}function s(e,t,n,r){var a,d=arguments.length,u=d<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(u=(d<3?a(u):d>3?a(t,n,u):a(t,n))||u);return d>3&&u&&Object.defineProperty(t,n,u),u}function i(e,t){return function(n,r){t(n,r,e)}}function o(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function c(e,t,n,r){return new(n||(n=Promise))(function(a,d){function u(e){try{i(r.next(e))}catch(e){d(e)}}function s(e){try{i(r.throw(e))}catch(e){d(e)}}function i(e){e.done?a(e.value):new n(function(t){t(e.value)}).then(u,s)}i((r=r.apply(e,t||[])).next())})}function l(e,t){var n,r,a,d,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return d={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(d[Symbol.iterator]=function(){return this}),d;function s(d){return function(s){return function(d){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(a=2&d[0]?r.return:d[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,d[1])).done)return a;switch(r=0,a&&(d=[2&d[0],a.value]),d[0]){case 0:case 1:a=d;break;case 4:return u.label++,{value:d[1],done:!1};case 5:u.label++,r=d[1],d=[0];continue;case 7:d=u.ops.pop(),u.trys.pop();continue;default:if(!(a=(a=u.trys).length>0&&a[a.length-1])&&(6===d[0]||2===d[0])){u=0;continue}if(3===d[0]&&(!a||d[1]>a[0]&&d[1]<a[3])){u.label=d[1];break}if(6===d[0]&&u.label<a[1]){u.label=a[1],a=d;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(d);break}a[2]&&u.ops.pop(),u.trys.pop();continue}d=t.call(e,u)}catch(e){d=[6,e],r=0}finally{n=a=0}if(5&d[0])throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}([d,s])}}}function f(e,t){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}function h(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}function m(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,a,d=n.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(r=d.next()).done;)u.push(r.value)}catch(e){a={error:e}}finally{try{r&&!r.done&&(n=d.return)&&n.call(d)}finally{if(a)throw a.error}}return u}function p(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(m(arguments[t]));return e}function b(e){return this instanceof b?(this.v=e,this):new b(e)}function g(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,a=n.apply(e,t||[]),d=[];return r={},u("next"),u("throw"),u("return"),r[Symbol.asyncIterator]=function(){return this},r;function u(e){a[e]&&(r[e]=function(t){return new Promise(function(n,r){d.push([e,t,n,r])>1||s(e,t)})})}function s(e,t){try{(n=a[e](t)).value instanceof b?Promise.resolve(n.value.v).then(i,o):c(d[0][2],n)}catch(e){c(d[0][3],e)}var n}function i(e){s("next",e)}function o(e){s("throw",e)}function c(e,t){e(t),d.shift(),d.length&&s(d[0][0],d[0][1])}}function w(e){var t,n;return t={},r("next"),r("throw",function(e){throw e}),r("return"),t[Symbol.iterator]=function(){return this},t;function r(r,a){t[r]=e[r]?function(t){return(n=!n)?{value:b(e[r](t)),done:"return"===r}:a?a(t):t}:a}}function v(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=h(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise(function(r,a){(function(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)})(r,a,(t=e[n](t)).done,t.value)})}}}function y(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function x(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function E(e){return e&&e.__esModule?e:{default:e}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}); /** * Utilities for simplification support for trees produced by the parser module. * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright 2013, 2014 Mangalam Research Center for Buddhist Languages */ const r=n(1);function a(e,t,n){for(const d of e.children)r.isElement(d)&&(d.local===t&&n.push(d),a(d,t,n))}function d(e,t){const n=Object.create(null);for(const r of t)n[r]=[];return function e(t,n,a){for(const d of t.children){if(!r.isElement(d))continue;const t=d.local;n.includes(t)&&a[t].push(d),e(d,n,a)}}(e,t,n),n}t.RELAXNG_URI="http://relaxng.org/ns/structure/1.0",t.findChildrenByLocalName=function(e,t){return e.children.filter(e=>r.isElement(e)&&e.local===t)},t.findDescendantsByLocalName=function(e,t){const n=[];return a(e,t,n),n},t._findDescendantsByLocalName=a,t.findMultiDescendantsByLocalName=d,t.findMultiNames=function(e,t){const n=e.children[0],r=d(n,t),a=n.local;return t.includes(a)&&(a in r?r[a].unshift(n):r[a]=[n]),r},t.indexBy=function(e,t){const n=new Map;for(const r of e)n.set(t(r),r);return n},t.groupBy=function(e,t){const n=new Map;for(const r of e){const e=t(r);let a=n.get(e);void 0===a&&(a=[],n.set(e,a)),a.push(r)}return n},t.getName=function(e){return e.mustGetAttribute("name")},t.removeUnreferencedDefs=function(e,t){const n=e.children;for(let r=1;r<n.length;++r)t.has(n[r].mustGetAttribute("name"))||(e.removeChildAt(r),--r)}},function(e,t,n){"use strict"; /** * Set utilities. * * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages * @private */Object.defineProperty(t,"__esModule",{value:!0}),t.union=function(e,t){for(const n of t)e.add(n)},t.filter=function(e,t){const n=new e.constructor;let r=0;for(const a of e)t(a,r++,e)&&n.add(a);return n},t.map=function(e,t){const n=new e.constructor;let r=0;for(const a of e){const d=t(a,r++,e);void 0!==d&&n.add(d)}return n}},function(e,t,n){"use strict"; /** * Common tools for salve. * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */Object.defineProperty(t,"__esModule",{value:!0}),t.fixPrototype=function(e,t){(void 0!==Object.getPrototypeOf?Object.getPrototypeOf(e):e.__proto__)!==t&&(void 0!==Object.setPrototypeOf?Object.setPrototypeOf(e,t.prototype):e.__proto__=t.prototype)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}); /** * Classes that model RNG patterns. * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */ var r=n(9);t.EName=r.EName;var a=n(24);t.Attribute=a.Attribute;var d=n(26);t.Choice=d.Choice;var u=n(27);t.Data=u.Data;var s=n(37);t.Define=s.Define;var i=n(38);t.Element=i.Element;var o=n(13);t.Empty=o.Empty;var c=n(39);t.Group=c.Group;var l=n(40);t.Interleave=l.Interleave;var f=n(41);t.List=f.List;var h=n(42);t.NotAllowed=h.NotAllowed;var m=n(43);t.OneOrMore=m.OneOrMore;var p=n(44);t.Param=p.Param;var b=n(45);t.Text=b.Text;var g=n(46);t.Value=g.Value;var w=n(47);t.Ref=w.Ref;var v=n(11);t.Name=v.Name,t.NameChoice=v.NameChoice,t.NsName=v.NsName,t.AnyName=v.AnyName;var y=n(0);t.eventsToTreeString=y.eventsToTreeString,t.Event=y.Event,t.BasePattern=y.BasePattern,t.Pattern=y.Pattern;var x=n(48);t.Grammar=x.Grammar,t.GrammarWalker=x.GrammarWalker,t.RefError=x.RefError},function(e,t,n){"use strict"; /** * Class for XML Expanded Names. * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */Object.defineProperty(t,"__esModule",{value:!0});t.EName=class{constructor(e,t){this.ns=e,this.name=t}toString(){return`{${this.ns}}${this.name}`}equal(e){return this.ns===e.ns&&this.name===e.name}}},function(e,t,n){"use strict"; /** * Classes that model datatypes used in RNG schemas. * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages * */Object.defineProperty(t,"__esModule",{value:!0});const r=n(28),a=n(29);class d{constructor(){this.libraries=Object.create(null)}add(e){const t=e.uri;if(t in this.libraries)throw new Error(`URI clash: ${t}`);this.libraries[t]=e}find(e){return this.libraries[e]}get(e){const t=this.find(e);if(void 0===t)throw new Error(`can't get library with URI: ${e}`);return t}}t.Registry=d,t.registry=new d,t.registry.add(r.builtin),t.registry.add(a.xmlschema);var u=n(12);t.ParameterParsingError=u.ParameterParsingError,t.ValueValidationError=u.ValueValidationError,t.ValueError=u.ValueError},function(e,t,n){"use strict"; /** * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */function r(e){return e.replace(/(["\\])/g,"\\$1")}Object.defineProperty(t,"__esModule",{value:!0});class a{constructor(e){this.path=e}getNamespaces(){const e=new Set;return this._recordNamespaces(e,!0),Array.from(e)}toJSON(){return this.toObject()}toString(){return void 0===this._asString&&(this._asString=this.asString()),this._asString}}t.Base=a;class d extends a{constructor(e,t,n){super(e),this.ns=t,this.name=n}match(e,t){return this.name===t&&this.ns===e}intersects(e){return e instanceof d?this.match(e.ns,e.name):e.intersects(this)}intersection(e){return 0===e?0:e instanceof d?this.match(e.ns,e.name)?this:0:e.intersection(this)}wildcardMatch(e,t){return!1}toObject(){return{ns:this.ns,name:this.name}}asString(){return`{"ns":"${r(this.ns)}","name":"${this.name}"}`}simple(){return!0}toArray(){return[this]}_recordNamespaces(e,t){(""!==this.ns||t)&&e.add(this.ns)}}t.Name=d;class u extends a{constructor(e,t,n){super(e),this.a=t,this.b=n}static makeTree(e){if(0===e.length)throw new Error("trying to make a tree out of nothing");let t;if(e.length>1){let n=new u("",e[0],e[1]);for(let t=2;t<e.length;t++)n=new u("",n,e[t]);t=n}else t=e[0];return t}match(e,t){return this.a.match(e,t)||this.b.match(e,t)}intersects(e){return this.a.intersects(e)||this.b.intersects(e)}intersection(e){if(0===e)return 0;const t=this.a.intersection(e),n=this.b.intersection(e);return 0!==t&&0!==n?new u("",t,n):0!==t?t:0!==n?n:0}applyRecursively(e){const{a:t,b:n}=this,r=t instanceof u?t.applyRecursively(e):e(t),a=n instanceof u?n.applyRecursively(e):e(n);return 0!==r&&0!==a?new u(this.path,r,a):0!==r?r:0!==a?a:0}wildcardMatch(e,t){return this.a.wildcardMatch(e,t)||this.b.wildcardMatch(e,t)}toObject(){return{a:this.a.toObject(),b:this.b.toObject()}}asString(){return`{"a":${this.a.toString()},"b":${this.b.toString()}}`}simple(){return this.a.simple()&&this.b.simple()}toArray(){const e=this.a.toArray();if(null===e)return null;const t=this.b.toArray();return null===t?null:e.concat(t)}_recordNamespaces(e,t){this.a._recordNamespaces(e,t),this.b._recordNamespaces(e,t)}}t.NameChoice=u;class s extends a{constructor(e,t,n){super(e),this.ns=t,this.except=n}match(e,t){return this.ns===e&&!(void 0!==this.except&&this.except.match(e,t))}intersects(e){return e instanceof d?this.ns===e.ns&&(void 0===this.except||!e.intersects(this.except)):e instanceof s?this.ns===e.ns:e.intersects(this)}intersection(e){if(0===e)return 0;if(e instanceof d)return this.ns!==e.ns?0:void 0!==this.except?0===e.intersection(this.except)?e:0:e;if(e instanceof s){if(this.ns!==e.ns)return 0;if(void 0!==this.except&&void 0!==e.except){const t=this.except.toArray(),n=e.except.toArray();if(null===t||null===n)throw new Error("complex pattern found in NsName except");const r=t.concat(n).reduce((e,t)=>(e.set(`{${t.ns}}${t.name}`,t),e),new Map),a=Array.from(r.values());return new s(this.path,this.ns,u.makeTree(a))}return void 0!==e.except?e:this}return e.intersection(this)}subtract(e){if(e instanceof u)return e.applyRecursively(e=>{if(!(e instanceof d||e instanceof s))throw new Error("child is not Name or NsName");return this.subtract(e)});if(this.ns!==e.ns)return this;if(e instanceof d)return new s(this.path,this.ns,void 0===this.except?e:new u(this.path,this.except,e));if(void 0===e.except)return 0;if(void 0===this.except)return e.except;const t=this.except.toArray(),n=e.except.toArray();if(null===t||null===n)throw new Error("NsName contains an except pattern which is not simple.");const r=n.filter(e=>!t.some(t=>e.ns===t.ns&&e.name===t.name));return 0===r.length?0:u.makeTree(r)}wildcardMatch(e,t){return this.match(e,t)}toObject(){const e={ns:this.ns};return void 0!==this.except&&(e.except=this.except.toObject()),e}asString(){const e=void 0===this.except?"":`,"except":${this.except.toString()}`;return`{"ns":"${r(this.ns)}"${e}}`}simple(){return!1}toArray(){return null}_recordNamespaces(e,t){(""!==this.ns||t)&&e.add(this.ns),void 0!==this.except&&e.add("::except")}}t.NsName=s;class i extends a{constructor(e,t){super(e),this.except=t}match(e,t){return void 0===this.except||!this.except.match(e,t)}intersects(e){if(void 0===this.except||e instanceof i)return!0;if(e instanceof d)return!this.except.intersects(e);if(e instanceof s){const t=this.except.intersection(e);if(0===t)return!0;if(t instanceof d||t instanceof s||t instanceof u)return 0!==e.subtract(t);throw new Error("negation should be 0, Name, NsName or NameChoice")}throw new Error("cannot compute intersection!")}intersection(e){if(0===e)return 0;if(void 0===this.except)return e;if(e instanceof d)return 0===this.except.intersection(e)?e:0;if(e instanceof s){const t=this.except.intersection(e);if(0===t)return e;if(t instanceof d||t instanceof s||t instanceof u)return e.subtract(t);throw new Error("negation should be 0, Name, NsName or NameChoice")}if(e instanceof i)return void 0!==e.except&&void 0!==this.except?new i(this.path,new u(this.path,this.except,e.except)):void 0!==e.except?e:this;throw new Error("cannot compute intersection!")}wildcardMatch(e,t){return this.match(e,t)}toObject(){const e={pattern:"AnyName"};return void 0!==this.except&&(e.except=this.except.toObject()),e}asString(){return`{"pattern":"AnyName"${void 0===this.except?"":`,"except":${this.except.toString()}`}}`}simple(){return!1}toArray(){return null}_recordNamespaces(e,t){e.add("*"),void 0!==this.except&&e.add("::except")}}t.AnyName=i},function(e,t,n){"use strict"; /** * Errors that can be raised during parsing of types. * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */Object.defineProperty(t,"__esModule",{value:!0});const r=n(7);t.ParamError=class{constructor(e){this.message=e}toString(){return this.message}};t.ValueError=class{constructor(e){this.message=e}toString(){return this.message}};class a extends Error{constructor(e,t){super(),this.errors=t;const n=`${e}: ${t.map(e=>e.toString()).join("\n")}`,d=new Error(n);this.name="ParameterParsingError",this.stack=d.stack,this.message=d.message,r.fixPrototype(this,a)}}t.ParameterParsingError=a;class d extends Error{constructor(e,t){super(),this.errors=t;const n=`${e}: ${t.map(e=>e.toString()).join("\n")}`,a=new Error(n);this.name="ValueValidationError",this.stack=a.stack,this.message=a.message,r.fixPrototype(this,d)}}t.ValueValidationError=d},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}); /** * Pattern and walker for RNG's ``empty`` elements. * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */ const r=n(0);class a extends r.Pattern{hasEmptyPattern(){return!0}newWalker(){return d}}t.Empty=a;const d=new class{constructor(e){this.el=e,this.canEnd=!0,this.canEndAttribute=!0}clone(){return this}possible(){return new Set}possibleAttributes(){return new Set}fireEvent(e,t){return new r.InternalFireEventResult("text"===e&&!/\S/.test(t[0]))}end(){return!1}endAttributes(){return!1}}(new a("FAKE ELEMENT"))},function(e,t,n){"use strict"; /** * Collection of constants that model the way XML refers to various * characters and groups of characters. This module is essentially private to * salve. * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */Object.defineProperty(t,"__esModule",{value:!0});t.xmlLetter="A-Z_a-zÀ-ÖØ-öø-ÿĀ-ıĴ-ľŁ-ňŊ-žƀ-ǃǍ-ǰǴ-ǵǺ-ȗɐ-ʨʻ-ˁΆΈ-ΊΌΎ-ΡΣ-ώϐ-ϖϚϜϞϠϢ-ϳЁ-ЌЎ-яё-ќў-ҁҐ-ӄӇ-ӈӋ-ӌӐ-ӫӮ-ӵӸ-ӹԱ-Ֆՙա-ֆא-תװ-ײء-غف-يٱ-ڷں-ھۀ-ێې-ۓەۥ-ۦअ-हऽक़-ॡঅ-ঌএ-ঐও-নপ-রলশ-হড়-ঢ়য়-ৡৰ-ৱਅ-ਊਏ-ਐਓ-ਨਪ-ਰਲ-ਲ਼ਵ-ਸ਼ਸ-ਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઋઍએ-ઑઓ-નપ-રલ-ળવ-હઽૠଅ-ଌଏ-ଐଓ-ନପ-ରଲ-ଳଶ-ହଽଡ଼-ଢ଼ୟ-ୡஅ-ஊஎ-ஐஒ-கங-சஜஞ-டண-தந-பம-வஷ-ஹఅ-ఌఎ-ఐఒ-నప-ళవ-హౠ-ౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹೞೠ-ೡഅ-ഌഎ-ഐഒ-നപ-ഹൠ-ൡก-ฮะา-ำเ-ๅກ-ຂຄງ-ຈຊຍດ-ທນ-ຟມ-ຣລວສ-ຫອ-ຮະາ-ຳຽເ-ໄཀ-ཇཉ-ཀྵႠ-Ⴥა-ჶᄀᄂ-ᄃᄅ-ᄇᄉᄋ-ᄌᄎ-ᄒᄼᄾᅀᅌᅎᅐᅔ-ᅕᅙᅟ-ᅡᅣᅥᅧᅩᅭ-ᅮᅲ-ᅳᅵᆞᆨᆫᆮ-ᆯᆷ-ᆸᆺᆼ-ᇂᇫᇰᇹḀ-ẛẠ-ỹἀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼΩK-Å℮ↀ-ↂぁ-ゔァ-ヺㄅ-ㄬ가-힣一-龥〇〡-〩";const r="0-9٠-٩۰-۹०-९০-৯੦-੯૦-૯୦-୯௧-௯౦-౯೦-೯൦-൯๐-๙໐-໙༠-༩",a="̀-͠ͅ-҃͡-֑҆-֣֡-ֹֻ-ֽֿׁ-ׂًׄ-ْٰۖ-ۜ۝-۟۠-ۤۧ-۪ۨ-ۭँ-ः़ा-ौ्॑-॔ॢ-ॣঁ-ঃ়ািী-ৄে-ৈো-্ৗৢ-ৣਂ਼ਾਿੀ-ੂੇ-ੈੋ-੍ੰ-ੱઁ-ઃ઼ા-ૅે-ૉો-્ଁ-ଃ଼ା-ୃେ-ୈୋ-୍ୖ-ୗஂ-ஃா-ூெ-ைொ-்ௗఁ-ఃా-ౄె-ైొ-్ౕ-ౖಂ-ಃಾ-ೄೆ-ೈೊ-್ೕ-ೖം-ഃാ-ൃെ-ൈൊ-്ൗัิ-ฺ็-๎ັິ-ູົ-ຼ່-ໍ༘-༹༙༵༷༾༿ཱ-྄྆-ྋྐ-ྕྗྙ-ྭྱ-ྷྐྵ⃐-〪⃜⃡-゙゚〯";t.xmlNameChar=`-${t.xmlLetter}${r}._:${a}·ːˑ·ـๆໆ々〱-〵ゝ-ゞー-ヾ`;const d=`[${t.xmlLetter}_:](?:[${t.xmlNameChar}])*`;t.xmlNameRe=new RegExp(`^\\s*${d}\\s*$`),t.xmlNcname=`[${t.xmlLetter}_](?:[-${t.xmlLetter}${r}._${a}`+"·ːˑ·ـๆໆ々〱-〵ゝ-ゞー-ヾ])*",t.xmlNcnameRe=new RegExp(`^\\s*${t.xmlNcname}\\s*$`)},function(e,t,n){"use strict"; /** * Facilities for loading resources. * * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */if(Object.defineProperty(t,"__esModule",{value:!0}),"undefined"==typeof fetch)throw new Error("all resource loaders require fetch to be available");t.makeResourceLoader=function(){if("undefined"==typeof window)return new(n(!function(){var e=new Error("Cannot find module './resource-loaders/node'");throw e.code="MODULE_NOT_FOUND",e}()).NodeResourceLoader);return new(n(52).FetchResourceLoader)}},function(e,t,n){"use strict";const{isS:r,isChar:a,isNameStartChar:d,isNameChar:u,S_LIST:s}=n(54),{isNCNameStartChar:i,isNCNameChar:o}=n(55),c="http://www.w3.org/XML/1998/namespace",l="http://www.w3.org/2000/xmlns/",f={__proto__:null,xml:c,xmlns:l},h={__proto__:null,amp:"&",gt:">",lt:"<",quot:'"',apos:"'"},m="sBeginWhitespace",p="sText",b="sEntityFirstChar",g="sEntityRest",w="sOpenWaka",v="sOpenWakaBang",y="sDoctype",x="sDoctypeQuoted",E="sDoctypeDTD",_="sDoctypeDTDQuoted",A="sComment",S="sCommentEnding",I="sCommentEnded",N="sCData",k="sCDataEnding",C="sCDataEnding2",P="sPIFirstChar",M="sPIRest",T="sPIBody",$="sPIEnding",R="sOpenTag",O="sOpenTagSlash",L="sAttrib",V="sAttribName",D="sAttribNameSawWhite",j="sAttribValue",F="sAttribValueQuoted",B="sAttribValueClosed",W="sAttribValueUnquoted",G="sCloseTag",U="sCloseTagSawWhite",H=1,X=2,q=3,z=4,Z=5,K="SPACE_SEPARATOR";t.EVENTS=["text","processinginstruction","doctype","comment","opentagstart","opentag","closetag","cdata","error","end","ready"];const J=10,Y=13,Q=32,ee=33,te=34,ne=35,re=38,ae=39,de=45,ue=47,se=59,ie=60,oe=61,ce=62,le=63,fe=91,he=93;function me(e){return e===te||e===ae}const pe=[te,ae],be=[ie,re],ge=[...pe,fe,ce],we=[...pe,he],ve=[oe,le,...s],ye=[...s,ce,re,ie];function xe(e,t){const{xml:n,xmlns:r}=t;n&&n!==c&&e.fail(`xml prefix must be bound to ${c}.`),r&&r!==l&&e.fail(`xmlns prefix must be bound to ${l}.`);for(const a of Object.keys(t)){const n=t[a];switch(n){case l:e.fail(""===a?`the default namespace may not be set to ${n}.`:`may not assign a prefix (even "xmlns") to the URI ${l}.`);break;case c:switch(a){case"xml":break;case"":e.fail(`the default namespace may not be set to ${n}.`);break;default:e.fail("may not assign the xml namespace to another prefix.")}}}}t.SaxesParser=class{constructor(e){this._init(e)}_init(e){this.comment="",this.openWakaBang="",this.text="",this.name="",this.doctype="",this.piTarget="",this.piBody="",this.entity="",this.cdata="",this.xmlDeclName="",this.xmlDeclValue="",this.opt=e||{},this.closed=!1,this.xmlDecl={version:void 0,encoding:void 0,standalone:void 0},this.q=null,this.tags=[],this.initial=!0,this.tag=null,this.chunk="",this.chunkPosition=0,this.i=0,this.trailingCR=!1,this.ENTITIES=Object.create(h),this.attribList=[];const t=this.fragmentOpt=!!this.opt.fragment;if(this.state=t?p:m,this.reportedTextBeforeRoot=this.reportedTextAfterRoot=this.closedRoot=this.sawRoot=this.inRoot=t,this.xmlDeclPossible=!t,this.piIsXMLDecl=!1,this.xmlDeclState=H,this.xmlDeclExpects=["version"],this.requiredSeparator=void 0,this.entityReturnState=void 0,this.badEntityName=!1,this.textCheckedBefore=0,this.xmlnsOpt=!!this.opt.xmlns){this.nameStartCheck=i,this.nameCheck=o,this.processAttributes=this.processAttributesNS,this.ns=Object.assign({__proto__:null},f);const e=this.opt.additionalNamespaces;e&&(xe(this,e),Object.assign(this.ns,e))}else this.nameStartCheck=d,this.nameCheck=u,this.processAttributes=this.processAttributesPlain;this.trackPosition=!1!==this.opt.position,this.line=1,this.column=0,this.fileName=this.opt.fileName,this.onready()}get position(){return this.chunkPosition+this.i}ontext(){}onprocessinginstruction(){}ondoctype(){}oncomment(){}onopentagstart(){}onopentag(){}onclosetag(){}oncdata(){}onend(){}onready(){}onerror(e){throw new Error(e)}fail(e){const t=this.trackPosition?`${this.fileName}:${this.line}:${this.column}: ${e}`:e;return this.onerror(new Error(t)),this}write(e){if(this.closed)return this.fail("cannot write after close; assign an onready handler.");let t=!1;null===e&&(t=!0,e=""),"object"==typeof e&&(e=e.toString());let n=e.length;for(this.trailingCR&&(e=`\r${e}`),t||e[n-1]!==Y||(n--,this.trailingCR=!0),this.limit=n,this.chunk=e,this.i=0;this.i<n;)this[this.state]();return this.chunkPosition+=n,t?this.end():this}close(){return this.write(null)}getCode(){const{chunk:e}=this;let{i:t}=this,n=e.charCodeAt(t),r=1;return n===Y&&(e.charCodeAt(t+1)===J&&t++,n=J),n===J?(this.line++,this.column=0):(n>=55296&&n<=56319&&(r=2,n=65536+1024*(n-55296)+(e.charCodeAt(t+1)-56320)),this.column+=r,a(n)||this.fail("disallowed character.")),this.i=t+r,n}captureWhile(e,t){const{chunk:n,limit:r,i:a}=this;for(;this.i<r;){const r=this.getCode();if(!e(r))return this[t]+=n.substring(a,this.i-(r<=65535?1:2)),r}this[t]+=n.substring(a)}captureTo(e,t){const{chunk:n,limit:r,i:a}=this;for(;this.i<r;){const r=this.getCode();if(e.includes(r))return this[t]+=n.substring(a,this.i-(r<=65535?1:2)),r}this[t]+=n.substring(a)}captureToChar(e,t){const{chunk:n,limit:r,i:a}=this;for(;this.i<r;){const r=this.getCode();if(r===e)return this[t]+=n.substring(a,this.i-(r<=65535?1:2)),!0}return this[t]+=n.substring(a),!1}captureName(){const{chunk:e,limit:t,i:n}=this;for(;this.i<t;){const t=this.getCode();if(!u(t))return this.name+=e.substring(n,this.i-(t<=65535?1:2)),t}this.name+=e.substring(n)}skipWhile(e){const{limit:t}=this;for(;this.i<t;){const t=this.getCode();if(!e(t))return t}}sBeginWhitespace(){const{limit:e}=this;let t=this.getCode();if(this.initial&&65279===t){if(this.initial=!1,this.i>=e)return;t=this.getCode()}else this.initial=!1;for(;this.i<e&&r(t);)t=this.getCode(),this.xmlDeclPossible=!1;t===ie?this.state=w:(this.reportedTextBeforeRoot||(this.fail("text data outside of root node."),this.reportedTextBeforeRoot=!0),this.text=String.fromCodePoint(t),this.textCheckedBefore=0,this.state=p,this.xmlDeclPossible=!1)}sText(){const e=this.captureTo(be,"text");switch(this.inRoot||!/\S/.test(this.text)&&e!==re||(this.sawRoot||this.reportedTextBeforeRoot||(this.fail("text data outside of root node."),this.reportedTextBeforeRoot=!0),this.closedRoot&&!this.reportedTextAfterRoot&&(this.fail("text data outside of root node."),this.reportedTextAfterRoot=!0)),this.text.includes("]]>",this.textCheckedBefore)&&this.fail('the string "]]>" is disallowed in char data.'),this.textCheckedBefore=this.text.length-2,e){case ie:this.state=w;break;case re:this.state=b,this.entityReturnState=p}}sOpenWaka(){const e=this.getCode();if(d(e))this.state=R,this.name=String.fromCodePoint(e),this.xmlDeclPossible=!1;else switch(e){case ue:this.state=G,this.xmlDeclPossible=!1;break;case ee:this.state=v,this.openWakaBang="",this.xmlDeclPossible=!1;break;case le:this.state=P;break;default:this.fail("disallowed character in tag name."),this.state=p,this.xmlDeclPossible=!1}}sOpenWakaBang(){const e=String.fromCodePoint(this.getCode());switch(this.openWakaBang+=e,this.openWakaBang){case"[CDATA[":this.sawRoot||this.reportedTextBeforeRoot||(this.fail("text data outside of root node."),this.reportedTextBeforeRoot=!0),this.closedRoot&&!this.reportedTextAfterRoot&&(this.fail("text data outside of root node."),this.reportedTextAfterRoot=!0),this.state=N,this.openWakaBang="";break;case"--":this.state=A,this.openWakaBang="";break;case"DOCTYPE":this.state=y,(this.doctype||this.sawRoot)&&this.fail("inappropriately located doctype declaration."),this.openWakaBang="";break;default:this.openWakaBang.length>=7&&this.fail("incorrect syntax.")}}sDoctype(){const e=this.captureTo(ge,"doctype");e===ce?(this.state=p,this.emitNode("ondoctype",this.doctype),this.doctype=!0):e&&(this.doctype+=String.fromCodePoint(e),e===fe?this.state=E:me(e)&&(this.state=x,this.q=e))}sDoctypeQuoted(){const{q:e}=this;this.captureToChar(e,"doctype")&&(this.doctype+=String.fromCodePoint(e),this.q=null,this.state=y)}sDoctypeDTD(){const e=this.captureTo(we,"doctype");e&&(this.doctype+=String.fromCodePoint(e),e===he?this.state=y:me(e)&&(this.state=_,this.q=e))}sDoctypeDTDQuoted(){const{q:e}=this;this.captureToChar(e,"doctype")&&(this.doctype+=String.fromCodePoint(e),this.state=E,this.q=null)}sComment(){this.captureToChar(de,"comment")&&(this.state=S)}sCommentEnding(){const e=this.getCode();e===de?(this.state=I,this.emitNode("oncomment",this.comment),this.comment=""):(this.comment+=`-${String.fromCodePoint(e)}`,this.state=A)}sCommentEnded(){const e=this.getCode();e!==ce?(this.fail("malformed comment."),this.comment+=`--${String.fromCodePoint(e)}`,this.state=A):this.state=p}sCData(){this.captureToChar(he,"cdata")&&(this.state=k)}sCDataEnding(){const e=this.getCode();e===he?this.state=C:(this.cdata+=`]${String.fromCodePoint(e)}`,this.state=N)}sCDataEnding2(){const e=this.getCode();switch(e){case ce:this.emitNode("oncdata",this.cdata),this.cdata="",this.state=p;break;case he:this.cdata+="]";break;default:this.cdata+=`]]${String.fromCodePoint(e)}`,this.state=N}}sPIFirstChar(){const e=this.getCode();this.nameStartCheck(e)?(this.piTarget+=String.fromCodePoint(e),this.state=M):e===le||r(e)?(this.fail("processing instruction without a target."),this.state=e===le?$:T):e&&(this.fail("disallowed character in processing instruction name."),this.piTarget+=String.fromCodePoint(e),this.state=M)}sPIRest(){const e=this.captureWhile(this.nameCheck,"piTarget");e===le||r(e)?(this.piIsXMLDecl="xml"===this.piTarget,this.piIsXMLDecl&&!this.xmlDeclPossible&&this.fail("an XML declaration must be at the start of the document."),this.state=e===le?$:T):e&&(this.fail("disallowed character in processing instruction name."),this.piTarget+=String.fromCodePoint(e))}sPIBody(){let e;if(this.piIsXMLDecl)switch(this.xmlDeclState){case H:if((e=this.skipWhile(e=>r(e)?(this.requiredSeparator=void 0,!0):(e!==le&&this.requiredSeparator===K&&this.fail("whitespace required."),this.requiredSeparator=void 0,!1)))===le)return void(this.state=$);e&&(this.xmlDeclState=X,this.xmlDeclName=String.fromCodePoint(e));break;case X:if((e=this.captureTo(ve,"xmlDeclName"))===le)return void(this.state=$);if(r(e)||e===oe){if(!this.xmlDeclExpects.includes(this.xmlDeclName))switch(this.xmlDeclName.length){case 0:this.fail("did not expect any more name/value pairs.");break;case 1:this.fail(`expected the name ${this.xmlDeclExpects[0]}.`);break;default:this.fail(`expected one of ${this.xmlDeclExpects.join(", ")}`)}this.xmlDeclState=e===oe?z:q}break;case q:if((e=this.getCode())===le)return void(this.state=$);e&&!r(e)&&(e!==oe&&this.fail("value required."),this.xmlDeclState=z);break;case z:if((e=this.getCode())===le)return void(this.state=$);e&&!r(e)&&(me(e)?this.q=e:(this.fail("value must be quoted."),this.q=Q),this.xmlDeclState=Z);break;case Z:if((e=this.captureTo([this.q,le],"xmlDeclValue"))===le)return void(this.state=$);if(e){switch(this.xmlDeclName){case"version":/^1\.[0-9]+$/.test(this.xmlDeclValue)||this.fail("version number must match /^1\\.[0-9]+$/."),this.xmlDeclExpects=["encoding","standalone"],this.xmlDecl.version=this.xmlDeclValue;break;case"encoding":/^[A-Za-z][A-Za-z0-9._-]*$/.test(this.xmlDeclValue)||this.fail("encoding value must match /^[A-Za-z0-9][A-Za-z0-9._-]*$/."),this.xmlDeclExpects=["standalone"],this.xmlDecl.encoding=this.xmlDeclValue;break;case"standalone":"yes"!==this.xmlDeclValue&&"no"!==this.xmlDeclValue&&this.fail('standalone value must match "yes" or "no".'),this.xmlDeclExpects=[],this.xmlDecl.standalone=this.xmlDeclValue}this.xmlDeclName=this.xmlDeclValue="",this.xmlDeclState=H,this.requiredSeparator=K}break;default:throw new Error(this,`Unknown XML declaration state: ${this.xmlDeclState}`)}else 0===this.piBody.length?(e=this.getCode())===le?this.state=$:e&&!r(e)&&(this.piBody=String.fromCodePoint(e)):this.captureToChar(le,"piBody")&&(this.state=$)}sPIEnding(){const e=this.getCode();this.piIsXMLDecl?e===ce?("xml"!==this.piTarget?this.fail("processing instructions are not allowed before root."):this.xmlDeclState!==H?this.fail("XML declaration is incomplete."):this.xmlDeclExpects.includes("version")&&this.fail("XML declaration must contain a version."),this.xmlDeclName=this.xmlDeclValue="",this.requiredSeparator=void 0,this.piTarget=this.piBody="",this.state=p):this.fail("The character ? is disallowed anywhere in XML declarations."):e===ce?("xml"===this.piTarget.trim().toLowerCase()&&this.fail("the XML declaration must appear at the start of the document."),this.emitNode("onprocessinginstruction",{target:this.piTarget,body:this.piBody}),this.piTarget=this.piBody="",this.state=p):e===le?this.piBody+="?":(this.piBody+=`?${String.fromCodePoint(e)}`,this.state=T),this.xmlDeclPossible=!1}sOpenTag(){const e=this.captureName();if(!e)return;const t=this.tag={name:this.name,attributes:Object.create(null)};switch(this.xmlnsOpt&&(t.ns=Object.create(null)),this.emitNode("onopentagstart",t),e){case ce:this.openTag();break;case ue:this.state=O;break;default:r(e)||this.fail("disallowed character in tag name."),this.state=L}}sOpenTagSlash(){this.getCode()===ce?this.openTag(!0):(this.fail("forward-slash in opening tag not followed by >."),this.state=L)}sAttrib(){const e=this.getCode();e&&!r(e)&&(d(e)?(this.name=String.fromCodePoint(e),this.state=V):e===ce?this.openTag():e===ue?this.state=O:this.fail("disallowed character in attribute name."))}sAttribName(){const e=this.captureName();e===oe?this.state=j:r(e)?this.state=D:e===ce?(this.fail("attribute without value."),this.attribList.push({name:this.name,value:this.name}),this.name=this.text="",this.openTag()):e&&this.fail("disallowed character in attribute name.")}sAttribNameSawWhite(){const e=this.getCode();r(e)||(e===oe?this.state=j:e&&(this.fail("attribute without value."),this.tag.attributes[this.name]="",this.text="",this.name="",e===ce?this.openTag():d(e)?(this.name=String.fromCodePoint(e),this.state=V):(this.fail("disallowed character in attribute name."),this.state=L)))}sAttribValue(){const e=this.getCode();me(e)?(this.q=e,this.state=F):e&&!r(e)&&(this.fail("unquoted attribute value."),this.state=W,this.text=String.fromCodePoint(e))}sAttribValueQuoted(){const e=this.captureTo([this.q,re,ie],"text");e===re?(this.state=b,this.entityReturnState=F):e===ie?this.fail("disallowed character."):e&&(this.attribList.push({name:this.name,value:this.text}),this.name=this.text="",this.q=null,this.state=B)}sAttribValueClosed(){const e=this.getCode();r(e)?this.state=L:d(e)?(this.fail("no whitespace between attributes."),this.name=String.fromCodePoint(e),this.state=V):e===ce?this.openTag():e===ue?this.state=O:this.fail("disallowed character in attribute name.")}sAttribValueUnquoted(){const e=this.captureTo(ye,"text");e===re?(this.state=b,this.entityReturnState=W):e===ie?this.fail("disallowed character."):e&&(this.text.includes("]]>")&&this.fail('the string "]]>" is disallowed in char data.'),this.attribList.push({name:this.name,value:this.text}),this.name=this.text="",e===ce?this.openTag():this.state=L)}sCloseTag(){const e=this.captureName();e===ce?this.closeTag():r(e)?this.state=U:e&&this.fail("disallowed character in closing tag.")}sCloseTagSawWhite(){const e=this.getCode();e===ce?this.closeTag():e&&!r(e)&&this.fail("disallowed character in closing tag.")}sEntityFirstChar(){const e=this.getCode();this.nameStartCheck(e)||e===ne?(this.entity=String.fromCodePoint(e),this.state=g):e===se?(this.fail("empty entity name."),this.text+="&;",this.state=this.entityReturnState):(this.fail("disallowed first character in entity name."),this.entity=String.fromCodePoint(e),this.badEntityName=!0,this.state=g)}sEntityRest(){const e=this.captureWhile(this.nameCheck,"entity");e===se?(this.badEntityName?this.text+=`&${this.entity}${String.fromCodePoint(e)}`:this.text+=this.parseEntity(this.entity),this.textCheckedBefore=this.text.length,this.entity="",this.state=this.entityReturnState,this.badEntityName=!1):e&&(this.fail("disallowed character in entity name."),this.text+=`&${this.entity}${String.fromCodePoint(e)}`,this.textCheckedBefore=this.text.length,this.entity="",this.state=this.entityReturnState,this.badEntityName=!1)}end(){return this.sawRoot||this.fail("document must contain a root element."),this.sawRoot&&!this.closedRoot&&this.fail("unclosed root tag."),this.state!==m&&this.state!==p&&this.fail("unexpected end."),this.text&&this.closeText(),this.closed=!0,this.onend(),this._init(this.opt),this}closeText(){this.ontext(this.text),this.text="",this.textCheckedBefore=0}emitNode(e,t){this.text&&this.closeText(),this[e](t)}emitNodes(e,t,n){this.text&&this.closeText(),this[e](n),this[t](n)}resolve(e){let t=this.tag.ns[e];if(void 0!==t)return t;const{tags:n}=this;for(let a=n.length-1;a>=0;a--)if(void 0!==(t=n[a].ns[e]))return t;if(t=this.ns[e])return t;const{resolvePrefix:r}=this.opt;return r?r(e):void 0}qname(e){const t=e.indexOf(":");if(t<0)return{prefix:"",local:e};0===t&&this.fail(`malformed name: ${e}.`);const n=e.substring(t+1);return-1!==n.indexOf(":")&&this.fail(`malformed name: ${e}.`),{prefix:e.substring(0,t),local:n}}processAttributesNS(){const{tag:e,attribList:t}=this,{name:n,attributes:r,ns:a}=e;for(const{name:u,value:s}of t){const{prefix:e,local:t}=this.qname(u);"xmlns"===e?a[t]=s.trim():"xmlns"===u&&(a[""]=s.trim())}xe(this,a);{const{prefix:t,local:r}=this.qname(n);e.prefix=t,e.local=r;const a=e.uri=this.resolve(t)||"";t&&("xmlns"===t&&this.fail('tags may not have "xmlns" as prefix.'),a||(this.fail(`unbound namespace prefix: ${JSON.stringify(t)}.`),e.uri=t))}const d=new Set;for(const{name:u,value:s}of t){const{prefix:e,local:t}=this.qname(u);let n,a;""===e?(n="xmlns"===u?l:"",a=u):((n=this.resolve(e))||(this.fail(`unbound namespace prefix: ${JSON.stringify(e)}.`),n=e),a=`{${n}}${t}`),d.has(a)&&this.fail(`duplicate attribute: ${a}.`),d.add(a),r[u]={name:u,value:s,prefix:e,local:t,uri:n}}this.attribList=[]}processAttributesPlain(){const{attribList:e,tag:{attributes:t}}=this;for(const{name:n,value:r}of e)t[n]&&this.fail(`duplicate attribute: ${n}.`),t[n]=r;this.attribList=[]}openTag(e){this.processAttributes();const{tag:t}=this;e=!!e,t.isSelfClosing=e,!this.fragmentOpt&&this.closedRoot&&this.fail("documents may contain only one root."),this.sawRoot=!0;const{tags:n}=this;e?(this.emitNodes("onopentag","onclosetag",t),(this.tag=n[n.length-1])||(this.closedRoot=!0)):(this.emitNode("onopentag",t),this.inRoot=!0,n.push(t)),this.state=p,this.name=""}closeTag(){const{tags:e,name:t}=this;if(this.state=p,this.name="",!t)return this.fail("weird empty close tag."),void(this.text+="</>");let n=e.length;for(;n-- >0;){const n=this.tag=e.pop();if(this.emitNode("onclosetag",n),n.name===t)break;this.fail("unexpected close tag.")}0===n?(this.inRoot=!1,this.closedRoot=!0):n<0&&(this.fail(`unmatched closing tag: ${t}.`),this.text+=`