makethisbetter 1.14.1 → 1.14.2

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.
@@ -5,7 +5,7 @@
5
5
  <button class="mtb-frustration-tell">${e.frustration.action}</button>
6
6
  <button class="mtb-frustration-dismiss">${e.frustration.dismiss}</button>
7
7
  </div>
8
- `,this.el.querySelector(".mtb-frustration-tell").addEventListener("click",r.onTell),this.el.querySelector(".mtb-frustration-dismiss").addEventListener("click",r.onDismiss),t.append(this.el),this.autoHideTimer=setTimeout(r.onAutoHide,oe)}destroy(){this.autoHideTimer&&(clearTimeout(this.autoHideTimer),this.autoHideTimer=null),this.el.remove()}}class le{constructor(t,e){this.onClick=e,this.el=t.el("div","mtb-dim mtb-dim-clickable"),this.el.addEventListener("click",this.onClick),t.append(this.el)}destroy(){this.el.removeEventListener("click",this.onClick),this.el.remove()}}class ce{constructor(){this.locked=!1,this.prevOverflow="",this.prevTouchAction=""}isTouchPointer(){return window.matchMedia?.("(pointer: coarse)").matches??!1}lock(){this.locked||!this.isTouchPointer()||(this.locked=!0,this.prevOverflow=document.body.style.overflow,this.prevTouchAction=document.body.style.touchAction,document.body.style.overflow="hidden",document.body.style.touchAction="none")}unlock(){this.locked&&(this.locked=!1,document.body.style.overflow=this.prevOverflow,document.body.style.touchAction=this.prevTouchAction)}isLocked(){return this.locked}}class de{constructor(t,e,r,n,s="right"){this.currentMode="markup",this.handlePointerMove=o=>{if(o.pointerType!=="mouse")return;const a=this.hintBarEl.getBoundingClientRect(),l=o.clientX>=a.left&&o.clientX<=a.right&&o.clientY>=a.top&&o.clientY<=a.bottom;this.hintBarEl.classList.toggle("mtb-hint-bar--under-pointer",l)},this.messages=e,this.hintBarEl=t.el("div","mtb-hint-bar"),this.hintBarEl.innerHTML=`<span class="mtb-toolbar-hint">${e.toolbar.hint}</span>`,this.el=t.el("div","mtb-toolbar"),s==="left"&&this.el.classList.add("left"),this.el.innerHTML=this.buildHTML(e),t.append(this.hintBarEl,this.el),this.host=t.host,this.host.setAttribute("data-mtb-toolbar",""),this.hintTextEl=this.hintBarEl.querySelector(".mtb-toolbar-hint"),this.markupBtn=this.el.querySelector(".mtb-toolbar-mode-markup"),this.recordBtn=this.el.querySelector(".mtb-toolbar-mode-record"),this.markupBtn.addEventListener("click",()=>{this.setMode("markup"),n?.("markup")}),this.recordBtn.addEventListener("click",()=>{this.setMode("record"),n?.("record")}),this.el.querySelector(".mtb-exit-btn").addEventListener("click",r),document.addEventListener("pointermove",this.handlePointerMove)}buildHTML(t){return`
8
+ `,this.el.querySelector(".mtb-frustration-tell").addEventListener("click",r.onTell),this.el.querySelector(".mtb-frustration-dismiss").addEventListener("click",r.onDismiss),t.append(this.el),this.autoHideTimer=setTimeout(r.onAutoHide,oe)}destroy(){this.autoHideTimer&&(clearTimeout(this.autoHideTimer),this.autoHideTimer=null),this.el.remove()}}class le{constructor(t,e){this.onClick=e,this.el=t.el("div","mtb-dim mtb-dim-clickable"),this.el.addEventListener("click",this.onClick),t.append(this.el)}destroy(){this.el.removeEventListener("click",this.onClick),this.el.remove()}}class ce{constructor(){this.locked=!1,this.prevOverflow="",this.prevTouchAction="",this.anchorX=0,this.anchorY=0,this.onScroll=()=>{(window.scrollX!==this.anchorX||window.scrollY!==this.anchorY)&&window.scrollTo(this.anchorX,this.anchorY)}}isTouchPointer(){return window.matchMedia?.("(pointer: coarse)").matches??!1}lock(){this.locked||!this.isTouchPointer()||(this.locked=!0,this.prevOverflow=document.body.style.overflow,this.prevTouchAction=document.body.style.touchAction,document.body.style.overflow="hidden",document.body.style.touchAction="none",this.anchorX=window.scrollX,this.anchorY=window.scrollY,window.addEventListener("scroll",this.onScroll,{passive:!0}))}unlock(){this.locked&&(this.locked=!1,window.removeEventListener("scroll",this.onScroll),document.body.style.overflow=this.prevOverflow,document.body.style.touchAction=this.prevTouchAction)}isLocked(){return this.locked}}class de{constructor(t,e,r,n,s="right"){this.currentMode="markup",this.handlePointerMove=o=>{if(o.pointerType!=="mouse")return;const a=this.hintBarEl.getBoundingClientRect(),l=o.clientX>=a.left&&o.clientX<=a.right&&o.clientY>=a.top&&o.clientY<=a.bottom;this.hintBarEl.classList.toggle("mtb-hint-bar--under-pointer",l)},this.messages=e,this.hintBarEl=t.el("div","mtb-hint-bar"),this.hintBarEl.innerHTML=`<span class="mtb-toolbar-hint">${e.toolbar.hint}</span>`,this.el=t.el("div","mtb-toolbar"),s==="left"&&this.el.classList.add("left"),this.el.innerHTML=this.buildHTML(e),t.append(this.hintBarEl,this.el),this.host=t.host,this.host.setAttribute("data-mtb-toolbar",""),this.hintTextEl=this.hintBarEl.querySelector(".mtb-toolbar-hint"),this.markupBtn=this.el.querySelector(".mtb-toolbar-mode-markup"),this.recordBtn=this.el.querySelector(".mtb-toolbar-mode-record"),this.markupBtn.addEventListener("click",()=>{this.setMode("markup"),n?.("markup")}),this.recordBtn.addEventListener("click",()=>{this.setMode("record"),n?.("record")}),this.el.querySelector(".mtb-exit-btn").addEventListener("click",r),document.addEventListener("pointermove",this.handlePointerMove)}buildHTML(t){return`
9
9
  <div class="mtb-toolbar-modes">
