@pubann/textae 14.1.2 → 14.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -207,7 +207,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
207
207
  ${this.#Et.attributes.map(t=>t.contentHTML)}
208
208
  </div>
209
209
  </div>
210
- `}}class Ft{#c;#mt;#Qt;#Dt;#Rt;#It;constructor(t,e,i,n,s,o){this.#c=I(t),this.#mt=e,this.#Qt=i,this.#Dt=l().create('<div class="textae-editor__relation__signboard-location"></div>'),this.#Lt(),this.#Rt=new Zt(e,"relation",null),this.#Dt.appendChild(this.#Rt.element),this.#c.appendChild(this.#Dt),this.#Dt.addEventListener("click",n),this.#Dt.addEventListener("mouseenter",s),this.#Dt.addEventListener("mouseleave",o)}updateValue(){this.#Lt(),this.#Rt.updateLabel()}updateHighlighting(){this.#Lt(),this.#Rt.clearCSSClass(),this.#mt.isSelected?this.#Rt.select():this.#mt.isHovered&&this.#Rt.hover()}destructor(){this.#c.removeChild(this.#Dt)}get y(){return this.#It.getBBox().y}get width(){return this.#Dt.getBBox().width}get height(){return this.#Dt.getBBox().height}#Lt(){this.#Dt.style.width="0px",this.#Dt.style.left=`${this.#Qt.highestX}px`,this.#Dt.style.top=this.#Qt.top-18-18*this.#mt.attributes.length+"px"}}class Xt{#Q;#Nt;#U;#jt;#H;#ft;#W;#Y;#K;#J;#gt;#u;#zt;#Qt;#Bt;constructor(t,e,i,n,s,{id:o,pred:r,subj:a,obj:l},c,h){this.#Q=t,this.#Nt=e,this.#U=i,this.#jt=n,this.#H=o,this.#W=a,this.#Y=l,this.#K=s,this.#J=c,this.#gt=h,this.#u=!1,this.#zt=!1,this.typeName=r}get id(){return this.#H}set id(t){this.#H=t}get typeName(){return this.#ft}set typeName(t){this.#ft=String(t)}get typeValues(){return new Ot(this.#ft,this.#jt.getAttributesFor(this.#H))}get subj(){return this.#W}get obj(){return this.#Y}get attributes(){return this.#jt.getAttributesFor(this.#H)}get sourceEntity(){return this.#U.get(this.subj)}get targetEntity(){return this.#U.get(this.obj)}get sourceColor(){return this.sourceEntity.color}get targetColor(){return this.targetEntity.color}get isSelected(){return this.#u}get isHovered(){return this.#zt}select(){this.#u||(this.#u=!0,this.#Bt&&this.#Bt.updateHighlighting())}deselect(){this.#u&&(this.#u=!1,(this.#Qt||this.#Bt)&&this.redrawLineConsideringSelection())}render(t,e){this.sourceEntity.isInViewport(t,e)||this.targetEntity.isInViewport(t,e)?(this.#Qt?this.#qt():(this.#Qt=new zt(this.#Q,this,this.#gt,t=>{this.#Nt.emit("textae-event.editor.relation.click",t,this),t.stopPropagation()},(t,e)=>{this.#Nt.emit("textae-event.editor.relation-bollard.click",t,e),t.stopPropagation()},()=>this.#Zt(),()=>this.#Ft()),this.#Bt=new Ft(this.#Q,this,this.#Qt,(t,e)=>{this.#Nt.emit("textae-event.editor.relation.click",t,this,e),t.stopPropagation()},()=>this.#Zt(),()=>this.#Ft())),this.sourceEntity.clientTop>this.targetEntity.clientTop&&this.targetEntity.isInViewport(t,e)||this.sourceEntity.clientTop<this.targetEntity.clientTop&&this.sourceEntity.isInViewport(t,e)||this.sourceEntity.clientTop===this.targetEntity.clientTop?this.#Bt?this.#Xt():(this.#Bt=new Ft(this.#Q,this,this.#Qt,(t,e)=>{this.#Nt.emit("textae-event.editor.relation.click",t,this,e),t.stopPropagation()},()=>this.#Zt(),()=>this.#Ft()),this.#Bt.updateHighlighting()):this.#Bt&&(this.#Bt.destructor(),this.#Bt=void 0)):(this.#Qt||this.#Bt)&&this.erase()}updateElement(){this.#Qt&&this.#Qt.update(this.isSelected,this.isSelected,this.isSelected),this.#Bt&&this.#Bt.updateValue()}redrawLineConsideringSelection(){this.#qt(),this.#Xt()}pointUpPathAndSourceBollards(){this.#Qt&&(this.targetEntity.isSelected?this.#Qt.update(!0,!0,!0):this.#Qt.update(!0,!0,this.isSelected)),this.#Bt&&this.#Bt.updateHighlighting()}pointUpPathAndTargetBollards(){this.#Qt&&(this.sourceEntity.isSelected?this.#Qt.update(!0,!0,!0):this.#Qt.update(!0,this.isSelected,!0)),this.#Bt&&this.#Bt.updateHighlighting()}pointUpSourceBollardsAndTargetBollards(){this.#Qt&&this.#Qt.update(this.isSelected,!0,!0),this.#Bt&&this.#Bt.updateHighlighting()}pointUpSourceBollards(){this.#Qt&&this.#Qt.update(this.isSelected,!0,this.isSelected),this.#Bt&&this.#Bt.updateHighlighting()}pointUpTargetBollards(){this.#Qt&&this.#Qt.update(this.isSelected,this.isSelected,!0),this.#Bt&&this.#Bt.updateHighlighting()}erase(){this.#Qt&&(this.#Qt.destructor(),this.#Qt=void 0),this.#Bt&&(this.#Bt.destructor(),this.#Bt=void 0)}get title(){return`[${this.id}] pred: type, value: ${this.typeName}`}get color(){return this.#J.getColor(this.typeName)}get anchorHTML(){return pt(this.#lt,this.#nt)}get#lt(){return ht(this.#K,this.typeName,this.#J.getLabel(this.typeName))}get#nt(){return ft(this.#K,this.typeName,this.#J.getURI(this.typeName))}#Zt(){this.#zt=!0,this.#Qt.update(!0,!0,!0),this.#Bt&&this.#Bt.updateHighlighting();const t=new Set,e=new Set,i=new Set;for(const i of this.sourceEntity.relationsWhereThisIsSource)i!==this&&(i.targetEntity==this.targetEntity?t.add(i):e.add(i));for(const e of this.sourceEntity.relationsWhereThisIsTarget)e!==this&&(e.sourceEntity==this.targetEntity?t.add(e):i.add(e));for(const i of this.targetEntity.relationsWhereThisIsSource)i!==this&&(i.targetEntity==this.sourceEntity?t.add(i):e.add(i));for(const e of this.targetEntity.relationsWhereThisIsTarget)e!==this&&(e.sourceEntity==this.sourceEntity?t.add(e):i.add(e));for(const e of t)e.pointUpSourceBollardsAndTargetBollards();for(const t of e)t.pointUpSourceBollards();for(const t of i)t.pointUpTargetBollards()}#Ft(){this.#zt=!1;const t=new Set;for(const e of this.sourceEntity.relations)t.add(e);for(const e of this.targetEntity.relations)t.add(e);for(const e of t)e.redrawLineConsideringSelection()}#qt(){this.#Qt&&(this.sourceEntity.isSelected&&this.targetEntity.isSelected?this.#Qt.update(!0,!0,!0):this.sourceEntity.isSelected?this.#Qt.update(!0,!0,this.isSelected):this.targetEntity.isSelected?this.#Qt.update(!0,this.isSelected,!0):this.#Qt.update(this.isSelected,this.isSelected,this.isSelected))}#Xt(){this.#Bt&&this.#Bt.updateHighlighting()}}class Ht extends gt{#Q;#Nt;#Ht;#K;#J;#gt;constructor(t,e,i,n){super(e,"relation",()=>"R"),this.#Q=t,this.#Nt=e,this.#Ht=i,this.#K=i.namespaceInstanceContainer,this.#J=n}set toolBarHeight(t){this.#gt=t}_toInstance(t){return new Xt(this.#Q,this.#Nt,this.#Ht.entityInstanceContainer,this.#Ht.attributeInstanceContainer,this.#K,t,this.#J,this.#gt)}add(t){t=t instanceof Xt?t:new Xt(this.#Q,this.#Nt,this.#Ht.entityInstanceContainer,this.#Ht.attributeInstanceContainer,this.#K,t,this.#J,this.#gt);const e=super.add(t),{clientHeight:i,clientWidth:n}=document.documentElement;return e.render(i,n),e}changeType(t,e){const i=super.changeType(t,e);return i.updateElement(),i}remove(t){console.assert(t,"id is necessary!");super.remove(t).erase()}clear(){for(const t of this.all)t.erase();super.clear()}}class Wt{#M;#H;#jt;#G;#K;#Wt;#Vt;#gt;#u=!1;#zt=!1;#Yt=!1;#Rt=null;#Ut;#ft;constructor(t,e,i,n,s,o,r,a,l,c=null){this.#M=t,this.#H=c,this.#jt=e,this.#G=i,this.#Wt=s,this.#Vt=o,this.#K=n,this.#gt=l,this.span=r,this.typeName=a}get id(){return this.#H}set id(t){this.#H=t}get title(){return`[${this.id}] pred: type, value: ${this.#ft}`}get color(){return this.#J.getColor(this.typeName)}get anchorHTML(){return pt(this.#lt,this.#nt)}get span(){return this.#Ut}set span(t){this.#Ut=t,t.add(this)}get typeName(){return this.#ft}set typeName(t){this.#ft=String(t)}get typeValues(){return new Ot(this.#ft,this.#jt.getAttributesFor(this.#H))}get relations(){return this.relationsWhereThisIsSource.concat(this.relationsWhereThisIsTarget)}get attributes(){return this.#jt.getAttributesFor(this.#H)}get relationsWhereThisIsSource(){return this.#G.all.filter(t=>t.subj===this.id)}get relationsWhereThisIsTarget(){return this.#G.all.filter(t=>t.obj===this.id)}get hasMultipleEndpoints(){const t=new Map;t.set("whereThisIsSourceAndTargetIsOnTheLeft",new Set),t.set("whereThisIsSourceAndTargetIsOnTheRight",new Set),t.set("whereThisIsSourceAndTargetIsUpOrDown",new Set);for(const e of this.relationsWhereThisIsSource)e.targetEntity.offsetCenter<this.offsetCenter?t.get("whereThisIsSourceAndTargetIsOnTheLeft").add(e):this.offsetCenter<e.targetEntity.offsetCenter?t.get("whereThisIsSourceAndTargetIsOnTheRight").add(e):t.get("whereThisIsSourceAndTargetIsUpOrDown").add(e);t.set("whereThisIsTargetAndSourceIsOnTheLeft",new Set),t.set("whereThisIsTargetAndSourceIsOnTheRight",new Set),t.set("whereThisIsTargetAndSourceIsUpOrDown",new Set);for(const e of this.relationsWhereThisIsTarget)e.sourceEntity.offsetCenter<this.offsetCenter?t.get("whereThisIsTargetAndSourceIsOnTheLeft").add(e):this.offsetCenter<e.targetEntity.offsetCenter?t.get("whereThisIsTargetAndSourceIsOnTheRight").add(e):t.get("whereThisIsTargetAndSourceIsUpOrDown").add(e);return[...t.values()].filter(t=>t.size).length>1}get clientTop(){const{span:t}=this;if(t.isDenotation){let e=t.clientTopOfGrid+this.#Wt.height;for(const i of t.entities){if(i===this)break;e+=this.#Wt.height+i.height}return T(e)}if(t.isBlock){const e=15;return T(t.clientBottomOfGrid-this.height-e)}throw new Error("Unexpected type of span")}get offsetTop(){return this.clientTop-this.span.element.offsetParent.offsetParent.getBoundingClientRect().top}get clientBottom(){return this.clientTop+this.height}isInViewport(t){return this.#gt<=this.clientBottom&&this.clientTop<=t}get width(){return this.span.widthOfGrid}get height(){return 18+this.#Gt}get heightWithTypeGap(){return this.height+this.#Wt.height}get offsetCenter(){return T(this.span.offsetCenterOfGrid)}get isDenotation(){return this.#Ut.isDenotation}get isBlock(){return this.#Ut.isBlock}get isSelected(){return this.#u}getSourceAnchorPosition(t){const e=this.width/2>=28||this.hasMultipleEndpoints&&t;return{left:e?this.offsetCenter-24:this.offsetCenter,right:e?this.offsetCenter+24:this.offsetCenter}}getTargetAnchorPosition(t){const e=this.width/2>=28||this.hasMultipleEndpoints&&t;return{left:e?this.offsetCenter-8:this.offsetCenter,right:e?this.offsetCenter+8:this.offsetCenter}}focus(){if(this.isDenotation)this.span.focus();else{if(!this.isBlock)throw new Error("Unexpected type of entity");this.span.forceRenderGrid(),this.#Rt.focus()}}select(){this.#u||(this.#u=!0,this.#Kt(),this.#Jt())}deselect(){this.#u&&(this.#u=!1,this.#Rt&&this.#Rt.deselect(),this.#Jt())}startCut(){this.#Rt&&this.#Rt.startCut()}cancelCut(){this.#Rt&&this.#Rt.cancelCut()}render(){if(!this.#Rt&&this.span.isGridRendered){this.#Rt=this.#te(),this.span.addEntityElementToGridElement(this.#Rt.element),this.reflectTypeGapInTheHeight();for(const t of this.span.entities.filter(t=>t!==this))for(const e of t.relations)e.redrawLineConsideringSelection();this.#u&&this.#Rt.select()}}updateElement(){if(this.#Rt){this.#Rt=this.#Rt.replaceWith(this.#te()),this.#u&&this.#Kt(),this.reflectTypeGapInTheHeight(),this.span.updateSelfAndAncestorsGridPosition();for(const t of this.span.entities)for(const e of t.relations)e.redrawLineConsideringSelection()}}reflectTypeGapInTheHeight(){this.isDenotation&&this.#Rt&&this.#Rt.reflectTypeGapInTheHeight(this.#Wt.height)}clarifyLabel(){this.#Rt&&this.#Rt.clarifyLabel(),this.#Yt=!0}declarifyLabel(){!this.#zt&&this.#Rt&&this.#Rt.declarifyLabel(),this.#Yt=!1}erase(){this.#Rt&&(this.#Rt.remove(),this.#Rt=null,this.span.updateSelfAndAncestorsGridPosition())}#te(){const t=new Zt(this,this.isDenotation?"denotation":"block",`${this.#M}__E${this.id.replace(/[:¥.]/g,"")}`);return t.addEventListener("mouseenter",()=>{t.clarifyLabel(),this.#ee(),this.#zt=!0}),t.addEventListener("mouseleave",()=>{this.#Yt||t.declarifyLabel(),this.#Jt(),this.#zt=!1}),t}#Kt(){this.span.forceRenderGrid(),this.#Rt.select(),this.span.isGridBeforePositioned?this.span.entityToFocusOn=this:this.focus()}get#J(){if(this.isDenotation)return this.#Vt.denotation;if(this.isBlock)return this.#Vt.block;throw"unknown entity type"}get#lt(){return ht(this.#K,this.typeName,this.#J.getLabel(this.typeName))}get#nt(){return ft(this.#K,this.typeName,this.#J.getURI(this.typeName))}get#Gt(){return this.attributes.map(({height:t})=>t).reduce((t,e)=>t+e,0)}#ee(){for(const t of this.relationsWhereThisIsSource)t.pointUpPathAndSourceBollards();for(const t of this.relationsWhereThisIsTarget)t.pointUpPathAndTargetBollards()}#Jt(){for(const t of this.relations)t.redrawLineConsideringSelection()}}class Vt extends gt{#M;#Ht;#Wt;#K;#gt;constructor(t,e,i,n){super(e,"entity",t=>t.isDenotation?"T":"B"),this.#M=t,this.#Ht=i,this.#Wt=n,this.#K=i.namespaceInstanceContainer}get#T(){return this.#Ht.spanInstanceContainer}get#jt(){return this.#Ht.attributeInstanceContainer}get#G(){return this.#Ht.relationInstanceContainer}set toolBarHeight(t){this.#gt=t}_toInstance(t,e){const i=this.#ie(e,t);return new Wt(this.#M,this.#jt,this.#G,this.#K,this.#Wt,this.#Ht.typeDictionary,i,t.obj,this.#gt,t.id)}add(t){if(t instanceof Wt){if(!t.span)throw new Error(`entity has no span! ${JSON.stringify(t)}`);return super.add(t),t.span.add(t),t.render(),t}if(void 0===t.spanType||void 0===t.begin||void 0===t.end)throw new Error(`entity has no span information! ${JSON.stringify(t)}`);const e=this.#T.find(t.spanType,t.begin,t.end),i=new Wt(this.#M,this.#jt,this.#G,this.#K,this.#Wt,this.#Ht.typeDictionary,e,t.typeName,this.#gt);return console.assert(i.span.isDenotation||i.span.entities.length>0,"A block span cannot have more than one entity."),super.add(i),i.render(),i}remove(t){const e=super.get(t);e.span.remove(e),super.remove(t),e.erase()}changeType(t,e){const i=super.changeType(t,e);return i.updateElement(),i}moveEntities(t,e){for(const i of e){i.erase();const e=i.span;e.remove(i),e.updateSelfAndAncestorsGridPosition(),i.span=t,i.render();for(const t of i.relations)t.redrawLineConsideringSelection()}super._emit("textae-event.annotation-data.entity.move")}get denotations(){return this.all.filter(t=>t.isDenotation)}get blocks(){return this.all.filter(t=>t.isBlock)}redrawEntitiesWithSpecifiedAttribute(t){const e=this.all.filter(e=>e.typeValues.hasSpecificPredicateAttribute(t));for(const t of e)t.updateElement();for(const t of new Set([...e.map(({span:t})=>t)]))t.updateGridPosition()}clarifyLabelOfAll(){for(const t of this.all)t.clarifyLabel()}declarifyLabelOfAll(){for(const t of this.all)t.declarifyLabel()}#ie(t,e){return this.#T.find(t,e.span.begin,e.span.end)}hasDenotation(t){return this.denotations.some(e=>e.id===t)}}class Yt{constructor(t){this._trackNumber=t}addTrackNumberAsIDPrefix(t,e,i,n){const s=t.map(t=>({...t,id:this._prependToIDOf(t)})),o=e.map(t=>({...t,id:this._prependToIDOf(t)})),r=n.map(t=>({...t,id:this._prependToIDOf(t),subj:this._prependTrackNumberTo(t.subj),obj:t.obj})),a=i.map(t=>({...t,id:this._prependToIDOf(t),subj:this._prependTrackNumberTo(t.subj),obj:this._prependTrackNumberTo(t.obj)}));return{denotations:s,blocks:o,relations:a,attributes:r}}_prependToIDOf(t){return t.id?this._prependTrackNumberTo(t.id):null}_prependTrackNumberTo(t){return this._trackNumber+t}}function Ut(t){const{span:e}=t;return{...t,span:Gt(e)}}function Gt(t){return{...t,begin:parseInt(t.begin),end:parseInt(t.end)}}function Kt(t,e,i,n,s,o=""){const[r,a,l]=function(t,e,i){return[t.map(Ut),e.map(Ut),i.map(Ut)]}(s.typeSetting,s.denotation,s.block),{relation:c,attribute:h}=s,{denotations:u,blocks:d,relations:f,attributes:p}=new Yt(o).addTrackNumberAsIDPrefix(a,l,c,h);t.addSource(r,"typesetting"),t.addSource(u,"denotation"),t.addSource(d,"block"),e.addSource(u,"denotation"),e.addSource(d,"block"),n.addSource(f),i.addSource(p)}function Jt(t,e){return 0<=t&&t<=e.length}class te{constructor(){this._map=new Map}set(t,e,i){this._map.set(t,[e,i])}getErrors(t){return this._map.has(t)?this._map.get(t)[0]:[]}getInhibitors(t){return this._map.has(t)?this._map.get(t)[1]:[]}get size(){return this._map.size}}function ee(t,e){return e.reduce((e,i)=>e.concat(i.getErrors(t)),[])}class ie{constructor(t,e,i="",n=()=>!0,s){this._candidates=t||[],this._name=i,this._predicate=n,this._prevValidation=s,this._sourcePropertyName=e}and(t,e){return new ie(this._candidates,this._sourcePropertyName,t,e,this)}validateAll(){const t=new te;let e,i;for(e=this,i=this._candidates;e;e=e._prevValidation)i=e._validate(i,this._candidates,t);return[i,t]}_validate(t,e,i){return this._getRejects(e).length>0&&i.set(this._name,this._getRejects(e),this._getInhibitors(e)),this._getAccepts(t)}_getAccepts(t){return t.filter(t=>this._test(t))}_getRejects(t){return t.filter(t=>!this._test(t)).map(t=>function(t,e){return t.sourceProperty=e,t}(t,this._sourcePropertyName))}_getInhibitors(t){const e=new Map;for(const i of t){const t=this._predicate(i);Array.isArray(t)&&!t[0]&&e.set(i,t[1])}return e}_test(t){const e=this._predicate(t);return Array.isArray(e)?e[0]:e}}function ne(t,e,i,n){return new ie(t,n).and("hasLength",t=>t.span.end-t.span.begin>0).and("inText",t=>function(t,e){return Jt(e.begin,t)&&Jt(e.end,t)}(e,t.span)).and("isNotCrossing",t=>{const e=H(i,t.span.begin,t.span.end);return[0===e.length,e]})}function se(t,e){return t.some(t=>t.id===e)}function oe(t,e){return void 0===e.id||1===t.filter(t=>e.id&&e.id===t.id).length}function re(t,e){for(const[i,n]of e.getInhibitors("isNotCrossing"))console.warn(`Crossing ${t}: [${i.span.begin}:${i.span.end}](${i.id}) crosses with ${n.map(({id:t,span:e})=>`[${e.begin}:${e.end}](${t})`).join(", ")}`)}function ae(t){const{typesettings:e,denotations:i,blocks:n}=t;return(e||[]).concat(i||[]).concat(n||[])}function le(t,e,i){const[n,s]=function(t,e,i){return ne(e,t,i,"typesettings").validateAll()}(t,i.typesettings,e),o=ae(i),[r,a]=function(t,e,i,n){return ne(e,t,i,"denotations").and("uniqueID",t=>oe(n,t)).validateAll()}(t,i.denotations,e,o),[l,c]=function(t,e,i,n){return ne(e,t,i,"blocks").and("uniqueID",t=>oe(n,t)).and("uniqueRange",({span:t})=>1===e.filter(({span:e})=>t.begin===e.begin&t.end===e.end).length).validateAll()}(t,i.blocks,e,o),[h,u]=(d=r.concat(l),f=i.relations,new ie(f).and("object",t=>se(d,t.obj)).and("subject",t=>se(d,t.subj)).validateAll());var d,f;const[p,m]=(g=r.concat(l).concat(h),v=i.attributes,new ie(v).and("subject",t=>se(g,t.subj)).and("unique",t=>function(t,e){return 1===t.filter(t=>t.subj===e.subj&&t.pred===e.pred&&t.obj===e.obj).length}(v,t)).validateAll());var g,v,y,O,b;return re("TypeSettings",s),re("Denotations",a),re("Blocks",c),{accept:{denotation:r,attribute:p,relation:h,typeSetting:n,block:l},reject:{wrongRangeDenotations:a.getErrors("hasLength"),outOfTextDenotations:a.getErrors("inText"),wrongRangeBlocks:c.getErrors("hasLength"),outOfTextBlocks:c.getErrors("inText"),duplicatedRangeBlocks:c.getErrors("uniqueRange"),wrongRangeTypesettings:s.getErrors("hasLength"),outOfTextTypesettings:s.getErrors("inText"),duplicatedIDs:ee("uniqueID",[a,c]),boundaryCrossingSpans:ee("isNotCrossing",[s,a,c]),referencedEntitiesDoNotExist:(y=m.getErrors("subject"),O=u.getErrors("object"),b=u.getErrors("subject"),y.map(t=>(t.sourceProperty="attributes",t.alertSubj=!0,t)).concat(O.map(t=>(t.sourceProperty="relations",t.alertObj=!0,t))).concat(b.map(t=>(t.sourceProperty="relations",t.alertSubj=!0,t)))),duplicatedAttributes:m.getErrors("unique"),hasError:a.size||c.size||m.size||u.size||s.size}}}class ce{#K;#T;#U;#G;#jt;#ne;#se;#oe;constructor(t,e){const{namespaceInstanceContainer:i,spanInstanceContainer:n,entityInstanceContainer:s,attributeInstanceContainer:o,relationInstanceContainer:r}=t;this.#K=i,this.#T=n,this.#U=s,this.#G=r,this.#jt=o,this.#ne=e}eval(){this.#ne.namespaces?this.#K.addSource(this.#ne.namespaces.map(t=>({id:t.prefix,...t}))):this.#K.addSource([]);const{accept:t,reject:e}=le(this.#re,this.#ae,this.#ne);Kt(this.#T,this.#U,this.#jt,this.#G,t),e.name="Root annotations.",this.#se=e,this.hasMultiTracks&&(this.#oe=function(t,e,i,n,s,o,r){console.assert(r.tracks);const{tracks:a}=r;return a.map((r,a)=>{const l=a+1,c=`track${l}_`,{accept:h,reject:u}=le(s,o,r);return Kt(t,e,i,n,h,c),u.name=`Track ${l} annotations.`,u})}(this.#T,this.#U,this.#jt,this.#G,this.#re,this.#ae,this.#ne))}get hasMultiTracks(){return Boolean(this.#ne.tracks)}get rejects(){return this.hasMultiTracks?[this.#se].concat(this.#oe):[this.#se]}get#re(){return this.#ne.text}get#ae(){return function(t){let e=ae(t);if(t.tracks)for(const i of t.tracks)e=e.concat(ae(i));return e}(this.#ne)}}function he(t){return t.relationInstanceContainer.all.map(t=>({id:t.id,pred:t.typeName,subj:t.subj,obj:t.obj}))}function ue(t){return t.entityInstanceContainer.blocks.map(t=>({id:t.id,span:{begin:t.span.begin,end:t.span.end},obj:t.typeName}))}class de{constructor(t){this._isGapShown=!0,this._numberOfGap=1,this._callback=t}set show(t){this._isGapShown!==t&&(this._isGapShown=t,this._callback(this.value))}get show(){return this._isGapShown}get value(){return this._isGapShown?this._numberOfGap:0}get height(){return 24*this.value}set value(t){this._numberOfGap!==t&&(this._numberOfGap=t,this._callback(t))}}function fe(t){const e=parseInt(t,10);return isNaN(e)?0:e}class pe{#Q;#r;#Ht;#le;constructor(t,e,i){this.#Q=t,this.#r=t.querySelector(".textae-editor__text-box"),this.#Ht=e,this.#le=i}get boundingClientRect(){return this.#r.getBoundingClientRect()}get lineHeight(){return t=this.#r,fe(window.getComputedStyle(t).lineHeight);var t}set lineHeight(t){var e,i,n;e=this.#r,i=t,n=this.#le,e.style.lineHeight=`${i}px`,e.style.paddingTop=`${i/2+n}px`,this.forceUpdate(),this.#Ht.updatePosition()}render(t){this.#r.innerHTML=t.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#039;")}updateLineHeight(){const t=this.#Ht.spanInstanceContainer.maxHeight;t?this.lineHeight=t:this.#ce()}forceUpdate(){!function(t,e){const i=window.getComputedStyle(t);t.style.height="auto",t.style.height=`${t.offsetHeight-fe(i.paddingTop)+20+e}px`}(this.#r,this.#le),this.#he()}#ce(){const{lineHeight:t}=window.getComputedStyle(this.#Q);this.lineHeight=fe(t)}#he(){const t=this.#Q.querySelector(".textae-editor__relation-box");t.style.height=this.#r.style.height;const e=parseFloat(window.getComputedStyle(this.#r).width);t.style.width=e-10+"px"}}function me(t,e,i){const n='\n <div class="textae-editor__body">\n <div class="textae-editor__annotation-box"></div>\n <svg\n namespace="http://www.w3.org/2000/svg"\n class="textae-editor__relation-box">\n </svg>\n <div class="textae-editor__text-box"></div>\n </div>\n ';return t.innerHTML=n.replace(/[\n\r]+/g,""),function(t){new MutationObserver(e=>{e.forEach(e=>{e.removedNodes.length&&1===e.removedNodes[0].nodeType&&(e.removedNodes[0].classList.contains("textae-editor__span")||e.removedNodes[0].classList.contains("textae-editor__type"))&&"BODY"===document.activeElement.tagName&&t.focus()})}).observe(t.querySelector(".textae-editor__body"),{childList:!0,subtree:!0})}(t),new pe(t,e,i)}var ge=i(504),ve=i.n(ge);class ye{#Nt;#ue;#de;#fe;#pe;#me=new(ve())(!1);constructor(t,e,i,n,s,o=!0){this.#Nt=t,this.#ue=e,this.#de=i,this.#fe=n,this.#pe=s,this.#me(()=>this.#Nt.emit("textae-event.type-definition.lock")),this.#me.set(o)}set autocompletionWs(t){this.#ue.autocompletionWs=t,this.#fe.autocompletionWs=t,this.#de.autocompletionWs=t}set autocompletionFunction(t){this.#ue.autocompletionFunction=t,this.#fe.autocompletionFunction=t,this.#de.autocompletionFunction=t}get denotation(){return this.#ue}get block(){return this.#de}get relation(){return this.#fe}get attribute(){return this.#pe}get autocompletionWs(){return this.#ue.autocompletionWs}get config(){const t={};return this.#ue.config.length&&(t["entity types"]=this.#ue.config),this.#fe.config.length&&(t["relation types"]=this.#fe.config),this.#pe.config.length&&(t["attribute types"]=this.#pe.config),this.#de.config.length&&(t["block types"]=this.#de.config),t}get isLock(){return this.#me()}lockEdit(){this.#me.set(!0)}unlockEdit(){this.#me.set(!1)}setTypeConfig(t){t?(this.#ue.config=t["entity types"],this.#fe.config=t["relation types"],this.#pe.config=t["attribute types"],this.#de.config=t["block types"],this.autocompletionWs=t.autocompletion_ws):(this.#ue.config=null,this.#fe.config=null,this.#pe.config=null,this.#de.config=null,this.autocompletionWs=""),this.#Nt.emit("textae-event.type-definition.reset")}}function Oe(t){const e=Array.from(t.keys());return e.sort((e,i)=>{const n=t.get(i).usage-t.get(e).usage;return 0!==n?n:e>i?1:e<i?-1:0}),e}function be(t,e){for(const[e,i]of t.entries())t.set(e,{...i,usage:0});return e.reduce((t,{typeName:e})=>(t.get(e).usage+=1,t),t)}class xe{#H;#st;#Bt;#ge;constructor(t,e,i,n){this.#H=t,this.#st=e,this.#Bt=i,this.#ge=n}get id(){return this.#H}get color(){return this.#st}get label(){return this.#Bt}get default(){return this.#ge}toJSON(){return{id:this.#H,color:this.#st,label:this.#Bt,default:this.#ge}}}class we{#ve;constructor(t=[]){this.#ve=t.map(t=>new xe(t.id,t.color,t.label,t.default))}has(t){return this.map.has(t)}get default(){return this.#ve.find(t=>!0===t.default)}replace(t,e){e=new xe(e.id,e.color,e.label,e.default);const i=this.#ve.findIndex(e=>e.id===t);-1!==i?this.#ve.splice(i,1,e):this.#ve.push(e)}delete(t){this.#ve=this.#ve.filter(e=>e.id!==t)}ids(){return this.map.keys()}getColorOf(t){return this.#ye(t)?.color}getLabelOf(t){return this.#ye(t)?.label}labelsIncludes(t){return this.#ve.filter(t=>t.label).filter(e=>e.label.includes(t))}get map(){return new Map(this.#ve.map(t=>[t.id,t]))}#ye(t){if(this.has(t))return this.map.get(t);const e=function(t,e){const i=function(t,e){const i=[];for(const n of t)-1!==n.indexOf("*")&&0===e.indexOf(n.slice(0,-1))&&i.push(n);return i}(t,e);return 0===i.length?null:function(t){let e="";for(const i of t)i.length>e.length&&(e=i);return e}(i)}(this.ids(),t);return this.map.get(e)}}function _e(t,e){const i=new URL(t,location);return i.searchParams.append("term",e),fetch(i.href).then(t=>t.ok?t.json():[])}class Se{#Nt;#Oe;#be=new we([]);#xe;#we;#_e;#Se="";#ke;constructor(t,e,i,n){this.#Nt=t,this.#Oe=e,this.#xe=i,this.#we=n}set autocompletionWs(t){this.#Se=t}set autocompletionFunction(t){this.#ke=t}get autocompletionWs(){return this.#Se}get annotationType(){return this.#Oe}get config(){const t=this.#$e;for(const[e,i]of t.entries()){const n=i.toJSON();i.id===this.defaultType?n.default=!0:delete n.default,t.set(e,n)}return[...t.values()]}set config(t){this.#be=new we(t);const e=this.#be.default;e?(delete e.default,this.#_e=e.id):this.#_e=null}has(t){return this.#be.has(t)}get(t){const e={...this.#be.map.get(t)};return this.#_e===t?(e.default=!0,e):(delete e.default,e)}replace(t,e){this.#be.replace(t,e),this.#Nt.emit(`textae-event.type-definition.${this.#Oe}.change`,e.id)}addDefinedType(t){if(void 0===t.color){const e=this.getColor(t.id);e!==this.#we&&(t.color=e)}if(void 0===t.label){const e=this.getLabel(t.id);e&&(t.label=e)}t.default&&(this.#_e=t.id),this.replace(t.id,t)}get defaultType(){return this.#_e?this.#_e:this.#xe().length>0?Oe(be(this.#$e,this.#xe()))[0]:"something"}set defaultType(t){this.#_e=t,this.#Nt.emit(`textae-event.type-definition.${this.#Oe}.change-default`,t)}get defaultColor(){return this.#we}getColor(t){return this.#be.getColorOf(t)||this.#we}getLabel(t){return this.#be.getLabelOf(t)}getURI(t){return ct(t)?t:void 0}searchByLabel(t,e){if("function"==typeof this.#ke){const i=this.#ke(t),n=this.mergeWithLocalData(i,t);return void e(n)}this.#Se?_e(this.#Se,t).then(i=>{const n=this.mergeWithLocalData(i,t);e(n)}):e(this.findByLabel(t))}findByLabel(t){return this.#be.labelsIncludes(t)}mergeWithLocalData(t,e){const i=this.findByLabel(e),n=(t||[]).filter(t=>!i.some(e=>t.id===e.id));return i.concat(n)}get pallet(){const t=be(this.#$e,this.#xe());return function(t,e,i,n,s){return t.map(t=>({id:t,label:i.getLabelOf(t)||void 0,defaultType:t===n,uri:ct(t)?t:void 0,color:i.getColorOf(t)||s,useNumber:e.get(t).usage}))}(Oe(t),t,this.#be,this.defaultType,this.#we)}get#$e(){const t=this.#be.map;for(const{typeName:e}of this.#xe())t.has(e)||t.set(e,new xe(e));return t}delete(t,e){this.#be.delete(t),this.#_e=e,this.#Nt.emit(`textae-event.type-definition.${this.#Oe}.delete`,t)}}class ke{constructor(t,e){this.valueType=t,this.pred=e}get values(){return console.assert(this._values,"this._values to return!"),this._values}get externalFormat(){return{pred:this.pred}}get _valuesClone(){if(console.assert(this._values,"this._values is necessary to clone!"),Array.isArray(this._values)&&0===this._values.length)return;const t=[];for(const e of this._values)t.push({...e});return t}}class $e extends ke{constructor(t,e){super(t,e.pred),this.default=!0,this.label=e.label,this.color=e.color}getLabel(){return this.label}getDisplayName(){return this.label?this.label:this.pred}getColor(){return this.color}get externalFormat(){return{...super.externalFormat,"value type":"flag",default:this.default,label:this.label,color:this.color}}}function Ce(t,e){return t<=e}function Te(t,e){return t<e}function Pe(t){if(t.startsWith("["))return e=>Ce(new Number(t.replace("[","")),e);if(t.startsWith("("))return e=>Te(new Number(t.replace("(","")),e);throw`${t} is not valid interval notation`}function Ee(t){if(t.endsWith("]"))return e=>Ce(e,new Number(t.replace("]","")));if(t.endsWith(")"))return e=>Te(e,new Number(t.replace(")","")));throw`${t} is not valid interval notation`}class Ae{constructor(t){const[e,i]=t.split(",");if(i?(this._lowwerCond=Pe(e),this._upperCond=Ee(i)):((e.startsWith("[")||e.startsWith("("))&&(this._lowwerCond=Pe(e),this._upperCond=t=>!0),(e.endsWith("]")||e.endsWith(")"))&&(this._lowwerCond=t=>!0,this._upperCond=Ee(e))),!this._lowwerCond||!this._upperCond)throw`${t} is not valid interval notation`}test(t){return this._lowwerCond(t)&&this._upperCond(t)}}function Me(t){return!Number.isNaN(parseFloat(t))}class Qe extends ke{constructor(t,e){super(t,e.pred),this.default=Me(e.default)?parseFloat(e.default):0,Me(e.min)&&(this.min=parseFloat(e.min)),Me(e.max)&&(this.max=parseFloat(e.max)),this.step=Me(e.step)?parseFloat(e.step):2,this._values=e.values||[]}getLabel(t){const e=this.#Ce(t);if(e&&e.label)return e.label}getDisplayName(t){return this.getLabel(t)||String(t)}getColor(t){const e=this.#Ce(t);return e&&e.color?e.color:null}#Ce(t){const e=this._values.filter(t=>"default"!==t.range).find(e=>new Ae(e.range).test(t));if(e)return e;const i=this._values.find(t=>"default"===t.range);return i||null}get externalFormat(){return{...super.externalFormat,"value type":"numeric",default:this.default,min:this.min,max:this.max,step:this.step,values:super._valuesClone}}}class De extends ke{constructor(t,e){super(t,e.pred),this._values=e.values||[]}get default(){return this.values.find(t=>t.default).id}getLabel(t){const e=this.#Ce(t);if(e&&e.label)return e.label}getDisplayName(t){return this.getLabel(t)}getColor(t){const e=this.#Ce(t);return e&&e.color?e.color:null}get values(){return this._values}get hasOnlyOneValue(){return 1===this._values.length}#Ce(t){return this.values.find(e=>e.id==t)}get externalFormat(){return{...super.externalFormat,"value type":"selection",values:super._valuesClone}}}class Re extends ke{constructor(t,e){super(t,e.pred),this.autocompletionWs=e.autocompletion_ws,this.default=e.default,Me(e["media height"])&&(this.mediaHeight=parseFloat(e["media height"])),this._values=e.values||[]}getLabel(t){const e=this.#Ce(t);if(e&&e.label)return e.label}getDisplayName(t){return this.getLabel(t)}getColor(t){const e=this.#Ce(t);return e&&e.color?e.color:null}#Ce(t){const e=this._values.filter(t=>"default"!==t.pattern).find(e=>new RegExp(e.pattern).test(t));if(e)return e;const i=this._values.find(t=>"default"===t.pattern);return i||null}get externalFormat(){return{...super.externalFormat,"value type":"string",autocompletion_ws:this.autocompletionWs,default:this.default,values:super._valuesClone,"media height":this.mediaHeight}}}function Ie(t,e){switch(t){case"flag":return new $e(t,e);case"numeric":return new Qe(t,e);case"selection":return new De(t,e);case"string":return new Re(t,e);default:throw new Error(`${t} of ${JSON.stringify(e)} is Uknown Attribute`)}}class Le{#Nt;#xe;#be=new Map;constructor(t,e){this.#Nt=t,this.#xe=e}get config(){return this.attributes.map(t=>t.externalFormat)}set config(t){this.#be=new Map((t||[]).map(t=>[t.pred,Ie(t["value type"],t)]))}create(t,e,i=null){null!==i&&this.#be.size!==i?this.#be=new Map(Array.from(this.#be.entries()).reduce((n,[s,o],r)=>(r===i&&n.push([e.pred,Ie(t,e)]),n.push([s,o]),n),[])):this.#be.set(e.pred,Ie(t,e)),this.#Nt.emit("textae-event.type-definition.attribute.create",e.pred)}get(t){return this.#be.get(t)}update(t,e){return this.#be=new Map(Array.from(this.#be.entries()).map(([i,n])=>i===t?[e.pred,Ie(n.valueType,e)]:[i,n])),this.#Nt.emit("textae-event.type-definition.attribute.change",e.pred),this.get(e.pred)}updateValues(t,e){const i=this.get(t).externalFormat;return this.update(t,{...i,values:e})}move(t,e){var i,n,s;this.#be=new Map((i=this.attributes,n=t,s=e,function(t,e,i){const n=e<0?t.length+e:e;if(n>=0&&n<t.length){const n=i<0?t.length+i:i,[s]=t.splice(e,1);t.splice(n,0,s)}}(i=[...i],n,s),i).map(t=>[t.pred,t]));const{pred:o}=this.attributes[-1===e?this.attributes.length-1:e];this.#Nt.emit("textae-event.type-definition.attribute.move",o)}delete(t){this.#be.delete(t),this.#Nt.emit("textae-event.type-definition.attribute.delete")}get attributes(){return Array.from(this.#be.values())||[]}isSelectionAttributeValueIndelible(t,e){return!!this.get(t).hasOnlyOneValue||!!this.#xe().some(i=>i.equalsTo(t,e))}getLabel(t,e){return console.assert(this.#be.has(t),`There is no attribute definition for ${t}.`),this.get(t).getLabel(e)}getDisplayName(t,e){return console.assert(this.#be.has(t),`There is no attribute definition for ${t}.`),this.get(t).getDisplayName(e)}getColor(t,e){if(this.#be.has(t))return this.get(t).getColor(e)}getIndexOf(t){return Array.from(this.#be.values()).findIndex(e=>e.pred===t)}getAttributeAt(t){return Array.from(this.#be.values())[t-1]}attributeCompareFunction(t,e){const i=this.getIndexOf(t.pred),n=this.getIndexOf(e.pred);return i!==n?i-n:t.id&&e.id?t.id.localeCompare(e.id):0}}class Ne{constructor(t,e){this._textBox=e,this._enable=!1,t.on("textae-event.control.button.push",({name:t,isPushed:e})=>{"auto adjust lineheight"===t&&(this._enable=e)})}updateLineHeight(){this._enable&&this._textBox.updateLineHeight()}}function je(t,e,i){for(const n of i)t[n]=(...t)=>{const i=e();return console.assert(i[n],`No ${n} method to forward`,i),i[n].apply(i,t)};return t}class ze{#Te;#Wt;#O;#Pe;#K;#T;#U;#G;#jt;#Vt;#Q;#Nt;constructor(t,e,i,n,s,o,r,a){this.#Te="",this.#K=new w(i,"namespace");const l=new Se(i,"relation",()=>this.#G.all,"#00CC66");this.#G=new Ht(e,i,this,l),this.#Wt=new de(()=>{for(const t of this.entityInstanceContainer.denotations)t.reflectTypeGapInTheHeight();this.#O.updateLineHeight(),i.emit("textae-event.annotation-data.entity-gap.change")}),this.#U=new Vt(t,i,this,this.#Wt),this.attributeDefinitionContainer=new Le(i,()=>this.#jt.all),this.#jt=new yt(i,this.#U,this.#G,this.#K,this.attributeDefinitionContainer),this.updatePosition=()=>{try{n.startWait(),s(),this.#Ee()}catch(t){console.error(t)}finally{n.endWait(),o()}},this.#O=me(e,this,a),this.#Pe=new Ne(i,this.#O),this.#T=new it(t,e,i,this.#O),je(this,()=>this.#T,["getDenotationSpan","isBoundaryCrossingWithOtherSpans","hasParentOf","validateNewDenotationSpan","validateNewBlockSpan","validateEditableText"]),this.denotationDefinitionContainer=new Se(i,"entity",()=>this.#U.denotations,"#77DDDD");const c=new Se(i,"entity",()=>this.#U.blocks,"#77DDDD");this.#Vt=new ye(i,this.denotationDefinitionContainer,c,l,this.attributeDefinitionContainer,r),i.on("textae-event.annotation-data.span.add",t=>{(t.isDenotation||t.isBlock)&&(this.#O.forceUpdate(),this.#Ee())}).on("textae-event.annotation-data.span.remove",t=>{(t.isDenotation||t.isBlock)&&(this.#O.forceUpdate(),this.#Ee())}).on("textae-event.annotation-data.entity.add",t=>{t.span.isDenotation&&this.#Pe.updateLineHeight()}).on("textae-event.annotation-data.entity.remove",t=>{t.span.isDenotation&&this.#Pe.updateLineHeight()}),i.on("textae-event.type-definition.entity.change",t=>{for(const e of this.#U.all)(e.typeName===t||t.lastIndexOf("*")===t.length-1&&e.typeName.indexOf(0===t.slice(0,-1)))&&e.updateElement()}).on("textae-event.type-definition.attribute.change",t=>this.#U.redrawEntitiesWithSpecifiedAttribute(t)).on("textae-event.type-definition.attribute.move",t=>this.#U.redrawEntitiesWithSpecifiedAttribute(t)).on("textae-event.type-definition.relation.change",t=>{for(const e of this.#G.all)(e.typeName===t||t.lastIndexOf("*")===t.length-1&&e.typeName.indexOf(0===t.slice(0,-1)))&&e.updateElement()}),this.#Q=e,this.#Nt=i}reset(t,e){console.assert(t.text,"This is not a json file of annotations."),this.#Vt.setTypeConfig(e),this.#Te=t.text,this.#O.render(this.sourceDoc),this.#Ae();const i=new ce(this,t);i.eval(),this.#Me(),this.#Nt.emit("textae-event.annotation-data.all.change",i.hasMultiTracks,i.rejects),this.reLayout()}set autocompletionFunction(t){this.#Vt.autocompletionFunction=t}get externalFormat(){return{text:this.#Te,denotations:(t=this,t.entityInstanceContainer.denotations.map(t=>({id:t.id,span:{begin:t.span.begin,end:t.span.end},obj:t.typeName}))),attributes:this.#jt.all.map(({externalFormat:t})=>t),relations:he(this),blocks:ue(this)};var t}getReplicationRanges(t,e){return function(t,e,i,n,s){return function(t,e,i){const n=t.substring(e,i),s=i-e,o=[];let r=0;for(let e=t.indexOf(n);-1!==e;e=t.indexOf(n,r))r=e+s,o.push({begin:e,end:r});return o}(t,e,i).filter(({begin:t})=>t!==e).filter(({begin:e,end:i})=>function(t,e,i,n){const s=t.charAt(e-1),o=t.charAt(i);return n(s)&&n(o)}(t,e,i,s)).filter(({begin:t,end:e})=>!n.find("denotation",t,e)).filter(({begin:t,end:e})=>!n.isBoundaryCrossingWithOtherSpans(t,e))}(this.sourceDoc,t.begin,t.end,this.#T,e)}get typeGap(){return this.#Wt}get textBox(){return this.#O}get sourceDoc(){return this.#Te.replaceAll(/\r\n/g," \n")}get typeDictionary(){return this.#Vt}get spanInstanceContainer(){return this.#T}getSpan(t){return this.#T.get(t)}get entityInstanceContainer(){return this.#U}get relationInstanceContainer(){return this.#G}get attributeInstanceContainer(){return this.#jt}get namespaceInstanceContainer(){return this.#K}get textSelection(){return this.#T.textSelection}findDenotation(t,e){return this.#T.find("denotation",t,e)}findBlock(t,e){return this.#T.find("block",t,e)}getTextBetween(t,e){return this.sourceDoc.substring(t,e)}changeTextBetween(t,e,i){this.#Te=`${this.#Te.slice(0,t)}${i}${this.#Te.slice(e)}`;const n=i.length-(e-t),s=this.#T.offsetSpans(t,e,n);return this.#O.render(this.sourceDoc),this.#Me(),this.#Nt.emit("textae-event.annotation-data.text.change"),s}hasCharacters(t){const{begin:e,end:i}=this.textSelection,n=this.getTextBetween(e,i);return t.removeBlankCharacters(n).length>0}getTextSelection(t,e){const{begin:i,end:n}=this.textSelection;return{begin:e.backFromBegin(this.sourceDoc,i,t),end:e.forwardFromEnd(this.sourceDoc,n-1,t)+1}}getInstanceContainerFor(t){switch(t){case"span":return this.#T;case"relation":return this.#G;case"entity":return this.#U;case"attribute":return this.#jt}}drawGridsInSight(){if(this.#Qe){const{clientHeight:t,clientWidth:e}=document.documentElement;for(const i of this.#T.allDenotationSpans)i.drawGrid(t,e);for(const i of this.#T.allBlockSpans)i.drawGrid(t,e),i.updateBackgroundPosition();for(const i of this.#G.all)i.render(t,e)}}reLayout(){this.#O.forceUpdate(),this.#Qe&&this.updatePosition()}set toolBarHeight(t){this.#U.toolBarHeight=t,this.#G.toolBarHeight=t}get#Qe(){const{clientHeight:t}=document.documentElement,{top:e,bottom:i}=this.#Q.getBoundingClientRect();return 0<=i&&e<=t}focusDenotation(t){console.assert(this.#U.hasDenotation(t),"The denotation does not exist.");const{span:e}=this.#U.get(t);e.focus()}#Me(){this.#T.renderAll(),this.#O.updateLineHeight(),this.drawGridsInSight()}#Ee(){this.#T.arrangeDenotationEntityPosition(),this.#T.arrangeBackgroundOfBlockSpanPosition(),this.#T.arrangeBlockEntityPosition();for(const t of this.#G.all)t.sourceEntity.span.isGridRendered&&t.targetEntity.span.isGridRendered&&t.redrawLineConsideringSelection()}#Ae(){this.#T.clear(),this.#U.clear(),this.#jt.clear(),this.#G.clear(),this.#K.clear(),I(this.#Q).innerHTML=""}}const Be={"delimiter characters":[" ",".","!","?",",",":",";","-","/","&","(",")","{","}","[","]","+","*","\\",'"',"'","\n","–"],"non-edge characters":[" ","\n"]};class qe{#De;#Re;constructor(){this.#De=[],this.#Re=[]}get delimiterCharacters(){return this.#De}get blankCharacters(){return this.#Re}set(t){const e={...Be,...t};return this.#De=e["delimiter characters"],this.#Re=e["non-edge characters"],t}isDelimiter(t){return this.#De.indexOf("ANY")>=0?1:this.#De.indexOf(t)>=0}isBlankCharacter(t){return this.#Re.indexOf(t)>=0}removeBlankCharacters(t){for(const e of this.#Re)t=t.replaceAll(e,"");return t}}class Ze{constructor(t){this._resetHistory(),this._eventEmitter=t,t.on("textae-event.type-definition.reset",()=>{this._removeConfigurationOperationsFromHistory(),this._trigger()}).on("textae-event.annotation-data.all.change",()=>{this._resetHistory(),this._trigger()}).on("textae-event.resource.annotation.save",()=>{this._trigger()}).on("textae-event.resource.configuration.save",()=>{this._trigger()})}push(t){this._histories.splice(this._pointer+1,this._histories.length-this._pointer,t),this._pointer++,this._trigger()}next(){this._pointer++;const t=this._histories[this._pointer];return this._trigger(),t}prev(){const t=this._histories[this._pointer];return this._pointer--,this._trigger(),t}get hasAnythingToUndo(){return this._pointer>-1}get hasAnythingToRedo(){return this._pointer<this._histories.length-1}_trigger(){this._eventEmitter.emit("textae-event.history.change",this)}_removeConfigurationOperationsFromHistory(){for(let t=0;t<this._histories.length;t++)this._histories[t].isExactly("configuration_command")&&(this._pointer--,this._histories.splice(t,1))}_resetHistory(){this._pointer=-1,this._histories=[]}}function Fe(t,e,i){i?console.log(`[${t.constructor.name}]`,e,i):console.log(`[${t.constructor.name}]`,e)}class Xe{get isEmpty(){return!1}isExactly(t){return this.kind.has(t)&&1===this.kind.size}}class He extends Xe{get kind(){return new Set(["annotation_command"])}}class We extends He{#Ht;#Oe;#Et;#Ie;constructor(t,e,i,n=null){super(),this.#Ht=t,this.#Oe=e,this.#Et=i,this.#Ie=n}execute(){this.#Et=this.#Ht.getInstanceContainerFor(this.#Oe).add(this.#Et),this.#Ie&&this.#Ie.add(this.#Oe,[this.#Et.id]),Fe(this,`${this.#Oe}: ${this.#Et.id}`)}revert(){return new Ve(this.#Ht,this.#Oe,this.#Et)}}class Ve extends He{#Ht;#Oe;#Et;constructor(t,e,i){super(),this.#Ht=t,this.#Oe=e,this.#Et=i}execute(){this.#Ht.getInstanceContainerFor(this.#Oe).remove(this.#Et.id),Fe(this,`${this.#Oe}: ${this.#Et.id}`)}revert(){return new We(this.#Ht,this.#Oe,this.#Et)}}class Ye extends Xe{get kind(){return new Set(["configuration_command"])}}class Ue extends Ye{constructor(t,e,i,n=null){super(),this._definitionContainer=t,this._attrDef=e,this._index=i,this._indexThatAddDefaultTo=n}execute(){const t=[...this._attrDef.values];if("selection"===this._attrDef.valueType&&t[this._index].default&&null===this._indexThatAddDefaultTo){let e=null;t.forEach((t,i)=>{null===e&&i!=this._index&&(e=i)}),t[e]={...t[e],default:!0}}this._deletedValue=t.splice(this._index,1)[0],"selection"===this._attrDef.valueType&&null!==this._indexThatAddDefaultTo&&(t[this._indexThatAddDefaultTo]={...t[this._indexThatAddDefaultTo],default:!0}),this._updatedAttrDef=this._definitionContainer.updateValues(this._attrDef.pred,t),Fe(this,`remove a value from an attrribute:${this._attrDef.pred}, index:${this._index}, updated values: \n ${t.map(t=>JSON.stringify(t)).join("\n ")}`)}revert(){return new Ge(this._definitionContainer,this._updatedAttrDef,this._deletedValue,this._index)}}class Ge extends Ye{constructor(t,e,i,n=null){super(),this._definitionContainer=t,this._pred=e.pred,this._index=n,this._value=i;const s=[...e.values];if("selection"===e.valueType&&i.default){this._indexThatRemoveDefaultFrom||(this._indexThatRemoveDefaultFrom=s.findIndex(t=>t.default));const t={...s[this._indexThatRemoveDefaultFrom]};delete t.default,s[this._indexThatRemoveDefaultFrom]=t}s.splice(n||s.length,0,i),this._modifiedValues=s}execute(){this._updatedAttrDef=this._definitionContainer.updateValues(this._pred,this._modifiedValues),Fe(this,`add a new value to attrribute:${this._pred}, value: ${JSON.stringify(this._value)}, index: ${this._index}, updated values: \n ${this._modifiedValues.map(t=>JSON.stringify(t)).join("\n ")}`)}revert(){return new Ue(this._definitionContainer,this._updatedAttrDef,this._updatedAttrDef.values.length-1,this._indexThatRemoveDefaultFrom)}}class Ke extends Xe{constructor(){super(),this._isExecuteSubCommandsInReverseOrderWhenRevert=!0}execute(){if(console.assert(this._subCommands,"_subCommands is necessary!"),this.isEmpty)return void(this.revert=()=>({execute(){}}));for(const t of this._subCommands)t.execute();this._afterInvoke&&this._afterInvoke();const t=this;this.revert=()=>({_subCommands:this._subCommands,_logMessage:this._logMessage,_afterInvoke:this._afterInvoke,_isExecuteSubCommandsInReverseOrderWhenRevert:this._isExecuteSubCommandsInReverseOrderWhenRevert,execute(){let e=this._subCommands.map(t=>t.revert());this._isExecuteSubCommandsInReverseOrderWhenRevert&&(e=e.reverse());for(const t of e)t.execute();this._afterInvoke&&this._afterInvoke(),Fe(t,`revert: ${this._logMessage}`)}}),Fe(this,this._logMessage)}get kind(){return this._subCommands.reduce((t,e)=>new Set([...t,...e.kind]),new Set)}get isEmpty(){return!this._subCommands||0===this._subCommands.length}}class Je extends Ye{constructor(t,e,i){super(),this._definitionContainer=t,this._attrDef=e,this._changedProperties=i}execute(){const t=this._attrDef.pred,[e,i]=function(t,e){const i=t.externalFormat,n=new Map;for(const[s,o]of e.entries())null===o&&void 0!==t[s]?(delete i[s],n.set(s,t[s])):null!==o&&(i[s]=o,n.set(s,void 0===t[s]?null:t[s]));return[i,n]}(this._attrDef,this._changedProperties);this._revertAttrDef=this._definitionContainer.update(t,e),this._revertChangedProperties=i,Fe(this,`change old pred:${t} to new attridute definition:${JSON.stringify(e)}`)}revert(){return new Je(this._definitionContainer,this._revertAttrDef,this._revertChangedProperties)}}class ti extends He{#Ht;#Le;#Ne;#je;#ze;#Be;#qe;constructor(t,e,i,n){super(),this.#Ht=t,this.#Le=e,this.#Ne=e.pred,this.#je=e.obj,this.#ze=i,this.#Be=n}execute(){this.#qe=this.#Ht.attributeInstanceContainer.change(this.#Le.id,this.#ze,this.#Be),Fe(this,`attribute: ${this.#Le.id} changed from ${this.#Ne}:${this.#je} to ${this.#qe.pred}:${this.#qe.obj}.`)}revert(){return new ti(this.#Ht,this.#qe,this.#Ne,this.#je)}}class ei extends Ke{constructor(t,e,i,n,s){super(),this._isExecuteSubCommandsInReverseOrderWhenRevert=!1;const o=[new Je(i,n,s)];let r=[];if(s.has("pred")){const i=e.attributeInstanceContainer.getSameDefinitionsAttributes(n.pred);r=i.map(t=>new ti(e,t,s.get("pred"),t.obj)),this._afterInvoke=()=>{t.emit("textae-event.commander.attributes.change",i)}}this._subCommands=o.concat(r),this._logMessage=`set ${[...s.entries()].map(([t,e])=>`${t}:${e}`)} to attribute definition ${n.pred}`}}class ii extends Ke{constructor(t,e,i,n,s){super();const o=[];for(const t of i){const e=t.attributes.find(t=>t.pred==n.pred&&t.obj!==s);e&&o.push(e)}this._subCommands=o.map(t=>new ti(e,t,null,s)),o.length&&(this._afterInvoke=()=>t.emit("textae-event.commander.attributes.change",o)),this._logMessage=`update obj ${s} to attributes: ${o.map(t=>t.id).join(",")}`}}function ni(t,e,i,n){if("string"===e.valueType&&n&&!e.values.some(t=>t.pattern===i)&&n!==e.getLabel(i))return new Ge(t,e,{pattern:i,label:n})}class si extends Ke{constructor(t,e,i,n,s,o,r=null){super();const a=[];for(const t of n){const e=t.attributes.find(t=>t.pred==s.pred&&t.obj!==o);e&&a.push(e)}this._subCommands=a.map(t=>new ti(e,t,null,o)),a.length&&(this._afterInvoke=()=>t.emit("textae-event.commander.attributes.change",a));const l=ni(i,s,o,r);l&&this._subCommands.push(l),this._logMessage=`update obj ${o} to attributes: ${a.map(t=>t.id).join(",")}`}}class oi extends He{#Ze;#Oe;#H;#Fe;constructor(t,e,i,n){super(),this.#Ze=t,this.#Oe=e,this.#H=i,this.#Fe=n}execute(){this.oldType=this.#Ze.getInstanceContainerFor(this.#Oe).get(this.#H).typeName;const t=this.#Ze.getInstanceContainerFor(this.#Oe).changeType(this.#H,this.#Fe);Fe(this,`change type of a ${this.#Oe}. old type:${this.oldType} ${this.#Oe}:`,t)}revert(){return new oi(this.#Ze,this.#Oe,this.#H,this.oldType)}}class ri extends Ke{constructor(t,e,i,n,s){super();const o=e[i].all.filter(t=>!t.typeValues.isSameType(n,s));this._subCommands=o.map(e=>new oi(t,i,e.id,n)),this._subCommands=this._subCommands.concat(function(t,e,i){const n=[];for(const s of t){if(s.typeValues)for(const t of s.attributes){const s=e.find(e=>t.equalsTo(e.pred,e.obj));s?String(t.obj)!==s.obj&&n.push(new ti(i,t,s.pred,s.obj)):n.push(new Ve(i,"attribute",t))}for(const t of e)s.attributes.some(e=>e.equalsTo(t.pred,t.obj))||n.push(new We(i,"attribute",{subj:s.id,pred:t.pred,obj:t.obj}))}return n}(o,s,t));for(const{pred:e,obj:i,label:n}of s){const s=t.typeDictionary.attribute,o=s.get(e),r=ni(s,o,i,n);r&&this._subCommands.push(r)}this._logMessage=`set type ${n}${s.length>0?` and attributes ${JSON.stringify(s)}`:""} to ${i} items ${o.map(t=>t.id)}`}}class ai extends Ye{constructor(t,e,i,n,s){super(),this._annotationModel=t,this._definitionContainer=e,this._id=i,this._changedProperties=n,this._newDefaultTypeId=s}execute(){const t=this._definitionContainer.get(this._id),[e,i]=function(t,e){const i={...e},n=new Map;for(const[s,o]of t.entries())null===o&&void 0!==e[s]?(delete i[s],n.set(s,e[s])):null!==o&&(i[s]=o,n.set(s,void 0===e[s]?null:e[s]));return[i,n]}(this._changedProperties,t);this._definitionContainer.replace(this._id,e),e.default?(this.revertDefaultTypeId=this._definitionContainer.defaultType,this._definitionContainer.defaultType=e.id):this._newDefaultTypeId&&(this._definitionContainer.defaultType=this._newDefaultTypeId),this.revertId=e.id,this.revertChangedProperties=i,Fe(this,`change old type:${JSON.stringify(t)} to new type:${JSON.stringify(e)}, default is ${this._definitionContainer.defaultType}`)}revert(){return new ai(this._annotationModel,this._definitionContainer,this.revertId,this.revertChangedProperties,this.revertDefaultTypeId)}}class li extends Ye{constructor(t,e,i){super(),this._definitionContainer=t,this._removeType=e,this._revertDefaultTypeId=i}execute(){const{id:t}=this._removeType,e=this._definitionContainer.get(t);this._definitionContainer.delete(t,this._revertDefaultTypeId),e&&(this._removeType=e),Fe(this,`remove a type:${JSON.stringify(this._removeType)}, default is ${this._definitionContainer.defaultType}`)}revert(){return new ci(this._definitionContainer,this._removeType)}}class ci extends Ye{constructor(t,e){super(),this._definitionContainer=t,this._newType=e}execute(){this._revertDefaultTypeId=this._definitionContainer._defaultType,this._definitionContainer.addDefinedType(this._newType),Fe(this,`create a new type:${JSON.stringify(this._newType)}, default is ${this._definitionContainer.defaultType}`)}revert(){return new li(this._definitionContainer,this._newType,this._revertDefaultTypeId)}}function hi(t,e,i,n){return t.has(e)?new ai(i,t,e,n,null):new ci(t,{id:e,...Object.fromEntries(n)})}class ui extends Ke{constructor(t,e,i,n,s,o){super();const r=[];i&&r.push(hi(s,n,t,new Map([["label",i]])));const a=new ri(t,e,s.annotationType,n,o);a.isEmpty||r.push(a),this._subCommands=r,this._logMessage=`change ${s.annotationType} value:"${n}"${i?`, label:"${i}"`:""}${o.length>0?`, attributes:${JSON.stringify(o)}`:""}`}}class di extends Ke{constructor(t,e,i,n,s){super();const o=[hi(e,n,t,s)];let r=[];s.has("id")&&(r=function(t,e,i,n){return t.getInstanceContainerFor(e).all.filter(t=>t.typeName===i).map(i=>new oi(t,e,i.id,n))}(t,i,n,s.get("id"))),this._subCommands=o.concat(r),this._logMessage=`set ${[...s.entries()].map(([t,e])=>`${t}:${e}`)} to type definition ${n}`}}class fi extends Ke{constructor(t,e,i,n){super();const s=e[i].all.filter(t=>!t.typeValues.isSameType(n));this._subCommands=s.map(e=>new oi(t,i,e.id,n)),this._logMessage=`set type ${n} to ${i} items ${s}`}}class pi extends Ye{constructor(t,e,i,n,s){super(),this._definitionContainer=t,this._attrDef=e,this._targetIndex=i,this._newValue=n,this._indexThatRemoveDefaultFrom=s}execute(){if("selection"===this._attrDef["value type"]&&(!this._attrDef.values[this._targetIndex].default&&this._newValue.default&&(this._indexThatRemoveDefaultFrom||(this._indexThatRemoveDefaultFrom=this._attrDef.values.findIndex(t=>t.default)),delete this._attrDef.values[this._indexThatRemoveDefaultFrom].default),this._attrDef.values[this._targetIndex].default&&!this._newValue.default))if(1===this._attrDef.values.length)this._newValue.default=!0;else if(this._indexThatRemoveDefaultFrom)this._attrDef.values[this._indexThatRemoveDefaultFrom].default=!0;else{let t=null;this._attrDef.values.forEach((e,i)=>{null===t&&i!=this._targetIndex&&(t=i)}),this._attrDef.values[t].default=!0,this._indexThatRemoveDefaultFrom=t}this._valueBeforeChange=this._attrDef.values.splice(this._targetIndex,1,this._newValue)[0],this._definitionContainer.update(this._attrDef.pred,this._attrDef),Fe(this,`change value of attrribute:${this._attrDef.pred}, oldValue: ${JSON.stringify(this._valueBeforeChange)}, newValue: ${JSON.stringify(this._newValue)}`)}revert(){return new pi(this._definitionContainer,this._attrDef,this._targetIndex,this._valueBeforeChange,this._indexThatRemoveDefaultFrom)}}class mi extends Ke{constructor(t,e,i,n,s,o,r){if(super(),this._subCommands=[new pi(i,n,s,o,r)],"selection"===n["value type"]&&n.values[s].id!==o.id){const i=e.attributeInstanceContainer.getSameAttributes(n.pred,n.values[s].id),r=i.map(t=>new ti(e,t,null,o.id));this._subCommands=this._subCommands.concat(r),this._afterInvoke=()=>t.emit("textae-event.commander.attributes.change",i)}this._logMessage=`attribute: ${n.pred}`}}class gi extends Ye{constructor(t,e){super(),this._definitionContainer=t,this._removeAttrdef=e,this._index=t.getIndexOf(e.pred)}execute(){this._definitionContainer.delete(this._removeAttrdef.pred),Fe(this,`remove an attrribute definition:${JSON.stringify(this._removeAttrdef)}, index:${this._index}`)}revert(){return new vi(this._definitionContainer,this._removeAttrdef,this._index)}}class vi extends Ye{constructor(t,e,i){super(),this._definitionContainer=t,this._newAttrDef=e,this._index=i}execute(){"selection"!==this._newAttrDef.valueType||this._newAttrDef.values||(this._newAttrDef.values=[{id:"default",default:!0}]),this._definitionContainer.create(this._newAttrDef.valueType,this._newAttrDef,this._index),Fe(this,`create a new attrribute definition:${JSON.stringify(this._newAttrDef)}, index: ${this._index}`)}revert(){return new gi(this._definitionContainer,this._newAttrDef)}}function yi(t,e,i,n){return e.filter(t=>!t.typeValues.hasSpecificPredicateAttribute(i)).map(({id:e})=>new We(t,"attribute",{id:null,subj:e,pred:i,obj:n}))}class Oi extends Ke{constructor(t,e,i,n){super(),this._subCommands=yi(t,e,i.pred,n||i.default),this._logMessage=`create attirbute ${i.pred}:${i.default} to item ${e.map(({id:t})=>t).join(", ")}`}}class bi extends We{constructor(t,e,i){super(t,"attribute",{obj:e,pred:i})}execute(){const t=this._annotationModel.entityInstanceContainer.all.pop().id;return this._instance.subj=t,super.execute()}}class xi extends Ke{constructor(t,e,i,n,s,o,r){super(),this._subCommands=[new We(t,"entity",{spanType:i,begin:n,end:s,typeName:o},e)].concat(r.map(({obj:e,pred:i})=>new bi(t,e,i))),this._logMessage=`span: ${n}:${s}, type: ${o}${r.length?`, attributes: ${r.map(({pred:t})=>t).join(", ")}`:""}`}}class wi extends Ke{constructor(t,e,i,n,s,o){super();const r=new We(e,"span",{begin:n,end:s,isBlock:!0},i),a=new xi(e,i,"block",n,s,o,[]);this._subCommands=[r,a],this._logMessage=`create a span ${n}:${s} with type ${o}`}}class _i extends Ke{constructor(t,e,i){super();const n=e.span.all.filter(t=>t.isDenotation);this._subCommands=n.map(n=>new We(t,"entity",{spanType:"denotation",begin:n.begin,end:n.end,typeName:i},e)),this._logMessage=`create a ${i} type entity to ${n}`}}class Si extends Ke{constructor(t,e,i,n,s,o){super(),this._subCommands=[new We(t,"span",{begin:n,end:s},e)].concat(o.map(i=>new xi(t,e,"denotation",n,s,i.typeName,i.attributes))),this._logMessage=`span: ${n}:${s}, types: ${o.map(({typeName:t})=>t).join(", ")}`}}class ki extends Ke{constructor(t,e,i,n,s,o){super(),console.log(n),this._subCommands=e.getReplicationRanges(n,o).map(({begin:n,end:o})=>new Si(e,i,t,n,o,s)),this._logMessage=`from span: ${n.id}`}}class $i extends Ke{constructor(t,e,i,n,s,o,r){super();const a=[new Ot(s)];this._subCommands=[new Si(e,i,t,n.begin,n.end,a)],this._logMessage=`create a span ${n.begin}:${n.end} with type ${a[0].typeName}`,o&&n.end-n.begin<=100&&(this._subCommands.push(new ki(t,e,i,{begin:n.begin,end:n.end},a,r)),this._logMessage=`${this._logMessage} and replicate auto`)}}class Ci extends Ye{constructor(t,e,i){super(),this._definitionContainer=t,this._oldIndex=e,this._newIndex=i}execute(){this._definitionContainer.move(this._oldIndex,this._newIndex),Fe(this,`move the attrribute definition: from ${this._oldIndex} to ${this._newIndex}`)}revert(){return new Ci(this._definitionContainer,this._newIndex,this._oldIndex)}}class Ti extends He{#T;#Xe;#He;#We;#Ve;constructor(t,e,i,n,s){super(),this.#T=t,this.#Xe=e,this.#He=i,this.#We=n,this.#Ve=s}execute(){this.#T.moveBlockSpan(this.#Xe,this.#He,this.#We,this.#Ve),Fe(this,`move span: from {begin: ${this.#Xe}, end: ${this.#He} } to {begin: ${this.#We}, end: ${this.#Ve}}`)}revert(){return new Ti(this.#T,this.#We,this.#Ve,this.#Xe,this.#He)}}class Pi extends He{#T;#Xe;#He;#We;#Ve;constructor(t,e,i,n,s){super(),this.#T=t,this.#Xe=e,this.#He=i,this.#We=n,this.#Ve=s}execute(){this.#T.moveDenotationSpan(this.#Xe,this.#He,this.#We,this.#Ve),Fe(this,`move span: from {begin: ${this.#Xe}, end: ${this.#He} } to {begin: ${this.#We}, end: ${this.#Ve}}`)}revert(){return new Pi(this.#T,this.#We,this.#Ve,this.#Xe,this.#He)}}function Ei(t,e){return t.entities.every(t=>e.includes(t))}class Ai extends Ke{constructor(t,e){super(),this._subCommands=[];for(const[i,n]of e.entries())this._subCommands.push(new Mi(t,i,n));this._logMessage=`revert: move entities ${Array.from(e.values()).flat().map(t=>t.id).join(", ")}`}}class Mi extends He{constructor(t,e,i){super(),this._annotationModel=t,this._span=e,this._entities=i}execute(){this._moveMap=this._entities.reduce((t,e)=>(t.has(e.span)?t.get(e.span).push(e):t.set(e.span,[e]),t),new Map);const t=`${Array.from(this._moveMap.entries()).map(([t,e])=>`${e.map(t=>t.id).join(", ")} from ${e[0].span.id} to ${this._span.id}`).join(", ")}`;this._annotationModel.entityInstanceContainer.moveEntities(this._span,this._entities),Fe(this,t)}revert(){return new Ai(this._annotationModel,this._moveMap)}}class Qi extends Ke{constructor(t,e,i){console.assert(e.span.single,"There must be one span to be pasted."),super();const n=[new Mi(t,e.span.single,i)];for(const e of i.map(t=>t.span).reduce((t,e)=>(t.add(e),t),new Set).values())Ei(e,i)&&n.push(new Ve(t,"span",e));this._subCommands=n,this._logMessage="paste cut entities"}}class Di extends Ke{constructor(t,e,i,n,s,o){super();const r=e.span.all;this._subCommands=[];for(const e of n)this._subCommands.push(new ci(t.denotationDefinitionContainer,e));for(const e of s)this._subCommands.push(new vi(t.attributeInstanceContainerDefinitionContainer,{valueType:e["value type"],...e}));for(const{pred:e,value:i}of o)this._subCommands.push(new Ge(t.attributeInstanceContainerDefinitionContainer,t.attributeInstanceContainerDefinitionContainer.get(e),i));this._subCommands=this._subCommands.concat(r.map(n=>i.map(i=>new xi(t,e,"denotation",n.begin,n.end,i.typeName,i.attributes))).flat()),this._logMessage=`paste types [${i.map(({typeName:t,attributes:e})=>[`{type:${t}}`].concat(e.map(({pred:t,obj:e})=>`{${t}:${e}}`)))}] to ${r}`}}function Ri(t,e,i){return e.reduce((t,{attributes:e})=>t.concat(e),[]).filter(t=>t.pred===i).map(e=>new Ve(t,"attribute",e))}class Ii extends Ke{constructor(t,e,i){super();const n=Ri(t,e,i.pred);this._subCommands=n,this._logMessage=`remove ${i.pred} attribute from items ${e.map(t=>t.id).join(", ")}`}}function Li(t,e,i){t.add(i);for(const t of i.attributes)e.add(t)}function Ni(t,e,i,n){t.add(n);for(const t of n.attributes)i.add(t);for(const t of n.relations)Li(e,i,t)}class ji extends Ke{constructor(t,e){super();const i=new Set,n=new Set,s=new Set,o=new Set;for(const t of e.span.all){i.add(t);for(const e of t.entities)Ni(n,s,o,e)}for(const t of e.entity.all)Ni(n,s,o,t);for(const t of e.relation.all)Li(s,o,t);for(const n of t.spanInstanceContainer.all)n.entities.every(t=>e.entity.all.includes(t))&&(n.styleOnly||i.add(n));this._subCommands=[];for(const e of o)this._subCommands.push(new Ve(t,"attribute",e));for(const e of s)this._subCommands.push(new Ve(t,"relation",e));for(const e of n)this._subCommands.push(new Ve(t,"entity",e));for(const e of i)this._subCommands.push(new Ve(t,"span",e));this._logMessage=`remove selected ${[...i,...n,...s,...o].map(({id:t})=>t).join(", ")}`}}class zi extends Ke{constructor(t,e){super();const i=new Ve(t,"relation",e),n=e.attributes.map(e=>new Ve(t,"attribute",e));this._subCommands=n.concat(i),this._logMessage=`remove a relation ${e.id}`}}class Bi extends Ke{constructor(t,e){super();const i=new Ve(t,"entity",e),n=e.relations.map(e=>new zi(t,e)),s=e.attributes.map(e=>new Ve(t,"attribute",e));this._subCommands=n.concat(s).concat(i),this._logMessage=`remove an entity ${e.id}`}}class qi extends Ke{constructor(t,e){super();const i=t.getSpan(e),n=i.entities.map(e=>new Bi(t,e)),s=new Ve(t,"span",i);this._subCommands=n.concat(s),this._logMessage=`remove a span ${e}`}}class Zi extends Ke{constructor(t,e,i){super(),this._subCommands=yi(t,e,i.pred,i.default);const n=Ri(t,e,i.pred);this._subCommands=this._subCommands.concat(n),this._logMessage=`toggle flag attirbute ${i.pred} to item ${e.map(({id:t})=>t).join(", ")}`}}class Fi extends He{#Ht;#Ye;#Ue;#Ge;#Ke;#Je;constructor(t,e,i){super(),this.#Ht=t,this.#Ye=e.begin,this.#Ue=e.end,this.#Ge=i}execute(){this.#Ke=this.#Ye+this.#Ge.length,this.#Je=this.#Ht.getTextBetween(this.#Ye,this.#Ue);const t=this.#Ht.changeTextBetween(this.#Ye,this.#Ue,this.#Ge);Fe(this,`change text at ${this.#Ye}:${this.#Ue} to ${this.#Ge} and spans [${t.map(({begin:t,end:e})=>`${t}:${e}`).join(", ")}] are effected.`)}revert(){return new Fi(this.#Ht,{begin:this.#Ye,end:this.#Ke},this.#Je)}}class Xi extends Ke{constructor(t,e,i,n){super(),this._isExecuteSubCommandsInReverseOrderWhenRevert=!1,this._subCommands=[new Fi(t,{begin:e,end:i},n)],this._logMessage=`change text from ${e} to ${i} to ${n}`}}class Hi{#M;#Nt;#Ht;#Ie;constructor(t,e,i,n){this.#M=t,this.#Nt=e,this.#Ht=i,this.#Ie=n}addValueToAttributeDefinitionCommand(t,e){return new Ge(this.#Ht.typeDictionary.attribute,t,e)}changeAttributeDefinitionCommand(t,e){return new ei(this.#Nt,this.#Ht,this.#Ht.typeDictionary.attribute,t,e)}changeAttributeObjOfItemsCommand(t,e,i){return new ii(this.#Nt,this.#Ht,t,e,i)}changeStringAttributeObjOfItemsCommand(t,e,i,n){return new si(this.#Nt,this.#Ht,this.#Ht.typeDictionary.attribute,t,e,i,n)}changeTypeValuesCommand(t,e,i,n){return new ui(this.#Ht,this.#Ie,t,e,i,n)}changeTypeDefinitionCommand(t,e,i,n){return new di(this.#Ht,t,e,i,n)}changeTypeOfSelectedItemsCommand(t,e){return new fi(this.#Ht,this.#Ie,t,e)}changeValueOfAttributeDefinitionAndObjectOfSelectionAttributeCommand(t,e,i){return new mi(this.#Nt,this.#Ht,this.#Ht.typeDictionary.attribute,t,e,i)}createAttributeDefinitionCommand(t){return new vi(this.#Ht.typeDictionary.attribute,t)}createAttributeToItemsCommand(t,e,i=null){return new Oi(this.#Ht,t,e,i)}createBlockSpanCommand(t){return new wi(this.#M,this.#Ht,this.#Ie,t.begin,t.end,this.#Ht.typeDictionary.block.defaultType)}createDefaultTypeEntityToSelectedSpansCommand(t){return new _i(this.#Ht,this.#Ie,t)}createRelationCommand(t){return new We(this.#Ht,"relation",t,this.#Ie)}createSpanAndAutoReplicateCommand(t,e,i){return new $i(this.#M,this.#Ht,this.#Ie,t,this.#Ht.typeDictionary.denotation.defaultType,e,i)}createTypeDefinitionCommand(t,e){return new ci(t,e)}deleteAttributeDefinitionCommand(t){return new gi(this.#Ht.typeDictionary.attribute,t)}moveAttributeDefinitionCommand(t,e){return new Ci(this.#Ht.typeDictionary.attribute,t,e)}moveBlockSpanCommand(t,e,i){const{begin:n,end:s}=this.#Ht.getSpan(t);return new Ti(this.#Ht.spanInstanceContainer,n,s,e,i)}moveDenotationSpanCommand(t,e,i){const{begin:n,end:s}=this.#Ht.getSpan(t);return new Pi(this.#Ht.spanInstanceContainer,n,s,e,i)}moveEntitiesToSelectedSpanCommand(t){return new Qi(this.#Ht,this.#Ie,t)}pasteTypesToSelectedSpansCommand(t,e=[],i=[],n=[]){return new Di(this.#Ht,this.#Ie,t,e,i,n)}replicateSpanCommand(t,e,i){return new ki(this.#M,this.#Ht,this.#Ie,t,e,i)}removeAttributesFromItemsByPredCommand(t,e){return new Ii(this.#Ht,t,e)}removeSpanCommand(t){return new qi(this.#Ht,t)}removeSelectedCommand(){return new ji(this.#Ht,this.#Ie)}removeTypeDefinitionCommand(t,e){return new li(t,e)}removeValueFromAttributeDefinitionCommand(t,e){return new Ue(this.#Ht.typeDictionary.attribute,t,e)}toggleFlagAttributeToItemsCommand(t,e){return new Zi(this.#Ht,t,e)}changeTextAndMoveSpanCommand(t,e,i){return new Xi(this.#Ht,t,e,i)}}class Wi{#Q;#M;#Nt;#Ht;#Ie;#ti;constructor(t,e,i,n,s){this.#Q=t,this.#M=e,this.#Nt=i,this.#Ht=n,this.#Ie=s,this.#ti=new Ze(i)}invoke(t){t.isEmpty||(t.execute(),this.#ti.push(t))}undo(){if(this.#ti.hasAnythingToUndo){this.#Ie.removeAll(),this.#Q.focus();const t=this.#ti.prev();t.kind.has("configuration_command")&&e().success("configuration has been undone"),t.revert().execute()}}redo(){if(this.#ti.hasAnythingToRedo){this.#Ie.removeAll();const t=this.#ti.next();t.kind.has("configuration_command")&&e().success("configuration has been redo"),t.execute()}}get factory(){return new Hi(this.#M,this.#Nt,this.#Ht,this.#Ie,this.#Ht.typeDictionary)}}class Vi{constructor(t,e){this._editorHTMLElement=t,this._selectionModel=e}left(t){const e=this._searchLeft(".textae-editor__span");if(e)return void(t?this._selectionModel.add("span",[e.id]):this._selectionModel.selectSpan(e.id));const i=this._searchLeft(".textae-editor__grid .textae-editor__signboard");i&&(t?this._selectionModel.add("entity",[i.dataset.id]):this._selectionModel.selectEntity(i.dataset.id))}right(t){const e=this._searchRight(".textae-editor__span");if(e)return void(t?this._selectionModel.add("span",[e.id]):this._selectionModel.selectSpan(e.id));const i=this._searchRight(".textae-editor__grid .textae-editor__signboard");i&&(t?this._selectionModel.add("entity",[i.dataset.id]):this._selectionModel.selectEntity(i.dataset.id))}_searchLeft(t){const e=this._editorHTMLElement.querySelectorAll(t),i=[...e].findIndex(t=>t.classList.contains("ui-selected")||t.classList.contains("textae-editor__signboard--selected"));if(i>0)return e[i-1]}_searchRight(t){const e=this._editorHTMLElement.querySelectorAll(t),i=[...e].reverse().findIndex(t=>t.classList.contains("ui-selected")||t.classList.contains("textae-editor__signboard--selected"));if(e.length-i>0)return e[e.length-i]}}class Yi{constructor(t,e){this._editorHTMLElement=t,this._selectionModel=e}up(){if(this._selectionModel.span.single){const t=this._selectionModel.span.single.gridElement.querySelector(".textae-editor__signboard");this._selectionModel.selectEntity(t.dataset.id)}}down(){const t=this._editorHTMLElement.querySelector(".textae-editor__signboard--selected");if(t){const e=t.closest(".textae-editor__grid").id.substring(1);this._selectionModel.selectSpan(e)}}}function Ui(t){return s()(t,300)}function Gi(t,e){r()(t,".textae-editor__setting-dialog__line-height-text","change",Ui(t=>{e.lineHeight=t.target.value,function(){const t=new Event("resize");window.dispatchEvent(t)}()}))}function Ki(t,e,i,n,s,o){!function(t,e,i){r()(t,".textae-editor__setting-dialog__type-gap-text","change",Ui(n=>{e.value=Number(n.target.value),t.querySelector(".textae-editor__setting-dialog__line-height-text").value=i.lineHeight}))}(t,i,s),Gi(t,s),function(t,e){r()(t,".textae-editor__setting-dialog__lock-config-text","change",Ui(t=>{t.target.checked?e.lockEdit():e.unlockEdit()}))}(t,n),function(t,e,i){r()(t,".textae-editor__setting-dialog__function-availability-checkbox","change",Ui(({target:t})=>{const n=t.closest(".textae-editor__setting-dialog__function-availability-label").textContent.trim();t.checked?(i.enable(n),e.emit("textae-event.configuration.reset")):(i.disable(n),e.emit("textae-event.configuration.reset"))}))}(t,e,o)}const Ji="14.1.2";class tn{static escape(t){return t.replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")}static decode(t){return t.replace(/\\n/g,"\n").replace(/\\t/g,"\t").replace(/\\r/g,"\r")}}function en(t){const e=tn.escape(t);return st()(e)}function nn(t){const{typeGap:e,typeGapDisabled:i,lineHeight:n,autocompletionWs:s,typeDictionaryLocked:o,delimiterCharacters:r,blankCharacters:a,functionAvailability:l,version:c}=t;return ot`
210
+ `}}class Ft{#c;#mt;#Qt;#Dt;#Rt;#It;constructor(t,e,i,n,s,o){this.#c=I(t),this.#mt=e,this.#Qt=i,this.#Dt=l().create('<div class="textae-editor__relation__signboard-location"></div>'),this.#Lt(),this.#Rt=new Zt(e,"relation",null),this.#Dt.appendChild(this.#Rt.element),this.#c.appendChild(this.#Dt),this.#Dt.addEventListener("click",n),this.#Dt.addEventListener("mouseenter",s),this.#Dt.addEventListener("mouseleave",o)}updateValue(){this.#Lt(),this.#Rt.updateLabel()}updateHighlighting(){this.#Lt(),this.#Rt.clearCSSClass(),this.#mt.isSelected?this.#Rt.select():this.#mt.isHovered&&this.#Rt.hover()}destructor(){this.#c.removeChild(this.#Dt)}get y(){return this.#It.getBBox().y}get width(){return this.#Dt.getBBox().width}get height(){return this.#Dt.getBBox().height}#Lt(){this.#Dt.style.width="0px",this.#Dt.style.left=`${this.#Qt.highestX}px`,this.#Dt.style.top=this.#Qt.top-18-18*this.#mt.attributes.length+"px"}}class Xt{#Q;#Nt;#U;#jt;#H;#ft;#W;#Y;#K;#J;#gt;#u;#zt;#Qt;#Bt;constructor(t,e,i,n,s,{id:o,pred:r,subj:a,obj:l},c,h){this.#Q=t,this.#Nt=e,this.#U=i,this.#jt=n,this.#H=o,this.#W=a,this.#Y=l,this.#K=s,this.#J=c,this.#gt=h,this.#u=!1,this.#zt=!1,this.typeName=r}get id(){return this.#H}set id(t){this.#H=t}get typeName(){return this.#ft}set typeName(t){this.#ft=String(t)}get typeValues(){return new Ot(this.#ft,this.#jt.getAttributesFor(this.#H))}get subj(){return this.#W}get obj(){return this.#Y}get attributes(){return this.#jt.getAttributesFor(this.#H)}get sourceEntity(){return this.#U.get(this.subj)}get targetEntity(){return this.#U.get(this.obj)}get sourceColor(){return this.sourceEntity.color}get targetColor(){return this.targetEntity.color}get isSelected(){return this.#u}get isHovered(){return this.#zt}select(){this.#u||(this.#u=!0,this.#Bt&&this.#Bt.updateHighlighting())}deselect(){this.#u&&(this.#u=!1,(this.#Qt||this.#Bt)&&this.redrawLineConsideringSelection())}render(t,e){this.sourceEntity.isInViewport(t,e)||this.targetEntity.isInViewport(t,e)?(this.#Qt?this.#qt():(this.#Qt=new zt(this.#Q,this,this.#gt,t=>{this.#Nt.emit("textae-event.editor.relation.click",t,this),t.stopPropagation()},(t,e)=>{this.#Nt.emit("textae-event.editor.relation-bollard.click",t,e),t.stopPropagation()},()=>this.#Zt(),()=>this.#Ft()),this.#Bt=new Ft(this.#Q,this,this.#Qt,(t,e)=>{this.#Nt.emit("textae-event.editor.relation.click",t,this,e),t.stopPropagation()},()=>this.#Zt(),()=>this.#Ft())),this.sourceEntity.clientTop>this.targetEntity.clientTop&&this.targetEntity.isInViewport(t,e)||this.sourceEntity.clientTop<this.targetEntity.clientTop&&this.sourceEntity.isInViewport(t,e)||this.sourceEntity.clientTop===this.targetEntity.clientTop?this.#Bt?this.#Xt():(this.#Bt=new Ft(this.#Q,this,this.#Qt,(t,e)=>{this.#Nt.emit("textae-event.editor.relation.click",t,this,e),t.stopPropagation()},()=>this.#Zt(),()=>this.#Ft()),this.#Bt.updateHighlighting()):this.#Bt&&(this.#Bt.destructor(),this.#Bt=void 0)):(this.#Qt||this.#Bt)&&this.erase()}updateElement(){this.#Qt&&this.#Qt.update(this.isSelected,this.isSelected,this.isSelected),this.#Bt&&this.#Bt.updateValue()}redrawLineConsideringSelection(){this.#qt(),this.#Xt()}pointUpPathAndSourceBollards(){this.#Qt&&(this.targetEntity.isSelected?this.#Qt.update(!0,!0,!0):this.#Qt.update(!0,!0,this.isSelected)),this.#Bt&&this.#Bt.updateHighlighting()}pointUpPathAndTargetBollards(){this.#Qt&&(this.sourceEntity.isSelected?this.#Qt.update(!0,!0,!0):this.#Qt.update(!0,this.isSelected,!0)),this.#Bt&&this.#Bt.updateHighlighting()}pointUpSourceBollardsAndTargetBollards(){this.#Qt&&this.#Qt.update(this.isSelected,!0,!0),this.#Bt&&this.#Bt.updateHighlighting()}pointUpSourceBollards(){this.#Qt&&this.#Qt.update(this.isSelected,!0,this.isSelected),this.#Bt&&this.#Bt.updateHighlighting()}pointUpTargetBollards(){this.#Qt&&this.#Qt.update(this.isSelected,this.isSelected,!0),this.#Bt&&this.#Bt.updateHighlighting()}erase(){this.#Qt&&(this.#Qt.destructor(),this.#Qt=void 0),this.#Bt&&(this.#Bt.destructor(),this.#Bt=void 0)}get title(){return`[${this.id}] pred: type, value: ${this.typeName}`}get color(){return this.#J.getColor(this.typeName)}get anchorHTML(){return pt(this.#lt,this.#nt)}get#lt(){return ht(this.#K,this.typeName,this.#J.getLabel(this.typeName))}get#nt(){return ft(this.#K,this.typeName,this.#J.getURI(this.typeName))}#Zt(){this.#zt=!0,this.#Qt.update(!0,!0,!0),this.#Bt&&this.#Bt.updateHighlighting();const t=new Set,e=new Set,i=new Set;for(const i of this.sourceEntity.relationsWhereThisIsSource)i!==this&&(i.targetEntity==this.targetEntity?t.add(i):e.add(i));for(const e of this.sourceEntity.relationsWhereThisIsTarget)e!==this&&(e.sourceEntity==this.targetEntity?t.add(e):i.add(e));for(const i of this.targetEntity.relationsWhereThisIsSource)i!==this&&(i.targetEntity==this.sourceEntity?t.add(i):e.add(i));for(const e of this.targetEntity.relationsWhereThisIsTarget)e!==this&&(e.sourceEntity==this.sourceEntity?t.add(e):i.add(e));for(const e of t)e.pointUpSourceBollardsAndTargetBollards();for(const t of e)t.pointUpSourceBollards();for(const t of i)t.pointUpTargetBollards()}#Ft(){this.#zt=!1;const t=new Set;for(const e of this.sourceEntity.relations)t.add(e);for(const e of this.targetEntity.relations)t.add(e);for(const e of t)e.redrawLineConsideringSelection()}#qt(){this.#Qt&&(this.sourceEntity.isSelected&&this.targetEntity.isSelected?this.#Qt.update(!0,!0,!0):this.sourceEntity.isSelected?this.#Qt.update(!0,!0,this.isSelected):this.targetEntity.isSelected?this.#Qt.update(!0,this.isSelected,!0):this.#Qt.update(this.isSelected,this.isSelected,this.isSelected))}#Xt(){this.#Bt&&this.#Bt.updateHighlighting()}}class Ht extends gt{#Q;#Nt;#Ht;#K;#J;#gt;constructor(t,e,i,n){super(e,"relation",()=>"R"),this.#Q=t,this.#Nt=e,this.#Ht=i,this.#K=i.namespaceInstanceContainer,this.#J=n}set toolBarHeight(t){this.#gt=t}_toInstance(t){return new Xt(this.#Q,this.#Nt,this.#Ht.entityInstanceContainer,this.#Ht.attributeInstanceContainer,this.#K,t,this.#J,this.#gt)}add(t){t=t instanceof Xt?t:new Xt(this.#Q,this.#Nt,this.#Ht.entityInstanceContainer,this.#Ht.attributeInstanceContainer,this.#K,t,this.#J,this.#gt);const e=super.add(t),{clientHeight:i,clientWidth:n}=document.documentElement;return e.render(i,n),e}changeType(t,e){const i=super.changeType(t,e);return i.updateElement(),i}remove(t){console.assert(t,"id is necessary!");super.remove(t).erase()}clear(){for(const t of this.all)t.erase();super.clear()}}class Wt{#M;#H;#jt;#G;#K;#Wt;#Vt;#gt;#u=!1;#zt=!1;#Yt=!1;#Rt=null;#Ut;#ft;constructor(t,e,i,n,s,o,r,a,l,c=null){this.#M=t,this.#H=c,this.#jt=e,this.#G=i,this.#Wt=s,this.#Vt=o,this.#K=n,this.#gt=l,this.span=r,this.typeName=a}get id(){return this.#H}set id(t){this.#H=t}get title(){return`[${this.id}] pred: type, value: ${this.#ft}`}get color(){return this.#J.getColor(this.typeName)}get anchorHTML(){return pt(this.#lt,this.#nt)}get span(){return this.#Ut}set span(t){this.#Ut=t,t.add(this)}get typeName(){return this.#ft}set typeName(t){this.#ft=String(t)}get typeValues(){return new Ot(this.#ft,this.#jt.getAttributesFor(this.#H))}get relations(){return this.relationsWhereThisIsSource.concat(this.relationsWhereThisIsTarget)}get attributes(){return this.#jt.getAttributesFor(this.#H)}get relationsWhereThisIsSource(){return this.#G.all.filter(t=>t.subj===this.id)}get relationsWhereThisIsTarget(){return this.#G.all.filter(t=>t.obj===this.id)}get hasMultipleEndpoints(){const t=new Map;t.set("whereThisIsSourceAndTargetIsOnTheLeft",new Set),t.set("whereThisIsSourceAndTargetIsOnTheRight",new Set),t.set("whereThisIsSourceAndTargetIsUpOrDown",new Set);for(const e of this.relationsWhereThisIsSource)e.targetEntity.offsetCenter<this.offsetCenter?t.get("whereThisIsSourceAndTargetIsOnTheLeft").add(e):this.offsetCenter<e.targetEntity.offsetCenter?t.get("whereThisIsSourceAndTargetIsOnTheRight").add(e):t.get("whereThisIsSourceAndTargetIsUpOrDown").add(e);t.set("whereThisIsTargetAndSourceIsOnTheLeft",new Set),t.set("whereThisIsTargetAndSourceIsOnTheRight",new Set),t.set("whereThisIsTargetAndSourceIsUpOrDown",new Set);for(const e of this.relationsWhereThisIsTarget)e.sourceEntity.offsetCenter<this.offsetCenter?t.get("whereThisIsTargetAndSourceIsOnTheLeft").add(e):this.offsetCenter<e.targetEntity.offsetCenter?t.get("whereThisIsTargetAndSourceIsOnTheRight").add(e):t.get("whereThisIsTargetAndSourceIsUpOrDown").add(e);return[...t.values()].filter(t=>t.size).length>1}get clientTop(){const{span:t}=this;if(t.isDenotation){let e=t.clientTopOfGrid+this.#Wt.height;for(const i of t.entities){if(i===this)break;e+=this.#Wt.height+i.height}return T(e)}if(t.isBlock){const e=15;return T(t.clientBottomOfGrid-this.height-e)}throw new Error("Unexpected type of span")}get offsetTop(){return this.clientTop-this.span.element.offsetParent.offsetParent.getBoundingClientRect().top}get clientBottom(){return this.clientTop+this.height}isInViewport(t){return this.#gt<=this.clientBottom&&this.clientTop<=t}get width(){return this.span.widthOfGrid}get height(){return 18+this.#Gt}get heightWithTypeGap(){return this.height+this.#Wt.height}get offsetCenter(){return T(this.span.offsetCenterOfGrid)}get isDenotation(){return this.#Ut.isDenotation}get isBlock(){return this.#Ut.isBlock}get isSelected(){return this.#u}getSourceAnchorPosition(t){const e=this.width/2>=28||this.hasMultipleEndpoints&&t;return{left:e?this.offsetCenter-24:this.offsetCenter,right:e?this.offsetCenter+24:this.offsetCenter}}getTargetAnchorPosition(t){const e=this.width/2>=28||this.hasMultipleEndpoints&&t;return{left:e?this.offsetCenter-8:this.offsetCenter,right:e?this.offsetCenter+8:this.offsetCenter}}focus(){if(this.isDenotation)this.span.focus();else{if(!this.isBlock)throw new Error("Unexpected type of entity");this.span.forceRenderGrid(),this.#Rt.focus()}}select(){this.#u||(this.#u=!0,this.#Kt(),this.#Jt())}deselect(){this.#u&&(this.#u=!1,this.#Rt&&this.#Rt.deselect(),this.#Jt())}startCut(){this.#Rt&&this.#Rt.startCut()}cancelCut(){this.#Rt&&this.#Rt.cancelCut()}render(){if(!this.#Rt&&this.span.isGridRendered){this.#Rt=this.#te(),this.span.addEntityElementToGridElement(this.#Rt.element),this.reflectTypeGapInTheHeight();for(const t of this.span.entities.filter(t=>t!==this))for(const e of t.relations)e.redrawLineConsideringSelection();this.#u&&this.#Rt.select()}}updateElement(){if(this.#Rt){this.#Rt=this.#Rt.replaceWith(this.#te()),this.#u&&this.#Kt(),this.reflectTypeGapInTheHeight(),this.span.updateSelfAndAncestorsGridPosition();for(const t of this.span.entities)for(const e of t.relations)e.redrawLineConsideringSelection()}}reflectTypeGapInTheHeight(){this.isDenotation&&this.#Rt&&this.#Rt.reflectTypeGapInTheHeight(this.#Wt.height)}clarifyLabel(){this.#Rt&&this.#Rt.clarifyLabel(),this.#Yt=!0}declarifyLabel(){!this.#zt&&this.#Rt&&this.#Rt.declarifyLabel(),this.#Yt=!1}erase(){this.#Rt&&(this.#Rt.remove(),this.#Rt=null,this.span.updateSelfAndAncestorsGridPosition())}#te(){const t=new Zt(this,this.isDenotation?"denotation":"block",`${this.#M}__E${this.id.replace(/[:¥.]/g,"")}`);return t.addEventListener("mouseenter",()=>{t.clarifyLabel(),this.#ee(),this.#zt=!0}),t.addEventListener("mouseleave",()=>{this.#Yt||t.declarifyLabel(),this.#Jt(),this.#zt=!1}),t}#Kt(){this.span.forceRenderGrid(),this.#Rt.select(),this.span.isGridBeforePositioned?this.span.entityToFocusOn=this:this.focus()}get#J(){if(this.isDenotation)return this.#Vt.denotation;if(this.isBlock)return this.#Vt.block;throw"unknown entity type"}get#lt(){return ht(this.#K,this.typeName,this.#J.getLabel(this.typeName))}get#nt(){return ft(this.#K,this.typeName,this.#J.getURI(this.typeName))}get#Gt(){return this.attributes.map(({height:t})=>t).reduce((t,e)=>t+e,0)}#ee(){for(const t of this.relationsWhereThisIsSource)t.pointUpPathAndSourceBollards();for(const t of this.relationsWhereThisIsTarget)t.pointUpPathAndTargetBollards()}#Jt(){for(const t of this.relations)t.redrawLineConsideringSelection()}}class Vt extends gt{#M;#Ht;#Wt;#K;#gt;constructor(t,e,i,n){super(e,"entity",t=>t.isDenotation?"T":"B"),this.#M=t,this.#Ht=i,this.#Wt=n,this.#K=i.namespaceInstanceContainer}get#T(){return this.#Ht.spanInstanceContainer}get#jt(){return this.#Ht.attributeInstanceContainer}get#G(){return this.#Ht.relationInstanceContainer}set toolBarHeight(t){this.#gt=t}_toInstance(t,e){const i=this.#ie(e,t);return new Wt(this.#M,this.#jt,this.#G,this.#K,this.#Wt,this.#Ht.typeDictionary,i,t.obj,this.#gt,t.id)}add(t){if(t instanceof Wt){if(!t.span)throw new Error(`entity has no span! ${JSON.stringify(t)}`);return super.add(t),t.span.add(t),t.render(),t}if(void 0===t.spanType||void 0===t.begin||void 0===t.end)throw new Error(`entity has no span information! ${JSON.stringify(t)}`);const e=this.#T.find(t.spanType,t.begin,t.end),i=new Wt(this.#M,this.#jt,this.#G,this.#K,this.#Wt,this.#Ht.typeDictionary,e,t.typeName,this.#gt);return console.assert(i.span.isDenotation||i.span.entities.length>0,"A block span cannot have more than one entity."),super.add(i),i.render(),i}remove(t){const e=super.get(t);e.span.remove(e),super.remove(t),e.erase()}changeType(t,e){const i=super.changeType(t,e);return i.updateElement(),i}moveEntities(t,e){for(const i of e){i.erase();const e=i.span;e.remove(i),e.updateSelfAndAncestorsGridPosition(),i.span=t,i.render();for(const t of i.relations)t.redrawLineConsideringSelection()}super._emit("textae-event.annotation-data.entity.move")}get denotations(){return this.all.filter(t=>t.isDenotation)}get blocks(){return this.all.filter(t=>t.isBlock)}redrawEntitiesWithSpecifiedAttribute(t){const e=this.all.filter(e=>e.typeValues.hasSpecificPredicateAttribute(t));for(const t of e)t.updateElement();for(const t of new Set([...e.map(({span:t})=>t)]))t.updateGridPosition()}clarifyLabelOfAll(){for(const t of this.all)t.clarifyLabel()}declarifyLabelOfAll(){for(const t of this.all)t.declarifyLabel()}#ie(t,e){return this.#T.find(t,e.span.begin,e.span.end)}hasDenotation(t){return this.denotations.some(e=>e.id===t)}}class Yt{constructor(t){this._trackNumber=t}addTrackNumberAsIDPrefix(t,e,i,n){const s=t.map(t=>({...t,id:this._prependToIDOf(t)})),o=e.map(t=>({...t,id:this._prependToIDOf(t)})),r=n.map(t=>({...t,id:this._prependToIDOf(t),subj:this._prependTrackNumberTo(t.subj),obj:t.obj})),a=i.map(t=>({...t,id:this._prependToIDOf(t),subj:this._prependTrackNumberTo(t.subj),obj:this._prependTrackNumberTo(t.obj)}));return{denotations:s,blocks:o,relations:a,attributes:r}}_prependToIDOf(t){return t.id?this._prependTrackNumberTo(t.id):null}_prependTrackNumberTo(t){return this._trackNumber+t}}function Ut(t){const{span:e}=t;return{...t,span:Gt(e)}}function Gt(t){return{...t,begin:parseInt(t.begin),end:parseInt(t.end)}}function Kt(t,e,i,n,s,o=""){const[r,a,l]=function(t,e,i){return[t.map(Ut),e.map(Ut),i.map(Ut)]}(s.typeSetting,s.denotation,s.block),{relation:c,attribute:h}=s,{denotations:u,blocks:d,relations:f,attributes:p}=new Yt(o).addTrackNumberAsIDPrefix(a,l,c,h);t.addSource(r,"typesetting"),t.addSource(u,"denotation"),t.addSource(d,"block"),e.addSource(u,"denotation"),e.addSource(d,"block"),n.addSource(f),i.addSource(p)}function Jt(t,e){return 0<=t&&t<=e.length}class te{constructor(){this._map=new Map}set(t,e,i){this._map.set(t,[e,i])}getErrors(t){return this._map.has(t)?this._map.get(t)[0]:[]}getInhibitors(t){return this._map.has(t)?this._map.get(t)[1]:[]}get size(){return this._map.size}}function ee(t,e){return e.reduce((e,i)=>e.concat(i.getErrors(t)),[])}class ie{constructor(t,e,i="",n=()=>!0,s){this._candidates=t||[],this._name=i,this._predicate=n,this._prevValidation=s,this._sourcePropertyName=e}and(t,e){return new ie(this._candidates,this._sourcePropertyName,t,e,this)}validateAll(){const t=new te;let e,i;for(e=this,i=this._candidates;e;e=e._prevValidation)i=e._validate(i,this._candidates,t);return[i,t]}_validate(t,e,i){return this._getRejects(e).length>0&&i.set(this._name,this._getRejects(e),this._getInhibitors(e)),this._getAccepts(t)}_getAccepts(t){return t.filter(t=>this._test(t))}_getRejects(t){return t.filter(t=>!this._test(t)).map(t=>function(t,e){return t.sourceProperty=e,t}(t,this._sourcePropertyName))}_getInhibitors(t){const e=new Map;for(const i of t){const t=this._predicate(i);Array.isArray(t)&&!t[0]&&e.set(i,t[1])}return e}_test(t){const e=this._predicate(t);return Array.isArray(e)?e[0]:e}}function ne(t,e,i,n){return new ie(t,n).and("hasLength",t=>t.span.end-t.span.begin>0).and("inText",t=>function(t,e){return Jt(e.begin,t)&&Jt(e.end,t)}(e,t.span)).and("isNotCrossing",t=>{const e=H(i,t.span.begin,t.span.end);return[0===e.length,e]})}function se(t,e){return t.some(t=>t.id===e)}function oe(t,e){return void 0===e.id||1===t.filter(t=>e.id&&e.id===t.id).length}function re(t,e){for(const[i,n]of e.getInhibitors("isNotCrossing"))console.warn(`Crossing ${t}: [${i.span.begin}:${i.span.end}](${i.id}) crosses with ${n.map(({id:t,span:e})=>`[${e.begin}:${e.end}](${t})`).join(", ")}`)}function ae(t){const{typesettings:e,denotations:i,blocks:n}=t;return(e||[]).concat(i||[]).concat(n||[])}function le(t,e,i){const[n,s]=function(t,e,i){return ne(e,t,i,"typesettings").validateAll()}(t,i.typesettings,e),o=ae(i),[r,a]=function(t,e,i,n){return ne(e,t,i,"denotations").and("uniqueID",t=>oe(n,t)).validateAll()}(t,i.denotations,e,o),[l,c]=function(t,e,i,n){return ne(e,t,i,"blocks").and("uniqueID",t=>oe(n,t)).and("uniqueRange",({span:t})=>1===e.filter(({span:e})=>t.begin===e.begin&t.end===e.end).length).validateAll()}(t,i.blocks,e,o),[h,u]=(d=r.concat(l),f=i.relations,new ie(f).and("object",t=>se(d,t.obj)).and("subject",t=>se(d,t.subj)).validateAll());var d,f;const[p,m]=(g=r.concat(l).concat(h),v=i.attributes,new ie(v).and("subject",t=>se(g,t.subj)).and("unique",t=>function(t,e){return 1===t.filter(t=>t.subj===e.subj&&t.pred===e.pred&&t.obj===e.obj).length}(v,t)).validateAll());var g,v,y,O,b;return re("TypeSettings",s),re("Denotations",a),re("Blocks",c),{accept:{denotation:r,attribute:p,relation:h,typeSetting:n,block:l},reject:{wrongRangeDenotations:a.getErrors("hasLength"),outOfTextDenotations:a.getErrors("inText"),wrongRangeBlocks:c.getErrors("hasLength"),outOfTextBlocks:c.getErrors("inText"),duplicatedRangeBlocks:c.getErrors("uniqueRange"),wrongRangeTypesettings:s.getErrors("hasLength"),outOfTextTypesettings:s.getErrors("inText"),duplicatedIDs:ee("uniqueID",[a,c]),boundaryCrossingSpans:ee("isNotCrossing",[s,a,c]),referencedEntitiesDoNotExist:(y=m.getErrors("subject"),O=u.getErrors("object"),b=u.getErrors("subject"),y.map(t=>(t.sourceProperty="attributes",t.alertSubj=!0,t)).concat(O.map(t=>(t.sourceProperty="relations",t.alertObj=!0,t))).concat(b.map(t=>(t.sourceProperty="relations",t.alertSubj=!0,t)))),duplicatedAttributes:m.getErrors("unique"),hasError:a.size||c.size||m.size||u.size||s.size}}}class ce{#K;#T;#U;#G;#jt;#ne;#se;#oe;constructor(t,e){const{namespaceInstanceContainer:i,spanInstanceContainer:n,entityInstanceContainer:s,attributeInstanceContainer:o,relationInstanceContainer:r}=t;this.#K=i,this.#T=n,this.#U=s,this.#G=r,this.#jt=o,this.#ne=e}eval(){this.#ne.namespaces?this.#K.addSource(this.#ne.namespaces.map(t=>({id:t.prefix,...t}))):this.#K.addSource([]);const{accept:t,reject:e}=le(this.#re,this.#ae,this.#ne);Kt(this.#T,this.#U,this.#jt,this.#G,t),e.name="Root annotations.",this.#se=e,this.hasMultiTracks&&(this.#oe=function(t,e,i,n,s,o,r){console.assert(r.tracks);const{tracks:a}=r;return a.map((r,a)=>{const l=a+1,c=`track${l}_`,{accept:h,reject:u}=le(s,o,r);return Kt(t,e,i,n,h,c),u.name=`Track ${l} annotations.`,u})}(this.#T,this.#U,this.#jt,this.#G,this.#re,this.#ae,this.#ne))}get hasMultiTracks(){return Boolean(this.#ne.tracks)}get rejects(){return this.hasMultiTracks?[this.#se].concat(this.#oe):[this.#se]}get#re(){return this.#ne.text}get#ae(){return function(t){let e=ae(t);if(t.tracks)for(const i of t.tracks)e=e.concat(ae(i));return e}(this.#ne)}}function he(t){return t.relationInstanceContainer.all.map(t=>({id:t.id,pred:t.typeName,subj:t.subj,obj:t.obj}))}function ue(t){return t.entityInstanceContainer.blocks.map(t=>({id:t.id,span:{begin:t.span.begin,end:t.span.end},obj:t.typeName}))}class de{constructor(t){this._isGapShown=!0,this._numberOfGap=1,this._callback=t}set show(t){this._isGapShown!==t&&(this._isGapShown=t,this._callback(this.value))}get show(){return this._isGapShown}get value(){return this._isGapShown?this._numberOfGap:0}get height(){return 24*this.value}set value(t){this._numberOfGap!==t&&(this._numberOfGap=t,this._callback(t))}}function fe(t){const e=parseInt(t,10);return isNaN(e)?0:e}class pe{#Q;#r;#Ht;#le;constructor(t,e,i){this.#Q=t,this.#r=t.querySelector(".textae-editor__text-box"),this.#Ht=e,this.#le=i}get boundingClientRect(){return this.#r.getBoundingClientRect()}get lineHeight(){return t=this.#r,fe(window.getComputedStyle(t).lineHeight);var t}set lineHeight(t){var e,i,n;e=this.#r,i=t,n=this.#le,e.style.lineHeight=`${i}px`,e.style.paddingTop=`${i/2+n}px`,this.forceUpdate(),this.#Ht.updatePosition()}render(t){this.#r.innerHTML=t.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#039;")}updateLineHeight(){const t=this.#Ht.spanInstanceContainer.maxHeight;t?this.lineHeight=t:this.#ce()}forceUpdate(){!function(t,e){const i=window.getComputedStyle(t);t.style.height="auto",t.style.height=`${t.offsetHeight-fe(i.paddingTop)+20+e}px`}(this.#r,this.#le),this.#he()}#ce(){const{lineHeight:t}=window.getComputedStyle(this.#Q);this.lineHeight=fe(t)}#he(){const t=this.#Q.querySelector(".textae-editor__relation-box");t.style.height=this.#r.style.height;const e=parseFloat(window.getComputedStyle(this.#r).width);t.style.width=e-10+"px"}}function me(t,e,i){const n='\n <div class="textae-editor__body">\n <div class="textae-editor__annotation-box"></div>\n <svg\n namespace="http://www.w3.org/2000/svg"\n class="textae-editor__relation-box">\n </svg>\n <div class="textae-editor__text-box"></div>\n </div>\n ';return t.innerHTML=n.replace(/[\n\r]+/g,""),function(t){new MutationObserver(e=>{e.forEach(e=>{e.removedNodes.length&&1===e.removedNodes[0].nodeType&&(e.removedNodes[0].classList.contains("textae-editor__span")||e.removedNodes[0].classList.contains("textae-editor__type"))&&"BODY"===document.activeElement.tagName&&t.focus()})}).observe(t.querySelector(".textae-editor__body"),{childList:!0,subtree:!0})}(t),new pe(t,e,i)}var ge=i(504),ve=i.n(ge);class ye{#Nt;#ue;#de;#fe;#pe;#me=new(ve())(!1);constructor(t,e,i,n,s,o=!0){this.#Nt=t,this.#ue=e,this.#de=i,this.#fe=n,this.#pe=s,this.#me(()=>this.#Nt.emit("textae-event.type-definition.lock")),this.#me.set(o)}set autocompletionWs(t){this.#ue.autocompletionWs=t,this.#fe.autocompletionWs=t,this.#de.autocompletionWs=t}set autocompletionFunction(t){this.#ue.autocompletionFunction=t,this.#fe.autocompletionFunction=t,this.#de.autocompletionFunction=t}get denotation(){return this.#ue}get block(){return this.#de}get relation(){return this.#fe}get attribute(){return this.#pe}get autocompletionWs(){return this.#ue.autocompletionWs}get config(){const t={};return this.#ue.config.length&&(t["entity types"]=this.#ue.config),this.#fe.config.length&&(t["relation types"]=this.#fe.config),this.#pe.config.length&&(t["attribute types"]=this.#pe.config),this.#de.config.length&&(t["block types"]=this.#de.config),t}get isLock(){return this.#me()}lockEdit(){this.#me.set(!0)}unlockEdit(){this.#me.set(!1)}setTypeConfig(t){t?(this.#ue.config=t["entity types"],this.#fe.config=t["relation types"],this.#pe.config=t["attribute types"],this.#de.config=t["block types"],this.autocompletionWs=t.autocompletion_ws):(this.#ue.config=null,this.#fe.config=null,this.#pe.config=null,this.#de.config=null,this.autocompletionWs=""),this.#Nt.emit("textae-event.type-definition.reset")}}function Oe(t){const e=Array.from(t.keys());return e.sort((e,i)=>{const n=t.get(i).usage-t.get(e).usage;return 0!==n?n:e>i?1:e<i?-1:0}),e}function be(t,e){for(const[e,i]of t.entries())t.set(e,{...i,usage:0});return e.reduce((t,{typeName:e})=>(t.get(e).usage+=1,t),t)}class xe{#H;#st;#Bt;#ge;constructor(t,e,i,n){this.#H=t,this.#st=e,this.#Bt=i,this.#ge=n}get id(){return this.#H}get color(){return this.#st}get label(){return this.#Bt}get default(){return this.#ge}toJSON(){return{id:this.#H,color:this.#st,label:this.#Bt,default:this.#ge}}}class we{#ve;constructor(t=[]){this.#ve=t.map(t=>new xe(t.id,t.color,t.label,t.default))}has(t){return this.map.has(t)}get default(){return this.#ve.find(t=>!0===t.default)}replace(t,e){e=new xe(e.id,e.color,e.label,e.default);const i=this.#ve.findIndex(e=>e.id===t);-1!==i?this.#ve.splice(i,1,e):this.#ve.push(e)}delete(t){this.#ve=this.#ve.filter(e=>e.id!==t)}ids(){return this.map.keys()}getColorOf(t){return this.#ye(t)?.color}getLabelOf(t){return this.#ye(t)?.label}labelsIncludes(t){return this.#ve.filter(t=>t.label).filter(e=>e.label.includes(t))}get map(){return new Map(this.#ve.map(t=>[t.id,t]))}#ye(t){if(this.has(t))return this.map.get(t);const e=function(t,e){const i=function(t,e){const i=[];for(const n of t)-1!==n.indexOf("*")&&0===e.indexOf(n.slice(0,-1))&&i.push(n);return i}(t,e);return 0===i.length?null:function(t){let e="";for(const i of t)i.length>e.length&&(e=i);return e}(i)}(this.ids(),t);return this.map.get(e)}}function _e(t,e){const i=new URL(t,location);return i.searchParams.append("term",e),fetch(i.href).then(t=>t.ok?t.json():[])}class Se{#Nt;#Oe;#be=new we([]);#xe;#we;#_e;#Se="";#ke;constructor(t,e,i,n){this.#Nt=t,this.#Oe=e,this.#xe=i,this.#we=n}set autocompletionWs(t){this.#Se=t}set autocompletionFunction(t){this.#ke=t}get autocompletionWs(){return this.#Se}get annotationType(){return this.#Oe}get config(){const t=this.#$e;for(const[e,i]of t.entries()){const n=i.toJSON();i.id===this.defaultType?n.default=!0:delete n.default,t.set(e,n)}return[...t.values()]}set config(t){this.#be=new we(t);const e=this.#be.default;e?(delete e.default,this.#_e=e.id):this.#_e=null}has(t){return this.#be.has(t)}get(t){const e={...this.#be.map.get(t)};return this.#_e===t?(e.default=!0,e):(delete e.default,e)}replace(t,e){this.#be.replace(t,e),this.#Nt.emit(`textae-event.type-definition.${this.#Oe}.change`,e.id)}addDefinedType(t){if(void 0===t.color){const e=this.getColor(t.id);e!==this.#we&&(t.color=e)}if(void 0===t.label){const e=this.getLabel(t.id);e&&(t.label=e)}t.default&&(this.#_e=t.id),this.replace(t.id,t)}get defaultType(){return this.#_e?this.#_e:this.#xe().length>0?Oe(be(this.#$e,this.#xe()))[0]:"something"}set defaultType(t){this.#_e=t,this.#Nt.emit(`textae-event.type-definition.${this.#Oe}.change-default`,t)}get defaultColor(){return this.#we}getColor(t){return this.#be.getColorOf(t)||this.#we}getLabel(t){return this.#be.getLabelOf(t)}getURI(t){return ct(t)?t:void 0}searchByLabel(t,e){if("function"==typeof this.#ke){const i=this.#ke(t),n=this.mergeWithLocalData(i,t);return void e(n)}this.#Se?_e(this.#Se,t).then(i=>{const n=this.mergeWithLocalData(i,t);e(n)}):e(this.findByLabel(t))}findByLabel(t){return this.#be.labelsIncludes(t)}mergeWithLocalData(t,e){const i=this.findByLabel(e),n=(t||[]).filter(t=>!i.some(e=>t.id===e.id));return i.concat(n)}get pallet(){const t=be(this.#$e,this.#xe());return function(t,e,i,n,s){return t.map(t=>({id:t,label:i.getLabelOf(t)||void 0,defaultType:t===n,uri:ct(t)?t:void 0,color:i.getColorOf(t)||s,useNumber:e.get(t).usage}))}(Oe(t),t,this.#be,this.defaultType,this.#we)}get#$e(){const t=this.#be.map;for(const{typeName:e}of this.#xe())t.has(e)||t.set(e,new xe(e));return t}delete(t,e){this.#be.delete(t),this.#_e=e,this.#Nt.emit(`textae-event.type-definition.${this.#Oe}.delete`,t)}}class ke{constructor(t,e){this.valueType=t,this.pred=e}get values(){return console.assert(this._values,"this._values to return!"),this._values}get externalFormat(){return{pred:this.pred}}get _valuesClone(){if(console.assert(this._values,"this._values is necessary to clone!"),Array.isArray(this._values)&&0===this._values.length)return;const t=[];for(const e of this._values)t.push({...e});return t}}class $e extends ke{constructor(t,e){super(t,e.pred),this.default=!0,this.label=e.label,this.color=e.color}getLabel(){return this.label}getDisplayName(){return this.label?this.label:this.pred}getColor(){return this.color}get externalFormat(){return{...super.externalFormat,"value type":"flag",default:this.default,label:this.label,color:this.color}}}function Ce(t,e){return t<=e}function Te(t,e){return t<e}function Pe(t){if(t.startsWith("["))return e=>Ce(new Number(t.replace("[","")),e);if(t.startsWith("("))return e=>Te(new Number(t.replace("(","")),e);throw`${t} is not valid interval notation`}function Ee(t){if(t.endsWith("]"))return e=>Ce(e,new Number(t.replace("]","")));if(t.endsWith(")"))return e=>Te(e,new Number(t.replace(")","")));throw`${t} is not valid interval notation`}class Ae{constructor(t){const[e,i]=t.split(",");if(i?(this._lowwerCond=Pe(e),this._upperCond=Ee(i)):((e.startsWith("[")||e.startsWith("("))&&(this._lowwerCond=Pe(e),this._upperCond=t=>!0),(e.endsWith("]")||e.endsWith(")"))&&(this._lowwerCond=t=>!0,this._upperCond=Ee(e))),!this._lowwerCond||!this._upperCond)throw`${t} is not valid interval notation`}test(t){return this._lowwerCond(t)&&this._upperCond(t)}}function Me(t){return!Number.isNaN(parseFloat(t))}class Qe extends ke{constructor(t,e){super(t,e.pred),this.default=Me(e.default)?parseFloat(e.default):0,Me(e.min)&&(this.min=parseFloat(e.min)),Me(e.max)&&(this.max=parseFloat(e.max)),this.step=Me(e.step)?parseFloat(e.step):2,this._values=e.values||[]}getLabel(t){const e=this.#Ce(t);if(e&&e.label)return e.label}getDisplayName(t){return this.getLabel(t)||String(t)}getColor(t){const e=this.#Ce(t);return e&&e.color?e.color:null}#Ce(t){const e=this._values.filter(t=>"default"!==t.range).find(e=>new Ae(e.range).test(t));if(e)return e;const i=this._values.find(t=>"default"===t.range);return i||null}get externalFormat(){return{...super.externalFormat,"value type":"numeric",default:this.default,min:this.min,max:this.max,step:this.step,values:super._valuesClone}}}class De extends ke{constructor(t,e){super(t,e.pred),this._values=e.values||[]}get default(){return this.values.find(t=>t.default).id}getLabel(t){const e=this.#Ce(t);if(e&&e.label)return e.label}getDisplayName(t){return this.getLabel(t)}getColor(t){const e=this.#Ce(t);return e&&e.color?e.color:null}get values(){return this._values}get hasOnlyOneValue(){return 1===this._values.length}#Ce(t){return this.values.find(e=>e.id==t)}get externalFormat(){return{...super.externalFormat,"value type":"selection",values:super._valuesClone}}}class Re extends ke{constructor(t,e){super(t,e.pred),this.autocompletionWs=e.autocompletion_ws,this.default=e.default,Me(e["media height"])&&(this.mediaHeight=parseFloat(e["media height"])),this._values=e.values||[]}getLabel(t){const e=this.#Ce(t);if(e&&e.label)return e.label}getDisplayName(t){return this.getLabel(t)}getColor(t){const e=this.#Ce(t);return e&&e.color?e.color:null}#Ce(t){const e=this._values.filter(t=>"default"!==t.pattern).find(e=>new RegExp(e.pattern).test(t));if(e)return e;const i=this._values.find(t=>"default"===t.pattern);return i||null}get externalFormat(){return{...super.externalFormat,"value type":"string",autocompletion_ws:this.autocompletionWs,default:this.default,values:super._valuesClone,"media height":this.mediaHeight}}}function Ie(t,e){switch(t){case"flag":return new $e(t,e);case"numeric":return new Qe(t,e);case"selection":return new De(t,e);case"string":return new Re(t,e);default:throw new Error(`${t} of ${JSON.stringify(e)} is Uknown Attribute`)}}class Le{#Nt;#xe;#be=new Map;constructor(t,e){this.#Nt=t,this.#xe=e}get config(){return this.attributes.map(t=>t.externalFormat)}set config(t){this.#be=new Map((t||[]).map(t=>[t.pred,Ie(t["value type"],t)]))}create(t,e,i=null){null!==i&&this.#be.size!==i?this.#be=new Map(Array.from(this.#be.entries()).reduce((n,[s,o],r)=>(r===i&&n.push([e.pred,Ie(t,e)]),n.push([s,o]),n),[])):this.#be.set(e.pred,Ie(t,e)),this.#Nt.emit("textae-event.type-definition.attribute.create",e.pred)}get(t){return this.#be.get(t)}update(t,e){return this.#be=new Map(Array.from(this.#be.entries()).map(([i,n])=>i===t?[e.pred,Ie(n.valueType,e)]:[i,n])),this.#Nt.emit("textae-event.type-definition.attribute.change",e.pred),this.get(e.pred)}updateValues(t,e){const i=this.get(t).externalFormat;return this.update(t,{...i,values:e})}move(t,e){var i,n,s;this.#be=new Map((i=this.attributes,n=t,s=e,function(t,e,i){const n=e<0?t.length+e:e;if(n>=0&&n<t.length){const n=i<0?t.length+i:i,[s]=t.splice(e,1);t.splice(n,0,s)}}(i=[...i],n,s),i).map(t=>[t.pred,t]));const{pred:o}=this.attributes[-1===e?this.attributes.length-1:e];this.#Nt.emit("textae-event.type-definition.attribute.move",o)}delete(t){this.#be.delete(t),this.#Nt.emit("textae-event.type-definition.attribute.delete")}get attributes(){return Array.from(this.#be.values())||[]}isSelectionAttributeValueIndelible(t,e){return!!this.get(t).hasOnlyOneValue||!!this.#xe().some(i=>i.equalsTo(t,e))}getLabel(t,e){return console.assert(this.#be.has(t),`There is no attribute definition for ${t}.`),this.get(t).getLabel(e)}getDisplayName(t,e){return console.assert(this.#be.has(t),`There is no attribute definition for ${t}.`),this.get(t).getDisplayName(e)}getColor(t,e){if(this.#be.has(t))return this.get(t).getColor(e)}getIndexOf(t){return Array.from(this.#be.values()).findIndex(e=>e.pred===t)}getAttributeAt(t){return Array.from(this.#be.values())[t-1]}attributeCompareFunction(t,e){const i=this.getIndexOf(t.pred),n=this.getIndexOf(e.pred);return i!==n?i-n:t.id&&e.id?t.id.localeCompare(e.id):0}}class Ne{constructor(t,e){this._textBox=e,this._enable=!1,t.on("textae-event.control.button.push",({name:t,isPushed:e})=>{"auto adjust lineheight"===t&&(this._enable=e)})}updateLineHeight(){this._enable&&this._textBox.updateLineHeight()}}function je(t,e,i){for(const n of i)t[n]=(...t)=>{const i=e();return console.assert(i[n],`No ${n} method to forward`,i),i[n].apply(i,t)};return t}class ze{#Te;#Wt;#O;#Pe;#K;#T;#U;#G;#jt;#Vt;#Q;#Nt;constructor(t,e,i,n,s,o,r,a){this.#Te="",this.#K=new w(i,"namespace");const l=new Se(i,"relation",()=>this.#G.all,"#00CC66");this.#G=new Ht(e,i,this,l),this.#Wt=new de(()=>{for(const t of this.entityInstanceContainer.denotations)t.reflectTypeGapInTheHeight();this.#O.updateLineHeight(),i.emit("textae-event.annotation-data.entity-gap.change")}),this.#U=new Vt(t,i,this,this.#Wt),this.attributeDefinitionContainer=new Le(i,()=>this.#jt.all),this.#jt=new yt(i,this.#U,this.#G,this.#K,this.attributeDefinitionContainer),this.updatePosition=()=>{try{n.startWait(),s(),this.#Ee()}catch(t){console.error(t)}finally{n.endWait(),o()}},this.#O=me(e,this,a),this.#Pe=new Ne(i,this.#O),this.#T=new it(t,e,i,this.#O),je(this,()=>this.#T,["getDenotationSpan","isBoundaryCrossingWithOtherSpans","hasParentOf","validateNewDenotationSpan","validateNewBlockSpan","validateEditableText"]),this.denotationDefinitionContainer=new Se(i,"entity",()=>this.#U.denotations,"#77DDDD");const c=new Se(i,"entity",()=>this.#U.blocks,"#77DDDD");this.#Vt=new ye(i,this.denotationDefinitionContainer,c,l,this.attributeDefinitionContainer,r),i.on("textae-event.annotation-data.span.add",t=>{(t.isDenotation||t.isBlock)&&(this.#O.forceUpdate(),this.#Ee())}).on("textae-event.annotation-data.span.remove",t=>{(t.isDenotation||t.isBlock)&&(this.#O.forceUpdate(),this.#Ee())}).on("textae-event.annotation-data.entity.add",t=>{t.span.isDenotation&&this.#Pe.updateLineHeight()}).on("textae-event.annotation-data.entity.remove",t=>{t.span.isDenotation&&this.#Pe.updateLineHeight()}),i.on("textae-event.type-definition.entity.change",t=>{for(const e of this.#U.all)(e.typeName===t||t.lastIndexOf("*")===t.length-1&&e.typeName.indexOf(0===t.slice(0,-1)))&&e.updateElement()}).on("textae-event.type-definition.attribute.change",t=>this.#U.redrawEntitiesWithSpecifiedAttribute(t)).on("textae-event.type-definition.attribute.move",t=>this.#U.redrawEntitiesWithSpecifiedAttribute(t)).on("textae-event.type-definition.relation.change",t=>{for(const e of this.#G.all)(e.typeName===t||t.lastIndexOf("*")===t.length-1&&e.typeName.indexOf(0===t.slice(0,-1)))&&e.updateElement()}),this.#Q=e,this.#Nt=i}reset(t,e){console.assert(t.text,"This is not a json file of annotations."),this.#Vt.setTypeConfig(e),this.#Te=t.text,this.#O.render(this.sourceDoc),this.#Ae();const i=new ce(this,t);i.eval(),this.#Me(),this.#Nt.emit("textae-event.annotation-data.all.change",i.hasMultiTracks,i.rejects),this.reLayout()}set autocompletionFunction(t){this.#Vt.autocompletionFunction=t}get externalFormat(){return{text:this.#Te,denotations:(t=this,t.entityInstanceContainer.denotations.map(t=>({id:t.id,span:{begin:t.span.begin,end:t.span.end},obj:t.typeName}))),attributes:this.#jt.all.map(({externalFormat:t})=>t),relations:he(this),blocks:ue(this)};var t}getReplicationRanges(t,e){return function(t,e,i,n,s){return function(t,e,i){const n=t.substring(e,i),s=i-e,o=[];let r=0;for(let e=t.indexOf(n);-1!==e;e=t.indexOf(n,r))r=e+s,o.push({begin:e,end:r});return o}(t,e,i).filter(({begin:t})=>t!==e).filter(({begin:e,end:i})=>function(t,e,i,n){const s=t.charAt(e-1),o=t.charAt(i);return n(s)&&n(o)}(t,e,i,s)).filter(({begin:t,end:e})=>!n.find("denotation",t,e)).filter(({begin:t,end:e})=>!n.isBoundaryCrossingWithOtherSpans(t,e))}(this.sourceDoc,t.begin,t.end,this.#T,e)}get typeGap(){return this.#Wt}get textBox(){return this.#O}get sourceDoc(){return this.#Te.replaceAll(/\r\n/g," \n")}get typeDictionary(){return this.#Vt}get spanInstanceContainer(){return this.#T}getSpan(t){return this.#T.get(t)}get entityInstanceContainer(){return this.#U}get relationInstanceContainer(){return this.#G}get attributeInstanceContainer(){return this.#jt}get namespaceInstanceContainer(){return this.#K}get textSelection(){return this.#T.textSelection}findDenotation(t,e){return this.#T.find("denotation",t,e)}findBlock(t,e){return this.#T.find("block",t,e)}getTextBetween(t,e){return this.sourceDoc.substring(t,e)}changeTextBetween(t,e,i){this.#Te=`${this.#Te.slice(0,t)}${i}${this.#Te.slice(e)}`;const n=i.length-(e-t),s=this.#T.offsetSpans(t,e,n);return this.#O.render(this.sourceDoc),this.#Me(),this.#Nt.emit("textae-event.annotation-data.text.change"),s}hasCharacters(t){const{begin:e,end:i}=this.textSelection,n=this.getTextBetween(e,i);return t.removeBlankCharacters(n).length>0}getTextSelection(t,e){const{begin:i,end:n}=this.textSelection;return{begin:e.backFromBegin(this.sourceDoc,i,t),end:e.forwardFromEnd(this.sourceDoc,n-1,t)+1}}getInstanceContainerFor(t){switch(t){case"span":return this.#T;case"relation":return this.#G;case"entity":return this.#U;case"attribute":return this.#jt}}drawGridsInSight(){if(this.#Qe){const{clientHeight:t,clientWidth:e}=document.documentElement;for(const i of this.#T.allDenotationSpans)i.drawGrid(t,e);for(const i of this.#T.allBlockSpans)i.drawGrid(t,e),i.updateBackgroundPosition();for(const i of this.#G.all)i.render(t,e)}}reLayout(){this.#O.forceUpdate(),this.#Qe&&this.updatePosition()}set toolBarHeight(t){this.#U.toolBarHeight=t,this.#G.toolBarHeight=t}get#Qe(){const{clientHeight:t}=document.documentElement,{top:e,bottom:i}=this.#Q.getBoundingClientRect();return 0<=i&&e<=t}focusDenotation(t){console.assert(this.#U.hasDenotation(t),"The denotation does not exist.");const{span:e}=this.#U.get(t);e.focus()}#Me(){this.#T.renderAll(),this.#O.updateLineHeight(),this.drawGridsInSight()}#Ee(){this.#T.arrangeDenotationEntityPosition(),this.#T.arrangeBackgroundOfBlockSpanPosition(),this.#T.arrangeBlockEntityPosition();for(const t of this.#G.all)t.sourceEntity.span.isGridRendered&&t.targetEntity.span.isGridRendered&&t.redrawLineConsideringSelection()}#Ae(){this.#T.clear(),this.#U.clear(),this.#jt.clear(),this.#G.clear(),this.#K.clear(),I(this.#Q).innerHTML=""}}const Be={"delimiter characters":[" ",".","!","?",",",":",";","-","/","&","(",")","{","}","[","]","+","*","\\",'"',"'","\n","–"],"non-edge characters":[" ","\n"]};class qe{#De;#Re;constructor(){this.#De=[],this.#Re=[]}get delimiterCharacters(){return this.#De}get blankCharacters(){return this.#Re}set(t){const e={...Be,...t};return this.#De=e["delimiter characters"],this.#Re=e["non-edge characters"],t}isDelimiter(t){return this.#De.indexOf("ANY")>=0?1:this.#De.indexOf(t)>=0}isBlankCharacter(t){return this.#Re.indexOf(t)>=0}removeBlankCharacters(t){for(const e of this.#Re)t=t.replaceAll(e,"");return t}}class Ze{constructor(t){this._resetHistory(),this._eventEmitter=t,t.on("textae-event.type-definition.reset",()=>{this._removeConfigurationOperationsFromHistory(),this._trigger()}).on("textae-event.annotation-data.all.change",()=>{this._resetHistory(),this._trigger()}).on("textae-event.resource.annotation.save",()=>{this._trigger()}).on("textae-event.resource.configuration.save",()=>{this._trigger()})}push(t){this._histories.splice(this._pointer+1,this._histories.length-this._pointer,t),this._pointer++,this._trigger()}next(){this._pointer++;const t=this._histories[this._pointer];return this._trigger(),t}prev(){const t=this._histories[this._pointer];return this._pointer--,this._trigger(),t}get hasAnythingToUndo(){return this._pointer>-1}get hasAnythingToRedo(){return this._pointer<this._histories.length-1}_trigger(){this._eventEmitter.emit("textae-event.history.change",this)}_removeConfigurationOperationsFromHistory(){for(let t=0;t<this._histories.length;t++)this._histories[t].isExactly("configuration_command")&&(this._pointer--,this._histories.splice(t,1))}_resetHistory(){this._pointer=-1,this._histories=[]}}function Fe(t,e,i){i?console.log(`[${t.constructor.name}]`,e,i):console.log(`[${t.constructor.name}]`,e)}class Xe{get isEmpty(){return!1}isExactly(t){return this.kind.has(t)&&1===this.kind.size}}class He extends Xe{get kind(){return new Set(["annotation_command"])}}class We extends He{#Ht;#Oe;#Et;#Ie;constructor(t,e,i,n=null){super(),this.#Ht=t,this.#Oe=e,this.#Et=i,this.#Ie=n}execute(){this.#Et=this.#Ht.getInstanceContainerFor(this.#Oe).add(this.#Et),this.#Ie&&this.#Ie.add(this.#Oe,[this.#Et.id]),Fe(this,`${this.#Oe}: ${this.#Et.id}`)}revert(){return new Ve(this.#Ht,this.#Oe,this.#Et)}}class Ve extends He{#Ht;#Oe;#Et;constructor(t,e,i){super(),this.#Ht=t,this.#Oe=e,this.#Et=i}execute(){this.#Ht.getInstanceContainerFor(this.#Oe).remove(this.#Et.id),Fe(this,`${this.#Oe}: ${this.#Et.id}`)}revert(){return new We(this.#Ht,this.#Oe,this.#Et)}}class Ye extends Xe{get kind(){return new Set(["configuration_command"])}}class Ue extends Ye{constructor(t,e,i,n=null){super(),this._definitionContainer=t,this._attrDef=e,this._index=i,this._indexThatAddDefaultTo=n}execute(){const t=[...this._attrDef.values];if("selection"===this._attrDef.valueType&&t[this._index].default&&null===this._indexThatAddDefaultTo){let e=null;t.forEach((t,i)=>{null===e&&i!=this._index&&(e=i)}),t[e]={...t[e],default:!0}}this._deletedValue=t.splice(this._index,1)[0],"selection"===this._attrDef.valueType&&null!==this._indexThatAddDefaultTo&&(t[this._indexThatAddDefaultTo]={...t[this._indexThatAddDefaultTo],default:!0}),this._updatedAttrDef=this._definitionContainer.updateValues(this._attrDef.pred,t),Fe(this,`remove a value from an attrribute:${this._attrDef.pred}, index:${this._index}, updated values: \n ${t.map(t=>JSON.stringify(t)).join("\n ")}`)}revert(){return new Ge(this._definitionContainer,this._updatedAttrDef,this._deletedValue,this._index)}}class Ge extends Ye{constructor(t,e,i,n=null){super(),this._definitionContainer=t,this._pred=e.pred,this._index=n,this._value=i;const s=[...e.values];if("selection"===e.valueType&&i.default){this._indexThatRemoveDefaultFrom||(this._indexThatRemoveDefaultFrom=s.findIndex(t=>t.default));const t={...s[this._indexThatRemoveDefaultFrom]};delete t.default,s[this._indexThatRemoveDefaultFrom]=t}s.splice(n||s.length,0,i),this._modifiedValues=s}execute(){this._updatedAttrDef=this._definitionContainer.updateValues(this._pred,this._modifiedValues),Fe(this,`add a new value to attrribute:${this._pred}, value: ${JSON.stringify(this._value)}, index: ${this._index}, updated values: \n ${this._modifiedValues.map(t=>JSON.stringify(t)).join("\n ")}`)}revert(){return new Ue(this._definitionContainer,this._updatedAttrDef,this._updatedAttrDef.values.length-1,this._indexThatRemoveDefaultFrom)}}class Ke extends Xe{constructor(){super(),this._isExecuteSubCommandsInReverseOrderWhenRevert=!0}execute(){if(console.assert(this._subCommands,"_subCommands is necessary!"),this.isEmpty)return void(this.revert=()=>({execute(){}}));for(const t of this._subCommands)t.execute();this._afterInvoke&&this._afterInvoke();const t=this;this.revert=()=>({_subCommands:this._subCommands,_logMessage:this._logMessage,_afterInvoke:this._afterInvoke,_isExecuteSubCommandsInReverseOrderWhenRevert:this._isExecuteSubCommandsInReverseOrderWhenRevert,execute(){let e=this._subCommands.map(t=>t.revert());this._isExecuteSubCommandsInReverseOrderWhenRevert&&(e=e.reverse());for(const t of e)t.execute();this._afterInvoke&&this._afterInvoke(),Fe(t,`revert: ${this._logMessage}`)}}),Fe(this,this._logMessage)}get kind(){return this._subCommands.reduce((t,e)=>new Set([...t,...e.kind]),new Set)}get isEmpty(){return!this._subCommands||0===this._subCommands.length}}class Je extends Ye{constructor(t,e,i){super(),this._definitionContainer=t,this._attrDef=e,this._changedProperties=i}execute(){const t=this._attrDef.pred,[e,i]=function(t,e){const i=t.externalFormat,n=new Map;for(const[s,o]of e.entries())null===o&&void 0!==t[s]?(delete i[s],n.set(s,t[s])):null!==o&&(i[s]=o,n.set(s,void 0===t[s]?null:t[s]));return[i,n]}(this._attrDef,this._changedProperties);this._revertAttrDef=this._definitionContainer.update(t,e),this._revertChangedProperties=i,Fe(this,`change old pred:${t} to new attridute definition:${JSON.stringify(e)}`)}revert(){return new Je(this._definitionContainer,this._revertAttrDef,this._revertChangedProperties)}}class ti extends He{#Ht;#Le;#Ne;#je;#ze;#Be;#qe;constructor(t,e,i,n){super(),this.#Ht=t,this.#Le=e,this.#Ne=e.pred,this.#je=e.obj,this.#ze=i,this.#Be=n}execute(){this.#qe=this.#Ht.attributeInstanceContainer.change(this.#Le.id,this.#ze,this.#Be),Fe(this,`attribute: ${this.#Le.id} changed from ${this.#Ne}:${this.#je} to ${this.#qe.pred}:${this.#qe.obj}.`)}revert(){return new ti(this.#Ht,this.#qe,this.#Ne,this.#je)}}class ei extends Ke{constructor(t,e,i,n,s){super(),this._isExecuteSubCommandsInReverseOrderWhenRevert=!1;const o=[new Je(i,n,s)];let r=[];if(s.has("pred")){const i=e.attributeInstanceContainer.getSameDefinitionsAttributes(n.pred);r=i.map(t=>new ti(e,t,s.get("pred"),t.obj)),this._afterInvoke=()=>{t.emit("textae-event.commander.attributes.change",i)}}this._subCommands=o.concat(r),this._logMessage=`set ${[...s.entries()].map(([t,e])=>`${t}:${e}`)} to attribute definition ${n.pred}`}}class ii extends Ke{constructor(t,e,i,n,s){super();const o=[];for(const t of i){const e=t.attributes.find(t=>t.pred==n.pred&&t.obj!==s);e&&o.push(e)}this._subCommands=o.map(t=>new ti(e,t,null,s)),o.length&&(this._afterInvoke=()=>t.emit("textae-event.commander.attributes.change",o)),this._logMessage=`update obj ${s} to attributes: ${o.map(t=>t.id).join(",")}`}}function ni(t,e,i,n){if("string"===e.valueType&&n&&!e.values.some(t=>t.pattern===i)&&n!==e.getLabel(i))return new Ge(t,e,{pattern:i,label:n})}class si extends Ke{constructor(t,e,i,n,s,o,r=null){super();const a=[];for(const t of n){const e=t.attributes.find(t=>t.pred==s.pred&&t.obj!==o);e&&a.push(e)}this._subCommands=a.map(t=>new ti(e,t,null,o)),a.length&&(this._afterInvoke=()=>t.emit("textae-event.commander.attributes.change",a));const l=ni(i,s,o,r);l&&this._subCommands.push(l),this._logMessage=`update obj ${o} to attributes: ${a.map(t=>t.id).join(",")}`}}class oi extends He{#Ze;#Oe;#H;#Fe;constructor(t,e,i,n){super(),this.#Ze=t,this.#Oe=e,this.#H=i,this.#Fe=n}execute(){this.oldType=this.#Ze.getInstanceContainerFor(this.#Oe).get(this.#H).typeName;const t=this.#Ze.getInstanceContainerFor(this.#Oe).changeType(this.#H,this.#Fe);Fe(this,`change type of a ${this.#Oe}. old type:${this.oldType} ${this.#Oe}:`,t)}revert(){return new oi(this.#Ze,this.#Oe,this.#H,this.oldType)}}class ri extends Ke{constructor(t,e,i,n,s){super();const o=e[i].all.filter(t=>!t.typeValues.isSameType(n,s));this._subCommands=o.map(e=>new oi(t,i,e.id,n)),this._subCommands=this._subCommands.concat(function(t,e,i){const n=[];for(const s of t){if(s.typeValues)for(const t of s.attributes){const s=e.find(e=>t.equalsTo(e.pred,e.obj));s?String(t.obj)!==s.obj&&n.push(new ti(i,t,s.pred,s.obj)):n.push(new Ve(i,"attribute",t))}for(const t of e)s.attributes.some(e=>e.equalsTo(t.pred,t.obj))||n.push(new We(i,"attribute",{subj:s.id,pred:t.pred,obj:t.obj}))}return n}(o,s,t));for(const{pred:e,obj:i,label:n}of s){const s=t.typeDictionary.attribute,o=s.get(e),r=ni(s,o,i,n);r&&this._subCommands.push(r)}this._logMessage=`set type ${n}${s.length>0?` and attributes ${JSON.stringify(s)}`:""} to ${i} items ${o.map(t=>t.id)}`}}class ai extends Ye{constructor(t,e,i,n,s){super(),this._annotationModel=t,this._definitionContainer=e,this._id=i,this._changedProperties=n,this._newDefaultTypeId=s}execute(){const t=this._definitionContainer.get(this._id),[e,i]=function(t,e){const i={...e},n=new Map;for(const[s,o]of t.entries())null===o&&void 0!==e[s]?(delete i[s],n.set(s,e[s])):null!==o&&(i[s]=o,n.set(s,void 0===e[s]?null:e[s]));return[i,n]}(this._changedProperties,t);this._definitionContainer.replace(this._id,e),e.default?(this.revertDefaultTypeId=this._definitionContainer.defaultType,this._definitionContainer.defaultType=e.id):this._newDefaultTypeId&&(this._definitionContainer.defaultType=this._newDefaultTypeId),this.revertId=e.id,this.revertChangedProperties=i,Fe(this,`change old type:${JSON.stringify(t)} to new type:${JSON.stringify(e)}, default is ${this._definitionContainer.defaultType}`)}revert(){return new ai(this._annotationModel,this._definitionContainer,this.revertId,this.revertChangedProperties,this.revertDefaultTypeId)}}class li extends Ye{constructor(t,e,i){super(),this._definitionContainer=t,this._removeType=e,this._revertDefaultTypeId=i}execute(){const{id:t}=this._removeType,e=this._definitionContainer.get(t);this._definitionContainer.delete(t,this._revertDefaultTypeId),e&&(this._removeType=e),Fe(this,`remove a type:${JSON.stringify(this._removeType)}, default is ${this._definitionContainer.defaultType}`)}revert(){return new ci(this._definitionContainer,this._removeType)}}class ci extends Ye{constructor(t,e){super(),this._definitionContainer=t,this._newType=e}execute(){this._revertDefaultTypeId=this._definitionContainer._defaultType,this._definitionContainer.addDefinedType(this._newType),Fe(this,`create a new type:${JSON.stringify(this._newType)}, default is ${this._definitionContainer.defaultType}`)}revert(){return new li(this._definitionContainer,this._newType,this._revertDefaultTypeId)}}function hi(t,e,i,n){return t.has(e)?new ai(i,t,e,n,null):new ci(t,{id:e,...Object.fromEntries(n)})}class ui extends Ke{constructor(t,e,i,n,s,o){super();const r=[];i&&r.push(hi(s,n,t,new Map([["label",i]])));const a=new ri(t,e,s.annotationType,n,o);a.isEmpty||r.push(a),this._subCommands=r,this._logMessage=`change ${s.annotationType} value:"${n}"${i?`, label:"${i}"`:""}${o.length>0?`, attributes:${JSON.stringify(o)}`:""}`}}class di extends Ke{constructor(t,e,i,n,s){super();const o=[hi(e,n,t,s)];let r=[];s.has("id")&&(r=function(t,e,i,n){return t.getInstanceContainerFor(e).all.filter(t=>t.typeName===i).map(i=>new oi(t,e,i.id,n))}(t,i,n,s.get("id"))),this._subCommands=o.concat(r),this._logMessage=`set ${[...s.entries()].map(([t,e])=>`${t}:${e}`)} to type definition ${n}`}}class fi extends Ke{constructor(t,e,i,n){super();const s=e[i].all.filter(t=>!t.typeValues.isSameType(n));this._subCommands=s.map(e=>new oi(t,i,e.id,n)),this._logMessage=`set type ${n} to ${i} items ${s}`}}class pi extends Ye{constructor(t,e,i,n,s){super(),this._definitionContainer=t,this._attrDef=e,this._targetIndex=i,this._newValue=n,this._indexThatRemoveDefaultFrom=s}execute(){if("selection"===this._attrDef["value type"]&&(!this._attrDef.values[this._targetIndex].default&&this._newValue.default&&(this._indexThatRemoveDefaultFrom||(this._indexThatRemoveDefaultFrom=this._attrDef.values.findIndex(t=>t.default)),delete this._attrDef.values[this._indexThatRemoveDefaultFrom].default),this._attrDef.values[this._targetIndex].default&&!this._newValue.default))if(1===this._attrDef.values.length)this._newValue.default=!0;else if(this._indexThatRemoveDefaultFrom)this._attrDef.values[this._indexThatRemoveDefaultFrom].default=!0;else{let t=null;this._attrDef.values.forEach((e,i)=>{null===t&&i!=this._targetIndex&&(t=i)}),this._attrDef.values[t].default=!0,this._indexThatRemoveDefaultFrom=t}this._valueBeforeChange=this._attrDef.values.splice(this._targetIndex,1,this._newValue)[0],this._definitionContainer.update(this._attrDef.pred,this._attrDef),Fe(this,`change value of attrribute:${this._attrDef.pred}, oldValue: ${JSON.stringify(this._valueBeforeChange)}, newValue: ${JSON.stringify(this._newValue)}`)}revert(){return new pi(this._definitionContainer,this._attrDef,this._targetIndex,this._valueBeforeChange,this._indexThatRemoveDefaultFrom)}}class mi extends Ke{constructor(t,e,i,n,s,o,r){if(super(),this._subCommands=[new pi(i,n,s,o,r)],"selection"===n["value type"]&&n.values[s].id!==o.id){const i=e.attributeInstanceContainer.getSameAttributes(n.pred,n.values[s].id),r=i.map(t=>new ti(e,t,null,o.id));this._subCommands=this._subCommands.concat(r),this._afterInvoke=()=>t.emit("textae-event.commander.attributes.change",i)}this._logMessage=`attribute: ${n.pred}`}}class gi extends Ye{constructor(t,e){super(),this._definitionContainer=t,this._removeAttrdef=e,this._index=t.getIndexOf(e.pred)}execute(){this._definitionContainer.delete(this._removeAttrdef.pred),Fe(this,`remove an attrribute definition:${JSON.stringify(this._removeAttrdef)}, index:${this._index}`)}revert(){return new vi(this._definitionContainer,this._removeAttrdef,this._index)}}class vi extends Ye{constructor(t,e,i){super(),this._definitionContainer=t,this._newAttrDef=e,this._index=i}execute(){"selection"!==this._newAttrDef.valueType||this._newAttrDef.values||(this._newAttrDef.values=[{id:"default",default:!0}]),this._definitionContainer.create(this._newAttrDef.valueType,this._newAttrDef,this._index),Fe(this,`create a new attrribute definition:${JSON.stringify(this._newAttrDef)}, index: ${this._index}`)}revert(){return new gi(this._definitionContainer,this._newAttrDef)}}function yi(t,e,i,n){return e.filter(t=>!t.typeValues.hasSpecificPredicateAttribute(i)).map(({id:e})=>new We(t,"attribute",{id:null,subj:e,pred:i,obj:n}))}class Oi extends Ke{constructor(t,e,i,n){super(),this._subCommands=yi(t,e,i.pred,n||i.default),this._logMessage=`create attirbute ${i.pred}:${i.default} to item ${e.map(({id:t})=>t).join(", ")}`}}class bi extends We{constructor(t,e,i){super(t,"attribute",{obj:e,pred:i})}execute(){const t=this._annotationModel.entityInstanceContainer.all.pop().id;return this._instance.subj=t,super.execute()}}class xi extends Ke{constructor(t,e,i,n,s,o,r){super(),this._subCommands=[new We(t,"entity",{spanType:i,begin:n,end:s,typeName:o},e)].concat(r.map(({obj:e,pred:i})=>new bi(t,e,i))),this._logMessage=`span: ${n}:${s}, type: ${o}${r.length?`, attributes: ${r.map(({pred:t})=>t).join(", ")}`:""}`}}class wi extends Ke{constructor(t,e,i,n,s,o){super();const r=new We(e,"span",{begin:n,end:s,isBlock:!0},i),a=new xi(e,i,"block",n,s,o,[]);this._subCommands=[r,a],this._logMessage=`create a span ${n}:${s} with type ${o}`}}class _i extends Ke{constructor(t,e,i){super();const n=e.span.all.filter(t=>t.isDenotation);this._subCommands=n.map(n=>new We(t,"entity",{spanType:"denotation",begin:n.begin,end:n.end,typeName:i},e)),this._logMessage=`create a ${i} type entity to ${n}`}}class Si extends Ke{constructor(t,e,i,n,s,o){super(),this._subCommands=[new We(t,"span",{begin:n,end:s},e)].concat(o.map(i=>new xi(t,e,"denotation",n,s,i.typeName,i.attributes))),this._logMessage=`span: ${n}:${s}, types: ${o.map(({typeName:t})=>t).join(", ")}`}}class ki extends Ke{constructor(t,e,i,n,s,o){super(),console.log(n),this._subCommands=e.getReplicationRanges(n,o).map(({begin:n,end:o})=>new Si(e,i,t,n,o,s)),this._logMessage=`from span: ${n.id}`}}class $i extends Ke{constructor(t,e,i,n,s,o,r){super();const a=[new Ot(s)];this._subCommands=[new Si(e,i,t,n.begin,n.end,a)],this._logMessage=`create a span ${n.begin}:${n.end} with type ${a[0].typeName}`,o&&n.end-n.begin<=100&&(this._subCommands.push(new ki(t,e,i,{begin:n.begin,end:n.end},a,r)),this._logMessage=`${this._logMessage} and replicate auto`)}}class Ci extends Ye{constructor(t,e,i){super(),this._definitionContainer=t,this._oldIndex=e,this._newIndex=i}execute(){this._definitionContainer.move(this._oldIndex,this._newIndex),Fe(this,`move the attrribute definition: from ${this._oldIndex} to ${this._newIndex}`)}revert(){return new Ci(this._definitionContainer,this._newIndex,this._oldIndex)}}class Ti extends He{#T;#Xe;#He;#We;#Ve;constructor(t,e,i,n,s){super(),this.#T=t,this.#Xe=e,this.#He=i,this.#We=n,this.#Ve=s}execute(){this.#T.moveBlockSpan(this.#Xe,this.#He,this.#We,this.#Ve),Fe(this,`move span: from {begin: ${this.#Xe}, end: ${this.#He} } to {begin: ${this.#We}, end: ${this.#Ve}}`)}revert(){return new Ti(this.#T,this.#We,this.#Ve,this.#Xe,this.#He)}}class Pi extends He{#T;#Xe;#He;#We;#Ve;constructor(t,e,i,n,s){super(),this.#T=t,this.#Xe=e,this.#He=i,this.#We=n,this.#Ve=s}execute(){this.#T.moveDenotationSpan(this.#Xe,this.#He,this.#We,this.#Ve),Fe(this,`move span: from {begin: ${this.#Xe}, end: ${this.#He} } to {begin: ${this.#We}, end: ${this.#Ve}}`)}revert(){return new Pi(this.#T,this.#We,this.#Ve,this.#Xe,this.#He)}}function Ei(t,e){return t.entities.every(t=>e.includes(t))}class Ai extends Ke{constructor(t,e){super(),this._subCommands=[];for(const[i,n]of e.entries())this._subCommands.push(new Mi(t,i,n));this._logMessage=`revert: move entities ${Array.from(e.values()).flat().map(t=>t.id).join(", ")}`}}class Mi extends He{constructor(t,e,i){super(),this._annotationModel=t,this._span=e,this._entities=i}execute(){this._moveMap=this._entities.reduce((t,e)=>(t.has(e.span)?t.get(e.span).push(e):t.set(e.span,[e]),t),new Map);const t=`${Array.from(this._moveMap.entries()).map(([t,e])=>`${e.map(t=>t.id).join(", ")} from ${e[0].span.id} to ${this._span.id}`).join(", ")}`;this._annotationModel.entityInstanceContainer.moveEntities(this._span,this._entities),Fe(this,t)}revert(){return new Ai(this._annotationModel,this._moveMap)}}class Qi extends Ke{constructor(t,e,i){console.assert(e.span.single,"There must be one span to be pasted."),super();const n=[new Mi(t,e.span.single,i)];for(const e of i.map(t=>t.span).reduce((t,e)=>(t.add(e),t),new Set).values())Ei(e,i)&&n.push(new Ve(t,"span",e));this._subCommands=n,this._logMessage="paste cut entities"}}class Di extends Ke{constructor(t,e,i,n,s,o){super();const r=e.span.all;this._subCommands=[];for(const e of n)this._subCommands.push(new ci(t.denotationDefinitionContainer,e));for(const e of s)this._subCommands.push(new vi(t.attributeInstanceContainerDefinitionContainer,{valueType:e["value type"],...e}));for(const{pred:e,value:i}of o)this._subCommands.push(new Ge(t.attributeInstanceContainerDefinitionContainer,t.attributeInstanceContainerDefinitionContainer.get(e),i));this._subCommands=this._subCommands.concat(r.map(n=>i.map(i=>new xi(t,e,"denotation",n.begin,n.end,i.typeName,i.attributes))).flat()),this._logMessage=`paste types [${i.map(({typeName:t,attributes:e})=>[`{type:${t}}`].concat(e.map(({pred:t,obj:e})=>`{${t}:${e}}`)))}] to ${r}`}}function Ri(t,e,i){return e.reduce((t,{attributes:e})=>t.concat(e),[]).filter(t=>t.pred===i).map(e=>new Ve(t,"attribute",e))}class Ii extends Ke{constructor(t,e,i){super();const n=Ri(t,e,i.pred);this._subCommands=n,this._logMessage=`remove ${i.pred} attribute from items ${e.map(t=>t.id).join(", ")}`}}function Li(t,e,i){t.add(i);for(const t of i.attributes)e.add(t)}function Ni(t,e,i,n){t.add(n);for(const t of n.attributes)i.add(t);for(const t of n.relations)Li(e,i,t)}class ji extends Ke{constructor(t,e){super();const i=new Set,n=new Set,s=new Set,o=new Set;for(const t of e.span.all){i.add(t);for(const e of t.entities)Ni(n,s,o,e)}for(const t of e.entity.all)Ni(n,s,o,t);for(const t of e.relation.all)Li(s,o,t);for(const n of t.spanInstanceContainer.all)n.entities.every(t=>e.entity.all.includes(t))&&(n.styleOnly||i.add(n));this._subCommands=[];for(const e of o)this._subCommands.push(new Ve(t,"attribute",e));for(const e of s)this._subCommands.push(new Ve(t,"relation",e));for(const e of n)this._subCommands.push(new Ve(t,"entity",e));for(const e of i)this._subCommands.push(new Ve(t,"span",e));this._logMessage=`remove selected ${[...i,...n,...s,...o].map(({id:t})=>t).join(", ")}`}}class zi extends Ke{constructor(t,e){super();const i=new Ve(t,"relation",e),n=e.attributes.map(e=>new Ve(t,"attribute",e));this._subCommands=n.concat(i),this._logMessage=`remove a relation ${e.id}`}}class Bi extends Ke{constructor(t,e){super();const i=new Ve(t,"entity",e),n=e.relations.map(e=>new zi(t,e)),s=e.attributes.map(e=>new Ve(t,"attribute",e));this._subCommands=n.concat(s).concat(i),this._logMessage=`remove an entity ${e.id}`}}class qi extends Ke{constructor(t,e){super();const i=t.getSpan(e),n=i.entities.map(e=>new Bi(t,e)),s=new Ve(t,"span",i);this._subCommands=n.concat(s),this._logMessage=`remove a span ${e}`}}class Zi extends Ke{constructor(t,e,i){super(),this._subCommands=yi(t,e,i.pred,i.default);const n=Ri(t,e,i.pred);this._subCommands=this._subCommands.concat(n),this._logMessage=`toggle flag attirbute ${i.pred} to item ${e.map(({id:t})=>t).join(", ")}`}}class Fi extends He{#Ht;#Ye;#Ue;#Ge;#Ke;#Je;constructor(t,e,i){super(),this.#Ht=t,this.#Ye=e.begin,this.#Ue=e.end,this.#Ge=i}execute(){this.#Ke=this.#Ye+this.#Ge.length,this.#Je=this.#Ht.getTextBetween(this.#Ye,this.#Ue);const t=this.#Ht.changeTextBetween(this.#Ye,this.#Ue,this.#Ge);Fe(this,`change text at ${this.#Ye}:${this.#Ue} to ${this.#Ge} and spans [${t.map(({begin:t,end:e})=>`${t}:${e}`).join(", ")}] are effected.`)}revert(){return new Fi(this.#Ht,{begin:this.#Ye,end:this.#Ke},this.#Je)}}class Xi extends Ke{constructor(t,e,i,n){super(),this._isExecuteSubCommandsInReverseOrderWhenRevert=!1,this._subCommands=[new Fi(t,{begin:e,end:i},n)],this._logMessage=`change text from ${e} to ${i} to ${n}`}}class Hi{#M;#Nt;#Ht;#Ie;constructor(t,e,i,n){this.#M=t,this.#Nt=e,this.#Ht=i,this.#Ie=n}addValueToAttributeDefinitionCommand(t,e){return new Ge(this.#Ht.typeDictionary.attribute,t,e)}changeAttributeDefinitionCommand(t,e){return new ei(this.#Nt,this.#Ht,this.#Ht.typeDictionary.attribute,t,e)}changeAttributeObjOfItemsCommand(t,e,i){return new ii(this.#Nt,this.#Ht,t,e,i)}changeStringAttributeObjOfItemsCommand(t,e,i,n){return new si(this.#Nt,this.#Ht,this.#Ht.typeDictionary.attribute,t,e,i,n)}changeTypeValuesCommand(t,e,i,n){return new ui(this.#Ht,this.#Ie,t,e,i,n)}changeTypeDefinitionCommand(t,e,i,n){return new di(this.#Ht,t,e,i,n)}changeTypeOfSelectedItemsCommand(t,e){return new fi(this.#Ht,this.#Ie,t,e)}changeValueOfAttributeDefinitionAndObjectOfSelectionAttributeCommand(t,e,i){return new mi(this.#Nt,this.#Ht,this.#Ht.typeDictionary.attribute,t,e,i)}createAttributeDefinitionCommand(t){return new vi(this.#Ht.typeDictionary.attribute,t)}createAttributeToItemsCommand(t,e,i=null){return new Oi(this.#Ht,t,e,i)}createBlockSpanCommand(t){return new wi(this.#M,this.#Ht,this.#Ie,t.begin,t.end,this.#Ht.typeDictionary.block.defaultType)}createDefaultTypeEntityToSelectedSpansCommand(t){return new _i(this.#Ht,this.#Ie,t)}createRelationCommand(t){return new We(this.#Ht,"relation",t,this.#Ie)}createSpanAndAutoReplicateCommand(t,e,i){return new $i(this.#M,this.#Ht,this.#Ie,t,this.#Ht.typeDictionary.denotation.defaultType,e,i)}createTypeDefinitionCommand(t,e){return new ci(t,e)}deleteAttributeDefinitionCommand(t){return new gi(this.#Ht.typeDictionary.attribute,t)}moveAttributeDefinitionCommand(t,e){return new Ci(this.#Ht.typeDictionary.attribute,t,e)}moveBlockSpanCommand(t,e,i){const{begin:n,end:s}=this.#Ht.getSpan(t);return new Ti(this.#Ht.spanInstanceContainer,n,s,e,i)}moveDenotationSpanCommand(t,e,i){const{begin:n,end:s}=this.#Ht.getSpan(t);return new Pi(this.#Ht.spanInstanceContainer,n,s,e,i)}moveEntitiesToSelectedSpanCommand(t){return new Qi(this.#Ht,this.#Ie,t)}pasteTypesToSelectedSpansCommand(t,e=[],i=[],n=[]){return new Di(this.#Ht,this.#Ie,t,e,i,n)}replicateSpanCommand(t,e,i){return new ki(this.#M,this.#Ht,this.#Ie,t,e,i)}removeAttributesFromItemsByPredCommand(t,e){return new Ii(this.#Ht,t,e)}removeSpanCommand(t){return new qi(this.#Ht,t)}removeSelectedCommand(){return new ji(this.#Ht,this.#Ie)}removeTypeDefinitionCommand(t,e){return new li(t,e)}removeValueFromAttributeDefinitionCommand(t,e){return new Ue(this.#Ht.typeDictionary.attribute,t,e)}toggleFlagAttributeToItemsCommand(t,e){return new Zi(this.#Ht,t,e)}changeTextAndMoveSpanCommand(t,e,i){return new Xi(this.#Ht,t,e,i)}}class Wi{#Q;#M;#Nt;#Ht;#Ie;#ti;constructor(t,e,i,n,s){this.#Q=t,this.#M=e,this.#Nt=i,this.#Ht=n,this.#Ie=s,this.#ti=new Ze(i)}invoke(t){t.isEmpty||(t.execute(),this.#ti.push(t))}undo(){if(this.#ti.hasAnythingToUndo){this.#Ie.removeAll(),this.#Q.focus();const t=this.#ti.prev();t.kind.has("configuration_command")&&e().success("configuration has been undone"),t.revert().execute()}}redo(){if(this.#ti.hasAnythingToRedo){this.#Ie.removeAll();const t=this.#ti.next();t.kind.has("configuration_command")&&e().success("configuration has been redo"),t.execute()}}get factory(){return new Hi(this.#M,this.#Nt,this.#Ht,this.#Ie,this.#Ht.typeDictionary)}}class Vi{constructor(t,e){this._editorHTMLElement=t,this._selectionModel=e}left(t){const e=this._searchLeft(".textae-editor__span");if(e)return void(t?this._selectionModel.add("span",[e.id]):this._selectionModel.selectSpan(e.id));const i=this._searchLeft(".textae-editor__grid .textae-editor__signboard");i&&(t?this._selectionModel.add("entity",[i.dataset.id]):this._selectionModel.selectEntity(i.dataset.id))}right(t){const e=this._searchRight(".textae-editor__span");if(e)return void(t?this._selectionModel.add("span",[e.id]):this._selectionModel.selectSpan(e.id));const i=this._searchRight(".textae-editor__grid .textae-editor__signboard");i&&(t?this._selectionModel.add("entity",[i.dataset.id]):this._selectionModel.selectEntity(i.dataset.id))}_searchLeft(t){const e=this._editorHTMLElement.querySelectorAll(t),i=[...e].findIndex(t=>t.classList.contains("ui-selected")||t.classList.contains("textae-editor__signboard--selected"));if(i>0)return e[i-1]}_searchRight(t){const e=this._editorHTMLElement.querySelectorAll(t),i=[...e].reverse().findIndex(t=>t.classList.contains("ui-selected")||t.classList.contains("textae-editor__signboard--selected"));if(e.length-i>0)return e[e.length-i]}}class Yi{constructor(t,e){this._editorHTMLElement=t,this._selectionModel=e}up(){if(this._selectionModel.span.single){const t=this._selectionModel.span.single.gridElement.querySelector(".textae-editor__signboard");this._selectionModel.selectEntity(t.dataset.id)}}down(){const t=this._editorHTMLElement.querySelector(".textae-editor__signboard--selected");if(t){const e=t.closest(".textae-editor__grid").id.substring(1);this._selectionModel.selectSpan(e)}}}function Ui(t){return s()(t,300)}function Gi(t,e){r()(t,".textae-editor__setting-dialog__line-height-text","change",Ui(t=>{e.lineHeight=t.target.value,function(){const t=new Event("resize");window.dispatchEvent(t)}()}))}function Ki(t,e,i,n,s,o){!function(t,e,i){r()(t,".textae-editor__setting-dialog__type-gap-text","change",Ui(n=>{e.value=Number(n.target.value),t.querySelector(".textae-editor__setting-dialog__line-height-text").value=i.lineHeight}))}(t,i,s),Gi(t,s),function(t,e){r()(t,".textae-editor__setting-dialog__lock-config-text","change",Ui(t=>{t.target.checked?e.lockEdit():e.unlockEdit()}))}(t,n),function(t,e,i){r()(t,".textae-editor__setting-dialog__function-availability-checkbox","change",Ui(({target:t})=>{const n=t.closest(".textae-editor__setting-dialog__function-availability-label").textContent.trim();t.checked?(i.enable(n),e.emit("textae-event.configuration.reset")):(i.disable(n),e.emit("textae-event.configuration.reset"))}))}(t,e,o)}const Ji="14.2.0";class tn{static escape(t){return t.replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")}static decode(t){return t.replace(/\\n/g,"\n").replace(/\\t/g,"\t").replace(/\\r/g,"\r")}}function en(t){const e=tn.escape(t);return st()(e)}function nn(t){const{typeGap:e,typeGapDisabled:i,lineHeight:n,autocompletionWs:s,typeDictionaryLocked:o,delimiterCharacters:r,blankCharacters:a,functionAvailability:l,version:c}=t;return ot`
211
211
  <div class="textae-editor__setting-dialog__container">
212
212
  <div class="textae-editor__setting-dialog__row">
213
213
  <label>Type Gap</label>
@@ -301,7 +301,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
301
301
  ${this.#hi?"":'disabled="disabled"'}
302
302
  value="Open">
303
303
  </div>
304
- `}bind(t,e){r()(t,".textae-editor__load-dialog__url-text","input",t=>{wn(t.target.nextElementSibling,t.target.value)}),r()(t,".textae-editor__load-dialog__url-button","click",t=>e(t.target.previousElementSibling.value))}}var XO=i(2628),HO=i.n(XO);function WO(t,e){t.element.classList.remove("textae-editor__load-dialog__overlay-dropzone--maximized"),t.element.style.zIndex=e}class VO{#ui;get template(){return'\n<div class="textae-editor__load-dialog__row">\n <label>\n Local\n </label>\n <form class="dropzone textae-editor__load-dialog__dropzone">\n <div class="dz-message">\n Drop a file here or click to select\n </div>\n </form>\n <div class="textae-editor__load-dialog__dz-file-preview">\n <div class="dz-filename"><span data-dz-name>No file selected</span></div>\n </div>\n <input\n type="button"\n class="textae-editor__load-dialog__local-button"\n disabled="disabled"\n value="Open">\n</div>\n'}bind(t,e){r()(t,".textae-editor__load-dialog__local-button","click",()=>e(this.#ui))}intiializeDropzone(t){const e={url:"nothing",previewsContainer:".textae-editor__load-dialog__dz-file-preview",previewTemplate:t.querySelector(".textae-editor__load-dialog__dz-file-preview").innerHTML},i=new(HO())("body > div.ui-widget-overlay.ui-front",{...e,clickable:!1}),n=i.element.style.zIndex;i.on("dragenter",()=>function(t){const{element:e}=t;e.classList.add("textae-editor__load-dialog__overlay-dropzone--maximized"),e.style.zIndex=parseInt(e.style.zIndex)+1}(i)).on("dragleave",()=>WO(i,n)).on("addedfile",e=>{WO(i,n),this.#di(t,e)});new(HO())(".textae-editor__load-dialog__dropzone",e).on("addedfile",e=>{this.#di(t,e)})}#di(t,e){t.querySelector(".textae-editor__load-dialog__dz-file-preview").firstElementChild.remove(),t.querySelector(".textae-editor__load-dialog__dz-file-preview > div").setAttribute("title",e.name),this.#ui=e,wn(t.querySelector(".textae-editor__load-dialog__local-button"),!0)}}class YO extends u{#fi;constructor(t,e,i,n,s,o){const a=new FO(e),l=new VO;super(t,function(t){const{url:e,local:i}=t;return`\n<div class="textae-editor__load-dialog__container">\n ${e}\n ${i}\n <div class="textae-editor__load-dialog__row">\n <div class="textae-editor__load-dialog__format">\n <label class="textae-editor__load-dialog__format-button">\n <input type="radio" name="format" value="json" checked>JSON\n </label>\n <label class="textae-editor__load-dialog__format-button">\n <input type="radio" name="format" value="inline">Text\n </label>\n </div>\n <textarea class="textae-editor__load-dialog__textarea"></textarea>\n <input type="button" value="Edit" class="edit" disabled="disabled">\n <input type="button" value="Open" class="instant" disabled="disabled">\n </div>\n</div>`}({url:a.template,local:l.template})),this.#fi=l,a.bind(super.el,t=>{ZO(o)&&i(t),super.close()}),this.#fi.bind(super.el,t=>{ZO(o)&&n(t),super.close()}),r()(super.el,".textae-editor__load-dialog__textarea","input",t=>{wn(super.el.querySelector('[type="button"].instant'),t.target.value),wn(super.el.querySelector('[type="button"].edit'),t.target.value)});let c=null;r()(super.el,'[type="button"].instant',"click",()=>{const t=c?c.state.doc.toString():super.el.querySelector(".textae-editor__load-dialog__textarea").value,e=this.#pi();ZO(o)&&s(t,e),super.close()}),r()(super.el,'[type="button"].edit',"click",()=>{this.#mi();const t=super.el.querySelector(".textae-editor__load-dialog__textarea"),e=this.#pi();"json"===e&&_n(t.value)&&(t.value=JSON.stringify(JSON.parse(t.value),null,2));const i=super.el.closest(".textae-editor__dialog").clientHeight;c="json"===e?qO(t,i):function(t,e){const i=Tc.theme({"&":{height:.6*e+"px"}}),n=new Tc({doc:t.value,extensions:[Qy,Qf(If),i]});return t.parentNode.insertBefore(n.dom,t),t.style.display="none",n}(t,i);const n=super.el.querySelectorAll('.textae-editor__load-dialog__format-button input[type="radio"]');for(const t of n)t.disabled=!0;super.el.querySelector('[type="button"].edit').disabled=!0})}open(){super.open(),this.#fi.intiializeDropzone(super.el)}#mi(){super.el.closest(".textae-editor__dialog").classList.add("textae-editor__load-dialog--expanded")}#pi(){return super.el.querySelector('input[name="format"]:checked').value}}class UO extends u{#fi;constructor(t,e,i,n,s,o){const a=new FO(e),l=new VO;super(t,function(t){const{url:e,local:i}=t;return`\n<div class="textae-editor__load-dialog__container">\n ${e}\n ${i}\n <div class="textae-editor__load-dialog__row json">\n <label>\n JSON\n </label>\n <textarea class="textae-editor__load-dialog__textarea"></textarea>\n <input type="button" value="Edit" class="edit" disabled="disabled">\n <input type="button" value="Open" class="instant" disabled="disabled">\n </div>\n</div>`}({url:a.template,local:l.template})),this.#fi=l,a.bind(super.el,t=>{ZO(o)&&i(t),super.close()}),this.#fi.bind(super.el,t=>{ZO(o)&&n(t),super.close()}),r()(super.el,".textae-editor__load-dialog__textarea","input",t=>{wn(super.el.querySelector('[type="button"].instant'),t.target.value),wn(super.el.querySelector('[type="button"].edit'),t.target.value)});let c=null;r()(super.el,'[type="button"].instant',"click",()=>{const t=c?c.state.doc.toString():super.el.querySelector(".textae-editor__load-dialog__textarea").value;ZO(o)&&s(t),super.close()}),r()(super.el,'[type="button"].edit',"click",()=>{this.#mi();const t=super.el.querySelector(".textae-editor__load-dialog__textarea");_n(t.value)&&(t.value=JSON.stringify(JSON.parse(t.value),null,2));const e=super.el.closest(".textae-editor__dialog").clientHeight;c=qO(t,e),super.el.querySelector('[type="button"].edit').disabled=!0})}open(){super.open(),this.#fi.intiializeDropzone(super.el)}#mi(){super.el.closest(".textae-editor__dialog").classList.add("textae-editor__load-dialog--expanded")}}function GO(t){const e=new Blob([JSON.stringify(t)],{type:"application/json"});return URL.createObjectURL(e)}const KO=class{#gi;#vi;#Y;#H;constructor(t,e,i,n=null){this.#gi=t,this.#vi=e,this.#Y=i,this.#H=n}get beginPos(){return this.#gi}get endPos(){return this.#vi}get obj(){return this.#Y}get id(){return this.#H}get span(){return{begin:this.#gi,end:this.#vi}}toObject(){const t={span:this.span,obj:this.#Y};return this.#H&&(t.id=this.#H),t}isNestedWithin(t){return t.beginPos<=this.#gi&&this.#vi<=t.endPos}get isPositionNotInteger(){return!(Number.isInteger(this.#gi)&&Number.isInteger(this.endPos))}get isPositionNegative(){return this.#gi<0||this.#vi<0}get isPositionInvalid(){return this.#gi>this.#vi}isOutOfBounds(t){return this.#gi>=t||this.#vi>t}isBoundaryCrossing(t){const e=this.#gi>t.beginPos&&this.#gi<t.endPos,i=this.#vi>t.beginPos&&this.#vi<t.endPos;return e||i}};const JO=class{validateDenotations(t,e){let i=this.#yi(t);return i=this.#Oi(i),i=this.#bi(i),i=this.#xi(i),i=this.#wi(i,e),i=this.#_i(i),this.#Si(i)}#yi(t){const e=new Set;return t.filter(t=>{const i=JSON.stringify(t.span);return!e.has(i)&&(e.add(i),!0)})}#Oi(t){return t.filter(t=>!t.isPositionNotInteger)}#bi(t){return t.filter(t=>!t.isPositionNegative)}#xi(t){return t.filter(t=>!t.isPositionInvalid)}#wi(t,e){return t.filter(t=>!t.isOutOfBounds(e))}#_i(t){const e=t.sort((t,e)=>t.beginPos===e.beginPos?e.endPos-t.endPos:t.beginPos-e.beginPos),i=[];return e.forEach(t=>{i.some(e=>t.isNestedWithin(e))||i.push(t)}),i}#Si(t){return t.filter(e=>!t.some(t=>e!==t&&e.isBoundaryCrossing(t)))}};class tb extends Error{constructor(t){super(t),this.name=this.constructor.name}}const eb=tb;const ib=class{validateRelations(t){return this.#ki(t)}#ki(t){return t.filter(t=>t.subj&&t.pred&&t.obj)}};const nb=class{constructor(t){this.source=Object.freeze({...t}),this.denotations=this.#$i(t.denotations||[]),this.config=this.source.config}generate(){const t=this.source.text;if(!t)throw new eb('The "text" key is missing.');const e=(new JO).validateDenotations(this.denotations,t.length),i=(new ib).validateRelations(this.source.relations||[]);return[this.#Ci(t,e,i),this.#Ti()].filter(Boolean).join("\n\n")}#$i(t){return t.map(t=>new KO(t.span.begin,t.span.end,t.obj,t.id||null))}#Ci(t,e,i){return e.sort((t,e)=>e.beginPos-t.beginPos).forEach(e=>{const n=e.beginPos,s=e.endPos,o=e.id?this.#Pi(e,i):this.#Ei(e.obj),r=`[${t.slice(n,s)}][${o}]`;t=t.slice(0,n)+r+t.slice(s)}),t}#Ti(){const t=this.#Ai();return t&&0!==t.length?t.map(t=>`[${t.label}]: ${t.id}`).join("\n"):null}#Ai(){return this.config&&this.config["entity types"]?.filter(t=>t.hasOwnProperty("label"))||null}#Pi(t,e){const i=e.find(e=>e.subj===t.id)||null,n=[t.id,t.obj,i?.pred,i?.obj];if(!this.#Ai())return n.filter(t=>null!=t).join(", ");n[1]=this.#Ei(t.obj);this.#Ai().find(e=>e.id===t.obj);return n.filter(t=>null!=t).join(", ")}#Ei(t){if(!this.#Ai())return t;const e=this.#Ai().find(e=>e.id===t);return e?e.label:t}},sb=/^\s*\[([^\]]+)\]:\s+(\S+)(?:\s+(?:"[^"]*"|'[^']*'))?\s*$/,ob=new RegExp(`(?:\\A|\\n\\s*\\n)((?:${sb.source}(?:\\n|$))+)`,"gm");const rb=class{#Mi;#Qi=null;constructor(t){this.#Mi=t}get(t){return this.#Di[t]}get config(){return Object.entries(this.#Di).map(([t,e])=>({id:e,label:t}))}get#Di(){return this.#Qi||(this.#Qi=this.#Ri()),this.#Qi}#Ri(){const t={},e=Array.from(this.#Mi.matchAll(ob));for(const i of e)this.#Ii(i,t);return t}#Ii(t,e){const i=t[0].split("\n");for(const t of i)this.#Li(t,e)}#Li(t,e){const i=t.trim().match(sb);if(!i)return;const[n,s,o]=i;s!==o&&(e[s]||(e[s]=o))}},ab=new RegExp(`(?:\\A|\\n\\s*\\n)((?:${/^\s*\[([^\]]+)\]:\s+(\S+)(?:\s+(?:"[^"]*"|'[^']*'))?\s*$/.source}(?:\\n|$))+)`,"gm"),lb=/(?<!\\)\[([^\[]+?)\]\[([^\]]+?)\]/;const cb=class{#Mi;#D;#Ni;#ji;constructor(t){this.#Mi=t,this.#Ni=new rb(t)}parse(){this.#D=[],this.#ji=[];let t=this.#zi();return t=this.#Bi(t),new ub(t,this.#D,this.#ji,this.#Ni)}#zi(){return this.#Mi.replace(ab,t=>t.startsWith("\n\n")?"\n\n":"").trim()}#qi(t){return this.#Ni.get(t)||t}#Bi(t){const e=new RegExp(lb,"g");let i;for(;null!==(i=e.exec(t));){const n=i[1],s=i.index,o=s+n.length,r=i[2].split(", ");switch(r.length){case 1:this.#Zi(s,o,r[0]);break;case 2:this.#Fi(s,o,r);break;case 4:this.#Xi(s,o,r);break;default:e.lastIndex=i.index+i[0].length;continue}t=t.slice(0,i.index)+n+t.slice(i.index+i[0].length),e.lastIndex=o}return t}#Zi(t,e,i){const n=this.#qi(i);this.#D.push(new KO(t,e,n))}#Fi(t,e,i){const[n,s]=i,o=this.#qi(s);this.#D.push(new KO(t,e,o,n))}#Xi(t,e,i){const[n,s,o,r]=i,a=this.#qi(s);this.#D.push(new KO(t,e,a,n)),this.#ji.push({pred:o,subj:n,obj:r})}},hb=/\\(?=\[[^\]]+\]\[[^\]]+\])/;const ub=class{#re;#D;#ji;#Ni;constructor(t,e,i,n){this.#re=t,this.#D=e,this.#ji=i,this.#Ni=n}static parse(t){return new cb(t).parse().toObject()}static generate(t){return new nb(t).generate()}toObject(){const t={text:this.#Hi(this.#re),denotations:this.#D.map(t=>t.toObject())};this.#ji&&this.#ji.length>0&&(t.relations=this.#ji);const e=this.#Wi();return e&&Object.keys(e).length>0&&!Object.values(e).every(t=>null==t||Array.isArray(t)&&0===t.length)&&(t.config=e),t}#Hi(t){let e=this.#Vi(t);return this.#Yi(e)}#Vi(t){return t.replace(hb,"")}#Yi(t){return t.replace(/\n{2,}/g,"\n\n")}#Wi(){return this.#Ni&&0!==this.#Ni.length?{"entity types":this.#Ni.config}:null}};function db(t,e){if("json"===e)return GO(t);if("inline"===e){const e=ub.generate(t),i=new Blob([e],{type:"text/plain;charset=utf-8"});return URL.createObjectURL(i)}}function fb(t,e,i,n){t.preventDefault();!function(t,e){const i=document.createElement("a");i.setAttribute("href",t),i.setAttribute("download",e),document.body.appendChild(i),i.click(),document.body.removeChild(i)}(db(e,i),t.target.previousElementSibling.value),n.emit("textae-event.resource.annotation.save",e)}function pb(t,i,n,s,o,a){r()(i,".textae-editor__save-dialog__url-text","input",t=>{wn(t.target.nextElementSibling,t.target.value)}),r()(i,".textae-editor__save-dialog__url-text","keyup",t=>{if(13===t.keyCode){const e=a();o(t.target.value,e),s()}}),r()(i,".textae-editor__save-dialog__url-button","click",t=>{const e=a();o(t.target.previousElementSibling.value,e),s()}),r()(i,".textae-editor__save-dialog__download-link","click",i=>{const o=a();try{fb(i,n,o,t)}catch(t){e().error(`Failed to download the source as ${o} format.`)}finally{s()}}),r()(i,".textae-editor__save-dialog__viewsource-link","click",()=>{const i=a();try{!function(t,e,i){const n=db(t,e);window.open(n,"_blank"),i.emit("textae-event.resource.annotation.save",t)}(n,i,t)}catch(t){e().error(`Failed to view the source as ${i} format.`)}finally{s()}})}class mb extends u{constructor(t,e,i,n,s){super("Save Annotations",function(t){const{url:e,filename:i}=t;return`\n<div class="textae-editor__save-dialog__container">\n <div class="textae-editor__save-dialog__row">\n <span>Format</span>\n <div class="textae-editor__save-dialog__format">\n <label class="textae-editor__save-dialog__format-button">\n <input type="radio" name="format" value="json" checked>JSON\n </label>\n <label class="textae-editor__save-dialog__format-button">\n <input type="radio" name="format" value="inline">Text\n </label>\n </div>\n </div>\n <div class="textae-editor__save-dialog__row">\n <label>URL</label>\n <input\n type="text"\n value="${e}"\n class="textae-editor__save-dialog__url-text">\n <input\n type="button"\n class="textae-editor__save-dialog__url-button"\n ${e?"":'disabled="disabled"'}\n value="Save">\n </div>\n <div class="textae-editor__save-dialog__row">\n <label>Local</label>\n <input\n type="text"\n value="${i||""}"\n >\n <a class="textae-editor__save-dialog__download-link" href="#">Download</a>\n </div>\n <div class="textae-editor__save-dialog__row">\n <a class="textae-editor__save-dialog__viewsource-link" href="#">Click to see the source in a new window.</a>\n </div>\n</div>\n`}({filename:i,url:e})),pb(t,super.el,n,()=>super.close(),s,()=>super.el.querySelector('input[name="format"]:checked').value)}}function gb(t,e){if(t.length<2)throw new Error(e||"Expected an array with at least 2 items")}const vb=class{format(t,e){const i={};this.prepareContext(i);const n=i;return this.recurse(n,t,e),this.finalize(n)}prepareContext(t){t.buffer=[],t.out=function(...t){if(!this.buffer)throw new Error("context buffer is not initialized");this.buffer.push(...t)}}typeFormattterNotFound(t,e){throw new Error(`cannot format delta type: ${e}`)}typeFormattterErrorFormatter(t,e,i,n,s,o,r){}finalize({buffer:t}){return Array.isArray(t)?t.join(""):""}recurse(t,e,i,n,s,o,r){const a=e&&o?o.value:i;if(void 0===e&&void 0===n)return;const l=this.getDeltaType(e,o),c="node"===l?"a"===e._t?"array":"object":"";let h;void 0!==n?this.nodeBegin(t,n,s,l,c,null!=r&&r):this.rootBegin(t,l,c);try{h="unknown"!==l?this[`format_${l}`]:this.typeFormattterNotFound(t,l),h.call(this,t,e,a,n,s,o)}catch(i){this.typeFormattterErrorFormatter(t,i,e,a,n,s,o),"undefined"!=typeof console&&console.error&&console.error(i.stack)}void 0!==n?this.nodeEnd(t,n,s,l,c,null!=r&&r):this.rootEnd(t,l,c)}formatDeltaChildren(t,e,i){this.forEachDeltaKey(e,i,(n,s,o,r)=>{this.recurse(t,e[n],i?i[s]:void 0,n,s,o,r)})}forEachDeltaKey(t,e,i){const n=[];if(!("a"===t._t)){const s=Object.keys(t);"object"==typeof e&&null!==e&&n.push(...Object.keys(e));for(const t of s)n.indexOf(t)>=0||n.push(t);for(let t=0;t<n.length;t++){const e=n[t];if(void 0===e)continue;const s=t===n.length-1;i(e,e,void 0,s)}return}const s={};for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const i=t[e];if(Array.isArray(i)&&3===i[2]){s[i[1]]=Number.parseInt(e.substring(1))}}const o=t;let r=0,a=0;const l=Array.isArray(e)?e:void 0,c=l?l.length:Object.keys(o).reduce((t,e)=>{if("_t"===e)return t;if("_"===e.substring(0,1)){const i=o[e],n=Number.parseInt(e.substring(1)),s=Array.isArray(i)&&i.length>=3&&3===i[2]?i[1]:void 0,r=Math.max(n,null!=s?s:0);return r>t?r:t}const i=Number.parseInt(e),n=s[i],r=Math.max(null!=n?n:0,null!=i?i:0);return r>t?r:t},0)+1;let h,u=c;const d=(...t)=>{h&&i(...h),h=t};for(;r<c||a<u||`${a}`in o;){let t=!1;const e=`_${r}`,i=`${a}`,n=a in s?s[a]:void 0;if(e in o){t=!0;const i=o[e];d(e,null!=n?n:r,n?{key:`_${n}`,value:l?l[n]:void 0}:void 0,!1),Array.isArray(i)?0===i[2]?(u--,r++):(i[2],r++):r++}if(i in o){t=!0;const e=o[i],s=Array.isArray(e)&&1===e.length;d(i,null!=n?n:r,n?{key:`_${n}`,value:l?l[n]:void 0}:void 0,!1),s?(u++,a++):void 0===n?(r++,a++):a++}t||((l&&void 0===n||!1!==this.includeMoveDestinations)&&d(i,null!=n?n:r,n?{key:`_${n}`,value:l?l[n]:void 0}:void 0,!1),void 0!==n||r++,a++)}h&&i(h[0],h[1],h[2],!0)}getDeltaType(t,e){if(void 0===t)return void 0!==e?"movedestination":"unchanged";if(Array.isArray(t)){if(1===t.length)return"added";if(2===t.length)return"modified";if(3===t.length&&0===t[2])return"deleted";if(3===t.length&&2===t[2])return"textdiff";if(3===t.length&&3===t[2])return"moved"}else if("object"==typeof t)return"node";return"unknown"}parseTextDiff(t){var e;const i=[],n=t.split("\n@@ ");for(const t of n){const n={pieces:[]},s=null===(e=/^(?:@@ )?[-+]?(\d+),(\d+)/.exec(t))||void 0===e?void 0:e.slice(1);if(!s)throw new Error("invalid text diff format");gb(s),n.location={line:s[0],chr:s[1]};const o=t.split("\n").slice(1);for(let t=0,e=o.length;t<e;t++){const e=o[t];if(void 0===e||!e.length)continue;const i={type:"context"};"+"===e.substring(0,1)?i.type="added":"-"===e.substring(0,1)&&(i.type="deleted"),i.text=e.slice(1),n.pieces.push(i)}i.push(n)}return i}};class yb extends vb{typeFormattterErrorFormatter(t,e){const i="object"==typeof e&&null!==e&&"message"in e&&"string"==typeof e.message?e.message:String(e);t.out(`<pre class="jsondiffpatch-error">${Ob(i)}</pre>`)}formatValue(t,e){const i=void 0===e?"undefined":Ob(JSON.stringify(e,null,2));t.out(`<pre>${i}</pre>`)}formatTextDiffString(t,e){const i=this.parseTextDiff(e);t.out('<ul class="jsondiffpatch-textdiff">');for(let e=0,n=i.length;e<n;e++){const n=i[e];if(void 0===n)return;t.out(`<li><div class="jsondiffpatch-textdiff-location"><span class="jsondiffpatch-textdiff-line-number">${n.location.line}</span><span class="jsondiffpatch-textdiff-char">${n.location.chr}</span></div><div class="jsondiffpatch-textdiff-line">`);const s=n.pieces;for(let e=0,i=s.length;e<i;e++){const i=s[e];if(void 0===i)return;t.out(`<span class="jsondiffpatch-textdiff-${i.type}">${Ob(decodeURI(i.text))}</span>`)}t.out("</div></li>")}t.out("</ul>")}rootBegin(t,e,i){const n=`jsondiffpatch-${e}${i?` jsondiffpatch-child-node-type-${i}`:""}`;t.out(`<div class="jsondiffpatch-delta ${n}">`)}rootEnd(t){t.out("</div>"+(t.hasArrows?`<script type="text/javascript">setTimeout(${bb.toString()},10);<\/script>`:""))}nodeBegin(t,e,i,n,s){const o=`jsondiffpatch-${n}${s?` jsondiffpatch-child-node-type-${s}`:""}`,r="number"==typeof i&&"_"===e.substring(0,1)?e.substring(1):e;t.out(`<li class="${o}" data-key="${Ob(e)}"><div class="jsondiffpatch-property-name">${Ob(r)}</div>`)}nodeEnd(t){t.out("</li>")}format_unchanged(t,e,i){void 0!==i&&(t.out('<div class="jsondiffpatch-value">'),this.formatValue(t,i),t.out("</div>"))}format_movedestination(t,e,i){void 0!==i&&(t.out('<div class="jsondiffpatch-value">'),this.formatValue(t,i),t.out("</div>"))}format_node(t,e,i){const n="a"===e._t?"array":"object";t.out(`<ul class="jsondiffpatch-node jsondiffpatch-node-type-${n}">`),this.formatDeltaChildren(t,e,i),t.out("</ul>")}format_added(t,e){t.out('<div class="jsondiffpatch-value">'),this.formatValue(t,e[0]),t.out("</div>")}format_modified(t,e){t.out('<div class="jsondiffpatch-value jsondiffpatch-left-value">'),this.formatValue(t,e[0]),t.out('</div><div class="jsondiffpatch-value jsondiffpatch-right-value">'),this.formatValue(t,e[1]),t.out("</div>")}format_deleted(t,e){t.out('<div class="jsondiffpatch-value">'),this.formatValue(t,e[0]),t.out("</div>")}format_moved(t,e){t.out('<div class="jsondiffpatch-value">'),this.formatValue(t,e[0]),t.out(`</div><div class="jsondiffpatch-moved-destination">${e[1]}</div>`),t.out('<div class="jsondiffpatch-arrow" style="position: relative; left: -34px;">\n <svg width="30" height="60" style="position: absolute; display: none;">\n <defs>\n <marker id="markerArrow" markerWidth="8" markerHeight="8"\n refx="2" refy="4" stroke="#88f"\n orient="auto" markerUnits="userSpaceOnUse">\n <path d="M1,1 L1,7 L7,4 L1,1" style="fill: #339;" />\n </marker>\n </defs>\n <path d="M30,0 Q-10,25 26,50"\n style="stroke: #88f; stroke-width: 2px; fill: none; stroke-opacity: 0.5; marker-end: url(#markerArrow);"\n ></path>\n </svg>\n </div>'),t.hasArrows=!0}format_textdiff(t,e){t.out('<div class="jsondiffpatch-value">'),this.formatTextDiffString(t,e[0]),t.out("</div>")}}function Ob(t){if("number"==typeof t)return t;let e=String(t);const i=[[/&/g,"&amp;"],[/</g,"&lt;"],[/>/g,"&gt;"],[/'/g,"&apos;"],[/"/g,"&quot;"]];for(const t of i)e=e.replace(t[0],t[1]);return e}const bb=function(t){const e=t||document;((t,e,i)=>{const n=t.querySelectorAll(e);for(let t=0,e=n.length;t<e;t++)i(n[t])})(e,".jsondiffpatch-arrow",({parentNode:t,children:e,style:i})=>{const n=t,s=e[0],o=s.children[1];s.style.display="none";const r=n.querySelector(".jsondiffpatch-moved-destination");if(!(r instanceof HTMLElement))return;const a=(({textContent:t,innerText:e})=>t||e)(r),l=n.parentNode;if(!l)return;let c;if((({children:t},e)=>{for(let i=0,n=t.length;i<n;i++){const n=t[i];n&&e(n,i)}})(l,t=>{t.getAttribute("data-key")===a&&(c=t)}),c)try{const t=c.offsetTop-n.offsetTop;s.setAttribute("height",`${Math.abs(t)+6}`),i.top=`${-8+(t>0?0:t)}px`;const e=t>0?`M30,0 Q-10,${Math.round(t/2)} 26,${t-4}`:`M30,${-t} Q-10,${Math.round(-t/2)} 26,4`;o.setAttribute("d",e),s.style.display=""}catch(t){console.debug(`[jsondiffpatch] error adjusting arrows: ${t}`)}})},xb=(t,e)=>((t,e,i)=>{const n=e||document.body,s="jsondiffpatch-unchanged-",o={showing:`${s}showing`,hiding:`${s}hiding`,visible:`${s}visible`,hidden:`${s}hidden`},r=n.classList;if(!r)return;if(!i)return r.remove(o.showing),r.remove(o.hiding),r.remove(o.visible),r.remove(o.hidden),void(!1===t&&r.add(o.hidden));!1===t?(r.remove(o.showing),r.add(o.visible),setTimeout(()=>{r.add(o.hiding)},10)):(r.remove(o.hiding),r.add(o.showing),r.remove(o.hidden));const a=setInterval(()=>{bb(n)},100);setTimeout(()=>{r.remove(o.showing),r.remove(o.hiding),!1===t?(r.add(o.hidden),r.remove(o.visible)):(r.add(o.visible),r.remove(o.hidden)),setTimeout(()=>{r.remove(o.visible),clearInterval(a)},i+400)},i)})(!1,t,e);let wb;function _b(t){if("object"!=typeof t)return t;if(null===t)return null;if(Array.isArray(t))return t.map(_b);if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return function(t){var e;const i=/^\/(.*)\/([gimyu]*)$/.exec(t.toString());if(!i)throw new Error("Invalid RegExp");return new RegExp(null!==(e=i[1])&&void 0!==e?e:"",i[2])}(t);const e={};for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=_b(t[i]));return e}class Sb{setResult(t){return this.result=t,this.hasResult=!0,this}exit(){return this.exiting=!0,this}push(t,e){var i;return t.parent=this,void 0!==e&&(t.childName=e),t.root=this.root||this,t.options=t.options||this.options,this.children?(!function(t,e){if(0===t.length)throw new Error(e||"Expected a non-empty array")}(this.children),(i=this.children,i[i.length-1]).next=t,this.children.push(t)):(this.children=[t],this.nextAfterChildren=this.next||null,this.next=t),t.next=this,this}}const kb=class extends Sb{constructor(t,e){super(),this.left=t,this.right=e,this.pipe="diff"}prepareDeltaResult(t){var e,i,n,s;if("object"==typeof t&&((null===(e=this.options)||void 0===e?void 0:e.omitRemovedValues)&&Array.isArray(t)&&t.length>1&&(2===t.length||0===t[2]||3===t[2])&&(t[0]=0),null===(i=this.options)||void 0===i?void 0:i.cloneDiffValues)){const e="function"==typeof(null===(n=this.options)||void 0===n?void 0:n.cloneDiffValues)?null===(s=this.options)||void 0===s?void 0:s.cloneDiffValues:_b;"object"==typeof t[0]&&(t[0]=e(t[0])),"object"==typeof t[1]&&(t[1]=e(t[1]))}return t}setResult(t){return this.prepareDeltaResult(t),super.setResult(t)}};const $b=class extends Sb{constructor(t,e){super(),this.left=t,this.delta=e,this.pipe="patch"}};const Cb=class extends Sb{constructor(t){super(),this.delta=t,this.pipe="reverse"}};const Tb=class{constructor(t){this.name=t,this.filters=[]}process(t){if(!this.processor)throw new Error("add this pipe to a processor before using it");const e=this.debug,i=this.filters.length,n=t;for(let t=0;t<i;t++){const i=this.filters[t];if(i&&(e&&this.log(`filter: ${i.filterName}`),i(n),"object"==typeof n&&n.exiting)){n.exiting=!1;break}}!n.next&&this.resultCheck&&this.resultCheck(n)}log(t){console.log(`[jsondiffpatch] ${this.name} pipe, ${t}`)}append(...t){return this.filters.push(...t),this}prepend(...t){return this.filters.unshift(...t),this}indexOf(t){if(!t)throw new Error("a filter name is required");for(let e=0;e<this.filters.length;e++){const i=this.filters[e];if((null==i?void 0:i.filterName)===t)return e}throw new Error(`filter not found: ${t}`)}list(){return this.filters.map(t=>t.filterName)}after(t,...e){const i=this.indexOf(t);return this.filters.splice(i+1,0,...e),this}before(t,...e){const i=this.indexOf(t);return this.filters.splice(i,0,...e),this}replace(t,...e){const i=this.indexOf(t);return this.filters.splice(i,1,...e),this}remove(t){const e=this.indexOf(t);return this.filters.splice(e,1),this}clear(){return this.filters.length=0,this}shouldHaveResult(t){return!1===t?(this.resultCheck=null,this):(this.resultCheck||(this.resultCheck=t=>{if(!t.hasResult){console.log(t);const e=new Error(`${this.name} failed`);throw e.noResult=!0,e}}),this)}};const Pb=class{constructor(t){this.selfOptions=t||{},this.pipes={}}options(t){return t&&(this.selfOptions=t),this.selfOptions}pipe(t,e){let i=e;if("string"==typeof t){if(void 0===i)return this.pipes[t];this.pipes[t]=i}if(t&&t.name){if(i=t,i.processor===this)return i;this.pipes[i.name]=i}if(!i)throw new Error(`pipe is not defined: ${t}`);return i.processor=this,i}process(t,e){let i=t;i.options=this.options();let n,s=e||t.pipe||"default";for(;s;)void 0!==i.nextAfterChildren&&(i.next=i.nextAfterChildren,i.nextAfterChildren=null),"string"==typeof s&&(s=this.pipe(s)),s.process(i),n=s,s=null,i&&i.next&&(i=i.next,s=i.pipe||n);return i.hasResult?i.result:void 0}},Eb=(t,e,i,n)=>t[i]===e[n],Ab=(t,e,i,n)=>{const s=n||{},o=((t,e,i,n)=>{var s,o,r;const a=t.length,l=e.length;let c,h;const u=new Array(a+1);for(c=0;c<a+1;c++){const t=new Array(l+1);for(h=0;h<l+1;h++)t[h]=0;u[c]=t}for(u.match=i,c=1;c<a+1;c++){const a=u[c];if(void 0===a)throw new Error("LCS matrix row is undefined");const d=u[c-1];if(void 0===d)throw new Error("LCS matrix row is undefined");for(h=1;h<l+1;h++)i(t,e,c-1,h-1,n)?a[h]=(null!==(s=d[h-1])&&void 0!==s?s:0)+1:a[h]=Math.max(null!==(o=d[h])&&void 0!==o?o:0,null!==(r=a[h-1])&&void 0!==r?r:0)}return u})(t,e,i||Eb,s);return((t,e,i,n)=>{let s=e.length,o=i.length;const r={sequence:[],indices1:[],indices2:[]};for(;0!==s&&0!==o;){if(void 0===t.match)throw new Error("LCS matrix match function is undefined");if(t.match(e,i,s-1,o-1,n))r.sequence.unshift(e[s-1]),r.indices1.unshift(s-1),r.indices2.unshift(o-1),--s,--o;else{const e=t[s];if(void 0===e)throw new Error("LCS matrix row is undefined");const i=e[o-1];if(void 0===i)throw new Error("LCS matrix value is undefined");const n=t[s-1];if(void 0===n)throw new Error("LCS matrix row is undefined");const r=n[o];if(void 0===r)throw new Error("LCS matrix value is undefined");i>r?--o:--s}}return r})(o,t,e,s)};function Mb(t,e,i,n,s){const o=t[i],r=e[n];if(o===r)return!0;if("object"!=typeof o||"object"!=typeof r)return!1;const a=s.objectHash;if(!a)return s.matchByPosition&&i===n;s.hashCache1=s.hashCache1||[];let l=s.hashCache1[i];if(void 0===l&&(s.hashCache1[i]=l=a(o,i)),void 0===l)return!1;s.hashCache2=s.hashCache2||[];let c=s.hashCache2[n];return void 0===c&&(s.hashCache2[n]=c=a(r,n)),void 0!==c&&l===c}const Qb=function(t){var e,i,n,s,o;if(!t.leftIsArray)return;const r={objectHash:null===(e=t.options)||void 0===e?void 0:e.objectHash,matchByPosition:null===(i=t.options)||void 0===i?void 0:i.matchByPosition};let a,l,c,h=0,u=0;const d=t.left,f=t.right,p=d.length,m=f.length;let g,v;for(p>0&&m>0&&!r.objectHash&&"boolean"!=typeof r.matchByPosition&&(r.matchByPosition=!function(t,e,i,n){for(let s=0;s<i;s++){const i=t[s];for(let t=0;t<n;t++){const n=e[t];if(s!==t&&i===n)return!0}}return!1}(d,f,p,m));h<p&&h<m&&Mb(d,f,h,h,r);)a=h,g=new kb(d[a],f[a]),t.push(g,a),h++;for(;u+h<p&&u+h<m&&Mb(d,f,p-1-u,m-1-u,r);)l=p-1-u,c=m-1-u,g=new kb(d[l],f[c]),t.push(g,c),u++;if(h+u===p){if(p===m)return void t.setResult(void 0).exit();for(v=v||{_t:"a"},a=h;a<m-u;a++)v[a]=[f[a]],t.prepareDeltaResult(v[a]);return void t.setResult(v).exit()}if(h+u===m){for(v=v||{_t:"a"},a=h;a<p-u;a++){const e=`_${a}`;v[e]=[d[a],0,0],t.prepareDeltaResult(v[e])}return void t.setResult(v).exit()}r.hashCache1=void 0,r.hashCache2=void 0;const y=d.slice(h,p-u),O=f.slice(h,m-u),b=Ab(y,O,Mb,r),x=[];for(v=v||{_t:"a"},a=h;a<p-u;a++)if(b.indices1.indexOf(a-h)<0){const e=`_${a}`;v[e]=[d[a],0,0],t.prepareDeltaResult(v[e]),x.push(a)}let w=!0;(null===(n=t.options)||void 0===n?void 0:n.arrays)&&!1===t.options.arrays.detectMove&&(w=!1);let _=!1;(null===(o=null===(s=t.options)||void 0===s?void 0:s.arrays)||void 0===o?void 0:o.includeValueOnMove)&&(_=!0);const S=x.length;for(a=h;a<m-u;a++){const e=b.indices2.indexOf(a-h);if(e<0){let e=!1;if(w&&S>0)for(let i=0;i<S;i++){l=x[i];const n=void 0===l?void 0:v[`_${l}`];if(void 0!==l&&n&&Mb(y,O,l-h,a-h,r)){n.splice(1,2,a,3),n.splice(1,2,a,3),_||(n[0]=""),c=a,g=new kb(d[l],f[c]),t.push(g,c),x.splice(i,1),e=!0;break}}e||(v[a]=[f[a]],t.prepareDeltaResult(v[a]))}else{if(void 0===b.indices1[e])throw new Error(`Invalid indexOnArray2: ${e}, seq.indices1: ${b.indices1}`);if(l=b.indices1[e]+h,void 0===b.indices2[e])throw new Error(`Invalid indexOnArray2: ${e}, seq.indices2: ${b.indices2}`);c=b.indices2[e]+h,g=new kb(d[l],f[c]),t.push(g,c)}}t.setResult(v).exit()};Qb.filterName="arrays";const Db={numerically:(t,e)=>t-e,numericallyBy:t=>(e,i)=>e[t]-i[t]},Rb=function(t){var e;if(!t.nested)return;const i=t.delta;if("a"!==i._t)return;let n,s;const o=i,r=t.left;let a=[],l=[];const c=[];for(n in o)if("_t"!==n)if("_"===n[0]){const t=n;if(void 0===o[t]||0!==o[t][2]&&3!==o[t][2])throw new Error(`only removal or move can be applied at original array indices, invalid diff type: ${null===(e=o[t])||void 0===e?void 0:e[2]}`);a.push(Number.parseInt(n.slice(1),10))}else{const t=n;1===o[t].length?l.push({index:Number.parseInt(t,10),value:o[t][0]}):c.push({index:Number.parseInt(t,10),delta:o[t]})}for(a=a.sort(Db.numerically),n=a.length-1;n>=0;n--){if(s=a[n],void 0===s)continue;const t=o[`_${s}`],e=r.splice(s,1)[0];3===(null==t?void 0:t[2])&&l.push({index:t[1],value:e})}l=l.sort(Db.numericallyBy("index"));const h=l.length;for(n=0;n<h;n++){const t=l[n];void 0!==t&&r.splice(t.index,0,t.value)}const u=c.length;if(u>0)for(n=0;n<u;n++){const e=c[n];if(void 0===e)continue;const i=new $b(r[e.index],e.delta);t.push(i,e.index)}t.children?t.exit():t.setResult(r).exit()};Rb.filterName="arrays";const Ib=function(t){if(!t||!t.children)return;if("a"!==t.delta._t)return;const e=t.left,i=t.children.length;for(let n=0;n<i;n++){const i=t.children[n];if(void 0===i)continue;e[i.childName]=i.result}t.setResult(e).exit()};Ib.filterName="arraysCollectChildren";const Lb=function(t){if(!t.nested){const e=t.delta;if(3===e[2]){const i=e;t.newName=`_${i[1]}`,t.setResult([i[0],Number.parseInt(t.childName.substring(1),10),3]).exit()}return}const e=t.delta;if("a"!==e._t)return;const i=e;for(const e in i){if("_t"===e)continue;const n=new Cb(i[e]);t.push(n,e)}t.exit()};Lb.filterName="arrays";const Nb=(t,e,i)=>{if("string"==typeof e&&"_"===e[0])return Number.parseInt(e.substring(1),10);if(Array.isArray(i)&&0===i[2])return`_${e}`;let n=+e;for(const i in t){const s=t[i];if(Array.isArray(s))if(3===s[2]){const t=Number.parseInt(i.substring(1),10),o=s[1];if(o===+e)return t;t<=n&&o>n?n++:t>=n&&o<n&&n--}else if(0===s[2]){Number.parseInt(i.substring(1),10)<=n&&n++}else 1===s.length&&Number.parseInt(i,10)<=n&&n--}return n},jb=t=>{if(!t||!t.children)return;const e=t.delta;if("a"!==e._t)return;const i=e,n=t.children.length,s={_t:"a"};for(let e=0;e<n;e++){const n=t.children[e];if(void 0===n)continue;let o=n.newName;if(void 0===o){if(void 0===n.childName)throw new Error("child.childName is undefined");o=Nb(i,n.childName,n.result)}s[o]!==n.result&&(s[o]=n.result)}t.setResult(s).exit()};jb.filterName="arraysCollectChildren";const zb=function(t){t.left instanceof Date?(t.right instanceof Date?t.left.getTime()!==t.right.getTime()?t.setResult([t.left,t.right]):t.setResult(void 0):t.setResult([t.left,t.right]),t.exit()):t.right instanceof Date&&t.setResult([t.left,t.right]).exit()};zb.filterName="dates";const Bb=t=>{if(!t||!t.children)return;const e=t.children.length;let i=t.result;for(let n=0;n<e;n++){const e=t.children[n];if(void 0!==e&&void 0!==e.result){if(i=i||{},void 0===e.childName)throw new Error("diff child.childName is undefined");i[e.childName]=e.result}}i&&t.leftIsArray&&(i._t="a"),t.setResult(i).exit()};Bb.filterName="collectChildren";const qb=t=>{var e;if(t.leftIsArray||"object"!==t.leftType)return;const i=t.left,n=t.right,s=null===(e=t.options)||void 0===e?void 0:e.propertyFilter;for(const e in i){if(!Object.prototype.hasOwnProperty.call(i,e))continue;if(s&&!s(e,t))continue;const o=new kb(i[e],n[e]);t.push(o,e)}for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)&&(!s||s(e,t))&&void 0===i[e]){const i=new kb(void 0,n[e]);t.push(i,e)}t.children&&0!==t.children.length?t.exit():t.setResult(void 0).exit()};qb.filterName="objects";const Zb=function(t){if(!t.nested)return;const e=t.delta;if(e._t)return;const i=e;for(const e in i){const n=new $b(t.left[e],i[e]);t.push(n,e)}t.exit()};Zb.filterName="objects";const Fb=function(t){if(!t||!t.children)return;if(t.delta._t)return;const e=t.left,i=t.children.length;for(let n=0;n<i;n++){const i=t.children[n];if(void 0===i)continue;const s=i.childName;Object.prototype.hasOwnProperty.call(t.left,s)&&void 0===i.result?delete e[s]:e[s]!==i.result&&(e[s]=i.result)}t.setResult(e).exit()};Fb.filterName="collectChildren";const Xb=function(t){if(!t.nested)return;if(t.delta._t)return;const e=t.delta;for(const i in e){const n=new Cb(e[i]);t.push(n,i)}t.exit()};Xb.filterName="objects";const Hb=t=>{if(!t||!t.children)return;if(t.delta._t)return;const e=t.children.length,i={};for(let n=0;n<e;n++){const e=t.children[n];if(void 0===e)continue;const s=e.childName;i[s]!==e.result&&(i[s]=e.result)}t.setResult(i).exit()};Hb.filterName="collectChildren";let Wb=null;function Vb(t,e){var i;if(!Wb){let n;if(!(null===(i=null==t?void 0:t.textDiff)||void 0===i?void 0:i.diffMatchPatch)){if(!e)return null;const t=new Error("The diff-match-patch library was not provided. Pass the library in through the options or use the `jsondiffpatch/with-text-diffs` entry-point.");throw t.diff_match_patch_not_found=!0,t}n=new t.textDiff.diffMatchPatch,Wb={diff:(t,e)=>n.patch_toText(n.patch_make(t,e)),patch:(t,e)=>{const i=n.patch_apply(n.patch_fromText(e),t);for(const t of i[1])if(!t){const t=new Error("text patch failed");throw t.textPatchFailed=!0,t}return i[0]}}}return Wb}const Yb=function(t){var e,i;if("string"!==t.leftType)return;const n=t.left,s=t.right,o=(null===(i=null===(e=t.options)||void 0===e?void 0:e.textDiff)||void 0===i?void 0:i.minLength)||60;if(n.length<o||s.length<o)return void t.setResult([n,s]).exit();const r=Vb(t.options);if(!r)return void t.setResult([n,s]).exit();const a=r.diff;t.setResult([a(n,s),0,2]).exit()};Yb.filterName="texts";const Ub=function(t){if(t.nested)return;const e=t.delta;if(2!==e[2])return;const i=e,n=Vb(t.options,!0).patch;t.setResult(n(t.left,i[0])).exit()};Ub.filterName="texts";const Gb=t=>{var e,i,n;const s=/^@@ +-(\d+),(\d+) +\+(\d+),(\d+) +@@$/,o=t.split("\n");for(let t=0;t<o.length;t++){const r=o[t];if(void 0===r)continue;const a=r.slice(0,1);if("@"===a){const e=s.exec(r);if(null!==e){o[t]=`@@ -${e[3]},${e[4]} +${e[1]},${e[2]} @@`}}else if("+"===a){if(o[t]=`-${null===(e=o[t])||void 0===e?void 0:e.slice(1)}`,"+"===(null===(i=o[t-1])||void 0===i?void 0:i.slice(0,1))){const e=o[t];o[t]=o[t-1],o[t-1]=e}}else"-"===a&&(o[t]=`+${null===(n=o[t])||void 0===n?void 0:n.slice(1)}`)}return o.join("\n")},Kb=function(t){if(t.nested)return;const e=t.delta;if(2!==e[2])return;const i=e;t.setResult([Gb(i[0]),0,2]).exit()};Kb.filterName="texts";const Jb=function(t){if(t.left!==t.right)if(void 0!==t.left)if(void 0!==t.right){if("function"==typeof t.left||"function"==typeof t.right)throw new Error("functions are not supported");t.leftType=null===t.left?"null":typeof t.left,t.rightType=null===t.right?"null":typeof t.right,t.leftType===t.rightType&&"boolean"!==t.leftType&&"number"!==t.leftType?("object"===t.leftType&&(t.leftIsArray=Array.isArray(t.left)),"object"===t.rightType&&(t.rightIsArray=Array.isArray(t.right)),t.leftIsArray===t.rightIsArray?t.left instanceof RegExp&&(t.right instanceof RegExp?t.setResult([t.left.toString(),t.right.toString()]).exit():t.setResult([t.left,t.right]).exit()):t.setResult([t.left,t.right]).exit()):t.setResult([t.left,t.right]).exit()}else t.setResult([t.left,0,0]).exit();else{if("function"==typeof t.right)throw new Error("functions are not supported");t.setResult([t.right]).exit()}else t.setResult(void 0).exit()};Jb.filterName="trivial";const tx=function(t){if(void 0===t.delta)return void t.setResult(t.left).exit();if(t.nested=!Array.isArray(t.delta),t.nested)return;const e=t.delta;if(1!==e.length)if(2!==e.length)3===e.length&&0===e[2]&&t.setResult(void 0).exit();else{if(t.left instanceof RegExp){const i=/^\/(.*)\/([gimyu]+)$/.exec(e[1]);if(null==i?void 0:i[1])return void t.setResult(new RegExp(i[1],i[2])).exit()}t.setResult(e[1]).exit()}else t.setResult(e[0]).exit()};tx.filterName="trivial";const ex=function(t){if(void 0===t.delta)return void t.setResult(t.delta).exit();if(t.nested=!Array.isArray(t.delta),t.nested)return;const e=t.delta;1!==e.length?2!==e.length?3===e.length&&0===e[2]&&t.setResult([e[0]]).exit():t.setResult([e[1],e[0]]).exit():t.setResult([e[0],0,0]).exit()};ex.filterName="trivial";const ix=class{constructor(t){this.processor=new Pb(t),this.processor.pipe(new Tb("diff").append(Bb,Jb,zb,Yb,qb,Qb).shouldHaveResult()),this.processor.pipe(new Tb("patch").append(Fb,Ib,tx,Ub,Zb,Rb).shouldHaveResult()),this.processor.pipe(new Tb("reverse").append(Hb,jb,ex,Kb,Xb,Lb).shouldHaveResult())}options(t){return this.processor.options(t)}diff(t,e){return this.processor.process(new kb(t,e))}patch(t,e){return this.processor.process(new $b(t,e))}reverse(t){return this.processor.process(new Cb(t))}unpatch(t,e){return this.patch(t,this.reverse(e))}clone(t){return _b(t)}};let nx;function sx(t,e){return nx||(nx=new ix),nx.diff(t,e)}const ox=new ix({objectHash:(t,e)=>t.id||`$$index:${e}`});function rx(t,e){return function(t,e){return wb||(wb=new yb),wb.format(t,e)}(ox.diff(t,e),t)}class ax extends u{constructor(t,e,i,n,s,o){super("Save Configurations",function(t){const{url:e,filename:i,diff:n}=t;return`\n<div class="textae-editor__save-dialog__container">\n <div class="textae-editor__save-dialog__row">\n <label>URL</label>\n <input\n type="text" value="${e}"\n class="textae-editor__save-dialog__url-text">\n <input\n type="button"\n class="textae-editor__save-dialog__url-button"\n ${e?"":'disabled="disabled"'}\n value="Save">\n </div>\n <div class="textae-editor__save-dialog__row">\n <label>Local</label>\n <input\n type="text" value="${i||""}"\n >\n <a class="textae-editor__save-dialog__download-link" href="#">Download</a>\n </div>\n <div class="textae-editor__save-dialog__row">\n <div class="textae-editor__save-dialog__diff-title">\n Configuration differences\n <span class="textae-editor__save-dialog__diff-add-legend">added</span>\n <span class="textae-editor__save-dialog__diff-remove-legend">removed</span>\n </div>\n <div class="textae-editor__save-dialog__diff-viewer">${n}</div>\n </div>\n</div>\n`}({filename:i,url:e,diff:rx(n,s)||"nothing."}),{maxWidth:550}),this._$dialog.on("dialogopen",()=>xb()),function(t,e,i,n,s){r()(e,".textae-editor__save-dialog__url-text","input",t=>{wn(t.target.nextElementSibling,t.target.value)}),r()(e,".textae-editor__save-dialog__url-text","keyup",t=>{13===t.keyCode&&(s(t.target.value),n())}),r()(e,".textae-editor__save-dialog__url-button","click",t=>{s(t.target.previousElementSibling.value),n()}),r()(e,".textae-editor__save-dialog__download-link","click",e=>{const s=e.target,o=GO(i);s.setAttribute("href",o),s.setAttribute("download",s.previousElementSibling.value),t.emit("textae-event.resource.configuration.save",i),n()})}(t,super.el,s,()=>super.close(),o)}}async function lx(t){return new Promise(e=>{const i=new FileReader;i.onload=t=>e(t),i.readAsText(t)})}var cx=i(7975),hx=i.n(cx);const ux=Object.freeze({QUERY_PARAMETER:"parameter",INLINE:"inline",REMOTE_URL:"remote",INSTANT:"instant",LOCAL_FILE:"local file",UNKNOWN:"unknown"});class dx{#Ui;#H;#Gi;static createURLSource(t,e){return console.assert("string"==typeof t,"id must be a string when type is url."),new dx(ux.REMOTE_URL,t,e)}static createFileSource(t,e){return console.assert("string"==typeof t,"id must be a string when type is local file."),new dx(ux.LOCAL_FILE,t,e)}static createInstantSource(t){return new dx(ux.INSTANT,null,t)}static createInlineSource(t){return new dx(ux.INLINE,null,t)}static createParameterSource(t){return new dx(ux.QUERY_PARAMETER,null,t)}constructor(t,e,i){console.assert(Object.values(ux).includes(t),`type must be a member of RESOURCE_TYPE. type: ${t}`),t===ux.REMOTE_URL||t===ux.LOCAL_FILE?console.assert("string"==typeof e,"id must be a string when type is url or local file."):console.assert(null===e,"id must be null when type is not url."),this.#Ui=t,this.#H=e,this.#Gi=i}get resourceType(){return this.#Ui}get id(){return this.#H}get data(){return this.#Gi}get displayName(){switch(this.#Ui){case ux.REMOTE_URL:return new URL(this.#H,location.href).href;case ux.LOCAL_FILE:return`${this.#H}(local file)`;default:return`${this.#Ui}`}}}async function fx(t,i){const n=(await lx(t)).target.result;if(s=t.name,".txt"===hx().extname(s)){const s=function(t){try{return ub.parse(t)}catch{return null}}(n);if(!s){const i=dx.createFileSource(t.name);return void e().error(`Failed to load annotation from ${i.displayName}.`)}if(s.text)return void i.emit("textae-event.resource.annotation.load.success",dx.createFileSource(t.name,s))}var s;if(_n(n)){const e=JSON.parse(n);if(e.text)return void i.emit("textae-event.resource.annotation.load.success",dx.createFileSource(t.name,e))}i.emit("textae-event.resource.annotation.format.error",dx.createFileSource(t.name))}function px(t,e){return!!e.text&&(t.emit("textae-event.resource.annotation.load.success",dx.createInstantSource(e)),!0)}class mx{#Ki;#Ji;constructor(t){t.on("textae-event.original-data.annotation.reset",t=>{t.resourceType===ux.REMOTE_URL&&(this.#Ki=t.id)}).on("textae-event.original-data.configuration.reset",t=>{t.resourceType===ux.REMOTE_URL&&(this.#Ji=t.id)})}get annotation(){return this.#Ki||""}get configuration(){return this.#Ji||""}}class gx{#Ki;#Ji;constructor(t){t.on("textae-event.original-data.annotation.reset",t=>{t.resourceType===ux.LOCAL_FILE&&(this.#Ki=t.id)}).on("textae-event.original-data.configuration.reset",t=>{t.resourceType===ux.LOCAL_FILE&&(this.#Ji=t.id)})}get annotation(){return this.#Ki}get configuration(){return this.#Ji}}class vx{#Nt;#tn;#Ht;#en;#in;#nn;#sn;#ii;#on;#rn;constructor(t,e,i,n,s,o,r,a){this.#Nt=t,this.#tn=e,this.#Ht=i,this.#en=n,this.#in=s,this.#nn=o,this.#sn=r,this.#ii=a,this.#on=new mx(t),this.#rn=new gx(t),t.on("textae-event.pallet.import-button.click",()=>this.importConfiguration()).on("textae-event.pallet.upload-button.click",()=>this.uploadConfiguration())}importAnnotation(){new YO("Load Annotations",this.#on.annotation,t=>this.#tn.loadAnnotation(t),t=>fx(t,this.#Nt),(t,i)=>function(t,i,n){if("json"===n)_n(i)?px(t,JSON.parse(i)):t.emit("textae-event.resource.annotation.format.error",dx.createInstantSource());else if("inline"===n)try{px(t,ub.parse(i))}catch{const t=dx.createInstantSource();e().error(`Failed to load annotation from ${t.displayName}.`)}}(this.#Nt,t,i),this.#sn.hasChange).open()}uploadAnnotation(){const t=this.#nn||this.#on.annotation||"https://pubannotatoin.org/annotations.json";new mb(this.#Nt,t,this.#rn.annotation,this.#an,(t,e)=>this.#tn.saveAnnotation(t,this.#an,e)).open()}saveAnnotation(){this.#tn.saveAnnotation(this.#nn||this.#on.annotation,this.#an,"json")}importConfiguration(){new UO("Load Configurations",this.#on.configuration,t=>this.#tn.loadConfiguration(t),t=>function(t,e){lx(t).then(({target:i})=>{_n(i.result)?e.emit("textae-event.resource.configuration.load.success",dx.createFileSource(t.name,JSON.parse(i.result))):e.emit("textae-event.resource.configuration.format.error",dx.createFileSource(t.name))})}(t,this.#Nt),t=>{_n(t)?this.#Nt.emit("textae-event.resource.configuration.load.success",dx.createInstantSource(JSON.parse(t))):this.#Nt.emit("textae-event.resource.configuration.format.error",dx.createInstantSource())},this.#ii.diffOfConfiguration).open()}uploadConfiguration(){const t={...this.#in(),...this.#Ht.typeDictionary.config};new ax(this.#Nt,this.#on.configuration,this.#rn.configuration,this.#in(),t,e=>this.#tn.saveConfiguration(e,t)).open()}get#an(){const t={...this.#en(),...this.#Ht.externalFormat,config:this.#Ht.typeDictionary.config};return delete t.tracks,t}}function yx(t,e,i,n,s,o){e.setPushButtons(t),i.set(t),n.reset(s,t),o.availability=t["function availability"]}function Ox(t){if(!0===t)return"flag";if("number"==typeof t)return"numeric";if("string"==typeof t)return"string";throw`${JSON.stringify(t)} is an unexpected value for an Attribute.`}function bx(t){const e=t.reduce((t,e)=>t.has(e)?t.set(e,t.get(e)+1):t.set(e,1),new Map),i=Math.max(...e.values());for(const[t,n]of e.entries())if(n===i)return t}function xx(t){const e=Math.max(...t.map(t=>{const[e,i]=String(t).split(".");return i?i.length:0}));return Number(Array.from(Array(e)).reduce((t,e)=>.1*t,1).toFixed(e))}class wx{constructor({pred:t,obj:e}){this._pred=t,this._objects=[e]}push(t){this._objects.push(t)}get definition(){switch(Ox(this._objects[0])){case"flag":return this._prototype;case"numeric":return this._numericAttribute;case"string":return this._stringAttribute;default:throw new Error(`prototype: ${JSON.stringify(this._prototype)}`)}}get mostFrequentObject(){return bx(this._objects)}get _prototype(){return{pred:this._pred,"value type":Ox(this._objects[0])}}get _numericAttribute(){return{min:Math.min(...this._objects),max:Math.max(...this._objects),step:xx(this._objects),default:bx(this._objects),...this._prototype}}get _stringAttribute(){return{default:bx(this._objects),...this._prototype}}}function _x(t){return t.reduce((t,e)=>(t.has(e.pred)?t.get(e.pred).push(e.obj):t.set(e.pred,new wx(e)),t),new Map)}function Sx(t,e){const i=function(t){return[..._x(t).values()].map(t=>t.definition)}(e);return function(t,e){for(const i of e){const e=t.findIndex(t=>t.pred===i.pred);-1!==e?t[e]={...i,...t[e]}:t.push(i)}return t}(t,i)}function kx(t){return t?JSON.parse(JSON.stringify(t)):{}}class $x{constructor(t=[],e=[]){this._annotations=e,this._config=t}get configuration(){let t=Sx(this._config,this._annotations);return t=function(t){t=kx(t);for(const e of t.filter(t=>"numeric"===t["value type"]))Object.prototype.hasOwnProperty.call(e,"default")||(e.default=0),Object.prototype.hasOwnProperty.call(e,"step")||(e.step=2);return t}(t),t=function(t,e){t=kx(t);const i=_x(e);for(const e of function(t){return t.filter(t=>"selection"===t["value type"])}(t))if(e.values&&0!==e.values.length)if(e.values.find(t=>!0===t.default));else if(i.has(e.pred)){const t=i.get(e.pred);e.values.find(e=>e.id===t.mostFrequentObject).default=!0}else e.values[0].default=!0;else e.values=[{id:"default",default:!0}];return t}(t,this._annotations),t}}function Cx(t,e){if(console.assert(t),(e=kx(e))["attribute types"]=new $x(e["attribute types"],t.attributes).configuration,t.tracks)for(const i of t.tracks)e["attribute types"]=new $x(e["attribute types"],i.attributes).configuration;return e}const Tx=new(on())({verbose:!0});an()(Tx,["uri-reference","regex"]);const Px=Tx.compile(ln);function Ex(t){return console.assert(t,"config is required."),Px(t)?null:(console.warn(Px.errors),function(t){for(const e of t){if("required"===e.keyword)return`Invalid configuration: The attribute type whose predicate is '${e.data.pred}' misses a mandatory property, '${e.params.missingProperty}'.`;if(e.instancePath.includes("color"))return ot`Invalid configuration: '${e.data}' is invalid color format.`}}(Px.errors))}function Ax(t,i){const n=function(t,e){if(console.assert(e,"If you don't have a configuration, generate a configuration from the annotation."),t.attributes){const i=e["attribute types"],n=t.attributes.filter(t=>i.some(e=>e.pred===t.pred&&"selection"===e["value type"])).filter(t=>!i.some(e=>e.pred===t.pred&&e.values.some(e=>e.id===t.obj)));if(n.length)return console.warn("selection attribute values without definition",n),`selection attribute value definition for "${n.map(t=>t.obj).join(", ")}" in configuration is missing. `}}(t,i);if(!n)return i;e().error(n)}function Mx(t,i){const n=Cx(t,i),s=Ex(n);if(!s)return Ax(t,n);e().error(s)}function Qx(t){(function(t){if(t.denotations)for(const e of t.denotations){if(e.span.begin!==parseInt(e.span.begin))return!0;if(e.span.end!==parseInt(e.span.end))return!0}})(t)&&e().warning("In the annotation file, some of the begin and end offsets of denotations were not integer values.\n TextAE converted them to integer values.\n However, to avoid a chance of unexpected rendering, please fix them.",15)}function Dx(t,i,n,s,o,r,a,l){if(!t.data.config&&i)n.loadConfiguration(i,t);else{if(Qx(t.data),t.data.config&&"object"!=typeof t.data.config)return void e().error("configuration in annotation file is invalid.");const i=Mx(t.data,t.data.config);i&&(yx(i,s,o,r,t.data,a),l.annotation=t)}}const Rx='\n<div class="textae-editor__footer">\n <div class="textae-editor__footer__message"></div>\n</div>\n';class Ix{#Q;#ln;constructor(t,e){this.#Q=t,this.#ln=e}set status(t){var e;this.#ln&&(""!==t&&((e=this.#Q,e.querySelector(".textae-editor__footer__message")||(e.insertAdjacentHTML("beforeend",Rx.replace(/[\n\r]+/g,"")),e.querySelector(".textae-editor__footer__message"))).innerHTML=at(t)?`Source: <a class="textae-editor__footer__message__link" href="${t}">${decodeURI(t)}</a>`:`Source: ${t}`))}}class Lx{#Nt;#cn;#Ki;#Ji;constructor(t,e,i){this.#Nt=t,this.#cn=new Ix(e,i),t.on("textae-event.resource.annotation.save",t=>{this.#hn=t}).on("textae-event.resource.configuration.save",t=>{this.#Ji=t})}get defaultAnnotation(){return{text:"Currently, the document is empty. Use the `import` button or press the key `i` to open a document with annotation."}}get defaultConfiguration(){return Cx(this.defaultAnnotation)}get annotation(){return this.#Ki?this.#Ki:this.defaultAnnotation}set annotation(t){this.#hn=t.data,this.#cn.status=t.displayName,this.#Nt.emit("textae-event.original-data.annotation.reset",t)}get configuration(){return this.#Ji?this.#Ji:{}}set configuration(t){this.#Ji=t.data,this.#Nt.emit("textae-event.original-data.configuration.reset",t)}set#hn(t){this.#Ki=t,t.config&&(this.#Ji=t.config)}}const Nx=[{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"import",title:"Import [I]"},{type:"upload",title:"Upload [U]"},{type:"upload automatically",title:"Upload Automatically",push:!0}]},{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"view mode",title:"View Mode",push:!0},{type:"term edit mode",title:"Term Edit Mode",push:!0},{type:"block edit mode",title:"Block Edit Mode",push:!0},{type:"relation edit mode",title:"Relation Edit Mode",push:!0},{type:"text edit mode",title:"Text Edit Mode",push:!0}]},{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"simple view",title:"Simple View",push:!0},{type:"adjust lineheight",title:"Adjust LineHeight"},{type:"auto adjust lineheight",title:"Auto Adjust LineHeight",push:!0}]},{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"undo",title:"Undo [Z]"},{type:"redo",title:"Redo [A]"}]},{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"replicate span annotation",title:"Replicate span annotation [R]",enableWhenSelecting:t=>t.span.single&&t.span.single.isDenotation},{type:"auto replicate",title:"Auto replicate",push:!0},{type:"boundary detection",title:"Boundary Detection [B]",push:!0}]},{usage:{"keyboard device":[],"touch device":["control bar","context menu"]},list:[{type:"create span by touch",title:"Create span",availableModes:[vn,yn]},{type:"expand span by touch",title:"Expand span",availableModes:[vn,yn]},{type:"shrink span by touch",title:"Shrink span",availableModes:[vn,yn]},{type:"edit text by touch",title:"Edit text",availableModes:[bn]}]},{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"new entity",title:"New entity [E]",enableWhenSelecting:t=>t.span.contains(t=>t.isDenotation)},{type:"pallet"},{type:"edit properties",title:"Edit Properties [W]",enableWhenSelecting:t=>t.entity.some||t.relation.some},{type:"delete",title:"Delete [D]",enableWhenSelecting:t=>t.span.some||t.entity.some||t.relation.some}]},{usage:{"keyboard device":[],"touch device":["control bar"]},list:[{type:"copy",title:"Copy [C]",enableWhenSelecting:t=>t.span.contains(t=>t.isDenotation)||t.entity.contains(t=>t.isDenotation)},{type:"cut",title:"Cut [X]",enableWhenSelecting:t=>t.span.contains(t=>t.isDenotation)||t.entity.contains(t=>t.isDenotation)},{type:"paste",title:"Paste [V]",enableWhenSelecting:(t,e)=>e.hasCopyingItem&&t.span.some||e.hasCuttingItem&&Boolean(t.span.single)}]},{usage:{"keyboard device":["control bar"],"touch device":["control bar"]},list:[{type:"setting",title:"Setting"}]},{usage:{"keyboard device":["control bar"],"touch device":[]},list:[{type:"help",title:"Help [H]"}]}];function jx(){return/Android/.test(navigator.userAgent)}class zx{#un;#dn;constructor(t,e){this.#un=t,this.#dn=e}isShowOnControlBar(){return jx()||/iPad/.test(navigator.userAgent)||/iPhone/.test(navigator.userAgent)||/Macintosh/.test(navigator.userAgent)&&q()?this.#un["touch device"].includes("control bar"):this.#un["keyboard device"].includes("control bar")}isShowOnContextMenu(){return q()?this.#un["touch device"].includes("context menu"):this.#un["keyboard device"].includes("context menu")}getButtonsFor(t){const e=this.#dn.filter(({availableModes:e})=>e.includes(t));return new zx(this.#un,e)}get buttonList(){return this.#dn}get displayProperties(){return{list:this.#dn.map(t=>t.displayProperties)}}}class Bx{#Ui;#ot;#fn=!1;#pn=null;#mn=[gn,vn,yn,On,bn];constructor(t,e,i=!1,n=null,s=null){this.#Ui=t,this.#ot=e,this.#fn=i,n&&(this.#pn=n),s&&(this.#mn=s)}get displayProperties(){return{type:this.#Ui,title:this.#ot}}get type(){return this.#Ui}get push(){return this.#fn}get enableWhenSelecting(){return this.#pn}get availableModes(){return this.#mn}}class qx{#gn;constructor(){this.#gn=Nx.map(({usage:t,list:e})=>new zx(t,e.map(({type:t,title:e,push:i,enableWhenSelecting:n,availableModes:s})=>new Bx(t,e,i,n,s))))}get controlBar(){return this.#gn.filter(t=>t.isShowOnControlBar()).map(t=>t.displayProperties)}getContextMenuFor(t){return this.#gn.filter(t=>t.isShowOnContextMenu()).map(e=>e.getButtonsFor(t)).map(t=>t.displayProperties)}get pasteButton(){return this.#dn.find(({type:t})=>"paste"===t)}get enableButtonsWhenSelecting(){return this.#dn.filter(t=>t.enableWhenSelecting)}get pushButtons(){return this.#dn.filter(t=>t.push).map(t=>t.type)}get#dn(){return this.#gn.flatMap(t=>t.buttonList)}}class Zx{#l;#Nt;#vn;constructor(t,e=null){this.#l=t,this.#Nt=e,this.#vn=!1}get name(){return this.#l}get isPushed(){return this.#vn}set isPushed(t){this.#vn=t,this.#yn()}toggle(){this.#vn=!this.#vn,this.#yn()}#yn(){this.#Nt&&this.#Nt.emit("textae-event.control.button.push",this)}}class Fx{#On;constructor(t){this.#On=(new qx).pushButtons.reduce((e,i)=>(e.set(i,new Zx(i,t)),e),new Map),t.on("textae-event.edit-mode.transition",(t,e)=>this.#bn(t,!e))}get(t){return this.#On.has(t)?this.#On.get(t):new Zx(t)}get names(){return this.#On.keys()}#bn(t,e){switch(t){case gn:this.#xn(!0,!1,!1,!1,!1,e);break;case vn:this.#xn(!1,!0,!1,!1,!1,e);break;case yn:this.#xn(!1,!1,!0,!1,!1,e);break;case On:this.#xn(!1,!1,!1,!0,!1,!1);break;case bn:this.#xn(!1,!1,!1,!1,!0,e);break;default:throw`unknown edit mode!${t}`}}#xn(t,e,i,n,s,o){this.#On.get("view mode").isPushed=t,this.#On.get("term edit mode").isPushed=e,this.#On.get("block edit mode").isPushed=i,this.#On.get("relation edit mode").isPushed=n,this.#On.get("text edit mode").isPushed=s,this.#On.get("simple view").isPushed=o}}class Xx{#wn;#Nt;#Ie;#oi;constructor(t,e,i){this.#wn=new Map([["import",!0],["upload",!0],["view mode",!0],["term edit mode",!0],["block edit mode",!0],["relation edit mode",!0],["text edit mode",!0],["simple view",!0],["setting",!0],["help",!0]]),this.#Nt=t,this.#Ie=e,this.#oi=i,t.on("textae-event.history.change",t=>{this.enable("undo",t.hasAnythingToUndo),this.enable("redo",t.hasAnythingToRedo)}).on("textae-event.selection.span.change",()=>this.#_n()).on("textae-event.selection.relation.change",()=>this.#_n()).on("textae-event.selection.entity.change",()=>this.#_n()).on("textae-event.edit-mode.transition",t=>this.#Sn(t)).on("textae-event.clip-board.change",()=>this.#kn()).on("textae-event.annotation-auto-saver.enable",t=>this.enable("upload automatically",t))}get(t){return this.#wn.get(t)}enable(t,e){this.#wn.set(t,e),this.#yn()}updateButtonsToOperateSpanWithTouchDevice(t,e,i,n){this.#wn.set("create span by touch",t),this.#wn.set("expand span by touch",e),this.#wn.set("shrink span by touch",i),this.#wn.set("edit text by touch",n),this.#yn()}#_n(){for(const{type:t,enableWhenSelecting:e}of(new qx).enableButtonsWhenSelecting)this.enable(t,e(this.#Ie,this.#oi));this.#yn()}#kn(){this.enable("paste",(new qx).pasteButton.enableWhenSelecting(this.#Ie,this.#oi))}#yn(){this.#Nt.emit("textae-event.control.buttons.change",this.#wn.keys())}#Sn(t){switch(t){case gn:this.#$n(!0,!1,!1,!1,!1,!1,!1);break;case vn:this.#$n(!0,!0,!0,!0,!0,!0,!0);break;case yn:this.#$n(!0,!1,!0,!0,!0,!0,!0);break;case On:this.#$n(!1,!1,!1,!0,!0,!1,!0);break;case bn:this.#$n(!0,!1,!0,!0,!0,!1,!1);break;default:throw`unknown edit mode!${t}`}this.#yn()}#$n(t,e,i,n,s,o,r){this.#wn.set("simple view",t),this.#wn.set("auto replicate",e),this.#wn.set("boundary detection",i),this.#wn.set("adjust lineheight",n),this.#wn.set("auto adjust lineheight",s),this.#wn.set("create span by touch",o),this.#wn.set("expand span by touch",o),this.#wn.set("shrink span by touch",o),this.#wn.set("pallet",r)}}function Hx(t,e,i,n,s){for(;s(t(i,n));)n+=e;return n}const Wx=function(t,e){return t.charAt(e)},Vx=function(t,e,i){return Hx(Wx,1,t,e,i)},Yx=function(t,e,i){return Hx(Wx,-1,t,e,i)};class Ux{backFromBegin(t,e,i){}forwardFromEnd(t,e,i){}forwardFromBegin(t,e,i){}backFromEnd(t,e,i){}}function Gx(t,e){return[t.charAt(e),t.charAt(e-1)]}function Kx(t,e){return[t.charAt(e),t.charAt(e+1)]}function Jx(t,e,i){return""!==i[0]&&!t(i[1])&&!e(i[1])||e(i[0])}class tw extends Ux{backFromBegin(t,e,i){const n=function(t,e,i){return Hx(Gx,-1,t,e,t=>t[1]&&!i(t[0])&&!i(t[1]))}(t,Vx(t,e,t=>i.isBlankCharacter(t)),t=>i.isDelimiter(t));return n}forwardFromEnd(t,e,i){const n=function(t,e,i){return Hx(Kx,1,t,e,t=>t[1]&&!i(t[0])&&!i(t[1]))}(t,Yx(t,e,t=>i.isBlankCharacter(t)),t=>i.isDelimiter(t));return n}forwardFromBegin(t,e,i){return function(t,e,i){return Hx(Gx,1,t,e,i)}(t,e,t=>Jx(t=>i.isBlankCharacter(t),t=>i.isDelimiter(t),t))}backFromEnd(t,e,i){return function(t,e,i){return Hx(Kx,-1,t,e,i)}(t,e,t=>Jx(t=>i.isBlankCharacter(t),t=>i.isDelimiter(t),t))}}class ew extends Ux{backFromBegin(t,e,i){return Vx(t,e,t=>i.isBlankCharacter(t))}forwardFromEnd(t,e,i){return Yx(t,e,t=>i.isBlankCharacter(t))}forwardFromBegin(t,e,i){return Vx(t,e,t=>i.isBlankCharacter(t))}backFromEnd(t,e,i){return Yx(t,e,t=>i.isBlankCharacter(t))}}function iw(t){switch(t){case vn:return"Term Configuration";case yn:return"Block Configuration";case On:return"Relation Configuration";default:return""}}class nw{#Cn;#Tn;#sn;#Pn;#Vt;#si;#En;constructor(t,e,i,n,s,o,r,a){this.#Cn=new Xx(t,e,i),this.#Tn=new Fx(t),this.#sn=n,this.#Pn=s,this.#Vt=o,this.#si=r,this.#En=a}get pushButtonNames(){return this.#Tn.names}isPushed(t){return this.#Tn.get(t).isPushed}push(t){this.#Tn.get(t).isPushed=!0}release(t){this.#Tn.get(t).isPushed=!1}toggleButton(t){return this.#Tn.get(t).toggle()}get textSelectionAdjuster(){return this.isPushed("boundary detection")?new tw:new ew}get controlBarButton(){return(new qx).controlBar.map(({list:t})=>t.filter(({type:t})=>this.#si.isAvailable(t)).map(({type:t,title:e})=>this.#An(t,e)).map(({type:t,title:e})=>({type:t,title:e,pushed:this.getState(t,"pushed"),disabled:this.getState(t,"disabled")}))).filter(t=>t.length)}get contextMenuButton(){return(new qx).getContextMenuFor(this.#En.currentState).map(({list:t})=>t.filter(({type:t})=>this.#si.isAvailable(t)).map(({type:t,title:e})=>this.#An(t,e)).reduce((t,{type:e,title:i})=>(!q()&&this.getState(e,"disabled")||t.push(this.#Mn(e,i)),t),[])).filter(t=>t.length)}getState(t,e){switch(e){case"pushed":return this.#Tn.get(t).isPushed;case"disabled":return!this.#Cn.get(t);case"transit":switch(t){case"upload":return this.#sn.hasChange;case"pallet":return this.diffOfConfiguration;default:new Error("Unknown name")}break;default:new Error("Unknown state")}}updateButtonsToOperateSpanWithTouchDevice(t,e,i,n){this.#Cn.updateButtonsToOperateSpanWithTouchDevice(t,e,i,n)}get diffOfConfiguration(){return sx(this.#Pn.configuration,{...this.#Pn.configuration,...this.#Vt.config})}setPushButtons(t){!0===t.autosave?this.push("upload automatically"):this.release("upload automatically"),!1===t.autolineheight?this.release("auto adjust lineheight"):this.push("auto adjust lineheight"),!1===t.boundarydetection?this.release("boundary detection"):this.push("boundary detection")}get detailModifierClassName(){return this.#si.isAvailable("show logo")?"textae-control-details--show-logo":"textae-control-details--hide-logo"}#An(t,e){return"pallet"==t?{type:t,title:iw(this.#En.currentState)}:{type:t,title:e}}#Mn(t,e){return{type:t,title:e,pushed:this.getState(t,"pushed"),disabled:this.getState(t,"disabled"),transit:this.getState(t,"transit")}}}class sw{#Nt;#ei;#Ie;#Qn;#Dn;#Vt;#Rn;#In;constructor(t,e,i,n,s,o){this.#Nt=t,this.#ei=e,this.#Ie=i,this.#Qn=n,this.#Dn=s,this.#Vt=o,this.#Rn=[],this.#In=D(),t.on("textae-event.annotation-data.entity.remove",t=>{this.hasCuttingItem&&this.#Ln(this.#Rn.filter(e=>e!=t))}).on("textae-event.edit-mode.transition",()=>this.#Ln())}get hasCopyingItem(){return this.#Rn[0]instanceof Ot}get hasCuttingItem(){return this.#Rn[0]instanceof Wt}copyEntitiesToLocalClipboard(){this.#Ln(this.#Ie.copyingTargets)}copyEntitiesToSystemClipboard(t){if(this.#Ie.span.contains(t=>t.isBlock))return;const{copyingTargets:e}=this.#Ie;if(e.length>0){const i=this.#Qn.config.filter(({id:t})=>e.some(({typeName:e})=>e===t)),n=this.#Dn.config.filter(({pred:t})=>e.some(({attributes:e})=>e.some(e=>e.pred===t))),s=JSON.stringify({typeValues:e.map(({externalFormat:t})=>t),config:{"entity types":i,"attribute types":n}});t.clipboardData.setData("text/plain",s),t.clipboardData.setData("application/x-textae-type-values",s),t.preventDefault()}}cutEntitiesToLocalClipboard(){const{cuttingTargets:t}=this.#Ie;this.#Nn.length&&this.#Nn.every(e=>t.has(e))&&[...t].every(t=>this.#Nn.includes(t))?this.#Ln():this.#Ln([...t])}cutEntitiesToSystemClipboard(t){this.#Ie.span.contains(t=>t.isBlock)||(this.cutEntitiesToLocalClipboard(),t.clipboardData.setData("application/x-textae-editor-uuid",this.#In),this.copyEntitiesToSystemClipboard(t))}pasteEntitiesFromLocalClipboard(){if(this.#jn.length&&this.#Ie.span.single)this.#zn();else if(this.hasCopyingItem){const t=this.#ei.factory.pasteTypesToSelectedSpansCommand(this.#Rn);this.#ei.invoke(t)}}pasteEntitiesFromSystemClipboard(t){if(this.#Ie.span.contains(t=>t.isBlock))return;if(t.clipboardData.getData("application/x-textae-editor-uuid")===this.#In&&this.#jn.length&&this.#Ie.span.single)return void this.#zn();const e=t.clipboardData.getData("application/x-textae-type-values");if(e){const t=JSON.parse(e),i=new Le;if(i.definedTypes=t.config["attribute types"],this.#Vt.isLock){const e=t.typeValues.map(({obj:t,attributes:e})=>new Ot(t,e.filter(({pred:t})=>this.#Dn.get(t)&&this.#Dn.get(t).valueType===i.get(t).valueType))),n=this.#ei.factory.pasteTypesToSelectedSpansCommand(e);this.#ei.invoke(n)}else{const e=t.typeValues.map(({obj:t,attributes:e})=>new Ot(t,e.filter(({pred:t})=>!this.#Dn.get(t)||this.#Dn.get(t).valueType===i.get(t).valueType))),n=t.config["entity types"].filter(({id:t})=>!this.#Qn.config.some(e=>e.id===t)),s=t.config["attribute types"].filter(({pred:t})=>!this.#Dn.get(t)),o=this.#ei.factory.pasteTypesToSelectedSpansCommand(e,n,s,this.#Bn(e,i));this.#ei.invoke(o)}return void(this.hasCuttingItem&&this.#Ln())}}#Bn(t,e){const i=[],n=t.reduce((t,i)=>t.concat(i.attributes.filter(({pred:t})=>"selection"===e.get(t).valueType)),[]);for(const{pred:t,obj:s}of n)if(this.#Dn.get(t)&&!this.#Dn.get(t).values.some(({id:t})=>t===s)){const n=e.get(t).values.find(({id:t})=>t===s);i.push({pred:t,value:n})}return i}#zn(){const t=this.#ei.factory.moveEntitiesToSelectedSpanCommand(this.#jn);this.#ei.invoke(t),this.#Ln()}#Ln(t=[]){const e=this.#Nn.filter(e=>!t.includes(e));this.#Rn=t,this.#Nt.emit("textae-event.clip-board.change",this.#Nn,e)}get#jn(){return this.#Nn.filter(t=>t.span.id!==(this.#Ie.span.single&&this.#Ie.span.single.id))}get#Nn(){return this.hasCuttingItem?this.#Rn:[]}}class ow{#ii;constructor(t,e,i,n,o){this.#ii=e;const r=s()(()=>i.saveAnnotation(),5e3);t.on("textae-event.resource.annotation.load.success",()=>this.#qn()).on("textae-event.resource.save.error",()=>this.#qn()).on("textae-event.resource.annotation.url.set",e=>t.emit("textae-event.annotation-auto-saver.enable",Boolean(n||e.id))).on("textae-event.control.button.push",({name:t,isPushed:e})=>{"upload automatically"===t&&!0===e&&o.hasChange&&i.saveAnnotation()}).on("textae-event.annotation-data.events-observer.unsaved-change",t=>{t&&e.isPushed("upload automatically")&&r()})}#qn(){this.#ii.isPushed("upload automatically")&&this.#ii.toggleButton("upload automatically")}}const rw=new d;class aw{#r;constructor(t,e){const i=l().create(t);this.#r=i,function(t,e){r()(t,".textae-control-icon","touchstart",({target:t})=>{if(t.classList.contains("textae-control-icon--disabled"))return;const{buttonType:i}=t.dataset;switch(i){case"create span by touch":case"expand span by touch":case"shrink span by touch":case"edit text by touch":e.handle(i)}},{passive:!0}),r()(t,".textae-control-icon","click",({target:t})=>{if(t.classList.contains("textae-control-icon--disabled"))return;const{buttonType:i}=t.dataset;switch(i){case"help":rw.open();break;case"create span by touch":case"expand span by touch":case"shrink span by touch":case"edit text by touch":break;default:e.handle(i)}});const i=t.querySelector(".textae-control-hamburger-menu-button");i&&i.addEventListener("click",t=>t.target.closest(".textae-control").querySelector(".textae-control-details").classList.toggle("textae-control-details--force-show"))}(this.#r,e)}get el(){return this.#r}_querySelector(t){return this.#r.querySelector(t)}}function lw({type:t,title:e,classList:i}){return`\n<span \nclass="${i.join(" ")}" \ntitle="${e}" \ndata-button-type="${t}">\n</span>\n`}var cw=i(6438),hw=i.n(cw);function uw(t){return t.map(t=>{const e=[];for(const{type:i,title:n,pushed:s,disabled:o,transit:r}of t){const t=["textae-control-icon",`textae-control-${i.replaceAll(" ","-")}-button`];s&&t.push("textae-control-icon--pushed"),o&&t.push("textae-control-icon--disabled"),r&&t.push("textae-control-icon--transit"),e.push({type:i,title:n,classList:t})}return e})}function dw(t){return`\n<div class="textae-control ${q()?"textae-touch-bar":"textae-control-bar"}">\n <div class="textae-control-summary">\n <span class="textae-control-title">\n <a href="http://textae.pubannotation.org/" target="_blank">TextAE</a>\n </span>\n <button type="button" class="textae-control-hamburger-menu-button" >\n <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" class="bi" fill="currentColor" viewBox="0 0 16 16">\n <path fill-rule="evenodd" d="M2.5 11.5A.5.5 0 0 1 3 11h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4A.5.5 0 0 1 3 3h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z"></path>\n </svg>\n </button>\n </div>\n <div class="textae-control-details ${t.detailModifierClassName}">\n <span class="textae-control-title">\n <a href="http://textae.pubannotation.org/" target="_blank">TextAE</a>\n </span>\n ${uw(t.controlBarButton).map(t=>`\n <span class="textae-control-separator"></span>\n ${t.map(lw).join("\n")}\n `).join("\n")}\n </div>\n</div>\n`}class fw extends aw{#ii;constructor(t,e,i){super(dw(e),i),this.#ii=e,q()&&Math.max(document.documentElement.clientWidth,window.innerWidth)<768&&new(hw())(".textae-touch-bar",{stickyContainer:".textae-editor"}),t.on("textae-event.control.button.push",({name:t})=>{this.#Zn(t,"pushed")}).on("textae-event.control.buttons.change",t=>{for(const e of t)this.#Zn(e,"disabled")}).on("textae-event.annotation-data.events-observer.unsaved-change",()=>{this.#Zn("upload","transit")}).on("textae-event.edit-mode.transition",t=>{const e=iw(t);super._querySelector(".textae-control-pallet-button").title=e}).on("textae-event.configuration.reset",()=>this.#Fn()).on("textae-event.type-definition.entity.change",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.entity.delete",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.entity.change-default",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.relation.change",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.relation.delete",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.relation.change-default",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.attribute.create",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.attribute.change",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.attribute.delete",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.attribute.move",()=>this.#Zn("pallet","transit"))}#Zn(t,e){const i=super._querySelector(`.textae-control-${t.replaceAll(" ","-")}-button`);i&&(this.#ii.getState(t,e)?i.classList.add(`textae-control-icon--${e}`):i.classList.remove(`textae-control-icon--${e}`))}#Fn(){super.el.innerHTML="",super.el.insertAdjacentHTML("beforeend",dw(this.#ii))}}function pw({type:t,title:e,classList:i}){return`<p \n class="${i.join(" ")}" \n data-button-type="${t}">${e}\n </p>`}class mw extends aw{#Q;#ii;constructor(t,e,i){super(`<div class="textae-control ${q()?"textae-android-context-menu":"textae-context-menu"}"></div>`,i),this.#Q=t,this.#ii=e}show(t){const e=window.getSelection(),i=this.#Q.getBoundingClientRect();if(q()&&1===e.rangeCount){const t=e.getRangeAt(0).getBoundingClientRect(),n=this.#Q.querySelector(".textae-editor__text-box").getBoundingClientRect();this.#Xn(t.y-i.y,t.x-n.x)}else this.#Hn(t.pageY-i.y,t.pageX-i.x)}hide(){this.#Wn&&(super.el.classList.remove("textae-context-menu--show"),super.el.classList.add("textae-context-menu--hide"))}get#Wn(){return super.el.classList.contains("textae-context-menu--show")}#Xn(t,e){this.#Vn();const{height:i}=this.el.getBoundingClientRect();super.el.setAttribute("style",`top: ${t-i}px; left: ${e}px`)}#Hn(t,e){this.#Vn(),super.el.setAttribute("style",`top: ${t}px; left: ${e}px`)}#Vn(){const t=uw(this.#ii.contextMenuButton);if(0===t.length)return;const e=`\n <div">\n ${t.map(t=>t.map(pw).join("")).join('<p class="textae-control-separator"></p>\n')}\n </div>\n `;super.el.replaceChildren(...l().create(e).children),super.el.classList.remove("textae-context-menu--hide"),super.el.classList.add("textae-context-menu--show")}}class gw{constructor(t,e,i,n,s,o){this._map=new Map([["1",t=>s.manipulateAttribute(1,t)],["2",t=>s.manipulateAttribute(2,t)],["3",t=>s.manipulateAttribute(3,t)],["4",t=>s.manipulateAttribute(4,t)],["5",t=>s.manipulateAttribute(5,t)],["6",t=>s.manipulateAttribute(6,t)],["7",t=>s.manipulateAttribute(7,t)],["8",t=>s.manipulateAttribute(8,t)],["9",t=>s.manipulateAttribute(9,t)],["a",()=>n.isAvailable("redo")&&t.redo()],["b",()=>n.isAvailable("boundary detection")&&e.toggleButton("boundary detection")],["d",()=>n.isAvailable("delete")&&e.removeSelectedElements()],["e",()=>n.isAvailable("new entity")&&e.createEntity()],["f",()=>o.changeModeByShortcut()],["i",()=>n.isAvailable("import")&&i.importAnnotation()],["m",()=>o.changeModeByShortcut()],["q",()=>n.isAvailable("pallet")&&s.showPallet()],["r",()=>n.isAvailable("replicate span annotation")&&e.replicate()],["u",()=>n.isAvailable("upload")&&i.uploadAnnotation()],["w",()=>n.isAvailable("edit properties")&&s.editProperties()],["y",()=>n.isAvailable("redo")&&t.redo()],["z",()=>n.isAvailable("undo")&&t.undo()],["ArrowDown",()=>e.selectDown()],["ArrowLeft",t=>e.selectLeft(t)],["ArrowRight",t=>e.selectRight(t)],["ArrowUp",()=>e.selectUp()],["Backspace",()=>e.removeSelectedElements()],["Delete",()=>e.removeSelectedElements()],["Escape",()=>e.cancelSelect()]])}handle(t){const e=t.shiftKey&&48<=t.keyCode&&t.keyCode<=57?String.fromCharCode(t.keyCode):t.key;this._map.has(e)&&this._map.get(e)(t.shiftKey)}}class vw{constructor(t,e,i,n,s,o,r){this._map=new Map([["view mode",()=>r.toViewMode()],["term edit mode",()=>r.toTermEditMode()],["block edit mode",()=>r.toBlockEditMode()],["relation edit mode",()=>r.toRelationEditMode()],["text edit mode",()=>r.toTextEditMode()],["simple view",()=>r.toggleSimpleMode()],["import",()=>i.importAnnotation()],["upload",()=>i.uploadAnnotation()],["undo",()=>t.undo()],["redo",()=>t.redo()],["replicate span annotation",()=>e.replicate()],["create span by touch",()=>o.createSpanWithTouchDevice()],["expand span by touch",()=>o.expandSpanWithTouchDevice()],["shrink span by touch",()=>o.shrinkSpanWithTouchDevice()],["edit text by touch",()=>o.editTextWithTouchDevice()],["new entity",()=>e.createEntity()],["edit properties",()=>o.editProperties()],["pallet",()=>o.showPallet()],["delete",()=>e.removeSelectedElements()],["copy",()=>e.copyEntitiesToLocalClipboard()],["cut",()=>e.cutEntitiesToLocalClipboard()],["paste",()=>e.pasteEntitiesFromLocalClipboard()],["setting",()=>e.showSettingDialog()],["adjust lineheight",()=>s.textBox.updateLineHeight()]]);for(const t of n.pushButtonNames)this._map.has(t)||this._map.set(t,()=>e.toggleButton(t))}handle(t){this._map.has(t)&&this._map.get(t)()}}function yw(t,e){return t.id<e.id?-1:t.id>e.id?1:0}function Ow({text:t,denotations:e=[],attributes:i=[],relations:n=[],blocks:s=[],selectedText:o}){return{text:t,denotations:e.sort(yw),attributes:i.sort(yw),relations:n.sort(yw),blocks:s.sort(yw),selectedText:o}}function bw(t,e){return sx(Ow(t),Ow(e))}class xw{#Nt;#Pn;#Ht;#Yn=new(ve())(!1);constructor(t,e,i){this.#Nt=t,this.#Pn=e,this.#Ht=i,t.on("textae-event.resource.annotation.save",()=>{this.#Yn.set(!1),this.#Un()}).on("textae-event.annotation-data.all.change",()=>{this.#Yn.set(!1),this.#Un()}).on("textae-event.annotation-data.span.add",()=>this.#Gn()).on("textae-event.annotation-data.span.change",()=>this.#Gn()).on("textae-event.annotation-data.span.remove",()=>this.#Gn()).on("textae-event.annotation-data.entity.add",()=>this.#Gn()).on("textae-event.annotation-data.entity.change",()=>this.#Gn()).on("textae-event.annotation-data.entity.remove",()=>this.#Gn()).on("textae-event.annotation-data.entity.move",()=>this.#Gn()).on("textae-event.annotation-data.relation.add",()=>this.#Gn()).on("textae-event.annotation-data.relation.change",()=>this.#Gn()).on("textae-event.annotation-data.relation.remove",()=>this.#Gn()).on("textae-event.annotation-data.attribute.add",()=>this.#Gn()).on("textae-event.annotation-data.attribute.remove",()=>this.#Gn()).on("textae-event.annotation-data.text.change",()=>this.#Gn()),this.#Yn(()=>t.emit("textae-event.annotation-data.events-observer.unsaved-change",this.#Yn()))}get hasChange(){return this.#Yn()}#Gn(){this.#Yn.set(bw(this.#Pn.annotation,this.#Ht.externalFormat)),this.#Un()}#Un(){this.#Nt.emit("textae-event.annotation-data.events-observer.change",this.#Ht)}}async function ww(t,e){if(function(t,e){const i=hx().extname(e),n=t.headers.get("Content-Type");return".json"===i||n&&n.includes("application/json")}(t,e))return await t.json();if(function(t,e){const i=hx().extname(e),n=t.headers.get("Content-Type");return".txt"===i||n&&n.includes("text/plain")}(t,e)){const e=await t.text();return ub.parse(e)}throw new Error("The content type of the loaded content is not supported.")}class _w extends Error{constructor(t){super(t),this.name="FormatConversionError"}}class Sw{#Nt;constructor(t){this.#Nt=t}async loadFrom(t){console.assert(t,"url is necessary!"),this.#Nt.emit("textae-event.resource.startLoad");try{const e=await fetch(t,{method:"GET",cache:"no-cache",credentials:"omit",headers:{Accept:"application/json, text/plain"},signal:AbortSignal.timeout(3e4)});if(e.ok){const i=await ww(e,t);this.#Kn(t,i)}else 401===e.status?await this.#Jn(t):this.#ts(t)}catch(e){e instanceof _w||console.error(e),this.#ts(t)}finally{this.#Nt.emit("textae-event.resource.endLoad")}}#Kn(t,e){const i=dx.createURLSource(t,e);e&&e.text?(this.#Nt.emit("textae-event.resource.annotation.load.success",i),this.#Nt.emit("textae-event.resource.annotation.url.set",i)):this.#Nt.emit("textae-event.resource.annotation.format.error",i)}async#Jn(t){try{const e=await fetch(t,{method:"GET",cache:"no-cache",credentials:"include",headers:{Accept:"application/json, text/plain"},signal:AbortSignal.timeout(3e4)});if(e.ok){const i=await ww(e,t);this.#Kn(t,i)}else 401===e.status?await this.#Jn(t):this.#ts(t)}catch{this.#ts(t)}}#ts(t){e().error(`Could not load the file from the location you specified.: ${t}`),this.#Nt.emit("textae-event.resource.annotation.load.error",t)}}class kw{#Nt;constructor(t){this.#Nt=t}loadFrom(t,e){console.assert(t,"url is necessary!"),this.#Nt.emit("textae-event.resource.startLoad"),fetch(t,{method:"GET",cache:"no-cache",credentials:"omit",headers:{Accept:"application/json","Content-Type":"application/json"},signal:AbortSignal.timeout(3e4)}).then(i=>{if(i.ok)return i.json().then(i=>this.#Kn(t,i,e));this.#ts(t)}).catch(()=>this.#ts(t)).finally(()=>this.#Nt.emit("textae-event.resource.endLoad"))}#Kn(t,e,i){this.#Nt.emit("textae-event.resource.configuration.load.success",dx.createURLSource(t,e),i)}#ts(t){e().error(`Could not load the file from the location you specified.: ${t}`),this.#Nt.emit("textae-event.resource.configuration.load.error",t)}}function $w(t,e,i){return 401===t&&e&&"ServerPage"===e&&i?i:null}function Cw(t){return window.open(t,"_blank","width=600, height=500")}function Tw(t,e){return"json"===e?JSON.stringify(t):"inline"===e?ub.generate(t):void 0}class Pw{#es;#Nt;constructor(t,e){this.#es=t,this.#Nt=e}async saveTo(t,e){if(t){this.#Nt.emit("textae-event.resource.startSave");try{const i=Tw(e,this.#es),n=await this.#is(t,i);await this.#ns(n,t,e)}catch(t){t instanceof _w||console.error(t),this.#ts()}finally{this.#Nt.emit("textae-event.resource.endSave")}}}async#is(t,e){const i="json"===this.#es?"application/json":"text/plain";return fetch(t,{method:"POST",headers:{"Content-Type":i,"App-Name":"TextAE"},body:e,credentials:"include"})}async#ns(t,e,i){if(t.ok)this.#ss(i);else if(401===t.status){const n=$w(t.status,t.headers.get("WWW-Authenticate"),t.headers.get("Location"));n&&await this.#os(n,e,i)}else this.#ts()}#ss(t){e().success("annotation saved"),this.#Nt.emit("textae-event.resource.annotation.save",t)}async#os(t,e,i){const n=Cw(t);if(!n)return this.#ts();await async function(t){return new Promise(e=>{const i=setInterval(()=>{t.closed&&(clearInterval(i),e())},1e3)})}(n),await this.#rs(i,e)}async#rs(t,e){const i=Tw(t,this.#es);(await this.#is(e,i)).ok?this.#ss(t):this.#ts()}#ts(){e().error("could not save"),this.#Nt.emit("textae-event.resource.save.error")}}class Ew{#Nt;constructor(t){this.#Nt=t}saveTo(t,e){if(t){this.#Nt.emit("textae-event.resource.startSave");const i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),credentials:"include"};fetch(t,i).then(i=>{if(i.ok)return this.#ss(e);if(401===i.status){const n=$w(i.status,i.headers.get("WWW-Authenticate"),i.headers.get("Location"));if(n)return this.#os(n,t,e)}this.#ts()}).finally(()=>this.#Nt.emit("textae-event.resource.endSave"))}}#ss(t){e().success("configuration saved"),this.#Nt.emit("textae-event.resource.configuration.save",t)}#os(t,e,i){if(!Cw(t))return this.#ts();const n=setInterval(()=>{clearInterval(n),this.#rs(i,e)},1e3)}#rs(t,e){{const i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),credentials:"include"};fetch(e,i).then(e=>{e.ok?this.#ss(t):this.#ts()})}}#ts(){e().error("could not save"),this.#Nt.emit("textae-event.resource.save.error")}}class Aw{#Nt;constructor(t){this.#Nt=t}loadAnnotation(t){new Sw(this.#Nt).loadFrom(t)}loadConfiguration(t,e=null){new kw(this.#Nt).loadFrom(t,e)}saveAnnotation(t,e,i){new Pw(i,this.#Nt).saveTo(t,e)}saveConfiguration(t,e){new Ew(this.#Nt).saveTo(t,e)}}class Mw{#as;constructor(){this.#as=new Map([["logo",{name:"show logo",enabled:!0}],["read",{name:"import",enabled:!0}],["write",{name:"upload",enabled:!0}],["write-auto",{name:"upload automatically",enabled:!0}],["view",{name:"view mode",enabled:!0}],["term",{name:"term edit mode",enabled:!0}],["term-edit",{alias:"term"}],["block",{name:"block edit mode",enabled:!0}],["block-edit",{alias:"block"}],["relation",{name:"relation edit mode",enabled:!0}],["relation-edit",{alias:"relation"}],["text-edit",{name:"text edit mode",enabled:!0}],["simple",{name:"simple view",enabled:!0}],["line-height",{name:"adjust lineheight",enabled:!0}],["line-height-auto",{name:"auto adjust lineheight",enabled:!0}],["undo",{name:"undo",enabled:!0}],["redo",{name:"redo",enabled:!0}],["replicate",{name:"replicate span annotation",enabled:!0}],["replicate-auto",{name:"auto replicate",enabled:!0}],["boundary-detection",{name:"boundary detection",enabled:!0}],["create-span-by-touch",{name:"create span by touch",enabled:!0}],["expand-span-by-touch",{name:"expand span by touch",enabled:!0}],["shrink-span-by-touch",{name:"shrink span by touch",enabled:!0}],["edit-text-by-touch",{name:"edit text by touch",enabled:!0}],["entity",{name:"new entity",enabled:!0}],["pallet",{name:"pallet",enabled:!0}],["edit-properties",{name:"edit properties",enabled:!0}],["delete",{name:"delete",enabled:!0}],["copy",{name:"copy",enabled:!0}],["cut",{name:"cut",enabled:!0}],["paste",{name:"paste",enabled:!0}],["setting",{name:"setting",enabled:!0}],["help",{name:"help",enabled:!0}]])}get defaultAvailabilities(){return Array.from(this.#as.values()).filter(({name:t,enabled:e})=>void 0!==t&&void 0!==e).reduce((t,{name:e,enabled:i})=>t.set(e,i),new Map)}translateToInnerNameFrom(t){if(this.#as.has(t)){const e=this.#as.get(t);return e.alias?this.#as.get(e.alias).name:e.name}return e().warning(`'${t}' is an unknown function name for function availabilities.`),t}}class Qw{#ls;#cs;constructor(){this.#ls=new Mw,this.#cs=this.#ls.defaultAvailabilities}isAvailable(t){return this.#cs.get(t)}enable(t){this.#cs.set(t,!0)}disable(t){this.#cs.set(t,!1)}get names(){return Array.from(this.#cs.keys())}set availability(t){const e=this.#ls.defaultAvailabilities;if(t)for(const[i,n]of Object.entries(t))e.set(this.#ls.translateToInnerNameFrom(i),n);this.#cs=e}}class Dw{#hs;#us;#fe;#Nt;#si;constructor(t,e,i){this.#hs=!1,this.#us=mn,this.#fe=t,this.#Nt=e,this.#si=i}get currentState(){return this.#us}toViewMode(t){this.#hs=t,this.#us=gn,this.#ds()}toTermEditMode(t){this.#hs=t,this.#us=vn,this.#ds()}toBlockEditMode(t){this.#hs=t,this.#us=yn,this.#ds()}toRelationEditMode(){this.#hs=!0,this.#us=On,this.#ds()}toTextEditMode(t){this.#hs=t,this.#us=bn,this.#ds()}toggleSimpleMode(){switch(this.currentState){case vn:this.toTermEditMode(!this.#hs);break;case yn:this.toBlockEditMode(!this.#hs);break;case bn:this.toTextEditMode(!this.#hs);break;case gn:this.toViewMode(!this.#hs);break;default:throw new Error(`Invalid state: ${this.currentState}`)}}changeModeByShortcut(){const t=this.#fs;if(t.length<=1)return;const e=t.findIndex(t=>t.name===this.currentState);e<t.length-1?this[t[e+1].funcName](this.nextShowRelation):this[t[0].funcName](this.nextShowRelation)}get nextShowRelation(){return this.#us===On?this.#fe.some:this.#hs}#ds(){this.#Nt.emit("textae-event.edit-mode.transition",this.#us,this.#hs)}get#fs(){return[{name:gn,availabilityName:"view mode",funcName:"toViewMode"},{name:vn,availabilityName:"term edit mode",funcName:"toTermEditMode"},{name:yn,availabilityName:"block edit mode",funcName:"toBlockEditMode"},{name:On,availabilityName:"relation edit mode",funcName:"toRelationEditMode"}].filter(t=>this.#si.isAvailable(t.availabilityName))}}class Rw{#En;#ps;#G;#ms;constructor(t,e,i,n){this.#ps=t,this.#En=e,this.#G=i,this.#ms=n}toViewMode(){this.#ms(),this.#En.toViewMode(this.#En.nextShowRelation)}toTermEditMode(){this.#ms(),this.#En.toTermEditMode(this.#En.nextShowRelation)}toBlockEditMode(){this.#ms(),this.#En.toBlockEditMode(this.#En.nextShowRelation)}toRelationEditMode(){this.#ms(),this.#En.toRelationEditMode()}toTextEditMode(){this.#ms(),this.#En.toTextEditMode(this.#En.nextShowRelation)}toggleSimpleMode(){this.#ms(),this.#En.toggleSimpleMode()}changeModeByShortcut(){this.#ms(),this.#En.changeModeByShortcut()}reset(){this.#ps.isEditTermMode?this.#En.toTermEditMode(this.#G.some):this.#ps.isEditBlockMode?this.#En.toBlockEditMode(this.#G.some):this.#ps.isEditRelationMode?this.#En.toRelationEditMode():this.#ps.isTextEditMode?this.#En.toTextEditMode(this.#G.some):this.#En.toViewMode(this.#G.some)}}function Iw(){window.getSelection().removeAllRanges()}function Lw(t,i,n,s,o,r,a,l,c){if(a){s.removeAll();const h=L(t,a),u=function(t,i,n,s,o,r,a){const{begin:l,end:c}=t.getSpan(o).getShortenInAnchorNodeToFocusNodeDirection(s,i,r);if(t.isBoundaryCrossingWithOtherSpans(l,c))return e().warning("A span cannot be shrunken to make a boundary crossing."),!1;const h=t.findDenotation(l,c);return l<c&&!h?(a(l,c),!1):(n.invoke(n.factory.removeSpanCommand(o)),!0)}(i,n,o,r,a,l,c);u&&h&&s.selectSpan(h.id)}}class Nw{constructor(){this.selection=window.getSelection(),console.assert(this.parentOfAnchorNode.closest(".textae-editor__text-box")===this.parentOfFocusNode.closest(".textae-editor__text-box"),"Text selection across editors is disabled")}get isParentOfAnchorNodeTextBox(){return Y(this.parentOfAnchorNode)}get isParentOfAnchorNodeDenotationSpan(){return U(this.parentOfAnchorNode)}get isParentOfAnchorNodeBlockSpan(){return K(this.parentOfAnchorNode)}get isParentOfAnchorNodeStyleSpan(){return G(this.parentOfAnchorNode)}get isParentOfFocusNodeTextBox(){return Y(this.parentOfFocusNode)}get isParentOfFocusNodeDenotationSpan(){return U(this.parentOfFocusNode)}get isParentOfFocusNodeBlockSpan(){return K(this.parentOfFocusNode)}get isParentOfFocusNodeStyleSpan(){return G(this.parentOfFocusNode)}get isParentOfBothNodesSame(){return this.parentOfAnchorNode===this.parentOfFocusNode}get isParentOfBothNodesTextBox(){return this.isParentOfAnchorNodeTextBox&&this.isParentOfFocusNodeTextBox}get isParentsParentOfAnchorNodeAndFocusedNodeSame(){return this.parentOfAnchorNode.parentElement===this.parentOfFocusNode.parentElement}get isAnchorNodeParentIsDescendantOfFocusNodeParent(){return this.parentOfAnchorNode.closest(`#${this.parentOfFocusNode.id}`)}get ancestorDenotationSpanOfAnchorNode(){return this.parentOfAnchorNode.closest(".textae-editor__span")}get ancestorDenotationSpanOfFocusNode(){return this.parentOfFocusNode.closest(".textae-editor__span")}get ancestorBlockSpanOfAnchorNode(){return this.parentOfAnchorNode.closest(".textae-editor__block")}get ancestorBlockSpanOfFocusNode(){return this.parentOfFocusNode.closest(".textae-editor__block")}get doesFitInOneBlockSpan(){return this.ancestorBlockSpanOfAnchorNode===this.ancestorBlockSpanOfFocusNode}get parentOfAnchorNode(){return this.selection.anchorNode.parentElement}get parentOfFocusNode(){return this.selection.focusNode.parentElement}}class jw{#Q;#Ht;#ni;#ei;#ii;#Ie;constructor(t,e,i,n,s,o){this.#Q=t,this.#Ht=e,this.#ni=i,this.#ei=n,this.#ii=s,this.#Ie=o}editFor(){const t=new Nw;if(t.isParentOfAnchorNodeTextBox){if(t.isParentOfFocusNodeTextBox)return void this.#gs();if(t.isParentOfFocusNodeDenotationSpan||t.isParentOfFocusNodeStyleSpan)return void(t.ancestorBlockSpanOfFocusNode?this.#vs(t):this.#gs());if(t.isParentOfFocusNodeBlockSpan)return void this.#vs(t)}if(t.isParentOfAnchorNodeDenotationSpan||t.isParentOfAnchorNodeStyleSpan){if(t.isParentOfFocusNodeTextBox||t.isParentOfFocusNodeDenotationSpan||t.isParentOfFocusNodeStyleSpan){if(t.ancestorBlockSpanOfAnchorNode)if(t.doesFitInOneBlockSpan){const{anchor:e,focus:i}=this.#Ht.textSelection,n=this.#Ht.getSpan(t.parentOfAnchorNode.id),s=this.#Ht.getSpan(t.ancestorBlockSpanOfAnchorNode.id);e<i&&n.begin===s.begin||i<e&&n.end===s.end?this.#vs(t):Iw()}else this.#ys(t);else t.ancestorBlockSpanOfFocusNode?this.#vs(t):this.#gs();return}if(t.isParentOfFocusNodeBlockSpan)return void this.#vs(t)}if(t.isParentOfAnchorNodeBlockSpan){if(t.isParentOfFocusNodeTextBox||t.isParentOfFocusNodeDenotationSpan||t.isParentOfFocusNodeStyleSpan)return void(t.ancestorBlockSpanOfFocusNode?this.#vs(t):this.#ys(t));if(t.isParentOfFocusNodeBlockSpan){const{anchor:e}=this.#Ht.textSelection,i=this.#Ht.getSpan(t.parentOfFocusNode.id);if(e===i.begin||e===i.end)return void this.#vs(t)}}Iw()}cerateSpanForTouchDevice(){(new Nw).isParentOfBothNodesTextBox&&this.#gs()}expandForTouchDevice(){const t=this.#Os();if(t){const{spanID:e,begin:i,end:n}=t;this.#Ht.validateNewBlockSpan(i,n,e)&&this.#ei.invoke(this.#ei.factory.moveBlockSpanCommand(e,i,n))}}shrinkForTouchDevice(){const t=this.#bs();if(t){const{spanID:i,begin:n,end:s}=t,o=L(this.#Q,i);if(this.#Ht.isBoundaryCrossingWithOtherSpans(n,s))return void e().warning("A span cannot be modified to make a boundary crossing.");if(this.#Ht.hasParentOf(n,s,i))return;const r=this.#Ht.findBlock(n,s);n<s&&!r?this.#ei.invoke(this.#ei.factory.moveBlockSpanCommand(i,n,s)):(this.#ei.invoke(this.#ei.factory.removeSpanCommand(i)),o&&this.#Ie.selectSpan(o.id))}}#gs(){this.#Ht.hasCharacters(this.#ni)&&(this.#Ie.removeAll(),function(t,e,i,n){const{begin:s,end:o}=t.getTextSelection(n,i);if(t.validateNewBlockSpan(s,o)){const t=e.factory.createBlockSpanCommand({begin:s,end:o});e.invoke(t)}}(this.#Ht,this.#ei,this.#ii.textSelectionAdjuster,this.#ni)),Iw()}#ys(t){const e=t.ancestorBlockSpanOfAnchorNode.id;this.#Ie.removeAll();const{begin:i,end:n}=this.#Ht.getSpan(e).getExpandedInAnchorNodeToFocusNodeDirection(this.#ii.textSelectionAdjuster,this.#Ht.sourceDoc,this.#ni);this.#Ht.validateNewBlockSpan(i,n,e)&&this.#ei.invoke(this.#ei.factory.moveBlockSpanCommand(e,i,n)),Iw()}#vs(t){const e=t.ancestorBlockSpanOfFocusNode.id;Lw(this.#Q,this.#Ht,this.#Ht.sourceDoc,this.#Ie,this.#ei,this.#ii.textSelectionAdjuster,e,this.#ni,(t,i)=>{this.#ei.invoke(this.#ei.factory.moveBlockSpanCommand(e,t,i))}),Iw()}#Os(){const t=new Nw;if(null==t.ancestorBlockSpanOfAnchorNode&&null==t.ancestorBlockSpanOfFocusNode)return null;if(t.parentOfFocusNode.contains(t.parentOfAnchorNode)){const e=t.parentOfAnchorNode.id;return{spanID:e,...this.#Ht.getSpan(e).getExpandedInAnchorNodeToFocusNodeDirection(this.#ii.textSelectionAdjuster,this.#Ht.sourceDoc,this.#ni)}}if(t.parentOfAnchorNode.contains(t.parentOfFocusNode)){const e=t.parentOfFocusNode.id;return{spanID:e,...this.#Ht.getSpan(e).getExpandedInFocusNodeToAnchorNodeDirection(this.#ii.textSelectionAdjuster,this.#Ht.sourceDoc,this.#ni)}}}#bs(){const t=new Nw;if(null==t.ancestorBlockSpanOfAnchorNode&&null==t.ancestorBlockSpanOfFocusNode)return null;if(t.parentOfAnchorNode===t.parentOfFocusNode)return null;if(t.parentOfFocusNode.contains(t.parentOfAnchorNode)){const e=t.parentOfAnchorNode.id;return{spanID:e,...this.#Ht.getSpan(e).getShortenInFocusNodeToAnchorNodeDirection(this.#ii.textSelectionAdjuster,this.#Ht.sourceDoc,this.#ni)}}if(t.parentOfAnchorNode.contains(t.parentOfFocusNode)){const e=t.parentOfFocusNode.id;return{spanID:e,...this.#Ht.getSpan(e).getShortenInAnchorNodeToFocusNodeDirection(this.#ii.textSelectionAdjuster,this.#Ht.sourceDoc,this.#ni)}}}}function zw(t,e,i,n){e.length?t.selectSpanRange(e):i.ctrlKey||i.metaKey?t.span.toggle(n):t.selectSpan(n)}function Bw(t){const e=window.getSelection();return"Range"===e.type&&t.contains(e.anchorNode)&&t.contains(e.focusNode)}function qw(t){return t.closest(".textae-editor__signboard")}class Zw{#Q;#Ht;#Ie;#xs;#ws;constructor(t,e,i,n,s){this.#Q=t,this.#Ht=e,this.#Ie=i,this.#xs=n,this.#ws=s}bind(){const t=[];return t.push(r()(this.#Q,".textae-editor__text-box","click",t=>{t.target.classList.contains("textae-editor__text-box")&&this.#_s()})),t.push(r()(this.#Q,".textae-editor","click",t=>{t.target.classList.contains("textae-editor")&&this.#Ss()})),t.push(r()(this.#Q,".textae-editor__signboard","mousedown",()=>this.#ks())),t.push(r()(this.#Q,".textae-editor__signboard__type-values","click",t=>{const e=qw(t.target).dataset.id;this.#$s(t,e)})),t.push(r()(this.#Q,".textae-editor__block","mouseup",t=>{t.target.classList.contains("textae-editor__block")&&this.#Cs()})),t.push(r()(this.#Q,".textae-editor__block-hit-area","mouseup",t=>{t.target.classList.contains("textae-editor__block-hit-area")&&this.#Ts(t)})),t.push(r()(this.#Q,".textae-editor__style","mouseup",t=>{t.target.classList.contains("textae-editor__style")&&this.#Ps(t)})),t.push(r()(this.#Q,".textae-editor__span","mouseup",t=>{t.target.classList.contains("textae-editor__span")&&this.#Es(t)})),t}#Ss(){this.#ws.hide(),this.#Ie.removeAll()}#_s(){"Caret"===window.getSelection().type&&(this.#ws.hide(),this.#Ie.removeAll()),Bw(this.#Q.querySelector(".textae-editor__text-box"))&&this.#xs.editFor()}#Cs(){"Caret"===window.getSelection().type&&(this.#ws.hide(),Iw(),this.#Ie.removeAll()),Bw(this.#Q.querySelector(".textae-editor__text-box"))&&this.#xs.editFor()}#Ts(t){2===t.button&&Iw();const e=window.getSelection();if("Caret"===e.type||"None"===e.type){const e=t.target.dataset.id;this.#As(t,e)}}#Ps(t){"Caret"===window.getSelection().type&&this.#Ie.removeAll(),Bw(this.#Q.querySelector(".textae-editor__text-box"))&&(this.#xs.editFor(),t.stopPropagation())}#Es(t){"Caret"===window.getSelection().type&&this.#Ie.removeAll(),Bw(this.#Q.querySelector(".textae-editor__text-box"))&&(this.#xs.editFor(),t.stopPropagation())}#ks(){this.#Q.focus()}#$s(t,e){if(this.#Ht.entityInstanceContainer.get(e).isBlock){t.ctrlKey||t.metaKey?this.#Ie.entity.toggle(e):this.#Ie.selectEntity(e);const i=this.#Ie.entity.all.map(t=>t.span).map(t=>t.id);this.#Ie.add("span",i)}}#As(t,e){const i=this.#Ie.span.singleId,n=t.shiftKey&&i?this.#Ht.spanInstanceContainer.rangeBlockSpan(i,e):[];zw(this.#Ie,n,t,e);const s=this.#Ie.span.all.map(t=>t.entities.at(0)).map(t=>t.id);this.#Ie.add("entity",s)}}class Fw{createSpanWithTouchDevice(){}expandSpanWithTouchDevice(){}shrinkSpanWithTouchDevice(){}editTextWithTouchDevice(){}editProperties(){}relationClicked(){}relationBollardClicked(t){t.focus()}applyTextSelectionWithTouchDevice(){}manipulateAttribute(){}showPallet(){}hidePallet(){}get isPalletShown(){return!1}}class Xw extends u{constructor(t,e,i,n){const s=()=>{const t=n();t&&this.resolveFunc(t),super.close()},o={text:"OK",click:s};i.buttons=i.buttons?i.buttons.concat([o]):[o],super(t,e,i),r()(super.el,".textae-editor__promise-dialog__observable-element","keyup",t=>{13===t.keyCode&&s()})}open(){return super.open(),new Promise(t=>this.resolveFunc=t)}}class Hw extends Xw{constructor(t,e,i,n,s,o){const a=[];n&&a.unshift({class:"textae-editor__edit-numeric-attribute-dialog__remove-attribute",click:()=>{this.close(),this.resolveFunc({newObj:null})}}),o&&a.unshift({text:"...",title:"configuration",click:()=>{this.close(),o.show(),o.showAttribute(e.pred)}}),super(`Attribute [${i.map(({id:t})=>t||"-").join(",")}]`,function(t){const{subjects:e,pred:i,min:n,max:s,step:o,value:r}=t;return ot`
304
+ `}bind(t,e){r()(t,".textae-editor__load-dialog__url-text","input",t=>{wn(t.target.nextElementSibling,t.target.value)}),r()(t,".textae-editor__load-dialog__url-button","click",t=>e(t.target.previousElementSibling.value))}}var XO=i(2628),HO=i.n(XO);function WO(t,e){t.element.classList.remove("textae-editor__load-dialog__overlay-dropzone--maximized"),t.element.style.zIndex=e}class VO{#ui;get template(){return'\n<div class="textae-editor__load-dialog__row">\n <label>\n Local\n </label>\n <form class="dropzone textae-editor__load-dialog__dropzone">\n <div class="dz-message">\n Drop a file here or click to select\n </div>\n </form>\n <div class="textae-editor__load-dialog__dz-file-preview">\n <div class="dz-filename"><span data-dz-name>No file selected</span></div>\n </div>\n <input\n type="button"\n class="textae-editor__load-dialog__local-button"\n disabled="disabled"\n value="Open">\n</div>\n'}bind(t,e){r()(t,".textae-editor__load-dialog__local-button","click",()=>e(this.#ui))}intiializeDropzone(t){const e={url:"nothing",previewsContainer:".textae-editor__load-dialog__dz-file-preview",previewTemplate:t.querySelector(".textae-editor__load-dialog__dz-file-preview").innerHTML},i=new(HO())("body > div.ui-widget-overlay.ui-front",{...e,clickable:!1}),n=i.element.style.zIndex;i.on("dragenter",()=>function(t){const{element:e}=t;e.classList.add("textae-editor__load-dialog__overlay-dropzone--maximized"),e.style.zIndex=parseInt(e.style.zIndex)+1}(i)).on("dragleave",()=>WO(i,n)).on("addedfile",e=>{WO(i,n),this.#di(t,e)});new(HO())(".textae-editor__load-dialog__dropzone",e).on("addedfile",e=>{this.#di(t,e)})}#di(t,e){t.querySelector(".textae-editor__load-dialog__dz-file-preview").firstElementChild.remove(),t.querySelector(".textae-editor__load-dialog__dz-file-preview > div").setAttribute("title",e.name),this.#ui=e,wn(t.querySelector(".textae-editor__load-dialog__local-button"),!0)}}class YO extends u{#fi;constructor(t,e,i,n,s,o){const a=new FO(e),l=new VO;super(t,function(t){const{url:e,local:i}=t;return`\n<div class="textae-editor__load-dialog__container">\n ${e}\n ${i}\n <div class="textae-editor__load-dialog__row">\n <div class="textae-editor__load-dialog__format">\n <label class="textae-editor__load-dialog__format-button">\n <input type="radio" name="format" value="json" checked>JSON\n </label>\n <label class="textae-editor__load-dialog__format-button">\n <input type="radio" name="format" value="inline">Text\n </label>\n </div>\n <textarea class="textae-editor__load-dialog__textarea"></textarea>\n <input type="button" value="Edit" class="edit" disabled="disabled">\n <input type="button" value="Open" class="instant" disabled="disabled">\n </div>\n</div>`}({url:a.template,local:l.template})),this.#fi=l,a.bind(super.el,t=>{ZO(o)&&i(t),super.close()}),this.#fi.bind(super.el,t=>{ZO(o)&&n(t),super.close()}),r()(super.el,".textae-editor__load-dialog__textarea","input",t=>{wn(super.el.querySelector('[type="button"].instant'),t.target.value),wn(super.el.querySelector('[type="button"].edit'),t.target.value)});let c=null;r()(super.el,'[type="button"].instant',"click",()=>{const t=c?c.state.doc.toString():super.el.querySelector(".textae-editor__load-dialog__textarea").value,e=this.#pi();ZO(o)&&s(t,e),super.close()}),r()(super.el,'[type="button"].edit',"click",()=>{this.#mi();const t=super.el.querySelector(".textae-editor__load-dialog__textarea"),e=this.#pi();"json"===e&&_n(t.value)&&(t.value=JSON.stringify(JSON.parse(t.value),null,2));const i=super.el.closest(".textae-editor__dialog").clientHeight;c="json"===e?qO(t,i):function(t,e){const i=Tc.theme({"&":{height:.6*e+"px"}}),n=new Tc({doc:t.value,extensions:[Qy,Qf(If),i]});return t.parentNode.insertBefore(n.dom,t),t.style.display="none",n}(t,i);const n=super.el.querySelectorAll('.textae-editor__load-dialog__format-button input[type="radio"]');for(const t of n)t.disabled=!0;super.el.querySelector('[type="button"].edit').disabled=!0})}open(){super.open(),this.#fi.intiializeDropzone(super.el)}#mi(){super.el.closest(".textae-editor__dialog").classList.add("textae-editor__load-dialog--expanded")}#pi(){return super.el.querySelector('input[name="format"]:checked').value}}class UO extends u{#fi;constructor(t,e,i,n,s,o){const a=new FO(e),l=new VO;super(t,function(t){const{url:e,local:i}=t;return`\n<div class="textae-editor__load-dialog__container">\n ${e}\n ${i}\n <div class="textae-editor__load-dialog__row json">\n <label>\n JSON\n </label>\n <textarea class="textae-editor__load-dialog__textarea"></textarea>\n <input type="button" value="Edit" class="edit" disabled="disabled">\n <input type="button" value="Open" class="instant" disabled="disabled">\n </div>\n</div>`}({url:a.template,local:l.template})),this.#fi=l,a.bind(super.el,t=>{ZO(o)&&i(t),super.close()}),this.#fi.bind(super.el,t=>{ZO(o)&&n(t),super.close()}),r()(super.el,".textae-editor__load-dialog__textarea","input",t=>{wn(super.el.querySelector('[type="button"].instant'),t.target.value),wn(super.el.querySelector('[type="button"].edit'),t.target.value)});let c=null;r()(super.el,'[type="button"].instant',"click",()=>{const t=c?c.state.doc.toString():super.el.querySelector(".textae-editor__load-dialog__textarea").value;ZO(o)&&s(t),super.close()}),r()(super.el,'[type="button"].edit',"click",()=>{this.#mi();const t=super.el.querySelector(".textae-editor__load-dialog__textarea");_n(t.value)&&(t.value=JSON.stringify(JSON.parse(t.value),null,2));const e=super.el.closest(".textae-editor__dialog").clientHeight;c=qO(t,e),super.el.querySelector('[type="button"].edit').disabled=!0})}open(){super.open(),this.#fi.intiializeDropzone(super.el)}#mi(){super.el.closest(".textae-editor__dialog").classList.add("textae-editor__load-dialog--expanded")}}function GO(t){const e=new Blob([JSON.stringify(t)],{type:"application/json"});return URL.createObjectURL(e)}const KO=class{#gi;#vi;#Y;#H;constructor(t,e,i,n=null){this.#gi=t,this.#vi=e,this.#Y=i,this.#H=n}get beginPos(){return this.#gi}get endPos(){return this.#vi}get obj(){return this.#Y}get id(){return this.#H}get span(){return{begin:this.#gi,end:this.#vi}}toObject(){const t={span:this.span,obj:this.#Y};return this.#H&&(t.id=this.#H),t}isNestedWithin(t){return t.beginPos<=this.#gi&&this.#vi<=t.endPos}get isPositionNotInteger(){return!(Number.isInteger(this.#gi)&&Number.isInteger(this.endPos))}get isPositionNegative(){return this.#gi<0||this.#vi<0}get isPositionInvalid(){return this.#gi>this.#vi}isOutOfBounds(t){return this.#gi>=t||this.#vi>t}isBoundaryCrossing(t){const e=this.#gi>t.beginPos&&this.#gi<t.endPos,i=this.#vi>t.beginPos&&this.#vi<t.endPos;return e||i}};const JO=class{validateDenotations(t,e){let i=this.#yi(t);return i=this.#Oi(i),i=this.#bi(i),i=this.#xi(i),i=this.#wi(i,e),i=this.#_i(i),this.#Si(i)}#yi(t){const e=new Set;return t.filter(t=>{const i=JSON.stringify(t.span);return!e.has(i)&&(e.add(i),!0)})}#Oi(t){return t.filter(t=>!t.isPositionNotInteger)}#bi(t){return t.filter(t=>!t.isPositionNegative)}#xi(t){return t.filter(t=>!t.isPositionInvalid)}#wi(t,e){return t.filter(t=>!t.isOutOfBounds(e))}#_i(t){const e=t.sort((t,e)=>t.beginPos===e.beginPos?e.endPos-t.endPos:t.beginPos-e.beginPos),i=[];return e.forEach(t=>{i.some(e=>t.isNestedWithin(e))||i.push(t)}),i}#Si(t){return t.filter(e=>!t.some(t=>e!==t&&e.isBoundaryCrossing(t)))}};class tb extends Error{constructor(t){super(t),this.name=this.constructor.name}}const eb=tb;const ib=class{validateRelations(t){return this.#ki(t)}#ki(t){return t.filter(t=>t.subj&&t.pred&&t.obj)}};const nb=class{constructor(t){this.source=Object.freeze({...t}),this.denotations=this.#$i(t.denotations||[]),this.config=this.source.config}generate(){const t=this.source.text;if(!t)throw new eb('The "text" key is missing.');const e=(new JO).validateDenotations(this.denotations,t.length),i=(new ib).validateRelations(this.source.relations||[]);return[this.#Ci(t,e,i),this.#Ti()].filter(Boolean).join("\n\n")}#$i(t){return t.map(t=>new KO(t.span.begin,t.span.end,t.obj,t.id||null))}#Ci(t,e,i){return e.sort((t,e)=>e.beginPos-t.beginPos).forEach(e=>{const n=e.beginPos,s=e.endPos,o=e.id?this.#Pi(e,i):this.#Ei(e.obj),r=`[${t.slice(n,s)}][${o}]`;t=t.slice(0,n)+r+t.slice(s)}),t}#Ti(){const t=this.#Ai();return t&&0!==t.length?t.map(t=>`[${t.label}]: ${t.id}`).join("\n"):null}#Ai(){return this.config&&this.config["entity types"]?.filter(t=>t.hasOwnProperty("label"))||null}#Pi(t,e){const i=e.find(e=>e.subj===t.id)||null,n=[t.id,t.obj,i?.pred,i?.obj];if(!this.#Ai())return n.filter(t=>null!=t).join(", ");n[1]=this.#Ei(t.obj);this.#Ai().find(e=>e.id===t.obj);return n.filter(t=>null!=t).join(", ")}#Ei(t){if(!this.#Ai())return t;const e=this.#Ai().find(e=>e.id===t);return e?e.label:t}},sb=/^\s*\[([^\]]+)\]:\s+(\S+)(?:\s+(?:"[^"]*"|'[^']*'))?\s*$/,ob=new RegExp(`(?:\\A|\\n\\s*\\n)((?:${sb.source}(?:\\n|$))+)`,"gm");const rb=class{#Mi;#Qi=null;constructor(t){this.#Mi=t}get(t){return this.#Di[t]}get config(){return Object.entries(this.#Di).map(([t,e])=>({id:e,label:t}))}get#Di(){return this.#Qi||(this.#Qi=this.#Ri()),this.#Qi}#Ri(){const t={},e=Array.from(this.#Mi.matchAll(ob));for(const i of e)this.#Ii(i,t);return t}#Ii(t,e){const i=t[0].split("\n");for(const t of i)this.#Li(t,e)}#Li(t,e){const i=t.trim().match(sb);if(!i)return;const[n,s,o]=i;s!==o&&(e[s]||(e[s]=o))}},ab=new RegExp(`(?:\\A|\\n\\s*\\n)((?:${/^\s*\[([^\]]+)\]:\s+(\S+)(?:\s+(?:"[^"]*"|'[^']*'))?\s*$/.source}(?:\\n|$))+)`,"gm"),lb=/(?<!\\)\[([^\[]+?)\]\[([^\]]+?)\]/;const cb=class{#Mi;#D;#Ni;#ji;constructor(t){this.#Mi=t,this.#Ni=new rb(t)}parse(){this.#D=[],this.#ji=[];let t=this.#zi();return t=this.#Bi(t),new ub(t,this.#D,this.#ji,this.#Ni)}#zi(){return this.#Mi.replace(ab,t=>t.startsWith("\n\n")?"\n\n":"").trim()}#qi(t){return this.#Ni.get(t)||t}#Bi(t){const e=new RegExp(lb,"g");let i;for(;null!==(i=e.exec(t));){const n=i[1],s=i.index,o=s+n.length,r=i[2].split(", ");switch(r.length){case 1:this.#Zi(s,o,r[0]);break;case 2:this.#Fi(s,o,r);break;case 4:this.#Xi(s,o,r);break;default:e.lastIndex=i.index+i[0].length;continue}t=t.slice(0,i.index)+n+t.slice(i.index+i[0].length),e.lastIndex=o}return t}#Zi(t,e,i){const n=this.#qi(i);this.#D.push(new KO(t,e,n))}#Fi(t,e,i){const[n,s]=i,o=this.#qi(s);this.#D.push(new KO(t,e,o,n))}#Xi(t,e,i){const[n,s,o,r]=i,a=this.#qi(s);this.#D.push(new KO(t,e,a,n)),this.#ji.push({pred:o,subj:n,obj:r})}},hb=/\\(?=\[[^\]]+\]\[[^\]]+\])/;const ub=class{#re;#D;#ji;#Ni;constructor(t,e,i,n){this.#re=t,this.#D=e,this.#ji=i,this.#Ni=n}static parse(t){return new cb(t).parse().toObject()}static generate(t){return new nb(t).generate()}toObject(){const t={text:this.#Hi(this.#re),denotations:this.#D.map(t=>t.toObject())};this.#ji&&this.#ji.length>0&&(t.relations=this.#ji);const e=this.#Wi();return e&&Object.keys(e).length>0&&!Object.values(e).every(t=>null==t||Array.isArray(t)&&0===t.length)&&(t.config=e),t}#Hi(t){let e=this.#Vi(t);return this.#Yi(e)}#Vi(t){return t.replace(hb,"")}#Yi(t){return t.replace(/\n{2,}/g,"\n\n")}#Wi(){return this.#Ni&&0!==this.#Ni.length?{"entity types":this.#Ni.config}:null}};function db(t,e){if("json"===e)return GO(t);if("inline"===e){const e=ub.generate(t),i=new Blob([e],{type:"text/plain;charset=utf-8"});return URL.createObjectURL(i)}}function fb(t,e,i,n){t.preventDefault();!function(t,e){const i=document.createElement("a");i.setAttribute("href",t),i.setAttribute("download",e),document.body.appendChild(i),i.click(),document.body.removeChild(i)}(db(e,i),t.target.previousElementSibling.value),n.emit("textae-event.resource.annotation.save",e)}function pb(t,i,n,s,o,a){r()(i,".textae-editor__save-dialog__url-text","input",t=>{wn(t.target.nextElementSibling,t.target.value)}),r()(i,".textae-editor__save-dialog__url-text","keyup",t=>{if(13===t.keyCode){const e=a();o(t.target.value,e),s()}}),r()(i,".textae-editor__save-dialog__url-button","click",t=>{const e=a();o(t.target.previousElementSibling.value,e),s()}),r()(i,".textae-editor__save-dialog__download-link","click",i=>{const o=a();try{fb(i,n,o,t)}catch(t){e().error(`Failed to download the source as ${o} format.`)}finally{s()}}),r()(i,".textae-editor__save-dialog__viewsource-link","click",()=>{const i=a();try{!function(t,e,i){const n=db(t,e);window.open(n,"_blank"),i.emit("textae-event.resource.annotation.save",t)}(n,i,t)}catch(t){e().error(`Failed to view the source as ${i} format.`)}finally{s()}})}class mb extends u{constructor(t,e,i,n,s){super("Save Annotations",function(t){const{url:e,filename:i}=t;return`\n<div class="textae-editor__save-dialog__container">\n <div class="textae-editor__save-dialog__row">\n <span>Format</span>\n <div class="textae-editor__save-dialog__format">\n <label class="textae-editor__save-dialog__format-button">\n <input type="radio" name="format" value="json" checked>JSON\n </label>\n <label class="textae-editor__save-dialog__format-button">\n <input type="radio" name="format" value="inline">Text\n </label>\n </div>\n </div>\n <div class="textae-editor__save-dialog__row">\n <label>URL</label>\n <input\n type="text"\n value="${e}"\n class="textae-editor__save-dialog__url-text">\n <input\n type="button"\n class="textae-editor__save-dialog__url-button"\n ${e?"":'disabled="disabled"'}\n value="Save">\n </div>\n <div class="textae-editor__save-dialog__row">\n <label>Local</label>\n <input\n type="text"\n value="${i||""}"\n >\n <a class="textae-editor__save-dialog__download-link" href="#">Download</a>\n </div>\n <div class="textae-editor__save-dialog__row">\n <a class="textae-editor__save-dialog__viewsource-link" href="#">Click to see the source in a new window.</a>\n </div>\n</div>\n`}({filename:i,url:e})),pb(t,super.el,n,()=>super.close(),s,()=>super.el.querySelector('input[name="format"]:checked').value)}}function gb(t,e){if(t.length<2)throw new Error(e||"Expected an array with at least 2 items")}const vb=class{format(t,e){const i={};this.prepareContext(i);const n=i;return this.recurse(n,t,e),this.finalize(n)}prepareContext(t){t.buffer=[],t.out=function(...t){if(!this.buffer)throw new Error("context buffer is not initialized");this.buffer.push(...t)}}typeFormattterNotFound(t,e){throw new Error(`cannot format delta type: ${e}`)}typeFormattterErrorFormatter(t,e,i,n,s,o,r){}finalize({buffer:t}){return Array.isArray(t)?t.join(""):""}recurse(t,e,i,n,s,o,r){const a=e&&o?o.value:i;if(void 0===e&&void 0===n)return;const l=this.getDeltaType(e,o),c="node"===l?"a"===e._t?"array":"object":"";let h;void 0!==n?this.nodeBegin(t,n,s,l,c,null!=r&&r):this.rootBegin(t,l,c);try{h="unknown"!==l?this[`format_${l}`]:this.typeFormattterNotFound(t,l),h.call(this,t,e,a,n,s,o)}catch(i){this.typeFormattterErrorFormatter(t,i,e,a,n,s,o),"undefined"!=typeof console&&console.error&&console.error(i.stack)}void 0!==n?this.nodeEnd(t,n,s,l,c,null!=r&&r):this.rootEnd(t,l,c)}formatDeltaChildren(t,e,i){this.forEachDeltaKey(e,i,(n,s,o,r)=>{this.recurse(t,e[n],i?i[s]:void 0,n,s,o,r)})}forEachDeltaKey(t,e,i){const n=[];if(!("a"===t._t)){const s=Object.keys(t);"object"==typeof e&&null!==e&&n.push(...Object.keys(e));for(const t of s)n.indexOf(t)>=0||n.push(t);for(let t=0;t<n.length;t++){const e=n[t];if(void 0===e)continue;const s=t===n.length-1;i(e,e,void 0,s)}return}const s={};for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const i=t[e];if(Array.isArray(i)&&3===i[2]){s[i[1]]=Number.parseInt(e.substring(1))}}const o=t;let r=0,a=0;const l=Array.isArray(e)?e:void 0,c=l?l.length:Object.keys(o).reduce((t,e)=>{if("_t"===e)return t;if("_"===e.substring(0,1)){const i=o[e],n=Number.parseInt(e.substring(1)),s=Array.isArray(i)&&i.length>=3&&3===i[2]?i[1]:void 0,r=Math.max(n,null!=s?s:0);return r>t?r:t}const i=Number.parseInt(e),n=s[i],r=Math.max(null!=n?n:0,null!=i?i:0);return r>t?r:t},0)+1;let h,u=c;const d=(...t)=>{h&&i(...h),h=t};for(;r<c||a<u||`${a}`in o;){let t=!1;const e=`_${r}`,i=`${a}`,n=a in s?s[a]:void 0;if(e in o){t=!0;const i=o[e];d(e,null!=n?n:r,n?{key:`_${n}`,value:l?l[n]:void 0}:void 0,!1),Array.isArray(i)?0===i[2]?(u--,r++):(i[2],r++):r++}if(i in o){t=!0;const e=o[i],s=Array.isArray(e)&&1===e.length;d(i,null!=n?n:r,n?{key:`_${n}`,value:l?l[n]:void 0}:void 0,!1),s?(u++,a++):void 0===n?(r++,a++):a++}t||((l&&void 0===n||!1!==this.includeMoveDestinations)&&d(i,null!=n?n:r,n?{key:`_${n}`,value:l?l[n]:void 0}:void 0,!1),void 0!==n||r++,a++)}h&&i(h[0],h[1],h[2],!0)}getDeltaType(t,e){if(void 0===t)return void 0!==e?"movedestination":"unchanged";if(Array.isArray(t)){if(1===t.length)return"added";if(2===t.length)return"modified";if(3===t.length&&0===t[2])return"deleted";if(3===t.length&&2===t[2])return"textdiff";if(3===t.length&&3===t[2])return"moved"}else if("object"==typeof t)return"node";return"unknown"}parseTextDiff(t){var e;const i=[],n=t.split("\n@@ ");for(const t of n){const n={pieces:[]},s=null===(e=/^(?:@@ )?[-+]?(\d+),(\d+)/.exec(t))||void 0===e?void 0:e.slice(1);if(!s)throw new Error("invalid text diff format");gb(s),n.location={line:s[0],chr:s[1]};const o=t.split("\n").slice(1);for(let t=0,e=o.length;t<e;t++){const e=o[t];if(void 0===e||!e.length)continue;const i={type:"context"};"+"===e.substring(0,1)?i.type="added":"-"===e.substring(0,1)&&(i.type="deleted"),i.text=e.slice(1),n.pieces.push(i)}i.push(n)}return i}};class yb extends vb{typeFormattterErrorFormatter(t,e){const i="object"==typeof e&&null!==e&&"message"in e&&"string"==typeof e.message?e.message:String(e);t.out(`<pre class="jsondiffpatch-error">${Ob(i)}</pre>`)}formatValue(t,e){const i=void 0===e?"undefined":Ob(JSON.stringify(e,null,2));t.out(`<pre>${i}</pre>`)}formatTextDiffString(t,e){const i=this.parseTextDiff(e);t.out('<ul class="jsondiffpatch-textdiff">');for(let e=0,n=i.length;e<n;e++){const n=i[e];if(void 0===n)return;t.out(`<li><div class="jsondiffpatch-textdiff-location"><span class="jsondiffpatch-textdiff-line-number">${n.location.line}</span><span class="jsondiffpatch-textdiff-char">${n.location.chr}</span></div><div class="jsondiffpatch-textdiff-line">`);const s=n.pieces;for(let e=0,i=s.length;e<i;e++){const i=s[e];if(void 0===i)return;t.out(`<span class="jsondiffpatch-textdiff-${i.type}">${Ob(decodeURI(i.text))}</span>`)}t.out("</div></li>")}t.out("</ul>")}rootBegin(t,e,i){const n=`jsondiffpatch-${e}${i?` jsondiffpatch-child-node-type-${i}`:""}`;t.out(`<div class="jsondiffpatch-delta ${n}">`)}rootEnd(t){t.out("</div>"+(t.hasArrows?`<script type="text/javascript">setTimeout(${bb.toString()},10);<\/script>`:""))}nodeBegin(t,e,i,n,s){const o=`jsondiffpatch-${n}${s?` jsondiffpatch-child-node-type-${s}`:""}`,r="number"==typeof i&&"_"===e.substring(0,1)?e.substring(1):e;t.out(`<li class="${o}" data-key="${Ob(e)}"><div class="jsondiffpatch-property-name">${Ob(r)}</div>`)}nodeEnd(t){t.out("</li>")}format_unchanged(t,e,i){void 0!==i&&(t.out('<div class="jsondiffpatch-value">'),this.formatValue(t,i),t.out("</div>"))}format_movedestination(t,e,i){void 0!==i&&(t.out('<div class="jsondiffpatch-value">'),this.formatValue(t,i),t.out("</div>"))}format_node(t,e,i){const n="a"===e._t?"array":"object";t.out(`<ul class="jsondiffpatch-node jsondiffpatch-node-type-${n}">`),this.formatDeltaChildren(t,e,i),t.out("</ul>")}format_added(t,e){t.out('<div class="jsondiffpatch-value">'),this.formatValue(t,e[0]),t.out("</div>")}format_modified(t,e){t.out('<div class="jsondiffpatch-value jsondiffpatch-left-value">'),this.formatValue(t,e[0]),t.out('</div><div class="jsondiffpatch-value jsondiffpatch-right-value">'),this.formatValue(t,e[1]),t.out("</div>")}format_deleted(t,e){t.out('<div class="jsondiffpatch-value">'),this.formatValue(t,e[0]),t.out("</div>")}format_moved(t,e){t.out('<div class="jsondiffpatch-value">'),this.formatValue(t,e[0]),t.out(`</div><div class="jsondiffpatch-moved-destination">${e[1]}</div>`),t.out('<div class="jsondiffpatch-arrow" style="position: relative; left: -34px;">\n <svg width="30" height="60" style="position: absolute; display: none;">\n <defs>\n <marker id="markerArrow" markerWidth="8" markerHeight="8"\n refx="2" refy="4" stroke="#88f"\n orient="auto" markerUnits="userSpaceOnUse">\n <path d="M1,1 L1,7 L7,4 L1,1" style="fill: #339;" />\n </marker>\n </defs>\n <path d="M30,0 Q-10,25 26,50"\n style="stroke: #88f; stroke-width: 2px; fill: none; stroke-opacity: 0.5; marker-end: url(#markerArrow);"\n ></path>\n </svg>\n </div>'),t.hasArrows=!0}format_textdiff(t,e){t.out('<div class="jsondiffpatch-value">'),this.formatTextDiffString(t,e[0]),t.out("</div>")}}function Ob(t){if("number"==typeof t)return t;let e=String(t);const i=[[/&/g,"&amp;"],[/</g,"&lt;"],[/>/g,"&gt;"],[/'/g,"&apos;"],[/"/g,"&quot;"]];for(const t of i)e=e.replace(t[0],t[1]);return e}const bb=function(t){const e=t||document;((t,e,i)=>{const n=t.querySelectorAll(e);for(let t=0,e=n.length;t<e;t++)i(n[t])})(e,".jsondiffpatch-arrow",({parentNode:t,children:e,style:i})=>{const n=t,s=e[0],o=s.children[1];s.style.display="none";const r=n.querySelector(".jsondiffpatch-moved-destination");if(!(r instanceof HTMLElement))return;const a=(({textContent:t,innerText:e})=>t||e)(r),l=n.parentNode;if(!l)return;let c;if((({children:t},e)=>{for(let i=0,n=t.length;i<n;i++){const n=t[i];n&&e(n,i)}})(l,t=>{t.getAttribute("data-key")===a&&(c=t)}),c)try{const t=c.offsetTop-n.offsetTop;s.setAttribute("height",`${Math.abs(t)+6}`),i.top=`${-8+(t>0?0:t)}px`;const e=t>0?`M30,0 Q-10,${Math.round(t/2)} 26,${t-4}`:`M30,${-t} Q-10,${Math.round(-t/2)} 26,4`;o.setAttribute("d",e),s.style.display=""}catch(t){console.debug(`[jsondiffpatch] error adjusting arrows: ${t}`)}})},xb=(t,e)=>((t,e,i)=>{const n=e||document.body,s="jsondiffpatch-unchanged-",o={showing:`${s}showing`,hiding:`${s}hiding`,visible:`${s}visible`,hidden:`${s}hidden`},r=n.classList;if(!r)return;if(!i)return r.remove(o.showing),r.remove(o.hiding),r.remove(o.visible),r.remove(o.hidden),void(!1===t&&r.add(o.hidden));!1===t?(r.remove(o.showing),r.add(o.visible),setTimeout(()=>{r.add(o.hiding)},10)):(r.remove(o.hiding),r.add(o.showing),r.remove(o.hidden));const a=setInterval(()=>{bb(n)},100);setTimeout(()=>{r.remove(o.showing),r.remove(o.hiding),!1===t?(r.add(o.hidden),r.remove(o.visible)):(r.add(o.visible),r.remove(o.hidden)),setTimeout(()=>{r.remove(o.visible),clearInterval(a)},i+400)},i)})(!1,t,e);let wb;function _b(t){if("object"!=typeof t)return t;if(null===t)return null;if(Array.isArray(t))return t.map(_b);if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return function(t){var e;const i=/^\/(.*)\/([gimyu]*)$/.exec(t.toString());if(!i)throw new Error("Invalid RegExp");return new RegExp(null!==(e=i[1])&&void 0!==e?e:"",i[2])}(t);const e={};for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=_b(t[i]));return e}class Sb{setResult(t){return this.result=t,this.hasResult=!0,this}exit(){return this.exiting=!0,this}push(t,e){var i;return t.parent=this,void 0!==e&&(t.childName=e),t.root=this.root||this,t.options=t.options||this.options,this.children?(!function(t,e){if(0===t.length)throw new Error(e||"Expected a non-empty array")}(this.children),(i=this.children,i[i.length-1]).next=t,this.children.push(t)):(this.children=[t],this.nextAfterChildren=this.next||null,this.next=t),t.next=this,this}}const kb=class extends Sb{constructor(t,e){super(),this.left=t,this.right=e,this.pipe="diff"}prepareDeltaResult(t){var e,i,n,s;if("object"==typeof t&&((null===(e=this.options)||void 0===e?void 0:e.omitRemovedValues)&&Array.isArray(t)&&t.length>1&&(2===t.length||0===t[2]||3===t[2])&&(t[0]=0),null===(i=this.options)||void 0===i?void 0:i.cloneDiffValues)){const e="function"==typeof(null===(n=this.options)||void 0===n?void 0:n.cloneDiffValues)?null===(s=this.options)||void 0===s?void 0:s.cloneDiffValues:_b;"object"==typeof t[0]&&(t[0]=e(t[0])),"object"==typeof t[1]&&(t[1]=e(t[1]))}return t}setResult(t){return this.prepareDeltaResult(t),super.setResult(t)}};const $b=class extends Sb{constructor(t,e){super(),this.left=t,this.delta=e,this.pipe="patch"}};const Cb=class extends Sb{constructor(t){super(),this.delta=t,this.pipe="reverse"}};const Tb=class{constructor(t){this.name=t,this.filters=[]}process(t){if(!this.processor)throw new Error("add this pipe to a processor before using it");const e=this.debug,i=this.filters.length,n=t;for(let t=0;t<i;t++){const i=this.filters[t];if(i&&(e&&this.log(`filter: ${i.filterName}`),i(n),"object"==typeof n&&n.exiting)){n.exiting=!1;break}}!n.next&&this.resultCheck&&this.resultCheck(n)}log(t){console.log(`[jsondiffpatch] ${this.name} pipe, ${t}`)}append(...t){return this.filters.push(...t),this}prepend(...t){return this.filters.unshift(...t),this}indexOf(t){if(!t)throw new Error("a filter name is required");for(let e=0;e<this.filters.length;e++){const i=this.filters[e];if((null==i?void 0:i.filterName)===t)return e}throw new Error(`filter not found: ${t}`)}list(){return this.filters.map(t=>t.filterName)}after(t,...e){const i=this.indexOf(t);return this.filters.splice(i+1,0,...e),this}before(t,...e){const i=this.indexOf(t);return this.filters.splice(i,0,...e),this}replace(t,...e){const i=this.indexOf(t);return this.filters.splice(i,1,...e),this}remove(t){const e=this.indexOf(t);return this.filters.splice(e,1),this}clear(){return this.filters.length=0,this}shouldHaveResult(t){return!1===t?(this.resultCheck=null,this):(this.resultCheck||(this.resultCheck=t=>{if(!t.hasResult){console.log(t);const e=new Error(`${this.name} failed`);throw e.noResult=!0,e}}),this)}};const Pb=class{constructor(t){this.selfOptions=t||{},this.pipes={}}options(t){return t&&(this.selfOptions=t),this.selfOptions}pipe(t,e){let i=e;if("string"==typeof t){if(void 0===i)return this.pipes[t];this.pipes[t]=i}if(t&&t.name){if(i=t,i.processor===this)return i;this.pipes[i.name]=i}if(!i)throw new Error(`pipe is not defined: ${t}`);return i.processor=this,i}process(t,e){let i=t;i.options=this.options();let n,s=e||t.pipe||"default";for(;s;)void 0!==i.nextAfterChildren&&(i.next=i.nextAfterChildren,i.nextAfterChildren=null),"string"==typeof s&&(s=this.pipe(s)),s.process(i),n=s,s=null,i&&i.next&&(i=i.next,s=i.pipe||n);return i.hasResult?i.result:void 0}},Eb=(t,e,i,n)=>t[i]===e[n],Ab=(t,e,i,n)=>{const s=n||{},o=((t,e,i,n)=>{var s,o,r;const a=t.length,l=e.length;let c,h;const u=new Array(a+1);for(c=0;c<a+1;c++){const t=new Array(l+1);for(h=0;h<l+1;h++)t[h]=0;u[c]=t}for(u.match=i,c=1;c<a+1;c++){const a=u[c];if(void 0===a)throw new Error("LCS matrix row is undefined");const d=u[c-1];if(void 0===d)throw new Error("LCS matrix row is undefined");for(h=1;h<l+1;h++)i(t,e,c-1,h-1,n)?a[h]=(null!==(s=d[h-1])&&void 0!==s?s:0)+1:a[h]=Math.max(null!==(o=d[h])&&void 0!==o?o:0,null!==(r=a[h-1])&&void 0!==r?r:0)}return u})(t,e,i||Eb,s);return((t,e,i,n)=>{let s=e.length,o=i.length;const r={sequence:[],indices1:[],indices2:[]};for(;0!==s&&0!==o;){if(void 0===t.match)throw new Error("LCS matrix match function is undefined");if(t.match(e,i,s-1,o-1,n))r.sequence.unshift(e[s-1]),r.indices1.unshift(s-1),r.indices2.unshift(o-1),--s,--o;else{const e=t[s];if(void 0===e)throw new Error("LCS matrix row is undefined");const i=e[o-1];if(void 0===i)throw new Error("LCS matrix value is undefined");const n=t[s-1];if(void 0===n)throw new Error("LCS matrix row is undefined");const r=n[o];if(void 0===r)throw new Error("LCS matrix value is undefined");i>r?--o:--s}}return r})(o,t,e,s)};function Mb(t,e,i,n,s){const o=t[i],r=e[n];if(o===r)return!0;if("object"!=typeof o||"object"!=typeof r)return!1;const a=s.objectHash;if(!a)return s.matchByPosition&&i===n;s.hashCache1=s.hashCache1||[];let l=s.hashCache1[i];if(void 0===l&&(s.hashCache1[i]=l=a(o,i)),void 0===l)return!1;s.hashCache2=s.hashCache2||[];let c=s.hashCache2[n];return void 0===c&&(s.hashCache2[n]=c=a(r,n)),void 0!==c&&l===c}const Qb=function(t){var e,i,n,s,o;if(!t.leftIsArray)return;const r={objectHash:null===(e=t.options)||void 0===e?void 0:e.objectHash,matchByPosition:null===(i=t.options)||void 0===i?void 0:i.matchByPosition};let a,l,c,h=0,u=0;const d=t.left,f=t.right,p=d.length,m=f.length;let g,v;for(p>0&&m>0&&!r.objectHash&&"boolean"!=typeof r.matchByPosition&&(r.matchByPosition=!function(t,e,i,n){for(let s=0;s<i;s++){const i=t[s];for(let t=0;t<n;t++){const n=e[t];if(s!==t&&i===n)return!0}}return!1}(d,f,p,m));h<p&&h<m&&Mb(d,f,h,h,r);)a=h,g=new kb(d[a],f[a]),t.push(g,a),h++;for(;u+h<p&&u+h<m&&Mb(d,f,p-1-u,m-1-u,r);)l=p-1-u,c=m-1-u,g=new kb(d[l],f[c]),t.push(g,c),u++;if(h+u===p){if(p===m)return void t.setResult(void 0).exit();for(v=v||{_t:"a"},a=h;a<m-u;a++)v[a]=[f[a]],t.prepareDeltaResult(v[a]);return void t.setResult(v).exit()}if(h+u===m){for(v=v||{_t:"a"},a=h;a<p-u;a++){const e=`_${a}`;v[e]=[d[a],0,0],t.prepareDeltaResult(v[e])}return void t.setResult(v).exit()}r.hashCache1=void 0,r.hashCache2=void 0;const y=d.slice(h,p-u),O=f.slice(h,m-u),b=Ab(y,O,Mb,r),x=[];for(v=v||{_t:"a"},a=h;a<p-u;a++)if(b.indices1.indexOf(a-h)<0){const e=`_${a}`;v[e]=[d[a],0,0],t.prepareDeltaResult(v[e]),x.push(a)}let w=!0;(null===(n=t.options)||void 0===n?void 0:n.arrays)&&!1===t.options.arrays.detectMove&&(w=!1);let _=!1;(null===(o=null===(s=t.options)||void 0===s?void 0:s.arrays)||void 0===o?void 0:o.includeValueOnMove)&&(_=!0);const S=x.length;for(a=h;a<m-u;a++){const e=b.indices2.indexOf(a-h);if(e<0){let e=!1;if(w&&S>0)for(let i=0;i<S;i++){l=x[i];const n=void 0===l?void 0:v[`_${l}`];if(void 0!==l&&n&&Mb(y,O,l-h,a-h,r)){n.splice(1,2,a,3),n.splice(1,2,a,3),_||(n[0]=""),c=a,g=new kb(d[l],f[c]),t.push(g,c),x.splice(i,1),e=!0;break}}e||(v[a]=[f[a]],t.prepareDeltaResult(v[a]))}else{if(void 0===b.indices1[e])throw new Error(`Invalid indexOnArray2: ${e}, seq.indices1: ${b.indices1}`);if(l=b.indices1[e]+h,void 0===b.indices2[e])throw new Error(`Invalid indexOnArray2: ${e}, seq.indices2: ${b.indices2}`);c=b.indices2[e]+h,g=new kb(d[l],f[c]),t.push(g,c)}}t.setResult(v).exit()};Qb.filterName="arrays";const Db={numerically:(t,e)=>t-e,numericallyBy:t=>(e,i)=>e[t]-i[t]},Rb=function(t){var e;if(!t.nested)return;const i=t.delta;if("a"!==i._t)return;let n,s;const o=i,r=t.left;let a=[],l=[];const c=[];for(n in o)if("_t"!==n)if("_"===n[0]){const t=n;if(void 0===o[t]||0!==o[t][2]&&3!==o[t][2])throw new Error(`only removal or move can be applied at original array indices, invalid diff type: ${null===(e=o[t])||void 0===e?void 0:e[2]}`);a.push(Number.parseInt(n.slice(1),10))}else{const t=n;1===o[t].length?l.push({index:Number.parseInt(t,10),value:o[t][0]}):c.push({index:Number.parseInt(t,10),delta:o[t]})}for(a=a.sort(Db.numerically),n=a.length-1;n>=0;n--){if(s=a[n],void 0===s)continue;const t=o[`_${s}`],e=r.splice(s,1)[0];3===(null==t?void 0:t[2])&&l.push({index:t[1],value:e})}l=l.sort(Db.numericallyBy("index"));const h=l.length;for(n=0;n<h;n++){const t=l[n];void 0!==t&&r.splice(t.index,0,t.value)}const u=c.length;if(u>0)for(n=0;n<u;n++){const e=c[n];if(void 0===e)continue;const i=new $b(r[e.index],e.delta);t.push(i,e.index)}t.children?t.exit():t.setResult(r).exit()};Rb.filterName="arrays";const Ib=function(t){if(!t||!t.children)return;if("a"!==t.delta._t)return;const e=t.left,i=t.children.length;for(let n=0;n<i;n++){const i=t.children[n];if(void 0===i)continue;e[i.childName]=i.result}t.setResult(e).exit()};Ib.filterName="arraysCollectChildren";const Lb=function(t){if(!t.nested){const e=t.delta;if(3===e[2]){const i=e;t.newName=`_${i[1]}`,t.setResult([i[0],Number.parseInt(t.childName.substring(1),10),3]).exit()}return}const e=t.delta;if("a"!==e._t)return;const i=e;for(const e in i){if("_t"===e)continue;const n=new Cb(i[e]);t.push(n,e)}t.exit()};Lb.filterName="arrays";const Nb=(t,e,i)=>{if("string"==typeof e&&"_"===e[0])return Number.parseInt(e.substring(1),10);if(Array.isArray(i)&&0===i[2])return`_${e}`;let n=+e;for(const i in t){const s=t[i];if(Array.isArray(s))if(3===s[2]){const t=Number.parseInt(i.substring(1),10),o=s[1];if(o===+e)return t;t<=n&&o>n?n++:t>=n&&o<n&&n--}else if(0===s[2]){Number.parseInt(i.substring(1),10)<=n&&n++}else 1===s.length&&Number.parseInt(i,10)<=n&&n--}return n},jb=t=>{if(!t||!t.children)return;const e=t.delta;if("a"!==e._t)return;const i=e,n=t.children.length,s={_t:"a"};for(let e=0;e<n;e++){const n=t.children[e];if(void 0===n)continue;let o=n.newName;if(void 0===o){if(void 0===n.childName)throw new Error("child.childName is undefined");o=Nb(i,n.childName,n.result)}s[o]!==n.result&&(s[o]=n.result)}t.setResult(s).exit()};jb.filterName="arraysCollectChildren";const zb=function(t){t.left instanceof Date?(t.right instanceof Date?t.left.getTime()!==t.right.getTime()?t.setResult([t.left,t.right]):t.setResult(void 0):t.setResult([t.left,t.right]),t.exit()):t.right instanceof Date&&t.setResult([t.left,t.right]).exit()};zb.filterName="dates";const Bb=t=>{if(!t||!t.children)return;const e=t.children.length;let i=t.result;for(let n=0;n<e;n++){const e=t.children[n];if(void 0!==e&&void 0!==e.result){if(i=i||{},void 0===e.childName)throw new Error("diff child.childName is undefined");i[e.childName]=e.result}}i&&t.leftIsArray&&(i._t="a"),t.setResult(i).exit()};Bb.filterName="collectChildren";const qb=t=>{var e;if(t.leftIsArray||"object"!==t.leftType)return;const i=t.left,n=t.right,s=null===(e=t.options)||void 0===e?void 0:e.propertyFilter;for(const e in i){if(!Object.prototype.hasOwnProperty.call(i,e))continue;if(s&&!s(e,t))continue;const o=new kb(i[e],n[e]);t.push(o,e)}for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)&&(!s||s(e,t))&&void 0===i[e]){const i=new kb(void 0,n[e]);t.push(i,e)}t.children&&0!==t.children.length?t.exit():t.setResult(void 0).exit()};qb.filterName="objects";const Zb=function(t){if(!t.nested)return;const e=t.delta;if(e._t)return;const i=e;for(const e in i){const n=new $b(t.left[e],i[e]);t.push(n,e)}t.exit()};Zb.filterName="objects";const Fb=function(t){if(!t||!t.children)return;if(t.delta._t)return;const e=t.left,i=t.children.length;for(let n=0;n<i;n++){const i=t.children[n];if(void 0===i)continue;const s=i.childName;Object.prototype.hasOwnProperty.call(t.left,s)&&void 0===i.result?delete e[s]:e[s]!==i.result&&(e[s]=i.result)}t.setResult(e).exit()};Fb.filterName="collectChildren";const Xb=function(t){if(!t.nested)return;if(t.delta._t)return;const e=t.delta;for(const i in e){const n=new Cb(e[i]);t.push(n,i)}t.exit()};Xb.filterName="objects";const Hb=t=>{if(!t||!t.children)return;if(t.delta._t)return;const e=t.children.length,i={};for(let n=0;n<e;n++){const e=t.children[n];if(void 0===e)continue;const s=e.childName;i[s]!==e.result&&(i[s]=e.result)}t.setResult(i).exit()};Hb.filterName="collectChildren";let Wb=null;function Vb(t,e){var i;if(!Wb){let n;if(!(null===(i=null==t?void 0:t.textDiff)||void 0===i?void 0:i.diffMatchPatch)){if(!e)return null;const t=new Error("The diff-match-patch library was not provided. Pass the library in through the options or use the `jsondiffpatch/with-text-diffs` entry-point.");throw t.diff_match_patch_not_found=!0,t}n=new t.textDiff.diffMatchPatch,Wb={diff:(t,e)=>n.patch_toText(n.patch_make(t,e)),patch:(t,e)=>{const i=n.patch_apply(n.patch_fromText(e),t);for(const t of i[1])if(!t){const t=new Error("text patch failed");throw t.textPatchFailed=!0,t}return i[0]}}}return Wb}const Yb=function(t){var e,i;if("string"!==t.leftType)return;const n=t.left,s=t.right,o=(null===(i=null===(e=t.options)||void 0===e?void 0:e.textDiff)||void 0===i?void 0:i.minLength)||60;if(n.length<o||s.length<o)return void t.setResult([n,s]).exit();const r=Vb(t.options);if(!r)return void t.setResult([n,s]).exit();const a=r.diff;t.setResult([a(n,s),0,2]).exit()};Yb.filterName="texts";const Ub=function(t){if(t.nested)return;const e=t.delta;if(2!==e[2])return;const i=e,n=Vb(t.options,!0).patch;t.setResult(n(t.left,i[0])).exit()};Ub.filterName="texts";const Gb=t=>{var e,i,n;const s=/^@@ +-(\d+),(\d+) +\+(\d+),(\d+) +@@$/,o=t.split("\n");for(let t=0;t<o.length;t++){const r=o[t];if(void 0===r)continue;const a=r.slice(0,1);if("@"===a){const e=s.exec(r);if(null!==e){o[t]=`@@ -${e[3]},${e[4]} +${e[1]},${e[2]} @@`}}else if("+"===a){if(o[t]=`-${null===(e=o[t])||void 0===e?void 0:e.slice(1)}`,"+"===(null===(i=o[t-1])||void 0===i?void 0:i.slice(0,1))){const e=o[t];o[t]=o[t-1],o[t-1]=e}}else"-"===a&&(o[t]=`+${null===(n=o[t])||void 0===n?void 0:n.slice(1)}`)}return o.join("\n")},Kb=function(t){if(t.nested)return;const e=t.delta;if(2!==e[2])return;const i=e;t.setResult([Gb(i[0]),0,2]).exit()};Kb.filterName="texts";const Jb=function(t){if(t.left!==t.right)if(void 0!==t.left)if(void 0!==t.right){if("function"==typeof t.left||"function"==typeof t.right)throw new Error("functions are not supported");t.leftType=null===t.left?"null":typeof t.left,t.rightType=null===t.right?"null":typeof t.right,t.leftType===t.rightType&&"boolean"!==t.leftType&&"number"!==t.leftType?("object"===t.leftType&&(t.leftIsArray=Array.isArray(t.left)),"object"===t.rightType&&(t.rightIsArray=Array.isArray(t.right)),t.leftIsArray===t.rightIsArray?t.left instanceof RegExp&&(t.right instanceof RegExp?t.setResult([t.left.toString(),t.right.toString()]).exit():t.setResult([t.left,t.right]).exit()):t.setResult([t.left,t.right]).exit()):t.setResult([t.left,t.right]).exit()}else t.setResult([t.left,0,0]).exit();else{if("function"==typeof t.right)throw new Error("functions are not supported");t.setResult([t.right]).exit()}else t.setResult(void 0).exit()};Jb.filterName="trivial";const tx=function(t){if(void 0===t.delta)return void t.setResult(t.left).exit();if(t.nested=!Array.isArray(t.delta),t.nested)return;const e=t.delta;if(1!==e.length)if(2!==e.length)3===e.length&&0===e[2]&&t.setResult(void 0).exit();else{if(t.left instanceof RegExp){const i=/^\/(.*)\/([gimyu]+)$/.exec(e[1]);if(null==i?void 0:i[1])return void t.setResult(new RegExp(i[1],i[2])).exit()}t.setResult(e[1]).exit()}else t.setResult(e[0]).exit()};tx.filterName="trivial";const ex=function(t){if(void 0===t.delta)return void t.setResult(t.delta).exit();if(t.nested=!Array.isArray(t.delta),t.nested)return;const e=t.delta;1!==e.length?2!==e.length?3===e.length&&0===e[2]&&t.setResult([e[0]]).exit():t.setResult([e[1],e[0]]).exit():t.setResult([e[0],0,0]).exit()};ex.filterName="trivial";const ix=class{constructor(t){this.processor=new Pb(t),this.processor.pipe(new Tb("diff").append(Bb,Jb,zb,Yb,qb,Qb).shouldHaveResult()),this.processor.pipe(new Tb("patch").append(Fb,Ib,tx,Ub,Zb,Rb).shouldHaveResult()),this.processor.pipe(new Tb("reverse").append(Hb,jb,ex,Kb,Xb,Lb).shouldHaveResult())}options(t){return this.processor.options(t)}diff(t,e){return this.processor.process(new kb(t,e))}patch(t,e){return this.processor.process(new $b(t,e))}reverse(t){return this.processor.process(new Cb(t))}unpatch(t,e){return this.patch(t,this.reverse(e))}clone(t){return _b(t)}};let nx;function sx(t,e){return nx||(nx=new ix),nx.diff(t,e)}const ox=new ix({objectHash:(t,e)=>t.id||`$$index:${e}`});function rx(t,e){return function(t,e){return wb||(wb=new yb),wb.format(t,e)}(ox.diff(t,e),t)}class ax extends u{constructor(t,e,i,n,s,o){super("Save Configurations",function(t){const{url:e,filename:i,diff:n}=t;return`\n<div class="textae-editor__save-dialog__container">\n <div class="textae-editor__save-dialog__row">\n <label>URL</label>\n <input\n type="text" value="${e}"\n class="textae-editor__save-dialog__url-text">\n <input\n type="button"\n class="textae-editor__save-dialog__url-button"\n ${e?"":'disabled="disabled"'}\n value="Save">\n </div>\n <div class="textae-editor__save-dialog__row">\n <label>Local</label>\n <input\n type="text" value="${i||""}"\n >\n <a class="textae-editor__save-dialog__download-link" href="#">Download</a>\n </div>\n <div class="textae-editor__save-dialog__row">\n <div class="textae-editor__save-dialog__diff-title">\n Configuration differences\n <span class="textae-editor__save-dialog__diff-add-legend">added</span>\n <span class="textae-editor__save-dialog__diff-remove-legend">removed</span>\n </div>\n <div class="textae-editor__save-dialog__diff-viewer">${n}</div>\n </div>\n</div>\n`}({filename:i,url:e,diff:rx(n,s)||"nothing."}),{maxWidth:550}),this._$dialog.on("dialogopen",()=>xb()),function(t,e,i,n,s){r()(e,".textae-editor__save-dialog__url-text","input",t=>{wn(t.target.nextElementSibling,t.target.value)}),r()(e,".textae-editor__save-dialog__url-text","keyup",t=>{13===t.keyCode&&(s(t.target.value),n())}),r()(e,".textae-editor__save-dialog__url-button","click",t=>{s(t.target.previousElementSibling.value),n()}),r()(e,".textae-editor__save-dialog__download-link","click",e=>{const s=e.target,o=GO(i);s.setAttribute("href",o),s.setAttribute("download",s.previousElementSibling.value),t.emit("textae-event.resource.configuration.save",i),n()})}(t,super.el,s,()=>super.close(),o)}}async function lx(t){return new Promise(e=>{const i=new FileReader;i.onload=t=>e(t),i.readAsText(t)})}var cx=i(7975),hx=i.n(cx);const ux=Object.freeze({QUERY_PARAMETER:"parameter",INLINE:"inline",REMOTE_URL:"remote",INSTANT:"instant",LOCAL_FILE:"local file",UNKNOWN:"unknown"});class dx{#Ui;#H;#Gi;static createURLSource(t,e){return console.assert("string"==typeof t,"id must be a string when type is url."),new dx(ux.REMOTE_URL,t,e)}static createFileSource(t,e){return console.assert("string"==typeof t,"id must be a string when type is local file."),new dx(ux.LOCAL_FILE,t,e)}static createInstantSource(t){return new dx(ux.INSTANT,null,t)}static createInlineSource(t){return new dx(ux.INLINE,null,t)}static createParameterSource(t){return new dx(ux.QUERY_PARAMETER,null,t)}constructor(t,e,i){console.assert(Object.values(ux).includes(t),`type must be a member of RESOURCE_TYPE. type: ${t}`),t===ux.REMOTE_URL||t===ux.LOCAL_FILE?console.assert("string"==typeof e,"id must be a string when type is url or local file."):console.assert(null===e,"id must be null when type is not url."),this.#Ui=t,this.#H=e,this.#Gi=i}get resourceType(){return this.#Ui}get id(){return this.#H}get data(){return this.#Gi}get displayName(){switch(this.#Ui){case ux.REMOTE_URL:return new URL(this.#H,location.href).href;case ux.LOCAL_FILE:return`${this.#H}(local file)`;default:return`${this.#Ui}`}}}async function fx(t,i){const n=(await lx(t)).target.result;if(s=t.name,".txt"===hx().extname(s)){const s=function(t){try{return ub.parse(t)}catch{return null}}(n);if(!s){const i=dx.createFileSource(t.name);return void e().error(`Failed to load annotation from ${i.displayName}.`)}if(s.text)return void i.emit("textae-event.resource.annotation.load.success",dx.createFileSource(t.name,s))}var s;if(_n(n)){const e=JSON.parse(n);if(e.text)return void i.emit("textae-event.resource.annotation.load.success",dx.createFileSource(t.name,e))}i.emit("textae-event.resource.annotation.format.error",dx.createFileSource(t.name))}function px(t,e){return!!e.text&&(t.emit("textae-event.resource.annotation.load.success",dx.createInstantSource(e)),!0)}class mx{#Ki;#Ji;constructor(t){t.on("textae-event.original-data.annotation.reset",t=>{t.resourceType===ux.REMOTE_URL&&(this.#Ki=t.id)}).on("textae-event.original-data.configuration.reset",t=>{t.resourceType===ux.REMOTE_URL&&(this.#Ji=t.id)})}get annotation(){return this.#Ki||""}get configuration(){return this.#Ji||""}}class gx{#Ki;#Ji;constructor(t){t.on("textae-event.original-data.annotation.reset",t=>{t.resourceType===ux.LOCAL_FILE&&(this.#Ki=t.id)}).on("textae-event.original-data.configuration.reset",t=>{t.resourceType===ux.LOCAL_FILE&&(this.#Ji=t.id)})}get annotation(){return this.#Ki}get configuration(){return this.#Ji}}class vx{#Nt;#tn;#Ht;#en;#in;#nn;#sn;#ii;#on;#rn;constructor(t,e,i,n,s,o,r,a){this.#Nt=t,this.#tn=e,this.#Ht=i,this.#en=n,this.#in=s,this.#nn=o,this.#sn=r,this.#ii=a,this.#on=new mx(t),this.#rn=new gx(t),t.on("textae-event.pallet.import-button.click",()=>this.importConfiguration()).on("textae-event.pallet.upload-button.click",()=>this.uploadConfiguration())}importAnnotation(){new YO("Load Annotations",this.#on.annotation,t=>this.#tn.loadAnnotation(t),t=>fx(t,this.#Nt),(t,i)=>function(t,i,n){if("json"===n)_n(i)?px(t,JSON.parse(i)):t.emit("textae-event.resource.annotation.format.error",dx.createInstantSource());else if("inline"===n)try{px(t,ub.parse(i))}catch{const t=dx.createInstantSource();e().error(`Failed to load annotation from ${t.displayName}.`)}}(this.#Nt,t,i),this.#sn.hasChange).open()}uploadAnnotation(){const t=this.#nn||this.#on.annotation||"https://pubannotatoin.org/annotations.json";new mb(this.#Nt,t,this.#rn.annotation,this.#an,(t,e)=>this.#tn.saveAnnotation(t,this.#an,e)).open()}saveAnnotation(){this.#tn.saveAnnotation(this.#nn||this.#on.annotation,this.#an,"json")}importConfiguration(){new UO("Load Configurations",this.#on.configuration,t=>this.#tn.loadConfiguration(t),t=>function(t,e){lx(t).then(({target:i})=>{_n(i.result)?e.emit("textae-event.resource.configuration.load.success",dx.createFileSource(t.name,JSON.parse(i.result))):e.emit("textae-event.resource.configuration.format.error",dx.createFileSource(t.name))})}(t,this.#Nt),t=>{_n(t)?this.#Nt.emit("textae-event.resource.configuration.load.success",dx.createInstantSource(JSON.parse(t))):this.#Nt.emit("textae-event.resource.configuration.format.error",dx.createInstantSource())},this.#ii.diffOfConfiguration).open()}uploadConfiguration(){const t={...this.#in(),...this.#Ht.typeDictionary.config};new ax(this.#Nt,this.#on.configuration,this.#rn.configuration,this.#in(),t,e=>this.#tn.saveConfiguration(e,t)).open()}get#an(){const t={...this.#en(),...this.#Ht.externalFormat,config:this.#Ht.typeDictionary.config};return delete t.tracks,t}}function yx(t,e,i,n,s,o){e.setPushButtons(t),i.set(t),n.reset(s,t),o.availability=t["function availability"]}function Ox(t){if(!0===t)return"flag";if("number"==typeof t)return"numeric";if("string"==typeof t)return"string";throw`${JSON.stringify(t)} is an unexpected value for an Attribute.`}function bx(t){const e=t.reduce((t,e)=>t.has(e)?t.set(e,t.get(e)+1):t.set(e,1),new Map),i=Math.max(...e.values());for(const[t,n]of e.entries())if(n===i)return t}function xx(t){const e=Math.max(...t.map(t=>{const[e,i]=String(t).split(".");return i?i.length:0}));return Number(Array.from(Array(e)).reduce((t,e)=>.1*t,1).toFixed(e))}class wx{constructor({pred:t,obj:e}){this._pred=t,this._objects=[e]}push(t){this._objects.push(t)}get definition(){switch(Ox(this._objects[0])){case"flag":return this._prototype;case"numeric":return this._numericAttribute;case"string":return this._stringAttribute;default:throw new Error(`prototype: ${JSON.stringify(this._prototype)}`)}}get mostFrequentObject(){return bx(this._objects)}get _prototype(){return{pred:this._pred,"value type":Ox(this._objects[0])}}get _numericAttribute(){return{min:Math.min(...this._objects),max:Math.max(...this._objects),step:xx(this._objects),default:bx(this._objects),...this._prototype}}get _stringAttribute(){return{default:bx(this._objects),...this._prototype}}}function _x(t){return t.reduce((t,e)=>(t.has(e.pred)?t.get(e.pred).push(e.obj):t.set(e.pred,new wx(e)),t),new Map)}function Sx(t,e){const i=function(t){return[..._x(t).values()].map(t=>t.definition)}(e);return function(t,e){for(const i of e){const e=t.findIndex(t=>t.pred===i.pred);-1!==e?t[e]={...i,...t[e]}:t.push(i)}return t}(t,i)}function kx(t){return t?JSON.parse(JSON.stringify(t)):{}}class $x{constructor(t=[],e=[]){this._annotations=e,this._config=t}get configuration(){let t=Sx(this._config,this._annotations);return t=function(t){t=kx(t);for(const e of t.filter(t=>"numeric"===t["value type"]))Object.prototype.hasOwnProperty.call(e,"default")||(e.default=0),Object.prototype.hasOwnProperty.call(e,"step")||(e.step=2);return t}(t),t=function(t,e){t=kx(t);const i=_x(e);for(const e of function(t){return t.filter(t=>"selection"===t["value type"])}(t))if(e.values&&0!==e.values.length)if(e.values.find(t=>!0===t.default));else if(i.has(e.pred)){const t=i.get(e.pred);e.values.find(e=>e.id===t.mostFrequentObject).default=!0}else e.values[0].default=!0;else e.values=[{id:"default",default:!0}];return t}(t,this._annotations),t}}function Cx(t,e){if(console.assert(t),(e=kx(e))["attribute types"]=new $x(e["attribute types"],t.attributes).configuration,t.tracks)for(const i of t.tracks)e["attribute types"]=new $x(e["attribute types"],i.attributes).configuration;return e}const Tx=new(on())({verbose:!0});an()(Tx,["uri-reference","regex"]);const Px=Tx.compile(ln);function Ex(t){return console.assert(t,"config is required."),Px(t)?null:(console.warn(Px.errors),function(t){for(const e of t){if("required"===e.keyword)return`Invalid configuration: The attribute type whose predicate is '${e.data.pred}' misses a mandatory property, '${e.params.missingProperty}'.`;if(e.instancePath.includes("color"))return ot`Invalid configuration: '${e.data}' is invalid color format.`}}(Px.errors))}function Ax(t,i){const n=function(t,e){if(console.assert(e,"If you don't have a configuration, generate a configuration from the annotation."),t.attributes){const i=e["attribute types"],n=t.attributes.filter(t=>i.some(e=>e.pred===t.pred&&"selection"===e["value type"])).filter(t=>!i.some(e=>e.pred===t.pred&&e.values.some(e=>e.id===t.obj)));if(n.length)return console.warn("selection attribute values without definition",n),`selection attribute value definition for "${n.map(t=>t.obj).join(", ")}" in configuration is missing. `}}(t,i);if(!n)return i;e().error(n)}function Mx(t,i){const n=Cx(t,i),s=Ex(n);if(!s)return Ax(t,n);e().error(s)}function Qx(t){(function(t){if(t.denotations)for(const e of t.denotations){if(e.span.begin!==parseInt(e.span.begin))return!0;if(e.span.end!==parseInt(e.span.end))return!0}})(t)&&e().warning("In the annotation file, some of the begin and end offsets of denotations were not integer values.\n TextAE converted them to integer values.\n However, to avoid a chance of unexpected rendering, please fix them.",15)}function Dx(t,i,n,s,o,r,a,l){if(!t.data.config&&i)n.loadConfiguration(i,t);else{if(Qx(t.data),t.data.config&&"object"!=typeof t.data.config)return void e().error("configuration in annotation file is invalid.");const i=Mx(t.data,t.data.config);i&&(yx(i,s,o,r,t.data,a),l.annotation=t)}}const Rx='\n<div class="textae-editor__footer">\n <div class="textae-editor__footer__message"></div>\n</div>\n';class Ix{#Q;#ln;constructor(t,e){this.#Q=t,this.#ln=e}set status(t){var e;this.#ln&&(""!==t&&((e=this.#Q,e.querySelector(".textae-editor__footer__message")||(e.insertAdjacentHTML("beforeend",Rx.replace(/[\n\r]+/g,"")),e.querySelector(".textae-editor__footer__message"))).innerHTML=at(t)?`Source: <a class="textae-editor__footer__message__link" href="${t}">${decodeURI(t)}</a>`:`Source: ${t}`))}}class Lx{#Nt;#cn;#Ki;#Ji;constructor(t,e,i){this.#Nt=t,this.#cn=new Ix(e,i),t.on("textae-event.resource.annotation.save",t=>{this.#hn=t}).on("textae-event.resource.configuration.save",t=>{this.#Ji=t})}get defaultAnnotation(){return{text:"Currently, the document is empty. Use the `import` button or press the key `i` to open a document with annotation."}}get defaultConfiguration(){return Cx(this.defaultAnnotation)}get annotation(){return this.#Ki?this.#Ki:this.defaultAnnotation}set annotation(t){this.#hn=t.data,this.#cn.status=t.displayName,this.#Nt.emit("textae-event.original-data.annotation.reset",t)}get configuration(){return this.#Ji?this.#Ji:{}}set configuration(t){this.#Ji=t.data,this.#Nt.emit("textae-event.original-data.configuration.reset",t)}set#hn(t){this.#Ki=t,t.config&&(this.#Ji=t.config)}}const Nx=[{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"import",title:"Import [I]"},{type:"upload",title:"Upload [U]"},{type:"upload automatically",title:"Upload Automatically",push:!0}]},{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"view mode",title:"View Mode",push:!0},{type:"term edit mode",title:"Term Edit Mode",push:!0},{type:"block edit mode",title:"Block Edit Mode",push:!0},{type:"relation edit mode",title:"Relation Edit Mode",push:!0},{type:"text edit mode",title:"Text Edit Mode",push:!0}]},{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"simple view",title:"Simple View",push:!0},{type:"adjust lineheight",title:"Adjust LineHeight"},{type:"auto adjust lineheight",title:"Auto Adjust LineHeight",push:!0}]},{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"undo",title:"Undo [Z]"},{type:"redo",title:"Redo [A]"}]},{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"replicate span annotation",title:"Replicate span annotation [R]",enableWhenSelecting:t=>t.span.single&&t.span.single.isDenotation},{type:"auto replicate",title:"Auto replicate",push:!0},{type:"boundary detection",title:"Boundary Detection [B]",push:!0}]},{usage:{"keyboard device":[],"touch device":["control bar","context menu"]},list:[{type:"create span by touch",title:"Create span",availableModes:[vn,yn]},{type:"expand span by touch",title:"Expand span",availableModes:[vn,yn]},{type:"shrink span by touch",title:"Shrink span",availableModes:[vn,yn]},{type:"edit text by touch",title:"Edit text",availableModes:[bn]}]},{usage:{"keyboard device":["control bar","context menu"],"touch device":["control bar"]},list:[{type:"new entity",title:"New entity [E]",enableWhenSelecting:t=>t.span.contains(t=>t.isDenotation)},{type:"pallet"},{type:"edit properties",title:"Edit Properties [W]",enableWhenSelecting:t=>t.entity.some||t.relation.some},{type:"delete",title:"Delete [D]",enableWhenSelecting:t=>t.span.some||t.entity.some||t.relation.some}]},{usage:{"keyboard device":[],"touch device":["control bar"]},list:[{type:"copy",title:"Copy [C]",enableWhenSelecting:t=>t.span.contains(t=>t.isDenotation)||t.entity.contains(t=>t.isDenotation)},{type:"cut",title:"Cut [X]",enableWhenSelecting:t=>t.span.contains(t=>t.isDenotation)||t.entity.contains(t=>t.isDenotation)},{type:"paste",title:"Paste [V]",enableWhenSelecting:(t,e)=>e.hasCopyingItem&&t.span.some||e.hasCuttingItem&&Boolean(t.span.single)}]},{usage:{"keyboard device":["control bar"],"touch device":["control bar"]},list:[{type:"setting",title:"Setting"}]},{usage:{"keyboard device":["control bar"],"touch device":[]},list:[{type:"help",title:"Help [H]"}]}];function jx(){return/Android/.test(navigator.userAgent)}class zx{#un;#dn;constructor(t,e){this.#un=t,this.#dn=e}isShowOnControlBar(){return jx()||/iPad/.test(navigator.userAgent)||/iPhone/.test(navigator.userAgent)||/Macintosh/.test(navigator.userAgent)&&q()?this.#un["touch device"].includes("control bar"):this.#un["keyboard device"].includes("control bar")}isShowOnContextMenu(){return q()?this.#un["touch device"].includes("context menu"):this.#un["keyboard device"].includes("context menu")}getButtonsFor(t){const e=this.#dn.filter(({availableModes:e})=>e.includes(t));return new zx(this.#un,e)}get buttonList(){return this.#dn}get displayProperties(){return{list:this.#dn.map(t=>t.displayProperties)}}}class Bx{#Ui;#ot;#fn=!1;#pn=null;#mn=[gn,vn,yn,On,bn];constructor(t,e,i=!1,n=null,s=null){this.#Ui=t,this.#ot=e,this.#fn=i,n&&(this.#pn=n),s&&(this.#mn=s)}get displayProperties(){return{type:this.#Ui,title:this.#ot}}get type(){return this.#Ui}get push(){return this.#fn}get enableWhenSelecting(){return this.#pn}get availableModes(){return this.#mn}}class qx{#gn;constructor(){this.#gn=Nx.map(({usage:t,list:e})=>new zx(t,e.map(({type:t,title:e,push:i,enableWhenSelecting:n,availableModes:s})=>new Bx(t,e,i,n,s))))}get controlBar(){return this.#gn.filter(t=>t.isShowOnControlBar()).map(t=>t.displayProperties)}getContextMenuFor(t){return this.#gn.filter(t=>t.isShowOnContextMenu()).map(e=>e.getButtonsFor(t)).map(t=>t.displayProperties)}get pasteButton(){return this.#dn.find(({type:t})=>"paste"===t)}get enableButtonsWhenSelecting(){return this.#dn.filter(t=>t.enableWhenSelecting)}get pushButtons(){return this.#dn.filter(t=>t.push).map(t=>t.type)}get#dn(){return this.#gn.flatMap(t=>t.buttonList)}}class Zx{#l;#Nt;#vn;constructor(t,e=null){this.#l=t,this.#Nt=e,this.#vn=!1}get name(){return this.#l}get isPushed(){return this.#vn}set isPushed(t){this.#vn=t,this.#yn()}toggle(){this.#vn=!this.#vn,this.#yn()}#yn(){this.#Nt&&this.#Nt.emit("textae-event.control.button.push",this)}}class Fx{#On;constructor(t){this.#On=(new qx).pushButtons.reduce((e,i)=>(e.set(i,new Zx(i,t)),e),new Map),t.on("textae-event.edit-mode.transition",(t,e)=>this.#bn(t,!e))}get(t){return this.#On.has(t)?this.#On.get(t):new Zx(t)}get names(){return this.#On.keys()}#bn(t,e){switch(t){case gn:this.#xn(!0,!1,!1,!1,!1,e);break;case vn:this.#xn(!1,!0,!1,!1,!1,e);break;case yn:this.#xn(!1,!1,!0,!1,!1,e);break;case On:this.#xn(!1,!1,!1,!0,!1,!1);break;case bn:this.#xn(!1,!1,!1,!1,!0,e);break;default:throw`unknown edit mode!${t}`}}#xn(t,e,i,n,s,o){this.#On.get("view mode").isPushed=t,this.#On.get("term edit mode").isPushed=e,this.#On.get("block edit mode").isPushed=i,this.#On.get("relation edit mode").isPushed=n,this.#On.get("text edit mode").isPushed=s,this.#On.get("simple view").isPushed=o}}class Xx{#wn;#Nt;#Ie;#oi;constructor(t,e,i){this.#wn=new Map([["import",!0],["upload",!0],["view mode",!0],["term edit mode",!0],["block edit mode",!0],["relation edit mode",!0],["text edit mode",!0],["simple view",!0],["setting",!0],["help",!0]]),this.#Nt=t,this.#Ie=e,this.#oi=i,t.on("textae-event.history.change",t=>{this.enable("undo",t.hasAnythingToUndo),this.enable("redo",t.hasAnythingToRedo)}).on("textae-event.selection.span.change",()=>this.#_n()).on("textae-event.selection.relation.change",()=>this.#_n()).on("textae-event.selection.entity.change",()=>this.#_n()).on("textae-event.edit-mode.transition",t=>this.#Sn(t)).on("textae-event.clip-board.change",()=>this.#kn()).on("textae-event.annotation-auto-saver.enable",t=>this.enable("upload automatically",t))}get(t){return this.#wn.get(t)}enable(t,e){this.#wn.set(t,e),this.#yn()}updateButtonsToOperateSpanWithTouchDevice(t,e,i,n){this.#wn.set("create span by touch",t),this.#wn.set("expand span by touch",e),this.#wn.set("shrink span by touch",i),this.#wn.set("edit text by touch",n),this.#yn()}#_n(){for(const{type:t,enableWhenSelecting:e}of(new qx).enableButtonsWhenSelecting)this.enable(t,e(this.#Ie,this.#oi));this.#yn()}#kn(){this.enable("paste",(new qx).pasteButton.enableWhenSelecting(this.#Ie,this.#oi))}#yn(){this.#Nt.emit("textae-event.control.buttons.change",this.#wn.keys())}#Sn(t){switch(t){case gn:this.#$n(!0,!1,!1,!1,!1,!1,!1);break;case vn:this.#$n(!0,!0,!0,!0,!0,!0,!0);break;case yn:this.#$n(!0,!1,!0,!0,!0,!0,!0);break;case On:this.#$n(!1,!1,!1,!0,!0,!1,!0);break;case bn:this.#$n(!0,!1,!0,!0,!0,!1,!1);break;default:throw`unknown edit mode!${t}`}this.#yn()}#$n(t,e,i,n,s,o,r){this.#wn.set("simple view",t),this.#wn.set("auto replicate",e),this.#wn.set("boundary detection",i),this.#wn.set("adjust lineheight",n),this.#wn.set("auto adjust lineheight",s),this.#wn.set("create span by touch",o),this.#wn.set("expand span by touch",o),this.#wn.set("shrink span by touch",o),this.#wn.set("pallet",r)}}function Hx(t,e,i,n,s){for(;s(t(i,n));)n+=e;return n}const Wx=function(t,e){return t.charAt(e)},Vx=function(t,e,i){return Hx(Wx,1,t,e,i)},Yx=function(t,e,i){return Hx(Wx,-1,t,e,i)};class Ux{backFromBegin(t,e,i){}forwardFromEnd(t,e,i){}forwardFromBegin(t,e,i){}backFromEnd(t,e,i){}}function Gx(t,e){return[t.charAt(e),t.charAt(e-1)]}function Kx(t,e){return[t.charAt(e),t.charAt(e+1)]}function Jx(t,e,i){return""!==i[0]&&!t(i[1])&&!e(i[1])||e(i[0])}class tw extends Ux{backFromBegin(t,e,i){const n=function(t,e,i){return Hx(Gx,-1,t,e,t=>t[1]&&!i(t[0])&&!i(t[1]))}(t,Vx(t,e,t=>i.isBlankCharacter(t)),t=>i.isDelimiter(t));return n}forwardFromEnd(t,e,i){const n=function(t,e,i){return Hx(Kx,1,t,e,t=>t[1]&&!i(t[0])&&!i(t[1]))}(t,Yx(t,e,t=>i.isBlankCharacter(t)),t=>i.isDelimiter(t));return n}forwardFromBegin(t,e,i){return function(t,e,i){return Hx(Gx,1,t,e,i)}(t,e,t=>Jx(t=>i.isBlankCharacter(t),t=>i.isDelimiter(t),t))}backFromEnd(t,e,i){return function(t,e,i){return Hx(Kx,-1,t,e,i)}(t,e,t=>Jx(t=>i.isBlankCharacter(t),t=>i.isDelimiter(t),t))}}class ew extends Ux{backFromBegin(t,e,i){return Vx(t,e,t=>i.isBlankCharacter(t))}forwardFromEnd(t,e,i){return Yx(t,e,t=>i.isBlankCharacter(t))}forwardFromBegin(t,e,i){return Vx(t,e,t=>i.isBlankCharacter(t))}backFromEnd(t,e,i){return Yx(t,e,t=>i.isBlankCharacter(t))}}function iw(t){switch(t){case vn:return"Term Configuration";case yn:return"Block Configuration";case On:return"Relation Configuration";default:return""}}class nw{#Cn;#Tn;#sn;#Pn;#Vt;#si;#En;constructor(t,e,i,n,s,o,r,a){this.#Cn=new Xx(t,e,i),this.#Tn=new Fx(t),this.#sn=n,this.#Pn=s,this.#Vt=o,this.#si=r,this.#En=a}get pushButtonNames(){return this.#Tn.names}isPushed(t){return this.#Tn.get(t).isPushed}push(t){this.#Tn.get(t).isPushed=!0}release(t){this.#Tn.get(t).isPushed=!1}toggleButton(t){return this.#Tn.get(t).toggle()}get textSelectionAdjuster(){return this.isPushed("boundary detection")?new tw:new ew}get controlBarButton(){return(new qx).controlBar.map(({list:t})=>t.filter(({type:t})=>this.#si.isAvailable(t)).map(({type:t,title:e})=>this.#An(t,e)).map(({type:t,title:e})=>({type:t,title:e,pushed:this.getState(t,"pushed"),disabled:this.getState(t,"disabled")}))).filter(t=>t.length)}get contextMenuButton(){return(new qx).getContextMenuFor(this.#En.currentState).map(({list:t})=>t.filter(({type:t})=>this.#si.isAvailable(t)).map(({type:t,title:e})=>this.#An(t,e)).reduce((t,{type:e,title:i})=>(!q()&&this.getState(e,"disabled")||t.push(this.#Mn(e,i)),t),[])).filter(t=>t.length)}getState(t,e){switch(e){case"pushed":return this.#Tn.get(t).isPushed;case"disabled":return!this.#Cn.get(t);case"transit":switch(t){case"upload":return this.#sn.hasChange;case"pallet":return this.diffOfConfiguration;default:new Error("Unknown name")}break;default:new Error("Unknown state")}}updateButtonsToOperateSpanWithTouchDevice(t,e,i,n){this.#Cn.updateButtonsToOperateSpanWithTouchDevice(t,e,i,n)}get diffOfConfiguration(){return sx(this.#Pn.configuration,{...this.#Pn.configuration,...this.#Vt.config})}setPushButtons(t){!0===t.autosave?this.push("upload automatically"):this.release("upload automatically"),!1===t.autolineheight?this.release("auto adjust lineheight"):this.push("auto adjust lineheight"),!1===t.boundarydetection?this.release("boundary detection"):this.push("boundary detection")}get detailModifierClassName(){return this.#si.isAvailable("show logo")?"textae-control-details--show-logo":"textae-control-details--hide-logo"}#An(t,e){return"pallet"==t?{type:t,title:iw(this.#En.currentState)}:{type:t,title:e}}#Mn(t,e){return{type:t,title:e,pushed:this.getState(t,"pushed"),disabled:this.getState(t,"disabled"),transit:this.getState(t,"transit")}}}class sw{#Nt;#ei;#Ie;#Qn;#Dn;#Vt;#Rn;#In;constructor(t,e,i,n,s,o){this.#Nt=t,this.#ei=e,this.#Ie=i,this.#Qn=n,this.#Dn=s,this.#Vt=o,this.#Rn=[],this.#In=D(),t.on("textae-event.annotation-data.entity.remove",t=>{this.hasCuttingItem&&this.#Ln(this.#Rn.filter(e=>e!=t))}).on("textae-event.edit-mode.transition",()=>this.#Ln())}get hasCopyingItem(){return this.#Rn[0]instanceof Ot}get hasCuttingItem(){return this.#Rn[0]instanceof Wt}copyEntitiesToLocalClipboard(){this.#Ln(this.#Ie.copyingTargets)}copyEntitiesToSystemClipboard(t){if(this.#Ie.span.contains(t=>t.isBlock))return;const{copyingTargets:e}=this.#Ie;if(e.length>0){const i=this.#Qn.config.filter(({id:t})=>e.some(({typeName:e})=>e===t)),n=this.#Dn.config.filter(({pred:t})=>e.some(({attributes:e})=>e.some(e=>e.pred===t))),s=JSON.stringify({typeValues:e.map(({externalFormat:t})=>t),config:{"entity types":i,"attribute types":n}});t.clipboardData.setData("text/plain",s),t.clipboardData.setData("application/x-textae-type-values",s),t.preventDefault()}}cutEntitiesToLocalClipboard(){const{cuttingTargets:t}=this.#Ie;this.#Nn.length&&this.#Nn.every(e=>t.has(e))&&[...t].every(t=>this.#Nn.includes(t))?this.#Ln():this.#Ln([...t])}cutEntitiesToSystemClipboard(t){this.#Ie.span.contains(t=>t.isBlock)||(this.cutEntitiesToLocalClipboard(),t.clipboardData.setData("application/x-textae-editor-uuid",this.#In),this.copyEntitiesToSystemClipboard(t))}pasteEntitiesFromLocalClipboard(){if(this.#jn.length&&this.#Ie.span.single)this.#zn();else if(this.hasCopyingItem){const t=this.#ei.factory.pasteTypesToSelectedSpansCommand(this.#Rn);this.#ei.invoke(t)}}pasteEntitiesFromSystemClipboard(t){if(this.#Ie.span.contains(t=>t.isBlock))return;if(t.clipboardData.getData("application/x-textae-editor-uuid")===this.#In&&this.#jn.length&&this.#Ie.span.single)return void this.#zn();const e=t.clipboardData.getData("application/x-textae-type-values");if(e){const t=JSON.parse(e),i=new Le;if(i.definedTypes=t.config["attribute types"],this.#Vt.isLock){const e=t.typeValues.map(({obj:t,attributes:e})=>new Ot(t,e.filter(({pred:t})=>this.#Dn.get(t)&&this.#Dn.get(t).valueType===i.get(t).valueType))),n=this.#ei.factory.pasteTypesToSelectedSpansCommand(e);this.#ei.invoke(n)}else{const e=t.typeValues.map(({obj:t,attributes:e})=>new Ot(t,e.filter(({pred:t})=>!this.#Dn.get(t)||this.#Dn.get(t).valueType===i.get(t).valueType))),n=t.config["entity types"].filter(({id:t})=>!this.#Qn.config.some(e=>e.id===t)),s=t.config["attribute types"].filter(({pred:t})=>!this.#Dn.get(t)),o=this.#ei.factory.pasteTypesToSelectedSpansCommand(e,n,s,this.#Bn(e,i));this.#ei.invoke(o)}return void(this.hasCuttingItem&&this.#Ln())}}#Bn(t,e){const i=[],n=t.reduce((t,i)=>t.concat(i.attributes.filter(({pred:t})=>"selection"===e.get(t).valueType)),[]);for(const{pred:t,obj:s}of n)if(this.#Dn.get(t)&&!this.#Dn.get(t).values.some(({id:t})=>t===s)){const n=e.get(t).values.find(({id:t})=>t===s);i.push({pred:t,value:n})}return i}#zn(){const t=this.#ei.factory.moveEntitiesToSelectedSpanCommand(this.#jn);this.#ei.invoke(t),this.#Ln()}#Ln(t=[]){const e=this.#Nn.filter(e=>!t.includes(e));this.#Rn=t,this.#Nt.emit("textae-event.clip-board.change",this.#Nn,e)}get#jn(){return this.#Nn.filter(t=>t.span.id!==(this.#Ie.span.single&&this.#Ie.span.single.id))}get#Nn(){return this.hasCuttingItem?this.#Rn:[]}}class ow{#ii;constructor(t,e,i,n,o){this.#ii=e;const r=s()(()=>i.saveAnnotation(),5e3);t.on("textae-event.resource.annotation.load.success",()=>this.#qn()).on("textae-event.resource.save.error",()=>this.#qn()).on("textae-event.resource.annotation.url.set",e=>t.emit("textae-event.annotation-auto-saver.enable",Boolean(n||e.id))).on("textae-event.control.button.push",({name:t,isPushed:e})=>{"upload automatically"===t&&!0===e&&o.hasChange&&i.saveAnnotation()}).on("textae-event.annotation-data.events-observer.unsaved-change",t=>{t&&e.isPushed("upload automatically")&&r()})}#qn(){this.#ii.isPushed("upload automatically")&&this.#ii.toggleButton("upload automatically")}}const rw=new d;class aw{#r;constructor(t,e){const i=l().create(t);this.#r=i,function(t,e){r()(t,".textae-control-icon","touchstart",({target:t})=>{if(t.classList.contains("textae-control-icon--disabled"))return;const{buttonType:i}=t.dataset;switch(i){case"create span by touch":case"expand span by touch":case"shrink span by touch":case"edit text by touch":e.handle(i)}},{passive:!0}),r()(t,".textae-control-icon","click",({target:t})=>{if(t.classList.contains("textae-control-icon--disabled"))return;const{buttonType:i}=t.dataset;switch(i){case"help":rw.open();break;case"create span by touch":case"expand span by touch":case"shrink span by touch":case"edit text by touch":break;default:e.handle(i)}});const i=t.querySelector(".textae-control-hamburger-menu-button");i&&i.addEventListener("click",t=>t.target.closest(".textae-control").querySelector(".textae-control-details").classList.toggle("textae-control-details--force-show"))}(this.#r,e)}get el(){return this.#r}_querySelector(t){return this.#r.querySelector(t)}}function lw({type:t,title:e,classList:i}){return`\n<span \nclass="${i.join(" ")}" \ntitle="${e}" \ndata-button-type="${t}">\n</span>\n`}var cw=i(6438),hw=i.n(cw);function uw(t){return t.map(t=>{const e=[];for(const{type:i,title:n,pushed:s,disabled:o,transit:r}of t){const t=["textae-control-icon",`textae-control-${i.replaceAll(" ","-")}-button`];s&&t.push("textae-control-icon--pushed"),o&&t.push("textae-control-icon--disabled"),r&&t.push("textae-control-icon--transit"),e.push({type:i,title:n,classList:t})}return e})}function dw(t){return`\n<div class="textae-control ${q()?"textae-touch-bar":"textae-control-bar"}">\n <div class="textae-control-summary">\n <span class="textae-control-title">\n <a href="http://textae.pubannotation.org/" target="_blank">TextAE</a>\n </span>\n <button type="button" class="textae-control-hamburger-menu-button" >\n <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" class="bi" fill="currentColor" viewBox="0 0 16 16">\n <path fill-rule="evenodd" d="M2.5 11.5A.5.5 0 0 1 3 11h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4A.5.5 0 0 1 3 3h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z"></path>\n </svg>\n </button>\n </div>\n <div class="textae-control-details ${t.detailModifierClassName}">\n <span class="textae-control-title">\n <a href="http://textae.pubannotation.org/" target="_blank">TextAE</a>\n </span>\n ${uw(t.controlBarButton).map(t=>`\n <span class="textae-control-separator"></span>\n ${t.map(lw).join("\n")}\n `).join("\n")}\n </div>\n</div>\n`}class fw extends aw{#ii;constructor(t,e,i){super(dw(e),i),this.#ii=e,q()&&Math.max(document.documentElement.clientWidth,window.innerWidth)<768&&new(hw())(".textae-touch-bar",{stickyContainer:".textae-editor"}),t.on("textae-event.control.button.push",({name:t})=>{this.#Zn(t,"pushed")}).on("textae-event.control.buttons.change",t=>{for(const e of t)this.#Zn(e,"disabled")}).on("textae-event.annotation-data.events-observer.unsaved-change",()=>{this.#Zn("upload","transit")}).on("textae-event.edit-mode.transition",t=>{const e=iw(t);super._querySelector(".textae-control-pallet-button").title=e}).on("textae-event.configuration.reset",()=>this.#Fn()).on("textae-event.type-definition.entity.change",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.entity.delete",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.entity.change-default",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.relation.change",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.relation.delete",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.relation.change-default",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.attribute.create",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.attribute.change",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.attribute.delete",()=>this.#Zn("pallet","transit")).on("textae-event.type-definition.attribute.move",()=>this.#Zn("pallet","transit"))}#Zn(t,e){const i=super._querySelector(`.textae-control-${t.replaceAll(" ","-")}-button`);i&&(this.#ii.getState(t,e)?i.classList.add(`textae-control-icon--${e}`):i.classList.remove(`textae-control-icon--${e}`))}#Fn(){super.el.innerHTML="",super.el.insertAdjacentHTML("beforeend",dw(this.#ii))}}function pw({type:t,title:e,classList:i}){return`<p \n class="${i.join(" ")}" \n data-button-type="${t}">${e}\n </p>`}class mw extends aw{#Q;#ii;constructor(t,e,i){super(`<div class="textae-control ${q()?"textae-android-context-menu":"textae-context-menu"}"></div>`,i),this.#Q=t,this.#ii=e}show(t){const e=window.getSelection(),i=this.#Q.getBoundingClientRect();if(q()&&1===e.rangeCount){const t=e.getRangeAt(0).getBoundingClientRect(),n=this.#Q.querySelector(".textae-editor__text-box").getBoundingClientRect();this.#Xn(t.y-i.y,t.x-n.x)}else this.#Hn(t.pageY-i.y,t.pageX-i.x)}hide(){this.#Wn&&(super.el.classList.remove("textae-context-menu--show"),super.el.classList.add("textae-context-menu--hide"))}get#Wn(){return super.el.classList.contains("textae-context-menu--show")}#Xn(t,e){this.#Vn();const{height:i}=this.el.getBoundingClientRect();super.el.setAttribute("style",`top: ${t-i}px; left: ${e}px`)}#Hn(t,e){this.#Vn(),super.el.setAttribute("style",`top: ${t}px; left: ${e}px`)}#Vn(){const t=uw(this.#ii.contextMenuButton);if(0===t.length)return;const e=`\n <div">\n ${t.map(t=>t.map(pw).join("")).join('<p class="textae-control-separator"></p>\n')}\n </div>\n `;super.el.replaceChildren(...l().create(e).children),super.el.classList.remove("textae-context-menu--hide"),super.el.classList.add("textae-context-menu--show")}}class gw{constructor(t,e,i,n,s,o){this._map=new Map([["1",t=>s.manipulateAttribute(1,t)],["2",t=>s.manipulateAttribute(2,t)],["3",t=>s.manipulateAttribute(3,t)],["4",t=>s.manipulateAttribute(4,t)],["5",t=>s.manipulateAttribute(5,t)],["6",t=>s.manipulateAttribute(6,t)],["7",t=>s.manipulateAttribute(7,t)],["8",t=>s.manipulateAttribute(8,t)],["9",t=>s.manipulateAttribute(9,t)],["a",()=>n.isAvailable("redo")&&t.redo()],["b",()=>n.isAvailable("boundary detection")&&e.toggleButton("boundary detection")],["d",()=>n.isAvailable("delete")&&e.removeSelectedElements()],["e",()=>n.isAvailable("new entity")&&e.createEntity()],["f",()=>o.changeModeByShortcut()],["i",()=>n.isAvailable("import")&&i.importAnnotation()],["m",()=>o.changeModeByShortcut()],["q",()=>n.isAvailable("pallet")&&s.showPallet()],["r",()=>n.isAvailable("replicate span annotation")&&e.replicate()],["u",()=>n.isAvailable("upload")&&i.uploadAnnotation()],["w",()=>n.isAvailable("edit properties")&&s.editProperties()],["y",()=>n.isAvailable("redo")&&t.redo()],["z",()=>n.isAvailable("undo")&&t.undo()],["ArrowDown",()=>e.selectDown()],["ArrowLeft",t=>e.selectLeft(t)],["ArrowRight",t=>e.selectRight(t)],["ArrowUp",()=>e.selectUp()],["Backspace",()=>e.removeSelectedElements()],["Delete",()=>e.removeSelectedElements()],["Escape",()=>e.cancelSelect()]])}handle(t){const e=t.shiftKey&&48<=t.keyCode&&t.keyCode<=57?String.fromCharCode(t.keyCode):t.key;this._map.has(e)&&this._map.get(e)(t.shiftKey)}}class vw{constructor(t,e,i,n,s,o,r){this._map=new Map([["view mode",()=>r.toViewMode()],["term edit mode",()=>r.toTermEditMode()],["block edit mode",()=>r.toBlockEditMode()],["relation edit mode",()=>r.toRelationEditMode()],["text edit mode",()=>r.toTextEditMode()],["simple view",()=>r.toggleSimpleMode()],["import",()=>i.importAnnotation()],["upload",()=>i.uploadAnnotation()],["undo",()=>t.undo()],["redo",()=>t.redo()],["replicate span annotation",()=>e.replicate()],["create span by touch",()=>o.createSpanWithTouchDevice()],["expand span by touch",()=>o.expandSpanWithTouchDevice()],["shrink span by touch",()=>o.shrinkSpanWithTouchDevice()],["edit text by touch",()=>o.editTextWithTouchDevice()],["new entity",()=>e.createEntity()],["edit properties",()=>o.editProperties()],["pallet",()=>o.showPallet()],["delete",()=>e.removeSelectedElements()],["copy",()=>e.copyEntitiesToLocalClipboard()],["cut",()=>e.cutEntitiesToLocalClipboard()],["paste",()=>e.pasteEntitiesFromLocalClipboard()],["setting",()=>e.showSettingDialog()],["adjust lineheight",()=>s.textBox.updateLineHeight()]]);for(const t of n.pushButtonNames)this._map.has(t)||this._map.set(t,()=>e.toggleButton(t))}handle(t){this._map.has(t)&&this._map.get(t)()}}function yw(t,e){return t.id<e.id?-1:t.id>e.id?1:0}function Ow({text:t,denotations:e=[],attributes:i=[],relations:n=[],blocks:s=[],selectedText:o}){return{text:t,denotations:e.sort(yw),attributes:i.sort(yw),relations:n.sort(yw),blocks:s.sort(yw),selectedText:o}}function bw(t,e){return sx(Ow(t),Ow(e))}class xw{#Nt;#Pn;#Ht;#Yn=new(ve())(!1);constructor(t,e,i){this.#Nt=t,this.#Pn=e,this.#Ht=i,t.on("textae-event.resource.annotation.save",()=>{this.#Yn.set(!1),this.#Un()}).on("textae-event.annotation-data.all.change",()=>{this.#Yn.set(!1),this.#Un()}).on("textae-event.annotation-data.span.add",()=>this.#Gn()).on("textae-event.annotation-data.span.change",()=>this.#Gn()).on("textae-event.annotation-data.span.remove",()=>this.#Gn()).on("textae-event.annotation-data.entity.add",()=>this.#Gn()).on("textae-event.annotation-data.entity.change",()=>this.#Gn()).on("textae-event.annotation-data.entity.remove",()=>this.#Gn()).on("textae-event.annotation-data.entity.move",()=>this.#Gn()).on("textae-event.annotation-data.relation.add",()=>this.#Gn()).on("textae-event.annotation-data.relation.change",()=>this.#Gn()).on("textae-event.annotation-data.relation.remove",()=>this.#Gn()).on("textae-event.annotation-data.attribute.add",()=>this.#Gn()).on("textae-event.annotation-data.attribute.remove",()=>this.#Gn()).on("textae-event.annotation-data.text.change",()=>this.#Gn()),this.#Yn(()=>t.emit("textae-event.annotation-data.events-observer.unsaved-change",this.#Yn()))}get hasChange(){return this.#Yn()}#Gn(){this.#Yn.set(bw(this.#Pn.annotation,this.#Ht.externalFormat)),this.#Un()}#Un(){this.#Nt.emit("textae-event.annotation-data.events-observer.change",this.#Ht)}}async function ww(t,e){if(function(t,e){const i=hx().extname(e),n=t.headers.get("Content-Type");return".json"===i||n&&n.includes("application/json")}(t,e))return await t.json();if(function(t,e){const i=hx().extname(e),n=t.headers.get("Content-Type");return".txt"===i||n&&n.includes("text/plain")}(t,e)){const e=await t.text();return ub.parse(e)}throw new Error("The content type of the loaded content is not supported.")}class _w extends Error{constructor(t){super(t),this.name="FormatConversionError"}}class Sw{#Nt;constructor(t){this.#Nt=t}async loadFrom(t){console.assert(t,"url is necessary!"),this.#Nt.emit("textae-event.resource.startLoad");try{const e=await fetch(t,{method:"GET",cache:"no-cache",credentials:"omit",headers:{Accept:"application/json, text/plain"},signal:AbortSignal.timeout(3e4)});if(e.ok){const i=await ww(e,t);this.#Kn(t,i)}else 401===e.status?await this.#Jn(t):this.#ts(t)}catch(e){e instanceof _w||console.error(e),this.#ts(t)}finally{this.#Nt.emit("textae-event.resource.endLoad")}}#Kn(t,e){const i=dx.createURLSource(t,e);e&&e.text?(this.#Nt.emit("textae-event.resource.annotation.load.success",i),this.#Nt.emit("textae-event.resource.annotation.url.set",i)):this.#Nt.emit("textae-event.resource.annotation.format.error",i)}async#Jn(t){try{const e=await fetch(t,{method:"GET",cache:"no-cache",credentials:"include",headers:{Accept:"application/json, text/plain"},signal:AbortSignal.timeout(3e4)});if(e.ok){const i=await ww(e,t);this.#Kn(t,i)}else 401===e.status?await this.#Jn(t):this.#ts(t)}catch{this.#ts(t)}}#ts(t){e().error(`Could not load the file from the location you specified.: ${t}`),this.#Nt.emit("textae-event.resource.annotation.load.error",t)}}class kw{#Nt;constructor(t){this.#Nt=t}loadFrom(t,e){console.assert(t,"url is necessary!"),this.#Nt.emit("textae-event.resource.startLoad"),fetch(t,{method:"GET",cache:"no-cache",credentials:"omit",headers:{Accept:"application/json","Content-Type":"application/json"},signal:AbortSignal.timeout(3e4)}).then(i=>{if(i.ok)return i.json().then(i=>this.#Kn(t,i,e));this.#ts(t)}).catch(()=>this.#ts(t)).finally(()=>this.#Nt.emit("textae-event.resource.endLoad"))}#Kn(t,e,i){this.#Nt.emit("textae-event.resource.configuration.load.success",dx.createURLSource(t,e),i)}#ts(t){e().error(`Could not load the file from the location you specified.: ${t}`),this.#Nt.emit("textae-event.resource.configuration.load.error",t)}}function $w(t,e,i){return 401===t&&e&&"ServerPage"===e&&i?i:null}function Cw(t){return window.open(t,"_blank","width=600, height=500")}function Tw(t,e){return"json"===e?JSON.stringify(t):"inline"===e?ub.generate(t):void 0}class Pw{#es;#Nt;constructor(t,e){this.#es=t,this.#Nt=e}async saveTo(t,e){if(t){this.#Nt.emit("textae-event.resource.startSave");try{const i=Tw(e,this.#es),n=await this.#is(t,i);await this.#ns(n,t,e)}catch(t){t instanceof _w||console.error(t),this.#ts()}finally{this.#Nt.emit("textae-event.resource.endSave")}}}async#is(t,e){const i="json"===this.#es?"application/json":"text/plain";return fetch(t,{method:"POST",headers:{"Content-Type":i,"App-Name":"TextAE"},body:e,credentials:"include"})}async#ns(t,e,i){if(t.ok)this.#ss(i);else if(401===t.status){const n=$w(t.status,t.headers.get("WWW-Authenticate"),t.headers.get("Location"));n&&await this.#os(n,e,i)}else this.#ts()}#ss(t){e().success("annotation saved"),this.#Nt.emit("textae-event.resource.annotation.save",t)}async#os(t,e,i){const n=Cw(t);if(!n)return this.#ts();await async function(t){return new Promise(e=>{const i=setInterval(()=>{t.closed&&(clearInterval(i),e())},1e3)})}(n),await this.#rs(i,e)}async#rs(t,e){const i=Tw(t,this.#es);(await this.#is(e,i)).ok?this.#ss(t):this.#ts()}#ts(){e().error("could not save"),this.#Nt.emit("textae-event.resource.save.error")}}class Ew{#Nt;constructor(t){this.#Nt=t}saveTo(t,e){if(t){this.#Nt.emit("textae-event.resource.startSave");const i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),credentials:"include"};fetch(t,i).then(i=>{if(i.ok)return this.#ss(e);if(401===i.status){const n=$w(i.status,i.headers.get("WWW-Authenticate"),i.headers.get("Location"));if(n)return this.#os(n,t,e)}this.#ts()}).finally(()=>this.#Nt.emit("textae-event.resource.endSave"))}}#ss(t){e().success("configuration saved"),this.#Nt.emit("textae-event.resource.configuration.save",t)}#os(t,e,i){if(!Cw(t))return this.#ts();const n=setInterval(()=>{clearInterval(n),this.#rs(i,e)},1e3)}#rs(t,e){{const i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),credentials:"include"};fetch(e,i).then(e=>{e.ok?this.#ss(t):this.#ts()})}}#ts(){e().error("could not save"),this.#Nt.emit("textae-event.resource.save.error")}}class Aw{#Nt;constructor(t){this.#Nt=t}loadAnnotation(t){new Sw(this.#Nt).loadFrom(t)}loadConfiguration(t,e=null){new kw(this.#Nt).loadFrom(t,e)}saveAnnotation(t,e,i){new Pw(i,this.#Nt).saveTo(t,e)}saveConfiguration(t,e){new Ew(this.#Nt).saveTo(t,e)}}class Mw{#as;constructor(){this.#as=new Map([["logo",{name:"show logo",enabled:!0}],["read",{name:"import",enabled:!0}],["write",{name:"upload",enabled:!0}],["write-auto",{name:"upload automatically",enabled:!0}],["view",{name:"view mode",enabled:!0}],["term",{name:"term edit mode",enabled:!0}],["term-edit",{alias:"term"}],["block",{name:"block edit mode",enabled:!0}],["block-edit",{alias:"block"}],["relation",{name:"relation edit mode",enabled:!0}],["relation-edit",{alias:"relation"}],["text-edit",{name:"text edit mode",enabled:!0}],["simple",{name:"simple view",enabled:!0}],["line-height",{name:"adjust lineheight",enabled:!0}],["line-height-auto",{name:"auto adjust lineheight",enabled:!0}],["undo",{name:"undo",enabled:!0}],["redo",{name:"redo",enabled:!0}],["replicate",{name:"replicate span annotation",enabled:!0}],["replicate-auto",{name:"auto replicate",enabled:!0}],["boundary-detection",{name:"boundary detection",enabled:!0}],["create-span-by-touch",{name:"create span by touch",enabled:!0}],["expand-span-by-touch",{name:"expand span by touch",enabled:!0}],["shrink-span-by-touch",{name:"shrink span by touch",enabled:!0}],["edit-text-by-touch",{name:"edit text by touch",enabled:!0}],["entity",{name:"new entity",enabled:!0}],["pallet",{name:"pallet",enabled:!0}],["edit-properties",{name:"edit properties",enabled:!0}],["delete",{name:"delete",enabled:!0}],["copy",{name:"copy",enabled:!0}],["cut",{name:"cut",enabled:!0}],["paste",{name:"paste",enabled:!0}],["setting",{name:"setting",enabled:!0}],["help",{name:"help",enabled:!0}]])}get defaultAvailabilities(){return Array.from(this.#as.values()).filter(({name:t,enabled:e})=>void 0!==t&&void 0!==e).reduce((t,{name:e,enabled:i})=>t.set(e,i),new Map)}translateToInnerNameFrom(t){if(this.#as.has(t)){const e=this.#as.get(t);return e.alias?this.#as.get(e.alias).name:e.name}return e().warning(`'${t}' is an unknown function name for function availabilities.`),t}}class Qw{#ls;#cs;constructor(){this.#ls=new Mw,this.#cs=this.#ls.defaultAvailabilities}isAvailable(t){return this.#cs.get(t)}enable(t){this.#cs.set(t,!0)}disable(t){this.#cs.set(t,!1)}get names(){return Array.from(this.#cs.keys())}set availability(t){const e=this.#ls.defaultAvailabilities;if(t)for(const[i,n]of Object.entries(t))e.set(this.#ls.translateToInnerNameFrom(i),n);this.#cs=e}}class Dw{#hs;#us;#fe;#Nt;#si;constructor(t,e,i){this.#hs=!1,this.#us=mn,this.#fe=t,this.#Nt=e,this.#si=i}get currentState(){return this.#us}toViewMode(t){this.#hs=t,this.#us=gn,this.#ds()}toTermEditMode(t){this.#hs=t,this.#us=vn,this.#ds()}toBlockEditMode(t){this.#hs=t,this.#us=yn,this.#ds()}toRelationEditMode(){this.#hs=!0,this.#us=On,this.#ds()}toTextEditMode(t){this.#hs=t,this.#us=bn,this.#ds()}toggleSimpleMode(){switch(this.currentState){case vn:this.toTermEditMode(!this.#hs);break;case yn:this.toBlockEditMode(!this.#hs);break;case bn:this.toTextEditMode(!this.#hs);break;case gn:this.toViewMode(!this.#hs);break;default:throw new Error(`Invalid state: ${this.currentState}`)}}changeModeByShortcut(){const t=this.#fs;if(t.length<=1)return;const e=t.findIndex(t=>t.name===this.currentState);e<t.length-1?this[t[e+1].funcName](this.nextShowRelation):this[t[0].funcName](this.nextShowRelation)}get nextShowRelation(){return this.#us===On?this.#fe.some:this.#hs}#ds(){this.#Nt.emit("textae-event.edit-mode.transition",this.#us,this.#hs)}get#fs(){return[{name:gn,availabilityName:"view mode",funcName:"toViewMode"},{name:vn,availabilityName:"term edit mode",funcName:"toTermEditMode"},{name:yn,availabilityName:"block edit mode",funcName:"toBlockEditMode"},{name:On,availabilityName:"relation edit mode",funcName:"toRelationEditMode"}].filter(t=>this.#si.isAvailable(t.availabilityName))}}class Rw{#En;#ps;#G;#ms;constructor(t,e,i,n){this.#ps=t,this.#En=e,this.#G=i,this.#ms=n}toViewMode(){this.#ms(),this.#En.toViewMode(this.#En.nextShowRelation)}toTermEditMode(){this.#ms(),this.#En.toTermEditMode(this.#En.nextShowRelation)}toBlockEditMode(){this.#ms(),this.#En.toBlockEditMode(this.#En.nextShowRelation)}toRelationEditMode(){this.#ms(),this.#En.toRelationEditMode()}toTextEditMode(){this.#ms(),this.#En.toTextEditMode(this.#En.nextShowRelation)}toggleSimpleMode(){this.#ms(),this.#En.toggleSimpleMode()}changeModeByShortcut(){this.#ms(),this.#En.changeModeByShortcut()}reset(){this.#ps.isEditTermMode?this.#En.toTermEditMode(this.#G.some):this.#ps.isEditBlockMode?this.#En.toBlockEditMode(this.#G.some):this.#ps.isEditRelationMode?this.#En.toRelationEditMode():this.#ps.isTextEditMode?this.#En.toTextEditMode(this.#G.some):this.#En.toViewMode(this.#G.some)}}function Iw(){window.getSelection().removeAllRanges()}function Lw(t,i,n,s,o,r,a,l,c){if(a){s.removeAll();const h=L(t,a),u=function(t,i,n,s,o,r,a){const{begin:l,end:c}=t.getSpan(o).getShortenInAnchorNodeToFocusNodeDirection(s,i,r);if(t.isBoundaryCrossingWithOtherSpans(l,c))return e().warning("A span cannot be shrunken to make a boundary crossing."),!1;const h=t.findDenotation(l,c);return l<c&&!h?(a(l,c),!1):(n.invoke(n.factory.removeSpanCommand(o)),!0)}(i,n,o,r,a,l,c);u&&h&&s.selectSpan(h.id)}}class Nw{constructor(){this.selection=window.getSelection(),console.assert(this.parentOfAnchorNode.closest(".textae-editor__text-box")===this.parentOfFocusNode.closest(".textae-editor__text-box"),"Text selection across editors is disabled")}get isParentOfAnchorNodeTextBox(){return Y(this.parentOfAnchorNode)}get isParentOfAnchorNodeDenotationSpan(){return U(this.parentOfAnchorNode)}get isParentOfAnchorNodeBlockSpan(){return K(this.parentOfAnchorNode)}get isParentOfAnchorNodeStyleSpan(){return G(this.parentOfAnchorNode)}get isParentOfFocusNodeTextBox(){return Y(this.parentOfFocusNode)}get isParentOfFocusNodeDenotationSpan(){return U(this.parentOfFocusNode)}get isParentOfFocusNodeBlockSpan(){return K(this.parentOfFocusNode)}get isParentOfFocusNodeStyleSpan(){return G(this.parentOfFocusNode)}get isParentOfBothNodesSame(){return this.parentOfAnchorNode===this.parentOfFocusNode}get isParentOfBothNodesTextBox(){return this.isParentOfAnchorNodeTextBox&&this.isParentOfFocusNodeTextBox}get isParentsParentOfAnchorNodeAndFocusedNodeSame(){return this.parentOfAnchorNode.parentElement===this.parentOfFocusNode.parentElement}get isAnchorNodeParentIsDescendantOfFocusNodeParent(){return this.parentOfAnchorNode.closest(`#${this.parentOfFocusNode.id}`)}get ancestorDenotationSpanOfAnchorNode(){return this.parentOfAnchorNode.closest(".textae-editor__span")}get ancestorDenotationSpanOfFocusNode(){return this.parentOfFocusNode.closest(".textae-editor__span")}get ancestorBlockSpanOfAnchorNode(){return this.parentOfAnchorNode.closest(".textae-editor__block")}get ancestorBlockSpanOfFocusNode(){return this.parentOfFocusNode.closest(".textae-editor__block")}get doesFitInOneBlockSpan(){return this.ancestorBlockSpanOfAnchorNode===this.ancestorBlockSpanOfFocusNode}get parentOfAnchorNode(){return this.selection.anchorNode.parentElement}get parentOfFocusNode(){return this.selection.focusNode.parentElement}}class jw{#Q;#Ht;#ni;#ei;#ii;#Ie;constructor(t,e,i,n,s,o){this.#Q=t,this.#Ht=e,this.#ni=i,this.#ei=n,this.#ii=s,this.#Ie=o}editFor(){const t=new Nw;if(t.isParentOfAnchorNodeTextBox){if(t.isParentOfFocusNodeTextBox)return void this.#gs();if(t.isParentOfFocusNodeDenotationSpan||t.isParentOfFocusNodeStyleSpan)return void(t.ancestorBlockSpanOfFocusNode?this.#vs(t):this.#gs());if(t.isParentOfFocusNodeBlockSpan)return void this.#vs(t)}if(t.isParentOfAnchorNodeDenotationSpan||t.isParentOfAnchorNodeStyleSpan){if(t.isParentOfFocusNodeTextBox||t.isParentOfFocusNodeDenotationSpan||t.isParentOfFocusNodeStyleSpan){if(t.ancestorBlockSpanOfAnchorNode)if(t.doesFitInOneBlockSpan){const{anchor:e,focus:i}=this.#Ht.textSelection,n=this.#Ht.getSpan(t.parentOfAnchorNode.id),s=this.#Ht.getSpan(t.ancestorBlockSpanOfAnchorNode.id);e<i&&n.begin===s.begin||i<e&&n.end===s.end?this.#vs(t):Iw()}else this.#ys(t);else t.ancestorBlockSpanOfFocusNode?this.#vs(t):this.#gs();return}if(t.isParentOfFocusNodeBlockSpan)return void this.#vs(t)}if(t.isParentOfAnchorNodeBlockSpan){if(t.isParentOfFocusNodeTextBox||t.isParentOfFocusNodeDenotationSpan||t.isParentOfFocusNodeStyleSpan)return void(t.ancestorBlockSpanOfFocusNode?this.#vs(t):this.#ys(t));if(t.isParentOfFocusNodeBlockSpan){const{anchor:e}=this.#Ht.textSelection,i=this.#Ht.getSpan(t.parentOfFocusNode.id);if(e===i.begin||e===i.end)return void this.#vs(t)}}Iw()}cerateSpanForTouchDevice(){(new Nw).isParentOfBothNodesTextBox&&this.#gs()}expandForTouchDevice(){const t=this.#Os();if(t){const{spanID:e,begin:i,end:n}=t;this.#Ht.validateNewBlockSpan(i,n,e)&&this.#ei.invoke(this.#ei.factory.moveBlockSpanCommand(e,i,n))}}shrinkForTouchDevice(){const t=this.#bs();if(t){const{spanID:i,begin:n,end:s}=t,o=L(this.#Q,i);if(this.#Ht.isBoundaryCrossingWithOtherSpans(n,s))return void e().warning("A span cannot be modified to make a boundary crossing.");if(this.#Ht.hasParentOf(n,s,i))return;const r=this.#Ht.findBlock(n,s);n<s&&!r?this.#ei.invoke(this.#ei.factory.moveBlockSpanCommand(i,n,s)):(this.#ei.invoke(this.#ei.factory.removeSpanCommand(i)),o&&this.#Ie.selectSpan(o.id))}}#gs(){this.#Ht.hasCharacters(this.#ni)&&(this.#Ie.removeAll(),function(t,e,i,n){const{begin:s,end:o}=t.getTextSelection(n,i);if(t.validateNewBlockSpan(s,o)){const t=e.factory.createBlockSpanCommand({begin:s,end:o});e.invoke(t)}}(this.#Ht,this.#ei,this.#ii.textSelectionAdjuster,this.#ni)),Iw()}#ys(t){const e=t.ancestorBlockSpanOfAnchorNode.id;this.#Ie.removeAll();const{begin:i,end:n}=this.#Ht.getSpan(e).getExpandedInAnchorNodeToFocusNodeDirection(this.#ii.textSelectionAdjuster,this.#Ht.sourceDoc,this.#ni);this.#Ht.validateNewBlockSpan(i,n,e)&&this.#ei.invoke(this.#ei.factory.moveBlockSpanCommand(e,i,n)),Iw()}#vs(t){const e=t.ancestorBlockSpanOfFocusNode.id;Lw(this.#Q,this.#Ht,this.#Ht.sourceDoc,this.#Ie,this.#ei,this.#ii.textSelectionAdjuster,e,this.#ni,(t,i)=>{this.#ei.invoke(this.#ei.factory.moveBlockSpanCommand(e,t,i))}),Iw()}#Os(){const t=new Nw;if(null==t.ancestorBlockSpanOfAnchorNode&&null==t.ancestorBlockSpanOfFocusNode)return null;if(t.parentOfFocusNode.contains(t.parentOfAnchorNode)){const e=t.parentOfAnchorNode.id;return{spanID:e,...this.#Ht.getSpan(e).getExpandedInAnchorNodeToFocusNodeDirection(this.#ii.textSelectionAdjuster,this.#Ht.sourceDoc,this.#ni)}}if(t.parentOfAnchorNode.contains(t.parentOfFocusNode)){const e=t.parentOfFocusNode.id;return{spanID:e,...this.#Ht.getSpan(e).getExpandedInFocusNodeToAnchorNodeDirection(this.#ii.textSelectionAdjuster,this.#Ht.sourceDoc,this.#ni)}}}#bs(){const t=new Nw;if(null==t.ancestorBlockSpanOfAnchorNode&&null==t.ancestorBlockSpanOfFocusNode)return null;if(t.parentOfAnchorNode===t.parentOfFocusNode)return null;if(t.parentOfFocusNode.contains(t.parentOfAnchorNode)){const e=t.parentOfAnchorNode.id;return{spanID:e,...this.#Ht.getSpan(e).getShortenInFocusNodeToAnchorNodeDirection(this.#ii.textSelectionAdjuster,this.#Ht.sourceDoc,this.#ni)}}if(t.parentOfAnchorNode.contains(t.parentOfFocusNode)){const e=t.parentOfFocusNode.id;return{spanID:e,...this.#Ht.getSpan(e).getShortenInAnchorNodeToFocusNodeDirection(this.#ii.textSelectionAdjuster,this.#Ht.sourceDoc,this.#ni)}}}}function zw(t,e,i,n){e.length?t.selectSpanRange(e):i.ctrlKey||i.metaKey?t.span.toggle(n):t.selectSpan(n)}function Bw(t){const e=window.getSelection();return"Range"===e.type&&t.contains(e.anchorNode)&&t.contains(e.focusNode)}function qw(t){return t.closest(".textae-editor__signboard")}class Zw{#Q;#Ht;#Ie;#xs;#ws;constructor(t,e,i,n,s){this.#Q=t,this.#Ht=e,this.#Ie=i,this.#xs=n,this.#ws=s}bind(){const t=[];return t.push(r()(this.#Q,".textae-editor__text-box","click",t=>{t.target.classList.contains("textae-editor__text-box")&&this.#_s()})),t.push(r()(this.#Q,".textae-editor","click",t=>{t.target.classList.contains("textae-editor")&&this.#Ss()})),t.push(r()(this.#Q,".textae-editor__signboard","mousedown",()=>this.#ks())),t.push(r()(this.#Q,".textae-editor__signboard__type-values","click",t=>{const e=qw(t.target).dataset.id;this.#$s(t,e)})),t.push(r()(this.#Q,".textae-editor__block","mouseup",t=>{t.target.classList.contains("textae-editor__block")&&this.#Cs()})),t.push(r()(this.#Q,".textae-editor__block-hit-area","mouseup",t=>{t.target.classList.contains("textae-editor__block-hit-area")&&this.#Ts(t)})),t.push(r()(this.#Q,".textae-editor__style","mouseup",t=>{t.target.classList.contains("textae-editor__style")&&this.#Ps(t)})),t.push(r()(this.#Q,".textae-editor__span","mouseup",t=>{t.target.classList.contains("textae-editor__span")&&this.#Es(t)})),t}#Ss(){this.#ws.hide(),this.#Ie.removeAll()}#_s(){"Caret"===window.getSelection().type&&(this.#ws.hide(),this.#Ie.removeAll()),Bw(this.#Q.querySelector(".textae-editor__text-box"))&&this.#xs.editFor()}#Cs(){"Caret"===window.getSelection().type&&(this.#ws.hide(),Iw(),this.#Ie.removeAll()),Bw(this.#Q.querySelector(".textae-editor__text-box"))&&this.#xs.editFor()}#Ts(t){2===t.button&&Iw();const e=window.getSelection();if("Caret"===e.type||"None"===e.type){const e=t.target.dataset.id;this.#As(t,e)}}#Ps(t){"Caret"===window.getSelection().type&&this.#Ie.removeAll(),Bw(this.#Q.querySelector(".textae-editor__text-box"))&&(this.#xs.editFor(),t.stopPropagation())}#Es(t){"Caret"===window.getSelection().type&&this.#Ie.removeAll(),Bw(this.#Q.querySelector(".textae-editor__text-box"))&&(this.#xs.editFor(),t.stopPropagation())}#ks(){this.#Q.focus()}#$s(t,e){if(this.#Ht.entityInstanceContainer.get(e).isBlock){t.ctrlKey||t.metaKey?this.#Ie.entity.toggle(e):this.#Ie.selectEntity(e);const i=this.#Ie.entity.all.map(t=>t.span).map(t=>t.id);this.#Ie.add("span",i)}}#As(t,e){const i=this.#Ie.span.singleId,n=t.shiftKey&&i?this.#Ht.spanInstanceContainer.rangeBlockSpan(i,e):[];zw(this.#Ie,n,t,e);const s=this.#Ie.span.all.map(t=>t.entities.at(0)).map(t=>t.id);this.#Ie.add("entity",s)}}class Fw{createSpanWithTouchDevice(){}expandSpanWithTouchDevice(){}shrinkSpanWithTouchDevice(){}editTextWithTouchDevice(){}editProperties(){}relationClicked(){}relationBollardClicked(t){t.focus()}applyTextSelectionWithTouchDevice(){}manipulateAttribute(){}showPallet(){}hidePallet(){}get isPalletShown(){return!1}updateSelectedTextOffsets(){}}class Xw extends u{constructor(t,e,i,n){const s=()=>{const t=n();t&&this.resolveFunc(t),super.close()},o={text:"OK",click:s};i.buttons=i.buttons?i.buttons.concat([o]):[o],super(t,e,i),r()(super.el,".textae-editor__promise-dialog__observable-element","keyup",t=>{13===t.keyCode&&s()})}open(){return super.open(),new Promise(t=>this.resolveFunc=t)}}class Hw extends Xw{constructor(t,e,i,n,s,o){const a=[];n&&a.unshift({class:"textae-editor__edit-numeric-attribute-dialog__remove-attribute",click:()=>{this.close(),this.resolveFunc({newObj:null})}}),o&&a.unshift({text:"...",title:"configuration",click:()=>{this.close(),o.show(),o.showAttribute(e.pred)}}),super(`Attribute [${i.map(({id:t})=>t||"-").join(",")}]`,function(t){const{subjects:e,pred:i,min:n,max:s,step:o,value:r}=t;return ot`
305
305
  <div class="textae-editor__edit-numeric-attribute-dialog__container">
306
306
  <div class="textae-editor__edit-numeric-attribute-dialog__row">
307
307
  <label>Subject</label>
@@ -904,7 +904,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
904
904
  <button value="OK">OK</button>
905
905
  </div>
906
906
  </form>
907
- `}}class V_ extends Fw{#Q;#Ht;#ni;#ii;#ei;#jo;constructor(t,e,i,n,s){super(),this.#Q=t,this.#Ht=e,this.#ni=i,this.#ii=n,this.#ei=s,this.#jo=new W_(t,(t,e,i,n)=>{if(i===n)return;const s=this.#ei.factory.changeTextAndMoveSpanCommand(t,e,n);this.#ei.invoke(s)})}bindMouseEvents(){const t=[];return t.push(r()(this.#Q,".textae-editor__text-box","click",()=>this.#Bo())),t}applyTextSelectionWithTouchDevice(){this.#ii.updateButtonsToOperateSpanWithTouchDevice(!1,!1,!1,this.#qo)}editTextWithTouchDevice(){this.#Bo()}#Bo(){if(!this.#qo)return;const{begin:t,end:e}=this.#Ht.getTextSelection(this.#ni,this.#ii.textSelectionAdjuster);if(!this.#Ht.validateEditableText(t,e))return!1;const i=this.#Ht.getTextBetween(t,e);this.#jo.open(t,e,i)}get#qo(){return!!Bw(this.#O)&&!!this.#Ht.hasCharacters(this.#ni)}get#O(){return this.#Q.querySelector(".textae-editor__text-box")}}class Y_ extends Fw{#Q;#Ht;#Zo;#Fo;#Xo;constructor(t,e,i){super(),this.#Q=t,this.#Ht=i,this.#Xo=Ui(()=>{this.#Ho(),e.emit("textae-event.editor.selected-text.change")}),document.addEventListener("selectionchange",this.#Xo)}get selectedText(){return void 0===this.#Zo||void 0===this.#Fo?{status:"unselected"}:this.#Ht.isBoundaryCrossingWithOtherSpans(this.#Zo,this.#Fo)?{status:"cross boundary detected"}:{begin:this.#Zo,end:this.#Fo,status:"selected"}}#Ho(){const t=document.getSelection();if(t&&t.rangeCount>0){const e=t.getRangeAt(0),i=this.#Q.querySelector(".textae-editor__text-box");i.contains(e.startContainer)&&i.contains(e.endContainer)&&(this.#Zo=this.#Ht.textSelection.begin,this.#Fo=this.#Ht.textSelection.end)}else this.#Zo=void 0,this.#Fo=void 0}}class U_{static createTermEditMode(t,e,i,n,s,o,r,a){return new H_(t,e,i,n,s,o,r,a)}static createBlockEditMode(t,e,i,n,s,o,r,a){return new B_(t,e,i,n,s,o,r,a)}static createRelationEditMode(t,e,i,n,s,o,r){return new Z_(t,e,i,n,s,o,r)}static createTextEditMode(t,e,i,n,s){return new V_(t,e,i,n,s)}static createViewMode(t,e,i){return new Y_(t,e,i)}}class G_{#En;#Wo;#Vo;#Yo;#Uo;#Go;constructor(t,e,i,n,s,o,r){this.#En=t,this.#Wo=e,this.#Vo=i,this.#Yo=n,this.#Uo=s,this.#Go=o,r.on("textae-event.editor.relation.click",(t,e)=>this.#Ko.relationClicked(t,e)).on("textae-event.editor.relation-bollard.click",(t,e)=>this.#Ko.relationBollardClicked(e)),je(this,()=>this.#Ko,["showPallet","hidePallet","selectLeftAttributeTab","selectRightAttributeTab","createSpanWithTouchDevice","expandSpanWithTouchDevice","shrinkSpanWithTouchDevice","editTextWithTouchDevice","applyTextSelectionWithTouchDevice","editProperties","manipulateAttribute"])}get isEditDenotation(){return this.#En.currentState===vn}get isTypeValuesPalletShown(){return this.#Ko.isPalletShown}get#Ko(){switch(this.#En.currentState){case vn:return this.#Wo;case yn:return this.#Vo;case On:return this.#Yo;case bn:return this.#Uo;default:return this.#Go}}}class K_{constructor(t){this._editorHTMLElement=t}clear(){for(const t of this._editorHTMLElement.classList)t.startsWith("textae-editor__mode")&&this._editorHTMLElement.classList.remove(t)}setFor(t){this._editorHTMLElement.classList.add(`textae-editor__mode--${t}`)}}class J_{#Jo;constructor(t,e,i,n,s,o,r){this.#Jo=[];const a=new K_(t);e.on("textae-event.edit-mode.transition",(t,e)=>{switch(this.#tr(),a.clear(),t){case gn:i.typeGap.show=e,e?a.setFor("view-with-relation"):a.setFor("view-without-relation");break;case vn:i.typeGap.show=e,this.#Jo=n.bindMouseEvents(),e?a.setFor("denotation-with-relation"):a.setFor("denotation-without-relation");break;case yn:i.typeGap.show=e,this.#Jo=s.bindMouseEvents(),e?a.setFor("block-with-relation"):a.setFor("block-without-relation");break;case On:i.typeGap.show=!0,this.#Jo=o.bindMouseEvents(),a.setFor("relation");break;case bn:i.typeGap.show=e,this.#Jo=r.bindMouseEvents(),e?a.setFor("text-with-relation"):a.setFor("text-without-relation");break;default:throw new Error(`Unknown mode: ${t}`)}})}#tr(){for(const t of this.#Jo)t.destroy();this.#Jo=[]}}class tS{#er;#Ht;#En;#Go;#ir;constructor(t,i,n,s,o,r,a){this.#Ht=o;const l=new qe,c=new Wi(t,i,s,o,a),h=new sw(s,c,a,o.denotationDefinitionContainer,o.attributeDefinitionContainer,o.typeDictionary),u=new Lx(s,t,r.statusBar),d=new xw(s,u,o),f=new Qw,p=new Dw(o.relationInstanceContainer,s,f);this.#En=p;const m=new nw(s,a,h,d,u,o.typeDictionary,f,p),g=U_.createTermEditMode(t,s,o,a,l,c,m,n),v=U_.createBlockEditMode(t,s,o,a,l,c,m,n),y=U_.createRelationEditMode(t,s,o,a,c,m,n),O=U_.createTextEditMode(t,o,l,m,c),b=U_.createViewMode(t,s,o);this.#Go=b;const x=new G_(p,g,v,y,O,b,s),w=new Rw(r,p,o.relationInstanceContainer,()=>x.hidePallet());s.on("textae-event.annotation-data.all.change",t=>{r.isEditMode&&t&&e().success("track annotations have been merged to root annotations."),w.reset()}),this.#ir=w;const _=new xn(t,s,o,a,c,l,f,h,m,x),S=new Aw(s),k=new vx(s,S,o,()=>u.annotation,()=>u.configuration,r.saveTo,d,m);new ow(s,m,k,r.saveTo,d),new J_(t,s,o,g,v,y,O),function(t,i,n,s,o,r,a,l){t.on("textae-event.resource.annotation.load.success",c=>{if(!c.data.config&&i.config)n.loadConfiguration(i.config,c);else{if(Qx(c.data),c.data.config&&"object"!=typeof c.data.config)return void e().error("configuration in annotation file is invalid.");const n=Mx(c.data,c.data.config);if(n){if(yx(n,s,o,r,c.data,a),t.emit("textae-event.configuration.reset"),i.isFocusFirstDenotation){const t=r.spanInstanceContainer.allDenotationSpans.at(0);t&&t.focus()}l.annotation=c}}}).on("textae-event.resource.configuration.load.success",(i,n=null)=>{if("object"!=typeof i.data)return void e().error(`${i.displayName} is not a configuration file or its format is invalid.`);n&&Qx(n.data);const c=n&&n.data||{...l.annotation,...r.externalFormat},h=Mx(c,i.data);h&&(yx(h,s,o,r,c,a),t.emit("textae-event.configuration.reset"),n&&(l.annotation=n),l.configuration=i)})}(s,r,S,m,l,o,f,u);const $=new vw(c,_,k,m,o,x,w),C=new fw(s,m,$).el;switch(t.insertBefore(C,t.childNodes[0]),r.control){case"hidden":t.classList.add("textae-editor--control-hidden");break;case"visible":t.classList.add("textae-editor--control-visible");break;default:r.isEditMode||t.classList.add("textae-editor--control-hidden")}o.toolBarHeight=C.getBoundingClientRect().height,function(t,i,n,s,o,r,a){switch(r.resourceType){case ux.QUERY_PARAMETER:{const l=r.annotation();l?Dx(dx.createParameterSource(l),r.config,n,s,t,i,a,o):e().error("failed to load annotation from query parameter.");break}case ux.INLINE:{const l=r.annotation();l?Dx(dx.createInlineSource(l),r.config,n,s,t,i,a,o):e().error("failed to load annotation from directly included in the div element.");break}case ux.REMOTE_URL:n.loadAnnotation(r.annotationURL);break;default:r.config?n.loadConfiguration(r.config):yx(o.defaultConfiguration,s,t,i,o.defaultAnnotation,a)}}(l,o,S,m,u,r,f);const T=new mw(t,m,$);t.appendChild(T.el),t.addEventListener("keyup",t=>{T.hide(),_.isActive&&new gw(c,_,k,f,x,w).handle(t)}),je(this,()=>_,["copyEntitiesToSystemClipboard","cutEntitiesToSystemClipboard","pasteEntitiesFromSystemClipboard","activate","deactivate","applyTextSelectionWithTouchDevice"]),this.#er=T}showContextMenu(t){this.#er.show(t)}hideContextMenu(){this.#er.hide()}focusDenotation(t){this.#ir.toTermEditMode(),this.#Ht.focusDenotation(t)}getSelectedText(){return this.#En.currentState===gn?this.#Go.selectedText:{status:"unselected"}}}var eS=i(7007);class iS{#Ki;#nr;constructor(t,e,i){if(i)this.#Ki=i;else if(e)this.#nr=e;else{const e=this.#sr(t);e&&(this.#Ki=e)}}get isLoaded(){return Boolean(this.#Ki)}get isRemote(){return Boolean(this.#nr)}get URL(){return this.#nr}annotation(){try{return _n(this.#Ki)?JSON.parse(this.#Ki):ub.parse(this.#Ki)}catch{return null}}#sr(t){const e=t.textContent;return t.innerHTML="",e}}class nS{#At;#or;constructor(t){this.#At=t,this.#or=new iS(this.#At,this.#nr,this.#rr)}get resourceType(){return this.#rr?ux.QUERY_PARAMETER:this.#or.isLoaded?ux.INLINE:this.annotationURL?ux.REMOTE_URL:ux.UNKNOWN}get annotationURL(){return this.#or.isRemote?this.#or.URL:null}get config(){return this.#ar("config")}get configLock(){if(this.#nr){const t=new URLSearchParams(this.#nr.split("?")[1]);if(t.has("config_lock"))return t.get("config_lock")}return this.#lr("config_lock")}get control(){return this.#lr("control")}get inspect(){return this.#lr("inspect")}get isEditMode(){switch(this.#lr("mode")){case"edit":case"term-edit":case"block-edit":case"relation-edit":case"text-edit":return!0;default:return!1}}get isEditTermMode(){return"edit"===this.#lr("mode")||"term-edit"===this.#lr("mode")}get isEditBlockMode(){return"block-edit"===this.#lr("mode")}get isEditRelationMode(){return"relation-edit"===this.#lr("mode")}get isTextEditMode(){return"text-edit"===this.#lr("mode")}get statusBar(){return this.#lr("status_bar")}get saveTo(){return this.#ar("save_to")}get isFocusFirstDenotation(){const t="true"===this.#lr("focus_first_denotation");if(t&&this.isEditMode)throw new Error("focus_first_denotation is only available in view mode.");return t}get additionalPaddingTop(){return this.#lr("padding_top")?parseInt(this.#lr("padding_top"),10):0}get#nr(){return this.#ar("source")||this.#ar("target")}annotation(){return this.#or.isLoaded?this.#or.annotation():null}#lr(t){return this.#At.hasAttribute(t)?this.#At.getAttribute(t):null}#ar(t){return this.#At.hasAttribute(t)?decodeURIComponent(this.#At.getAttribute(t)):null}get#rr(){if(this.#cr)return null;const t=new URLSearchParams(window.location.search);return t.has("annotation")?decodeURIComponent(t.get("annotation")):null}get#cr(){return Boolean(this.#At.getAttribute("ignore_annotation_parameter"))}}class sS{constructor(t){this._editorHTMLElement=t}startWait(){this._editorHTMLElement.classList.add("textae-editor--wait")}endWait(){this._editorHTMLElement.classList.remove("textae-editor--wait")}}function oS(t){return t.length?ot`
907
+ `}}class V_ extends Fw{#Q;#Ht;#ni;#ii;#ei;#jo;constructor(t,e,i,n,s){super(),this.#Q=t,this.#Ht=e,this.#ni=i,this.#ii=n,this.#ei=s,this.#jo=new W_(t,(t,e,i,n)=>{if(i===n)return;const s=this.#ei.factory.changeTextAndMoveSpanCommand(t,e,n);this.#ei.invoke(s)})}bindMouseEvents(){const t=[];return t.push(r()(this.#Q,".textae-editor__text-box","click",()=>this.#Bo())),t}applyTextSelectionWithTouchDevice(){this.#ii.updateButtonsToOperateSpanWithTouchDevice(!1,!1,!1,this.#qo)}editTextWithTouchDevice(){this.#Bo()}#Bo(){if(!this.#qo)return;const{begin:t,end:e}=this.#Ht.getTextSelection(this.#ni,this.#ii.textSelectionAdjuster);if(!this.#Ht.validateEditableText(t,e))return!1;const i=this.#Ht.getTextBetween(t,e);this.#jo.open(t,e,i)}get#qo(){return!!Bw(this.#O)&&!!this.#Ht.hasCharacters(this.#ni)}get#O(){return this.#Q.querySelector(".textae-editor__text-box")}}function Y_(t,e){let i=0;return function t(n){for(const s of n.childNodes)if(s.nodeType===Node.TEXT_NODE){const t=s.textContent.length;if(i+t>=e)return{node:s,offset:e-i};i+=t}else if(s.nodeType===Node.ELEMENT_NODE){const e=t(s);if(e)return e}return null}(t)}class U_ extends Fw{#Q;#Nt;#Ht;#Zo;#Fo;#ni;#ii;constructor(t,e,i,n,s){super(),this.#Q=t,this.#Nt=e,this.#Ht=i,this.#ni=n,this.#ii=s}get selectedText(){return void 0===this.#Zo||void 0===this.#Fo?{status:"unselected"}:this.#Ht.isBoundaryCrossingWithOtherSpans(this.#Zo,this.#Fo)?{status:"cross boundary detected"}:{begin:this.#Zo,end:this.#Fo,status:"selected"}}updateSelectedTextOffsets(){const t=document.getSelection();if(t&&t.rangeCount>0){const e=t.getRangeAt(0),i=this.#Q.querySelector(".textae-editor__text-box");if(i.contains(e.startContainer)&&i.contains(e.endContainer)){const{begin:e,end:n}=this.#Ht.getTextSelection(this.#ni,this.#ii.textSelectionAdjuster);!function(t,e,i,n){const s=Y_(e,i),o=Y_(e,n),r=document.createRange();r.setStart(s.node,s.offset),r.setEnd(o.node,o.offset),t.removeAllRanges(),t.addRange(r)}(t,i,e,n),this.#Zo=e,this.#Fo=n}}else this.#Zo=void 0,this.#Fo=void 0;this.#Nt.emit("textae-event.editor.selected-text.change")}}class G_{static createTermEditMode(t,e,i,n,s,o,r,a){return new H_(t,e,i,n,s,o,r,a)}static createBlockEditMode(t,e,i,n,s,o,r,a){return new B_(t,e,i,n,s,o,r,a)}static createRelationEditMode(t,e,i,n,s,o,r){return new Z_(t,e,i,n,s,o,r)}static createTextEditMode(t,e,i,n,s){return new V_(t,e,i,n,s)}static createViewMode(t,e,i,n,s){return new U_(t,e,i,n,s)}}class K_{#En;#Xo;#Ho;#Wo;#Vo;#Yo;constructor(t,e,i,n,s,o,r){this.#En=t,this.#Xo=e,this.#Ho=i,this.#Wo=n,this.#Vo=s,this.#Yo=o;const a=Ui(()=>this.#Uo.updateSelectedTextOffsets());document.addEventListener("selectionchange",a),r.on("textae-event.editor.relation.click",(t,e)=>this.#Uo.relationClicked(t,e)).on("textae-event.editor.relation-bollard.click",(t,e)=>this.#Uo.relationBollardClicked(e)),je(this,()=>this.#Uo,["showPallet","hidePallet","selectLeftAttributeTab","selectRightAttributeTab","createSpanWithTouchDevice","expandSpanWithTouchDevice","shrinkSpanWithTouchDevice","editTextWithTouchDevice","applyTextSelectionWithTouchDevice","editProperties","manipulateAttribute"])}get isEditDenotation(){return this.#En.currentState===vn}get isTypeValuesPalletShown(){return this.#Uo.isPalletShown}get#Uo(){switch(this.#En.currentState){case vn:return this.#Xo;case yn:return this.#Ho;case On:return this.#Wo;case bn:return this.#Vo;default:return this.#Yo}}}class J_{constructor(t){this._editorHTMLElement=t}clear(){for(const t of this._editorHTMLElement.classList)t.startsWith("textae-editor__mode")&&this._editorHTMLElement.classList.remove(t)}setFor(t){this._editorHTMLElement.classList.add(`textae-editor__mode--${t}`)}}class tS{#Go;constructor(t,e,i,n,s,o,r){this.#Go=[];const a=new J_(t);e.on("textae-event.edit-mode.transition",(t,e)=>{switch(this.#Ko(),a.clear(),t){case gn:i.typeGap.show=e,e?a.setFor("view-with-relation"):a.setFor("view-without-relation");break;case vn:i.typeGap.show=e,this.#Go=n.bindMouseEvents(),e?a.setFor("denotation-with-relation"):a.setFor("denotation-without-relation");break;case yn:i.typeGap.show=e,this.#Go=s.bindMouseEvents(),e?a.setFor("block-with-relation"):a.setFor("block-without-relation");break;case On:i.typeGap.show=!0,this.#Go=o.bindMouseEvents(),a.setFor("relation");break;case bn:i.typeGap.show=e,this.#Go=r.bindMouseEvents(),e?a.setFor("text-with-relation"):a.setFor("text-without-relation");break;default:throw new Error(`Unknown mode: ${t}`)}})}#Ko(){for(const t of this.#Go)t.destroy();this.#Go=[]}}class eS{#Jo;#Ht;#En;#Yo;#tr;constructor(t,i,n,s,o,r,a){this.#Ht=o;const l=new qe,c=new Wi(t,i,s,o,a),h=new sw(s,c,a,o.denotationDefinitionContainer,o.attributeDefinitionContainer,o.typeDictionary),u=new Lx(s,t,r.statusBar),d=new xw(s,u,o),f=new Qw,p=new Dw(o.relationInstanceContainer,s,f);this.#En=p;const m=new nw(s,a,h,d,u,o.typeDictionary,f,p),g=G_.createTermEditMode(t,s,o,a,l,c,m,n),v=G_.createBlockEditMode(t,s,o,a,l,c,m,n),y=G_.createRelationEditMode(t,s,o,a,c,m,n),O=G_.createTextEditMode(t,o,l,m,c),b=G_.createViewMode(t,s,o,l,m);this.#Yo=b;const x=new K_(p,g,v,y,O,b,s),w=new Rw(r,p,o.relationInstanceContainer,()=>x.hidePallet());s.on("textae-event.annotation-data.all.change",t=>{r.isEditMode&&t&&e().success("track annotations have been merged to root annotations."),w.reset()}),this.#tr=w;const _=new xn(t,s,o,a,c,l,f,h,m,x),S=new Aw(s),k=new vx(s,S,o,()=>u.annotation,()=>u.configuration,r.saveTo,d,m);new ow(s,m,k,r.saveTo,d),new tS(t,s,o,g,v,y,O),function(t,i,n,s,o,r,a,l){t.on("textae-event.resource.annotation.load.success",c=>{if(!c.data.config&&i.config)n.loadConfiguration(i.config,c);else{if(Qx(c.data),c.data.config&&"object"!=typeof c.data.config)return void e().error("configuration in annotation file is invalid.");const n=Mx(c.data,c.data.config);if(n){if(yx(n,s,o,r,c.data,a),t.emit("textae-event.configuration.reset"),i.isFocusFirstDenotation){const t=r.spanInstanceContainer.allDenotationSpans.at(0);t&&t.focus()}l.annotation=c}}}).on("textae-event.resource.configuration.load.success",(i,n=null)=>{if("object"!=typeof i.data)return void e().error(`${i.displayName} is not a configuration file or its format is invalid.`);n&&Qx(n.data);const c=n&&n.data||{...l.annotation,...r.externalFormat},h=Mx(c,i.data);h&&(yx(h,s,o,r,c,a),t.emit("textae-event.configuration.reset"),n&&(l.annotation=n),l.configuration=i)})}(s,r,S,m,l,o,f,u);const $=new vw(c,_,k,m,o,x,w),C=new fw(s,m,$).el;switch(t.insertBefore(C,t.childNodes[0]),r.control){case"hidden":t.classList.add("textae-editor--control-hidden");break;case"visible":t.classList.add("textae-editor--control-visible");break;default:r.isEditMode||t.classList.add("textae-editor--control-hidden")}o.toolBarHeight=C.getBoundingClientRect().height,function(t,i,n,s,o,r,a){switch(r.resourceType){case ux.QUERY_PARAMETER:{const l=r.annotation();l?Dx(dx.createParameterSource(l),r.config,n,s,t,i,a,o):e().error("failed to load annotation from query parameter.");break}case ux.INLINE:{const l=r.annotation();l?Dx(dx.createInlineSource(l),r.config,n,s,t,i,a,o):e().error("failed to load annotation from directly included in the div element.");break}case ux.REMOTE_URL:n.loadAnnotation(r.annotationURL);break;default:r.config?n.loadConfiguration(r.config):yx(o.defaultConfiguration,s,t,i,o.defaultAnnotation,a)}}(l,o,S,m,u,r,f);const T=new mw(t,m,$);t.appendChild(T.el),t.addEventListener("keyup",t=>{T.hide(),_.isActive&&new gw(c,_,k,f,x,w).handle(t)}),je(this,()=>_,["copyEntitiesToSystemClipboard","cutEntitiesToSystemClipboard","pasteEntitiesFromSystemClipboard","activate","deactivate","applyTextSelectionWithTouchDevice"]),this.#Jo=T}showContextMenu(t){this.#Jo.show(t)}hideContextMenu(){this.#Jo.hide()}focusDenotation(t){this.#tr.toTermEditMode(),this.#Ht.focusDenotation(t)}getSelectedText(){return this.#En.currentState===gn?this.#Yo.selectedText:{status:"unselected"}}}var iS=i(7007);class nS{#Ki;#er;constructor(t,e,i){if(i)this.#Ki=i;else if(e)this.#er=e;else{const e=this.#ir(t);e&&(this.#Ki=e)}}get isLoaded(){return Boolean(this.#Ki)}get isRemote(){return Boolean(this.#er)}get URL(){return this.#er}annotation(){try{return _n(this.#Ki)?JSON.parse(this.#Ki):ub.parse(this.#Ki)}catch{return null}}#ir(t){const e=t.textContent;return t.innerHTML="",e}}class sS{#At;#nr;constructor(t){this.#At=t,this.#nr=new nS(this.#At,this.#er,this.#sr)}get resourceType(){return this.#sr?ux.QUERY_PARAMETER:this.#nr.isLoaded?ux.INLINE:this.annotationURL?ux.REMOTE_URL:ux.UNKNOWN}get annotationURL(){return this.#nr.isRemote?this.#nr.URL:null}get config(){return this.#or("config")}get configLock(){if(this.#er){const t=new URLSearchParams(this.#er.split("?")[1]);if(t.has("config_lock"))return t.get("config_lock")}return this.#rr("config_lock")}get control(){return this.#rr("control")}get inspect(){return this.#rr("inspect")}get isEditMode(){switch(this.#rr("mode")){case"edit":case"term-edit":case"block-edit":case"relation-edit":case"text-edit":return!0;default:return!1}}get isEditTermMode(){return"edit"===this.#rr("mode")||"term-edit"===this.#rr("mode")}get isEditBlockMode(){return"block-edit"===this.#rr("mode")}get isEditRelationMode(){return"relation-edit"===this.#rr("mode")}get isTextEditMode(){return"text-edit"===this.#rr("mode")}get statusBar(){return this.#rr("status_bar")}get saveTo(){return this.#or("save_to")}get isFocusFirstDenotation(){const t="true"===this.#rr("focus_first_denotation");if(t&&this.isEditMode)throw new Error("focus_first_denotation is only available in view mode.");return t}get additionalPaddingTop(){return this.#rr("padding_top")?parseInt(this.#rr("padding_top"),10):0}get#er(){return this.#or("source")||this.#or("target")}annotation(){return this.#nr.isLoaded?this.#nr.annotation():null}#rr(t){return this.#At.hasAttribute(t)?this.#At.getAttribute(t):null}#or(t){return this.#At.hasAttribute(t)?decodeURIComponent(this.#At.getAttribute(t)):null}get#sr(){if(this.#ar)return null;const t=new URLSearchParams(window.location.search);return t.has("annotation")?decodeURIComponent(t.get("annotation")):null}get#ar(){return Boolean(this.#At.getAttribute("ignore_annotation_parameter"))}}class oS{constructor(t){this._editorHTMLElement=t}startWait(){this._editorHTMLElement.classList.add("textae-editor--wait")}endWait(){this._editorHTMLElement.classList.remove("textae-editor--wait")}}function rS(t){return t.length?ot`
908
908
  <table>
909
909
  <caption>Denotations or Blocks or Typesettings with boundary-cross.</caption>
910
910
  <thead>
@@ -928,7 +928,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
928
928
  `}(t,e,i,n,s))}
929
929
  </tbody>
930
930
  </table>
931
- `:""}function rS(t){return t.length?ot`
931
+ `:""}function aS(t){return t.length?ot`
932
932
  <table>
933
933
  <caption>Duplicated attributes.</caption>
934
934
  <thead>
@@ -950,7 +950,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
950
950
  `}(t,e,i,n))}
951
951
  </tbody>
952
952
  </table>
953
- `:""}function aS(t){return t.length?ot`
953
+ `:""}function lS(t){return t.length?ot`
954
954
  <table>
955
955
  <caption>Duplicated IDs in Denotations and Blocks.</caption>
956
956
  <thead>
@@ -974,7 +974,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
974
974
  `}(t,e,i,n))}
975
975
  </tbody>
976
976
  </table>
977
- `:""}function lS(t){return t.length?ot`
977
+ `:""}function cS(t){return t.length?ot`
978
978
  <table>
979
979
  <caption>Duplicated range blocks.</caption>
980
980
  <thead>
@@ -996,7 +996,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
996
996
  `}(t,e,i))}
997
997
  </tbody>
998
998
  </table>
999
- `:""}function cS(t){return t.length?ot`
999
+ `:""}function hS(t){return t.length?ot`
1000
1000
  <table>
1001
1001
  <caption>Out of text blocks.</caption>
1002
1002
  <thead>
@@ -1018,7 +1018,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
1018
1018
  `}(t,e,i))}
1019
1019
  </tbody>
1020
1020
  </table>
1021
- `:""}function hS(t){return t.length?ot`
1021
+ `:""}function uS(t){return t.length?ot`
1022
1022
  <table>
1023
1023
  <caption>Out of text denotations.</caption>
1024
1024
  <thead>
@@ -1039,7 +1039,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
1039
1039
  </tr>
1040
1040
  `}(t,e,i))}
1041
1041
  </tbody>
1042
- </table>`:""}function uS(t){return t.length?ot`
1042
+ </table>`:""}function dS(t){return t.length?ot`
1043
1043
  <table>
1044
1044
  <caption>Out of text typesettings.</caption>
1045
1045
  <thead>
@@ -1061,7 +1061,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
1061
1061
  `}(t,e,i))}
1062
1062
  </tbody>
1063
1063
  </table>
1064
- `:""}function dS(t){return t.length?ot`
1064
+ `:""}function fS(t){return t.length?ot`
1065
1065
  <table>
1066
1066
  <caption>Referenced entities do not exist.</caption>
1067
1067
  <thead>
@@ -1085,7 +1085,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
1085
1085
  `}(t,e,i,n,s,o,r))}
1086
1086
  </tbody>
1087
1087
  </table>
1088
- `:""}function fS(t){return t.length?ot`
1088
+ `:""}function pS(t){return t.length?ot`
1089
1089
  <table>
1090
1090
  <caption>Wrong range blocks.</caption>
1091
1091
  <thead>
@@ -1107,7 +1107,7 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
1107
1107
  `}(t,e,i))}
1108
1108
  </tbody>
1109
1109
  </table>
1110
- `:""}function pS(t){return t.length?ot`
1110
+ `:""}function mS(t){return t.length?ot`
1111
1111
  <table>
1112
1112
  <caption>Wrong range denotations.</caption>
1113
1113
  <thead>
@@ -1128,4 +1128,4 @@ var i,n=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?
1128
1128
  </tr>
1129
1129
  `}(t,e,i))}
1130
1130
  </tbody>
1131
- </table>`:""}class mS extends u{constructor(t){const e=t.map(({name:t,wrongRangeDenotations:e,outOfTextDenotations:i,wrongRangeBlocks:n,outOfTextBlocks:s,duplicatedRangeBlocks:o,wrongRangeTypesettings:r,outOfTextTypesettings:a,duplicatedIDs:l,boundaryCrossingSpans:c,referencedEntitiesDoNotExist:h,duplicatedAttributes:u},d)=>`\n ${1===d?'\n <div class="textae-editor__validate-dialog__content">\n <h1>Track annotations will be merged to the root annotations.</h1>\n </div>':""}\n <div class="textae-editor__validate-dialog__content">\n <h2>${t}</h2>\n ${pS(e)}\n ${hS(i)}\n ${fS(n)}\n ${cS(s)}\n ${lS(o)}\n ${function(t){return t.length?`\n <table>\n <caption>Wrong range typesettings.</caption>\n <thead>\n <tr>\n <th class="id">id</th>\n <th class="range">begin</th>\n <th class="range">end</th>\n <th>style</th>\n </tr>\n </thead>\n <tbody>\n ${t.map(({id:t,span:e,style:i})=>`\n <tr>\n <td>${t||""}</td>\n <td class="alert">${e.begin}</td>\n <td class="alert">${e.end}</td>\n <td>${i}</td>\n </tr>\n `).join("\n")}\n </tbody>\n </table>\n `:""}(r)}\n ${uS(a)}\n ${aS(l)}\n ${oS(c)}\n ${dS(h)}\n ${rS(u)}\n </div>\n `).join("\n");super("The following erroneous annotations ignored",e,{maxWidth:900})}}class gS{#Nt;#hr;#ur;constructor(t,e,i){this.#Nt=t,this.#hr=e,this.#ur=i;for(const i of e)t.on(i,this.#ur)}dispose(){for(const t of this.#hr)this.#Nt.off(t,this.#ur)}}class vS{#dr;#fr;#ur;constructor(t,e,i){this.#dr=t,this.#fr=e,this.#ur=i,this.#pr()}dispose(){this.#dr.removeEventListener(this.#fr,this.#ur)}#pr(){this.#dr.addEventListener(this.#fr,this.#ur)}}class yS{#a;#Oe;#mr;constructor(t,e,i){this.#a=t,this.#Oe=e,this.#mr=i.getInstanceContainerFor(e)}add(t){const e=this.#mr.get(t);console.assert(e,`${t} is not a instance of ${this.#Oe}.`),e.isSelected||(e.select(),this.triggerChange())}has(t){const e=this.#mr.get(t);return!!e&&e.isSelected}contains(t){for(const e of this.#mr.selectedItems)if(t(e))return!0;return!1}get all(){return this.#mr.selectedItems}get size(){return this.#mr.selectedItems.length}get some(){return this.size>0}get singleId(){const t=this.single;return t?t.id:null}get single(){return 1===this.size?this.#mr.selectedItems[0]:null}toggle(t){this.has(t)?this.remove(t):this.add(t)}remove(t){this.has(t)&&(this.#mr.get(t).deselect(),this.triggerChange())}removeInstance(t){this.remove(t.id)}removeAll(){if(0!==this.size){for(const t of this.all)t.deselect();this.triggerChange()}}triggerChange(){this.#a.emit(`textae-event.selection.${this.#Oe}.change`)}}class OS extends yS{selectedWithAttributeOf(t){return this.all.some(e=>e.attributes.some(e=>e.pred===t))}onlySelectedWithJustOneAttributeOf(t){return this.all.every(e=>1===e.attributes.filter(e=>e.pred===t).length)}selectedWithoutAttributeOf(t){return this.all.some(e=>!e.attributes.some(e=>e.pred===t))}isDuplicatedPredAttributeSelected(t){return this.all.some(e=>e.attributes.filter(e=>e.pred===t).length>1)}findSelectedWithSamePredicateAttribute(t){return this.all.find(e=>e.attributes.find(e=>e.pred===t))}findSelectedAttributeWithSamePredicate(t){const e=this.findSelectedWithSamePredicateAttribute(t);if(e)return e.attributes.find(e=>e.pred===t)}}class bS{#Ht;#Nt;constructor(t,e){this.#Nt=t,this.#Ht=e,this.span=new yS(t,"span",e),this.entity=new OS(t,"entity",e),this.relation=new OS(t,"relation",e),t.on("textae-event.annotation-data.span.remove",t=>this.span.removeInstance(t)).on("textae-event.annotation-data.entity.remove",t=>this.entity.removeInstance(t)).on("textae-event.annotation-data.relation.remove",t=>this.relation.removeInstance(t)).on("textae-event.annotation-data.all.change",()=>{this.span.triggerChange(),this.entity.triggerChange(),this.relation.triggerChange()})}get copyingTargets(){return[...this.#gr].map(({typeValues:t})=>t)}get cuttingTargets(){return this.#gr}add(t,e){console.assert(this[t]);for(const i of e)this[t].add(i);"entity"===t&&this.#vr(e[e.length-1])&&this.#Nt.emit("textae-event.selection-model.last-selected-denotation-id.change",e[e.length-1])}remove(t,e){console.assert(this[t]),this[t].remove(e)}removeAll(){this.span.removeAll(),this.entity.removeAll(),this.relation.removeAll()}selectSpan(t){this.removeAll(),this.span.add(t)}selectSpanRange(t){this.removeAll();for(const e of t)this.span.add(e)}selectEntity(t){this.removeAll(),this.entity.add(t),this.#vr(t)&&this.#Nt.emit("textae-event.selection-model.last-selected-denotation-id.change",t)}selectDenotation(t){if(!this.#vr(t))throw new Error(`Denotation ${t} not found`);this.selectEntity(t)}selectRelation(t){this.removeAll(),this.relation.add(t)}get#gr(){return new Set(this.span.all.map(t=>t.entities).flat().concat(this.entity.all))}#vr(t){return this.#Ht.entityInstanceContainer.hasDenotation(t)}}class xS{#At;#Ht;#Nt;#yr;#Or;#br;#xr;constructor(t,i,n,s,o){t.tabIndex=-1,jx()&&t.classList.add("textae-editor--android"),function(t){t.addEventListener("mousedown",t=>{t.shiftKey&&t.preventDefault()}),r()(t,".textae-editor__signboard","mousedown",t=>t.preventDefault())}(t);const a=new eS.EventEmitter;!function(t){t.on("textae-event.resource.annotation.format.error",({displayName:t})=>e().error(`${t} is not a annotation file or its format is invalid.`)).on("textae-event.resource.configuration.format.error",({displayName:t})=>e().error(`${t} is not a configuration file or its format is invalid.!`)).on("textae-event.annotation-data.all.change",(t,e)=>{e.some(t=>t.hasError)&&new mS(e).open()}).on("textae-event.annotation-data.events-observer.unsaved-change",t=>{window.onbeforeunload=jx()||t?()=>!0:null}),t.on("textae-event.clip-board.change",(t,e)=>{for(const e of t)e.startCut();for(const t of e)t.cancelCut()}),t.on("textae-event.commander.attributes.change",t=>{for(const e of t.reduce((t,e)=>t.add(e.subjectInstance),new Set))e.updateElement()})}(a);const l=new sS(t);!function(t,e){t.on("textae-event.resource.startLoad",()=>e.startWait()).on("textae-event.resource.endLoad",()=>e.endWait()).on("textae-event.resource.startSave",()=>e.startWait()).on("textae-event.resource.endSave",()=>e.endWait())}(a,l);const c=new nS(t),h=new ze(i,t,a,l,s,o,"true"===c.configLock,c.additionalPaddingTop);this.#At=t,this.#Ht=h,this.#Nt=a;const u=new bS(a,h);if(this.#xr=new tS(t,i,n,a,h,c,u),c.inspect){const t=t=>{const e=document.querySelector(`#${c.inspect}`);e&&(e.textContent=JSON.stringify(t,null,2))};this.#wr(t)}this.#br=this.#_r(h,t),je(this,()=>this.#xr,["copyEntitiesToSystemClipboard","cutEntitiesToSystemClipboard","pasteEntitiesFromSystemClipboard","activate","deactivate","applyTextSelectionWithTouchDevice","showContextMenu","hideContextMenu","focusDenotation"]),je(this,()=>u,["selectDenotation"]),je(this,()=>h,["drawGridsInSight","reLayout"])}updateDenotationEntitiesWidth(){for(const t of this.#Ht.spanInstanceContainer.allDenotationSpans)t.updateDenotationEntitiesWidth()}load(t){px(this.#Nt,t)}setInspector(t){this.#yr&&(this.#yr.dispose(),this.#yr=null),"function"==typeof t&&(this.#yr=this.#wr(t))}setLastSelectedDenotationIDCallback(t){this.#Or&&(this.#Or.dispose(),this.#Or=null),"function"==typeof t&&(this.#Or=new gS(this.#Nt,["textae-event.selection-model.last-selected-denotation-id.change"],t))}setAutocompletionFunction(t){if("function"!=typeof t)throw new TypeError("autocompletionFunction must be a function");this.#Ht.autocompletionFunction=t}get HTMLElementID(){return this.#At.id}dispose(){for(const t of this.#br)t.dispose()}focusDenotation(t){if(!this.#Ht.denotations.has(t))throw new Error(`Denotation ${t} not found`);this.#xr.focusDenotation(t)}#_r(t,e){const i=new Set,n=()=>t.drawGridsInSight(),s=new vS(e,"scroll",n);i.add(s);const o=e.closest(".textae-container");if(o){const t=new vS(o,"scroll",n);i.add(t)}return i}#wr(t){const e=function(t){let e=t;return function(t,i){bw(e,t)&&(e=t,i(t))}}(this.#Sr);return new gS(this.#Nt,["textae-event.annotation-data.events-observer.change","textae-event.editor.selected-text.change"],()=>e(this.#Sr,t))}get#Sr(){return{...this.#Ht.externalFormat,selectedText:this.#xr.getSelectedText()}}}function wS(t,e){const i=function(t,e){return new xS(t,e.nextID,e.mousePoint,()=>{for(const t of document.querySelectorAll(".ui-dialog"))t.classList.add("textae-editor--wait");for(const t of document.querySelectorAll(".ui-widget-overlay"))t.classList.add("textae-editor--wait")},()=>{for(const t of document.querySelectorAll(".ui-dialog"))t.classList.remove("textae-editor--wait");for(const t of document.querySelectorAll(".ui-widget-overlay"))t.classList.remove("textae-editor--wait")})}(e,t);return t.registerEditor(e,i),e.dataset.textaeInitialized=!0,i}class _S{constructor(t){this._editor=t}set annotation(t){this._editor.load(t)}set inspectCallback(t){this._editor.setInspector(t)}set lastSelectedDenotationIDCallback(t){this._editor.setLastSelectedDenotationIDCallback(t)}set autocompletionCallback(t){this._editor.setAutocompletionFunction(t)}get id(){return this._editor.HTMLElementID}focusDenotation(t){this._editor.focusDenotation(t)}selectDenotation(t){this._editor.selectDenotation(t)}}const SS=new class{#kr;#$r;#so;constructor(){this.#kr=new y,this.#$r=new b,this.#so=x,window.addEventListener("load",()=>{return t=this.#kr,document.body.addEventListener("focus",e=>{const i=e.target.closest(".textae-editor");i&&(t.selected&&t.selected!==i&&(t.selected=null),t.selected=i)},!0),document.body.addEventListener("click",e=>{null===e.target.closest(".textae-editor__dialog")&&null===e.target.closest(".ui-autocomplete")&&null===e.target.closest(".ui-widget-overlay")&&null===e.target.closest(".textae-editor__pallet__content")&&(t.has(e.target.closest(".textae-editor"))||t.selected&&(t.selected=null))}),void new MutationObserver(e=>{for(const i of e)if("childList"===i.type)for(const e of i.removedNodes)if(e instanceof HTMLElement){e.classList.contains("textae-editor")&&t.remove(e);for(const i of e.querySelectorAll(".textae-editor"))t.remove(i)}}).observe(document.body,{childList:!0,subtree:!0});var t}),window.addEventListener("resize",m()(()=>{this.#kr.reLayout(),this.#kr.drawGridsInSight(),this.#kr.updateDenotationEntitiesWidth()},500))}get nextID(){return this.#kr.nextID}get mousePoint(){return this.#so}registerEditor(t,e){this.#$r.setObserver(t),this.#kr.set(t,e)}};function kS(){return e().set("notifier","position","top-right"),Array.from(document.querySelectorAll(".textae-editor")).filter(t=>!t.dataset.textaeInitialized).map(t=>wS(SS,t)).map(t=>new _S(t))}document.addEventListener("DOMContentLoaded",kS),window.initializeTextAEEditor=kS,console.log(`TextAE Version ${Ji} loaded.`)})()})();
1131
+ </table>`:""}class gS extends u{constructor(t){const e=t.map(({name:t,wrongRangeDenotations:e,outOfTextDenotations:i,wrongRangeBlocks:n,outOfTextBlocks:s,duplicatedRangeBlocks:o,wrongRangeTypesettings:r,outOfTextTypesettings:a,duplicatedIDs:l,boundaryCrossingSpans:c,referencedEntitiesDoNotExist:h,duplicatedAttributes:u},d)=>`\n ${1===d?'\n <div class="textae-editor__validate-dialog__content">\n <h1>Track annotations will be merged to the root annotations.</h1>\n </div>':""}\n <div class="textae-editor__validate-dialog__content">\n <h2>${t}</h2>\n ${mS(e)}\n ${uS(i)}\n ${pS(n)}\n ${hS(s)}\n ${cS(o)}\n ${function(t){return t.length?`\n <table>\n <caption>Wrong range typesettings.</caption>\n <thead>\n <tr>\n <th class="id">id</th>\n <th class="range">begin</th>\n <th class="range">end</th>\n <th>style</th>\n </tr>\n </thead>\n <tbody>\n ${t.map(({id:t,span:e,style:i})=>`\n <tr>\n <td>${t||""}</td>\n <td class="alert">${e.begin}</td>\n <td class="alert">${e.end}</td>\n <td>${i}</td>\n </tr>\n `).join("\n")}\n </tbody>\n </table>\n `:""}(r)}\n ${dS(a)}\n ${lS(l)}\n ${rS(c)}\n ${fS(h)}\n ${aS(u)}\n </div>\n `).join("\n");super("The following erroneous annotations ignored",e,{maxWidth:900})}}class vS{#Nt;#lr;#cr;constructor(t,e,i){this.#Nt=t,this.#lr=e,this.#cr=i;for(const i of e)t.on(i,this.#cr)}dispose(){for(const t of this.#lr)this.#Nt.off(t,this.#cr)}}class yS{#hr;#ur;#cr;constructor(t,e,i){this.#hr=t,this.#ur=e,this.#cr=i,this.#dr()}dispose(){this.#hr.removeEventListener(this.#ur,this.#cr)}#dr(){this.#hr.addEventListener(this.#ur,this.#cr)}}class OS{#a;#Oe;#fr;constructor(t,e,i){this.#a=t,this.#Oe=e,this.#fr=i.getInstanceContainerFor(e)}add(t){const e=this.#fr.get(t);console.assert(e,`${t} is not a instance of ${this.#Oe}.`),e.isSelected||(e.select(),this.triggerChange())}has(t){const e=this.#fr.get(t);return!!e&&e.isSelected}contains(t){for(const e of this.#fr.selectedItems)if(t(e))return!0;return!1}get all(){return this.#fr.selectedItems}get size(){return this.#fr.selectedItems.length}get some(){return this.size>0}get singleId(){const t=this.single;return t?t.id:null}get single(){return 1===this.size?this.#fr.selectedItems[0]:null}toggle(t){this.has(t)?this.remove(t):this.add(t)}remove(t){this.has(t)&&(this.#fr.get(t).deselect(),this.triggerChange())}removeInstance(t){this.remove(t.id)}removeAll(){if(0!==this.size){for(const t of this.all)t.deselect();this.triggerChange()}}triggerChange(){this.#a.emit(`textae-event.selection.${this.#Oe}.change`)}}class bS extends OS{selectedWithAttributeOf(t){return this.all.some(e=>e.attributes.some(e=>e.pred===t))}onlySelectedWithJustOneAttributeOf(t){return this.all.every(e=>1===e.attributes.filter(e=>e.pred===t).length)}selectedWithoutAttributeOf(t){return this.all.some(e=>!e.attributes.some(e=>e.pred===t))}isDuplicatedPredAttributeSelected(t){return this.all.some(e=>e.attributes.filter(e=>e.pred===t).length>1)}findSelectedWithSamePredicateAttribute(t){return this.all.find(e=>e.attributes.find(e=>e.pred===t))}findSelectedAttributeWithSamePredicate(t){const e=this.findSelectedWithSamePredicateAttribute(t);if(e)return e.attributes.find(e=>e.pred===t)}}class xS{#Ht;#Nt;constructor(t,e){this.#Nt=t,this.#Ht=e,this.span=new OS(t,"span",e),this.entity=new bS(t,"entity",e),this.relation=new bS(t,"relation",e),t.on("textae-event.annotation-data.span.remove",t=>this.span.removeInstance(t)).on("textae-event.annotation-data.entity.remove",t=>this.entity.removeInstance(t)).on("textae-event.annotation-data.relation.remove",t=>this.relation.removeInstance(t)).on("textae-event.annotation-data.all.change",()=>{this.span.triggerChange(),this.entity.triggerChange(),this.relation.triggerChange()})}get copyingTargets(){return[...this.#pr].map(({typeValues:t})=>t)}get cuttingTargets(){return this.#pr}add(t,e){console.assert(this[t]);for(const i of e)this[t].add(i);"entity"===t&&this.#mr(e[e.length-1])&&this.#Nt.emit("textae-event.selection-model.last-selected-denotation-id.change",e[e.length-1])}remove(t,e){console.assert(this[t]),this[t].remove(e)}removeAll(){this.span.removeAll(),this.entity.removeAll(),this.relation.removeAll()}selectSpan(t){this.removeAll(),this.span.add(t)}selectSpanRange(t){this.removeAll();for(const e of t)this.span.add(e)}selectEntity(t){this.removeAll(),this.entity.add(t),this.#mr(t)&&this.#Nt.emit("textae-event.selection-model.last-selected-denotation-id.change",t)}selectDenotation(t){if(!this.#mr(t))throw new Error(`Denotation ${t} not found`);this.selectEntity(t)}selectRelation(t){this.removeAll(),this.relation.add(t)}get#pr(){return new Set(this.span.all.map(t=>t.entities).flat().concat(this.entity.all))}#mr(t){return this.#Ht.entityInstanceContainer.hasDenotation(t)}}class wS{#At;#Ht;#Nt;#gr;#vr;#yr;#Or;constructor(t,i,n,s,o){t.tabIndex=-1,jx()&&t.classList.add("textae-editor--android"),function(t){t.addEventListener("mousedown",t=>{t.shiftKey&&t.preventDefault()}),r()(t,".textae-editor__signboard","mousedown",t=>t.preventDefault())}(t);const a=new iS.EventEmitter;!function(t){t.on("textae-event.resource.annotation.format.error",({displayName:t})=>e().error(`${t} is not a annotation file or its format is invalid.`)).on("textae-event.resource.configuration.format.error",({displayName:t})=>e().error(`${t} is not a configuration file or its format is invalid.!`)).on("textae-event.annotation-data.all.change",(t,e)=>{e.some(t=>t.hasError)&&new gS(e).open()}).on("textae-event.annotation-data.events-observer.unsaved-change",t=>{window.onbeforeunload=jx()||t?()=>!0:null}),t.on("textae-event.clip-board.change",(t,e)=>{for(const e of t)e.startCut();for(const t of e)t.cancelCut()}),t.on("textae-event.commander.attributes.change",t=>{for(const e of t.reduce((t,e)=>t.add(e.subjectInstance),new Set))e.updateElement()})}(a);const l=new oS(t);!function(t,e){t.on("textae-event.resource.startLoad",()=>e.startWait()).on("textae-event.resource.endLoad",()=>e.endWait()).on("textae-event.resource.startSave",()=>e.startWait()).on("textae-event.resource.endSave",()=>e.endWait())}(a,l);const c=new sS(t),h=new ze(i,t,a,l,s,o,"true"===c.configLock,c.additionalPaddingTop);this.#At=t,this.#Ht=h,this.#Nt=a;const u=new xS(a,h);if(this.#Or=new eS(t,i,n,a,h,c,u),c.inspect){const t=t=>{const e=document.querySelector(`#${c.inspect}`);e&&(e.textContent=JSON.stringify(t,null,2))};this.#br(t)}this.#yr=this.#xr(h,t),je(this,()=>this.#Or,["copyEntitiesToSystemClipboard","cutEntitiesToSystemClipboard","pasteEntitiesFromSystemClipboard","activate","deactivate","applyTextSelectionWithTouchDevice","showContextMenu","hideContextMenu","focusDenotation"]),je(this,()=>u,["selectDenotation"]),je(this,()=>h,["drawGridsInSight","reLayout"])}updateDenotationEntitiesWidth(){for(const t of this.#Ht.spanInstanceContainer.allDenotationSpans)t.updateDenotationEntitiesWidth()}load(t){px(this.#Nt,t)}setInspector(t){this.#gr&&(this.#gr.dispose(),this.#gr=null),"function"==typeof t&&(this.#gr=this.#br(t))}setLastSelectedDenotationIDCallback(t){this.#vr&&(this.#vr.dispose(),this.#vr=null),"function"==typeof t&&(this.#vr=new vS(this.#Nt,["textae-event.selection-model.last-selected-denotation-id.change"],t))}setAutocompletionFunction(t){if("function"!=typeof t)throw new TypeError("autocompletionFunction must be a function");this.#Ht.autocompletionFunction=t}get HTMLElementID(){return this.#At.id}dispose(){for(const t of this.#yr)t.dispose()}focusDenotation(t){if(!this.#Ht.denotations.has(t))throw new Error(`Denotation ${t} not found`);this.#Or.focusDenotation(t)}#xr(t,e){const i=new Set,n=()=>t.drawGridsInSight(),s=new yS(e,"scroll",n);i.add(s);const o=e.closest(".textae-container");if(o){const t=new yS(o,"scroll",n);i.add(t)}return i}#br(t){const e=function(t){let e=t;return function(t,i){bw(e,t)&&(e=t,i(t))}}(this.#wr);return new vS(this.#Nt,["textae-event.annotation-data.events-observer.change","textae-event.editor.selected-text.change"],()=>e(this.#wr,t))}get#wr(){return{...this.#Ht.externalFormat,selectedText:this.#Or.getSelectedText()}}}function _S(t,e){const i=function(t,e){return new wS(t,e.nextID,e.mousePoint,()=>{for(const t of document.querySelectorAll(".ui-dialog"))t.classList.add("textae-editor--wait");for(const t of document.querySelectorAll(".ui-widget-overlay"))t.classList.add("textae-editor--wait")},()=>{for(const t of document.querySelectorAll(".ui-dialog"))t.classList.remove("textae-editor--wait");for(const t of document.querySelectorAll(".ui-widget-overlay"))t.classList.remove("textae-editor--wait")})}(e,t);return t.registerEditor(e,i),e.dataset.textaeInitialized=!0,i}class SS{constructor(t){this._editor=t}set annotation(t){this._editor.load(t)}set inspectCallback(t){this._editor.setInspector(t)}set lastSelectedDenotationIDCallback(t){this._editor.setLastSelectedDenotationIDCallback(t)}set autocompletionCallback(t){this._editor.setAutocompletionFunction(t)}get id(){return this._editor.HTMLElementID}focusDenotation(t){this._editor.focusDenotation(t)}selectDenotation(t){this._editor.selectDenotation(t)}}const kS=new class{#_r;#Sr;#so;constructor(){this.#_r=new y,this.#Sr=new b,this.#so=x,window.addEventListener("load",()=>{return t=this.#_r,document.body.addEventListener("focus",e=>{const i=e.target.closest(".textae-editor");i&&(t.selected&&t.selected!==i&&(t.selected=null),t.selected=i)},!0),document.body.addEventListener("click",e=>{null===e.target.closest(".textae-editor__dialog")&&null===e.target.closest(".ui-autocomplete")&&null===e.target.closest(".ui-widget-overlay")&&null===e.target.closest(".textae-editor__pallet__content")&&(t.has(e.target.closest(".textae-editor"))||t.selected&&(t.selected=null))}),void new MutationObserver(e=>{for(const i of e)if("childList"===i.type)for(const e of i.removedNodes)if(e instanceof HTMLElement){e.classList.contains("textae-editor")&&t.remove(e);for(const i of e.querySelectorAll(".textae-editor"))t.remove(i)}}).observe(document.body,{childList:!0,subtree:!0});var t}),window.addEventListener("resize",m()(()=>{this.#_r.reLayout(),this.#_r.drawGridsInSight(),this.#_r.updateDenotationEntitiesWidth()},500))}get nextID(){return this.#_r.nextID}get mousePoint(){return this.#so}registerEditor(t,e){this.#Sr.setObserver(t),this.#_r.set(t,e)}};function $S(){return e().set("notifier","position","top-right"),Array.from(document.querySelectorAll(".textae-editor")).filter(t=>!t.dataset.textaeInitialized).map(t=>_S(kS,t)).map(t=>new SS(t))}document.addEventListener("DOMContentLoaded",$S),window.initializeTextAEEditor=$S,console.log(`TextAE Version ${Ji} loaded.`)})()})();