"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("../../../../quill-delta@5.1.0/node_modules/quill-delta/dist/Delta.js"),u=require("../core/module.js"),l=require("../core/quill.js"),o=require("./keyboard.js"),d=["insertText","insertReplacementText"];class c extends u.default{constructor(e,t){super(e,t),e.root.addEventListener("beforeinput",n=>{this.handleBeforeInput(n)}),/Android/i.test(navigator.userAgent)||e.on(l.default.events.COMPOSITION_BEFORE_START,()=>{this.handleCompositionStart()})}deleteRange(e){o.deleteRange({range:e,quill:this.quill})}replaceText(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";if(e.length===0)return!1;if(t){const n=this.quill.getFormat(e.index,1);this.deleteRange(e),this.quill.updateContents(new a.default().retain(e.index).insert(t,n),l.default.sources.USER)}else this.deleteRange(e);return this.quill.setSelection(e.index+t.length,0,l.default.sources.SILENT),!0}handleBeforeInput(e){if(this.quill.composition.isComposing||e.defaultPrevented||!d.includes(e.inputType))return;const t=e.getTargetRanges?e.getTargetRanges()[0]:null;if(!t||t.collapsed===!0)return;const n=f(e);if(n==null)return;const s=this.quill.selection.normalizeNative(t),r=s?this.quill.selection.normalizedToRange(s):null;r&&this.replaceText(r,n)&&e.preventDefault()}handleCompositionStart(){const e=this.quill.getSelection();e&&this.replaceText(e)}}function f(i){var e;return typeof i.data=="string"?i.data:(e=i.dataTransfer)!=null&&e.types.includes("text/plain")?i.dataTransfer.getData("text/plain"):null}exports.default=c;
