@lionrapid/core 0.1.4-beta.0 → 0.1.4-beta.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.
- package/dist/browser/lionrapid.auto.dev.js +34 -3
- package/dist/browser/lionrapid.auto.dev.js.map +3 -3
- package/dist/browser/lionrapid.auto.js +34 -3
- package/dist/browser/lionrapid.auto.js.map +3 -3
- package/dist/browser/lionrapid.auto.min.js +3 -3
- package/dist/browser/lionrapid.auto.min.js.map +4 -4
- package/dist/browser/lionrapid.editor.js +22 -1
- package/dist/browser/lionrapid.editor.js.map +3 -3
- package/dist/browser/lionrapid.editor.min.js +3 -3
- package/dist/browser/lionrapid.editor.min.js.map +4 -4
- package/dist/browser/lionrapid.esm.js +34 -3
- package/dist/browser/lionrapid.esm.js.map +3 -3
- package/dist/browser/lionrapid.esm.min.js +2 -2
- package/dist/browser/lionrapid.esm.min.js.map +4 -4
- package/dist/browser/lionrapid.iife.dev.js +34 -3
- package/dist/browser/lionrapid.iife.dev.js.map +3 -3
- package/dist/browser/lionrapid.iife.js +34 -3
- package/dist/browser/lionrapid.iife.js.map +3 -3
- package/dist/browser/lionrapid.iife.min.js +2 -2
- package/dist/browser/lionrapid.iife.min.js.map +4 -4
- package/dist/browser/lionrapid.umd.js +34 -3
- package/dist/browser/lionrapid.umd.js.map +3 -3
- package/dist/browser/lionrapid.umd.min.js +2 -2
- package/dist/browser/lionrapid.umd.min.js.map +4 -4
- package/dist/content/safe-href.d.ts +22 -0
- package/dist/content/safe-href.d.ts.map +1 -0
- package/dist/content/safe-href.js +48 -0
- package/dist/content/safe-href.js.map +1 -0
- package/dist/content/style-mapper/DefaultStyleMapper.d.ts.map +1 -1
- package/dist/content/style-mapper/DefaultStyleMapper.js +5 -1
- package/dist/content/style-mapper/DefaultStyleMapper.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +29 -3
- package/dist/utils/logger.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var LionRapidEditor=(()=>{var
|
|
1
|
+
"use strict";var LionRapidEditor=(()=>{var he=Object.defineProperty;var me=(i,t,e)=>t in i?he(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var a=(i,t,e)=>me(i,typeof t!="symbol"?t+"":t,e);var se=`
|
|
2
2
|
/* Reset inside shadow DOM */
|
|
3
3
|
:host {
|
|
4
4
|
all: initial;
|
|
@@ -492,6 +492,6 @@
|
|
|
492
492
|
white-space: nowrap;
|
|
493
493
|
margin-top: 2px;
|
|
494
494
|
}
|
|
495
|
-
`;var A=class{constructor(){a(this,"elementToStyles",{b:"bold",strong:"bold",i:"italic",em:"italic",u:"underline",s:"strikethrough",del:"strikethrough",strike:"strikethrough",code:"code",mark:"highlight",sub:"subscript",sup:"superscript"});a(this,"styleToElement",{bold:"b",italic:"i",underline:"u",strikethrough:"s",code:"code",highlight:"mark",subscript:"sub",superscript:"sup",strong:"b",b:"b",em:"i",i:"i",u:"u",s:"s",del:"s",strike:"s",mark:"mark",sub:"sub",sup:"sup"})}mapElementToStyles(t,e){let n=[],r=t.toLowerCase(),s=this.elementToStyles[r];return s&&n.push(s),r==="a"&&e.href&&n.push(`hyperlink:${e.href}`),n}mapStylesToElement(t){for(let e of t)if(e.startsWith("hyperlink:"))return{element:"a",attrs:{href:e.slice(10)}};for(let e of t){let n=this.styleToElement[e];if(n)return{element:n,attrs:{}}}return{element:"span",attrs:{}}}};var me=new A;function S(i){let t={},e=0;function n(s){if(s.nodeType===Node.TEXT_NODE)return s.nodeValue??"";if(s.nodeType!==Node.ELEMENT_NODE)return"";let o=s,d=o.tagName.toLowerCase(),u={};for(let l=0;l<o.attributes.length;l++){let m=o.attributes[l];u[m.name.toLowerCase()]=m.value}let c=me.mapElementToStyles(d,u);if(c.length>0){e++;let l=e;t[String(l)]=c;let m="";for(let p=0;p<s.childNodes.length;p++)m+=n(s.childNodes[p]);return`<${l}>${m}</${l}>`}let h="";for(let l=0;l<s.childNodes.length;l++)h+=n(s.childNodes[l]);return h}let r="";for(let s=0;s<i.childNodes.length;s++)r+=n(i.childNodes[s]);return{text:r,styles:t}}function C(i,t){let e=(i&65535)+(t&65535);return(i>>16)+(t>>16)+(e>>16)<<16|e&65535}function fe(i,t){return i<<t|i>>>32-t}function U(i,t,e,n,r,s){return C(fe(C(C(t,i),C(n,s)),r),e)}function b(i,t,e,n,r,s,o){return U(t&e|~t&n,i,t,r,s,o)}function v(i,t,e,n,r,s,o){return U(t&n|e&~n,i,t,r,s,o)}function y(i,t,e,n,r,s,o){return U(t^e^n,i,t,r,s,o)}function x(i,t,e,n,r,s,o){return U(e^(t|~n),i,t,r,s,o)}function ge(i,t){i[t>>5]|=128<<t%32,i[(t+64>>>9<<4)+14]=t;let e=1732584193,n=-271733879,r=-1732584194,s=271733878;for(let o=0;o<i.length;o+=16){let d=e,u=n,c=r,h=s;e=b(e,n,r,s,i[o],7,-680876936),s=b(s,e,n,r,i[o+1],12,-389564586),r=b(r,s,e,n,i[o+2],17,606105819),n=b(n,r,s,e,i[o+3],22,-1044525330),e=b(e,n,r,s,i[o+4],7,-176418897),s=b(s,e,n,r,i[o+5],12,1200080426),r=b(r,s,e,n,i[o+6],17,-1473231341),n=b(n,r,s,e,i[o+7],22,-45705983),e=b(e,n,r,s,i[o+8],7,1770035416),s=b(s,e,n,r,i[o+9],12,-1958414417),r=b(r,s,e,n,i[o+10],17,-42063),n=b(n,r,s,e,i[o+11],22,-1990404162),e=b(e,n,r,s,i[o+12],7,1804603682),s=b(s,e,n,r,i[o+13],12,-40341101),r=b(r,s,e,n,i[o+14],17,-1502002290),n=b(n,r,s,e,i[o+15],22,1236535329),e=v(e,n,r,s,i[o+1],5,-165796510),s=v(s,e,n,r,i[o+6],9,-1069501632),r=v(r,s,e,n,i[o+11],14,643717713),n=v(n,r,s,e,i[o],20,-373897302),e=v(e,n,r,s,i[o+5],5,-701558691),s=v(s,e,n,r,i[o+10],9,38016083),r=v(r,s,e,n,i[o+15],14,-660478335),n=v(n,r,s,e,i[o+4],20,-405537848),e=v(e,n,r,s,i[o+9],5,568446438),s=v(s,e,n,r,i[o+14],9,-1019803690),r=v(r,s,e,n,i[o+3],14,-187363961),n=v(n,r,s,e,i[o+8],20,1163531501),e=v(e,n,r,s,i[o+13],5,-1444681467),s=v(s,e,n,r,i[o+2],9,-51403784),r=v(r,s,e,n,i[o+7],14,1735328473),n=v(n,r,s,e,i[o+12],20,-1926607734),e=y(e,n,r,s,i[o+5],4,-378558),s=y(s,e,n,r,i[o+8],11,-2022574463),r=y(r,s,e,n,i[o+11],16,1839030562),n=y(n,r,s,e,i[o+14],23,-35309556),e=y(e,n,r,s,i[o+1],4,-1530992060),s=y(s,e,n,r,i[o+4],11,1272893353),r=y(r,s,e,n,i[o+7],16,-155497632),n=y(n,r,s,e,i[o+10],23,-1094730640),e=y(e,n,r,s,i[o+13],4,681279174),s=y(s,e,n,r,i[o+0],11,-358537222),r=y(r,s,e,n,i[o+3],16,-722521979),n=y(n,r,s,e,i[o+6],23,76029189),e=y(e,n,r,s,i[o+9],4,-640364487),s=y(s,e,n,r,i[o+12],11,-421815835),r=y(r,s,e,n,i[o+15],16,530742520),n=y(n,r,s,e,i[o+2],23,-995338651),e=x(e,n,r,s,i[o],6,-198630844),s=x(s,e,n,r,i[o+7],10,1126891415),r=x(r,s,e,n,i[o+14],15,-1416354905),n=x(n,r,s,e,i[o+5],21,-57434055),e=x(e,n,r,s,i[o+12],6,1700485571),s=x(s,e,n,r,i[o+3],10,-1894986606),r=x(r,s,e,n,i[o+10],15,-1051523),n=x(n,r,s,e,i[o+1],21,-2054922799),e=x(e,n,r,s,i[o+8],6,1873313359),s=x(s,e,n,r,i[o+15],10,-30611744),r=x(r,s,e,n,i[o+6],15,-1560198380),n=x(n,r,s,e,i[o+13],21,1309151649),e=x(e,n,r,s,i[o+4],6,-145523070),s=x(s,e,n,r,i[o+11],10,-1120210379),r=x(r,s,e,n,i[o+2],15,718787259),n=x(n,r,s,e,i[o+9],21,-343485551),e=C(e,d),n=C(n,u),r=C(r,c),s=C(s,h)}return[e,n,r,s]}function be(i){let t="0123456789abcdef",e="";for(let n=0;n<i.length*4;n++)e+=t.charAt(i[n>>2]>>n%4*8+4&15)+t.charAt(i[n>>2]>>n%4*8&15);return e}function ve(i){let t=[];for(let e=0;e<i.length*8;e+=8)t[e>>5]|=(i.charCodeAt(e/8)&255)<<e%32;return t}function ye(i){return be(ge(ve(i),i.length*8))}function _(i){let t=i.trim();return"auto_"+ye(t).substring(0,12)}var xe="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption";function ie(i){let t=i.closest("[data-lr-block]");if(t){let r=t.getAttribute("data-lr-block"),s=t.getAttribute("data-lr-original"),o,d=null;if(s){let u=document.createElement(t.tagName);u.innerHTML=s,o=S(u),d=S(t)}else o=S(t);return{key:r,unit:o,translatedUnit:d,element:t}}let e=i.closest(xe);if(e){let r=S(e);return{key:_(r.text),unit:r,translatedUnit:null,element:e}}let n=i.textContent?.trim();return n&&n.length>=2?{key:_(n),unit:{text:n,styles:{}},translatedUnit:null,element:i}:null}var Ee=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),oe="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",z=class{constructor(t,e,n,r){a(this,"overlay");a(this,"currentTarget",null);a(this,"onSelect");a(this,"rafId",null);a(this,"active",!0);a(this,"rootElement");a(this,"snapshotKeyMap");this.onSelect=e,this.rootElement=n||document.body,this.snapshotKeyMap=r||null,this.overlay=document.createElement("div"),this.overlay.className="lr-overlay",t.appendChild(this.overlay),this.handleMouseOver=this.handleMouseOver.bind(this),this.handleClick=this.handleClick.bind(this),this.handleScroll=this.handleScroll.bind(this),document.addEventListener("mouseover",this.handleMouseOver,!0),document.addEventListener("click",this.handleClick,!0),window.addEventListener("scroll",this.handleScroll,!0),window.addEventListener("resize",this.handleScroll)}destroy(){this.active=!1,document.removeEventListener("mouseover",this.handleMouseOver,!0),document.removeEventListener("click",this.handleClick,!0),window.removeEventListener("scroll",this.handleScroll,!0),window.removeEventListener("resize",this.handleScroll),this.rafId!==null&&cancelAnimationFrame(this.rafId),this.overlay.remove()}clearHighlight(){this.currentTarget=null,this.overlay.classList.remove("active")}handleMouseOver(t){if(!this.active)return;let e=t.target;if(!e||!e.closest||e.closest("#__lionrapid-editor")||!this.rootElement.contains(e))return;if(this.shouldSkip(e)){this.clearHighlight();return}let n=e.closest(oe)||e.closest("[data-lr-block]");if(!n){this.clearHighlight();return}n!==this.currentTarget&&(this.currentTarget=n,this.positionOverlay(n))}handleClick(t){if(!this.active)return;let e=t.target;if(!e||!e.closest||e.closest("#__lionrapid-editor")||!this.rootElement.contains(e))return;let n=e.closest(oe)||e.closest("[data-lr-block]");if(!n||this.shouldSkip(n))return;if(t.preventDefault(),t.stopPropagation(),this.snapshotKeyMap){let s=n.getAttribute("data-lr-snap-idx");if(s!==null){let o=parseInt(s,10),d=this.snapshotKeyMap.get(o);if(d){let u=S(n);this.onSelect({key:d,unit:u,translatedUnit:null,element:n});return}}return}let r=ie(n);r&&this.onSelect(r)}handleScroll(){this.currentTarget&&(this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.currentTarget&&this.positionOverlay(this.currentTarget)}))}positionOverlay(t){let e=t.getBoundingClientRect();this.overlay.style.top=`${e.top}px`,this.overlay.style.left=`${e.left}px`,this.overlay.style.width=`${e.width}px`,this.overlay.style.height=`${e.height}px`,this.overlay.classList.add("active")}shouldSkip(t){let e=t;for(;e;){if(Ee.has(e.tagName)||e.hasAttribute("data-no-translate")||e.getAttribute("translate")==="no")return!0;e=e.parentElement}return!1}};var B=class{constructor(t,e,n,r,s,o=null,d={}){a(this,"el");a(this,"langBtnEl");a(this,"langMenuEl");a(this,"progressEl");a(this,"expanded",!1);a(this,"currentLocale");a(this,"onLanguageChange");a(this,"onExit");a(this,"onCaptureSnapshot");a(this,"dragging",!1);a(this,"dragOffsetX",0);a(this,"dragOffsetY",0);this.onLanguageChange=r,this.onExit=s,this.onCaptureSnapshot=o,this.currentLocale=n;let u=d.mode??"capture";this.el=document.createElement("div"),this.el.className="lr-fab";let c=document.createElement("button");c.className="lr-fab-btn",c.textContent="LR",c.addEventListener("click",p=>{this.dragging||(p.stopPropagation(),this.toggle())}),this.el.appendChild(c);let h=document.createElement("div");h.className="lr-fab-panel";let l=document.createElement("div");l.className="lr-lang-dropdown",this.langBtnEl=document.createElement("button"),this.langBtnEl.className="lr-lang-btn",this.langBtnEl.textContent=n.toUpperCase(),this.langBtnEl.addEventListener("click",p=>{p.stopPropagation(),this.langMenuEl.classList.toggle("open")}),l.appendChild(this.langBtnEl),this.langMenuEl=document.createElement("div"),this.langMenuEl.className="lr-lang-menu";for(let p of e){let f=document.createElement("button");f.className="lr-lang-item",p===n&&f.classList.add("active"),f.textContent=p.toUpperCase(),f.addEventListener("click",E=>{E.stopPropagation(),this.currentLocale=p,this.langBtnEl.textContent=p.toUpperCase(),this.langMenuEl.classList.remove("open"),this.langMenuEl.querySelectorAll(".lr-lang-item").forEach(I=>I.classList.remove("active")),f.classList.add("active"),this.onLanguageChange(p)}),this.langMenuEl.appendChild(f)}if(l.appendChild(this.langMenuEl),h.appendChild(l),this.onCaptureSnapshot){let p=document.createElement("button");p.className="lr-fab-snapshot",u==="recapture"?(p.textContent="Save re-capture",p.title="Save this page as a new version of the existing snapshot"):(p.textContent="Capture",p.title="Capture a redacted snapshot of this page for translators"),p.addEventListener("click",f=>{f.stopPropagation(),this.onCaptureSnapshot&&this.onCaptureSnapshot()}),h.appendChild(p)}this.progressEl=document.createElement("span"),this.progressEl.className="lr-fab-progress",h.appendChild(this.progressEl);let m=document.createElement("button");m.className="lr-fab-exit",m.textContent="Exit",m.addEventListener("click",()=>this.onExit()),h.appendChild(m),this.el.appendChild(h),t.appendChild(this.el),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this),c.addEventListener("mousedown",this.handleMouseDown)}toggle(){this.expanded=!this.expanded,this.el.classList.toggle("expanded",this.expanded)}updateProgress(t,e){this.progressEl.textContent=`${t}/${e}`}getCurrentLocale(){return this.currentLocale}destroy(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),this.el.remove()}handleMouseDown(t){this.dragging=!1,this.dragOffsetX=t.clientX-this.el.getBoundingClientRect().left,this.dragOffsetY=t.clientY-this.el.getBoundingClientRect().top,document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}handleMouseMove(t){this.dragging=!0;let e=Math.max(0,Math.min(t.clientX-this.dragOffsetX,window.innerWidth-this.el.offsetWidth)),n=Math.max(0,Math.min(t.clientY-this.dragOffsetY,window.innerHeight-this.el.offsetHeight));this.el.style.left=`${e}px`,this.el.style.top=`${n}px`,this.el.style.right="auto",this.el.style.bottom="auto"}handleMouseUp(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),this.dragging&&setTimeout(()=>{this.dragging=!1},0)}};var R=class{constructor(t={}){a(this,"styleMapper");this.styleMapper=t.styleMapper??new A}serialize(t){let{text:e,styles:n}=t,r=/<(\/?)?(\d+)(\/)?>/g,s="",o=0,d;for(;(d=r.exec(e))!==null;){s+=e.slice(o,d.index);let[u,c,h,l]=d,p=n[h]||[];if(c){let f=this.styleMapper.mapStylesToElement(p);s+=`</${f.element}>`}else if(l){let f=this.styleMapper.mapStylesToElement(p),E=this.formatAttributes(f.attrs);s+=`<${f.element}${E} />`}else{let f=this.styleMapper.mapStylesToElement(p),E=this.formatAttributes(f.attrs);s+=`<${f.element}${E}>`}o=d.index+u.length}return s+=e.slice(o),s}formatAttributes(t){let e=Object.entries(t);return e.length===0?"":" "+e.map(([n,r])=>`${n}="${this.escapeAttributeValue(r)}"`).join(" ")}escapeAttributeValue(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}};var Se=new R;function J(i,t,e,n,r,s){i.hasAttribute("data-lr-original")||i.setAttribute("data-lr-original",i.innerHTML);let d=window.LionRapid?.autoTranslator?ke():null;if(d){let u=`${r}:${s}:${n}`;d.set(u,t,e)}if(e&&Object.keys(e).length>0){let u={text:t,styles:e};i.innerHTML=Se.serialize(u)}else i.textContent=t;i.setAttribute("data-lr-block",n),i.setAttribute("data-lionrapid-client","1")}function ke(){try{let i=window.LionRapid;if(!i)return null;let t=i.autoTranslator;if(!t)return null;let e=t.core;if(!e)return null;let n=e.cache;return!n||typeof n.set!="function"?null:n}catch{return null}}var we={emails:!0,urls:!0,numbers:!0,phones:!0},H={email:/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,url:/^(https?:\/\/|www\.)[^\s]+$/i,number:/^[\d\s.,+-]+$/,phone:/^[+\d][\d\s().-]{6,}$/},j=class{constructor(t={},e=2){a(this,"patterns");a(this,"minTextLength");this.patterns={...we,...t},this.minTextLength=e}shouldExclude(t){let e=t.trim();return!!(e.length<this.minTextLength||this.patterns.emails&&H.email.test(e)||this.patterns.urls&&H.url.test(e)||this.patterns.numbers&&H.number.test(e)||this.patterns.phones&&H.phone.test(e))}};var Y="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",Te=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),Ce=["data-lionrapid-translated","data-lionrapid-client","data-no-translate"],P=class{constructor(t={},e=[],n=2){a(this,"excludeFilter");a(this,"excludeSelectors");this.excludeFilter=new j(t,n),this.excludeSelectors=e}extract(t,e=!1){let n=[],r=t.querySelectorAll(Y),s=[];t instanceof Element&&t.matches(Y)&&s.push(t);for(let o=0;o<r.length;o++)s.push(r[o]);for(let o=0;o<s.length;o++){let d=s[o];if(this.isInsideSkipTag(d)||!e&&this.hasSkipAttribute(d)||this.matchesExcludeSelector(d)||d.getAttribute("translate")==="no"||d.querySelector(Y))continue;let u=d.getAttribute("data-lr-block"),c=d.getAttribute("data-lr-original"),h;if(c){let p=document.createElement(d.tagName);p.innerHTML=c,h=S(p)}else h=S(d);let l=h.text.replace(/<\/?[0-9]+\/?>/g,"");if(this.excludeFilter.shouldExclude(l))continue;let m;if(u)m=u;else{let p=d.getAttribute("data-i18n");p?m=p.includes(":")?p:`common:${p}`:m=_(h.text)}n.push({element:d,unit:h,key:m})}return n}isInsideSkipTag(t){let e=t.parentElement;for(;e;){if(Te.has(e.tagName))return!0;e=e.parentElement}return!1}hasSkipAttribute(t){let e=t;for(;e;){for(let n of Ce)if(e.hasAttribute(n))return!0;e=e.parentElement}return!1}matchesExcludeSelector(t){for(let e of this.excludeSelectors)try{if(t.matches(e)||t.closest(e))return!0}catch{}return!1}};var Le=new R,D=class{constructor(t,e,n,r,s,o,d=""){a(this,"el");a(this,"bodyEl");a(this,"statusEl");a(this,"api");a(this,"locale");a(this,"namespace");a(this,"defaultLocale");a(this,"current",null);a(this,"blockExtractor");a(this,"onBlockClick");a(this,"statusMap",new Map);a(this,"unsavedKeys",new Set);a(this,"onProgressUpdate",null);a(this,"lastFetchTime",0);a(this,"lastFlushTime",0);a(this,"userRole");this.api=e,this.locale=n,this.namespace=r,this.defaultLocale=s,this.onBlockClick=o,this.userRole=d,this.blockExtractor=new P,this.el=document.createElement("div"),this.el.className="lr-sidebar";let u=document.createElement("div");u.className="lr-sidebar-resize",this.initResize(u),this.el.appendChild(u);let c=document.createElement("div");c.className="lr-sidebar-header";let h=document.createElement("span");h.className="lr-sidebar-title",h.textContent="Edit Translation",c.appendChild(h);let l=document.createElement("button");l.className="lr-sidebar-close",l.innerHTML="×",l.addEventListener("click",()=>this.close()),c.appendChild(l),this.el.appendChild(c),this.bodyEl=document.createElement("div"),this.bodyEl.className="lr-sidebar-body",this.el.appendChild(this.bodyEl),this.statusEl=document.createElement("div"),this.statusEl.className="lr-status",this.api.setStatusCallback((m,p)=>{this.statusEl.textContent=p||m,this.statusEl.className=`lr-status ${m}`}),this.api.setFlushedCallback(async m=>{this.lastFlushTime=Date.now();let p=await this.api.fetchStatus(m,this.locale,this.namespace);for(let[f,E]of Object.entries(p))this.statusMap.set(f,E),this.unsavedKeys.delete(f);this.refreshBlocksList(),this.emitProgress()}),t.appendChild(this.el)}open(t){this.current=t,this.el.classList.add("open"),this.renderContent(t)}close(){this.current=null,this.el.classList.remove("open")}isOpen(){return this.el.classList.contains("open")}updateLocale(t){this.locale=t,this.statusMap.clear(),this.unsavedKeys.clear()}setProgressCallback(t){this.onProgressUpdate=t}async hydrateStatus(){let t=this.blockExtractor.extract(document.body,!0),e=t.map(r=>r.key);if(e.length===0)return;let n=await this.api.fetchStatus(e,this.locale,this.namespace);for(let[r,s]of Object.entries(n))this.statusMap.set(r,s);for(let r of t){let s=this.statusMap.get(r.key);s&&s.text&&!s.isReady&&J(r.element,s.text,r.unit.styles,r.key,this.locale,this.namespace)}this.emitProgress()}getTranslatedCount(){let t=0;for(let e of this.statusMap.values())e&&e.rowState!=="empty"&&t++;return t}getTotalCount(){return this.blockExtractor.extract(document.body,!0).length}emitProgress(){this.onProgressUpdate&&this.onProgressUpdate(this.getTranslatedCount(),this.getTotalCount())}destroy(){this.el.remove()}async renderContent(t){let{key:e,unit:n,element:r}=t;if(this.bodyEl.innerHTML="",this.lastFlushTime>this.lastFetchTime||this.lastFetchTime===0){let m=this.blockExtractor.extract(document.body,!0).map(f=>f.key);m.includes(e)||m.push(e);let p=await this.api.fetchStatus(m,this.locale,this.namespace);for(let[f,E]of Object.entries(p))this.statusMap.set(f,E);this.lastFetchTime=Date.now()}else{let l=await this.api.fetchStatus([e],this.locale,this.namespace);l[e]!==void 0&&this.statusMap.set(e,l[e])}let o=this.statusMap.get(e)??null;this.addField("Key",()=>{let l=document.createElement("div");return l.className="lr-field-key",l.textContent=e,l}),this.addField("Original",()=>{let l=document.createElement("div");return l.className="lr-field-original",l.innerHTML=this.renderTextWithTags(n.text),l});let d=this.locale===this.defaultLocale,u=d||o?.isLocked||o?.isReady||!1,c=document.createElement("textarea");this.addField("Translation",()=>(c.className="lr-textarea",c.value=o?.text||t.translatedUnit?.text||"",c.placeholder=n.text,u&&(c.readOnly=!0,c.classList.add("lr-textarea-locked"),c.title=d?"Source language \u2014 switch to a target language to edit":o?.isReady?"Approved for delivery \u2014 read only":"Locked \u2014 read only"),c)),this.bodyEl.appendChild(this.statusEl);let h=document.createElement("div");this.addField("Preview",()=>(h.className="lr-preview",c.value&&(h.innerHTML=this.renderPreview(c.value,n.styles)),h)),d||this.renderWorkflowActions(e,o),u||c.addEventListener("input",()=>{let l=c.value;h.innerHTML=this.renderPreview(l,n.styles),l&&J(r,l,n.styles,e,this.locale,this.namespace),this.unsavedKeys.add(e),this.api.queueSave({key:e,locale:this.locale,namespace:this.namespace,text:l,styles:n.styles})}),this.renderBlocksList(),u||setTimeout(()=>c.focus(),100)}renderWorkflowActions(t,e){let n=this.userRole==="project_manager"||this.userRole==="admin",r=!!e?.isReady,s=!!e?.isLocked,o=!!e?.isConfirmed,d=`${this.locale}:${this.namespace}:${t}`,u=document.createElement("div");u.className="lr-workflow-actions";let c=(h,l,m="secondary")=>{let p=document.createElement("button");p.className=`lr-wf-btn lr-wf-${m}`,p.textContent=h,p.addEventListener("click",async()=>{p.disabled=!0;let f=await this.api.transitionTarget(d,l);p.disabled=!1,f&&await this.refreshStatusForKey(t)}),u.appendChild(p)};!s&&!r&&(c("Confirm","confirm","primary"),c("Reject","reject","danger")),o&&!s&&!r&&c("Unconfirm","unconfirm"),n&&(r?c("Unmark Ready","unmark-ready","danger"):c("Mark Ready","mark-ready","primary")),u.children.length>0&&this.bodyEl.appendChild(u)}async refreshStatusForKey(t){let e=await this.api.fetchStatus([t],this.locale,this.namespace);for(let[n,r]of Object.entries(e))this.statusMap.set(n,r);this.current&&this.renderContent(this.current),this.emitProgress()}addField(t,e){let n=document.createElement("div");n.className="lr-field";let r=document.createElement("span");r.className="lr-field-label",r.textContent=t,n.appendChild(r),n.appendChild(e()),this.bodyEl.appendChild(n)}getDotClass(t){if(this.unsavedKeys.has(t))return"unsaved";let e=this.statusMap.get(t);return e?e.isLocked?"locked":e.isReady?"ready":e.isConfirmed?"confirmed":e.rowState==="edited"?"edited":e.rowState==="machine_translated"?"mt":"missing":"missing"}renderTextWithTags(t){return t.replace(/<(\/?)?(\d+)(\/)?>/g,e=>`<span class="lr-field-tag">${e}</span>`)}renderPreview(t,e){if(!t)return"";if(Object.keys(e).length>0){let n={text:t,styles:e};return Le.serialize(n)}return t}initResize(t){let e=0,n=0,r=o=>{let d=n+(e-o.clientX),u=Math.max(280,Math.min(600,d));this.el.style.width=`${u}px`},s=()=>{t.classList.remove("active"),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",s)};t.addEventListener("mousedown",o=>{o.preventDefault(),e=o.clientX,n=this.el.offsetWidth,t.classList.add("active"),document.addEventListener("mousemove",r),document.addEventListener("mouseup",s)})}refreshBlocksList(){let t=this.bodyEl.querySelector(".lr-blocks-section");t&&t.remove(),this.renderBlocksList()}renderBlocksList(){let t=document.createElement("div");t.className="lr-blocks-section";let e=this.blockExtractor.extract(document.body,!0),n=this.getTranslatedCount(),r=document.createElement("div");r.className="lr-blocks-title",r.textContent=`Blocks on this page (${n}/${e.length} translated)`,t.appendChild(r);for(let s of e){let o=document.createElement("div");o.className="lr-block-item",this.current&&s.element===this.current.element&&o.classList.add("active");let u=document.createElement("span");u.className="lr-status-dot",u.classList.add(this.getDotClass(s.key)),o.appendChild(u);let c=document.createElement("div");c.className="lr-block-text";let h=s.unit.text.replace(/<\/?[0-9]+\/?>/g,""),l=document.createElement("div");l.className="lr-block-source",l.textContent=h.length>60?h.slice(0,60)+"...":h,l.title=h,c.appendChild(l);let m=this.statusMap.get(s.key);if(m&&m.text){let p=document.createElement("div");p.className="lr-block-preview";let f=m.text.replace(/<\/?[0-9]+\/?>/g,"");p.textContent=f.length>50?f.slice(0,50)+"...":f,c.appendChild(p)}o.appendChild(c),o.addEventListener("click",()=>{s.element.scrollIntoView({behavior:"smooth",block:"center"}),this.onBlockClick({key:s.key,unit:s.unit,translatedUnit:null,element:s.element})}),t.appendChild(o)}this.bodyEl.appendChild(t)}};var K=class{constructor(t,e,n){a(this,"queue",[]);a(this,"apiBase");a(this,"sessionToken");a(this,"projectId");a(this,"flushInterval",null);a(this,"renewalInterval",null);a(this,"onStatus",()=>{});a(this,"onFlushed",()=>{});a(this,"onSessionExpired",null);a(this,"statusAbort",null);a(this,"handleVisibility",()=>{document.visibilityState==="hidden"&&this.flush()});this.apiBase=t.replace(/\/$/,""),this.sessionToken=e,this.projectId=n}setStatusCallback(t){this.onStatus=t}setFlushedCallback(t){this.onFlushed=t}setSessionExpiredCallback(t){this.onSessionExpired=t}startAutoFlush(){this.flushInterval=setInterval(()=>this.flush(),3e4),document.addEventListener("visibilitychange",this.handleVisibility),this.renewalInterval=setInterval(()=>this.maybeRenewSession(),6e4)}async stopAndFlush(){this.flushInterval&&(clearInterval(this.flushInterval),this.flushInterval=null),this.renewalInterval&&(clearInterval(this.renewalInterval),this.renewalInterval=null),document.removeEventListener("visibilitychange",this.handleVisibility),await this.flush()}queueSave(t){let e=this.queue.findIndex(n=>n.key===t.key&&n.locale===t.locale&&n.namespace===t.namespace);e>=0?this.queue[e]=t:this.queue.push(t),this.onStatus("unsaved",`${this.queue.length} unsaved`),this.queue.length>50&&this.flush()}async flush(){if(this.queue.length===0)return;let t=[...this.queue];this.onStatus("saving");try{let e=await fetch(`${this.apiBase}/api/integrations/targets/batch`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`},body:JSON.stringify({translations:t.map(r=>({key:`${r.locale}:${r.namespace}:${r.key}`,value:{text:r.text,styles:r.styles}}))})});if(e.status===401){this.handleSessionExpired();return}if(!e.ok)throw new Error(`HTTP ${e.status}`);let n=t.map(r=>r.key);for(let r of t){let s=this.queue.indexOf(r);s>=0&&this.queue.splice(s,1)}this.onFlushed(n),this.queue.length===0?this.onStatus("saved","All changes saved"):this.onStatus("unsaved",`${this.queue.length} unsaved`)}catch(e){this.onStatus("error",`Save failed: ${e.message}`)}}async fetchStatus(t,e,n){if(t.length===0)return{};this.statusAbort&&this.statusAbort.abort(),this.statusAbort=new AbortController;let r=t.slice(0,200),s=new URLSearchParams({locale:e,namespace:n,keys:r.join(",")});try{let o=await fetch(`${this.apiBase}/api/integrations/targets/status?${s}`,{headers:{Authorization:`Bearer ${this.sessionToken}`},signal:this.statusAbort.signal});return o.status===401?(this.handleSessionExpired(),{}):o.ok?(await o.json()).translations:{}}catch(o){return o.name==="AbortError"?{}:{}}}get pendingCount(){return this.queue.length}async maybeRenewSession(){let t=this.getSessionExp();!t||t*1e3-Date.now()>12e4||await this.renewSession()}async renewSession(){try{let t=await fetch(`${this.apiBase}/api/editor/renew`,{method:"POST",headers:{Authorization:`Bearer ${this.sessionToken}`}});if(t.status===401){this.handleSessionExpired();return}if(!t.ok)return;let e=await t.json();this.sessionToken=e.session_token;try{let r=(this.sessionToken.startsWith("es_")?this.sessionToken.slice(3):this.sessionToken).split(".");if(r.length===3){let s=JSON.parse(atob(r[1]));sessionStorage.setItem("__lr_editor_session",JSON.stringify({token:this.sessionToken,exp:s.exp||0}))}}catch{}}catch{}}getSessionExp(){try{let e=(this.sessionToken.startsWith("es_")?this.sessionToken.slice(3):this.sessionToken).split(".");return e.length!==3?null:JSON.parse(atob(e[1])).exp||null}catch{return null}}handleSessionExpired(){this.onStatus("error","Session expired. Please reopen the editor from the dashboard."),this.onSessionExpired&&this.onSessionExpired()}async createSnapshot(t){try{let e=await fetch(`${this.apiBase}/api/editor/snapshots`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`},body:JSON.stringify({pageUrl:t.pageUrl,title:t.title,viewport:t.viewport,textEntries:t.textEntries,html:t.html})});if(e.status===401)return this.handleSessionExpired(),null;if(!e.ok)throw new Error(`HTTP ${e.status}`);let n=await e.json();return{snapshotUuid:n.snapshot_uuid||n.snapshotUuid}}catch(e){return this.onStatus("error",`Snapshot failed: ${e.message}`),null}}async recaptureSnapshot(t,e){try{let n=await fetch(`${this.apiBase}/api/editor/snapshots/${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`},body:JSON.stringify({pageUrl:e.pageUrl,title:e.title,viewport:e.viewport,textEntries:e.textEntries,html:e.html})});if(n.status===401)return this.handleSessionExpired(),null;if(!n.ok)throw new Error(`HTTP ${n.status}`);let r=await n.json();return{snapshotUuid:r.snapshot_uuid||r.snapshotUuid,version:r.version||1}}catch(n){return this.onStatus("error",`Re-capture failed: ${n.message}`),null}}async getSnapshot(t){try{let e=await fetch(`${this.apiBase}/api/editor/snapshots/${encodeURIComponent(t)}`,{headers:{Authorization:`Bearer ${this.sessionToken}`}});return e.status===401?(this.handleSessionExpired(),null):e.ok?await e.json():null}catch{return null}}async listSnapshots(){try{let t=await fetch(`${this.apiBase}/api/editor/snapshots`,{headers:{Authorization:`Bearer ${this.sessionToken}`}});return t.status===401?(this.handleSessionExpired(),[]):t.ok?(await t.json()).snapshots||[]:[]}catch{return[]}}async deleteSnapshot(t){try{let e=await fetch(`${this.apiBase}/api/editor/snapshots/${encodeURIComponent(t)}`,{method:"DELETE",headers:{Authorization:`Bearer ${this.sessionToken}`}});return e.status===401?(this.handleSessionExpired(),!1):e.ok}catch{return!1}}async transitionTarget(t,e){try{let n=await fetch(`${this.apiBase}/api/integrations/targets/${encodeURIComponent(t)}/${e}`,{method:"POST",headers:{Authorization:`Bearer ${this.sessionToken}`}});return n.status===401?(this.handleSessionExpired(),null):n.ok?await n.json():(this.onStatus("error",`${e} failed: HTTP ${n.status}`),null)}catch(n){return this.onStatus("error",`${e} failed: ${n.message}`),null}}};var N="[REDACTED]",Me=/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/gi,Ae=/(?:\+\d{1,3}[\s.-]?)?(?:\(\d{3}\)|\d{3})[\s.-]\d{3}[\s.-]\d{4}/g,Re=/\b\d{3}[\s-]\d{2}[\s-]\d{4}\b/g,Pe=/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g,Ne=/\b(?:https?:\/\/|www\.)[^\s<>"']+/gi,_e=/\b\d(?:[ -]?\d){12,18}\b/g;function Ie(i){if(i.length<13||i.length>19)return!1;let t=0,e=!1;for(let n=i.length-1;n>=0;n--){let r=i.charCodeAt(n)-48;if(r<0||r>9)return!1;e&&(r*=2,r>9&&(r-=9)),t+=r,e=!e}return t%10===0}function Oe(i){let t=i.split(".");if(t.length!==4)return!1;for(let e of t){let n=Number(e);if(!Number.isInteger(n)||n<0||n>255)return!1}return!0}function $e(i){if(!i)return i;let t=i;return t=t.replace(Ne,N),t=t.replace(Me,N),t=t.replace(Ae,N),t=t.replace(Re,N),t=t.replace(Pe,e=>Oe(e)?N:e),t=t.replace(_e,e=>{let n=e.replace(/[\s-]/g,"");return Ie(n)?N:e}),t}var Ue=new Set(["CODE","PRE","STYLE","TEXTAREA"]);function ae(i){let t=document.createTreeWalker(i,NodeFilter.SHOW_TEXT),e=[],n=t.nextNode();for(;n;){if(!ze(n)){let r=n.nodeValue||"",s=$e(r);s!==r&&e.push({node:n,value:s})}n=t.nextNode()}for(let{node:r,value:s}of e)r.nodeValue=s}function ze(i){let t=i.parentNode;for(;t&&t.nodeType===Node.ELEMENT_NODE;){let e=t;if(Ue.has(e.tagName)||e.hasAttribute("data-no-redact"))return!0;t=e.parentNode}return!1}var le="[REDACTED]";function de(){let i=document.documentElement.cloneNode(!0),t=qe(i);return Be(i),He(i),je(i),De(i),Ke(i),Fe(i),{html:`<!DOCTYPE html>
|
|
496
|
-
`+i.outerHTML,textEntries:t,pageUrl:window.location.href,title:document.title,viewport:{width:window.innerWidth,height:window.innerHeight,devicePixelRatio:window.devicePixelRatio||1}}}function
|
|
495
|
+
`;var fe=/^[a-z][a-z0-9+.-]*:/i,ge=new Set(["http:","https:","mailto:","tel:","sms:"]);function ie(i){if(!i)return"#";let t=i.trim();if(!t||t.startsWith("//"))return"#";if(t.startsWith("/")||t.startsWith("?")||t.startsWith("#")||t.startsWith("./")||t.startsWith("../"))return t;let e=fe.exec(t);if(e){let n=e[0].toLowerCase();return ge.has(n)?t:"#"}return t}var A=class{constructor(){a(this,"elementToStyles",{b:"bold",strong:"bold",i:"italic",em:"italic",u:"underline",s:"strikethrough",del:"strikethrough",strike:"strikethrough",code:"code",mark:"highlight",sub:"subscript",sup:"superscript"});a(this,"styleToElement",{bold:"b",italic:"i",underline:"u",strikethrough:"s",code:"code",highlight:"mark",subscript:"sub",superscript:"sup",strong:"b",b:"b",em:"i",i:"i",u:"u",s:"s",del:"s",strike:"s",mark:"mark",sub:"sub",sup:"sup"})}mapElementToStyles(t,e){let n=[],r=t.toLowerCase(),s=this.elementToStyles[r];return s&&n.push(s),r==="a"&&e.href&&n.push(`hyperlink:${e.href}`),n}mapStylesToElement(t){for(let e of t)if(e.startsWith("hyperlink:"))return{element:"a",attrs:{href:ie(e.slice(10))}};for(let e of t){let n=this.styleToElement[e];if(n)return{element:n,attrs:{}}}return{element:"span",attrs:{}}}};var be=new A;function S(i){let t={},e=0;function n(s){if(s.nodeType===Node.TEXT_NODE)return s.nodeValue??"";if(s.nodeType!==Node.ELEMENT_NODE)return"";let o=s,c=o.tagName.toLowerCase(),u={};for(let l=0;l<o.attributes.length;l++){let m=o.attributes[l];u[m.name.toLowerCase()]=m.value}let d=be.mapElementToStyles(c,u);if(d.length>0){e++;let l=e;t[String(l)]=d;let m="";for(let p=0;p<s.childNodes.length;p++)m+=n(s.childNodes[p]);return`<${l}>${m}</${l}>`}let h="";for(let l=0;l<s.childNodes.length;l++)h+=n(s.childNodes[l]);return h}let r="";for(let s=0;s<i.childNodes.length;s++)r+=n(i.childNodes[s]);return{text:r,styles:t}}function C(i,t){let e=(i&65535)+(t&65535);return(i>>16)+(t>>16)+(e>>16)<<16|e&65535}function ve(i,t){return i<<t|i>>>32-t}function U(i,t,e,n,r,s){return C(ve(C(C(t,i),C(n,s)),r),e)}function b(i,t,e,n,r,s,o){return U(t&e|~t&n,i,t,r,s,o)}function v(i,t,e,n,r,s,o){return U(t&n|e&~n,i,t,r,s,o)}function y(i,t,e,n,r,s,o){return U(t^e^n,i,t,r,s,o)}function x(i,t,e,n,r,s,o){return U(e^(t|~n),i,t,r,s,o)}function ye(i,t){i[t>>5]|=128<<t%32,i[(t+64>>>9<<4)+14]=t;let e=1732584193,n=-271733879,r=-1732584194,s=271733878;for(let o=0;o<i.length;o+=16){let c=e,u=n,d=r,h=s;e=b(e,n,r,s,i[o],7,-680876936),s=b(s,e,n,r,i[o+1],12,-389564586),r=b(r,s,e,n,i[o+2],17,606105819),n=b(n,r,s,e,i[o+3],22,-1044525330),e=b(e,n,r,s,i[o+4],7,-176418897),s=b(s,e,n,r,i[o+5],12,1200080426),r=b(r,s,e,n,i[o+6],17,-1473231341),n=b(n,r,s,e,i[o+7],22,-45705983),e=b(e,n,r,s,i[o+8],7,1770035416),s=b(s,e,n,r,i[o+9],12,-1958414417),r=b(r,s,e,n,i[o+10],17,-42063),n=b(n,r,s,e,i[o+11],22,-1990404162),e=b(e,n,r,s,i[o+12],7,1804603682),s=b(s,e,n,r,i[o+13],12,-40341101),r=b(r,s,e,n,i[o+14],17,-1502002290),n=b(n,r,s,e,i[o+15],22,1236535329),e=v(e,n,r,s,i[o+1],5,-165796510),s=v(s,e,n,r,i[o+6],9,-1069501632),r=v(r,s,e,n,i[o+11],14,643717713),n=v(n,r,s,e,i[o],20,-373897302),e=v(e,n,r,s,i[o+5],5,-701558691),s=v(s,e,n,r,i[o+10],9,38016083),r=v(r,s,e,n,i[o+15],14,-660478335),n=v(n,r,s,e,i[o+4],20,-405537848),e=v(e,n,r,s,i[o+9],5,568446438),s=v(s,e,n,r,i[o+14],9,-1019803690),r=v(r,s,e,n,i[o+3],14,-187363961),n=v(n,r,s,e,i[o+8],20,1163531501),e=v(e,n,r,s,i[o+13],5,-1444681467),s=v(s,e,n,r,i[o+2],9,-51403784),r=v(r,s,e,n,i[o+7],14,1735328473),n=v(n,r,s,e,i[o+12],20,-1926607734),e=y(e,n,r,s,i[o+5],4,-378558),s=y(s,e,n,r,i[o+8],11,-2022574463),r=y(r,s,e,n,i[o+11],16,1839030562),n=y(n,r,s,e,i[o+14],23,-35309556),e=y(e,n,r,s,i[o+1],4,-1530992060),s=y(s,e,n,r,i[o+4],11,1272893353),r=y(r,s,e,n,i[o+7],16,-155497632),n=y(n,r,s,e,i[o+10],23,-1094730640),e=y(e,n,r,s,i[o+13],4,681279174),s=y(s,e,n,r,i[o+0],11,-358537222),r=y(r,s,e,n,i[o+3],16,-722521979),n=y(n,r,s,e,i[o+6],23,76029189),e=y(e,n,r,s,i[o+9],4,-640364487),s=y(s,e,n,r,i[o+12],11,-421815835),r=y(r,s,e,n,i[o+15],16,530742520),n=y(n,r,s,e,i[o+2],23,-995338651),e=x(e,n,r,s,i[o],6,-198630844),s=x(s,e,n,r,i[o+7],10,1126891415),r=x(r,s,e,n,i[o+14],15,-1416354905),n=x(n,r,s,e,i[o+5],21,-57434055),e=x(e,n,r,s,i[o+12],6,1700485571),s=x(s,e,n,r,i[o+3],10,-1894986606),r=x(r,s,e,n,i[o+10],15,-1051523),n=x(n,r,s,e,i[o+1],21,-2054922799),e=x(e,n,r,s,i[o+8],6,1873313359),s=x(s,e,n,r,i[o+15],10,-30611744),r=x(r,s,e,n,i[o+6],15,-1560198380),n=x(n,r,s,e,i[o+13],21,1309151649),e=x(e,n,r,s,i[o+4],6,-145523070),s=x(s,e,n,r,i[o+11],10,-1120210379),r=x(r,s,e,n,i[o+2],15,718787259),n=x(n,r,s,e,i[o+9],21,-343485551),e=C(e,c),n=C(n,u),r=C(r,d),s=C(s,h)}return[e,n,r,s]}function xe(i){let t="0123456789abcdef",e="";for(let n=0;n<i.length*4;n++)e+=t.charAt(i[n>>2]>>n%4*8+4&15)+t.charAt(i[n>>2]>>n%4*8&15);return e}function Ee(i){let t=[];for(let e=0;e<i.length*8;e+=8)t[e>>5]|=(i.charCodeAt(e/8)&255)<<e%32;return t}function Se(i){return xe(ye(Ee(i),i.length*8))}function _(i){let t=i.trim();return"auto_"+Se(t).substring(0,12)}var ke="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption";function oe(i){let t=i.closest("[data-lr-block]");if(t){let r=t.getAttribute("data-lr-block"),s=t.getAttribute("data-lr-original"),o,c=null;if(s){let u=document.createElement(t.tagName);u.innerHTML=s,o=S(u),c=S(t)}else o=S(t);return{key:r,unit:o,translatedUnit:c,element:t}}let e=i.closest(ke);if(e){let r=S(e);return{key:_(r.text),unit:r,translatedUnit:null,element:e}}let n=i.textContent?.trim();return n&&n.length>=2?{key:_(n),unit:{text:n,styles:{}},translatedUnit:null,element:i}:null}var we=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),ae="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",z=class{constructor(t,e,n,r){a(this,"overlay");a(this,"currentTarget",null);a(this,"onSelect");a(this,"rafId",null);a(this,"active",!0);a(this,"rootElement");a(this,"snapshotKeyMap");this.onSelect=e,this.rootElement=n||document.body,this.snapshotKeyMap=r||null,this.overlay=document.createElement("div"),this.overlay.className="lr-overlay",t.appendChild(this.overlay),this.handleMouseOver=this.handleMouseOver.bind(this),this.handleClick=this.handleClick.bind(this),this.handleScroll=this.handleScroll.bind(this),document.addEventListener("mouseover",this.handleMouseOver,!0),document.addEventListener("click",this.handleClick,!0),window.addEventListener("scroll",this.handleScroll,!0),window.addEventListener("resize",this.handleScroll)}destroy(){this.active=!1,document.removeEventListener("mouseover",this.handleMouseOver,!0),document.removeEventListener("click",this.handleClick,!0),window.removeEventListener("scroll",this.handleScroll,!0),window.removeEventListener("resize",this.handleScroll),this.rafId!==null&&cancelAnimationFrame(this.rafId),this.overlay.remove()}clearHighlight(){this.currentTarget=null,this.overlay.classList.remove("active")}handleMouseOver(t){if(!this.active)return;let e=t.target;if(!e||!e.closest||e.closest("#__lionrapid-editor")||!this.rootElement.contains(e))return;if(this.shouldSkip(e)){this.clearHighlight();return}let n=e.closest(ae)||e.closest("[data-lr-block]");if(!n){this.clearHighlight();return}n!==this.currentTarget&&(this.currentTarget=n,this.positionOverlay(n))}handleClick(t){if(!this.active)return;let e=t.target;if(!e||!e.closest||e.closest("#__lionrapid-editor")||!this.rootElement.contains(e))return;let n=e.closest(ae)||e.closest("[data-lr-block]");if(!n||this.shouldSkip(n))return;if(t.preventDefault(),t.stopPropagation(),this.snapshotKeyMap){let s=n.getAttribute("data-lr-snap-idx");if(s!==null){let o=parseInt(s,10),c=this.snapshotKeyMap.get(o);if(c){let u=S(n);this.onSelect({key:c,unit:u,translatedUnit:null,element:n});return}}return}let r=oe(n);r&&this.onSelect(r)}handleScroll(){this.currentTarget&&(this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.currentTarget&&this.positionOverlay(this.currentTarget)}))}positionOverlay(t){let e=t.getBoundingClientRect();this.overlay.style.top=`${e.top}px`,this.overlay.style.left=`${e.left}px`,this.overlay.style.width=`${e.width}px`,this.overlay.style.height=`${e.height}px`,this.overlay.classList.add("active")}shouldSkip(t){let e=t;for(;e;){if(we.has(e.tagName)||e.hasAttribute("data-no-translate")||e.getAttribute("translate")==="no")return!0;e=e.parentElement}return!1}};var H=class{constructor(t,e,n,r,s,o=null,c={}){a(this,"el");a(this,"langBtnEl");a(this,"langMenuEl");a(this,"progressEl");a(this,"expanded",!1);a(this,"currentLocale");a(this,"onLanguageChange");a(this,"onExit");a(this,"onCaptureSnapshot");a(this,"dragging",!1);a(this,"dragOffsetX",0);a(this,"dragOffsetY",0);this.onLanguageChange=r,this.onExit=s,this.onCaptureSnapshot=o,this.currentLocale=n;let u=c.mode??"capture";this.el=document.createElement("div"),this.el.className="lr-fab";let d=document.createElement("button");d.className="lr-fab-btn",d.textContent="LR",d.addEventListener("click",p=>{this.dragging||(p.stopPropagation(),this.toggle())}),this.el.appendChild(d);let h=document.createElement("div");h.className="lr-fab-panel";let l=document.createElement("div");l.className="lr-lang-dropdown",this.langBtnEl=document.createElement("button"),this.langBtnEl.className="lr-lang-btn",this.langBtnEl.textContent=n.toUpperCase(),this.langBtnEl.addEventListener("click",p=>{p.stopPropagation(),this.langMenuEl.classList.toggle("open")}),l.appendChild(this.langBtnEl),this.langMenuEl=document.createElement("div"),this.langMenuEl.className="lr-lang-menu";for(let p of e){let f=document.createElement("button");f.className="lr-lang-item",p===n&&f.classList.add("active"),f.textContent=p.toUpperCase(),f.addEventListener("click",E=>{E.stopPropagation(),this.currentLocale=p,this.langBtnEl.textContent=p.toUpperCase(),this.langMenuEl.classList.remove("open"),this.langMenuEl.querySelectorAll(".lr-lang-item").forEach(I=>I.classList.remove("active")),f.classList.add("active"),this.onLanguageChange(p)}),this.langMenuEl.appendChild(f)}if(l.appendChild(this.langMenuEl),h.appendChild(l),this.onCaptureSnapshot){let p=document.createElement("button");p.className="lr-fab-snapshot",u==="recapture"?(p.textContent="Save re-capture",p.title="Save this page as a new version of the existing snapshot"):(p.textContent="Capture",p.title="Capture a redacted snapshot of this page for translators"),p.addEventListener("click",f=>{f.stopPropagation(),this.onCaptureSnapshot&&this.onCaptureSnapshot()}),h.appendChild(p)}this.progressEl=document.createElement("span"),this.progressEl.className="lr-fab-progress",h.appendChild(this.progressEl);let m=document.createElement("button");m.className="lr-fab-exit",m.textContent="Exit",m.addEventListener("click",()=>this.onExit()),h.appendChild(m),this.el.appendChild(h),t.appendChild(this.el),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this),d.addEventListener("mousedown",this.handleMouseDown)}toggle(){this.expanded=!this.expanded,this.el.classList.toggle("expanded",this.expanded)}updateProgress(t,e){this.progressEl.textContent=`${t}/${e}`}getCurrentLocale(){return this.currentLocale}destroy(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),this.el.remove()}handleMouseDown(t){this.dragging=!1,this.dragOffsetX=t.clientX-this.el.getBoundingClientRect().left,this.dragOffsetY=t.clientY-this.el.getBoundingClientRect().top,document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}handleMouseMove(t){this.dragging=!0;let e=Math.max(0,Math.min(t.clientX-this.dragOffsetX,window.innerWidth-this.el.offsetWidth)),n=Math.max(0,Math.min(t.clientY-this.dragOffsetY,window.innerHeight-this.el.offsetHeight));this.el.style.left=`${e}px`,this.el.style.top=`${n}px`,this.el.style.right="auto",this.el.style.bottom="auto"}handleMouseUp(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),this.dragging&&setTimeout(()=>{this.dragging=!1},0)}};var R=class{constructor(t={}){a(this,"styleMapper");this.styleMapper=t.styleMapper??new A}serialize(t){let{text:e,styles:n}=t,r=/<(\/?)?(\d+)(\/)?>/g,s="",o=0,c;for(;(c=r.exec(e))!==null;){s+=e.slice(o,c.index);let[u,d,h,l]=c,p=n[h]||[];if(d){let f=this.styleMapper.mapStylesToElement(p);s+=`</${f.element}>`}else if(l){let f=this.styleMapper.mapStylesToElement(p),E=this.formatAttributes(f.attrs);s+=`<${f.element}${E} />`}else{let f=this.styleMapper.mapStylesToElement(p),E=this.formatAttributes(f.attrs);s+=`<${f.element}${E}>`}o=c.index+u.length}return s+=e.slice(o),s}formatAttributes(t){let e=Object.entries(t);return e.length===0?"":" "+e.map(([n,r])=>`${n}="${this.escapeAttributeValue(r)}"`).join(" ")}escapeAttributeValue(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}};var Te=new R;function J(i,t,e,n,r,s){i.hasAttribute("data-lr-original")||i.setAttribute("data-lr-original",i.innerHTML);let c=window.LionRapid?.autoTranslator?Ce():null;if(c){let u=`${r}:${s}:${n}`;c.set(u,t,e)}if(e&&Object.keys(e).length>0){let u={text:t,styles:e};i.innerHTML=Te.serialize(u)}else i.textContent=t;i.setAttribute("data-lr-block",n),i.setAttribute("data-lionrapid-client","1")}function Ce(){try{let i=window.LionRapid;if(!i)return null;let t=i.autoTranslator;if(!t)return null;let e=t.core;if(!e)return null;let n=e.cache;return!n||typeof n.set!="function"?null:n}catch{return null}}var Le={emails:!0,urls:!0,numbers:!0,phones:!0},B={email:/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,url:/^(https?:\/\/|www\.)[^\s]+$/i,number:/^[\d\s.,+-]+$/,phone:/^[+\d][\d\s().-]{6,}$/},j=class{constructor(t={},e=2){a(this,"patterns");a(this,"minTextLength");this.patterns={...Le,...t},this.minTextLength=e}shouldExclude(t){let e=t.trim();return!!(e.length<this.minTextLength||this.patterns.emails&&B.email.test(e)||this.patterns.urls&&B.url.test(e)||this.patterns.numbers&&B.number.test(e)||this.patterns.phones&&B.phone.test(e))}};var Y="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",Me=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),Ae=["data-lionrapid-translated","data-lionrapid-client","data-no-translate"],P=class{constructor(t={},e=[],n=2){a(this,"excludeFilter");a(this,"excludeSelectors");this.excludeFilter=new j(t,n),this.excludeSelectors=e}extract(t,e=!1){let n=[],r=t.querySelectorAll(Y),s=[];t instanceof Element&&t.matches(Y)&&s.push(t);for(let o=0;o<r.length;o++)s.push(r[o]);for(let o=0;o<s.length;o++){let c=s[o];if(this.isInsideSkipTag(c)||!e&&this.hasSkipAttribute(c)||this.matchesExcludeSelector(c)||c.getAttribute("translate")==="no"||c.querySelector(Y))continue;let u=c.getAttribute("data-lr-block"),d=c.getAttribute("data-lr-original"),h;if(d){let p=document.createElement(c.tagName);p.innerHTML=d,h=S(p)}else h=S(c);let l=h.text.replace(/<\/?[0-9]+\/?>/g,"");if(this.excludeFilter.shouldExclude(l))continue;let m;if(u)m=u;else{let p=c.getAttribute("data-i18n");p?m=p.includes(":")?p:`common:${p}`:m=_(h.text)}n.push({element:c,unit:h,key:m})}return n}isInsideSkipTag(t){let e=t.parentElement;for(;e;){if(Me.has(e.tagName))return!0;e=e.parentElement}return!1}hasSkipAttribute(t){let e=t;for(;e;){for(let n of Ae)if(e.hasAttribute(n))return!0;e=e.parentElement}return!1}matchesExcludeSelector(t){for(let e of this.excludeSelectors)try{if(t.matches(e)||t.closest(e))return!0}catch{}return!1}};var Re=new R,D=class{constructor(t,e,n,r,s,o,c=""){a(this,"el");a(this,"bodyEl");a(this,"statusEl");a(this,"api");a(this,"locale");a(this,"namespace");a(this,"defaultLocale");a(this,"current",null);a(this,"blockExtractor");a(this,"onBlockClick");a(this,"statusMap",new Map);a(this,"unsavedKeys",new Set);a(this,"onProgressUpdate",null);a(this,"lastFetchTime",0);a(this,"lastFlushTime",0);a(this,"userRole");this.api=e,this.locale=n,this.namespace=r,this.defaultLocale=s,this.onBlockClick=o,this.userRole=c,this.blockExtractor=new P,this.el=document.createElement("div"),this.el.className="lr-sidebar";let u=document.createElement("div");u.className="lr-sidebar-resize",this.initResize(u),this.el.appendChild(u);let d=document.createElement("div");d.className="lr-sidebar-header";let h=document.createElement("span");h.className="lr-sidebar-title",h.textContent="Edit Translation",d.appendChild(h);let l=document.createElement("button");l.className="lr-sidebar-close",l.innerHTML="×",l.addEventListener("click",()=>this.close()),d.appendChild(l),this.el.appendChild(d),this.bodyEl=document.createElement("div"),this.bodyEl.className="lr-sidebar-body",this.el.appendChild(this.bodyEl),this.statusEl=document.createElement("div"),this.statusEl.className="lr-status",this.api.setStatusCallback((m,p)=>{this.statusEl.textContent=p||m,this.statusEl.className=`lr-status ${m}`}),this.api.setFlushedCallback(async m=>{this.lastFlushTime=Date.now();let p=await this.api.fetchStatus(m,this.locale,this.namespace);for(let[f,E]of Object.entries(p))this.statusMap.set(f,E),this.unsavedKeys.delete(f);this.refreshBlocksList(),this.emitProgress()}),t.appendChild(this.el)}open(t){this.current=t,this.el.classList.add("open"),this.renderContent(t)}close(){this.current=null,this.el.classList.remove("open")}isOpen(){return this.el.classList.contains("open")}updateLocale(t){this.locale=t,this.statusMap.clear(),this.unsavedKeys.clear()}setProgressCallback(t){this.onProgressUpdate=t}async hydrateStatus(){let t=this.blockExtractor.extract(document.body,!0),e=t.map(r=>r.key);if(e.length===0)return;let n=await this.api.fetchStatus(e,this.locale,this.namespace);for(let[r,s]of Object.entries(n))this.statusMap.set(r,s);for(let r of t){let s=this.statusMap.get(r.key);s&&s.text&&!s.isReady&&J(r.element,s.text,r.unit.styles,r.key,this.locale,this.namespace)}this.emitProgress()}getTranslatedCount(){let t=0;for(let e of this.statusMap.values())e&&e.rowState!=="empty"&&t++;return t}getTotalCount(){return this.blockExtractor.extract(document.body,!0).length}emitProgress(){this.onProgressUpdate&&this.onProgressUpdate(this.getTranslatedCount(),this.getTotalCount())}destroy(){this.el.remove()}async renderContent(t){let{key:e,unit:n,element:r}=t;if(this.bodyEl.innerHTML="",this.lastFlushTime>this.lastFetchTime||this.lastFetchTime===0){let m=this.blockExtractor.extract(document.body,!0).map(f=>f.key);m.includes(e)||m.push(e);let p=await this.api.fetchStatus(m,this.locale,this.namespace);for(let[f,E]of Object.entries(p))this.statusMap.set(f,E);this.lastFetchTime=Date.now()}else{let l=await this.api.fetchStatus([e],this.locale,this.namespace);l[e]!==void 0&&this.statusMap.set(e,l[e])}let o=this.statusMap.get(e)??null;this.addField("Key",()=>{let l=document.createElement("div");return l.className="lr-field-key",l.textContent=e,l}),this.addField("Original",()=>{let l=document.createElement("div");return l.className="lr-field-original",l.innerHTML=this.renderTextWithTags(n.text),l});let c=this.locale===this.defaultLocale,u=c||o?.isLocked||o?.isReady||!1,d=document.createElement("textarea");this.addField("Translation",()=>(d.className="lr-textarea",d.value=o?.text||t.translatedUnit?.text||"",d.placeholder=n.text,u&&(d.readOnly=!0,d.classList.add("lr-textarea-locked"),d.title=c?"Source language \u2014 switch to a target language to edit":o?.isReady?"Approved for delivery \u2014 read only":"Locked \u2014 read only"),d)),this.bodyEl.appendChild(this.statusEl);let h=document.createElement("div");this.addField("Preview",()=>(h.className="lr-preview",d.value&&(h.innerHTML=this.renderPreview(d.value,n.styles)),h)),c||this.renderWorkflowActions(e,o),u||d.addEventListener("input",()=>{let l=d.value;h.innerHTML=this.renderPreview(l,n.styles),l&&J(r,l,n.styles,e,this.locale,this.namespace),this.unsavedKeys.add(e),this.api.queueSave({key:e,locale:this.locale,namespace:this.namespace,text:l,styles:n.styles})}),this.renderBlocksList(),u||setTimeout(()=>d.focus(),100)}renderWorkflowActions(t,e){let n=this.userRole==="project_manager"||this.userRole==="admin",r=!!e?.isReady,s=!!e?.isLocked,o=!!e?.isConfirmed,c=`${this.locale}:${this.namespace}:${t}`,u=document.createElement("div");u.className="lr-workflow-actions";let d=(h,l,m="secondary")=>{let p=document.createElement("button");p.className=`lr-wf-btn lr-wf-${m}`,p.textContent=h,p.addEventListener("click",async()=>{p.disabled=!0;let f=await this.api.transitionTarget(c,l);p.disabled=!1,f&&await this.refreshStatusForKey(t)}),u.appendChild(p)};!s&&!r&&(d("Confirm","confirm","primary"),d("Reject","reject","danger")),o&&!s&&!r&&d("Unconfirm","unconfirm"),n&&(r?d("Unmark Ready","unmark-ready","danger"):d("Mark Ready","mark-ready","primary")),u.children.length>0&&this.bodyEl.appendChild(u)}async refreshStatusForKey(t){let e=await this.api.fetchStatus([t],this.locale,this.namespace);for(let[n,r]of Object.entries(e))this.statusMap.set(n,r);this.current&&this.renderContent(this.current),this.emitProgress()}addField(t,e){let n=document.createElement("div");n.className="lr-field";let r=document.createElement("span");r.className="lr-field-label",r.textContent=t,n.appendChild(r),n.appendChild(e()),this.bodyEl.appendChild(n)}getDotClass(t){if(this.unsavedKeys.has(t))return"unsaved";let e=this.statusMap.get(t);return e?e.isLocked?"locked":e.isReady?"ready":e.isConfirmed?"confirmed":e.rowState==="edited"?"edited":e.rowState==="machine_translated"?"mt":"missing":"missing"}renderTextWithTags(t){return t.replace(/<(\/?)?(\d+)(\/)?>/g,e=>`<span class="lr-field-tag">${e}</span>`)}renderPreview(t,e){if(!t)return"";if(Object.keys(e).length>0){let n={text:t,styles:e};return Re.serialize(n)}return t}initResize(t){let e=0,n=0,r=o=>{let c=n+(e-o.clientX),u=Math.max(280,Math.min(600,c));this.el.style.width=`${u}px`},s=()=>{t.classList.remove("active"),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",s)};t.addEventListener("mousedown",o=>{o.preventDefault(),e=o.clientX,n=this.el.offsetWidth,t.classList.add("active"),document.addEventListener("mousemove",r),document.addEventListener("mouseup",s)})}refreshBlocksList(){let t=this.bodyEl.querySelector(".lr-blocks-section");t&&t.remove(),this.renderBlocksList()}renderBlocksList(){let t=document.createElement("div");t.className="lr-blocks-section";let e=this.blockExtractor.extract(document.body,!0),n=this.getTranslatedCount(),r=document.createElement("div");r.className="lr-blocks-title",r.textContent=`Blocks on this page (${n}/${e.length} translated)`,t.appendChild(r);for(let s of e){let o=document.createElement("div");o.className="lr-block-item",this.current&&s.element===this.current.element&&o.classList.add("active");let u=document.createElement("span");u.className="lr-status-dot",u.classList.add(this.getDotClass(s.key)),o.appendChild(u);let d=document.createElement("div");d.className="lr-block-text";let h=s.unit.text.replace(/<\/?[0-9]+\/?>/g,""),l=document.createElement("div");l.className="lr-block-source",l.textContent=h.length>60?h.slice(0,60)+"...":h,l.title=h,d.appendChild(l);let m=this.statusMap.get(s.key);if(m&&m.text){let p=document.createElement("div");p.className="lr-block-preview";let f=m.text.replace(/<\/?[0-9]+\/?>/g,"");p.textContent=f.length>50?f.slice(0,50)+"...":f,d.appendChild(p)}o.appendChild(d),o.addEventListener("click",()=>{s.element.scrollIntoView({behavior:"smooth",block:"center"}),this.onBlockClick({key:s.key,unit:s.unit,translatedUnit:null,element:s.element})}),t.appendChild(o)}this.bodyEl.appendChild(t)}};var K=class{constructor(t,e,n){a(this,"queue",[]);a(this,"apiBase");a(this,"sessionToken");a(this,"projectId");a(this,"flushInterval",null);a(this,"renewalInterval",null);a(this,"onStatus",()=>{});a(this,"onFlushed",()=>{});a(this,"onSessionExpired",null);a(this,"statusAbort",null);a(this,"handleVisibility",()=>{document.visibilityState==="hidden"&&this.flush()});this.apiBase=t.replace(/\/$/,""),this.sessionToken=e,this.projectId=n}setStatusCallback(t){this.onStatus=t}setFlushedCallback(t){this.onFlushed=t}setSessionExpiredCallback(t){this.onSessionExpired=t}startAutoFlush(){this.flushInterval=setInterval(()=>this.flush(),3e4),document.addEventListener("visibilitychange",this.handleVisibility),this.renewalInterval=setInterval(()=>this.maybeRenewSession(),6e4)}async stopAndFlush(){this.flushInterval&&(clearInterval(this.flushInterval),this.flushInterval=null),this.renewalInterval&&(clearInterval(this.renewalInterval),this.renewalInterval=null),document.removeEventListener("visibilitychange",this.handleVisibility),await this.flush()}queueSave(t){let e=this.queue.findIndex(n=>n.key===t.key&&n.locale===t.locale&&n.namespace===t.namespace);e>=0?this.queue[e]=t:this.queue.push(t),this.onStatus("unsaved",`${this.queue.length} unsaved`),this.queue.length>50&&this.flush()}async flush(){if(this.queue.length===0)return;let t=[...this.queue];this.onStatus("saving");try{let e=await fetch(`${this.apiBase}/api/integrations/targets/batch`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`},body:JSON.stringify({translations:t.map(r=>({key:`${r.locale}:${r.namespace}:${r.key}`,value:{text:r.text,styles:r.styles}}))})});if(e.status===401){this.handleSessionExpired();return}if(!e.ok)throw new Error(`HTTP ${e.status}`);let n=t.map(r=>r.key);for(let r of t){let s=this.queue.indexOf(r);s>=0&&this.queue.splice(s,1)}this.onFlushed(n),this.queue.length===0?this.onStatus("saved","All changes saved"):this.onStatus("unsaved",`${this.queue.length} unsaved`)}catch(e){this.onStatus("error",`Save failed: ${e.message}`)}}async fetchStatus(t,e,n){if(t.length===0)return{};this.statusAbort&&this.statusAbort.abort(),this.statusAbort=new AbortController;let r=t.slice(0,200),s=new URLSearchParams({locale:e,namespace:n,keys:r.join(",")});try{let o=await fetch(`${this.apiBase}/api/integrations/targets/status?${s}`,{headers:{Authorization:`Bearer ${this.sessionToken}`},signal:this.statusAbort.signal});return o.status===401?(this.handleSessionExpired(),{}):o.ok?(await o.json()).translations:{}}catch(o){return o.name==="AbortError"?{}:{}}}get pendingCount(){return this.queue.length}async maybeRenewSession(){let t=this.getSessionExp();!t||t*1e3-Date.now()>12e4||await this.renewSession()}async renewSession(){try{let t=await fetch(`${this.apiBase}/api/editor/renew`,{method:"POST",headers:{Authorization:`Bearer ${this.sessionToken}`}});if(t.status===401){this.handleSessionExpired();return}if(!t.ok)return;let e=await t.json();this.sessionToken=e.session_token;try{let r=(this.sessionToken.startsWith("es_")?this.sessionToken.slice(3):this.sessionToken).split(".");if(r.length===3){let s=JSON.parse(atob(r[1]));sessionStorage.setItem("__lr_editor_session",JSON.stringify({token:this.sessionToken,exp:s.exp||0}))}}catch{}}catch{}}getSessionExp(){try{let e=(this.sessionToken.startsWith("es_")?this.sessionToken.slice(3):this.sessionToken).split(".");return e.length!==3?null:JSON.parse(atob(e[1])).exp||null}catch{return null}}handleSessionExpired(){this.onStatus("error","Session expired. Please reopen the editor from the dashboard."),this.onSessionExpired&&this.onSessionExpired()}async createSnapshot(t){try{let e=await fetch(`${this.apiBase}/api/editor/snapshots`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`},body:JSON.stringify({pageUrl:t.pageUrl,title:t.title,viewport:t.viewport,textEntries:t.textEntries,html:t.html})});if(e.status===401)return this.handleSessionExpired(),null;if(!e.ok)throw new Error(`HTTP ${e.status}`);let n=await e.json();return{snapshotUuid:n.snapshot_uuid||n.snapshotUuid}}catch(e){return this.onStatus("error",`Snapshot failed: ${e.message}`),null}}async recaptureSnapshot(t,e){try{let n=await fetch(`${this.apiBase}/api/editor/snapshots/${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`},body:JSON.stringify({pageUrl:e.pageUrl,title:e.title,viewport:e.viewport,textEntries:e.textEntries,html:e.html})});if(n.status===401)return this.handleSessionExpired(),null;if(!n.ok)throw new Error(`HTTP ${n.status}`);let r=await n.json();return{snapshotUuid:r.snapshot_uuid||r.snapshotUuid,version:r.version||1}}catch(n){return this.onStatus("error",`Re-capture failed: ${n.message}`),null}}async getSnapshot(t){try{let e=await fetch(`${this.apiBase}/api/editor/snapshots/${encodeURIComponent(t)}`,{headers:{Authorization:`Bearer ${this.sessionToken}`}});return e.status===401?(this.handleSessionExpired(),null):e.ok?await e.json():null}catch{return null}}async listSnapshots(){try{let t=await fetch(`${this.apiBase}/api/editor/snapshots`,{headers:{Authorization:`Bearer ${this.sessionToken}`}});return t.status===401?(this.handleSessionExpired(),[]):t.ok?(await t.json()).snapshots||[]:[]}catch{return[]}}async deleteSnapshot(t){try{let e=await fetch(`${this.apiBase}/api/editor/snapshots/${encodeURIComponent(t)}`,{method:"DELETE",headers:{Authorization:`Bearer ${this.sessionToken}`}});return e.status===401?(this.handleSessionExpired(),!1):e.ok}catch{return!1}}async transitionTarget(t,e){try{let n=await fetch(`${this.apiBase}/api/integrations/targets/${encodeURIComponent(t)}/${e}`,{method:"POST",headers:{Authorization:`Bearer ${this.sessionToken}`}});return n.status===401?(this.handleSessionExpired(),null):n.ok?await n.json():(this.onStatus("error",`${e} failed: HTTP ${n.status}`),null)}catch(n){return this.onStatus("error",`${e} failed: ${n.message}`),null}}};var N="[REDACTED]",Pe=/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/gi,Ne=/(?:\+\d{1,3}[\s.-]?)?(?:\(\d{3}\)|\d{3})[\s.-]\d{3}[\s.-]\d{4}/g,_e=/\b\d{3}[\s-]\d{2}[\s-]\d{4}\b/g,Ie=/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g,Oe=/\b(?:https?:\/\/|www\.)[^\s<>"']+/gi,$e=/\b\d(?:[ -]?\d){12,18}\b/g;function Ue(i){if(i.length<13||i.length>19)return!1;let t=0,e=!1;for(let n=i.length-1;n>=0;n--){let r=i.charCodeAt(n)-48;if(r<0||r>9)return!1;e&&(r*=2,r>9&&(r-=9)),t+=r,e=!e}return t%10===0}function ze(i){let t=i.split(".");if(t.length!==4)return!1;for(let e of t){let n=Number(e);if(!Number.isInteger(n)||n<0||n>255)return!1}return!0}function He(i){if(!i)return i;let t=i;return t=t.replace(Oe,N),t=t.replace(Pe,N),t=t.replace(Ne,N),t=t.replace(_e,N),t=t.replace(Ie,e=>ze(e)?N:e),t=t.replace($e,e=>{let n=e.replace(/[\s-]/g,"");return Ue(n)?N:e}),t}var Be=new Set(["CODE","PRE","STYLE","TEXTAREA"]);function le(i){let t=document.createTreeWalker(i,NodeFilter.SHOW_TEXT),e=[],n=t.nextNode();for(;n;){if(!je(n)){let r=n.nodeValue||"",s=He(r);s!==r&&e.push({node:n,value:s})}n=t.nextNode()}for(let{node:r,value:s}of e)r.nodeValue=s}function je(i){let t=i.parentNode;for(;t&&t.nodeType===Node.ELEMENT_NODE;){let e=t;if(Be.has(e.tagName)||e.hasAttribute("data-no-redact"))return!0;t=e.parentNode}return!1}var ce="[REDACTED]";function de(){let i=document.documentElement.cloneNode(!0),t=Xe(i);return De(i),Ke(i),Fe(i),We(i),qe(i),Ve(i),{html:`<!DOCTYPE html>
|
|
496
|
+
`+i.outerHTML,textEntries:t,pageUrl:window.location.href,title:document.title,viewport:{width:window.innerWidth,height:window.innerHeight,devicePixelRatio:window.devicePixelRatio||1}}}function De(i){let t=["script","noscript","iframe","embed","object","#__lionrapid-editor",'link[rel="prefetch"]','link[rel="preload"]','link[rel="modulepreload"]'];for(let e of t){let n=i.querySelectorAll(e);for(let r=0;r<n.length;r++)n[r].remove()}}function Ke(i){let t=i.querySelectorAll("input, textarea, select");for(let e=0;e<t.length;e++){let n=t[e];if("value"in n&&(n.value=""),n.hasAttribute("value")&&n.setAttribute("value",""),n.tagName==="TEXTAREA"&&(n.textContent=""),n.tagName==="SELECT"){let s=n.querySelectorAll("option");for(let o=0;o<s.length;o++)s[o].selected=!1,s[o].removeAttribute("selected")}let r=Array.from(n.attributes);for(let s of r)(s.name.startsWith("data-value")||s.name==="data-initial")&&n.removeAttribute(s.name)}}function Fe(i){let t=i.querySelectorAll("[data-pii], [data-sensitive]");for(let e=0;e<t.length;e++){let n=t[e];n.textContent=ce;let r=Array.from(n.attributes);for(let s of r)s.name!=="class"&&s.name!=="id"&&s.name!=="style"&&n.removeAttribute(s.name)}}function We(i){let t=document.createTreeWalker(i,NodeFilter.SHOW_ELEMENT),e=t.nextNode();for(;e;){let n=Array.from(e.attributes);for(let r of n)r.name.toLowerCase().startsWith("on")&&e.removeAttribute(r.name);e=t.nextNode()}}function qe(i){le(i)}function Ve(i){let t=i.querySelectorAll('meta[name="csrf-token"], meta[name="csp-nonce"], meta[name="csrf-param"], meta[http-equiv="set-cookie"]');for(let r=0;r<t.length;r++)t[r].remove();let e=["token","auth","access_token","session","sid","key","api_key","apikey"],n=i.querySelectorAll("link[href], a[href], img[src]");for(let r=0;r<n.length;r++){let s=n[r],o=s.tagName==="IMG"?"src":"href",c=s.getAttribute(o);if(c)try{let u=new URL(c,window.location.href),d=!1;for(let h of e)u.searchParams.has(h)&&(u.searchParams.set(h,ce),d=!0);d&&s.setAttribute(o,u.toString())}catch{}}}function Xe(i){return new P({emails:!0,urls:!0,numbers:!0,phones:!0},[],2).extract(i).map((n,r)=>(n.element.setAttribute("data-lr-snap-idx",String(r)),{key:n.key,tagName:n.element.tagName,blockIndex:r}))}async function ue(i,t){let e=await t.getSnapshot(i);if(!e)return null;let r=new DOMParser().parseFromString(e.html,"text/html"),s=r.head.querySelectorAll('link[rel="stylesheet"], style');for(let h=0;h<s.length;h++){let l=s[h].cloneNode(!0);l.setAttribute("data-lr-snapshot-style",""),document.head.appendChild(l)}e.title&&(document.title=`[Snapshot] ${e.title}`);let o=document.getElementById("__lionrapid-editor");for(;document.body.firstChild;)if(document.body.firstChild===o){let h=document.body.firstChild.nextSibling;if(!h)break;document.body.removeChild(h)}else document.body.removeChild(document.body.firstChild);let c=document.createElement("div");c.id="__lr_snapshot_root",c.setAttribute("data-lr-snapshot-uuid",i),c.innerHTML=r.body.innerHTML,o&&o.parentNode===document.body?document.body.insertBefore(c,o):document.body.appendChild(c);let u=new Map,d=e.textEntries||[];for(let h of d)u.set(h.blockIndex,h.key);return{root:c,pageUrl:e.pageUrl,title:e.title,keyMap:u}}var F="__lr_editor_session";function pe(){try{let i=sessionStorage.getItem(F);if(!i)return null;let t=JSON.parse(i);return t.exp*1e3<Date.now()+3e4?(sessionStorage.removeItem(F),null):t.token}catch{return null}}function Je(i){try{let e=(i.startsWith("es_")?i.slice(3):i).split(".");if(e.length!==3)return;let n=JSON.parse(atob(e[1])),r={token:i,exp:n.exp||0};sessionStorage.setItem(F,JSON.stringify(r))}catch{}}function Ye(){sessionStorage.removeItem(F)}function Ge(i){try{let e=(i.startsWith("es_")?i.slice(3):i).split(".");if(e.length!==3)return"";let n=JSON.parse(atob(e[1]));return typeof n.role=="string"?n.role:""}catch{return""}}function w(i){let t=document.createElement("div");t.setAttribute("data-no-translate",""),Object.assign(t.style,{position:"fixed",bottom:"24px",right:"24px",zIndex:"2147483647",background:"#1a1a2e",color:"#fff",padding:"16px 20px",borderRadius:"8px",fontFamily:"system-ui, sans-serif",fontSize:"14px",maxWidth:"360px",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"}),t.textContent=i;let e=document.createElement("button");Object.assign(e.style,{position:"absolute",top:"4px",right:"8px",background:"none",border:"none",color:"#888",cursor:"pointer",fontSize:"16px"}),e.textContent="\xD7",e.addEventListener("click",()=>t.remove()),t.appendChild(e),document.body.appendChild(t),setTimeout(()=>t.remove(),8e3)}function Qe(){let i=document.querySelector("script[data-grant]")||document.querySelector("script[data-lr-editor]");if(!i)return;let t=i.dataset.grant||"",e=pe()!==null;if(!t&&!e)return;let n=i.dataset.locale||"",r=i.dataset.api||"https://api.lionrapid.com",s=i.dataset.project||"",o=0,c=100,u=setInterval(()=>{o++;let d=window.LionRapid;d?(clearInterval(u),Ze(d,t,n,r,s)):o>=c&&(clearInterval(u),console.warn("[LionRapid Editor] Timed out waiting for window.LionRapid"))},100)}async function Ze(i,t,e,n,r){let s=window.__lionrapidConfig,o=s?.languages||[e],c=s?.namespace||"default",u=s?.defaultLocale||"en",d=e||i.getCurrentLocale(),h=n.replace(/\/$/,""),l=pe();if(!l&&t)try{let g=await fetch(`${h}/api/editor/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant:t,domain:window.location.host})});if(!g.ok){console.error("[LionRapid Editor] Grant exchange failed:",g.status),w("Editor session expired. Please reopen the editor from the dashboard.");return}l=(await g.json()).session_token,l&&Je(l)}catch(g){console.error("[LionRapid Editor] Grant exchange error:",g),w("Could not connect to LionRapid. Please check your connection and try again.");return}if(!l){console.error("[LionRapid Editor] No valid session. Please reopen the editor from the dashboard."),w("Editor session expired. Please reopen the editor from the dashboard.");return}let m=Ge(l),p=m==="project_manager"||m==="admin",f=document.createElement("div");f.id="__lionrapid-editor",f.setAttribute("data-no-translate",""),document.body.appendChild(f);let E=f.attachShadow({mode:"closed"}),I=document.createElement("style");I.textContent=se,E.appendChild(I);let G=document.querySelector("[data-lionrapid-switcher]");G&&(G.style.display="none");let M=new K(h,l,r);M.startAutoFlush();let Q=new URL(window.location.href),W=Q.searchParams.get("__lr_snapshot"),q=Q.searchParams.get("__lr_recapture"),Z,ee;if(W){let g=await ue(W,M);if(!g){w("Snapshot not found or expired. Please check the dashboard.");return}Z=g.root,ee=g.keyMap}let te=g=>{k.open(g),V.clearHighlight()},k=new D(E,M,d,c,u,te,m),V=new z(E,te,Z,ee),X=new H(E,o,d,async g=>{if(document.querySelector('script[data-mode="dynamic-only"]')!==null){let $=new URL(window.location.href),ne=$.pathname.replace(/^\/[a-z]{2}(\/|$)/,"/"),re=g===u?"":`/${g}`;$.pathname=re+(ne==="/"&&re?"":ne),$.searchParams.set("__lr_editor",t),window.location.href=$.toString();return}k.updateLocale(g),k.close(),V.clearHighlight(),await i.changeLanguage(g),await k.hydrateStatus()},async()=>{await M.stopAndFlush(),V.destroy(),X.destroy(),k.destroy(),f.remove(),Ye()},W||!p?null:async()=>{try{let g=de();if(q){let T=await M.recaptureSnapshot(q,g);w(T?`Re-captured as v${T.version} (${g.textEntries.length} blocks). You can close this tab.`:"Re-capture failed. Please try again.")}else{let T=await M.createSnapshot(g);w(T?`Snapshot captured (${g.textEntries.length} blocks). Open it from the Snapshots tab in the dashboard.`:"Snapshot upload failed. Please try again.")}}catch(g){console.error("[LionRapid Editor] Snapshot capture error:",g),w("Snapshot capture failed. See console for details.")}},q?{mode:"recapture"}:void 0);k.setProgressCallback((g,T)=>{X.updateProgress(g,T)}),k.hydrateStatus().then(()=>{X.updateProgress(k.getTranslatedCount(),k.getTotalCount())});let L=new URL(window.location.href),O=!1;L.searchParams.has("__lr_editor")&&(L.searchParams.delete("__lr_editor"),O=!0),L.searchParams.has("__lr_snapshot")&&(L.searchParams.delete("__lr_snapshot"),O=!0),L.searchParams.has("__lr_recapture")&&(L.searchParams.delete("__lr_recapture"),O=!0),O&&history.replaceState(null,"",L.toString())}Qe();})();
|
|
497
497
|
//# sourceMappingURL=lionrapid.editor.min.js.map
|