@lionrapid/core 0.1.1 → 0.1.3-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.
Files changed (31) hide show
  1. package/dist/browser/editor/editor-api.d.ts +52 -0
  2. package/dist/browser/editor/editor-api.d.ts.map +1 -1
  3. package/dist/browser/editor/editor-api.js +136 -0
  4. package/dist/browser/editor/editor-api.js.map +1 -1
  5. package/dist/browser/editor/editor-init.js +145 -6
  6. package/dist/browser/editor/editor-init.js.map +1 -1
  7. package/dist/browser/editor/editor-styles.d.ts +1 -1
  8. package/dist/browser/editor/editor-styles.d.ts.map +1 -1
  9. package/dist/browser/editor/editor-styles.js +29 -0
  10. package/dist/browser/editor/editor-styles.js.map +1 -1
  11. package/dist/browser/editor/inspector.d.ts +5 -1
  12. package/dist/browser/editor/inspector.d.ts.map +1 -1
  13. package/dist/browser/editor/inspector.js +32 -1
  14. package/dist/browser/editor/inspector.js.map +1 -1
  15. package/dist/browser/editor/snapshot-capture.d.ts +57 -0
  16. package/dist/browser/editor/snapshot-capture.d.ts.map +1 -0
  17. package/dist/browser/editor/snapshot-capture.js +249 -0
  18. package/dist/browser/editor/snapshot-capture.js.map +1 -0
  19. package/dist/browser/editor/snapshot-viewer.d.ts +35 -0
  20. package/dist/browser/editor/snapshot-viewer.d.ts.map +1 -0
  21. package/dist/browser/editor/snapshot-viewer.js +90 -0
  22. package/dist/browser/editor/snapshot-viewer.js.map +1 -0
  23. package/dist/browser/editor/toolbar.d.ts +7 -1
  24. package/dist/browser/editor/toolbar.d.ts.map +1 -1
  25. package/dist/browser/editor/toolbar.js +26 -1
  26. package/dist/browser/editor/toolbar.js.map +1 -1
  27. package/dist/browser/lionrapid.editor.js +532 -6
  28. package/dist/browser/lionrapid.editor.js.map +3 -3
  29. package/dist/browser/lionrapid.editor.min.js +32 -2
  30. package/dist/browser/lionrapid.editor.min.js.map +4 -4
  31. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- "use strict";var LionRapidEditor=(()=>{var G=Object.defineProperty;var Q=(i,n,e)=>n in i?G(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var a=(i,n,e)=>Q(i,typeof n!="symbol"?n+"":n,e);var V=`
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=`
2
2
  /* Reset inside shadow DOM */
3
3
  :host {
4
4
  all: initial;
@@ -146,6 +146,35 @@
146
146
  background: rgba(255,255,255,0.1);
147
147
  }
148
148
 
149
+ .lr-fab-snapshot {
150
+ background: #2d7f7f;
151
+ border: 1px solid #2d7f7f;
152
+ color: #fff;
153
+ padding: 4px 10px;
154
+ border-radius: 4px;
155
+ cursor: pointer;
156
+ font-size: 13px;
157
+ font-weight: 600;
158
+ }
159
+
160
+ .lr-fab-snapshot:hover {
161
+ background: #3a9999;
162
+ border-color: #3a9999;
163
+ }
164
+
165
+ .lr-fab-snapshot:disabled {
166
+ opacity: 0.5;
167
+ cursor: not-allowed;
168
+ }
169
+
170
+ /* Snapshot viewer sandbox wrapper */
171
+ #__lr_snapshot_root {
172
+ isolation: isolate;
173
+ position: relative;
174
+ width: 100%;
175
+ min-height: 100vh;
176
+ }
177
+
149
178
  /* \u2500\u2500 Overlay \u2500\u2500 */
150
179
  .lr-overlay {
151
180
  position: fixed;
@@ -411,5 +440,6 @@
411
440
  white-space: nowrap;
412
441
  margin-top: 2px;
413
442
  }
414
- `;var C=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=[],r=n.toLowerCase(),s=this.elementToStyles[r];return s&&t.push(s),r==="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 Z=new C;function S(i){let n={},e=0;function t(s){if(s.nodeType===Node.TEXT_NODE)return s.nodeValue??"";if(s.nodeType!==Node.ELEMENT_NODE)return"";let o=s,d=o.tagName.toLowerCase(),c={};for(let l=0;l<o.attributes.length;l++){let h=o.attributes[l];c[h.name.toLowerCase()]=h.value}let p=Z.mapElementToStyles(d,c);if(p.length>0){e++;let l=e;n[String(l)]=p;let h="";for(let m=0;m<s.childNodes.length;m++)h+=t(s.childNodes[m]);return`<${l}>${h}</${l}>`}let u="";for(let l=0;l<s.childNodes.length;l++)u+=t(s.childNodes[l]);return u}let r="";for(let s=0;s<i.childNodes.length;s++)r+=t(i.childNodes[s]);return{text:r,styles:n}}function w(i,n){let e=(i&65535)+(n&65535);return(i>>16)+(n>>16)+(e>>16)<<16|e&65535}function ee(i,n){return i<<n|i>>>32-n}function R(i,n,e,t,r,s){return w(ee(w(w(n,i),w(t,s)),r),e)}function f(i,n,e,t,r,s,o){return R(n&e|~n&t,i,n,r,s,o)}function b(i,n,e,t,r,s,o){return R(n&t|e&~t,i,n,r,s,o)}function v(i,n,e,t,r,s,o){return R(n^e^t,i,n,r,s,o)}function y(i,n,e,t,r,s,o){return R(e^(n|~t),i,n,r,s,o)}function te(i,n){i[n>>5]|=128<<n%32,i[(n+64>>>9<<4)+14]=n;let e=1732584193,t=-271733879,r=-1732584194,s=271733878;for(let o=0;o<i.length;o+=16){let d=e,c=t,p=r,u=s;e=f(e,t,r,s,i[o],7,-680876936),s=f(s,e,t,r,i[o+1],12,-389564586),r=f(r,s,e,t,i[o+2],17,606105819),t=f(t,r,s,e,i[o+3],22,-1044525330),e=f(e,t,r,s,i[o+4],7,-176418897),s=f(s,e,t,r,i[o+5],12,1200080426),r=f(r,s,e,t,i[o+6],17,-1473231341),t=f(t,r,s,e,i[o+7],22,-45705983),e=f(e,t,r,s,i[o+8],7,1770035416),s=f(s,e,t,r,i[o+9],12,-1958414417),r=f(r,s,e,t,i[o+10],17,-42063),t=f(t,r,s,e,i[o+11],22,-1990404162),e=f(e,t,r,s,i[o+12],7,1804603682),s=f(s,e,t,r,i[o+13],12,-40341101),r=f(r,s,e,t,i[o+14],17,-1502002290),t=f(t,r,s,e,i[o+15],22,1236535329),e=b(e,t,r,s,i[o+1],5,-165796510),s=b(s,e,t,r,i[o+6],9,-1069501632),r=b(r,s,e,t,i[o+11],14,643717713),t=b(t,r,s,e,i[o],20,-373897302),e=b(e,t,r,s,i[o+5],5,-701558691),s=b(s,e,t,r,i[o+10],9,38016083),r=b(r,s,e,t,i[o+15],14,-660478335),t=b(t,r,s,e,i[o+4],20,-405537848),e=b(e,t,r,s,i[o+9],5,568446438),s=b(s,e,t,r,i[o+14],9,-1019803690),r=b(r,s,e,t,i[o+3],14,-187363961),t=b(t,r,s,e,i[o+8],20,1163531501),e=b(e,t,r,s,i[o+13],5,-1444681467),s=b(s,e,t,r,i[o+2],9,-51403784),r=b(r,s,e,t,i[o+7],14,1735328473),t=b(t,r,s,e,i[o+12],20,-1926607734),e=v(e,t,r,s,i[o+5],4,-378558),s=v(s,e,t,r,i[o+8],11,-2022574463),r=v(r,s,e,t,i[o+11],16,1839030562),t=v(t,r,s,e,i[o+14],23,-35309556),e=v(e,t,r,s,i[o+1],4,-1530992060),s=v(s,e,t,r,i[o+4],11,1272893353),r=v(r,s,e,t,i[o+7],16,-155497632),t=v(t,r,s,e,i[o+10],23,-1094730640),e=v(e,t,r,s,i[o+13],4,681279174),s=v(s,e,t,r,i[o+0],11,-358537222),r=v(r,s,e,t,i[o+3],16,-722521979),t=v(t,r,s,e,i[o+6],23,76029189),e=v(e,t,r,s,i[o+9],4,-640364487),s=v(s,e,t,r,i[o+12],11,-421815835),r=v(r,s,e,t,i[o+15],16,530742520),t=v(t,r,s,e,i[o+2],23,-995338651),e=y(e,t,r,s,i[o],6,-198630844),s=y(s,e,t,r,i[o+7],10,1126891415),r=y(r,s,e,t,i[o+14],15,-1416354905),t=y(t,r,s,e,i[o+5],21,-57434055),e=y(e,t,r,s,i[o+12],6,1700485571),s=y(s,e,t,r,i[o+3],10,-1894986606),r=y(r,s,e,t,i[o+10],15,-1051523),t=y(t,r,s,e,i[o+1],21,-2054922799),e=y(e,t,r,s,i[o+8],6,1873313359),s=y(s,e,t,r,i[o+15],10,-30611744),r=y(r,s,e,t,i[o+6],15,-1560198380),t=y(t,r,s,e,i[o+13],21,1309151649),e=y(e,t,r,s,i[o+4],6,-145523070),s=y(s,e,t,r,i[o+11],10,-1120210379),r=y(r,s,e,t,i[o+2],15,718787259),t=y(t,r,s,e,i[o+9],21,-343485551),e=w(e,d),t=w(t,c),r=w(r,p),s=w(s,u)}return[e,t,r,s]}function ne(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 se(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 re(i){return ne(te(se(i),i.length*8))}function T(i){let n=i.trim();return"auto_"+re(n).substring(0,12)}var ie="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption";function J(i){let n=i.closest("[data-lr-block]");if(n){let r=n.getAttribute("data-lr-block"),s=n.getAttribute("data-lr-original"),o,d=null;if(s){let c=document.createElement(n.tagName);c.innerHTML=s,o=S(c),d=S(n)}else o=S(n);return{key:r,unit:o,translatedUnit:d,element:n}}let e=i.closest(ie);if(e){let r=S(e);return{key:T(r.text),unit:r,translatedUnit:null,element:e}}let t=i.textContent?.trim();return t&&t.length>=2?{key:T(t),unit:{text:t,styles:{}},translatedUnit:null,element:i}:null}var oe=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),Y="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",A=class{constructor(n,e){a(this,"overlay");a(this,"currentTarget",null);a(this,"onSelect");a(this,"rafId",null);a(this,"active",!0);this.onSelect=e,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"))return;if(this.shouldSkip(e)){this.clearHighlight();return}let t=e.closest(Y)||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"))return;let t=e.closest(Y)||e.closest("[data-lr-block]");if(!t||this.shouldSkip(t))return;n.preventDefault(),n.stopPropagation();let r=J(t);r&&this.onSelect(r)}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(oe.has(e.tagName)||e.hasAttribute("data-no-translate")||e.getAttribute("translate")==="no")return!0;e=e.parentElement}return!1}};var I=class{constructor(n,e,t,r,s){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,"dragging",!1);a(this,"dragOffsetX",0);a(this,"dragOffsetY",0);this.onLanguageChange=r,this.onExit=s,this.currentLocale=t,this.el=document.createElement("div"),this.el.className="lr-fab";let o=document.createElement("button");o.className="lr-fab-btn",o.textContent="LR",o.addEventListener("click",u=>{this.dragging||(u.stopPropagation(),this.toggle())}),this.el.appendChild(o);let d=document.createElement("div");d.className="lr-fab-panel";let c=document.createElement("div");c.className="lr-lang-dropdown",this.langBtnEl=document.createElement("button"),this.langBtnEl.className="lr-lang-btn",this.langBtnEl.textContent=t.toUpperCase(),this.langBtnEl.addEventListener("click",u=>{u.stopPropagation(),this.langMenuEl.classList.toggle("open")}),c.appendChild(this.langBtnEl),this.langMenuEl=document.createElement("div"),this.langMenuEl.className="lr-lang-menu";for(let u of e){let l=document.createElement("button");l.className="lr-lang-item",u===t&&l.classList.add("active"),l.textContent=u.toUpperCase(),l.addEventListener("click",h=>{h.stopPropagation(),this.currentLocale=u,this.langBtnEl.textContent=u.toUpperCase(),this.langMenuEl.classList.remove("open"),this.langMenuEl.querySelectorAll(".lr-lang-item").forEach(m=>m.classList.remove("active")),l.classList.add("active"),this.onLanguageChange(u)}),this.langMenuEl.appendChild(l)}c.appendChild(this.langMenuEl),d.appendChild(c),this.progressEl=document.createElement("span"),this.progressEl.className="lr-fab-progress",d.appendChild(this.progressEl);let p=document.createElement("button");p.className="lr-fab-exit",p.textContent="Exit",p.addEventListener("click",()=>this.onExit()),d.appendChild(p),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),o.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 L=class{constructor(n={}){a(this,"styleMapper");this.styleMapper=n.styleMapper??new C}serialize(n){let{text:e,styles:t}=n,r=/<(\/?)?(\d+)(\/)?>/g,s="",o=0,d;for(;(d=r.exec(e))!==null;){s+=e.slice(o,d.index);let[c,p,u,l]=d,m=t[u]||[];if(p){let g=this.styleMapper.mapStylesToElement(m);s+=`</${g.element}>`}else if(l){let g=this.styleMapper.mapStylesToElement(m),k=this.formatAttributes(g.attrs);s+=`<${g.element}${k} />`}else{let g=this.styleMapper.mapStylesToElement(m),k=this.formatAttributes(g.attrs);s+=`<${g.element}${k}>`}o=d.index+c.length}return s+=e.slice(o),s}formatAttributes(n){let e=Object.entries(n);return e.length===0?"":" "+e.map(([t,r])=>`${t}="${this.escapeAttributeValue(r)}"`).join(" ")}escapeAttributeValue(n){return n.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}};var ae=new L;function j(i,n,e,t,r,s){i.hasAttribute("data-lr-original")||i.setAttribute("data-lr-original",i.innerHTML);let d=window.LionRapid?.autoTranslator?le():null;if(d){let c=`${r}:${s}:${t}`;d.set(c,n,e)}if(e&&Object.keys(e).length>0){let c={text:n,styles:e};i.innerHTML=ae.serialize(c)}else i.textContent=n;i.setAttribute("data-lr-block",t),i.setAttribute("data-lionrapid-client","1")}function le(){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 de={emails:!0,urls:!0,numbers:!0,phones:!0},P={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,}$/},N=class{constructor(n={},e=2){a(this,"patterns");a(this,"minTextLength");this.patterns={...de,...n},this.minTextLength=e}shouldExclude(n){let e=n.trim();return!!(e.length<this.minTextLength||this.patterns.emails&&P.email.test(e)||this.patterns.urls&&P.url.test(e)||this.patterns.numbers&&P.number.test(e)||this.patterns.phones&&P.phone.test(e))}};var D="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",ce=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),ue=["data-lionrapid-translated","data-lionrapid-client","data-no-translate"],O=class{constructor(n={},e=[],t=2){a(this,"excludeFilter");a(this,"excludeSelectors");this.excludeFilter=new N(n,t),this.excludeSelectors=e}extract(n,e=!1){let t=[],r=n.querySelectorAll(D),s=[];n instanceof Element&&n.matches(D)&&s.push(n);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(D))continue;let c=d.getAttribute("data-lr-block"),p=d.getAttribute("data-lr-original"),u;if(p){let m=document.createElement(d.tagName);m.innerHTML=p,u=S(m)}else u=S(d);let l=u.text.replace(/<\/?[0-9]+\/?>/g,"");if(this.excludeFilter.shouldExclude(l))continue;let h;if(c)h=c;else{let m=d.getAttribute("data-i18n");m?h=m.includes(":")?m:`common:${m}`:h=T(u.text)}t.push({element:d,unit:u,key:h})}return t}isInsideSkipTag(n){let e=n.parentElement;for(;e;){if(ce.has(e.tagName))return!0;e=e.parentElement}return!1}hasSkipAttribute(n){let e=n;for(;e;){for(let t of ue)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 pe=new L,z=class{constructor(n,e,t,r,s,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=r,this.defaultLocale=s,this.onBlockClick=o,this.blockExtractor=new O,this.el=document.createElement("div"),this.el.className="lr-sidebar";let d=document.createElement("div");d.className="lr-sidebar-resize",this.initResize(d),this.el.appendChild(d);let c=document.createElement("div");c.className="lr-sidebar-header";let p=document.createElement("span");p.className="lr-sidebar-title",p.textContent="Edit Translation",c.appendChild(p);let u=document.createElement("button");u.className="lr-sidebar-close",u.innerHTML="&times;",u.addEventListener("click",()=>this.close()),c.appendChild(u),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((l,h)=>{this.statusEl.textContent=h||l,this.statusEl.className=`lr-status ${l}`}),this.api.setFlushedCallback(async l=>{this.lastFlushTime=Date.now();let h=await this.api.fetchStatus(l,this.locale,this.namespace);for(let[m,g]of Object.entries(h))this.statusMap.set(m,g),this.unsavedKeys.delete(m);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(r=>r.key);if(e.length===0)return;let t=await this.api.fetchStatus(e,this.locale,this.namespace);for(let[r,s]of Object.entries(t))this.statusMap.set(r,s);for(let r of n){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 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:r}=n;if(this.bodyEl.innerHTML="",this.lastFlushTime>this.lastFetchTime||this.lastFetchTime===0){let h=this.blockExtractor.extract(document.body,!0).map(g=>g.key);h.includes(e)||h.push(e);let m=await this.api.fetchStatus(h,this.locale,this.namespace);for(let[g,k]of Object.entries(m))this.statusMap.set(g,k);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 d=this.locale===this.defaultLocale,c=d||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,c&&(p.readOnly=!0,p.classList.add("lr-textarea-locked"),p.title=d?"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 u=document.createElement("div");this.addField("Preview",()=>(u.className="lr-preview",p.value&&(u.innerHTML=this.renderPreview(p.value,t.styles)),u)),c||p.addEventListener("input",()=>{let l=p.value;u.innerHTML=this.renderPreview(l,t.styles),l&&j(r,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(),c||setTimeout(()=>p.focus(),100)}addField(n,e){let t=document.createElement("div");t.className="lr-field";let r=document.createElement("span");r.className="lr-field-label",r.textContent=n,t.appendChild(r),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 pe.serialize(t)}return n}initResize(n){let e=0,t=0,r=o=>{let d=t+(e-o.clientX),c=Math.max(280,Math.min(600,d));this.el.style.width=`${c}px`},s=()=>{n.classList.remove("active"),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",s)};n.addEventListener("mousedown",o=>{o.preventDefault(),e=o.clientX,t=this.el.offsetWidth,n.classList.add("active"),document.addEventListener("mousemove",r),document.addEventListener("mouseup",s)})}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(),r=document.createElement("div");r.className="lr-blocks-title",r.textContent=`Blocks on this page (${t}/${e.length} translated)`,n.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 c=document.createElement("span");c.className="lr-status-dot",c.classList.add(this.getDotClass(s.key)),o.appendChild(c);let p=document.createElement("div");p.className="lr-block-text";let u=s.unit.text.replace(/<\/?[0-9]+\/?>/g,""),l=document.createElement("div");l.className="lr-block-source",l.textContent=u.length>60?u.slice(0,60)+"...":u,l.title=u,p.appendChild(l);let h=this.statusMap.get(s.key);if(h&&h.text){let m=document.createElement("div");m.className="lr-block-preview";let g=h.text.replace(/<\/?[0-9]+\/?>/g,"");m.textContent=g.length>50?g.slice(0,50)+"...":g,p.appendChild(m)}o.appendChild(p),o.addEventListener("click",()=>{s.element.scrollIntoView({behavior:"smooth",block:"center"}),this.onBlockClick({key:s.key,unit:s.unit,translatedUnit:null,element:s.element})}),n.appendChild(o)}this.bodyEl.appendChild(n)}};var $=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(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 t=n.map(r=>r.key);for(let r of n){let s=this.queue.indexOf(r);s>=0&&this.queue.splice(s,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 r=n.slice(0,200),s=new URLSearchParams({locale:e,namespace:t,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 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 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()}};var B="__lr_editor_session";function he(){try{let i=sessionStorage.getItem(B);if(!i)return null;let n=JSON.parse(i);return n.exp*1e3<Date.now()+3e4?(sessionStorage.removeItem(B),null):n.token}catch{return null}}function me(i){try{let e=(i.startsWith("es_")?i.slice(3):i).split(".");if(e.length!==3)return;let t=JSON.parse(atob(e[1])),r={token:i,exp:t.exp||0};sessionStorage.setItem(B,JSON.stringify(r))}catch{}}function ge(){sessionStorage.removeItem(B)}function fe(){let i=document.querySelector("script[data-grant]");if(!i){console.warn("[LionRapid Editor] No script tag with data-grant found");return}let n=i.dataset.grant||"",e=i.dataset.locale||"",t=i.dataset.api||"https://api.lionrapid.com",r=i.dataset.project||"",s=0,o=100,d=setInterval(()=>{s++;let c=window.LionRapid;c?(clearInterval(d),be(c,n,e,t,r)):s>=o&&(clearInterval(d),console.warn("[LionRapid Editor] Timed out waiting for window.LionRapid"))},100)}async function be(i,n,e,t,r){let s=window.__lionrapidConfig,o=s?.languages||[e],d=s?.namespace||"default",c=s?.defaultLocale||"en",p=e||i.getCurrentLocale(),u=t.replace(/\/$/,""),l=he();if(!l&&n)try{let x=await fetch(`${u}/api/editor/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant:n,domain:window.location.host})});if(!x.ok){console.error("[LionRapid Editor] Grant exchange failed:",x.status);return}l=(await x.json()).session_token,l&&me(l)}catch(x){console.error("[LionRapid Editor] Grant exchange error:",x);return}if(!l){console.error("[LionRapid Editor] No valid session. Please reopen the editor from the dashboard.");return}let h=document.createElement("div");h.id="__lionrapid-editor",h.setAttribute("data-no-translate",""),document.body.appendChild(h);let m=h.attachShadow({mode:"closed"}),g=document.createElement("style");g.textContent=V,m.appendChild(g);let k=document.querySelector("[data-lionrapid-switcher]");k&&(k.style.display="none");let _=new $(u,l,r);_.startAutoFlush();let q=x=>{E.open(x),U.clearHighlight()},E=new z(m,_,p,d,c,q),U=new A(m,q),H=new I(m,o,p,async x=>{if(document.querySelector('script[data-mode="dynamic-only"]')!==null){let M=new URL(window.location.href),W=M.pathname.replace(/^\/[a-z]{2}(\/|$)/,"/"),X=x===c?"":`/${x}`;M.pathname=X+(W==="/"&&X?"":W),M.searchParams.set("__lr_editor",n),window.location.href=M.toString();return}E.updateLocale(x),E.close(),U.clearHighlight(),await i.changeLanguage(x),await E.hydrateStatus()},async()=>{await _.stopAndFlush(),U.destroy(),H.destroy(),E.destroy(),h.remove(),ge()});E.setProgressCallback((x,F)=>{H.updateProgress(x,F)}),E.hydrateStatus().then(()=>{H.updateProgress(E.getTranslatedCount(),E.getTotalCount())});let K=new URL(window.location.href);K.searchParams.has("__lr_editor")&&(K.searchParams.delete("__lr_editor"),history.replaceState(null,"",K.toString()))}fe();})();
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();})();
415
445
  //# sourceMappingURL=lionrapid.editor.min.js.map