10
10
  <button class="mtb-toolbar-mode-btn mtb-toolbar-mode-markup active" aria-label="${t.toolbar.markup}" title="${t.toolbar.markup}">
11
11
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><line x1="12" y1="3" x2="12" y2="7"/><line x1="12" y1="17" x2="12" y2="21"/><line x1="3" y1="12" x2="7" y2="12"/><line x1="17" y1="12" x2="21" y2="12"/></svg><span class="mtb-toolbar-label">${t.toolbar.markup}</span>
@@ -20,7 +20,7 @@
20
20
  <path d="M18 6L6 18M6 6l12 12"/>
21
21
  </svg><span class="mtb-toolbar-label">${t.toolbar.exit}</span>
22
22
  </button>
23
- `}setMode(t){this.currentMode=t,t==="markup"?(this.markupBtn.classList.add("active"),this.recordBtn.classList.remove("active"),this.hintTextEl.textContent=this.messages.toolbar.hint):(this.markupBtn.classList.remove("active"),this.recordBtn.classList.add("active"),this.hintTextEl.textContent=this.messages.toolbar.hintRecord)}getMode(){return this.currentMode}destroy(){document.removeEventListener("pointermove",this.handlePointerMove),this.host.removeAttribute("data-mtb-toolbar"),this.hintBarEl.remove(),this.el.remove()}}class he{constructor(t,e){this.handlers=e,this.overlayEl=t.el("div","mtb-overlay"),this.onPointerDown=r=>{const n=r;if(n.isPrimary){try{this.overlayEl.setPointerCapture(n.pointerId)}catch{}this.handlers.onPointerDown(n)}},this.onPointerMove=r=>{const n=r;n.isPrimary&&this.handlers.onPointerMove(n)},this.onPointerUp=r=>{const n=r;n.isPrimary&&(this.releaseCapture(n.pointerId),this.handlers.onPointerUp(n))},this.onPointerCancel=r=>{const n=r;n.isPrimary&&(this.releaseCapture(n.pointerId),this.handlers.onPointerCancel(n))},this.overlayEl.addEventListener("pointerdown",this.onPointerDown),this.overlayEl.addEventListener("pointermove",this.onPointerMove),this.overlayEl.addEventListener("pointerup",this.onPointerUp),this.overlayEl.addEventListener("pointercancel",this.onPointerCancel),t.append(this.overlayEl),this.dimEl=t.el("div","mtb-dim"),t.append(this.dimEl)}releaseCapture(t){try{this.overlayEl.releasePointerCapture(t)}catch{}}destroy(){this.overlayEl.removeEventListener("pointerdown",this.onPointerDown),this.overlayEl.removeEventListener("pointermove",this.onPointerMove),this.overlayEl.removeEventListener("pointerup",this.onPointerUp),this.overlayEl.removeEventListener("pointercancel",this.onPointerCancel),this.overlayEl.remove(),this.dimEl.remove()}}class ue{constructor(t){this.highlightEl=t.el("div","mtb-highlight"),this.tooltipEl=t.el("div","mtb-highlight-tooltip"),this.hide(),t.append(this.highlightEl,this.tooltipEl)}highlight(t){const e=t.getBoundingClientRect();this.highlightEl.style.top=`${e.top-2}px`,this.highlightEl.style.left=`${e.left-2}px`,this.highlightEl.style.width=`${e.width+4}px`,this.highlightEl.style.height=`${e.height+4}px`,this.highlightEl.style.display="block",this.showTooltip(t,e)}showTooltip(t,e){this.tooltipEl.textContent=G(t);const r=e.top<30;this.tooltipEl.classList.toggle("below",r),this.tooltipEl.style.left=`${e.left+e.width/2}px`,this.tooltipEl.style.top=r?`${e.bottom+8}px`:`${e.top-8}px`,this.tooltipEl.style.display="block"}select(){this.highlightEl.classList.add("selected"),this.tooltipEl.style.display="none"}hide(){this.highlightEl.style.display="none",this.highlightEl.classList.remove("selected"),this.tooltipEl.style.display="none"}destroy(){this.highlightEl.remove(),this.tooltipEl.remove()}}const me=/^(script|style|noscript|template)$/i;function Lt(i,t=80){let e="";for(const r of Array.from(i.childNodes)){if(e.length>=t)break;r.nodeType===3?e+=r.nodeValue??"":r instanceof Element&&!me.test(r.tagName)&&(e+=Lt(r,t-e.length))}return e}function G(i){if(i instanceof HTMLElement){const t=i.getAttribute("aria-label");if(t)return t;const e=i.getAttribute("title");if(e)return e;const r=Lt(i).trim().slice(0,40);if(r)return r;const n=i.placeholder;if(n)return n;const s=i.alt;if(s)return s;const o=i.getAttribute("data-mark");if(o)return o}return i.tagName.toLowerCase()}function Mt(i){const t=[];let e=i;for(;e&&e!==document.body&&t.length<5;){let r=e.tagName.toLowerCase();if(e.id){r=`#${e.id}`,t.unshift(r);break}const n=Array.from(e.classList).filter(o=>!o.startsWith("mtb-")).slice(0,2).join(".");n&&(r+=`.${n}`);const s=e.parentElement;if(s){const o=Array.from(s.children).filter(a=>a.tagName===e.tagName);if(o.length>1){const a=o.indexOf(e)+1;r+=`:nth-of-type(${a})`}}t.unshift(r),e=e.parentElement}return t.join(" > ")}class fe{constructor(t){this.pins=[],this.shadow=t}addPin(t,e){const r=this.shadow.el("div","mtb-pin");r.style.top=`${e}px`,r.style.left=`${t}px`,this.shadow.append(r),this.pins.push(r)}clearAll(){for(const t of this.pins)t.remove();this.pins=[]}destroy(){this.clearAll()}}const z="#059669",be="5,150,105";function J(i){return`rgba(${be},${i})`}const pe='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',C={color:z,width:"3.5",linecap:"round",linejoin:"round",filter:`drop-shadow(0 1px 2px ${J(.35)})`};class ge{constructor(t){this.currentPath=null,this.currentPoints=[],this.isDrawing=!1,this.committed=[],this.redoStack=[],this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svg.setAttribute("class","mtb-draw-svg"),t.append(this.svg)}startDraw(t,e){this.isDrawing=!0,this.currentPoints=[[t,e]],this.currentPath=this.createPath(),this.svg.appendChild(this.currentPath)}continueDraw(t,e){!this.isDrawing||!this.currentPath||(this.currentPoints.push([t,e]),this.currentPath.setAttribute("d",rt(this.currentPoints)))}getCurrentSpan(){const[t]=this.currentPoints;if(!t)return 0;let e=0;for(const[r,n]of this.currentPoints)e=Math.max(e,Math.hypot(r-t[0],n-t[1]));return e}commitStroke(){return!this.isDrawing||!this.currentPath?!1:(this.isDrawing=!1,this.committed.push({path:this.currentPath,d:rt(this.currentPoints),points:this.currentPoints}),this.redoStack=[],this.currentPath=null,this.currentPoints=[],!0)}cancelCurrentDraw(){this.currentPath?.remove(),this.currentPath=null,this.isDrawing=!1,this.currentPoints=[]}undo(){const t=this.committed.pop();return t?(t.path.remove(),this.redoStack.push({d:t.d,points:t.points}),!0):!1}redo(){const t=this.redoStack.pop();if(!t)return!1;const e=this.createPath();return e.setAttribute("d",t.d),this.svg.appendChild(e),this.committed.push({path:e,d:t.d,points:t.points}),!0}canUndo(){return this.committed.length>0}canRedo(){return this.redoStack.length>0}hasStrokes(){return this.committed.length>0}getAnnotation(){if(this.committed.length===0)return null;const t=this.committed.flatMap(n=>n.points),[e,r]=ye(t);return{type:"draw",x:e,y:r,drawPath:this.committed.map(n=>n.d).join(" ")}}clearAll(){for(;this.svg.firstChild;)this.svg.removeChild(this.svg.firstChild);this.currentPath=null,this.isDrawing=!1,this.currentPoints=[],this.committed=[],this.redoStack=[]}isCurrentlyDrawing(){return this.isDrawing}destroy(){this.svg.remove()}createPath(){const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("fill","none"),t.setAttribute("stroke",C.color),t.setAttribute("stroke-width",C.width),t.setAttribute("stroke-linecap",C.linecap),t.setAttribute("stroke-linejoin",C.linejoin),t.setAttribute("style",`filter:${C.filter}`),t}}function rt(i){if(i.length===0)return"";const[t,e]=i[0];let r=`M ${t} ${e}`;for(let n=1;n<i.length;n++){const[s,o]=i[n];r+=` L ${s} ${o}`}return r}function ye(i){const t=i.map(s=>s[0]),e=i.map(s=>s[1]),r=(Math.min(...t)+Math.max(...t))/2,n=(Math.min(...e)+Math.max(...e))/2;return[r,n]}const we=10;class xe{constructor(t,e,r){this.messages=e,this.handlers=r,this.interactionActive=!0,this.pendingHighlightFrame=null,this.lastMoveX=0,this.lastMoveY=0,this.highlighter=new ue(t),this.pinMarker=new fe(t),this.drawLayer=new ge(t),this.overlay=new he(t,{onPointerDown:n=>this.handlePointerDown(n),onPointerMove:n=>this.handlePointerMove(n),onPointerUp:n=>this.handlePointerUp(n),onPointerCancel:()=>{this.drawLayer.isCurrentlyDrawing()&&this.finishStroke(),this.cancelPendingHighlight(),this.highlighter.hide()}})}handlePointerDown(t){t.preventDefault(),this.drawLayer.startDraw(t.clientX,t.clientY)}handlePointerMove(t){if(this.drawLayer.isCurrentlyDrawing()){this.cancelPendingHighlight(),this.drawLayer.continueDraw(t.clientX,t.clientY),this.highlighter.hide();return}this.lastMoveX=t.clientX,this.lastMoveY=t.clientY,this.pendingHighlightFrame===null&&(this.pendingHighlightFrame=requestAnimationFrame(()=>{this.pendingHighlightFrame=null,this.updateHighlight()}))}updateHighlight(){if(!this.interactionActive||this.drawLayer.isCurrentlyDrawing()||this.drawSessionActive())return;const t=nt(this.lastMoveX,this.lastMoveY);t?this.highlighter.highlight(t):this.highlighter.hide()}cancelPendingHighlight(){this.pendingHighlightFrame!==null&&(cancelAnimationFrame(this.pendingHighlightFrame),this.pendingHighlightFrame=null)}handlePointerUp(t){this.drawLayer.isCurrentlyDrawing()&&this.finishStroke(t)}finishStroke(t){if(this.drawLayer.getCurrentSpan()>=we){this.drawLayer.commitStroke(),this.highlighter.hide(),this.handlers.onDrawStroke();return}if(this.drawLayer.cancelCurrentDraw(),this.drawLayer.hasStrokes()||!t)return;const e=nt(t.clientX,t.clientY),r=e?G(e):this.messages.annotation.element,n=e?.getBoundingClientRect(),s={type:"pin",x:t.clientX,y:t.clientY,targetSelector:e?Mt(e):void 0,targetText:e?.textContent?.trim().slice(0,200)??"",targetName:r,targetRect:n?{top:n.top,left:n.left,width:n.width,height:n.height,bottom:n.bottom}:void 0};this.pinMarker.addPin(t.clientX,t.clientY),this.highlighter.select(),this.handlers.onPin(s,r)}undoDraw(){this.drawLayer.undo()}redoDraw(){this.drawLayer.redo()}canUndoDraw(){return this.drawLayer.canUndo()}canRedoDraw(){return this.drawLayer.canRedo()}hasDrawStrokes(){return this.drawLayer.hasStrokes()}drawSessionActive(){return this.drawLayer.hasStrokes()||this.drawLayer.canRedo()}getDrawAnnotation(){return this.drawLayer.getAnnotation()}clearDraw(){this.drawLayer.clearAll()}dismissInteraction(){this.interactionActive&&(this.interactionActive=!1,this.cancelPendingHighlight(),this.overlay.destroy())}hideHighlight(){this.highlighter.hide()}destroy(){this.dismissInteraction(),this.highlighter.destroy(),this.pinMarker.destroy(),this.drawLayer.destroy()}}function nt(i,t){return document.elementsFromPoint(i,t).find(e=>e.id!=="mtb-widget-host")??null}const ve="mtb-widget-host";function S(i){const t=document.getElementById(ve);return t?t===i||t.contains(i):!1}function h(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}class ke{constructor(){this.onChange=null,this.handler=()=>{this.onChange?.(this.current())}}current(){const t=window.visualViewport;return t?Math.max(0,Math.round(window.innerHeight-(t.height+t.offsetTop))):0}observe(t){const e=window.visualViewport;e&&(this.onChange=t,e.addEventListener("resize",this.handler),e.addEventListener("scroll",this.handler))}stop(){const t=window.visualViewport;this.onChange=null,t&&(t.removeEventListener("resize",this.handler),t.removeEventListener("scroll",this.handler))}}const Se=480;function Ee(){return window.innerWidth<=Se}class Q{constructor(t){this.el=t,this.inset=new ke}apply(){return Ee()?(this.el.style.left="",this.el.style.top="",this.el.style.maxHeight="",this.lift(this.inset.current()),this.inset.observe(t=>this.lift(t)),!0):!1}release(){this.inset.stop()}lift(t){this.el.style.bottom=t>0?`${t}px`:""}}class Ce{constructor(t,e){this.loading=!1,this.onSubmit=e.onSubmit,this.submitLabel=e.messages.draw.submit,this.el=t.el("div","mtb-draw-bar"),this.el.innerHTML=this.buildHTML(e.messages),t.append(this.el),this.sheet=new Q(this.el),this.sheet.apply(),this.input=this.el.querySelector(".mtb-draw-input"),this.undoBtn=this.el.querySelector(".mtb-draw-undo"),this.redoBtn=this.el.querySelector(".mtb-draw-redo"),this.submitBtn=this.el.querySelector(".mtb-draw-submit"),this.errorEl=this.el.querySelector(".mtb-draw-error"),this.undoBtn.addEventListener("click",e.onUndo),this.redoBtn.addEventListener("click",e.onRedo),this.el.querySelector(".mtb-draw-cancel").addEventListener("click",e.onCancel),this.submitBtn.addEventListener("click",()=>this.submit()),this.input.addEventListener("keydown",r=>{r.isComposing||r.keyCode===229||r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),this.submit())}),this.input.focus()}buildHTML(t){return`
23
+ `}setMode(t){this.currentMode=t,t==="markup"?(this.markupBtn.classList.add("active"),this.recordBtn.classList.remove("active"),this.hintTextEl.textContent=this.messages.toolbar.hint):(this.markupBtn.classList.remove("active"),this.recordBtn.classList.add("active"),this.hintTextEl.textContent=this.messages.toolbar.hintRecord)}getMode(){return this.currentMode}destroy(){document.removeEventListener("pointermove",this.handlePointerMove),this.host.removeAttribute("data-mtb-toolbar"),this.hintBarEl.remove(),this.el.remove()}}class he{constructor(t,e){this.handlers=e,this.overlayEl=t.el("div","mtb-overlay"),this.onPointerDown=r=>{const n=r;if(n.isPrimary){try{this.overlayEl.setPointerCapture(n.pointerId)}catch{}this.handlers.onPointerDown(n)}},this.onPointerMove=r=>{const n=r;n.isPrimary&&this.handlers.onPointerMove(n)},this.onPointerUp=r=>{const n=r;n.isPrimary&&(this.releaseCapture(n.pointerId),this.handlers.onPointerUp(n))},this.onPointerCancel=r=>{const n=r;n.isPrimary&&(this.releaseCapture(n.pointerId),this.handlers.onPointerCancel(n))},this.overlayEl.addEventListener("pointerdown",this.onPointerDown),this.overlayEl.addEventListener("pointermove",this.onPointerMove),this.overlayEl.addEventListener("pointerup",this.onPointerUp),this.overlayEl.addEventListener("pointercancel",this.onPointerCancel),t.append(this.overlayEl),this.dimEl=t.el("div","mtb-dim"),t.append(this.dimEl)}releaseCapture(t){try{this.overlayEl.releasePointerCapture(t)}catch{}}destroy(){this.overlayEl.removeEventListener("pointerdown",this.onPointerDown),this.overlayEl.removeEventListener("pointermove",this.onPointerMove),this.overlayEl.removeEventListener("pointerup",this.onPointerUp),this.overlayEl.removeEventListener("pointercancel",this.onPointerCancel),this.overlayEl.remove(),this.dimEl.remove()}}class ue{constructor(t){this.highlightEl=t.el("div","mtb-highlight"),this.tooltipEl=t.el("div","mtb-highlight-tooltip"),this.hide(),t.append(this.highlightEl,this.tooltipEl)}highlight(t){const e=t.getBoundingClientRect();this.highlightEl.style.top=`${e.top-2}px`,this.highlightEl.style.left=`${e.left-2}px`,this.highlightEl.style.width=`${e.width+4}px`,this.highlightEl.style.height=`${e.height+4}px`,this.highlightEl.style.display="block",this.showTooltip(t,e)}showTooltip(t,e){this.tooltipEl.textContent=G(t);const r=e.top<30;this.tooltipEl.classList.toggle("below",r),this.tooltipEl.style.left=`${e.left+e.width/2}px`,this.tooltipEl.style.top=r?`${e.bottom+8}px`:`${e.top-8}px`,this.tooltipEl.style.display="block"}select(){this.highlightEl.classList.add("selected"),this.tooltipEl.style.display="none"}hide(){this.highlightEl.style.display="none",this.highlightEl.classList.remove("selected"),this.tooltipEl.style.display="none"}destroy(){this.highlightEl.remove(),this.tooltipEl.remove()}}const me=/^(script|style|noscript|template)$/i;function Lt(i,t=80){let e="";for(const r of Array.from(i.childNodes)){if(e.length>=t)break;r.nodeType===3?e+=r.nodeValue??"":r instanceof Element&&!me.test(r.tagName)&&(e+=Lt(r,t-e.length))}return e}function G(i){if(i instanceof HTMLElement){const t=i.getAttribute("aria-label");if(t)return t;const e=i.getAttribute("title");if(e)return e;const r=Lt(i).trim().slice(0,40);if(r)return r;const n=i.placeholder;if(n)return n;const s=i.alt;if(s)return s;const o=i.getAttribute("data-mark");if(o)return o}return i.tagName.toLowerCase()}function Mt(i){const t=[];let e=i;for(;e&&e!==document.body&&t.length<5;){let r=e.tagName.toLowerCase();if(e.id){r=`#${e.id}`,t.unshift(r);break}const n=Array.from(e.classList).filter(o=>!o.startsWith("mtb-")).slice(0,2).join(".");n&&(r+=`.${n}`);const s=e.parentElement;if(s){const o=Array.from(s.children).filter(a=>a.tagName===e.tagName);if(o.length>1){const a=o.indexOf(e)+1;r+=`:nth-of-type(${a})`}}t.unshift(r),e=e.parentElement}return t.join(" > ")}class fe{constructor(t){this.pins=[],this.shadow=t}addPin(t,e){const r=this.shadow.el("div","mtb-pin");r.style.top=`${e}px`,r.style.left=`${t}px`,this.shadow.append(r),this.pins.push(r)}clearAll(){for(const t of this.pins)t.remove();this.pins=[]}destroy(){this.clearAll()}}const z="#059669",be="5,150,105";function J(i){return`rgba(${be},${i})`}const pe='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',C={color:z,width:"3.5",linecap:"round",linejoin:"round",filter:`drop-shadow(0 1px 2px ${J(.35)})`};class ge{constructor(t){this.currentPath=null,this.currentPoints=[],this.isDrawing=!1,this.committed=[],this.redoStack=[],this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svg.setAttribute("class","mtb-draw-svg"),t.append(this.svg)}startDraw(t,e){this.isDrawing=!0,this.currentPoints=[[t,e]],this.currentPath=this.createPath(),this.svg.appendChild(this.currentPath)}continueDraw(t,e){!this.isDrawing||!this.currentPath||(this.currentPoints.push([t,e]),this.currentPath.setAttribute("d",rt(this.currentPoints)))}getCurrentSpan(){const[t]=this.currentPoints;if(!t)return 0;let e=0;for(const[r,n]of this.currentPoints)e=Math.max(e,Math.hypot(r-t[0],n-t[1]));return e}commitStroke(){return!this.isDrawing||!this.currentPath?!1:(this.isDrawing=!1,this.committed.push({path:this.currentPath,d:rt(this.currentPoints),points:this.currentPoints}),this.redoStack=[],this.currentPath=null,this.currentPoints=[],!0)}cancelCurrentDraw(){this.currentPath?.remove(),this.currentPath=null,this.isDrawing=!1,this.currentPoints=[]}undo(){const t=this.committed.pop();return t?(t.path.remove(),this.redoStack.push({d:t.d,points:t.points}),!0):!1}redo(){const t=this.redoStack.pop();if(!t)return!1;const e=this.createPath();return e.setAttribute("d",t.d),this.svg.appendChild(e),this.committed.push({path:e,d:t.d,points:t.points}),!0}canUndo(){return this.committed.length>0}canRedo(){return this.redoStack.length>0}hasStrokes(){return this.committed.length>0}getAnnotation(){if(this.committed.length===0)return null;const t=this.committed.flatMap(n=>n.points),[e,r]=ye(t);return{type:"draw",x:e,y:r,drawPath:this.committed.map(n=>n.d).join(" ")}}clearAll(){for(;this.svg.firstChild;)this.svg.removeChild(this.svg.firstChild);this.currentPath=null,this.isDrawing=!1,this.currentPoints=[],this.committed=[],this.redoStack=[]}isCurrentlyDrawing(){return this.isDrawing}destroy(){this.svg.remove()}createPath(){const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("fill","none"),t.setAttribute("stroke",C.color),t.setAttribute("stroke-width",C.width),t.setAttribute("stroke-linecap",C.linecap),t.setAttribute("stroke-linejoin",C.linejoin),t.setAttribute("style",`filter:${C.filter}`),t}}function rt(i){if(i.length===0)return"";const[t,e]=i[0];let r=`M ${t} ${e}`;for(let n=1;n<i.length;n++){const[s,o]=i[n];r+=` L ${s} ${o}`}return r}function ye(i){const t=i.map(s=>s[0]),e=i.map(s=>s[1]),r=(Math.min(...t)+Math.max(...t))/2,n=(Math.min(...e)+Math.max(...e))/2;return[r,n]}const we=10;class xe{constructor(t,e,r){this.messages=e,this.handlers=r,this.interactionActive=!0,this.pendingHighlightFrame=null,this.lastMoveX=0,this.lastMoveY=0,this.highlighter=new ue(t),this.pinMarker=new fe(t),this.drawLayer=new ge(t),this.overlay=new he(t,{onPointerDown:n=>this.handlePointerDown(n),onPointerMove:n=>this.handlePointerMove(n),onPointerUp:n=>this.handlePointerUp(n),onPointerCancel:()=>{this.drawLayer.isCurrentlyDrawing()&&this.finishStroke(),this.cancelPendingHighlight(),this.highlighter.hide()}})}handlePointerDown(t){t.preventDefault(),this.drawLayer.startDraw(t.clientX,t.clientY)}handlePointerMove(t){if(this.drawLayer.isCurrentlyDrawing()){this.cancelPendingHighlight(),this.drawLayer.continueDraw(t.clientX,t.clientY),this.highlighter.hide();return}this.lastMoveX=t.clientX,this.lastMoveY=t.clientY,this.pendingHighlightFrame===null&&(this.pendingHighlightFrame=requestAnimationFrame(()=>{this.pendingHighlightFrame=null,this.updateHighlight()}))}updateHighlight(){if(!this.interactionActive||this.drawLayer.isCurrentlyDrawing()||this.drawSessionActive())return;const t=nt(this.lastMoveX,this.lastMoveY);t?this.highlighter.highlight(t):this.highlighter.hide()}cancelPendingHighlight(){this.pendingHighlightFrame!==null&&(cancelAnimationFrame(this.pendingHighlightFrame),this.pendingHighlightFrame=null)}handlePointerUp(t){this.drawLayer.isCurrentlyDrawing()&&this.finishStroke(t)}finishStroke(t){if(this.drawLayer.getCurrentSpan()>=we){this.drawLayer.commitStroke(),this.highlighter.hide(),this.handlers.onDrawStroke();return}if(this.drawLayer.cancelCurrentDraw(),this.drawLayer.hasStrokes()||!t)return;const e=nt(t.clientX,t.clientY),r=e?G(e):this.messages.annotation.element,n=e?.getBoundingClientRect(),s={type:"pin",x:t.clientX,y:t.clientY,targetSelector:e?Mt(e):void 0,targetText:e?.textContent?.trim().slice(0,200)??"",targetName:r,targetRect:n?{top:n.top,left:n.left,width:n.width,height:n.height,bottom:n.bottom}:void 0};this.pinMarker.addPin(t.clientX,t.clientY),this.highlighter.select(),this.handlers.onPin(s,r)}undoDraw(){this.drawLayer.undo()}redoDraw(){this.drawLayer.redo()}canUndoDraw(){return this.drawLayer.canUndo()}canRedoDraw(){return this.drawLayer.canRedo()}hasDrawStrokes(){return this.drawLayer.hasStrokes()}drawSessionActive(){return this.drawLayer.hasStrokes()||this.drawLayer.canRedo()}getDrawAnnotation(){return this.drawLayer.getAnnotation()}clearDraw(){this.drawLayer.clearAll()}dismissInteraction(){this.interactionActive&&(this.interactionActive=!1,this.cancelPendingHighlight(),this.overlay.destroy())}hideHighlight(){this.highlighter.hide()}destroy(){this.dismissInteraction(),this.highlighter.destroy(),this.pinMarker.destroy(),this.drawLayer.destroy()}}function nt(i,t){return document.elementsFromPoint(i,t).find(e=>e.id!=="mtb-widget-host")??null}const ve="mtb-widget-host";function S(i){const t=document.getElementById(ve);return t?t===i||t.contains(i):!1}function h(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}class ke{constructor(){this.onChange=null,this.handler=()=>{this.onChange?.(this.current())}}current(){const t=window.visualViewport;return t?Math.max(0,Math.round(window.innerHeight-(t.height+t.offsetTop))):0}observe(t){const e=window.visualViewport;e&&(this.onChange=t,e.addEventListener("resize",this.handler),e.addEventListener("scroll",this.handler))}stop(){const t=window.visualViewport;this.onChange=null,t&&(t.removeEventListener("resize",this.handler),t.removeEventListener("scroll",this.handler))}}const Se=480;function Ee(){return window.innerWidth<=Se}class Q{constructor(t){this.el=t,this.inset=new ke}apply(){return Ee()?(this.el.style.left="",this.el.style.top="",this.el.style.maxHeight="",this.lift(this.inset.current()),this.inset.observe(t=>this.lift(t)),!0):!1}release(){this.inset.stop()}lift(t){this.el.style.bottom=t>0?`${t}px`:""}}class Ce{constructor(t,e){this.loading=!1,this.onSubmit=e.onSubmit,this.submitLabel=e.messages.draw.submit,this.el=t.el("div","mtb-draw-bar"),this.el.innerHTML=this.buildHTML(e.messages),t.append(this.el),this.sheet=new Q(this.el),this.sheet.apply(),this.input=this.el.querySelector(".mtb-draw-input"),this.undoBtn=this.el.querySelector(".mtb-draw-undo"),this.redoBtn=this.el.querySelector(".mtb-draw-redo"),this.submitBtn=this.el.querySelector(".mtb-draw-submit"),this.errorEl=this.el.querySelector(".mtb-draw-error"),this.undoBtn.addEventListener("click",e.onUndo),this.redoBtn.addEventListener("click",e.onRedo),this.el.querySelector(".mtb-draw-cancel").addEventListener("click",e.onCancel),this.submitBtn.addEventListener("click",()=>this.submit()),this.input.addEventListener("keydown",r=>{r.isComposing||r.keyCode===229||r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),this.submit())}),this.input.focus({preventScroll:!0})}buildHTML(t){return`
24
24
  <input class="mtb-draw-input" type="text" placeholder="${h(t.draw.note_placeholder)}" />
