UNPKG

annotorious-tahqiq

Version:
3 lines 298 kB
/*! For license information please see index.js.LICENSE.txt */ (()=>{var t={144(){!function(){"use strict";const t="undefined"!=typeof window?window:Function("return this;")(),e=(e,n)=>((e,n)=>{let o=null!=n?n:t;for(let t=0;t<e.length&&null!=o;++t)o=o[e[t]];return o})(e.split("."),n),n=Object.keys,o=Object.hasOwnProperty,a=(t,e)=>o.call(t,e);let i=0;const r=t=>{const e=(new Date).getTime(),n=Math.floor(1e9*Math.random());return i++,t+"_"+n+i+String(e)},s=()=>({listeners:[],scriptId:r("tiny-script"),scriptLoaded:!1}),l=(()=>{let t=s();return{load:(e,n,o)=>{t.scriptLoaded?o():(t.listeners.push(o),e.getElementById(t.scriptId)||((e,n,o)=>{const a=n.createElement("script");a.referrerPolicy="origin",a.type="application/javascript",a.id=e,a.src=o;const i=()=>{a.removeEventListener("load",i),t.listeners.forEach(t=>t()),t.scriptLoaded=!0};a.addEventListener("load",i),n.head&&n.head.appendChild(a)})(t.scriptId,e,n))},reinitialize:()=>{t=s()}}})();var c;!function(t){t[t.Raw=0]="Raw",t[t.Initializing=1]="Initializing",t[t.Ready=2]="Ready"}(c||(c={}));const d=t=>e=>((t,e)=>a(t,e))(t,e)?t[e]:e,h=e,u=t=>t,p=d({false:!1}),g=d({true:!0,false:!1}),A=t=>/^\d+$/.test(t)?Number.parseInt(t,10):t,b={setup:h,toolbar:p,menubar:p,plugins:u,content_css:u,content_style:u,width:A,height:A,toolbar_mode:u,contextmenu:p,quickbars_insert_toolbar:p,quickbars_selection_toolbar:p,powerpaste_word_import:u,powerpaste_html_import:u,powerpaste_allow_local_images:g,resize:g,skin:u,skin_url:u,images_upload_url:u,images_upload_handler:h,images_upload_base_path:u,images_upload_credentials:g,images_reuse_filename:g,icons:u,icons_url:u},m={};class f extends HTMLElement{constructor(){super(),this._eventAttrHandler=t=>{t.forEach(t=>{var e;"attributes"===t.type&&t.target===this&&(null===(e=t.attributeName)||void 0===e?void 0:e.toLowerCase().startsWith("on-"))&&this._updateEventAttr(t.attributeName,this.getAttribute(t.attributeName))})},this._formDataHandler=t=>{const e=this.name;if(null!=e){const n=this.value;null!=n&&t.formData.append(e,n)}},this._status=c.Raw,this._shadowDom=this.attachShadow({mode:"open"}),this._form=null,this._eventHandlers={},this._mutationObserver=new MutationObserver(this._eventAttrHandler)}static get formAssociated(){return!0}static get observedAttributes(){return["form","readonly","autofocus","placeholder"].concat(["on-BeforePaste","on-Blur","on-Click","on-ContextMenu","on-Copy","on-Cut","on-Dblclick","on-Drag","on-DragDrop","on-DragEnd","on-DragGesture","on-DragOver","on-Drop","on-Focus","on-FocusIn","on-FocusOut","on-KeyDown","on-KeyPress","on-KeyUp","on-MouseDown","on-MouseEnter","on-MouseLeave","on-MouseMove","on-MouseOut","on-MouseOver","on-MouseUp","on-Paste","on-SelectionChange"]).concat(["on-Activate","on-AddUndo","on-BeforeAddUndo","on-BeforeExecCommand","on-BeforeGetContent","on-BeforeRenderUI","on-BeforeSetContent","on-Change","on-ClearUndos","on-Deactivate","on-Dirty","on-ExecCommand","on-GetContent","on-Hide","on-Init","on-LoadContent","on-NodeChange","on-PostProcess","on-PostRender","on-PreProcess","on-ProgressState","on-Redo","on-Remove","on-Reset","on-SaveContent","on-SetAttrib","on-ObjectResizeStart","on-ObjectResized","on-ObjectSelected","on-SetContent","on-Show","on-Submit","on-Undo","on-VisualAid"])}_updateEventAttr(t,n){const o=t.substring(3).toLowerCase(),a=null!==n?e(n):void 0,i="function"==typeof a?a:void 0;this._eventHandlers[o]!==i&&(this._editor&&this._eventHandlers[o]&&this._editor.off(o,this._eventHandlers[o]),i?(this._editor&&this._editor.on(o,i),this._eventHandlers[o]=i):delete this._eventHandlers[o])}_updateForm(){if(this.isConnected){const t=this.getAttribute("form"),e=null!==t?this.ownerDocument.querySelector("form#"+t):this.closest("form");this._form!==e&&(null!==this._form&&this._form.removeEventListener("formdata",this._formDataHandler),this._form=e,null!==this._form&&this._form.addEventListener("formdata",this._formDataHandler))}else null!==this._form&&(this._form.removeEventListener("formdata",this._formDataHandler),this._form=null)}_getTinymce(){return t.tinymce}_getConfig(){var t,e;const n=null!==(e=h(null!==(t=this.getAttribute("config"))&&void 0!==t?t:""))&&void 0!==e?e:{};for(let t=0;t<this.attributes.length;t++){const e=this.attributes.item(t);null!==e&&a(b,e.name)&&(n[a(m,e.name)?m[e.name]:e.name]=b[e.name](e.value))}return this.readonly&&(n.readonly=!0),this.autofocus&&(n.auto_focus=!0),delete n.target,delete n.selector,n}_getEventHandlers(){const t={};for(let n=0;n<this.attributes.length;n++){const o=this.attributes.item(n);if(null!==o&&o.name.toLowerCase().startsWith("on-")){const n=o.name.toLowerCase().substring(3),a=e(o.value);"function"==typeof a&&(t[n]=a)}}return t}_doInit(){var t;this._status=c.Initializing;const e=document.createElement("textarea");e.value=null!==(t=this.textContent)&&void 0!==t?t:"",null!==this.placeholder&&(e.placeholder=this.placeholder),this._shadowDom.appendChild(e);const o=this._getConfig(),a=Object.assign(Object.assign({},o),{target:e,setup:t=>{this._editor=t,t.on("init",t=>{this._status=c.Ready}),t.on("SwitchMode",t=>{this.readonly=this.readonly}),((t,e)=>{const o=n(t);for(let n=0,a=o.length;n<a;n++){const a=o[n];e(t[a],a)}})(this._eventHandlers,(e,n)=>{void 0!==e&&t.on(n,e)}),"function"==typeof o.setup&&o.setup(t)}});this._getTinymce().init(a)}_getTinymceSrc(){var t;const e=this.getAttribute("src");if(e)return e;const n=null!==(t=this.getAttribute("channel"))&&void 0!==t?t:"6";return`https://cdn.tiny.cloud/1/${this.hasAttribute("api-key")?this.getAttribute("api-key"):"no-api-key"}/tinymce/${n}/tinymce.min.js`}_loadTinyDoInit(){this._getTinymce()?this._doInit():l.load(this.ownerDocument,this._getTinymceSrc(),()=>this._doInit())}attributeChangedCallback(t,e,n){e!==n&&("form"===t?this._updateForm():"readonly"===t?this.readonly=null!==n:"autofocus"===t?this.autofocus=null!==n:"placeholder"===t?this.placeholder=n:t.toLowerCase().startsWith("on-")&&this._updateEventAttr(t,n))}connectedCallback(){this._eventHandlers=this._getEventHandlers(),this._mutationObserver.observe(this,{attributes:!0,childList:!1,subtree:!1}),this._updateForm(),this._status===c.Raw&&this._loadTinyDoInit()}disconnectedCallback(){this._mutationObserver.disconnect(),this._updateForm()}get value(){var t,e;return null!==(e=this._status===c.Ready?null===(t=this._editor)||void 0===t?void 0:t.getContent():void 0)&&void 0!==e?e:null}set value(t){var e;this._status===c.Ready&&null!=t&&(null===(e=this._editor)||void 0===e||e.setContent(t))}get readonly(){return this._editor?"readonly"===this._editor.mode.get():this.hasAttribute("readonly")}set readonly(t){t?(this._editor&&"readonly"!==this._editor.mode.get()&&this._editor.mode.set("readonly"),this.hasAttribute("readonly")||this.setAttribute("readonly","")):(this._editor&&"readonly"===this._editor.mode.get()&&this._editor.mode.set("design"),this.hasAttribute("readonly")&&this.removeAttribute("readonly"))}get placeholder(){return this.getAttribute("placeholder")}set placeholder(t){if(this._editor){const e=this._editor.getElement();null!==e&&(null!==t?e.setAttribute("placeholder",t):e.removeAttribute("placeholder"))}null!==t?this.getAttribute("placeholder")!==t&&this.setAttribute("placeholder",t):this.hasAttribute("placeholder")&&this.removeAttribute("placeholder")}get autofocus(){return this.hasAttribute("autofocus")}set autofocus(t){t?this.hasAttribute("autofocus")||this.setAttribute("autofocus",""):this.hasAttribute("autofocus")&&this.removeAttribute("autofocus")}get form(){return this._form}get name(){return this.getAttribute("name")}get type(){return this.localName}}window.customElements.define("tinymce-editor",f)}()},316(){!function(){"use strict";var t=function(t,e){var n=function(t){for(var e=0,n=t.length;e<n;e++)o(t[e])},o=function(t){var e=t.target,n=t.attributeName,o=t.oldValue;e.attributeChangedCallback(n,o,e.getAttribute(n))};return function(a,i){var r=a.constructor.observedAttributes;return r&&t(i).then(function(){new e(n).observe(a,{attributes:!0,attributeOldValue:!0,attributeFilter:r});for(var t=0,i=r.length;t<i;t++)a.hasAttribute(r[t])&&o({target:a,attributeName:r[t],oldValue:null})}),a}};function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function n(t,n){var o="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!o){if(Array.isArray(t)||(o=function(t,n){if(t){if("string"==typeof t)return e(t,n);var o=Object.prototype.toString.call(t).slice(8,-1);return"Object"===o&&t.constructor&&(o=t.constructor.name),"Map"===o||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?e(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){o&&(t=o);var a=0,i=function(){};return{s:i,n:function(){return a>=t.length?{done:!0}:{done:!1,value:t[a++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,s=!0,l=!1;return{s:function(){o=o.call(t)},n:function(){var t=o.next();return s=t.done,t},e:function(t){l=!0,r=t},f:function(){try{s||null==o.return||o.return()}finally{if(l)throw r}}}}var o=!0,a=!1,i="querySelectorAll",r="querySelectorAll",s=self,l=s.document,c=s.Element,d=s.MutationObserver,h=s.Set,u=s.WeakMap,p=function(t){return r in t},g=[].filter,A=function(t){var e=new u,s=function(n,o){var a;if(o)for(var i,r=function(t){return t.matches||t.webkitMatchesSelector||t.msMatchesSelector}(n),s=0,l=b.length;s<l;s++)r.call(n,i=b[s])&&(e.has(n)||e.set(n,new h),(a=e.get(n)).has(i)||(a.add(i),t.handle(n,o,i)));else e.has(n)&&(a=e.get(n),e.delete(n),a.forEach(function(e){t.handle(n,o,e)}))},A=function(t){for(var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=0,o=t.length;n<o;n++)s(t[n],e)},b=t.query,m=t.root||l,f=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:MutationObserver,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:["*"],l=function e(a,r,s,l,c,d){var h,u=n(a);try{for(u.s();!(h=u.n()).done;){var p=h.value;(d||i in p)&&(c?s.has(p)||(s.add(p),l.delete(p),t(p,c)):l.has(p)||(l.add(p),s.delete(p),t(p,c)),d||e(p[i](r),r,s,l,c,o))}}catch(t){u.e(t)}finally{u.f()}},c=new r(function(t){if(s.length){var e,i=s.join(","),r=new Set,c=new Set,d=n(t);try{for(d.s();!(e=d.n()).done;){var h=e.value,u=h.addedNodes,p=h.removedNodes;l(p,i,r,c,a,a),l(u,i,r,c,o,a)}}catch(t){d.e(t)}finally{d.f()}}}),d=c.observe;return(c.observe=function(t){return d.call(c,t,{subtree:o,childList:o})})(e),c}(s,m,d,b),y=c.prototype.attachShadow;return y&&(c.prototype.attachShadow=function(t){var e=y.call(this,t);return f.observe(e),e}),b.length&&A(m[r](b)),{drop:function(t){for(var n=0,o=t.length;n<o;n++)e.delete(t[n])},flush:function(){for(var t=f.takeRecords(),e=0,n=t.length;e<n;e++)A(g.call(t[e].removedNodes,p),!1),A(g.call(t[e].addedNodes,p),!0)},observer:f,parse:A}},b=self,m=b.document,f=b.Map,y=b.MutationObserver,v=b.Object,C=b.Set,E=b.WeakMap,q=b.Element,k=b.HTMLElement,w=b.Node,_=b.Error,S=b.TypeError,L=b.Reflect,T=v.defineProperty,D=v.keys,x=v.getOwnPropertyNames,M=v.setPrototypeOf,I=!self.customElements,B=function(t){for(var e=D(t),n=[],o=e.length,a=0;a<o;a++)n[a]=t[e[a]],delete t[e[a]];return function(){for(var a=0;a<o;a++)t[e[a]]=n[a]}};if(I){var O=function(){var t=this.constructor;if(!P.has(t))throw new S("Illegal constructor");var e=P.get(t);if(z)return G(z,e);var n=R.call(m,e);return G(M(n,t.prototype),e)},R=m.createElement,P=new f,H=new f,j=new f,N=new f,$=[],U=A({query:$,handle:function(t,e,n){var o=j.get(n);if(e&&!o.isPrototypeOf(t)){var a=B(t);z=M(t,o);try{new o.constructor}finally{z=null,a()}}var i="".concat(e?"":"dis","connectedCallback");i in o&&t[i]()}}).parse,z=null,F=function(t){if(!H.has(t)){var e,n=new Promise(function(t){e=t});H.set(t,{$:n,_:e})}return H.get(t).$},G=t(F,y);T(self,"customElements",{configurable:!0,value:{define:function(t,e){if(N.has(t))throw new _('the name "'.concat(t,'" has already been used with this registry'));P.set(e,t),j.set(t,e.prototype),N.set(t,e),$.push(t),F(t).then(function(){U(m.querySelectorAll(t))}),H.get(t)._(e)},get:function(t){return N.get(t)},whenDefined:F}}),T(O.prototype=k.prototype,"constructor",{value:O}),T(self,"HTMLElement",{configurable:!0,value:O}),T(m,"createElement",{configurable:!0,value:function(t,e){var n=e&&e.is,o=n?N.get(n):N.get(t);return o?new o:R.call(m,t)}}),"isConnected"in w.prototype||T(w.prototype,"isConnected",{configurable:!0,get:function(){return!(this.ownerDocument.compareDocumentPosition(this)&this.DOCUMENT_POSITION_DISCONNECTED)}})}else try{var J=function t(){return self.Reflect.construct(HTMLLIElement,[],t)};J.prototype=HTMLLIElement.prototype;var K="extends-li";self.customElements.define("extends-li",J,{extends:"li"}),I=m.createElement("li",{is:K}).outerHTML.indexOf(K)<0;var W=self.customElements,V=W.get,X=W.whenDefined;T(self.customElements,"whenDefined",{configurable:!0,value:function(t){var e=this;return X.call(this,t).then(function(n){return n||V.call(e,t)})}})}catch(t){I=!I}if(I){var Y=function(t){var e=it.get(t);gt(e.querySelectorAll(this),t.isConnected)},Q=self.customElements,Z=m.createElement,tt=Q.define,et=Q.get,nt=Q.upgrade,ot=L||{construct:function(t){return t.call(this)}},at=ot.construct,it=new E,rt=new C,st=new f,lt=new f,ct=new f,dt=new f,ht=[],ut=[],pt=function(t){return dt.get(t)||et.call(Q,t)},gt=A({query:ut,handle:function(t,e,n){var o=ct.get(n);if(e&&!o.isPrototypeOf(t)){var a=B(t);yt=M(t,o);try{new o.constructor}finally{yt=null,a()}}var i="".concat(e?"":"dis","connectedCallback");i in o&&t[i]()}}).parse,At=A({query:ht,handle:function(t,e){it.has(t)&&(e?rt.add(t):rt.delete(t),ut.length&&Y.call(ut,t))}}).parse,bt=q.prototype.attachShadow;bt&&(q.prototype.attachShadow=function(t){var e=bt.call(this,t);return it.set(this,e),e});var mt=function(t){if(!lt.has(t)){var e,n=new Promise(function(t){e=t});lt.set(t,{$:n,_:e})}return lt.get(t).$},ft=t(mt,y),yt=null;x(self).filter(function(t){return/^HTML.*Element$/.test(t)}).forEach(function(t){var e=self[t];function n(){var t=this.constructor;if(!st.has(t))throw new S("Illegal constructor");var n=st.get(t),o=n.is,a=n.tag;if(o){if(yt)return ft(yt,o);var i=Z.call(m,a);return i.setAttribute("is",o),ft(M(i,t.prototype),o)}return at.call(this,e,[],t)}T(n.prototype=e.prototype,"constructor",{value:n}),T(self,t,{value:n})}),T(m,"createElement",{configurable:!0,value:function(t,e){var n=e&&e.is;if(n){var o=dt.get(n);if(o&&st.get(o).tag===t)return new o}var a=Z.call(m,t);return n&&a.setAttribute("is",n),a}}),T(Q,"get",{configurable:!0,value:pt}),T(Q,"whenDefined",{configurable:!0,value:mt}),T(Q,"upgrade",{configurable:!0,value:function(t){var e=t.getAttribute("is");if(e){var n=dt.get(e);if(n)return void ft(M(t,n.prototype),e)}nt.call(Q,t)}}),T(Q,"define",{configurable:!0,value:function(t,e,n){if(pt(t))throw new _("'".concat(t,"' has already been defined as a custom element"));var o,a=n&&n.extends;st.set(e,a?{is:t,tag:a}:{is:"",tag:t}),a?(o="".concat(a,'[is="').concat(t,'"]'),ct.set(o,e.prototype),dt.set(t,e),ut.push(o)):(tt.apply(Q,arguments),ht.push(o=t)),mt(t).then(function(){a?(gt(m.querySelectorAll(o)),rt.forEach(Y,[o])):At(m.querySelectorAll(o))}),lt.get(t)._(e)}})}}()},219(t,e,n){"use strict";n.d(e,{A:()=>s});var o=n(354),a=n.n(o),i=n(314),r=n.n(i)()(a());r.push([t.id,".tahqiq-block-display{display:block;border:1px solid rgba(128,128,128,.5);margin:.5rem;padding:.5rem;opacity:1;transition:opacity 200ms;pointer-events:all}.tahqiq-block-display:hover{border:1px solid gray;cursor:pointer}.tahqiq-block-display.tahqiq-drag-target{border:2px dashed rgba(128,128,128,.5)}.tahqiq-block-display.tahqiq-loading{opacity:.3;pointer-events:none;cursor:default}.tahqiq-block-display *{pointer-events:none}.tahqiq-block-editor{display:block;opacity:1}.tahqiq-block-editor .tahqiq-label-editor{background-color:#fff;color:#000;min-height:3em;border:1px solid #ccc}.tahqiq-block-editor .tahqiq-label-editor[contenteditable=true]:empty:not(:focus):before{content:attr(data-placeholder);color:gray}.tahqiq-line-group{border:1px solid rgba(128,128,128,.5);margin:0 0 1rem;counter-reset:linecounter}.tahqiq-line-group .tahqiq-block-display{border:none;padding:0;margin:0;counter-increment:linecounter;display:flex;align-items:center}.tahqiq-line-group .tahqiq-block-display:hover{background-color:rgba(69,175,214,.5);cursor:pointer}.tahqiq-line-group .tahqiq-block-display::before{content:counter(linecounter);flex-basis:2rem}.tahqiq-line-group .tahqiq-block-editor{counter-increment:linecounter}.tahqiq-line-group:has(.tahqiq-block-editor) .tahqiq-block-display:hover{background-color:rgba(0,0,0,0);cursor:default}annotation-label.tahqiq-block-display{margin:0}","",{version:3,sources:["webpack://./src/styles/AnnotationBlock.scss"],names:[],mappings:"AACA,sBACI,aAAA,CACA,qCAAA,CACA,YAAA,CACA,aAAA,CACA,SAAA,CACA,wBAAA,CACA,kBAAA,CACA,4BACI,qBAAA,CACA,cAAA,CAIJ,yCACI,sCAAA,CAGJ,qCACI,UAAA,CACA,mBAAA,CACA,cAAA,CAIJ,wBACI,mBAAA,CAKR,qBACI,aAAA,CACA,SAAA,CAEA,0CACI,qBAAA,CACA,UAAA,CACA,cAAA,CACA,qBAAA,CACA,yFACI,8BAAA,CACA,UAAA,CAMZ,mBACI,qCAAA,CACA,eAAA,CACA,yBAAA,CAEA,yCACI,WAAA,CACA,SAAA,CACA,QAAA,CAEA,6BAAA,CACA,YAAA,CACA,kBAAA,CACA,+CACI,oCAAA,CACA,cAAA,CAEJ,iDACI,4BAAA,CACA,eAAA,CAGR,wCAEI,6BAAA,CAGJ,yEACI,8BAAA,CACA,cAAA,CAKR,sCACI,QAAA",sourcesContent:['// Read-only mode annotation block styling\n.tahqiq-block-display {\n display: block;\n border: 1px solid rgba(128, 128, 128, 0.5);\n margin: 0.5rem;\n padding: 0.5rem;\n opacity: 1;\n transition: opacity 200ms;\n pointer-events: all;\n &:hover {\n border: 1px solid rgba(128, 128, 128, 1);\n cursor: pointer;\n }\n // Drag and drop\n // Dragged over styling\n &.tahqiq-drag-target {\n border: 2px dashed rgba(128, 128, 128, 0.5);\n }\n // Waiting for network requests after a drop\n &.tahqiq-loading {\n opacity: 0.3;\n pointer-events: none;\n cursor: default;\n }\n // Required to prevent unwanted dragenter and dragleave events from bubbling\n // via child elements\n * {\n pointer-events: none;\n }\n}\n\n// Edit mode annotation block styling\n.tahqiq-block-editor {\n display: block;\n opacity: 1;\n // Editable label with placeholder\n .tahqiq-label-editor {\n background-color: white;\n color: black;\n min-height: 3em;\n border: 1px solid #ccc;\n &[contenteditable="true"]:empty:not(:focus):before {\n content: attr(data-placeholder);\n color: gray;\n }\n }\n}\n\n// Line group styling for line-level annotation editing\n.tahqiq-line-group {\n border: 1px solid rgba(128, 128, 128, 0.5);\n margin: 0 0 1rem;\n counter-reset: linecounter;\n // styling for a line in a group\n .tahqiq-block-display {\n border: none;\n padding: 0;\n margin: 0;\n\n counter-increment: linecounter;\n display: flex;\n align-items: center;\n &:hover {\n background-color: rgba(69, 175, 214, 0.5);\n cursor: pointer;\n }\n &::before {\n content: counter(linecounter);\n flex-basis: 2rem;\n }\n }\n .tahqiq-block-editor {\n // editor should also increment the line count\n counter-increment: linecounter;\n }\n // Prevent cursor/hover effects on other lines when an editor is open\n &:has(.tahqiq-block-editor) .tahqiq-block-display:hover {\n background-color: transparent;\n cursor: default;\n }\n}\n\n// Remove margins on labels in line-level editor mode\nannotation-label.tahqiq-block-display {\n margin: 0;\n}\n'],sourceRoot:""}]);const s=r},705(t,e,n){"use strict";n.d(e,{A:()=>s});var o=n(354),a=n.n(o),i=n(314),r=n.n(i)()(a());r.push([t.id,".tahqiq-drop-zone{width:100%;height:100%;display:none;border:none}.tahqiq-drop-zone.tahqiq-drag-targetable{border:1px solid rgba(128,128,128,.5);display:block}.tahqiq-drop-zone.tahqiq-drag-target{border:2px dashed rgba(128,128,128,.5);display:block}","",{version:3,sources:["webpack://./src/styles/index.scss"],names:[],mappings:"AAAA,kBACI,UAAA,CACA,WAAA,CACA,YAAA,CACA,WAAA,CACA,yCACI,qCAAA,CACA,aAAA,CAEJ,qCACI,sCAAA,CACA,aAAA",sourcesContent:[".tahqiq-drop-zone {\n width: 100%;\n height: 100%;\n display: none; // Only display when targeted or targetable\n border: none;\n &.tahqiq-drag-targetable {\n border: 1px solid rgba(128, 128, 128, 0.5);\n display: block;\n }\n &.tahqiq-drag-target {\n border: 2px dashed rgba(128, 128, 128, 0.5);\n display: block;\n }\n}\n"],sourceRoot:""}]);const s=r},314(t){"use strict";t.exports=function(t){var e=[];return e.toString=function(){return this.map(function(e){var n="",o=void 0!==e[5];return e[4]&&(n+="@supports (".concat(e[4],") {")),e[2]&&(n+="@media ".concat(e[2]," {")),o&&(n+="@layer".concat(e[5].length>0?" ".concat(e[5]):""," {")),n+=t(e),o&&(n+="}"),e[2]&&(n+="}"),e[4]&&(n+="}"),n}).join("")},e.i=function(t,n,o,a,i){"string"==typeof t&&(t=[[null,t,void 0]]);var r={};if(o)for(var s=0;s<this.length;s++){var l=this[s][0];null!=l&&(r[l]=!0)}for(var c=0;c<t.length;c++){var d=[].concat(t[c]);o&&r[d[0]]||(void 0!==i&&(void 0===d[5]||(d[1]="@layer".concat(d[5].length>0?" ".concat(d[5]):""," {").concat(d[1],"}")),d[5]=i),n&&(d[2]?(d[1]="@media ".concat(d[2]," {").concat(d[1],"}"),d[2]=n):d[2]=n),a&&(d[4]?(d[1]="@supports (".concat(d[4],") {").concat(d[1],"}"),d[4]=a):d[4]="".concat(a)),e.push(d))}},e}},354(t){"use strict";t.exports=function(t){var e=t[1],n=t[3];if(!n)return e;if("function"==typeof btoa){var o=btoa(unescape(encodeURIComponent(JSON.stringify(n)))),a="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(o),i="/*# ".concat(a," */"),r=n.sources.map(function(t){return"/*# sourceURL=".concat(n.sourceRoot||"").concat(t," */")});return[e].concat(r).concat([i]).join("\n")}return[e].join("\n")}},626(t,e,n){"use strict";n.r(e),n.d(e,{default:()=>m});var o=n(72),a=n.n(o),i=n(825),r=n.n(i),s=n(659),l=n.n(s),c=n(56),d=n.n(c),h=n(540),u=n.n(h),p=n(113),g=n.n(p),A=n(219),b={};b.styleTagTransform=g(),b.setAttributes=d(),b.insert=l().bind(null,"head"),b.domAPI=r(),b.insertStyleElement=u(),a()(A.A,b);const m=A.A&&A.A.locals?A.A.locals:void 0},136(t,e,n){"use strict";n.r(e),n.d(e,{default:()=>m});var o=n(72),a=n.n(o),i=n(825),r=n.n(i),s=n(659),l=n.n(s),c=n(56),d=n.n(c),h=n(540),u=n.n(h),p=n(113),g=n.n(p),A=n(705),b={};b.styleTagTransform=g(),b.setAttributes=d(),b.insert=l().bind(null,"head"),b.domAPI=r(),b.insertStyleElement=u(),a()(A.A,b);const m=A.A&&A.A.locals?A.A.locals:void 0},72(t){"use strict";var e=[];function n(t){for(var n=-1,o=0;o<e.length;o++)if(e[o].identifier===t){n=o;break}return n}function o(t,o){for(var i={},r=[],s=0;s<t.length;s++){var l=t[s],c=o.base?l[0]+o.base:l[0],d=i[c]||0,h="".concat(c," ").concat(d);i[c]=d+1;var u=n(h),p={css:l[1],media:l[2],sourceMap:l[3],supports:l[4],layer:l[5]};if(-1!==u)e[u].references++,e[u].updater(p);else{var g=a(p,o);o.byIndex=s,e.splice(s,0,{identifier:h,updater:g,references:1})}r.push(h)}return r}function a(t,e){var n=e.domAPI(e);return n.update(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap&&e.supports===t.supports&&e.layer===t.layer)return;n.update(t=e)}else n.remove()}}t.exports=function(t,a){var i=o(t=t||[],a=a||{});return function(t){t=t||[];for(var r=0;r<i.length;r++){var s=n(i[r]);e[s].references--}for(var l=o(t,a),c=0;c<i.length;c++){var d=n(i[c]);0===e[d].references&&(e[d].updater(),e.splice(d,1))}i=l}}},659(t){"use strict";var e={};t.exports=function(t,n){var o=function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(t){n=null}e[t]=n}return e[t]}(t);if(!o)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");o.appendChild(n)}},540(t){"use strict";t.exports=function(t){var e=document.createElement("style");return t.setAttributes(e,t.attributes),t.insert(e,t.options),e}},56(t,e,n){"use strict";t.exports=function(t){var e=n.nc;e&&t.setAttribute("nonce",e)}},825(t){"use strict";t.exports=function(t){var e=t.insertStyleElement(t);return{update:function(n){!function(t,e,n){var o="";n.supports&&(o+="@supports (".concat(n.supports,") {")),n.media&&(o+="@media ".concat(n.media," {"));var a=void 0!==n.layer;a&&(o+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),o+=n.css,a&&(o+="}"),n.media&&(o+="}"),n.supports&&(o+="}");var i=n.sourceMap;i&&"undefined"!=typeof btoa&&(o+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),e.styleTagTransform(o,t,e.options)}(e,t,n)},remove:function(){!function(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t)}(e)}}}},113(t){"use strict";t.exports=function(t,e){if(e.styleSheet)e.styleSheet.cssText=t;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(t))}}},982(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.AnnotationBlock=void 0;const o=n(413),a=n(312),i=n(765),r=n(175);n(626);class s extends HTMLElement{constructor(t){super(),this.annotation=t.annotation,this.onCancel=t.onCancel,this.onClick=t.onClick,this.onDelete=t.onDelete,this.onDrag=t.onDrag,this.onReorder=t.onReorder,this.onSave=t.onSave,this.updateAnnotorious=t.updateAnnotorious,this.setAttribute("class","tahqiq-block-display"),this.labelElement=document.createElement("h3"),this.labelElement.setAttribute("class","tahqiq-label-display"),this.labelElement.setAttribute("data-placeholder","Optional label"),this.bodyElement=document.createElement("div"),this.bodyElement.setAttribute("class","tahqiq-body-display"),Array.isArray(this.annotation.body)&&this.annotation.body.length>0&&(this.labelElement.innerHTML=this.annotation.body[0].label||"",this.bodyElement.innerHTML=this.annotation.body[0].value),this.annotation.textGranularity!==o.TextGranularity.LINE&&this.append(this.labelElement),this.append(this.bodyElement),this.annotation.id&&(this.dataset.annotationId=this.annotation.id),this.clickable=!0,this.addEventListener("click",()=>{this.clickable&&(this.classList.contains("tahqiq-block-editor")||(this.onClick(this),this.makeEditable()))}),this.draggable=!0,this.addEventListener("dragstart",this.startDrag.bind(this)),this.addEventListener("dragover",t=>{t.preventDefault()}),this.addEventListener("dragend",()=>{this.onDrag(!1)}),this.addEventListener("dragenter",t=>{t.currentTarget instanceof s&&this.classList.add("tahqiq-drag-target")}),this.addEventListener("dragleave",t=>{t.currentTarget instanceof s&&this.classList.remove("tahqiq-drag-target")}),this.addEventListener("drop",this.onReorder),t.editable&&this.makeEditable()}encodeHTML(t){return t.replace(/[&<>'"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;","'":"&#39;",'"':"&quot;"}[t]||t))}makeEditable(){if("tahqiq-block-editor"==this.getAttribute("class"))return;this.setAttribute("class","tahqiq-block-editor"),this.draggable=!1,this.labelElement.setAttribute("contenteditable","true"),this.labelElement.setAttribute("class","tahqiq-label-editor"),window.tinyConfig.init_instance_callback=this.setEditorId.bind(this);const t=document.createElement("tinymce-editor");t.setAttribute("config","tinyConfig"),t.setAttribute("api-key",window.tinyApiKey),t.innerHTML=this.encodeHTML(this.bodyElement.innerHTML),this.bodyElement.setAttribute("class","tahqiq-body-editor"),this.bodyElement.innerHTML="",this.bodyElement.append(t),this.bodyElement.focus(),this.append(new r.SaveButton(this)),this.append(new a.CancelButton(this)),this.annotation.id&&this.append(new i.DeleteButton(this))}makeReadOnly(t){if(this.setAttribute("class","tahqiq-block-display"),this.draggable=!0,this.labelElement.setAttribute("contenteditable","false"),this.labelElement.setAttribute("class","tahqiq-label-display"),this.bodyElement.setAttribute("class","tahqiq-body-display"),t)Array.isArray(this.annotation.body)&&this.annotation.body.length>0&&(this.bodyElement.innerHTML=this.annotation.body[0].value,this.labelElement.innerHTML=this.annotation.body[0].label||""),this.updateAnnotorious(this.annotation);else{const t=window.tinymce.get(this.editorId).getContent();this.bodyElement.innerHTML=t}this.querySelectorAll("button").forEach(t=>t.remove())}setAnnotation(t){this.annotation=t}setEditorId(t){this.editorId=t.id}startDrag(t){const e=t.target;t.dataTransfer?.setData("text",e?.dataset?.annotationId||""),this.onDrag(!0)}setDraggedOver(t){t?this.classList.add("tahqiq-drag-target"):this.classList.remove("tahqiq-drag-target")}setDraggable(t){this.draggable=t}setClickable(t){this.clickable=t}}e.AnnotationBlock=s},505(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.AnnotationLabel=void 0;const o=n(312),a=n(175);n(626);class i extends HTMLElement{constructor(t){super(),this.annotation=t.annotation,this.onCancel=t.onCancel,this.onClick=t.onClick,this.onSave=t.onSave,this.setAttribute("class","tahqiq-block-display"),this.labelElement=document.createElement("h3"),this.labelElement.setAttribute("class","tahqiq-label-display"),this.labelElement.setAttribute("data-placeholder","Optional label"),Array.isArray(this.annotation.body)&&this.annotation.body.length>0&&this.annotation.body[0].label?this.labelElement.innerHTML=this.annotation.body[0].label:this.labelElement.innerHTML="[no label]",this.append(this.labelElement),this.annotation.id&&(this.dataset.annotationId=this.annotation.id),this.clickable=!0,this.addEventListener("click",()=>{this.clickable&&(this.classList.contains("tahqiq-block-editor")||(this.onClick(this),this.makeEditable()))}),t.editable&&this.makeEditable()}makeEditable(){this.classList.contains("tahqiq-block-editor")||(this.setAttribute("class","tahqiq-block-editor"),this.labelElement.setAttribute("contenteditable","true"),this.labelElement.setAttribute("class","tahqiq-label-editor"),this.append(new a.SaveButton(this)),this.append(new o.CancelButton(this)))}makeReadOnly(t){this.setAttribute("class","tahqiq-block-display"),this.labelElement.setAttribute("contenteditable","false"),this.labelElement.setAttribute("class","tahqiq-line-group-label tahqiq-label-display"),t&&(Array.isArray(this.annotation.body)&&this.annotation.body.length>0&&this.annotation.body[0].label?this.labelElement.innerHTML=this.annotation.body[0].label:this.labelElement.innerHTML="[no label]"),this.querySelectorAll("button").forEach(t=>t.remove())}setAnnotation(t){this.annotation=t}setEditorId(t){this.editorId=t.id}setClickable(t){this.clickable=t}}e.AnnotationLabel=i},312(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.CancelButton=void 0,n(316);class o extends HTMLButtonElement{constructor(t){super(),this.annotationElement=t,this.classList.add("tahqiq-button","tahqiq-cancel-button"),this.textContent="Cancel",this.addEventListener("click",this.handleCancel.bind(this)),document.addEventListener("cancel-annotation",this.handleCancel.bind(this))}handleCancel(t){if(t.stopPropagation(),window.tinymce?.activeEditor?.isDirty()&&1==confirm("You have unsaved changes. Do you want to keep editing?"))return;let e=this.annotationElement.annotation.target.source;"string"!=typeof e&&(e=e.id);const n=t instanceof CustomEvent&&(t.detail?.target?.source===e||t.detail?.target?.source?.id===e);t instanceof CustomEvent&&!n||(this.annotationElement.onCancel(),this.annotationElement.annotation.id?this.annotationElement.makeReadOnly(!0):this.annotationElement.remove())}}e.CancelButton=o},765(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.DeleteButton=void 0,n(316);class o extends HTMLButtonElement{constructor(t){super(),this.annotationBlock=t,this.classList.add("tahqiq-button","tahqiq-delete-button"),this.textContent="Delete",this.addEventListener("click",this.handleClick.bind(this))}handleClick(t){t.stopPropagation(),this.annotationBlock.onDelete(this.annotationBlock)}}e.DeleteButton=o},175(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SaveButton=void 0;const o=n(982),a=n(505);n(316);class i extends HTMLButtonElement{constructor(t){super(),this.annotationElement=t,this.classList.add("tahqiq-button","tahqiq-save-button"),this.textContent="Save",this.addEventListener("click",this.handleClick.bind(this))}async handleClick(t){t.stopPropagation(),(this.annotationElement instanceof o.AnnotationBlock||this.annotationElement instanceof a.AnnotationLabel)&&await this.annotationElement.onSave(this.annotationElement)}}e.SaveButton=i},156(t,e,n){"use strict";var o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.AnnotationServerStorage=e.TranscriptionEditor=void 0;const a=n(982),i=n(312),r=n(765),s=n(175),l=n(413),c=n(144),d=o(n(421));e.AnnotationServerStorage=d.default,n(316),n(136);const h=n(505),u=new Event("reload-all-positions");class p{constructor(t,e,n,o,l,d,u){if(this.anno=t,this.storage=e,this.anno.disableEditor=!0,this.anno.readOnly=this.storage.settings.lineMode,this.annotationContainer=n,this.currentAnnotationBlock=null,customElements.get("save-button")||customElements.define("save-button",s.SaveButton,{extends:"button"}),customElements.get("cancel-button")||customElements.define("cancel-button",i.CancelButton,{extends:"button"}),customElements.get("delete-button")||customElements.define("delete-button",r.DeleteButton,{extends:"button"}),customElements.get("annotation-block")||customElements.define("annotation-block",a.AnnotationBlock),customElements.get("annotation-label")||customElements.define("annotation-label",h.AnnotationLabel),document.addEventListener("annotations-loaded",this.handleAnnotationsLoaded.bind(this)),document.addEventListener("reload-all-positions",this.handleReloadAllPositions.bind(this)),this.anno.on("createSelection",this.handleCreateSelection.bind(this)),this.anno.on("selectAnnotation",this.handleSelectAnnotation.bind(this)),this.anno.on("changeSelectionTarget",this.handleChangeSelectionTarget.bind(this)),this.anno.on("cancelSelected",this.handleCancelSelection.bind(this)),this.toolbarContainer=o,this.initializeToolbar(),customElements.get("tinymce-editor")||(0,c.Editor)(),!window.tinyConfig){const t=`language |${this.storage.settings?.lineMode?"":" numlist |"}${u?" italic":""} strikethrough superscript | ltr rtl | undo redo | `;window.tinyConfig={height:this.storage?.settings?.lineMode?150:500,plugins:"lists directionality",toolbar:t,directionality:d||"rtl",formats:{italic:{inline:"i"},strikethrough:{inline:"del"},ins:{inline:"ins"}},extended_valid_elements:"i,em,p[dir],ol[dir],li[dir]",content_langs:[{title:"English",code:"en"},{title:"Hebrew",code:"he"},{title:"Arabic",code:"ar"}],content_style:"::marker { margin-inline-end: 1em; } li { padding-inline-start: 1em; } ins { color: gray; }",menubar:!1}}window.tinyApiKey||(window.tinyApiKey=l||"no-api-key")}initializeToolbar(){const t=document.createElement("label");t.classList.add("tahqiq-tool","rectangle-tool");const e=document.createElement("input");e.type="radio";const n=document.createElement("span");n.innerText="Select a rectangle for image annotation",t.append(e,n);const o=document.createElement("label");o.classList.add("tahqiq-tool","polygon-tool");const a=document.createElement("input");a.type="radio";const i=document.createElement("span");i.innerText="Select a polygon for image annotation",o.append(a,i),e.checked=!0,t.classList.add("active-tool"),e.addEventListener("change",e=>{e?.target instanceof HTMLInputElement&&e.target.checked&&(this.anno.setDrawingTool("rect"),t.classList.add("active-tool"),a.checked=!1,o.classList.remove("active-tool"))}),a.addEventListener("change",n=>{n?.target instanceof HTMLInputElement&&n.target.checked&&(this.anno.setDrawingTool("polygon"),o.classList.add("active-tool"),e.checked=!1,t.classList.remove("active-tool"))}),this.toolbarContainer.append(t,o)}createBlocks(t,e){t.sort((t,e)=>null===t["schema:position"]?1:null===e["schema:position"]?-1:t["schema:position"]&&e["schema:position"]?t["schema:position"]-e["schema:position"]:0),t.forEach(t=>{e.append(new a.AnnotationBlock({annotation:t,editable:!1,onCancel:this.handleCancel.bind(this),onClick:this.handleClickAnnotationBlock.bind(this),onDelete:this.handleDeleteAnnotation.bind(this),onDrag:this.handleDrag.bind(this),onReorder:this.handleDropAnnotationBlock.bind(this),onSave:this.handleSaveAnnotation.bind(this),updateAnnotorious:this.anno.addAnnotation}))})}async handleAnnotationsLoaded(t){if(t instanceof CustomEvent&&t.detail?.target===this.storage?.settings?.target){this.annotationContainer.querySelectorAll("[class^='tahqiq-block'], .tahqiq-drop-zone, .tahqiq-line-group").forEach(t=>t.remove());const o=t.detail.annotations;if(o&&(this.storage.settings.lineMode?Object.entries((e=o.filter(t=>t.textGranularity===l.TextGranularity.LINE),n=t=>t.partOf||"group",e.reduce((t,e)=>((t[n(e)]||=[]).push(e),t),{}))).forEach(([t,e])=>{const n=o.find(e=>e.textGranularity===l.TextGranularity.BLOCK&&e.id===t),a=document.createElement("DIV");a.classList.add("tahqiq-line-group"),this.annotationContainer.append(new h.AnnotationLabel({annotation:n,editable:!1,onCancel:this.handleCancel.bind(this),onClick:this.handleClickAnnotationBlock.bind(this),onSave:this.handleSaveAnnotation.bind(this)}),a),this.createBlocks(e,a)}):this.createBlocks(o,this.annotationContainer)),!o?.length){const t=document.createElement("div");t.className="tahqiq-drop-zone",t.addEventListener("dragover",t=>{t.preventDefault()}),t.addEventListener("dragenter",t=>{t.currentTarget instanceof HTMLDivElement&&t.currentTarget.classList.add("tahqiq-drag-target")}),t.addEventListener("dragleave",t=>{t.currentTarget instanceof HTMLDivElement&&t.currentTarget.classList.remove("tahqiq-drag-target")}),t.addEventListener("drop",t=>{t.currentTarget instanceof HTMLDivElement&&t.currentTarget.classList.remove("tahqiq-drag-target"),this.handleDropAnnotationBlock(t)}),this.annotationContainer.append(t)}}var e,n;this.setAllInteractive(!0)}async handleCreateSelection(t){const e=new a.AnnotationBlock({annotation:t,editable:!0,onCancel:this.handleCancel.bind(this),onClick:this.handleClickAnnotationBlock.bind(this),onDelete:this.handleDeleteAnnotation.bind(this),onDrag:this.handleDrag.bind(this),onReorder:this.handleDropAnnotationBlock.bind(this),onSave:this.handleSaveAnnotation.bind(this),updateAnnotorious:this.anno.addAnnotation});this.annotationContainer.append(e),this.makeAllReadOnlyExcept(e),this.setAllInteractive(!1),this.allowDragging(this.anno._element)}handleCancel(){this.anno.getSelected()&&this.anno.cancelSelected(),this.setAllInteractive(!0),document.dispatchEvent(new CustomEvent("tahqiq-cancel"))}handleSelectAnnotation(t,e){const n=document.querySelector('[data-annotation-id="'+t.id+'"]');n&&n instanceof a.AnnotationBlock&&(this.allowDragging(e),this.makeAllReadOnlyExcept(n),n.makeEditable(),this.currentAnnotationBlock=n,this.setAllInteractive(!1))}handleChangeSelectionTarget(t){null!=this.currentAnnotationBlock&&(this.currentAnnotationBlock.annotation.target=t)}handleCancelSelection(t){document.dispatchEvent(new CustomEvent("cancel-annotation",{detail:t}))}async handleDeleteAnnotation(t){try{if(this.storage.alert("Deleting..."),t.annotation.id){await this.storage.delete(t.annotation),this.anno.removeAnnotation(t.annotation.id),this.storage.setAnnotationCount(this.storage.annotationCount-1),t.remove();const e=this.annotationContainer.querySelectorAll(".tahqiq-block-display"),n=Array.from(e).map(e=>{if(e instanceof a.AnnotationBlock&&e.annotation.id!==t.annotation.id&&(!e.annotation.partOf||e.annotation.partOf===t.annotation.partOf))return e.annotation});await this.updateSequence(n),this.storage.alert("Annotation deleted","success")}else this.storage.alert("No annotation ID associated with this display block","error")}catch(t){this.storage.alert(t.message,"error")}}async handleSaveAnnotation(t){this.storage.alert("Saving...");const e=t.annotation,n=window.tinymce?.get(t.editorId)?.getContent();Array.isArray(e.body)&&0==e.body.length?e.body.push({type:"TextualBody",value:n||"",format:"text/html",label:t.labelElement.textContent||void 0}):Array.isArray(e.body)&&(e.body[0].value=n||"",e.body[0].label=t.labelElement.textContent||void 0),this.setAllInteractive(!1),t instanceof a.AnnotationBlock?await this.anno.updateSelected(e,!0):await this.storage.handleUpdateAnnotationInStore(e)}handleClickAnnotationBlock(t){t.annotation.id&&(t instanceof a.AnnotationBlock&&this.anno.selectAnnotation(t.annotation.id),this.makeAllReadOnlyExcept(t),this.setAllInteractive(!1))}handleDrag(t){document.querySelectorAll(".tahqiq-drop-zone").forEach(e=>{t?e.classList.add("tahqiq-drag-targetable"):e.classList.remove("tahqiq-drag-targetable")})}async handleDropAnnotationBlock(t){t.preventDefault(),this.annotationContainer.querySelectorAll("annotation-block").forEach(t=>{t instanceof a.AnnotationBlock&&t.classList.add("tahqiq-loading")});const e=this.annotationContainer.querySelectorAll("annotation-block"),n=Array.from(e).map(t=>{if(t instanceof a.AnnotationBlock)return t.annotation}),o=t.dataTransfer?.getData("text"),i=n.find(t=>t?.id===o);if(i&&t.currentTarget instanceof a.AnnotationBlock){this.storage.alert("Reordering...");const e=n.indexOf(i),o=n.indexOf(t.currentTarget.annotation);n.splice(e,1),n.splice(o,0,i);try{await this.updateSequence(n),this.storage.alert("Annotations reordered","success")}catch(t){this.storage.alert(t.message,"error")}}else{this.storage.alert("Moving...");const t=document.querySelector(`[data-annotation-id="${o}"]`);if(t instanceof a.AnnotationBlock){const e={...t.annotation,target:{...t.annotation.target,source:{...this.storage.adjustTargetSource(t.annotation.target.source),id:this.storage.settings.target}},"schema:position":null};try{await this.storage.update(e),this.storage.alert("Annotation moved","success"),document.dispatchEvent(u)}catch(t){this.storage.alert(t.message,"error")}}else this.storage.alert("Error finding the dragged annotation","error")}}async handleReloadAllPositions(){const t=await this.storage.loadAnnotations();try{await this.updateSequence(t)}catch(t){this.storage.alert(t.message,"error")}}async updateSequence(t){return this.setAllInteractive(!1),await Promise.all(t.map(async(t,e)=>{const n=e+1;if(t&&t["schema:position"]!==n){const e={...t,"schema:position":n};await this.storage.update(e)}return Promise.resolve()})),this.storage.loadAnnotations()}makeAllReadOnlyExcept(t){this.annotationContainer.querySelectorAll(".tahqiq-block-editor, .tahqiq-label-editor").forEach(e=>{(e instanceof a.AnnotationBlock||e instanceof h.AnnotationLabel)&&e!==t&&e.makeReadOnly()})}setAnnotoriousPointerEvents(t){const e=this.anno._element.querySelector("g.a9s-annotation.editable.selected"),n=this.anno._element.querySelector("div.openseadragon-canvas"),o=this.anno._element.querySelector("svg.a9s-annotationlayer");t?(n.style.pointerEvents="auto",o.style.pointerEvents="all",this.anno._element.querySelectorAll("g.a9s-annotation").forEach(t=>{t.style.pointerEvents="all"})):(n.style.pointerEvents="none",o.style.pointerEvents="none",this.anno._element.querySelectorAll("g.a9s-annotation:not(.editable)").forEach(t=>{t.style.pointerEvents="none"}),e&&(e.style.pointerEvents="all"))}allowDragging(t){t.querySelectorAll("g.a9s-handle").forEach(t=>{t.addEventListener("mousedown",()=>this.setAnnotoriousPointerEvents(!0)),t.addEventListener("mouseup",()=>this.setAnnotoriousPointerEvents(!1))})}setAllInteractive(t){this.annotationContainer.querySelectorAll("annotation-block, annotation-label").forEach(e=>{e instanceof a.AnnotationBlock?(e.setDraggable(t&&!this.storage?.settings?.lineMode),e.setClickable(t)):e instanceof h.AnnotationLabel&&e.setClickable(t)}),this.setAnnotoriousPointerEvents(t)}}e.TranscriptionEditor=p,e.default=p},421(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const o=n(413);e.default=class{constructor(t,e){this.anno=t,this.settings=e,this.annotationCount=0,this.anno.on("createAnnotation",this.handleCreateAnnotation.bind(this)),this.anno.on("updateAnnotation",this.handleUpdateAnnotation.bind(this)),this.anno.on("deleteAnnotation",this.handleDeleteAnnotation.bind(this)),this.loadAnnotations()}async loadAnnotations(){try{const t=await this.search(this.settings.target);return this.settings.lineMode?await this.anno.setAnnotations(t?.filter(t=>t.textGranularity===o.TextGranularity.LINE)):await this.anno.setAnnotations(t),t instanceof Array&&(this.annotationCount=t.length),document.dispatchEvent(new CustomEvent("annotations-loaded",{detail:{target:this.settings.target,annotations:t}})),t}catch(t){this.alert(t.message,"error")}}async handleCreateAnnotation(t){try{t.target.source=this.adjustTargetSource(t.target.source),this.settings.sourceUri&&(t["dc:source"]=this.settings.sourceUri),t.motivation=this.settings.secondaryMotivation?["sc:supplementing",this.settings.secondaryMotivation]:"sc:supplementing",this.setAnnotationCount(this.annotationCount+1),t["schema:position"]||(t["schema:position"]=this.annotationCount);const e=await this.create(t);return this.anno.removeAnnotation(t.id),this.anno.addAnnotation(e),await this.loadAnnotations(),this.alert("Annotation created","success"),await Promise.resolve(e)}catch(t){this.alert(t.message,"error")}}async handleUpdateAnnotation(t,e){t.id=e.id,t.target.source=this.adjustTargetSource(t.target.source);try{const e=await this.update(t);return this.anno.addAnnotation(e),await this.loadAnnotations(),this.alert("Annotation saved","success"),await Promise.resolve(e)}catch(e){this.anno.selectAnnotation(t),this.alert(e.message,"error")}}async handleUpdateAnnotationInStore(t){try{const e=await this.update(t);return await this.loadAnnotations(),this.alert("Annotation saved","success"),await Promise.resolve(e)}catch(t){this.alert(t.message,"error")}}async handleDeleteAnnotation(t){try{return await this.delete(t),this.setAnnotationCount(this.annotationCount-1),await this.loadAnnotations(),this.alert("Annotation deleted","success"),await Promise.resolve()}catch(e){this.anno.selectAnnotation(t),this.alert(e.message,"error")}}setAnnotationCount(t){this.annotationCount=t}async create(t){const e=await fetch(`${this.settings.annotationEndpoint}`,{body:JSON.stringify(t),headers:{Accept:"application/json","Content-Type":"application/json","X-CSRFToken":this.settings.csrf_token},method:"POST"});if(e.ok)return e.json();throw new Error(`Error creating annotation: ${e.status} ${e.statusText}`)}async update(t){const e=await fetch(t.id,{body:JSON.stringify(t),headers:{Accept:"application/json","Content-Type":"application/json","X-CSRFToken":this.settings.csrf_token,"If-Match":t.etag},method:"POST"});if(e.ok)return e.json();throw 412===e.status?new Error("Error: Annotation was modified by another user while you were working.\n Refresh the page to get the latest version, then make your changes."):new Error(`Error updating annotation: ${e.status} ${e.statusText}`)}async delete(t){const e=await fetch(t.id,{headers:{Accept:"application/json","Content-Type":"application/json","X-CSRFToken":this.settings.csrf_token,"If-Match":t.etag},method:"DELETE"});if(e.ok)return e;throw 412===e.status?new Error("Error: Annotation was modified by another user.\n Refresh the page to get the latest version, then delete it."):new Error(`Error deleting annotation: ${e.status} ${e.statusText}`)}async search(t){const{annotationEndpoint:e,sourceUri:n,manifest:o,secondaryMotivation:a}=this.settings,i=n?`&source=${n}`:"",r=o?`&manifest=${o}`:"",s=a?`&motivation=${a}`:"",l=await fetch(`${e}search/?uri=${t}${i}${r}${s}`,{headers:{Accept:"application/json","Content-Type":"application/json","X-CSRFToken":this.settings.csrf_token}});if(l.ok)return(await l.json()).resources;throw new Error(`Error retrieving annotations: ${l.status} ${l.statusText}`)}adjustTargetSource(t){return"string"==typeof t&&(t={id:this.settings.target,partOf:{id:this.settings.manifest,type:"Manifest"},type:"Canvas"}),t}alert(t,e){document.dispatchEvent(new CustomEvent("tahqiq-alert",{detail:{message:t,status:e||"info",target:this.settings.target}}))}}},413(t,e){"use strict";var n;Object.defineProperty(e,"__esModule",{value:!0}),e.TextGranularity=void 0,function(t){t.LINE="line",t.BLOCK="block"}(n||(n={})),e.TextGranularity=n}},e={};function n(o){var a=e[o];if(void 0!==a)return a.exports;var i=e[o]={id:o,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.nc=void 0;var o=n(156);module.exports=o})(); //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJtYXBwaW5ncyI6IjtvQkFBQSxXQUNJLGFBRUEsTUFBTUEsRUFBMkIsb0JBQVhDLE9BQXlCQSxPQUFTQyxTQUFTLGVBQVRBLEdBU2xEQyxFQUFVLENBQUNDLEVBQUdDLElBUFAsRUFBQ0MsRUFBT0QsS0FDbkIsSUFBSUUsRUFBSUYsUUFBd0NBLEVBQVFMLEVBQ3hELElBQUssSUFBSVEsRUFBSSxFQUFHQSxFQUFJRixFQUFNRyxRQUFWRCxNQUFvQkQsSUFBaUNDLEVBQ25FRCxFQUFJQSxFQUFFRCxFQUFNRSxJQUVkLE9BQU9ELEdBSUFHLENBRE9OLEVBQUVPLE1BQU0sS0FDSE4sR0FPZk8sRUFBT0MsT0FBT0QsS0FDZEUsRUFBaUJELE9BQU9DLGVBU3hCQyxFQUFNLENBQUNDLEVBQUtDLElBQVFILEVBQWVJLEtBQUtGLEVBQUtDLEdBRW5ELElBQUlFLEVBQVMsRUFDYixNQUFNQyxFQUFXQyxJQUNmLE1BQ01DLEdBRE8sSUFBSUMsTUFDQ0MsVUFDWkMsRUFBU0MsS0FBS0MsTUFBc0IsSUFBaEJELEtBQUtELFVBRS9CLE9BREFOLElBQ09FLEVBQVMsSUFBTUksRUFBU04sRUFBU1MsT0FBT04sSUFHM0NPLEVBQWMsS0FBTSxDQUN4QkMsVUFBVyxHQUNYQyxTQUFVWCxFQUFTLGVBQ25CWSxjQUFjLElBd0NWQyxFQXRDcUIsTUFDekIsSUFBSUMsRUFBUUwsSUFnQ1osTUFBTyxDQUNMTSxLQWpCVyxDQUFDQyxFQUFLQ