@lionrapid/core 0.4.0 → 0.6.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.
- package/dist/base/event-emitter.d.ts.map +1 -1
- package/dist/base/event-emitter.js +2 -1
- package/dist/base/event-emitter.js.map +1 -1
- package/dist/browser/attribute-extractor.d.ts.map +1 -1
- package/dist/browser/attribute-extractor.js +2 -1
- package/dist/browser/attribute-extractor.js.map +1 -1
- package/dist/browser/auto-init.d.ts +69 -0
- package/dist/browser/auto-init.d.ts.map +1 -1
- package/dist/browser/auto-init.js +193 -61
- package/dist/browser/auto-init.js.map +1 -1
- package/dist/browser/block-extractor.d.ts.map +1 -1
- package/dist/browser/block-extractor.js +3 -1
- package/dist/browser/block-extractor.js.map +1 -1
- package/dist/browser/editor/editor-api.d.ts +50 -6
- package/dist/browser/editor/editor-api.d.ts.map +1 -1
- package/dist/browser/editor/editor-api.js +121 -19
- package/dist/browser/editor/editor-api.js.map +1 -1
- package/dist/browser/editor/editor-init.js +4 -1
- package/dist/browser/editor/editor-init.js.map +1 -1
- package/dist/browser/editor/sidebar.d.ts +4 -3
- package/dist/browser/editor/sidebar.d.ts.map +1 -1
- package/dist/browser/editor/sidebar.js +93 -27
- package/dist/browser/editor/sidebar.js.map +1 -1
- package/dist/browser/editor/snapshot-viewer.d.ts.map +1 -1
- package/dist/browser/editor/snapshot-viewer.js +32 -3
- package/dist/browser/editor/snapshot-viewer.js.map +1 -1
- package/dist/browser/lionrapid.auto.dev.js +599 -245
- package/dist/browser/lionrapid.auto.dev.js.map +4 -4
- package/dist/browser/lionrapid.auto.js +599 -245
- package/dist/browser/lionrapid.auto.js.map +4 -4
- package/dist/browser/lionrapid.auto.min.js +4 -3
- package/dist/browser/lionrapid.auto.min.js.map +4 -4
- package/dist/browser/lionrapid.editor.js +1467 -1115
- package/dist/browser/lionrapid.editor.js.map +4 -4
- package/dist/browser/lionrapid.editor.min.js +4 -3
- package/dist/browser/lionrapid.editor.min.js.map +4 -4
- package/dist/browser/lionrapid.esm.js +951 -196
- package/dist/browser/lionrapid.esm.js.map +4 -4
- package/dist/browser/lionrapid.esm.min.js +3 -2
- package/dist/browser/lionrapid.esm.min.js.map +4 -4
- package/dist/browser/lionrapid.iife.dev.js +951 -196
- package/dist/browser/lionrapid.iife.dev.js.map +4 -4
- package/dist/browser/lionrapid.iife.js +951 -196
- package/dist/browser/lionrapid.iife.js.map +4 -4
- package/dist/browser/lionrapid.iife.min.js +3 -2
- package/dist/browser/lionrapid.iife.min.js.map +4 -4
- package/dist/browser/lionrapid.umd.js +951 -196
- package/dist/browser/lionrapid.umd.js.map +4 -4
- package/dist/browser/lionrapid.umd.min.js +3 -2
- package/dist/browser/lionrapid.umd.min.js.map +4 -4
- package/dist/browser/sanitizer.d.ts +37 -0
- package/dist/browser/sanitizer.d.ts.map +1 -0
- package/dist/browser/sanitizer.js +93 -0
- package/dist/browser/sanitizer.js.map +1 -0
- package/dist/builder.d.ts +16 -0
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +43 -5
- package/dist/builder.js.map +1 -1
- package/dist/config/lionrapid.config.d.ts +0 -1
- package/dist/config/lionrapid.config.d.ts.map +1 -1
- package/dist/config/repository.config.d.ts +2 -2
- package/dist/config/repository.config.d.ts.map +1 -1
- package/dist/content/index.d.ts +3 -0
- package/dist/content/index.d.ts.map +1 -1
- package/dist/content/index.js +5 -0
- package/dist/content/index.js.map +1 -1
- package/dist/content/sanitizer/HTMLSanitizer.d.ts +105 -0
- package/dist/content/sanitizer/HTMLSanitizer.d.ts.map +1 -0
- package/dist/content/sanitizer/HTMLSanitizer.js +257 -0
- package/dist/content/sanitizer/HTMLSanitizer.js.map +1 -0
- package/dist/content/serializer/HTMLSerializer.d.ts +6 -2
- package/dist/content/serializer/HTMLSerializer.d.ts.map +1 -1
- package/dist/content/serializer/HTMLSerializer.js +16 -8
- package/dist/content/serializer/HTMLSerializer.js.map +1 -1
- package/dist/content/splitter/BlockSplitter.d.ts +66 -0
- package/dist/content/splitter/BlockSplitter.d.ts.map +1 -0
- package/dist/content/splitter/BlockSplitter.js +219 -0
- package/dist/content/splitter/BlockSplitter.js.map +1 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -1
- package/dist/index.js.map +1 -1
- package/dist/lionRapid.d.ts +1 -2
- package/dist/lionRapid.d.ts.map +1 -1
- package/dist/lionRapid.js +5 -7
- package/dist/lionRapid.js.map +1 -1
- package/dist/repositories/index.d.ts +1 -0
- package/dist/repositories/index.d.ts.map +1 -1
- package/dist/repositories/index.js +1 -0
- package/dist/repositories/index.js.map +1 -1
- package/dist/repositories/network-repository.d.ts +30 -8
- package/dist/repositories/network-repository.d.ts.map +1 -1
- package/dist/repositories/network-repository.js +88 -74
- package/dist/repositories/network-repository.js.map +1 -1
- package/dist/repositories/static-repository.d.ts +40 -0
- package/dist/repositories/static-repository.d.ts.map +1 -0
- package/dist/repositories/static-repository.js +60 -0
- package/dist/repositories/static-repository.js.map +1 -0
- package/dist/types/lionRapid.types.d.ts +2 -0
- package/dist/types/lionRapid.types.d.ts.map +1 -1
- package/dist/types/translation.types.d.ts +0 -3
- package/dist/types/translation.types.d.ts.map +1 -1
- package/dist/utils/context-utils.d.ts +1 -2
- package/dist/utils/context-utils.d.ts.map +1 -1
- package/dist/utils/context-utils.js +3 -6
- package/dist/utils/context-utils.js.map +1 -1
- package/dist/utils/locale.d.ts +57 -0
- package/dist/utils/locale.d.ts.map +1 -0
- package/dist/utils/locale.js +116 -0
- package/dist/utils/locale.js.map +1 -0
- package/dist/utils/translation-flow.d.ts +1 -1
- package/dist/utils/translation-flow.d.ts.map +1 -1
- package/dist/utils/translation-flow.js +2 -3
- package/dist/utils/translation-flow.js.map +1 -1
- package/package.json +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var LionRapidEditor=(()=>{var
|
|
1
|
+
"use strict";var LionRapidEditor=(()=>{var Me=Object.defineProperty;var Ne=(s,t,e)=>t in s?Me(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var p=(s,t,e)=>Ne(s,typeof t!="symbol"?t+"":t,e);var pe=`
|
|
2
2
|
/* Reset inside shadow DOM */
|
|
3
3
|
:host {
|
|
4
4
|
all: initial;
|
|
@@ -584,6 +584,7 @@
|
|
|
584
584
|
white-space: nowrap;
|
|
585
585
|
margin-top: 2px;
|
|
586
586
|
}
|
|
587
|
-
`;var D=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function ke(s){return s.replace(/"/g,""")}function ae(s,t){let n=`<${s.toLowerCase()}`;for(let[r,o]of Object.entries(t))n+=` ${r.toLowerCase()}="${ke(o)}"`;return n+=">",n}function le(s){let t=s.search(/[\s>]/);return s.slice(1,t===-1?s.length:t).toLowerCase()}function ce(s){for(let t of s)if(t.startsWith("raw:"))return t.slice(4);return null}function S(s){let t={},e=0;function n(o){if(o.nodeType===Node.TEXT_NODE)return o.nodeValue??"";if(o.nodeType!==Node.ELEMENT_NODE)return"";let i=o,a=i.tagName.toLowerCase(),p={};for(let c=0;c<i.attributes.length;c++){let h=i.attributes[c];p[h.name.toLowerCase()]=h.value}e++;let l=e;if(t[String(l)]=[`raw:${ae(a,p)}`],D.has(a))return`<${l}/>`;let d="";for(let c=0;c<o.childNodes.length;c++)d+=n(o.childNodes[c]);return`<${l}>${d}</${l}>`}let r="";for(let o=0;o<s.childNodes.length;o++)r+=n(s.childNodes[o]);return{text:r,styles:t}}function A(s,t){let e=(s&65535)+(t&65535);return(s>>16)+(t>>16)+(e>>16)<<16|e&65535}function Se(s,t){return s<<t|s>>>32-t}function F(s,t,e,n,r,o){return A(Se(A(A(t,s),A(n,o)),r),e)}function v(s,t,e,n,r,o,i){return F(t&e|~t&n,s,t,r,o,i)}function x(s,t,e,n,r,o,i){return F(t&n|e&~n,s,t,r,o,i)}function w(s,t,e,n,r,o,i){return F(t^e^n,s,t,r,o,i)}function y(s,t,e,n,r,o,i){return F(e^(t|~n),s,t,r,o,i)}function Te(s,t){s[t>>5]|=128<<t%32,s[(t+64>>>9<<4)+14]=t;let e=1732584193,n=-271733879,r=-1732584194,o=271733878;for(let i=0;i<s.length;i+=16){let a=e,p=n,l=r,d=o;e=v(e,n,r,o,s[i],7,-680876936),o=v(o,e,n,r,s[i+1],12,-389564586),r=v(r,o,e,n,s[i+2],17,606105819),n=v(n,r,o,e,s[i+3],22,-1044525330),e=v(e,n,r,o,s[i+4],7,-176418897),o=v(o,e,n,r,s[i+5],12,1200080426),r=v(r,o,e,n,s[i+6],17,-1473231341),n=v(n,r,o,e,s[i+7],22,-45705983),e=v(e,n,r,o,s[i+8],7,1770035416),o=v(o,e,n,r,s[i+9],12,-1958414417),r=v(r,o,e,n,s[i+10],17,-42063),n=v(n,r,o,e,s[i+11],22,-1990404162),e=v(e,n,r,o,s[i+12],7,1804603682),o=v(o,e,n,r,s[i+13],12,-40341101),r=v(r,o,e,n,s[i+14],17,-1502002290),n=v(n,r,o,e,s[i+15],22,1236535329),e=x(e,n,r,o,s[i+1],5,-165796510),o=x(o,e,n,r,s[i+6],9,-1069501632),r=x(r,o,e,n,s[i+11],14,643717713),n=x(n,r,o,e,s[i],20,-373897302),e=x(e,n,r,o,s[i+5],5,-701558691),o=x(o,e,n,r,s[i+10],9,38016083),r=x(r,o,e,n,s[i+15],14,-660478335),n=x(n,r,o,e,s[i+4],20,-405537848),e=x(e,n,r,o,s[i+9],5,568446438),o=x(o,e,n,r,s[i+14],9,-1019803690),r=x(r,o,e,n,s[i+3],14,-187363961),n=x(n,r,o,e,s[i+8],20,1163531501),e=x(e,n,r,o,s[i+13],5,-1444681467),o=x(o,e,n,r,s[i+2],9,-51403784),r=x(r,o,e,n,s[i+7],14,1735328473),n=x(n,r,o,e,s[i+12],20,-1926607734),e=w(e,n,r,o,s[i+5],4,-378558),o=w(o,e,n,r,s[i+8],11,-2022574463),r=w(r,o,e,n,s[i+11],16,1839030562),n=w(n,r,o,e,s[i+14],23,-35309556),e=w(e,n,r,o,s[i+1],4,-1530992060),o=w(o,e,n,r,s[i+4],11,1272893353),r=w(r,o,e,n,s[i+7],16,-155497632),n=w(n,r,o,e,s[i+10],23,-1094730640),e=w(e,n,r,o,s[i+13],4,681279174),o=w(o,e,n,r,s[i+0],11,-358537222),r=w(r,o,e,n,s[i+3],16,-722521979),n=w(n,r,o,e,s[i+6],23,76029189),e=w(e,n,r,o,s[i+9],4,-640364487),o=w(o,e,n,r,s[i+12],11,-421815835),r=w(r,o,e,n,s[i+15],16,530742520),n=w(n,r,o,e,s[i+2],23,-995338651),e=y(e,n,r,o,s[i],6,-198630844),o=y(o,e,n,r,s[i+7],10,1126891415),r=y(r,o,e,n,s[i+14],15,-1416354905),n=y(n,r,o,e,s[i+5],21,-57434055),e=y(e,n,r,o,s[i+12],6,1700485571),o=y(o,e,n,r,s[i+3],10,-1894986606),r=y(r,o,e,n,s[i+10],15,-1051523),n=y(n,r,o,e,s[i+1],21,-2054922799),e=y(e,n,r,o,s[i+8],6,1873313359),o=y(o,e,n,r,s[i+15],10,-30611744),r=y(r,o,e,n,s[i+6],15,-1560198380),n=y(n,r,o,e,s[i+13],21,1309151649),e=y(e,n,r,o,s[i+4],6,-145523070),o=y(o,e,n,r,s[i+11],10,-1120210379),r=y(r,o,e,n,s[i+2],15,718787259),n=y(n,r,o,e,s[i+9],21,-343485551),e=A(e,a),n=A(n,p),r=A(r,l),o=A(o,d)}return[e,n,r,o]}function Ce(s){let t="0123456789abcdef",e="";for(let n=0;n<s.length*4;n++)e+=t.charAt(s[n>>2]>>n%4*8+4&15)+t.charAt(s[n>>2]>>n%4*8&15);return e}function Le(s){if(typeof TextEncoder<"u")return new TextEncoder().encode(s);let t=[];for(let e=0;e<s.length;e++){let n=s.charCodeAt(e);if(n<128)t.push(n);else if(n<2048)t.push(192|n>>6,128|n&63);else if(n>=55296&&n<56320&&e+1<s.length){let r=s.charCodeAt(++e),o=65536+(n-55296<<10)+(r-56320);t.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63)}else t.push(224|n>>12,128|n>>6&63,128|n&63)}return new Uint8Array(t)}function Ae(s){let t=[];for(let e=0;e<s.length;e++)t[e>>2]|=s[e]<<e%4*8;return t}function Me(s){let t=Le(s);return Ce(Te(Ae(t),t.length*8))}function M(s){let t=s.trim();return"auto_"+Me(t).substring(0,12)}var _e="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption";function de(s){let t=s.closest("[data-lr-block]");if(t){let r=t.getAttribute("data-lr-block"),o=t.getAttribute("data-lr-original"),i,a=null;if(o){let p=document.createElement(t.tagName);p.innerHTML=o,i=S(p),a=S(t)}else i=S(t);return{key:r,unit:i,translatedUnit:a,element:t}}let e=s.closest(_e);if(e){let r=S(e);return{key:M(r.text),unit:r,translatedUnit:null,element:e}}let n=s.textContent?.trim();return n&&n.length>=2?{key:M(n),unit:{text:n,styles:{}},translatedUnit:null,element:s}:null}var Re=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),ue="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",j=class{constructor(t,e,n,r){u(this,"overlay");u(this,"currentTarget",null);u(this,"onSelect");u(this,"rafId",null);u(this,"active",!0);u(this,"rootElement");u(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")}setActive(t){this.active=t,t||this.clearHighlight()}isActive(){return this.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(ue)||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(ue)||e.closest("[data-lr-block]");if(!n||this.shouldSkip(n))return;if(t.preventDefault(),t.stopPropagation(),this.snapshotKeyMap){let o=n.getAttribute("data-lr-snap-idx");if(o!==null){let i=parseInt(o,10),a=this.snapshotKeyMap.get(i);if(a){let p=S(n);this.onSelect({key:a,unit:p,translatedUnit:null,element:n});return}}return}let r=de(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(Re.has(e.tagName)||e.hasAttribute("data-no-translate")||e.getAttribute("translate")==="no")return!0;e=e.parentElement}return!1}};var K=class{constructor(t,e,n,r,o,i=null,a={},p=null){u(this,"el");u(this,"langBtnEl");u(this,"langMenuEl");u(this,"progressEl");u(this,"expanded",!1);u(this,"currentLocale");u(this,"onLanguageChange");u(this,"onExit");u(this,"onCaptureSnapshot");u(this,"onBrowseToggle");u(this,"browsing",!1);u(this,"browseBtnEl",null);u(this,"dragging",!1);u(this,"dragOffsetX",0);u(this,"dragOffsetY",0);this.onLanguageChange=r,this.onExit=o,this.onCaptureSnapshot=i,this.onBrowseToggle=p,this.currentLocale=n;let l=a.mode??"capture";this.el=document.createElement("div"),this.el.className="lr-fab";let d=document.createElement("button");d.className="lr-fab-btn",d.textContent="LR",d.addEventListener("click",f=>{this.dragging||(f.stopPropagation(),this.toggle())});let c=document.createElement("div");c.className="lr-fab-panel";let h=document.createElement("div");h.className="lr-lang-dropdown",this.langBtnEl=document.createElement("button"),this.langBtnEl.className="lr-lang-btn",this.langBtnEl.textContent=n.toUpperCase(),this.langBtnEl.addEventListener("click",f=>{f.stopPropagation(),this.langMenuEl.classList.toggle("open")}),h.appendChild(this.langBtnEl),this.langMenuEl=document.createElement("div"),this.langMenuEl.className="lr-lang-menu";for(let f of e){let b=document.createElement("button");b.className="lr-lang-item",f===n&&b.classList.add("active"),b.textContent=f.toUpperCase(),b.addEventListener("click",E=>{E.stopPropagation(),this.currentLocale=f,this.langBtnEl.textContent=f.toUpperCase(),this.langMenuEl.classList.remove("open"),this.langMenuEl.querySelectorAll(".lr-lang-item").forEach(B=>B.classList.remove("active")),b.classList.add("active"),this.onLanguageChange(f)}),this.langMenuEl.appendChild(b)}if(h.appendChild(this.langMenuEl),c.appendChild(h),this.onCaptureSnapshot){let f=document.createElement("button");f.className="lr-fab-snapshot",l==="recapture"?(f.textContent="Save re-capture",f.title="Save this page as a new version of the existing snapshot"):(f.textContent="Capture",f.title="Capture a redacted snapshot of this page for translators"),f.addEventListener("click",b=>{b.stopPropagation(),this.onCaptureSnapshot&&this.onCaptureSnapshot()}),c.appendChild(f)}if(this.onBrowseToggle){let f=document.createElement("button");f.className="lr-fab-browse",f.textContent="Browse",f.title="Pause editing so you can click links and navigate to another page",f.addEventListener("click",b=>{b.stopPropagation(),this.setBrowsing(!this.browsing)}),this.browseBtnEl=f,c.appendChild(f)}this.progressEl=document.createElement("span"),this.progressEl.className="lr-fab-progress",c.appendChild(this.progressEl);let m=document.createElement("button");m.className="lr-fab-exit",m.textContent="Exit",m.addEventListener("click",()=>this.onExit()),c.appendChild(m),this.el.appendChild(c),this.el.appendChild(d),t.appendChild(this.el),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this),d.addEventListener("mousedown",this.handleMouseDown)}toggle(){this.expanded=!this.expanded,this.el.classList.toggle("expanded",this.expanded)}setBrowsing(t){this.browsing=t,this.browseBtnEl&&(this.browseBtnEl.textContent=t?"Editing":"Browse",this.browseBtnEl.classList.toggle("active",t),this.browseBtnEl.title=t?"Resume editing \u2014 clicks open the edit drawer again":"Pause editing so you can click links and navigate to another page"),this.el.classList.toggle("lr-fab--browsing",t),this.onBrowseToggle&&this.onBrowseToggle(t)}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)),r=window.innerWidth-e-this.el.offsetWidth;this.el.style.right=`${Math.max(0,r)}px`,this.el.style.top=`${n}px`,this.el.style.left="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 I=class{serialize(t){let{text:e,styles:n}=t,r=/<(\/?)?(\d+)(\/)?>/g,o="",i=0,a;for(;(a=r.exec(e))!==null;){o+=e.slice(i,a.index);let[p,l,d]=a,c=n[d]??[],h=ce(c);if(h){let m=le(h),f=D.has(m);l?f||(o+=`</${m}>`):o+=h}else o+=p;i=a.index+p.length}return o+=e.slice(i),o}};var pe=new I;function Z(s,t,e,n,r,o,i,a){s.hasAttribute("data-lr-original")||s.setAttribute("data-lr-original",s.innerHTML);let l=window.LionRapid?.autoTranslator?Pe():null;if(l){let m=`${r}:${o}:${n}`;l.set(m,t,e)}let d=/<\/?[0-9]+\/?>/.test(t),c=a==="machine_translated",h=i?i.match(/^<(\d+)>([\s\S]*)<\/\1>$/):null;if(d){let m={text:t,styles:e};s.innerHTML=pe.serialize(m)}else if(c&&h&&e&&Object.keys(e).length>0){let m=h[1],b={text:`<${m}>${t}</${m}>`,styles:e};s.innerHTML=pe.serialize(b)}else s.textContent=t;s.setAttribute("data-lr-block",n),s.setAttribute("data-lionrapid-client","1")}function Pe(){try{let s=window.LionRapid;if(!s)return null;let t=s.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 Ie={emails:!0,urls:!0,numbers:!0,phones:!0},W={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,}$/},q=class{constructor(t={},e=2){u(this,"patterns");u(this,"minTextLength");this.patterns={...Ie,...t},this.minTextLength=e}shouldExclude(t){let e=t.trim();return!!(e.length<this.minTextLength||this.patterns.emails&&W.email.test(e)||this.patterns.urls&&W.url.test(e)||this.patterns.numbers&&W.number.test(e)||this.patterns.phones&&W.phone.test(e))}};var $="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",ee="a",Ne=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),Oe=["data-lionrapid-translated","data-lionrapid-client","data-no-translate","data-lr-block"],_=class{constructor(t={},e=[],n=2){u(this,"excludeFilter");u(this,"excludeSelectors");this.excludeFilter=new q(t,n),this.excludeSelectors=e}extract(t,e=!1){let n=[],r=t.querySelectorAll($),o=[];t instanceof Element&&t.matches($)&&o.push(t);for(let i=0;i<r.length;i++)o.push(r[i]);for(let i=0;i<o.length;i++){let a=o[i];if(this.isInsideSkipTag(a)||!e&&this.hasSkipAttribute(a)||this.matchesExcludeSelector(a)||a.getAttribute("translate")==="no"||a.querySelector($))continue;let p=a.getAttribute("data-lr-block"),l=a.getAttribute("data-lr-original"),d;if(l){let m=document.createElement(a.tagName);m.innerHTML=l,d=S(m)}else d=S(a);let c=d.text.replace(/<\/?[0-9]+\/?>/g,"");if(this.excludeFilter.shouldExclude(c))continue;let h;if(p)h=p;else{let m=a.getAttribute("data-i18n");m?h=m.includes(":")?m:`common:${m}`:h=M(d.text)}n.push({element:a,unit:d,key:h})}return this.extractOrphanInline(t,n,e),n}extractOrphanInline(t,e,n){let r=t.querySelectorAll(ee),o=[];t instanceof Element&&t.matches(ee)&&o.push(t);for(let i=0;i<r.length;i++)o.push(r[i]);for(let i=0;i<o.length;i++){let a=o[i];if(this.isInsideSkipTag(a)||!n&&this.hasSkipAttribute(a)||this.matchesExcludeSelector(a)||a.getAttribute("translate")==="no"||a.parentElement?.closest($)||a.parentElement?.closest(ee)||a.querySelector($))continue;let p=a.getAttribute("data-lr-original"),l;if(p){let m=document.createElement(a.tagName);m.innerHTML=p,l=S(m)}else l=S(a);let d=l.text.replace(/<\/?[0-9]+\/?>/g,"");if(this.excludeFilter.shouldExclude(d))continue;let c=a.getAttribute("data-lr-block"),h;if(c)h=c;else{let m=a.getAttribute("data-i18n");m?h=m.includes(":")?m:`common:${m}`:h=M(l.text)}e.push({element:a,unit:l,key:h})}}isInsideSkipTag(t){let e=t.parentElement;for(;e;){if(Ne.has(e.tagName))return!0;e=e.parentElement}return!1}hasSkipAttribute(t){let e=t;for(;e;){for(let n of Oe)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}};function V(s,t){let e;try{e=new URL(s,window.location.href)}catch{return s}if(e.origin!==window.location.origin)return s;let n=window.location.pathname.match(/^\/([a-z]{2})(\/|$)/),r=n?n[1]:t;return r===t||/^\/[a-z]{2}(\/|$)/.test(e.pathname)||(e.pathname="/"+r+e.pathname),e.href}var $e=new I,J=class{constructor(t,e,n,r,o,i,a=""){u(this,"el");u(this,"bodyEl");u(this,"statusEl");u(this,"api");u(this,"locale");u(this,"namespace");u(this,"defaultLocale");u(this,"current",null);u(this,"blockExtractor");u(this,"onBlockClick");u(this,"statusMap",new Map);u(this,"unsavedKeys",new Set);u(this,"onProgressUpdate",null);u(this,"lastFetchTime",0);u(this,"lastFlushTime",0);u(this,"userRole");u(this,"workflowInfo",null);u(this,"workflowInfoFetched",!1);this.api=e,this.locale=n,this.namespace=r,this.defaultLocale=o,this.onBlockClick=i,this.userRole=a,this.blockExtractor=new _,this.el=document.createElement("div"),this.el.className="lr-sidebar";let p=document.createElement("div");p.className="lr-sidebar-resize",this.initResize(p),this.el.appendChild(p);let l=document.createElement("div");l.className="lr-sidebar-header";let d=document.createElement("span");d.className="lr-sidebar-title",d.textContent="Edit Translation",l.appendChild(d);let c=document.createElement("button");c.className="lr-sidebar-close",c.innerHTML="×",c.addEventListener("click",()=>this.close()),l.appendChild(c),this.el.appendChild(l),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((h,m)=>{this.statusEl.textContent=m||h,this.statusEl.className=`lr-status ${h}`}),this.api.setFlushedCallback(async h=>{this.lastFlushTime=Date.now();let m=await this.api.fetchStatus(h,this.locale,this.namespace);for(let[f,b]of Object.entries(m))this.statusMap.set(f,b),this.unsavedKeys.delete(f);this.refreshBlocksList(),this.emitProgress()}),typeof window<"u"&&(window.__lr_dump_keys=()=>{let m=this.blockExtractor.extract(document.body,!0).map((f,b)=>{let E=this.statusMap.get(f.key);return{i:b,key:f.key,text:f.unit.text,stylesJson:JSON.stringify(f.unit.styles),statusText:E?.text??"",isReady:!!E?.isReady,hasTranslation:!!E?.text}});return console.table(m),m},window.__lr_editor_edit=(h,m)=>{let b=this.blockExtractor.extract(document.body,!0).find(E=>E.key===h);if(!b)throw new Error(`[__lr_editor_edit] no block on page with key ${h}`);this.unsavedKeys.add(h),this.api.queueSave({key:h,locale:this.locale,namespace:this.namespace,text:m,styles:b.unit.styles})},window.__lr_editor_flush=()=>this.api.flush()),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(i=>i.key);if(e.length===0)return;let n=await this.api.fetchStatus(e,this.locale,this.namespace);for(let[i,a]of Object.entries(n))this.statusMap.set(i,a);let r=[],o=0;for(let i of t){let a=this.statusMap.get(i.key);if(a&&a.text&&!a.isReady)Z(i.element,a.text,i.unit.styles,i.key,this.locale,this.namespace,i.unit.text,a.rowState);else if(!a||!a.text){o++;let p=i.element.getAttribute("data-lr-block");if(p&&p.startsWith("auto_")){let l=M(i.unit.text);l!==p&&r.push({stamped:p,recomputed:l,text:i.unit.text.slice(0,80)})}}}r.length>0?console.warn(`[LionRapid Editor] ${r.length} block(s) where the client-side auto_ key does NOT match the server's data-lr-block stamp \u2014 JS and server key generation are diverging for these inputs. Sample (first 5):`,r.slice(0,5)):o>0&&console.debug(`[LionRapid Editor] ${o} block(s) untranslated (no server text yet) \u2014 normal for in-progress pages.`),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 h=this.blockExtractor.extract(document.body,!0).map(f=>f.key);h.includes(e)||h.push(e);let m=await this.api.fetchStatus(h,this.locale,this.namespace);for(let[f,b]of Object.entries(m))this.statusMap.set(f,b);this.lastFetchTime=Date.now()}else{let c=await this.api.fetchStatus([e],this.locale,this.namespace);c[e]!==void 0&&this.statusMap.set(e,c[e])}let i=this.statusMap.get(e)??null;this.addField("Key",()=>{let c=document.createElement("div");return c.className="lr-field-key",c.textContent=e,c}),this.addField("Original",()=>{let c=document.createElement("div");return c.className="lr-field-original",c.innerHTML=this.renderTextWithTags(n.text),c}),this.renderLinkNav(r);let a=this.locale===this.defaultLocale,p=a||i?.isLocked||i?.isReady||!1,l=document.createElement("textarea");this.addField("Translation",()=>(l.className="lr-textarea",l.value=i?.text||t.translatedUnit?.text||"",l.placeholder=n.text,p&&(l.readOnly=!0,l.classList.add("lr-textarea-locked"),l.title=a?"Source language \u2014 switch to a target language to edit":i?.isReady?"Approved for delivery \u2014 read only":"Locked \u2014 read only"),l)),this.bodyEl.appendChild(this.statusEl);let d=document.createElement("div");this.addField("Preview",()=>(d.className="lr-preview",l.value&&(d.innerHTML=this.renderPreview(l.value,n.styles)),d)),a||this.renderWorkflowActions(e,i),p||l.addEventListener("input",()=>{let c=l.value;d.innerHTML=this.renderPreview(c,n.styles),c&&Z(r,c,n.styles,e,this.locale,this.namespace,n.text,"edited"),this.unsavedKeys.add(e),this.api.queueSave({key:e,locale:this.locale,namespace:this.namespace,text:c,styles:n.styles})}),this.renderBlocksList(),p||setTimeout(()=>l.focus(),100)}renderWorkflowActions(t,e){let n=this.userRole==="project_manager"||this.userRole==="admin",r=!!e?.isReady,o=!!e?.isLocked,i=!!e?.isConfirmed,a=e?.canEdit!==!1,p=`${this.locale}:${this.namespace}:${t}`,l=document.createElement("div");l.className="lr-workflow-actions";let d=document.createElement("div");d.className="lr-wf-strip-host",l.appendChild(d),this.renderWorkflowStrip(d,e);let c=(h,m,f="secondary")=>{let b=document.createElement("button");b.className=`lr-wf-btn lr-wf-${f}`,b.textContent=h,b.addEventListener("click",async()=>{b.disabled=!0;let E=await this.api.transitionTarget(p,m);b.disabled=!1,E&&await this.refreshStatusForKey(t)}),l.appendChild(b)};if(a&&!o&&!r&&(i?(this.workflowInfo?.workflowMode==="per_file"||c("Advance","advance","primary"),c("Unconfirm","unconfirm")):(c("Confirm","confirm","primary"),c("Reject","reject","danger"))),n&&(r?c("Unmark Ready","unmark-ready","danger"):c("Mark Ready","mark-ready","primary")),!a&&!n&&!r&&!o){let h=document.createElement("span");h.className="lr-wf-note",h.textContent=typeof e?.stageIndex=="number"&&e.stageIndex>0?`Row already advanced (stage ${e.stageIndex+1}) \u2014 out of your scope.`:"You are not assigned to this row at the current stage.",l.appendChild(h)}l.children.length>0&&this.bodyEl.appendChild(l)}renderWorkflowStrip(t,e){if(this.workflowInfo){let n=this.buildWorkflowStripNode(this.workflowInfo,e);t.replaceChildren(...n?[n]:[]);return}this.workflowInfoFetched||(this.workflowInfoFetched=!0,this.api.fetchWorkflowInfo().then(n=>{if(this.workflowInfo=n,!this.current)return;let r=this.statusMap.get(this.current.key)??e??null,o=n?this.buildWorkflowStripNode(n,r):null;t.isConnected&&t.replaceChildren(...o?[o]:[])}))}buildWorkflowStripNode(t,e){if(!t.stages||t.stages.length===0)return null;let n=null;t.isPmAdmin?n=typeof e?.stageIndex=="number"?e.stageIndex:null:t.userAssignedStages.length>0&&(n=t.userAssignedStages[0]);let r=document.createElement("div");r.className="lr-wf-strip";let o=document.createElement("div");o.className="lr-wf-strip-stages",t.stages.forEach((a,p)=>{let l=document.createElement("span");if(l.className="lr-wf-strip-stage",n!==null&&a.index===n?l.classList.add("is-active"):l.classList.add("is-muted"),l.textContent=a.name,o.appendChild(l),p<t.stages.length-1){let d=document.createElement("span");d.className="lr-wf-strip-sep",d.textContent="\u2192",o.appendChild(d)}}),r.appendChild(o);let i=document.createElement("div");if(i.className="lr-wf-strip-caption",n!==null){let p=t.stages.find(d=>d.index===n)?.name??`Stage ${n+1}`,l=t.isPmAdmin?"Row currently at":"You are here";i.textContent=`${l}: stage ${n+1} of ${t.stages.length} \u2014 ${p}`}else!t.isPmAdmin&&t.userAssignedStages.length===0?i.textContent="You have no stage assignment on this project.":i.textContent=`${t.stages.length} stages`;return r.appendChild(i),r}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()}renderLinkNav(t){let e=t.matches?.("a[href]")?t:t.querySelector?.("a[href]");if(!e)return;let n;try{n=new URL(e.href,window.location.href)}catch{return}n.origin===window.location.origin&&(n.pathname===window.location.pathname&&!n.hash||this.addField("Linked page",()=>{let r=document.createElement("button");return r.className="lr-link-nav",r.textContent="Open linked page \u2192",r.title=n.pathname+n.search,r.addEventListener("click",()=>{window.location.href=V(n.href,this.defaultLocale)}),r}))}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.canEdit===!1&&typeof e.stageIndex=="number"&&e.stageIndex>0?"readonly":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 $e.serialize(n)}return t}initResize(t){let e=0,n=0,r=i=>{let a=n+(e-i.clientX),p=Math.max(280,Math.min(600,a));this.el.style.width=`${p}px`},o=()=>{t.classList.remove("active"),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",o)};t.addEventListener("mousedown",i=>{i.preventDefault(),e=i.clientX,n=this.el.offsetWidth,t.classList.add("active"),document.addEventListener("mousemove",r),document.addEventListener("mouseup",o)})}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 o of e){let i=document.createElement("div");i.className="lr-block-item",this.current&&o.element===this.current.element&&i.classList.add("active");let p=document.createElement("span");p.className="lr-status-dot",p.classList.add(this.getDotClass(o.key)),i.appendChild(p);let l=document.createElement("div");l.className="lr-block-text";let d=o.unit.text.replace(/<\/?[0-9]+\/?>/g,""),c=document.createElement("div");c.className="lr-block-source",c.textContent=d.length>60?d.slice(0,60)+"...":d,c.title=d,l.appendChild(c);let h=this.statusMap.get(o.key);if(h&&h.text){let m=document.createElement("div");m.className="lr-block-preview";let f=h.text.replace(/<\/?[0-9]+\/?>/g,"");m.textContent=f.length>50?f.slice(0,50)+"...":f,l.appendChild(m)}i.appendChild(l),i.addEventListener("click",()=>{o.element.scrollIntoView({behavior:"smooth",block:"center"}),this.onBlockClick({key:o.key,unit:o.unit,translatedUnit:null,element:o.element})}),t.appendChild(i)}this.bodyEl.appendChild(t)}};var X=class{constructor(t,e,n){u(this,"queue",[]);u(this,"apiBase");u(this,"sessionToken");u(this,"projectId");u(this,"flushInterval",null);u(this,"renewalInterval",null);u(this,"onStatus",()=>{});u(this,"onFlushed",()=>{});u(this,"onSessionExpired",null);u(this,"workflowInfoPromise",null);u(this,"statusAbort",null);u(this,"handleVisibility",()=>{document.visibilityState==="hidden"?this.flush():document.visibilityState==="visible"&&this.maybeRenewSession()});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 this.authFetch(`${this.apiBase}/api/integrations/targets/batch`,{method:"PUT",headers:{"Content-Type":"application/json"},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 o=this.queue.indexOf(r);o>=0&&this.queue.splice(o,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),o=new URLSearchParams({locale:e,namespace:n,keys:r.join(",")});try{let i=await this.authFetch(`${this.apiBase}/api/integrations/targets/status?${o}`,{signal:this.statusAbort.signal});return i.status===401?(this.handleSessionExpired(),{}):i.ok?(await i.json()).translations:{}}catch(i){return i.name==="AbortError"?{}:{}}}get pendingCount(){return this.queue.length}async fetchWorkflowInfo(){return this.workflowInfoPromise?this.workflowInfoPromise:(this.workflowInfoPromise=(async()=>{try{let t=await this.authFetch(`${this.apiBase}/api/integrations/editor/workflow`);if(t.status===401)return this.handleSessionExpired(),null;if(!t.ok)return null;let e=await t.json();return{stages:Array.isArray(e.stages)?e.stages:[],userAssignedStages:Array.isArray(e.user_assigned_stages)?e.user_assigned_stages:[],isPmAdmin:!!e.is_pm_admin,workflowMode:e.workflow_mode==="per_file"?"per_file":"per_row"}}catch{return null}})(),this.workflowInfoPromise)}async maybeRenewSession(){let t=this.getSessionExp();!t||t*1e3-Date.now()>3e5||await this.renewSession()}async tryRenew(){let t=this.sessionToken;return await this.renewSession(),this.sessionToken!==t}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 o=JSON.parse(atob(r[1]));sessionStorage.setItem("__lr_editor_session",JSON.stringify({token:this.sessionToken,exp:o.exp||0})),document.cookie="__lr_editor_active=1; path=/; SameSite=Lax"}}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}}async authFetch(t,e={}){let n=()=>{let o=new Headers(e.headers);return o.set("Authorization",`Bearer ${this.sessionToken}`),o},r=await fetch(t,{...e,headers:n()});return r.status===401&&await this.tryRenew()&&(r=await fetch(t,{...e,headers:n()})),r}handleSessionExpired(){document.cookie="__lr_editor_active=; path=/; SameSite=Lax; Max-Age=0",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 this.authFetch(`${this.apiBase}/api/integrations/targets/${encodeURIComponent(t)}/${e}`,{method:"POST"});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]",Be=/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/gi,Ue=/(?:\+\d{1,3}[\s.-]?)?(?:\(\d{3}\)|\d{3})[\s.-]\d{3}[\s.-]\d{4}/g,ze=/\b\d{3}[\s-]\d{2}[\s-]\d{4}\b/g,He=/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g,De=/\b(?:https?:\/\/|www\.)[^\s<>"']+/gi,Fe=/\b\d(?:[ -]?\d){12,18}\b/g;function je(s){if(s.length<13||s.length>19)return!1;let t=0,e=!1;for(let n=s.length-1;n>=0;n--){let r=s.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 Ke(s){let t=s.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 We(s){if(!s)return s;let t=s;return t=t.replace(De,N),t=t.replace(Be,N),t=t.replace(Ue,N),t=t.replace(ze,N),t=t.replace(He,e=>Ke(e)?N:e),t=t.replace(Fe,e=>{let n=e.replace(/[\s-]/g,"");return je(n)?N:e}),t}var qe=new Set(["CODE","PRE","STYLE","TEXTAREA"]);function he(s){let t=document.createTreeWalker(s,NodeFilter.SHOW_TEXT),e=[],n=t.nextNode();for(;n;){if(!Ve(n)){let r=n.nodeValue||"",o=We(r);o!==r&&e.push({node:n,value:o})}n=t.nextNode()}for(let{node:r,value:o}of e)r.nodeValue=o}function Ve(s){let t=s.parentNode;for(;t&&t.nodeType===Node.ELEMENT_NODE;){let e=t;if(qe.has(e.tagName)||e.hasAttribute("data-no-redact"))return!0;t=e.parentNode}return!1}var fe="[REDACTED]";function me(){let s=document.documentElement.cloneNode(!0),t=et(s);return Je(s),Xe(s),Ye(s),Ge(s),Qe(s),Ze(s),{html:`<!DOCTYPE html>
|
|
588
|
-
`+s.outerHTML,textEntries:t,pageUrl:window.location.href,title:document.title,viewport:{width:window.innerWidth,height:window.innerHeight,devicePixelRatio:window.devicePixelRatio||1}}}function Je(s){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=s.querySelectorAll(e);for(let r=0;r<n.length;r++)n[r].remove()}}function Xe(s){let t=s.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 o=n.querySelectorAll("option");for(let i=0;i<o.length;i++)o[i].selected=!1,o[i].removeAttribute("selected")}let r=Array.from(n.attributes);for(let o of r)(o.name.startsWith("data-value")||o.name==="data-initial")&&n.removeAttribute(o.name)}}function Ye(s){let t=s.querySelectorAll("[data-pii], [data-sensitive]");for(let e=0;e<t.length;e++){let n=t[e];n.textContent=fe;let r=Array.from(n.attributes);for(let o of r)o.name!=="class"&&o.name!=="id"&&o.name!=="style"&&n.removeAttribute(o.name)}}function Ge(s){let t=document.createTreeWalker(s,NodeFilter.SHOW_ELEMENT),e=t.nextNode();for(;e;){let n=Array.from(e.attributes);for(let r of n)r.name.toLowerCase().startsWith("on")&&e.removeAttribute(r.name);e=t.nextNode()}}function Qe(s){he(s)}function Ze(s){let t=s.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=s.querySelectorAll("link[href], a[href], img[src]");for(let r=0;r<n.length;r++){let o=n[r],i=o.tagName==="IMG"?"src":"href",a=o.getAttribute(i);if(a)try{let p=new URL(a,window.location.href),l=!1;for(let d of e)p.searchParams.has(d)&&(p.searchParams.set(d,fe),l=!0);l&&o.setAttribute(i,p.toString())}catch{}}}function et(s){return new _({emails:!0,urls:!0,numbers:!0,phones:!0},[],2).extract(s).map((n,r)=>(n.element.setAttribute("data-lr-snap-idx",String(r)),{key:n.key,tagName:n.element.tagName,blockIndex:r}))}async function ge(s,t){let e=await t.getSnapshot(s);if(!e)return null;let r=new DOMParser().parseFromString(e.html,"text/html"),o=r.head.querySelectorAll('link[rel="stylesheet"], style');for(let d=0;d<o.length;d++){let c=o[d].cloneNode(!0);c.setAttribute("data-lr-snapshot-style",""),document.head.appendChild(c)}e.title&&(document.title=`[Snapshot] ${e.title}`);let i=document.getElementById("__lionrapid-editor");for(;document.body.firstChild;)if(document.body.firstChild===i){let d=document.body.firstChild.nextSibling;if(!d)break;document.body.removeChild(d)}else document.body.removeChild(document.body.firstChild);let a=document.createElement("div");a.id="__lr_snapshot_root",a.setAttribute("data-lr-snapshot-uuid",s),a.innerHTML=r.body.innerHTML,i&&i.parentNode===document.body?document.body.insertBefore(a,i):document.body.appendChild(a);let p=new Map,l=e.textEntries||[];for(let d of l)p.set(d.blockIndex,d.key);return{root:a,pageUrl:e.pageUrl,title:e.title,keyMap:p}}typeof window<"u"&&(window.__lr_dump_keys=()=>{let e=new _().extract(document.body,!0).map((n,r)=>({i:r,key:n.key,text:n.unit.text,stylesJson:JSON.stringify(n.unit.styles)}));return console.table(e),e});var Y="__lr_editor_session",be="__lr_editor_active";function ve(){document.cookie=`${be}=1; path=/; SameSite=Lax`}function xe(){document.cookie=`${be}=; path=/; SameSite=Lax; Max-Age=0`}function we(){try{let s=sessionStorage.getItem(Y);if(!s)return null;let t=JSON.parse(s);return t.exp*1e3<Date.now()+3e4?(sessionStorage.removeItem(Y),xe(),null):(ve(),t.token)}catch{return null}}function tt(s){try{let e=(s.startsWith("es_")?s.slice(3):s).split(".");if(e.length!==3)return;let n=JSON.parse(atob(e[1])),r={token:s,exp:n.exp||0};sessionStorage.setItem(Y,JSON.stringify(r)),ve()}catch{}}function nt(){sessionStorage.removeItem(Y),xe()}function rt(s){try{let e=(s.startsWith("es_")?s.slice(3):s).split(".");if(e.length!==3)return"";let n=JSON.parse(atob(e[1]));return typeof n.role=="string"?n.role:""}catch{return""}}function L(s){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=s;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 st(){let s=document.querySelector("script[data-grant]")||document.querySelector("script[data-lr-editor]");if(!s)return;let t=s.dataset.grant||"",e=we()!==null;if(!t&&!e)return;let n=s.dataset.locale||"",r=s.dataset.api||"https://api.lionrapid.com",o=s.dataset.project||"",i=0,a=100,p=setInterval(()=>{i++;let l=window.LionRapid;l?(clearInterval(p),ot(l,t,n,r,o)):i>=a&&(clearInterval(p),console.warn("[LionRapid Editor] Timed out waiting for window.LionRapid"))},100)}async function ot(s,t,e,n,r){let o=window.__lionrapidConfig,i=o?.languages||[e],a=o?.namespace||"default",p=o?.defaultLocale||"en",l=e||s.getCurrentLocale(),d=n.replace(/\/$/,""),c=we();if(!c&&t)try{let g=await fetch(`${d}/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),L("Editor session expired. Please reopen the editor from the dashboard.");return}c=(await g.json()).session_token,c&&tt(c)}catch(g){console.error("[LionRapid Editor] Grant exchange error:",g),L("Could not connect to LionRapid. Please check your connection and try again.");return}if(!c){console.error("[LionRapid Editor] No valid session. Please reopen the editor from the dashboard."),L("Editor session expired. Please reopen the editor from the dashboard.");return}let h=rt(c),m=h==="project_manager"||h==="admin",f=document.createElement("div");f.id="__lionrapid-editor",f.setAttribute("data-no-translate",""),document.body.appendChild(f);let b=f.attachShadow({mode:"closed"}),E=document.createElement("style");E.textContent=ie,b.appendChild(E);let B=document.querySelector("[data-lionrapid-switcher]");B&&(B.style.display="none");let P=new X(d,c,r);P.startAutoFlush();let te=new URL(window.location.href),U=te.searchParams.get("__lr_snapshot"),G=te.searchParams.get("__lr_recapture"),ne,re;if(U){let g=await ge(U,P);if(!g){L("Snapshot not found or expired. Please check the dashboard.");return}ne=g.root,re=g.keyMap}let se=g=>{T.open(g),z.clearHighlight()},T=new J(b,P,l,a,p,se,h),z=new j(b,se,ne,re),Q=new K(b,i,l,async g=>{if(document.querySelector('script[data-mode="dynamic-only"]')!==null){let C=new URL(window.location.href),O=C.pathname.replace(/^\/[a-z]{2}(\/|$)/,"/"),oe=g===p?"":`/${g}`;C.pathname=oe+(O==="/"&&oe?"":O),window.location.href=C.toString();return}T.updateLocale(g),T.close(),z.clearHighlight(),await s.changeLanguage(g),await T.hydrateStatus()},async()=>{await P.stopAndFlush(),z.destroy(),Q.destroy(),T.destroy(),f.remove(),nt()},U||!m?null:async()=>{try{let g=me();if(G){let k=await P.recaptureSnapshot(G,g);L(k?`Re-captured as v${k.version} (${g.textEntries.length} blocks). You can close this tab.`:"Re-capture failed. Please try again.")}else{let k=await P.createSnapshot(g);L(k?`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),L("Snapshot capture failed. See console for details.")}},G?{mode:"recapture"}:void 0,U?null:g=>{z.setActive(!g),g&&T.close()});T.setProgressCallback((g,k)=>{Q.updateProgress(g,k)}),document.addEventListener("click",g=>{if(g.defaultPrevented||g.metaKey||g.ctrlKey||g.shiftKey||g.altKey||g.button!==0)return;let k=g.target;if(!k?.closest||k.closest("#__lionrapid-editor"))return;let C=k.closest("a[href]");if(!C||C.target&&C.target!=="_self"||C.hasAttribute("download"))return;let O=V(C.href,p);O!==C.href&&(g.preventDefault(),window.location.href=O)}),T.hydrateStatus().then(()=>{Q.updateProgress(T.getTranslatedCount(),T.getTotalCount())});let R=new URL(window.location.href),H=!1;R.searchParams.has("__lr_editor")&&(R.searchParams.delete("__lr_editor"),H=!0),R.searchParams.has("__lr_snapshot")&&(R.searchParams.delete("__lr_snapshot"),H=!0),R.searchParams.has("__lr_recapture")&&(R.searchParams.delete("__lr_recapture"),H=!0),H&&history.replaceState(null,"",R.toString())}st();})();
|
|
587
|
+
`;var W=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function Ie(s){return s.replace(/"/g,""")}function j(s,t){let n=`<${s.toLowerCase()}`;for(let[r,o]of Object.entries(t))n+=` ${r.toLowerCase()}="${Ie(o)}"`;return n+=">",n}function F(s){let t=s.search(/[\s>]/);return s.slice(1,t===-1?s.length:t).toLowerCase()}function re(s){for(let t of s)if(t.startsWith("raw:"))return t.slice(4);return null}function S(s){let t={},e=0;function n(o){if(o.nodeType===Node.TEXT_NODE)return o.nodeValue??"";if(o.nodeType!==Node.ELEMENT_NODE)return"";let i=o,a=i.tagName.toLowerCase(),l={};for(let u=0;u<i.attributes.length;u++){let m=i.attributes[u];l[m.name.toLowerCase()]=m.value}e++;let c=e;if(t[String(c)]=[`raw:${j(a,l)}`],W.has(a))return`<${c}/>`;let h="";for(let u=0;u<o.childNodes.length;u++)h+=n(o.childNodes[u]);return`<${c}>${h}</${c}>`}let r="";for(let o=0;o<s.childNodes.length;o++)r+=n(s.childNodes[o]);return{text:r,styles:t}}function R(s,t){let e=(s&65535)+(t&65535);return(s>>16)+(t>>16)+(e>>16)<<16|e&65535}function Pe(s,t){return s<<t|s>>>32-t}function K(s,t,e,n,r,o){return R(Pe(R(R(t,s),R(n,o)),r),e)}function w(s,t,e,n,r,o,i){return K(t&e|~t&n,s,t,r,o,i)}function x(s,t,e,n,r,o,i){return K(t&n|e&~n,s,t,r,o,i)}function y(s,t,e,n,r,o,i){return K(t^e^n,s,t,r,o,i)}function E(s,t,e,n,r,o,i){return K(e^(t|~n),s,t,r,o,i)}function $e(s,t){s[t>>5]|=128<<t%32,s[(t+64>>>9<<4)+14]=t;let e=1732584193,n=-271733879,r=-1732584194,o=271733878;for(let i=0;i<s.length;i+=16){let a=e,l=n,c=r,h=o;e=w(e,n,r,o,s[i],7,-680876936),o=w(o,e,n,r,s[i+1],12,-389564586),r=w(r,o,e,n,s[i+2],17,606105819),n=w(n,r,o,e,s[i+3],22,-1044525330),e=w(e,n,r,o,s[i+4],7,-176418897),o=w(o,e,n,r,s[i+5],12,1200080426),r=w(r,o,e,n,s[i+6],17,-1473231341),n=w(n,r,o,e,s[i+7],22,-45705983),e=w(e,n,r,o,s[i+8],7,1770035416),o=w(o,e,n,r,s[i+9],12,-1958414417),r=w(r,o,e,n,s[i+10],17,-42063),n=w(n,r,o,e,s[i+11],22,-1990404162),e=w(e,n,r,o,s[i+12],7,1804603682),o=w(o,e,n,r,s[i+13],12,-40341101),r=w(r,o,e,n,s[i+14],17,-1502002290),n=w(n,r,o,e,s[i+15],22,1236535329),e=x(e,n,r,o,s[i+1],5,-165796510),o=x(o,e,n,r,s[i+6],9,-1069501632),r=x(r,o,e,n,s[i+11],14,643717713),n=x(n,r,o,e,s[i],20,-373897302),e=x(e,n,r,o,s[i+5],5,-701558691),o=x(o,e,n,r,s[i+10],9,38016083),r=x(r,o,e,n,s[i+15],14,-660478335),n=x(n,r,o,e,s[i+4],20,-405537848),e=x(e,n,r,o,s[i+9],5,568446438),o=x(o,e,n,r,s[i+14],9,-1019803690),r=x(r,o,e,n,s[i+3],14,-187363961),n=x(n,r,o,e,s[i+8],20,1163531501),e=x(e,n,r,o,s[i+13],5,-1444681467),o=x(o,e,n,r,s[i+2],9,-51403784),r=x(r,o,e,n,s[i+7],14,1735328473),n=x(n,r,o,e,s[i+12],20,-1926607734),e=y(e,n,r,o,s[i+5],4,-378558),o=y(o,e,n,r,s[i+8],11,-2022574463),r=y(r,o,e,n,s[i+11],16,1839030562),n=y(n,r,o,e,s[i+14],23,-35309556),e=y(e,n,r,o,s[i+1],4,-1530992060),o=y(o,e,n,r,s[i+4],11,1272893353),r=y(r,o,e,n,s[i+7],16,-155497632),n=y(n,r,o,e,s[i+10],23,-1094730640),e=y(e,n,r,o,s[i+13],4,681279174),o=y(o,e,n,r,s[i+0],11,-358537222),r=y(r,o,e,n,s[i+3],16,-722521979),n=y(n,r,o,e,s[i+6],23,76029189),e=y(e,n,r,o,s[i+9],4,-640364487),o=y(o,e,n,r,s[i+12],11,-421815835),r=y(r,o,e,n,s[i+15],16,530742520),n=y(n,r,o,e,s[i+2],23,-995338651),e=E(e,n,r,o,s[i],6,-198630844),o=E(o,e,n,r,s[i+7],10,1126891415),r=E(r,o,e,n,s[i+14],15,-1416354905),n=E(n,r,o,e,s[i+5],21,-57434055),e=E(e,n,r,o,s[i+12],6,1700485571),o=E(o,e,n,r,s[i+3],10,-1894986606),r=E(r,o,e,n,s[i+10],15,-1051523),n=E(n,r,o,e,s[i+1],21,-2054922799),e=E(e,n,r,o,s[i+8],6,1873313359),o=E(o,e,n,r,s[i+15],10,-30611744),r=E(r,o,e,n,s[i+6],15,-1560198380),n=E(n,r,o,e,s[i+13],21,1309151649),e=E(e,n,r,o,s[i+4],6,-145523070),o=E(o,e,n,r,s[i+11],10,-1120210379),r=E(r,o,e,n,s[i+2],15,718787259),n=E(n,r,o,e,s[i+9],21,-343485551),e=R(e,a),n=R(n,l),r=R(r,c),o=R(o,h)}return[e,n,r,o]}function Oe(s){let t="0123456789abcdef",e="";for(let n=0;n<s.length*4;n++)e+=t.charAt(s[n>>2]>>n%4*8+4&15)+t.charAt(s[n>>2]>>n%4*8&15);return e}function Ue(s){if(typeof TextEncoder<"u")return new TextEncoder().encode(s);let t=[];for(let e=0;e<s.length;e++){let n=s.charCodeAt(e);if(n<128)t.push(n);else if(n<2048)t.push(192|n>>6,128|n&63);else if(n>=55296&&n<56320&&e+1<s.length){let r=s.charCodeAt(++e),o=65536+(n-55296<<10)+(r-56320);t.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63)}else t.push(224|n>>12,128|n>>6&63,128|n&63)}return new Uint8Array(t)}function ze(s){let t=[];for(let e=0;e<s.length;e++)t[e>>2]|=s[e]<<e%4*8;return t}function Be(s){let t=Ue(s);return Oe($e(ze(t),t.length*8))}function _(s){let t=s.trim();return"auto_"+Be(t).substring(0,12)}var He="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption";function he(s){let t=s.closest("[data-lr-block]");if(t){let r=t.getAttribute("data-lr-block"),o=t.getAttribute("data-lr-original"),i,a=null;if(o){let l=document.createElement(t.tagName);l.innerHTML=o,i=S(l),a=S(t)}else i=S(t);return{key:r,unit:i,translatedUnit:a,element:t}}let e=s.closest(He);if(e){let r=S(e);return{key:_(r.text),unit:r,translatedUnit:null,element:e}}let n=s.textContent?.trim();return n&&n.length>=2?{key:_(n),unit:{text:n,styles:{}},translatedUnit:null,element:s}:null}var De=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),fe="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",q=class{constructor(t,e,n,r){p(this,"overlay");p(this,"currentTarget",null);p(this,"onSelect");p(this,"rafId",null);p(this,"active",!0);p(this,"rootElement");p(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")}setActive(t){this.active=t,t||this.clearHighlight()}isActive(){return this.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(fe)||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(fe)||e.closest("[data-lr-block]");if(!n||this.shouldSkip(n))return;if(t.preventDefault(),t.stopPropagation(),this.snapshotKeyMap){let o=n.getAttribute("data-lr-snap-idx");if(o!==null){let i=parseInt(o,10),a=this.snapshotKeyMap.get(i);if(a){let l=S(n);this.onSelect({key:a,unit:l,translatedUnit:null,element:n});return}}return}let r=he(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(De.has(e.tagName)||e.hasAttribute("data-no-translate")||e.getAttribute("translate")==="no")return!0;e=e.parentElement}return!1}};var V=class{constructor(t,e,n,r,o,i=null,a={},l=null){p(this,"el");p(this,"langBtnEl");p(this,"langMenuEl");p(this,"progressEl");p(this,"expanded",!1);p(this,"currentLocale");p(this,"onLanguageChange");p(this,"onExit");p(this,"onCaptureSnapshot");p(this,"onBrowseToggle");p(this,"browsing",!1);p(this,"browseBtnEl",null);p(this,"dragging",!1);p(this,"dragOffsetX",0);p(this,"dragOffsetY",0);this.onLanguageChange=r,this.onExit=o,this.onCaptureSnapshot=i,this.onBrowseToggle=l,this.currentLocale=n;let c=a.mode??"capture";this.el=document.createElement("div"),this.el.className="lr-fab";let h=document.createElement("button");h.className="lr-fab-btn",h.textContent="LR",h.addEventListener("click",f=>{this.dragging||(f.stopPropagation(),this.toggle())});let u=document.createElement("div");u.className="lr-fab-panel";let m=document.createElement("div");m.className="lr-lang-dropdown",this.langBtnEl=document.createElement("button"),this.langBtnEl.className="lr-lang-btn",this.langBtnEl.textContent=n.toUpperCase(),this.langBtnEl.addEventListener("click",f=>{f.stopPropagation(),this.langMenuEl.classList.toggle("open")}),m.appendChild(this.langBtnEl),this.langMenuEl=document.createElement("div"),this.langMenuEl.className="lr-lang-menu";for(let f of e){let b=document.createElement("button");b.className="lr-lang-item",f===n&&b.classList.add("active"),b.textContent=f.toUpperCase(),b.addEventListener("click",v=>{v.stopPropagation(),this.currentLocale=f,this.langBtnEl.textContent=f.toUpperCase(),this.langMenuEl.classList.remove("open"),this.langMenuEl.querySelectorAll(".lr-lang-item").forEach(A=>A.classList.remove("active")),b.classList.add("active"),this.onLanguageChange(f)}),this.langMenuEl.appendChild(b)}if(m.appendChild(this.langMenuEl),u.appendChild(m),this.onCaptureSnapshot){let f=document.createElement("button");f.className="lr-fab-snapshot",c==="recapture"?(f.textContent="Save re-capture",f.title="Save this page as a new version of the existing snapshot"):(f.textContent="Capture",f.title="Capture a redacted snapshot of this page for translators"),f.addEventListener("click",b=>{b.stopPropagation(),this.onCaptureSnapshot&&this.onCaptureSnapshot()}),u.appendChild(f)}if(this.onBrowseToggle){let f=document.createElement("button");f.className="lr-fab-browse",f.textContent="Browse",f.title="Pause editing so you can click links and navigate to another page",f.addEventListener("click",b=>{b.stopPropagation(),this.setBrowsing(!this.browsing)}),this.browseBtnEl=f,u.appendChild(f)}this.progressEl=document.createElement("span"),this.progressEl.className="lr-fab-progress",u.appendChild(this.progressEl);let d=document.createElement("button");d.className="lr-fab-exit",d.textContent="Exit",d.addEventListener("click",()=>this.onExit()),u.appendChild(d),this.el.appendChild(u),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),h.addEventListener("mousedown",this.handleMouseDown)}toggle(){this.expanded=!this.expanded,this.el.classList.toggle("expanded",this.expanded)}setBrowsing(t){this.browsing=t,this.browseBtnEl&&(this.browseBtnEl.textContent=t?"Editing":"Browse",this.browseBtnEl.classList.toggle("active",t),this.browseBtnEl.title=t?"Resume editing \u2014 clicks open the edit drawer again":"Pause editing so you can click links and navigate to another page"),this.el.classList.toggle("lr-fab--browsing",t),this.onBrowseToggle&&this.onBrowseToggle(t)}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)),r=window.innerWidth-e-this.el.offsetWidth;this.el.style.right=`${Math.max(0,r)}px`,this.el.style.top=`${n}px`,this.el.style.left="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 We=new Set(["a","abbr","b","bdi","bdo","br","cite","code","del","dfn","em","i","img","ins","kbd","mark","q","s","samp","small","span","strong","sub","sup","time","u","var","wbr"]),je=new Set(["alt","cite","class","datetime","dir","height","href","id","lang","loading","rel","role","src","target","title","width"]),Fe=new Set(["href","src","cite"]),Ke=new Set(["color","background-color","font-family","font-size","font-style","font-weight","letter-spacing","line-height","text-decoration","text-decoration-color","text-decoration-line","text-decoration-style","text-transform","vertical-align","white-space","word-spacing"]),qe=/url\s*\(|expression\s*\(|image-set\s*\(|element\s*\(|paint\s*\(|javascript:|\\|[<>{}@]/i,Ve=new Set(["http","https","mailto","tel"]),Xe={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:"\xA0",colon:":",semi:";",sol:"/",bsol:"\\",Tab:" ",NewLine:`
|
|
588
|
+
`};function me(s){return s.replace(/&(?:#[xX]([0-9a-fA-F]+);?|#(\d+);?|([a-zA-Z]+);)/g,(t,e,n,r)=>e?String.fromCodePoint(parseInt(e,16)):n?String.fromCodePoint(parseInt(n,10)):Xe[r]??t)}function M(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function se(s){let e=me(s).replace(/[\u0000-\u0020\u007f]/g,"").toLowerCase(),n=/^([a-z][a-z0-9+.-]*):/.exec(e);return n?Ve.has(n[1])?s:null:s}function Je(s){return be(s,!0)}function ge(s){return be(s,!1)}function be(s,t){let e=me(s),n=[];for(let r of e.split(";")){let o=r.indexOf(":");if(o===-1)continue;let i=r.slice(0,o).trim().toLowerCase(),a=r.slice(o+1).trim();/^[a-z-]+$/.test(i)&&(t&&!Ke.has(i)||a===""||qe.test(a)||n.push(`${i}: ${a}`))}return n.length>0?n.join("; "):null}var Ye=/([^\s=/>"']+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]*)))?/g;function ve(s){if(!s.startsWith("<"))return null;let t=F(s);if(!/^[a-z][a-z0-9-]*$/.test(t)||!We.has(t))return null;let e=s.endsWith("/>")?s.length-2:s.endsWith(">")?s.length-1:s.length,n=s.slice(1+t.length,e),r={};for(let o of n.matchAll(Ye)){let i=o[1].toLowerCase(),a=o[2]??o[3]??o[4]??"";if(i in r)continue;if(i==="style"){let c=Je(a);c!==null&&(r[i]=c);continue}(je.has(i)||/^data-[a-z0-9-]*$/.test(i)||/^aria-[a-z0-9-]*$/.test(i))&&(Fe.has(i)&&se(a)===null||(r[i]=a))}return j(t,r)}var $=class{serialize(t){let{text:e,styles:n}=t,r=/<(\/?)?(\d+)(\/)?>/g,o="",i=0,a;for(;(a=r.exec(e))!==null;){o+=M(e.slice(i,a.index));let[l,c,h]=a,u=n[h]??[],m=re(u),d=m===null?null:ve(m);if(m&&d!==null){let f=F(m),b=W.has(f);c?b||(o+=`</${f}>`):o+=d}else o+=l;i=a.index+l.length}return o+=M(e.slice(i)),o}};var we=new $;function oe(s,t,e,n,r,o,i,a){s.hasAttribute("data-lr-original")||s.setAttribute("data-lr-original",s.innerHTML);let c=window.LionRapid?.autoTranslator?Ge():null;if(c){let d=`${r}:${o}:${n}`;c.set(d,t,e)}let h=/<\/?[0-9]+\/?>/.test(t),u=a==="machine_translated",m=i?i.match(/^<(\d+)>([\s\S]*)<\/\1>$/):null;if(h){let d={text:t,styles:e};s.innerHTML=we.serialize(d)}else if(u&&m&&e&&Object.keys(e).length>0){let d=m[1],b={text:`<${d}>${t}</${d}>`,styles:e};s.innerHTML=we.serialize(b)}else s.textContent=t;s.setAttribute("data-lr-block",n),s.setAttribute("data-lionrapid-client","1")}function Ge(){try{let s=window.LionRapid;if(!s)return null;let t=s.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}}function xe(s,t){return s!==null&&typeof t=="number"&&t>=s.workStageCount}var J=class J{constructor(t,e,n){p(this,"queue",[]);p(this,"apiBase");p(this,"sessionToken");p(this,"projectId");p(this,"flushInterval",null);p(this,"renewalInterval",null);p(this,"onStatus",()=>{});p(this,"onFlushed",()=>{});p(this,"onSessionExpired",null);p(this,"workflowInfoCache",new Map);p(this,"canCreateMissing",!0);p(this,"targetBusy",!1);p(this,"busyRetryTimer",null);p(this,"statusAbort",null);p(this,"handleVisibility",()=>{document.visibilityState==="hidden"?this.flush():document.visibilityState==="visible"&&this.maybeRenewSession()});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 this.authFetch(`${this.apiBase}/api/integrations/targets/batch`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({translations:t.map(l=>({key:`${l.locale}:${l.namespace}:${l.key}`,value:{text:l.text,styles:l.styles}}))})});if(e.status===401){this.handleSessionExpired();return}if(!e.ok)throw new Error(`HTTP ${e.status}`);let r=(await e.json().catch(()=>null))?.denied_rows??[],o=new Set(r.filter(l=>l.reason==="busy").map(l=>l.key)),i=r.filter(l=>l.reason!=="busy"),a=[];for(let l of t){let c=this.queue.indexOf(l);if(o.has(`${l.locale}:${l.namespace}:${l.key}`)){a.push(l);continue}c>=0&&this.queue.splice(c,1)}if(this.onFlushed(t.filter(l=>!o.has(`${l.locale}:${l.namespace}:${l.key}`)).map(l=>l.key)),a.length>0&&this.scheduleBusyRetry(),i.length>0){let l=i.filter(h=>h.reason==="locked").length,c=i.length===1?l===1?"1 change not saved \u2014 row is locked (only a PM can edit it)":"1 change not saved \u2014 you are not assigned to that row":`${i.length} changes not saved \u2014 locked or not assigned to you`;this.onStatus("error",c)}else a.length>0?this.onStatus("unsaved",`${a.length} waiting \u2014 machine translation is filling this page, retrying shortly`):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}`)}}scheduleBusyRetry(){this.busyRetryTimer||(this.busyRetryTimer=setTimeout(()=>{this.busyRetryTimer=null,this.flush()},8e3))}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),o=new URLSearchParams({locale:e,namespace:n,keys:r.join(",")});try{let i=await this.authFetch(`${this.apiBase}/api/integrations/targets/status?${o}`,{signal:this.statusAbort.signal});if(i.status===401)return this.handleSessionExpired(),{};if(!i.ok)return{};let a=await i.json();return this.canCreateMissing=a.can_create!==!1,this.targetBusy=a.target_busy===!0,a.translations}catch(i){return i.name==="AbortError"?{}:{}}}get pendingCount(){return this.queue.length}async fetchWorkflowInfo(t){let e=t??"",n=this.workflowInfoCache.get(e);if(n&&Date.now()-n.fetchedAt<J.WORKFLOW_INFO_TTL_MS)return n.promise;let r=(async()=>{try{let o=`${this.apiBase}/api/integrations/editor/workflow`+(t?`?locale=${encodeURIComponent(t)}`:""),i=await this.authFetch(o);if(i.status===401)return this.handleSessionExpired(),null;if(!i.ok)return null;let a=await i.json(),l=(Array.isArray(a.stages)?a.stages:[]).map(c=>({index:c.index,name:c.name,role:c.role??null,isPostreview:!!c.is_postreview}));return{stages:l,userAssignedStages:Array.isArray(a.user_assigned_stages)?a.user_assigned_stages:[],isPmAdmin:!!a.is_pm_admin,workflowMode:a.workflow_mode==="per_file"?"per_file":"per_row",workStageCount:typeof a.work_stage_count=="number"?a.work_stage_count:l.length}}catch{return null}})();return this.workflowInfoCache.set(e,{promise:r,fetchedAt:Date.now()}),r}async maybeRenewSession(){let t=this.getSessionExp();!t||t*1e3-Date.now()>3e5||await this.renewSession()}async tryRenew(){let t=this.sessionToken;return await this.renewSession(),this.sessionToken!==t}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 o=JSON.parse(atob(r[1]));sessionStorage.setItem("__lr_editor_session",JSON.stringify({token:this.sessionToken,exp:o.exp||0})),document.cookie="__lr_editor_active=1; path=/; SameSite=Lax"}}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}}async authFetch(t,e={}){let n=()=>{let o=new Headers(e.headers);return o.set("Authorization",`Bearer ${this.sessionToken}`),o},r=await fetch(t,{...e,headers:n()});return r.status===401&&await this.tryRenew()&&(r=await fetch(t,{...e,headers:n()})),r}handleSessionExpired(){document.cookie="__lr_editor_active=; path=/; SameSite=Lax; Max-Age=0",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 this.authFetch(`${this.apiBase}/api/integrations/targets/${encodeURIComponent(t)}/${e}`,{method:"POST"});if(n.status===401)return this.handleSessionExpired(),null;if(!n.ok){let r=await n.json().catch(()=>null);return n.status===423&&r?.error?.code==="TARGET_BUSY"?this.onStatus("error","Machine translation is filling this page \u2014 try again in a few seconds."):this.onStatus("error",`${e} failed: HTTP ${n.status}`),null}return await n.json()}catch(n){return this.onStatus("error",`${e} failed: ${n.message}`),null}}};p(J,"WORKFLOW_INFO_TTL_MS",300*1e3);var X=J;var Qe={emails:!0,urls:!0,numbers:!0,phones:!0},Y={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,}$/},G=class{constructor(t={},e=2){p(this,"patterns");p(this,"minTextLength");this.patterns={...Qe,...t},this.minTextLength=e}shouldExclude(t){let e=t.trim();return!!(e.length<this.minTextLength||this.patterns.emails&&Y.email.test(e)||this.patterns.urls&&Y.url.test(e)||this.patterns.numbers&&Y.number.test(e)||this.patterns.phones&&Y.phone.test(e))}};var z="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",ie="a",Ze=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),et=["data-lionrapid-translated","data-lionrapid-client","data-no-translate","data-lr-block"],N=class{constructor(t={},e=[],n=2){p(this,"excludeFilter");p(this,"excludeSelectors");this.excludeFilter=new G(t,n),this.excludeSelectors=e}extract(t,e=!1){let n=[],r=t.querySelectorAll(z),o=[];t instanceof Element&&t.matches(z)&&o.push(t);for(let i=0;i<r.length;i++)o.push(r[i]);for(let i=0;i<o.length;i++){let a=o[i];if(this.isInsideSkipTag(a)||!e&&this.hasSkipAttribute(a)||this.matchesExcludeSelector(a)||a.getAttribute("translate")==="no"||a.querySelector(z))continue;let l=a.getAttribute("data-lr-block"),c=a.getAttribute("data-lr-original"),h;if(c){let d=document.createElement(a.tagName);d.innerHTML=c,h=S(d)}else h=S(a);let u=h.text.replace(/<\/?[0-9]+\/?>/g,"");if(this.excludeFilter.shouldExclude(u))continue;let m;if(l)m=l;else{let d=a.getAttribute("data-i18n");d?m=d.includes(":")?d:`common:${d}`:m=_(h.text)}n.push({element:a,unit:h,key:m})}return this.extractOrphanInline(t,n,e),n}extractOrphanInline(t,e,n){let r=t.querySelectorAll(ie),o=[];t instanceof Element&&t.matches(ie)&&o.push(t);for(let i=0;i<r.length;i++)o.push(r[i]);for(let i=0;i<o.length;i++){let a=o[i];if(this.isInsideSkipTag(a)||!n&&this.hasSkipAttribute(a)||this.matchesExcludeSelector(a)||a.getAttribute("translate")==="no"||a.parentElement?.closest(z)||a.parentElement?.closest(ie)||a.querySelector(z))continue;let l=a.getAttribute("data-lr-original"),c;if(l){let d=document.createElement(a.tagName);d.innerHTML=l,c=S(d)}else c=S(a);let h=c.text.replace(/<\/?[0-9]+\/?>/g,"");if(this.excludeFilter.shouldExclude(h))continue;let u=a.getAttribute("data-lr-block"),m;if(u)m=u;else{let d=a.getAttribute("data-i18n");d?m=d.includes(":")?d:`common:${d}`:m=_(c.text)}e.push({element:a,unit:c,key:m})}}isInsideSkipTag(t){let e=t.parentElement;for(;e;){if(Ze.has(e.tagName.toUpperCase()))return!0;e=e.parentElement}return!1}hasSkipAttribute(t){let e=t;for(;e;){for(let n of et)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}};function Q(s,t){let e;try{e=new URL(s,window.location.href)}catch{return s}if(e.origin!==window.location.origin)return s;let n=window.location.pathname.match(/^\/([a-z]{2})(\/|$)/),r=n?n[1]:t;return r===t||/^\/[a-z]{2}(\/|$)/.test(e.pathname)||(e.pathname="/"+r+e.pathname),e.href}var tt=new $,Z=class{constructor(t,e,n,r,o,i,a=""){p(this,"el");p(this,"bodyEl");p(this,"statusEl");p(this,"api");p(this,"locale");p(this,"namespace");p(this,"defaultLocale");p(this,"current",null);p(this,"blockExtractor");p(this,"onBlockClick");p(this,"statusMap",new Map);p(this,"unsavedKeys",new Set);p(this,"onProgressUpdate",null);p(this,"lastFetchTime",0);p(this,"lastFlushTime",0);p(this,"userRole");p(this,"workflowInfo",null);this.api=e,this.locale=n,this.namespace=r,this.defaultLocale=o,this.onBlockClick=i,this.userRole=a,this.blockExtractor=new N,this.el=document.createElement("div"),this.el.className="lr-sidebar";let l=document.createElement("div");l.className="lr-sidebar-resize",this.initResize(l),this.el.appendChild(l);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 u=document.createElement("button");u.className="lr-sidebar-close",u.innerHTML="×",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((m,d)=>{this.statusEl.textContent=d||m,this.statusEl.className=`lr-status ${m}`}),this.api.setFlushedCallback(async m=>{this.lastFlushTime=Date.now();let d=await this.api.fetchStatus(m,this.locale,this.namespace);for(let[f,b]of Object.entries(d))this.statusMap.set(f,b),this.unsavedKeys.delete(f);this.refreshBlocksList(),this.emitProgress()}),typeof window<"u"&&(window.__lr_dump_keys=()=>{let d=this.blockExtractor.extract(document.body,!0).map((f,b)=>{let v=this.statusMap.get(f.key);return{i:b,key:f.key,text:f.unit.text,stylesJson:JSON.stringify(f.unit.styles),statusText:v?.text??"",isReady:!!v?.isReady,hasTranslation:!!v?.text}});return console.table(d),d},window.__lr_editor_edit=(m,d)=>{let b=this.blockExtractor.extract(document.body,!0).find(v=>v.key===m);if(!b)throw new Error(`[__lr_editor_edit] no block on page with key ${m}`);this.unsavedKeys.add(m),this.api.queueSave({key:m,locale:this.locale,namespace:this.namespace,text:d,styles:b.unit.styles})},window.__lr_editor_flush=()=>this.api.flush()),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(i=>i.key);if(e.length===0)return;let n=await this.api.fetchStatus(e,this.locale,this.namespace);for(let[i,a]of Object.entries(n))this.statusMap.set(i,a);let r=[],o=0;for(let i of t){let a=this.statusMap.get(i.key);if(a&&a.text&&!a.isReady)oe(i.element,a.text,i.unit.styles,i.key,this.locale,this.namespace,i.unit.text,a.rowState);else if(!a||!a.text){o++;let l=i.element.getAttribute("data-lr-block");if(l&&l.startsWith("auto_")){let c=_(i.unit.text);c!==l&&r.push({stamped:l,recomputed:c,text:i.unit.text.slice(0,80)})}}}r.length>0?console.warn(`[LionRapid Editor] ${r.length} block(s) where the client-side auto_ key does NOT match the server's data-lr-block stamp \u2014 JS and server key generation are diverging for these inputs. Sample (first 5):`,r.slice(0,5)):o>0&&console.debug(`[LionRapid Editor] ${o} block(s) untranslated (no server text yet) \u2014 normal for in-progress pages.`),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 f=this.blockExtractor.extract(document.body,!0).map(v=>v.key);f.includes(e)||f.push(e);let b=await this.api.fetchStatus(f,this.locale,this.namespace);for(let[v,A]of Object.entries(b))this.statusMap.set(v,A);this.lastFetchTime=Date.now()}else{let d=await this.api.fetchStatus([e],this.locale,this.namespace);d[e]!==void 0&&this.statusMap.set(e,d[e])}let i=this.statusMap.get(e)??null;this.addField("Key",()=>{let d=document.createElement("div");return d.className="lr-field-key",d.textContent=e,d}),this.addField("Original",()=>{let d=document.createElement("div");return d.className="lr-field-original",d.innerHTML=this.renderTextWithTags(n.text),d}),this.renderLinkNav(r);let a=this.locale===this.defaultLocale,l=a||i?.isLocked||i?.isReady||!1,c=i?i.canEdit===!1:!this.api.canCreateMissing,h=l||c,u=document.createElement("textarea");this.addField("Translation",()=>(u.className="lr-textarea",u.value=i?.text||t.translatedUnit?.text||"",u.placeholder=n.text,h&&(u.readOnly=!0,u.classList.add("lr-textarea-locked"),u.title=a?"Source language \u2014 switch to a target language to edit":i?.isReady?"Approved for delivery \u2014 read only":l?"Locked \u2014 read only":i?"Assigned to another stage \u2014 read only":"Not yet translated \u2014 rows are created at the translation stage"),u)),this.bodyEl.appendChild(this.statusEl);let m=document.createElement("div");this.addField("Preview",()=>(m.className="lr-preview",u.value&&(m.innerHTML=this.renderPreview(u.value,n.styles)),m)),a||this.renderWorkflowActions(e,i),h||u.addEventListener("input",()=>{let d=u.value;m.innerHTML=this.renderPreview(d,n.styles),d&&oe(r,d,n.styles,e,this.locale,this.namespace,n.text,"edited"),this.unsavedKeys.add(e),this.api.queueSave({key:e,locale:this.locale,namespace:this.namespace,text:d,styles:n.styles})}),this.renderBlocksList(),h||setTimeout(()=>u.focus(),100)}renderWorkflowActions(t,e){let n=this.userRole==="project_manager"||this.userRole==="admin",r=!!e?.isReady,o=!!e?.isLocked,i=!!e?.isConfirmed,a=e?e.canEdit!==!1:this.api.canCreateMissing,l=`${this.locale}:${this.namespace}:${t}`,c=document.createElement("div");c.className="lr-workflow-actions";let h=document.createElement("div");h.className="lr-wf-strip-host",c.appendChild(h),this.renderWorkflowStrip(h,e);let u=(d,f,b="secondary")=>{let v=document.createElement("button");v.className=`lr-wf-btn lr-wf-${b}`,v.textContent=d,v.addEventListener("click",async()=>{v.disabled=!0;let A=await this.api.transitionTarget(l,f);v.disabled=!1,A&&await this.refreshStatusForKey(t)}),c.appendChild(v)},m=this.api.targetBusy;if(m&&a&&!o&&!r){let d=document.createElement("span");d.className="lr-wf-note",d.textContent="Machine translation is filling this page \u2014 edits save automatically; stage actions unlock in a moment.",c.appendChild(d)}if(!m&&a&&!o&&!r)if(!i)u("Confirm","confirm","primary"),e?.stageIndex!==0&&u("Reject","reject","danger");else{let d=this.workflowInfo?.workflowMode==="per_file",f=xe(this.workflowInfo,e?.stageIndex);if(!d&&!f&&u("Advance","advance","primary"),u("Unconfirm","unconfirm"),!d&&f){let b=document.createElement("span");b.className="lr-wf-note",b.textContent=this.workflowInfo&&this.workflowInfo.stages.length===0?"No translation workflow configured \u2014 set one in project settings to use stages.":"In final review \u2014 no further stages to advance.",c.appendChild(b)}}if(n&&(r?u("Unmark Ready","unmark-ready","danger"):u("Mark Ready","mark-ready","primary")),!a&&!n&&!r&&!o){let d=document.createElement("span");d.className="lr-wf-note",d.textContent=typeof e?.stageIndex=="number"&&e.stageIndex>0?`Row already advanced (stage ${e.stageIndex+1}) \u2014 out of your scope.`:"You are not assigned to this row at the current stage.",c.appendChild(d)}c.children.length>0&&this.bodyEl.appendChild(c)}renderWorkflowStrip(t,e){if(this.workflowInfo){let n=this.buildWorkflowStripNode(this.workflowInfo,e);t.replaceChildren(...n?[n]:[])}this.api.fetchWorkflowInfo(this.locale).then(n=>{if(!n||n===this.workflowInfo||(this.workflowInfo=n,!this.current))return;let r=this.statusMap.get(this.current.key)??e??null,o=this.buildWorkflowStripNode(n,r);t.isConnected&&t.replaceChildren(...o?[o]:[])})}buildWorkflowStripNode(t,e){if(!t.stages||t.stages.length===0)return null;let n=null;t.isPmAdmin?n=typeof e?.stageIndex=="number"?e.stageIndex:null:t.userAssignedStages.length>0&&(n=t.userAssignedStages[0]);let r=document.createElement("div");r.className="lr-wf-strip";let o=document.createElement("div");o.className="lr-wf-strip-stages",t.stages.forEach((a,l)=>{let c=document.createElement("span");if(c.className="lr-wf-strip-stage",n!==null&&a.index===n?c.classList.add("is-active"):c.classList.add("is-muted"),c.textContent=a.name,o.appendChild(c),l<t.stages.length-1){let h=document.createElement("span");h.className="lr-wf-strip-sep",h.textContent="\u2192",o.appendChild(h)}}),r.appendChild(o);let i=document.createElement("div");if(i.className="lr-wf-strip-caption",n!==null){let l=t.stages.find(h=>h.index===n)?.name??`Stage ${n+1}`,c=t.isPmAdmin?"Row currently at":"You are here";i.textContent=`${c}: stage ${n+1} of ${t.stages.length} \u2014 ${l}`}else!t.isPmAdmin&&t.userAssignedStages.length===0?i.textContent="You have no stage assignment on this project.":i.textContent=`${t.stages.length} stages`;return r.appendChild(i),r}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()}renderLinkNav(t){let e=t.matches?.("a[href]")?t:t.querySelector?.("a[href]");if(!e)return;let n;try{n=new URL(e.href,window.location.href)}catch{return}n.origin===window.location.origin&&(n.pathname===window.location.pathname&&!n.hash||this.addField("Linked page",()=>{let r=document.createElement("button");return r.className="lr-link-nav",r.textContent="Open linked page \u2192",r.title=n.pathname+n.search,r.addEventListener("click",()=>{window.location.href=Q(n.href,this.defaultLocale)}),r}))}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.canEdit===!1&&typeof e.stageIndex=="number"&&e.stageIndex>0?"readonly":e.isReady?"ready":e.isConfirmed?"confirmed":e.rowState==="edited"?"edited":e.rowState==="machine_translated"?"mt":"missing":this.api.canCreateMissing?"missing":"readonly"}renderTextWithTags(t){let e=/<(\/?)?(\d+)(\/)?>/g,n="",r=0,o;for(;(o=e.exec(t))!==null;)n+=M(t.slice(r,o.index)),n+=`<span class="lr-field-tag">${M(o[0])}</span>`,r=o.index+o[0].length;return n+M(t.slice(r))}renderPreview(t,e){if(!t)return"";if(Object.keys(e).length>0){let n={text:t,styles:e};return tt.serialize(n)}return M(t)}initResize(t){let e=0,n=0,r=i=>{let a=n+(e-i.clientX),l=Math.max(280,Math.min(600,a));this.el.style.width=`${l}px`},o=()=>{t.classList.remove("active"),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",o)};t.addEventListener("mousedown",i=>{i.preventDefault(),e=i.clientX,n=this.el.offsetWidth,t.classList.add("active"),document.addEventListener("mousemove",r),document.addEventListener("mouseup",o)})}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 o of e){let i=document.createElement("div");i.className="lr-block-item",this.current&&o.element===this.current.element&&i.classList.add("active");let l=document.createElement("span");l.className="lr-status-dot",l.classList.add(this.getDotClass(o.key)),i.appendChild(l);let c=document.createElement("div");c.className="lr-block-text";let h=o.unit.text.replace(/<\/?[0-9]+\/?>/g,""),u=document.createElement("div");u.className="lr-block-source",u.textContent=h.length>60?h.slice(0,60)+"...":h,u.title=h,c.appendChild(u);let m=this.statusMap.get(o.key);if(m&&m.text){let d=document.createElement("div");d.className="lr-block-preview";let f=m.text.replace(/<\/?[0-9]+\/?>/g,"");d.textContent=f.length>50?f.slice(0,50)+"...":f,c.appendChild(d)}i.appendChild(c),i.addEventListener("click",()=>{o.element.scrollIntoView({behavior:"smooth",block:"center"}),this.onBlockClick({key:o.key,unit:o.unit,translatedUnit:null,element:o.element})}),t.appendChild(i)}this.bodyEl.appendChild(t)}};var O="[REDACTED]",nt=/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/gi,rt=/(?:\+\d{1,3}[\s.-]?)?(?:\(\d{3}\)|\d{3})[\s.-]\d{3}[\s.-]\d{4}/g,st=/\b\d{3}[\s-]\d{2}[\s-]\d{4}\b/g,ot=/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g,it=/\b(?:https?:\/\/|www\.)[^\s<>"']+/gi,at=/\b\d(?:[ -]?\d){12,18}\b/g;function lt(s){if(s.length<13||s.length>19)return!1;let t=0,e=!1;for(let n=s.length-1;n>=0;n--){let r=s.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 ct(s){let t=s.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 dt(s){if(!s)return s;let t=s;return t=t.replace(it,O),t=t.replace(nt,O),t=t.replace(rt,O),t=t.replace(st,O),t=t.replace(ot,e=>ct(e)?O:e),t=t.replace(at,e=>{let n=e.replace(/[\s-]/g,"");return lt(n)?O:e}),t}var ut=new Set(["CODE","PRE","STYLE","TEXTAREA"]);function ye(s){let t=document.createTreeWalker(s,NodeFilter.SHOW_TEXT),e=[],n=t.nextNode();for(;n;){if(!pt(n)){let r=n.nodeValue||"",o=dt(r);o!==r&&e.push({node:n,value:o})}n=t.nextNode()}for(let{node:r,value:o}of e)r.nodeValue=o}function pt(s){let t=s.parentNode;for(;t&&t.nodeType===Node.ELEMENT_NODE;){let e=t;if(ut.has(e.tagName)||e.hasAttribute("data-no-redact"))return!0;t=e.parentNode}return!1}var Ee="[REDACTED]";function ke(){let s=document.documentElement.cloneNode(!0),t=wt(s);return ht(s),ft(s),mt(s),gt(s),bt(s),vt(s),{html:`<!DOCTYPE html>
|
|
589
|
+
`+s.outerHTML,textEntries:t,pageUrl:window.location.href,title:document.title,viewport:{width:window.innerWidth,height:window.innerHeight,devicePixelRatio:window.devicePixelRatio||1}}}function ht(s){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=s.querySelectorAll(e);for(let r=0;r<n.length;r++)n[r].remove()}}function ft(s){let t=s.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 o=n.querySelectorAll("option");for(let i=0;i<o.length;i++)o[i].selected=!1,o[i].removeAttribute("selected")}let r=Array.from(n.attributes);for(let o of r)(o.name.startsWith("data-value")||o.name==="data-initial")&&n.removeAttribute(o.name)}}function mt(s){let t=s.querySelectorAll("[data-pii], [data-sensitive]");for(let e=0;e<t.length;e++){let n=t[e];n.textContent=Ee;let r=Array.from(n.attributes);for(let o of r)o.name!=="class"&&o.name!=="id"&&o.name!=="style"&&n.removeAttribute(o.name)}}function gt(s){let t=document.createTreeWalker(s,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 bt(s){ye(s)}function vt(s){let t=s.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=s.querySelectorAll("link[href], a[href], img[src]");for(let r=0;r<n.length;r++){let o=n[r],i=o.tagName==="IMG"?"src":"href",a=o.getAttribute(i);if(a)try{let l=new URL(a,window.location.href),c=!1;for(let h of e)l.searchParams.has(h)&&(l.searchParams.set(h,Ee),c=!0);c&&o.setAttribute(i,l.toString())}catch{}}}function wt(s){return new N({emails:!0,urls:!0,numbers:!0,phones:!0},[],2).extract(s).map((n,r)=>(n.element.setAttribute("data-lr-snap-idx",String(r)),{key:n.key,tagName:n.element.tagName,blockIndex:r}))}var xt=new Set(["script","iframe","frame","frameset","object","embed","applet","base","meta","link","template","portal"]),yt=new Set(["href","src","action","formaction","poster","data","xlink:href"]);function Se(s){let t=[s,...Array.from(s.querySelectorAll("*"))];for(let e of t){let n=e.tagName.toLowerCase();if(xt.has(n)){e.remove();continue}for(let r of e.getAttributeNames()){let o=r.toLowerCase();if(o.startsWith("on")||o==="srcdoc"){e.removeAttribute(r);continue}if(yt.has(o)){se(e.getAttribute(r)??"")===null&&e.removeAttribute(r);continue}if(o==="style"){let i=ge(e.getAttribute(r)??"");i===null?e.removeAttribute(r):e.setAttribute(r,i)}}}}function Te(s,t){let e=s.replace(/@import[^;]*(;|$)/gi,"");return e=e.replace(/url\(\s*(['"]?)([^'")]*)\1\s*\)/gi,(n,r,o)=>{try{let i=new URL(o,t);if(i.protocol==="data:"||i.origin===new URL(t).origin)return n}catch{}return'url("")'}),e.replace(/expression\s*\(/gi,"blocked(")}async function Ce(s,t){let e=await t.getSnapshot(s);if(!e)return null;let r=new DOMParser().parseFromString(e.html,"text/html");Se(r.body);let o=r.head.querySelectorAll('link[rel="stylesheet"], style');for(let h=0;h<o.length;h++){let u=o[h];if(u.tagName.toLowerCase()==="link"){let m=u.getAttribute("href")??"",d=!1;try{d=new URL(m,window.location.href).origin===window.location.origin}catch{}if(!d)continue;let f=u.cloneNode(!0);f.setAttribute("data-lr-snapshot-style",""),document.head.appendChild(f)}else{let m=document.createElement("style");m.textContent=Te(u.textContent??"",window.location.href),m.setAttribute("data-lr-snapshot-style",""),document.head.appendChild(m)}}e.title&&(document.title=`[Snapshot] ${e.title}`);let i=document.getElementById("__lionrapid-editor");for(;document.body.firstChild;)if(document.body.firstChild===i){let h=document.body.firstChild.nextSibling;if(!h)break;document.body.removeChild(h)}else document.body.removeChild(document.body.firstChild);let a=document.createElement("div");a.id="__lr_snapshot_root",a.setAttribute("data-lr-snapshot-uuid",s),a.innerHTML=r.body.innerHTML,i&&i.parentNode===document.body?document.body.insertBefore(a,i):document.body.appendChild(a);let l=new Map,c=e.textEntries||[];for(let h of c)l.set(h.blockIndex,h.key);return{root:a,pageUrl:e.pageUrl,title:e.title,keyMap:l}}typeof window<"u"&&(window.__lr_dump_keys=()=>{let e=new N().extract(document.body,!0).map((n,r)=>({i:r,key:n.key,text:n.unit.text,stylesJson:JSON.stringify(n.unit.styles)}));return console.table(e),e});var ee="__lr_editor_session",Le="__lr_editor_active";function Ae(){document.cookie=`${Le}=1; path=/; SameSite=Lax`}function Re(){document.cookie=`${Le}=; path=/; SameSite=Lax; Max-Age=0`}function _e(){try{let s=sessionStorage.getItem(ee);if(!s)return null;let t=JSON.parse(s);return t.exp*1e3<Date.now()+3e4?(sessionStorage.removeItem(ee),Re(),null):(Ae(),t.token)}catch{return null}}function Et(s){try{let e=(s.startsWith("es_")?s.slice(3):s).split(".");if(e.length!==3)return;let n=JSON.parse(atob(e[1])),r={token:s,exp:n.exp||0};sessionStorage.setItem(ee,JSON.stringify(r)),Ae()}catch{}}function kt(){sessionStorage.removeItem(ee),Re()}function St(s){try{let e=(s.startsWith("es_")?s.slice(3):s).split(".");if(e.length!==3)return"";let n=JSON.parse(atob(e[1]));return typeof n.role=="string"?n.role:""}catch{return""}}function L(s){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=s;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 Tt(){let s=document.querySelector("script[data-grant]")||document.querySelector("script[data-lr-editor]");if(!s)return;let t=s.dataset.grant||"",e=_e()!==null;if(!t&&!e)return;let n=s.dataset.locale||"",r=s.dataset.api||"https://api.lionrapid.com",o=s.dataset.project||"",i=0,a=100,l=setInterval(()=>{i++;let c=window.LionRapid;c&&typeof c.getCurrentLocale=="function"?(clearInterval(l),Ct(c,t,n,r,o)):i>=a&&(clearInterval(l),console.warn("[LionRapid Editor] Timed out waiting for window.LionRapid"))},100)}async function Ct(s,t,e,n,r){let o=window.__lionrapidConfig,i=o?.languages||[e],a=o?.namespace||"default",l=o?.defaultLocale||"en",c=e||s.getCurrentLocale(),h=n.replace(/\/$/,""),u=_e();if(!u&&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),L("Editor session expired. Please reopen the editor from the dashboard.");return}u=(await g.json()).session_token,u&&Et(u)}catch(g){console.error("[LionRapid Editor] Grant exchange error:",g),L("Could not connect to LionRapid. Please check your connection and try again.");return}if(!u){console.error("[LionRapid Editor] No valid session. Please reopen the editor from the dashboard."),L("Editor session expired. Please reopen the editor from the dashboard.");return}let m=St(u),d=m==="project_manager"||m==="admin",f=document.createElement("div");f.id="__lionrapid-editor",f.setAttribute("data-no-translate",""),document.body.appendChild(f);let b=f.attachShadow({mode:"closed"}),v=document.createElement("style");v.textContent=pe,b.appendChild(v);let A=document.querySelector("[data-lionrapid-switcher]");A&&(A.style.display="none");let P=new X(h,u,r);P.startAutoFlush();let ae=new URL(window.location.href),B=ae.searchParams.get("__lr_snapshot"),te=ae.searchParams.get("__lr_recapture"),le,ce;if(B){let g=await Ce(B,P);if(!g){L("Snapshot not found or expired. Please check the dashboard.");return}le=g.root,ce=g.keyMap}let de=g=>{T.open(g),H.clearHighlight()},T=new Z(b,P,c,a,l,de,m),H=new q(b,de,le,ce),ne=new V(b,i,c,async g=>{if(document.querySelector('script[data-mode="dynamic-only"]')!==null){let C=new URL(window.location.href),U=C.pathname.replace(/^\/[a-z]{2}(\/|$)/,"/"),ue=g===l?"":`/${g}`;C.pathname=ue+(U==="/"&&ue?"":U),window.location.href=C.toString();return}T.updateLocale(g),T.close(),H.clearHighlight(),await s.changeLanguage(g),await T.hydrateStatus()},async()=>{await P.stopAndFlush(),H.destroy(),ne.destroy(),T.destroy(),f.remove(),kt()},B||!d?null:async()=>{try{let g=ke();if(te){let k=await P.recaptureSnapshot(te,g);L(k?`Re-captured as v${k.version} (${g.textEntries.length} blocks). You can close this tab.`:"Re-capture failed. Please try again.")}else{let k=await P.createSnapshot(g);L(k?`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),L("Snapshot capture failed. See console for details.")}},te?{mode:"recapture"}:void 0,B?null:g=>{H.setActive(!g),g&&T.close()});T.setProgressCallback((g,k)=>{ne.updateProgress(g,k)}),document.addEventListener("click",g=>{if(g.defaultPrevented||g.metaKey||g.ctrlKey||g.shiftKey||g.altKey||g.button!==0)return;let k=g.target;if(!k?.closest||k.closest("#__lionrapid-editor"))return;let C=k.closest("a[href]");if(!C||C.target&&C.target!=="_self"||C.hasAttribute("download"))return;let U=Q(C.href,l);U!==C.href&&(g.preventDefault(),window.location.href=U)}),T.hydrateStatus().then(()=>{ne.updateProgress(T.getTranslatedCount(),T.getTotalCount())});let I=new URL(window.location.href),D=!1;I.searchParams.has("__lr_editor")&&(I.searchParams.delete("__lr_editor"),D=!0),I.searchParams.has("__lr_snapshot")&&(I.searchParams.delete("__lr_snapshot"),D=!0),I.searchParams.has("__lr_recapture")&&(I.searchParams.delete("__lr_recapture"),D=!0),D&&history.replaceState(null,"",I.toString())}Tt();})();
|
|
589
590
|
//# sourceMappingURL=lionrapid.editor.min.js.map
|