@lionrapid/core 0.1.3-beta.0 → 0.1.4-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var LionRapidEditor=(()=>{var de=Object.defineProperty;var ue=(i,n,e)=>n in i?de(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var a=(i,n,e)=>ue(i,typeof n!="symbol"?n+"":n,e);var re=`
1
+ "use strict";var LionRapidEditor=(()=>{var pe=Object.defineProperty;var he=(i,t,e)=>t in i?pe(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var a=(i,t,e)=>he(i,typeof t!="symbol"?t+"":t,e);var se=`
2
2
  /* Reset inside shadow DOM */
3
3
  :host {
4
4
  all: initial;
@@ -167,6 +167,58 @@
167
167
  cursor: not-allowed;
168
168
  }
169
169
 
170
+ /* Workflow action buttons (Phase 3) */
171
+ .lr-workflow-actions {
172
+ display: flex;
173
+ flex-wrap: wrap;
174
+ gap: 6px;
175
+ margin: 12px 0 4px;
176
+ padding: 8px 0 0;
177
+ border-top: 1px solid #e5e7eb;
178
+ }
179
+
180
+ .lr-wf-btn {
181
+ font-size: 12px;
182
+ font-weight: 500;
183
+ padding: 5px 10px;
184
+ border-radius: 4px;
185
+ border: 1px solid transparent;
186
+ cursor: pointer;
187
+ transition: background-color 0.1s;
188
+ }
189
+
190
+ .lr-wf-btn:disabled {
191
+ opacity: 0.5;
192
+ cursor: not-allowed;
193
+ }
194
+
195
+ .lr-wf-primary {
196
+ background: #2563eb;
197
+ color: white;
198
+ border-color: #2563eb;
199
+ }
200
+ .lr-wf-primary:hover:not(:disabled) {
201
+ background: #1d4ed8;
202
+ }
203
+
204
+ .lr-wf-secondary {
205
+ background: white;
206
+ color: #374151;
207
+ border-color: #d1d5db;
208
+ }
209
+ .lr-wf-secondary:hover:not(:disabled) {
210
+ background: #f3f4f6;
211
+ }
212
+
213
+ .lr-wf-danger {
214
+ background: white;
215
+ color: #b91c1c;
216
+ border-color: #fca5a5;
217
+ }
218
+ .lr-wf-danger:hover:not(:disabled) {
219
+ background: #fef2f2;
220
+ }
221
+
170
222
  /* Snapshot viewer sandbox wrapper */
171
223
  #__lr_snapshot_root {
172
224
  isolation: isolate;
@@ -440,6 +492,6 @@
440
492
  white-space: nowrap;
441
493
  margin-top: 2px;
442
494
  }
443
- `;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(n,e){let t=[],s=n.toLowerCase(),r=this.elementToStyles[s];return r&&t.push(r),s==="a"&&e.href&&t.push(`hyperlink:${e.href}`),t}mapStylesToElement(n){for(let e of n)if(e.startsWith("hyperlink:"))return{element:"a",attrs:{href:e.slice(10)}};for(let e of n){let t=this.styleToElement[e];if(t)return{element:t,attrs:{}}}return{element:"span",attrs:{}}}};var pe=new A;function S(i){let n={},e=0;function t(r){if(r.nodeType===Node.TEXT_NODE)return r.nodeValue??"";if(r.nodeType!==Node.ELEMENT_NODE)return"";let o=r,c=o.tagName.toLowerCase(),u={};for(let l=0;l<o.attributes.length;l++){let f=o.attributes[l];u[f.name.toLowerCase()]=f.value}let p=pe.mapElementToStyles(c,u);if(p.length>0){e++;let l=e;n[String(l)]=p;let f="";for(let h=0;h<r.childNodes.length;h++)f+=t(r.childNodes[h]);return`<${l}>${f}</${l}>`}let d="";for(let l=0;l<r.childNodes.length;l++)d+=t(r.childNodes[l]);return d}let s="";for(let r=0;r<i.childNodes.length;r++)s+=t(i.childNodes[r]);return{text:s,styles:n}}function C(i,n){let e=(i&65535)+(n&65535);return(i>>16)+(n>>16)+(e>>16)<<16|e&65535}function he(i,n){return i<<n|i>>>32-n}function $(i,n,e,t,s,r){return C(he(C(C(n,i),C(t,r)),s),e)}function b(i,n,e,t,s,r,o){return $(n&e|~n&t,i,n,s,r,o)}function v(i,n,e,t,s,r,o){return $(n&t|e&~t,i,n,s,r,o)}function y(i,n,e,t,s,r,o){return $(n^e^t,i,n,s,r,o)}function x(i,n,e,t,s,r,o){return $(e^(n|~t),i,n,s,r,o)}function me(i,n){i[n>>5]|=128<<n%32,i[(n+64>>>9<<4)+14]=n;let e=1732584193,t=-271733879,s=-1732584194,r=271733878;for(let o=0;o<i.length;o+=16){let c=e,u=t,p=s,d=r;e=b(e,t,s,r,i[o],7,-680876936),r=b(r,e,t,s,i[o+1],12,-389564586),s=b(s,r,e,t,i[o+2],17,606105819),t=b(t,s,r,e,i[o+3],22,-1044525330),e=b(e,t,s,r,i[o+4],7,-176418897),r=b(r,e,t,s,i[o+5],12,1200080426),s=b(s,r,e,t,i[o+6],17,-1473231341),t=b(t,s,r,e,i[o+7],22,-45705983),e=b(e,t,s,r,i[o+8],7,1770035416),r=b(r,e,t,s,i[o+9],12,-1958414417),s=b(s,r,e,t,i[o+10],17,-42063),t=b(t,s,r,e,i[o+11],22,-1990404162),e=b(e,t,s,r,i[o+12],7,1804603682),r=b(r,e,t,s,i[o+13],12,-40341101),s=b(s,r,e,t,i[o+14],17,-1502002290),t=b(t,s,r,e,i[o+15],22,1236535329),e=v(e,t,s,r,i[o+1],5,-165796510),r=v(r,e,t,s,i[o+6],9,-1069501632),s=v(s,r,e,t,i[o+11],14,643717713),t=v(t,s,r,e,i[o],20,-373897302),e=v(e,t,s,r,i[o+5],5,-701558691),r=v(r,e,t,s,i[o+10],9,38016083),s=v(s,r,e,t,i[o+15],14,-660478335),t=v(t,s,r,e,i[o+4],20,-405537848),e=v(e,t,s,r,i[o+9],5,568446438),r=v(r,e,t,s,i[o+14],9,-1019803690),s=v(s,r,e,t,i[o+3],14,-187363961),t=v(t,s,r,e,i[o+8],20,1163531501),e=v(e,t,s,r,i[o+13],5,-1444681467),r=v(r,e,t,s,i[o+2],9,-51403784),s=v(s,r,e,t,i[o+7],14,1735328473),t=v(t,s,r,e,i[o+12],20,-1926607734),e=y(e,t,s,r,i[o+5],4,-378558),r=y(r,e,t,s,i[o+8],11,-2022574463),s=y(s,r,e,t,i[o+11],16,1839030562),t=y(t,s,r,e,i[o+14],23,-35309556),e=y(e,t,s,r,i[o+1],4,-1530992060),r=y(r,e,t,s,i[o+4],11,1272893353),s=y(s,r,e,t,i[o+7],16,-155497632),t=y(t,s,r,e,i[o+10],23,-1094730640),e=y(e,t,s,r,i[o+13],4,681279174),r=y(r,e,t,s,i[o+0],11,-358537222),s=y(s,r,e,t,i[o+3],16,-722521979),t=y(t,s,r,e,i[o+6],23,76029189),e=y(e,t,s,r,i[o+9],4,-640364487),r=y(r,e,t,s,i[o+12],11,-421815835),s=y(s,r,e,t,i[o+15],16,530742520),t=y(t,s,r,e,i[o+2],23,-995338651),e=x(e,t,s,r,i[o],6,-198630844),r=x(r,e,t,s,i[o+7],10,1126891415),s=x(s,r,e,t,i[o+14],15,-1416354905),t=x(t,s,r,e,i[o+5],21,-57434055),e=x(e,t,s,r,i[o+12],6,1700485571),r=x(r,e,t,s,i[o+3],10,-1894986606),s=x(s,r,e,t,i[o+10],15,-1051523),t=x(t,s,r,e,i[o+1],21,-2054922799),e=x(e,t,s,r,i[o+8],6,1873313359),r=x(r,e,t,s,i[o+15],10,-30611744),s=x(s,r,e,t,i[o+6],15,-1560198380),t=x(t,s,r,e,i[o+13],21,1309151649),e=x(e,t,s,r,i[o+4],6,-145523070),r=x(r,e,t,s,i[o+11],10,-1120210379),s=x(s,r,e,t,i[o+2],15,718787259),t=x(t,s,r,e,i[o+9],21,-343485551),e=C(e,c),t=C(t,u),s=C(s,p),r=C(r,d)}return[e,t,s,r]}function fe(i){let n="0123456789abcdef",e="";for(let t=0;t<i.length*4;t++)e+=n.charAt(i[t>>2]>>t%4*8+4&15)+n.charAt(i[t>>2]>>t%4*8&15);return e}function ge(i){let n=[];for(let e=0;e<i.length*8;e+=8)n[e>>5]|=(i.charCodeAt(e/8)&255)<<e%32;return n}function be(i){return fe(me(ge(i),i.length*8))}function _(i){let n=i.trim();return"auto_"+be(n).substring(0,12)}var ve="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption";function ie(i){let n=i.closest("[data-lr-block]");if(n){let s=n.getAttribute("data-lr-block"),r=n.getAttribute("data-lr-original"),o,c=null;if(r){let u=document.createElement(n.tagName);u.innerHTML=r,o=S(u),c=S(n)}else o=S(n);return{key:s,unit:o,translatedUnit:c,element:n}}let e=i.closest(ve);if(e){let s=S(e);return{key:_(s.text),unit:s,translatedUnit:null,element:e}}let t=i.textContent?.trim();return t&&t.length>=2?{key:_(t),unit:{text:t,styles:{}},translatedUnit:null,element:i}:null}var ye=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(n,e,t,s){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=t||document.body,this.snapshotKeyMap=s||null,this.overlay=document.createElement("div"),this.overlay.className="lr-overlay",n.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(n){if(!this.active)return;let e=n.target;if(!e||!e.closest||e.closest("#__lionrapid-editor")||!this.rootElement.contains(e))return;if(this.shouldSkip(e)){this.clearHighlight();return}let t=e.closest(oe)||e.closest("[data-lr-block]");if(!t){this.clearHighlight();return}t!==this.currentTarget&&(this.currentTarget=t,this.positionOverlay(t))}handleClick(n){if(!this.active)return;let e=n.target;if(!e||!e.closest||e.closest("#__lionrapid-editor")||!this.rootElement.contains(e))return;let t=e.closest(oe)||e.closest("[data-lr-block]");if(!t||this.shouldSkip(t))return;if(n.preventDefault(),n.stopPropagation(),this.snapshotKeyMap){let r=t.getAttribute("data-lr-snap-idx");if(r!==null){let o=parseInt(r,10),c=this.snapshotKeyMap.get(o);if(c){let u=S(t);this.onSelect({key:c,unit:u,translatedUnit:null,element:t});return}}return}let s=ie(t);s&&this.onSelect(s)}handleScroll(){this.currentTarget&&(this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.currentTarget&&this.positionOverlay(this.currentTarget)}))}positionOverlay(n){let e=n.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(n){let e=n;for(;e;){if(ye.has(e.tagName)||e.hasAttribute("data-no-translate")||e.getAttribute("translate")==="no")return!0;e=e.parentElement}return!1}};var B=class{constructor(n,e,t,s,r,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=s,this.onExit=r,this.onCaptureSnapshot=o,this.currentLocale=t;let u=c.mode??"capture";this.el=document.createElement("div"),this.el.className="lr-fab";let p=document.createElement("button");p.className="lr-fab-btn",p.textContent="LR",p.addEventListener("click",h=>{this.dragging||(h.stopPropagation(),this.toggle())}),this.el.appendChild(p);let d=document.createElement("div");d.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=t.toUpperCase(),this.langBtnEl.addEventListener("click",h=>{h.stopPropagation(),this.langMenuEl.classList.toggle("open")}),l.appendChild(this.langBtnEl),this.langMenuEl=document.createElement("div"),this.langMenuEl.className="lr-lang-menu";for(let h of e){let m=document.createElement("button");m.className="lr-lang-item",h===t&&m.classList.add("active"),m.textContent=h.toUpperCase(),m.addEventListener("click",E=>{E.stopPropagation(),this.currentLocale=h,this.langBtnEl.textContent=h.toUpperCase(),this.langMenuEl.classList.remove("open"),this.langMenuEl.querySelectorAll(".lr-lang-item").forEach(I=>I.classList.remove("active")),m.classList.add("active"),this.onLanguageChange(h)}),this.langMenuEl.appendChild(m)}if(l.appendChild(this.langMenuEl),d.appendChild(l),this.onCaptureSnapshot){let h=document.createElement("button");h.className="lr-fab-snapshot",u==="recapture"?(h.textContent="Save re-capture",h.title="Save this page as a new version of the existing snapshot"):(h.textContent="Capture",h.title="Capture a redacted snapshot of this page for translators"),h.addEventListener("click",m=>{m.stopPropagation(),this.onCaptureSnapshot&&this.onCaptureSnapshot()}),d.appendChild(h)}this.progressEl=document.createElement("span"),this.progressEl.className="lr-fab-progress",d.appendChild(this.progressEl);let f=document.createElement("button");f.className="lr-fab-exit",f.textContent="Exit",f.addEventListener("click",()=>this.onExit()),d.appendChild(f),this.el.appendChild(d),n.appendChild(this.el),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this),p.addEventListener("mousedown",this.handleMouseDown)}toggle(){this.expanded=!this.expanded,this.el.classList.toggle("expanded",this.expanded)}updateProgress(n,e){this.progressEl.textContent=`${n}/${e}`}getCurrentLocale(){return this.currentLocale}destroy(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),this.el.remove()}handleMouseDown(n){this.dragging=!1,this.dragOffsetX=n.clientX-this.el.getBoundingClientRect().left,this.dragOffsetY=n.clientY-this.el.getBoundingClientRect().top,document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}handleMouseMove(n){this.dragging=!0;let e=Math.max(0,Math.min(n.clientX-this.dragOffsetX,window.innerWidth-this.el.offsetWidth)),t=Math.max(0,Math.min(n.clientY-this.dragOffsetY,window.innerHeight-this.el.offsetHeight));this.el.style.left=`${e}px`,this.el.style.top=`${t}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(n={}){a(this,"styleMapper");this.styleMapper=n.styleMapper??new A}serialize(n){let{text:e,styles:t}=n,s=/<(\/?)?(\d+)(\/)?>/g,r="",o=0,c;for(;(c=s.exec(e))!==null;){r+=e.slice(o,c.index);let[u,p,d,l]=c,h=t[d]||[];if(p){let m=this.styleMapper.mapStylesToElement(h);r+=`</${m.element}>`}else if(l){let m=this.styleMapper.mapStylesToElement(h),E=this.formatAttributes(m.attrs);r+=`<${m.element}${E} />`}else{let m=this.styleMapper.mapStylesToElement(h),E=this.formatAttributes(m.attrs);r+=`<${m.element}${E}>`}o=c.index+u.length}return r+=e.slice(o),r}formatAttributes(n){let e=Object.entries(n);return e.length===0?"":" "+e.map(([t,s])=>`${t}="${this.escapeAttributeValue(s)}"`).join(" ")}escapeAttributeValue(n){return n.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}};var xe=new R;function X(i,n,e,t,s,r){i.hasAttribute("data-lr-original")||i.setAttribute("data-lr-original",i.innerHTML);let c=window.LionRapid?.autoTranslator?Ee():null;if(c){let u=`${s}:${r}:${t}`;c.set(u,n,e)}if(e&&Object.keys(e).length>0){let u={text:n,styles:e};i.innerHTML=xe.serialize(u)}else i.textContent=n;i.setAttribute("data-lr-block",t),i.setAttribute("data-lionrapid-client","1")}function Ee(){try{let i=window.LionRapid;if(!i)return null;let n=i.autoTranslator;if(!n)return null;let e=n.core;if(!e)return null;let t=e.cache;return!t||typeof t.set!="function"?null:t}catch{return null}}var Se={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,}$/},P=class{constructor(n={},e=2){a(this,"patterns");a(this,"minTextLength");this.patterns={...Se,...n},this.minTextLength=e}shouldExclude(n){let e=n.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 J="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",ke=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),we=["data-lionrapid-translated","data-lionrapid-client","data-no-translate"],N=class{constructor(n={},e=[],t=2){a(this,"excludeFilter");a(this,"excludeSelectors");this.excludeFilter=new P(n,t),this.excludeSelectors=e}extract(n,e=!1){let t=[],s=n.querySelectorAll(J),r=[];n instanceof Element&&n.matches(J)&&r.push(n);for(let o=0;o<s.length;o++)r.push(s[o]);for(let o=0;o<r.length;o++){let c=r[o];if(this.isInsideSkipTag(c)||!e&&this.hasSkipAttribute(c)||this.matchesExcludeSelector(c)||c.getAttribute("translate")==="no"||c.querySelector(J))continue;let u=c.getAttribute("data-lr-block"),p=c.getAttribute("data-lr-original"),d;if(p){let h=document.createElement(c.tagName);h.innerHTML=p,d=S(h)}else d=S(c);let l=d.text.replace(/<\/?[0-9]+\/?>/g,"");if(this.excludeFilter.shouldExclude(l))continue;let f;if(u)f=u;else{let h=c.getAttribute("data-i18n");h?f=h.includes(":")?h:`common:${h}`:f=_(d.text)}t.push({element:c,unit:d,key:f})}return t}isInsideSkipTag(n){let e=n.parentElement;for(;e;){if(ke.has(e.tagName))return!0;e=e.parentElement}return!1}hasSkipAttribute(n){let e=n;for(;e;){for(let t of we)if(e.hasAttribute(t))return!0;e=e.parentElement}return!1}matchesExcludeSelector(n){for(let e of this.excludeSelectors)try{if(n.matches(e)||n.closest(e))return!0}catch{}return!1}};var Te=new R,j=class{constructor(n,e,t,s,r,o){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);this.api=e,this.locale=t,this.namespace=s,this.defaultLocale=r,this.onBlockClick=o,this.blockExtractor=new N,this.el=document.createElement("div"),this.el.className="lr-sidebar";let c=document.createElement("div");c.className="lr-sidebar-resize",this.initResize(c),this.el.appendChild(c);let u=document.createElement("div");u.className="lr-sidebar-header";let p=document.createElement("span");p.className="lr-sidebar-title",p.textContent="Edit Translation",u.appendChild(p);let d=document.createElement("button");d.className="lr-sidebar-close",d.innerHTML="&times;",d.addEventListener("click",()=>this.close()),u.appendChild(d),this.el.appendChild(u),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((l,f)=>{this.statusEl.textContent=f||l,this.statusEl.className=`lr-status ${l}`}),this.api.setFlushedCallback(async l=>{this.lastFlushTime=Date.now();let f=await this.api.fetchStatus(l,this.locale,this.namespace);for(let[h,m]of Object.entries(f))this.statusMap.set(h,m),this.unsavedKeys.delete(h);this.refreshBlocksList(),this.emitProgress()}),n.appendChild(this.el)}open(n){this.current=n,this.el.classList.add("open"),this.renderContent(n)}close(){this.current=null,this.el.classList.remove("open")}isOpen(){return this.el.classList.contains("open")}updateLocale(n){this.locale=n,this.statusMap.clear(),this.unsavedKeys.clear()}setProgressCallback(n){this.onProgressUpdate=n}async hydrateStatus(){let n=this.blockExtractor.extract(document.body,!0),e=n.map(s=>s.key);if(e.length===0)return;let t=await this.api.fetchStatus(e,this.locale,this.namespace);for(let[s,r]of Object.entries(t))this.statusMap.set(s,r);for(let s of n){let r=this.statusMap.get(s.key);r&&r.text&&!r.isReady&&X(s.element,r.text,s.unit.styles,s.key,this.locale,this.namespace)}this.emitProgress()}getTranslatedCount(){let n=0;for(let e of this.statusMap.values())e&&e.rowState!=="empty"&&n++;return n}getTotalCount(){return this.blockExtractor.extract(document.body,!0).length}emitProgress(){this.onProgressUpdate&&this.onProgressUpdate(this.getTranslatedCount(),this.getTotalCount())}destroy(){this.el.remove()}async renderContent(n){let{key:e,unit:t,element:s}=n;if(this.bodyEl.innerHTML="",this.lastFlushTime>this.lastFetchTime||this.lastFetchTime===0){let f=this.blockExtractor.extract(document.body,!0).map(m=>m.key);f.includes(e)||f.push(e);let h=await this.api.fetchStatus(f,this.locale,this.namespace);for(let[m,E]of Object.entries(h))this.statusMap.set(m,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(t.text),l});let c=this.locale===this.defaultLocale,u=c||o?.isLocked||o?.isReady||!1,p=document.createElement("textarea");this.addField("Translation",()=>(p.className="lr-textarea",p.value=o?.text||n.translatedUnit?.text||"",p.placeholder=t.text,u&&(p.readOnly=!0,p.classList.add("lr-textarea-locked"),p.title=c?"Source language \u2014 switch to a target language to edit":o?.isReady?"Approved for delivery \u2014 read only":"Locked \u2014 read only"),p)),this.bodyEl.appendChild(this.statusEl);let d=document.createElement("div");this.addField("Preview",()=>(d.className="lr-preview",p.value&&(d.innerHTML=this.renderPreview(p.value,t.styles)),d)),u||p.addEventListener("input",()=>{let l=p.value;d.innerHTML=this.renderPreview(l,t.styles),l&&X(s,l,t.styles,e,this.locale,this.namespace),this.unsavedKeys.add(e),this.api.queueSave({key:e,locale:this.locale,namespace:this.namespace,text:l,styles:t.styles})}),this.renderBlocksList(),u||setTimeout(()=>p.focus(),100)}addField(n,e){let t=document.createElement("div");t.className="lr-field";let s=document.createElement("span");s.className="lr-field-label",s.textContent=n,t.appendChild(s),t.appendChild(e()),this.bodyEl.appendChild(t)}getDotClass(n){if(this.unsavedKeys.has(n))return"unsaved";let e=this.statusMap.get(n);return e?e.isLocked?"locked":e.isReady?"ready":e.isConfirmed?"confirmed":e.rowState==="edited"?"edited":e.rowState==="machine_translated"?"mt":"missing":"missing"}renderTextWithTags(n){return n.replace(/<(\/?)?(\d+)(\/)?>/g,e=>`<span class="lr-field-tag">${e}</span>`)}renderPreview(n,e){if(!n)return"";if(Object.keys(e).length>0){let t={text:n,styles:e};return Te.serialize(t)}return n}initResize(n){let e=0,t=0,s=o=>{let c=t+(e-o.clientX),u=Math.max(280,Math.min(600,c));this.el.style.width=`${u}px`},r=()=>{n.classList.remove("active"),document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",r)};n.addEventListener("mousedown",o=>{o.preventDefault(),e=o.clientX,t=this.el.offsetWidth,n.classList.add("active"),document.addEventListener("mousemove",s),document.addEventListener("mouseup",r)})}refreshBlocksList(){let n=this.bodyEl.querySelector(".lr-blocks-section");n&&n.remove(),this.renderBlocksList()}renderBlocksList(){let n=document.createElement("div");n.className="lr-blocks-section";let e=this.blockExtractor.extract(document.body,!0),t=this.getTranslatedCount(),s=document.createElement("div");s.className="lr-blocks-title",s.textContent=`Blocks on this page (${t}/${e.length} translated)`,n.appendChild(s);for(let r of e){let o=document.createElement("div");o.className="lr-block-item",this.current&&r.element===this.current.element&&o.classList.add("active");let u=document.createElement("span");u.className="lr-status-dot",u.classList.add(this.getDotClass(r.key)),o.appendChild(u);let p=document.createElement("div");p.className="lr-block-text";let d=r.unit.text.replace(/<\/?[0-9]+\/?>/g,""),l=document.createElement("div");l.className="lr-block-source",l.textContent=d.length>60?d.slice(0,60)+"...":d,l.title=d,p.appendChild(l);let f=this.statusMap.get(r.key);if(f&&f.text){let h=document.createElement("div");h.className="lr-block-preview";let m=f.text.replace(/<\/?[0-9]+\/?>/g,"");h.textContent=m.length>50?m.slice(0,50)+"...":m,p.appendChild(h)}o.appendChild(p),o.addEventListener("click",()=>{r.element.scrollIntoView({behavior:"smooth",block:"center"}),this.onBlockClick({key:r.key,unit:r.unit,translatedUnit:null,element:r.element})}),n.appendChild(o)}this.bodyEl.appendChild(n)}};var D=class{constructor(n,e,t){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=n.replace(/\/$/,""),this.sessionToken=e,this.projectId=t}setStatusCallback(n){this.onStatus=n}setFlushedCallback(n){this.onFlushed=n}setSessionExpiredCallback(n){this.onSessionExpired=n}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(n){let e=this.queue.findIndex(t=>t.key===n.key&&t.locale===n.locale&&t.namespace===n.namespace);e>=0?this.queue[e]=n:this.queue.push(n),this.onStatus("unsaved",`${this.queue.length} unsaved`),this.queue.length>50&&this.flush()}async flush(){if(this.queue.length===0)return;let n=[...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:n.map(s=>({key:`${s.locale}:${s.namespace}:${s.key}`,value:{text:s.text,styles:s.styles}}))})});if(e.status===401){this.handleSessionExpired();return}if(!e.ok)throw new Error(`HTTP ${e.status}`);let t=n.map(s=>s.key);for(let s of n){let r=this.queue.indexOf(s);r>=0&&this.queue.splice(r,1)}this.onFlushed(t),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(n,e,t){if(n.length===0)return{};this.statusAbort&&this.statusAbort.abort(),this.statusAbort=new AbortController;let s=n.slice(0,200),r=new URLSearchParams({locale:e,namespace:t,keys:s.join(",")});try{let o=await fetch(`${this.apiBase}/api/integrations/targets/status?${r}`,{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 n=this.getSessionExp();!n||n*1e3-Date.now()>12e4||await this.renewSession()}async renewSession(){try{let n=await fetch(`${this.apiBase}/api/editor/renew`,{method:"POST",headers:{Authorization:`Bearer ${this.sessionToken}`}});if(n.status===401){this.handleSessionExpired();return}if(!n.ok)return;let e=await n.json();this.sessionToken=e.session_token;try{let s=(this.sessionToken.startsWith("es_")?this.sessionToken.slice(3):this.sessionToken).split(".");if(s.length===3){let r=JSON.parse(atob(s[1]));sessionStorage.setItem("__lr_editor_session",JSON.stringify({token:this.sessionToken,exp:r.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(n){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:n.pageUrl,title:n.title,viewport:n.viewport,textEntries:n.textEntries,html:n.html})});if(e.status===401)return this.handleSessionExpired(),null;if(!e.ok)throw new Error(`HTTP ${e.status}`);let t=await e.json();return{snapshotUuid:t.snapshot_uuid||t.snapshotUuid}}catch(e){return this.onStatus("error",`Snapshot failed: ${e.message}`),null}}async recaptureSnapshot(n,e){try{let t=await fetch(`${this.apiBase}/api/editor/snapshots/${encodeURIComponent(n)}`,{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(t.status===401)return this.handleSessionExpired(),null;if(!t.ok)throw new Error(`HTTP ${t.status}`);let s=await t.json();return{snapshotUuid:s.snapshot_uuid||s.snapshotUuid,version:s.version||1}}catch(t){return this.onStatus("error",`Re-capture failed: ${t.message}`),null}}async getSnapshot(n){try{let e=await fetch(`${this.apiBase}/api/editor/snapshots/${encodeURIComponent(n)}`,{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 n=await fetch(`${this.apiBase}/api/editor/snapshots`,{headers:{Authorization:`Bearer ${this.sessionToken}`}});return n.status===401?(this.handleSessionExpired(),[]):n.ok?(await n.json()).snapshots||[]:[]}catch{return[]}}async deleteSnapshot(n){try{let e=await fetch(`${this.apiBase}/api/editor/snapshots/${encodeURIComponent(n)}`,{method:"DELETE",headers:{Authorization:`Bearer ${this.sessionToken}`}});return e.status===401?(this.handleSessionExpired(),!1):e.ok}catch{return!1}}};var Y="[REDACTED]";function ae(){let i=document.documentElement.cloneNode(!0),n=Ne(i);return Ce(i),Le(i),Me(i),Ae(i),Re(i),Pe(i),{html:`<!DOCTYPE html>
444
- `+i.outerHTML,textEntries:n,pageUrl:window.location.href,title:document.title,viewport:{width:window.innerWidth,height:window.innerHeight,devicePixelRatio:window.devicePixelRatio||1}}}function Ce(i){let n=["script","noscript","iframe","embed","object","#__lionrapid-editor",'link[rel="prefetch"]','link[rel="preload"]','link[rel="modulepreload"]'];for(let e of n){let t=i.querySelectorAll(e);for(let s=0;s<t.length;s++)t[s].remove()}}function Le(i){let n=i.querySelectorAll("input, textarea, select");for(let e=0;e<n.length;e++){let t=n[e];if("value"in t&&(t.value=""),t.hasAttribute("value")&&t.setAttribute("value",""),t.tagName==="TEXTAREA"&&(t.textContent=""),t.tagName==="SELECT"){let r=t.querySelectorAll("option");for(let o=0;o<r.length;o++)r[o].selected=!1,r[o].removeAttribute("selected")}let s=Array.from(t.attributes);for(let r of s)(r.name.startsWith("data-value")||r.name==="data-initial")&&t.removeAttribute(r.name)}}function Me(i){let n=i.querySelectorAll("[data-pii], [data-sensitive]");for(let e=0;e<n.length;e++){let t=n[e];t.textContent=Y;let s=Array.from(t.attributes);for(let r of s)r.name!=="class"&&r.name!=="id"&&r.name!=="style"&&t.removeAttribute(r.name)}}function Ae(i){let n=document.createTreeWalker(i,NodeFilter.SHOW_ELEMENT),e=n.nextNode();for(;e;){let t=Array.from(e.attributes);for(let s of t)s.name.toLowerCase().startsWith("on")&&e.removeAttribute(s.name);e=n.nextNode()}}function Re(i){let n=new P({emails:!0,urls:!0,numbers:!0,phones:!0},1),e=document.createTreeWalker(i,NodeFilter.SHOW_TEXT),t=[],s=e.nextNode();for(;s;){let r=(s.nodeValue||"").trim();r.length>=5&&n.shouldExclude(r)&&t.push(s),s=e.nextNode()}for(let r of t)r.nodeValue=Y}function Pe(i){let n=i.querySelectorAll('meta[name="csrf-token"], meta[name="csp-nonce"], meta[name="csrf-param"], meta[http-equiv="set-cookie"]');for(let s=0;s<n.length;s++)n[s].remove();let e=["token","auth","access_token","session","sid","key","api_key","apikey"],t=i.querySelectorAll("link[href], a[href], img[src]");for(let s=0;s<t.length;s++){let r=t[s],o=r.tagName==="IMG"?"src":"href",c=r.getAttribute(o);if(c)try{let u=new URL(c,window.location.href),p=!1;for(let d of e)u.searchParams.has(d)&&(u.searchParams.set(d,Y),p=!0);p&&r.setAttribute(o,u.toString())}catch{}}}function Ne(i){return new N({emails:!0,urls:!0,numbers:!0,phones:!0},[],2).extract(i).map((t,s)=>(t.element.setAttribute("data-lr-snap-idx",String(s)),{key:t.key,tagName:t.element.tagName,blockIndex:s}))}async function le(i,n){let e=await n.getSnapshot(i);if(!e)return null;let s=new DOMParser().parseFromString(e.html,"text/html"),r=s.head.querySelectorAll('link[rel="stylesheet"], style');for(let d=0;d<r.length;d++){let l=r[d].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 d=document.body.firstChild.nextSibling;if(!d)break;document.body.removeChild(d)}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=s.body.innerHTML,o&&o.parentNode===document.body?document.body.insertBefore(c,o):document.body.appendChild(c);let u=new Map,p=e.textEntries||[];for(let d of p)u.set(d.blockIndex,d.key);return{root:c,pageUrl:e.pageUrl,title:e.title,keyMap:u}}var K="__lr_editor_session";function ce(){try{let i=sessionStorage.getItem(K);if(!i)return null;let n=JSON.parse(i);return n.exp*1e3<Date.now()+3e4?(sessionStorage.removeItem(K),null):n.token}catch{return null}}function _e(i){try{let e=(i.startsWith("es_")?i.slice(3):i).split(".");if(e.length!==3)return;let t=JSON.parse(atob(e[1])),s={token:i,exp:t.exp||0};sessionStorage.setItem(K,JSON.stringify(s))}catch{}}function Ie(){sessionStorage.removeItem(K)}function Oe(i){try{let e=(i.startsWith("es_")?i.slice(3):i).split(".");if(e.length!==3)return"";let t=JSON.parse(atob(e[1]));return typeof t.role=="string"?t.role:""}catch{return""}}function w(i){let n=document.createElement("div");n.setAttribute("data-no-translate",""),Object.assign(n.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)"}),n.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",()=>n.remove()),n.appendChild(e),document.body.appendChild(n),setTimeout(()=>n.remove(),8e3)}function Ue(){let i=document.querySelector("script[data-grant]")||document.querySelector("script[data-lr-editor]");if(!i)return;let n=i.dataset.grant||"",e=ce()!==null;if(!n&&!e)return;let t=i.dataset.locale||"",s=i.dataset.api||"https://api.lionrapid.com",r=i.dataset.project||"",o=0,c=100,u=setInterval(()=>{o++;let p=window.LionRapid;p?(clearInterval(u),$e(p,n,t,s,r)):o>=c&&(clearInterval(u),console.warn("[LionRapid Editor] Timed out waiting for window.LionRapid"))},100)}async function $e(i,n,e,t,s){let r=window.__lionrapidConfig,o=r?.languages||[e],c=r?.namespace||"default",u=r?.defaultLocale||"en",p=e||i.getCurrentLocale(),d=t.replace(/\/$/,""),l=ce();if(!l&&n)try{let g=await fetch(`${d}/api/editor/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant:n,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&&_e(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 f=Oe(l),h=f==="project_manager"||f==="admin",m=document.createElement("div");m.id="__lionrapid-editor",m.setAttribute("data-no-translate",""),document.body.appendChild(m);let E=m.attachShadow({mode:"closed"}),I=document.createElement("style");I.textContent=re,E.appendChild(I);let G=document.querySelector("[data-lionrapid-switcher]");G&&(G.style.display="none");let M=new D(d,l,s);M.startAutoFlush();let Q=new URL(window.location.href),F=Q.searchParams.get("__lr_snapshot"),q=Q.searchParams.get("__lr_recapture"),Z,ee;if(F){let g=await le(F,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),W.clearHighlight()},k=new j(E,M,p,c,u,te),W=new z(E,te,Z,ee),V=new B(E,o,p,async g=>{if(document.querySelector('script[data-mode="dynamic-only"]')!==null){let U=new URL(window.location.href),ne=U.pathname.replace(/^\/[a-z]{2}(\/|$)/,"/"),se=g===u?"":`/${g}`;U.pathname=se+(ne==="/"&&se?"":ne),U.searchParams.set("__lr_editor",n),window.location.href=U.toString();return}k.updateLocale(g),k.close(),W.clearHighlight(),await i.changeLanguage(g),await k.hydrateStatus()},async()=>{await M.stopAndFlush(),W.destroy(),V.destroy(),k.destroy(),m.remove(),Ie()},F||!h?null:async()=>{try{let g=ae();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)=>{V.updateProgress(g,T)}),k.hydrateStatus().then(()=>{V.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())}Ue();})();
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,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}};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="&times;",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 Be(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 He(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 je(i){let t=i.querySelectorAll("[data-pii], [data-sensitive]");for(let e=0;e<t.length;e++){let n=t[e];n.textContent=le;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 De(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 Ke(i){ae(i)}function Fe(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",d=s.getAttribute(o);if(d)try{let u=new URL(d,window.location.href),c=!1;for(let h of e)u.searchParams.has(h)&&(u.searchParams.set(h,le),c=!0);c&&s.setAttribute(o,u.toString())}catch{}}}function qe(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 ce(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 d=document.createElement("div");d.id="__lr_snapshot_root",d.setAttribute("data-lr-snapshot-uuid",i),d.innerHTML=r.body.innerHTML,o&&o.parentNode===document.body?document.body.insertBefore(d,o):document.body.appendChild(d);let u=new Map,c=e.textEntries||[];for(let h of c)u.set(h.blockIndex,h.key);return{root:d,pageUrl:e.pageUrl,title:e.title,keyMap:u}}var F="__lr_editor_session";function ue(){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 We(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 Ve(){sessionStorage.removeItem(F)}function Xe(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 Je(){let i=document.querySelector("script[data-grant]")||document.querySelector("script[data-lr-editor]");if(!i)return;let t=i.dataset.grant||"",e=ue()!==null;if(!t&&!e)return;let n=i.dataset.locale||"",r=i.dataset.api||"https://api.lionrapid.com",s=i.dataset.project||"",o=0,d=100,u=setInterval(()=>{o++;let c=window.LionRapid;c?(clearInterval(u),Ye(c,t,n,r,s)):o>=d&&(clearInterval(u),console.warn("[LionRapid Editor] Timed out waiting for window.LionRapid"))},100)}async function Ye(i,t,e,n,r){let s=window.__lionrapidConfig,o=s?.languages||[e],d=s?.namespace||"default",u=s?.defaultLocale||"en",c=e||i.getCurrentLocale(),h=n.replace(/\/$/,""),l=ue();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&&We(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=Xe(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),q=Q.searchParams.get("__lr_snapshot"),W=Q.searchParams.get("__lr_recapture"),Z,ee;if(q){let g=await ce(q,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,c,d,u,te,m),V=new z(E,te,Z,ee),X=new B(E,o,c,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(),Ve()},q||!p?null:async()=>{try{let g=de();if(W){let T=await M.recaptureSnapshot(W,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.")}},W?{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())}Je();})();
445
497
  //# sourceMappingURL=lionrapid.editor.min.js.map