25
25
  <button class="mtb-draw-icon-btn mtb-draw-undo" type="button" title="${h(t.draw.undo)}" aria-label="${h(t.draw.undo)}" disabled>
26
26
  <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 14L4 9l5-5"/><path d="M4 9h11a5 5 0 0 1 0 10h-1"/></svg>
@@ -32,7 +32,7 @@
32
32
  <button class="mtb-draw-cancel" type="button">${h(t.draw.cancel)}</button>
33
33
  <button class="mtb-draw-submit" type="button">${h(t.draw.submit)}</button>
34
34
  <div class="mtb-draw-error" role="alert" hidden></div>
35
- `}setUndoRedo(t,e){this.undoBtn.disabled=!t||this.loading,this.redoBtn.disabled=!e||this.loading}setLoading(t){this.loading=t,this.input.disabled=t,this.submitBtn.disabled=t,this.undoBtn.disabled=t||this.undoBtn.disabled,this.redoBtn.disabled=t||this.redoBtn.disabled,t?(this.submitBtn.classList.add("loading"),this.submitBtn.innerHTML='<span class="mtb-dot"></span><span class="mtb-dot"></span><span class="mtb-dot"></span>',this.errorEl.hidden=!0,this.errorEl.textContent=""):(this.submitBtn.classList.remove("loading"),this.submitBtn.textContent=this.submitLabel)}setError(t){this.errorEl.textContent=t,this.errorEl.hidden=!1}submit(){this.loading||this.onSubmit(this.input.value.trim())}destroy(){this.sheet.release(),this.el.remove()}}class _e{constructor(t,e){this.loading=!1,this.selectedQuickOption=null,this.onSubmit=e.onSubmit,this.onClose=e.onClose,this.submitLabel=e.messages.popup.submit,this.messages=e.messages,this.el=t.el("div","mtb-popup"),this.el.innerHTML=this.buildHTML(e),t.append(this.el),this.sheet=new Q(this.el),this.textarea=this.el.querySelector(".mtb-textarea"),this.submitBtn=this.el.querySelector(".mtb-submit-btn"),this.positionPopup(e.x,e.y,e.targetRect,e.position??"right"),this.bindEvents(e.messages),e.onMyFeedback&&this.el.querySelector(".mtb-my-feedback").addEventListener("click",e.onMyFeedback),this.textarea.focus()}buildHTML(t){const e=t.messages,r=e.popup.quickOptions.map(n=>`
35
+ `}setUndoRedo(t,e){this.undoBtn.disabled=!t||this.loading,this.redoBtn.disabled=!e||this.loading}setLoading(t){this.loading=t,this.input.disabled=t,this.submitBtn.disabled=t,this.undoBtn.disabled=t||this.undoBtn.disabled,this.redoBtn.disabled=t||this.redoBtn.disabled,t?(this.submitBtn.classList.add("loading"),this.submitBtn.innerHTML='<span class="mtb-dot"></span><span class="mtb-dot"></span><span class="mtb-dot"></span>',this.errorEl.hidden=!0,this.errorEl.textContent=""):(this.submitBtn.classList.remove("loading"),this.submitBtn.textContent=this.submitLabel)}setError(t){this.errorEl.textContent=t,this.errorEl.hidden=!1}submit(){this.loading||this.onSubmit(this.input.value.trim())}destroy(){this.sheet.release(),this.el.remove()}}class _e{constructor(t,e){this.loading=!1,this.selectedQuickOption=null,this.onSubmit=e.onSubmit,this.onClose=e.onClose,this.submitLabel=e.messages.popup.submit,this.messages=e.messages,this.el=t.el("div","mtb-popup"),this.el.innerHTML=this.buildHTML(e),t.append(this.el),this.sheet=new Q(this.el),this.textarea=this.el.querySelector(".mtb-textarea"),this.submitBtn=this.el.querySelector(".mtb-submit-btn"),this.positionPopup(e.x,e.y,e.targetRect,e.position??"right"),this.bindEvents(e.messages),e.onMyFeedback&&this.el.querySelector(".mtb-my-feedback").addEventListener("click",e.onMyFeedback),this.textarea.focus({preventScroll:!0})}buildHTML(t){const e=t.messages,r=e.popup.quickOptions.map(n=>`
36
36
  <button class="mtb-quick-option" data-quick="${h(n.label)}">
37
37
  <span class="mtb-quick-option-emoji">${n.emoji}</span>
38
38
  <span>${h(n.label)}</span>
@@ -99,7 +99,7 @@
99
99
  <span>${h(t.clarify.send)}</span>
100
100
  </button>
101
101
  </div>
102
- `}bindEvents(){this.el.querySelector(".mtb-clarify-close").addEventListener("click",()=>this.skipAndFinalize()),this.bindConversationControls()}bindConversationControls(){this.inputEl=this.el.querySelector(".mtb-clarify-input"),this.sendBtn=this.el.querySelector(".mtb-clarify-send"),this.el.querySelector(".mtb-clarify-skip").addEventListener("click",()=>this.skipAndFinalize()),this.inputEl.addEventListener("input",()=>{this.sendBtn.disabled=!this.inputEl.value.trim()}),this.inputEl.addEventListener("keydown",t=>{t.isComposing||t.keyCode===229||t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),this.sendMessage())}),this.sendBtn.addEventListener("click",()=>this.sendMessage())}skipAndFinalize(){this.stopPolling(),this.finalize()}async startConversation(){if(this.preloadedResult){this.applyResult(this.preloadedResult);return}if(this.pendingClarification){this.showThinking();try{const t=await this.pendingClarification;if(this.destroyed)return;t?this.applyResult(t)||this.startPolling():await this.runInitialTurnViaPolling()}catch{if(this.destroyed)return;await this.runInitialTurnViaPolling()}return}this.showThinking(),await this.runInitialTurn()}async sendMessage(){const t=this.inputEl.value.trim();if(!(!t||this.sending)){this.sending=!0,this.inputEl.disabled=!0,this.sendBtn.disabled=!0,this.stopPolling(),this.appendMessage({role:"user",content:t}),this.inputEl.value="",this.showThinking(),this.clearError();try{await this.runAnswerTurn(t)}catch{if(this.destroyed)return;this.renderConversation(this.lastMessages,!1),this.inputEl.value=t,this.showError()}finally{this.sending=!1,this.inputEl.disabled=!1,this.sendBtn.disabled=!this.inputEl.value.trim(),this.inputEl.focus()}}}async runInitialTurn(){try{const t=await this.apiClient.streamClarification(this.submissionSessionId,this.submissionToken,e=>this.appendStreamDelta(e));if(this.destroyed)return;this.endStreamingBubble(),this.applyResult(t)||this.startPolling()}catch{if(this.destroyed)return;this.endStreamingBubble(),await this.runInitialTurnViaPolling()}}async runInitialTurnViaPolling(){try{const t=await this.apiClient.startClarification(this.submissionSessionId,this.submissionToken);if(this.destroyed)return;this.applyResult(t)||this.startPolling()}catch{if(this.destroyed)return;this.handleFailure()}}async runAnswerTurn(t){const e=await this.apiClient.startClarification(this.submissionSessionId,this.submissionToken,t);this.destroyed||this.applyResult(e)||this.startPolling()}showError(){const t=this.el.querySelector(".mtb-clarify-footer"),e=document.createElement("div");e.className="mtb-clarify-error",e.textContent=this.i18n.error.submit,t.prepend(e)}clearError(){this.el.querySelector(".mtb-clarify-error")?.remove()}appendStreamDelta(t){this.streamingBubble||(this.removeThinking(),this.streamingBubble=document.createElement("div"),this.streamingBubble.className="mtb-clarify-bubble mtb-clarify-ai",this.messagesEl.appendChild(this.streamingBubble)),this.streamingBubble.textContent=(this.streamingBubble.textContent??"")+t,this.messagesEl.scrollTop=this.messagesEl.scrollHeight}endStreamingBubble(){this.streamingBubble=null}startPolling(){this.stopPolling(),this.pollDeadline=Date.now()+De,this.pollTimer=setInterval(()=>this.poll(),Ie)}stopPolling(){this.pollTimer!==null&&(clearInterval(this.pollTimer),this.pollTimer=null)}async poll(){if(Date.now()>this.pollDeadline){this.stopPolling(),this.handleFailure();return}try{const t=await this.apiClient.getClarification(this.submissionSessionId,this.submissionToken);if(this.destroyed)return;this.applyResult(t)&&this.stopPolling()}catch{if(this.destroyed)return;this.stopPolling(),this.handleFailure()}}handleDone(){this.done||(this.done=!0,this.stopPolling(),this.removeThinking(),this.showFinalizeButton())}handleFailure(){this.done||(this.done=!0,this.stopPolling(),this.removeThinking(),this.showClarificationFailureActions())}showClarificationFailureActions(){const t=this.el.querySelector(".mtb-clarify-footer");t.innerHTML=`
102
+ `}bindEvents(){this.el.querySelector(".mtb-clarify-close").addEventListener("click",()=>this.skipAndFinalize()),this.bindConversationControls()}bindConversationControls(){this.inputEl=this.el.querySelector(".mtb-clarify-input"),this.sendBtn=this.el.querySelector(".mtb-clarify-send"),this.el.querySelector(".mtb-clarify-skip").addEventListener("click",()=>this.skipAndFinalize()),this.inputEl.addEventListener("input",()=>{this.sendBtn.disabled=!this.inputEl.value.trim()}),this.inputEl.addEventListener("keydown",t=>{t.isComposing||t.keyCode===229||t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),this.sendMessage())}),this.sendBtn.addEventListener("click",()=>this.sendMessage())}skipAndFinalize(){this.stopPolling(),this.finalize()}async startConversation(){if(this.preloadedResult){this.applyResult(this.preloadedResult);return}if(this.pendingClarification){this.showThinking();try{const t=await this.pendingClarification;if(this.destroyed)return;t?this.applyResult(t)||this.startPolling():await this.runInitialTurnViaPolling()}catch{if(this.destroyed)return;await this.runInitialTurnViaPolling()}return}this.showThinking(),await this.runInitialTurn()}async sendMessage(){const t=this.inputEl.value.trim();if(!(!t||this.sending)){this.sending=!0,this.inputEl.disabled=!0,this.sendBtn.disabled=!0,this.stopPolling(),this.appendMessage({role:"user",content:t}),this.inputEl.value="",this.showThinking(),this.clearError();try{await this.runAnswerTurn(t)}catch{if(this.destroyed)return;this.renderConversation(this.lastMessages,!1),this.inputEl.value=t,this.showError()}finally{this.sending=!1,this.inputEl.disabled=!1,this.sendBtn.disabled=!this.inputEl.value.trim(),this.inputEl.focus({preventScroll:!0})}}}async runInitialTurn(){try{const t=await this.apiClient.streamClarification(this.submissionSessionId,this.submissionToken,e=>this.appendStreamDelta(e));if(this.destroyed)return;this.endStreamingBubble(),this.applyResult(t)||this.startPolling()}catch{if(this.destroyed)return;this.endStreamingBubble(),await this.runInitialTurnViaPolling()}}async runInitialTurnViaPolling(){try{const t=await this.apiClient.startClarification(this.submissionSessionId,this.submissionToken);if(this.destroyed)return;this.applyResult(t)||this.startPolling()}catch{if(this.destroyed)return;this.handleFailure()}}async runAnswerTurn(t){const e=await this.apiClient.startClarification(this.submissionSessionId,this.submissionToken,t);this.destroyed||this.applyResult(e)||this.startPolling()}showError(){const t=this.el.querySelector(".mtb-clarify-footer"),e=document.createElement("div");e.className="mtb-clarify-error",e.textContent=this.i18n.error.submit,t.prepend(e)}clearError(){this.el.querySelector(".mtb-clarify-error")?.remove()}appendStreamDelta(t){this.streamingBubble||(this.removeThinking(),this.streamingBubble=document.createElement("div"),this.streamingBubble.className="mtb-clarify-bubble mtb-clarify-ai",this.messagesEl.appendChild(this.streamingBubble)),this.streamingBubble.textContent=(this.streamingBubble.textContent??"")+t,this.messagesEl.scrollTop=this.messagesEl.scrollHeight}endStreamingBubble(){this.streamingBubble=null}startPolling(){this.stopPolling(),this.pollDeadline=Date.now()+De,this.pollTimer=setInterval(()=>this.poll(),Ie)}stopPolling(){this.pollTimer!==null&&(clearInterval(this.pollTimer),this.pollTimer=null)}async poll(){if(Date.now()>this.pollDeadline){this.stopPolling(),this.handleFailure();return}try{const t=await this.apiClient.getClarification(this.submissionSessionId,this.submissionToken);if(this.destroyed)return;this.applyResult(t)&&this.stopPolling()}catch{if(this.destroyed)return;this.stopPolling(),this.handleFailure()}}handleDone(){this.done||(this.done=!0,this.stopPolling(),this.removeThinking(),this.showFinalizeButton())}handleFailure(){this.done||(this.done=!0,this.stopPolling(),this.removeThinking(),this.showClarificationFailureActions())}showClarificationFailureActions(){const t=this.el.querySelector(".mtb-clarify-footer");t.innerHTML=`
103
103
  <div class="mtb-clarify-error">${h(this.i18n.clarify.error)}</div>
104
104
  <div class="mtb-clarify-actions">
105
105
  <button class="mtb-clarify-fallback" type="button">${h(this.i18n.clarify.send_feedback)}</button>