@lionrapid/core 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/editor/editor-init.js +27 -0
- package/dist/browser/editor/editor-init.js.map +1 -1
- package/dist/browser/lionrapid.editor.js +38 -0
- package/dist/browser/lionrapid.editor.js.map +2 -2
- package/dist/browser/lionrapid.editor.min.js +2 -2
- package/dist/browser/lionrapid.editor.min.js.map +3 -3
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var LionRapidEditor=(()=>{var
|
|
1
|
+
"use strict";var LionRapidEditor=(()=>{var Q=Object.defineProperty;var Z=(i,t,e)=>t in i?Q(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var a=(i,t,e)=>Z(i,typeof t!="symbol"?t+"":t,e);var J=`
|
|
2
2
|
/* Reset inside shadow DOM */
|
|
3
3
|
:host {
|
|
4
4
|
all: initial;
|
|
@@ -411,5 +411,5 @@
|
|
|
411
411
|
white-space: nowrap;
|
|
412
412
|
margin-top: 2px;
|
|
413
413
|
}
|
|
414
|
-
`;var C=class{constructor(){a(this,"elementToStyles",{b:"bold",strong:"bold",i:"italic",em:"italic",u:"underline",s:"strikethrough",del:"strikethrough",strike:"strikethrough",code:"code",mark:"highlight",sub:"subscript",sup:"superscript"});a(this,"styleToElement",{bold:"b",italic:"i",underline:"u",strikethrough:"s",code:"code",highlight:"mark",subscript:"sub",superscript:"sup",strong:"b",b:"b",em:"i",i:"i",u:"u",s:"s",del:"s",strike:"s",mark:"mark",sub:"sub",sup:"sup"})}mapElementToStyles(n,e){let t=[],r=n.toLowerCase(),s=this.elementToStyles[r];return s&&t.push(s),r==="a"&&e.href&&t.push(`hyperlink:${e.href}`),t}mapStylesToElement(n){for(let e of n)if(e.startsWith("hyperlink:"))return{element:"a",attrs:{href:e.slice(10)}};for(let e of n){let t=this.styleToElement[e];if(t)return{element:t,attrs:{}}}return{element:"span",attrs:{}}}};var Z=new C;function S(i){let n={},e=0;function t(s){if(s.nodeType===Node.TEXT_NODE)return s.nodeValue??"";if(s.nodeType!==Node.ELEMENT_NODE)return"";let o=s,d=o.tagName.toLowerCase(),c={};for(let l=0;l<o.attributes.length;l++){let h=o.attributes[l];c[h.name.toLowerCase()]=h.value}let p=Z.mapElementToStyles(d,c);if(p.length>0){e++;let l=e;n[String(l)]=p;let h="";for(let m=0;m<s.childNodes.length;m++)h+=t(s.childNodes[m]);return`<${l}>${h}</${l}>`}let u="";for(let l=0;l<s.childNodes.length;l++)u+=t(s.childNodes[l]);return u}let r="";for(let s=0;s<i.childNodes.length;s++)r+=t(i.childNodes[s]);return{text:r,styles:n}}function w(i,n){let e=(i&65535)+(n&65535);return(i>>16)+(n>>16)+(e>>16)<<16|e&65535}function ee(i,n){return i<<n|i>>>32-n}function R(i,n,e,t,r,s){return w(ee(w(w(n,i),w(t,s)),r),e)}function f(i,n,e,t,r,s,o){return R(n&e|~n&t,i,n,r,s,o)}function b(i,n,e,t,r,s,o){return R(n&t|e&~t,i,n,r,s,o)}function v(i,n,e,t,r,s,o){return R(n^e^t,i,n,r,s,o)}function y(i,n,e,t,r,s,o){return R(e^(n|~t),i,n,r,s,o)}function te(i,n){i[n>>5]|=128<<n%32,i[(n+64>>>9<<4)+14]=n;let e=1732584193,t=-271733879,r=-1732584194,s=271733878;for(let o=0;o<i.length;o+=16){let d=e,c=t,p=r,u=s;e=f(e,t,r,s,i[o],7,-680876936),s=f(s,e,t,r,i[o+1],12,-389564586),r=f(r,s,e,t,i[o+2],17,606105819),t=f(t,r,s,e,i[o+3],22,-1044525330),e=f(e,t,r,s,i[o+4],7,-176418897),s=f(s,e,t,r,i[o+5],12,1200080426),r=f(r,s,e,t,i[o+6],17,-1473231341),t=f(t,r,s,e,i[o+7],22,-45705983),e=f(e,t,r,s,i[o+8],7,1770035416),s=f(s,e,t,r,i[o+9],12,-1958414417),r=f(r,s,e,t,i[o+10],17,-42063),t=f(t,r,s,e,i[o+11],22,-1990404162),e=f(e,t,r,s,i[o+12],7,1804603682),s=f(s,e,t,r,i[o+13],12,-40341101),r=f(r,s,e,t,i[o+14],17,-1502002290),t=f(t,r,s,e,i[o+15],22,1236535329),e=b(e,t,r,s,i[o+1],5,-165796510),s=b(s,e,t,r,i[o+6],9,-1069501632),r=b(r,s,e,t,i[o+11],14,643717713),t=b(t,r,s,e,i[o],20,-373897302),e=b(e,t,r,s,i[o+5],5,-701558691),s=b(s,e,t,r,i[o+10],9,38016083),r=b(r,s,e,t,i[o+15],14,-660478335),t=b(t,r,s,e,i[o+4],20,-405537848),e=b(e,t,r,s,i[o+9],5,568446438),s=b(s,e,t,r,i[o+14],9,-1019803690),r=b(r,s,e,t,i[o+3],14,-187363961),t=b(t,r,s,e,i[o+8],20,1163531501),e=b(e,t,r,s,i[o+13],5,-1444681467),s=b(s,e,t,r,i[o+2],9,-51403784),r=b(r,s,e,t,i[o+7],14,1735328473),t=b(t,r,s,e,i[o+12],20,-1926607734),e=v(e,t,r,s,i[o+5],4,-378558),s=v(s,e,t,r,i[o+8],11,-2022574463),r=v(r,s,e,t,i[o+11],16,1839030562),t=v(t,r,s,e,i[o+14],23,-35309556),e=v(e,t,r,s,i[o+1],4,-1530992060),s=v(s,e,t,r,i[o+4],11,1272893353),r=v(r,s,e,t,i[o+7],16,-155497632),t=v(t,r,s,e,i[o+10],23,-1094730640),e=v(e,t,r,s,i[o+13],4,681279174),s=v(s,e,t,r,i[o+0],11,-358537222),r=v(r,s,e,t,i[o+3],16,-722521979),t=v(t,r,s,e,i[o+6],23,76029189),e=v(e,t,r,s,i[o+9],4,-640364487),s=v(s,e,t,r,i[o+12],11,-421815835),r=v(r,s,e,t,i[o+15],16,530742520),t=v(t,r,s,e,i[o+2],23,-995338651),e=y(e,t,r,s,i[o],6,-198630844),s=y(s,e,t,r,i[o+7],10,1126891415),r=y(r,s,e,t,i[o+14],15,-1416354905),t=y(t,r,s,e,i[o+5],21,-57434055),e=y(e,t,r,s,i[o+12],6,1700485571),s=y(s,e,t,r,i[o+3],10,-1894986606),r=y(r,s,e,t,i[o+10],15,-1051523),t=y(t,r,s,e,i[o+1],21,-2054922799),e=y(e,t,r,s,i[o+8],6,1873313359),s=y(s,e,t,r,i[o+15],10,-30611744),r=y(r,s,e,t,i[o+6],15,-1560198380),t=y(t,r,s,e,i[o+13],21,1309151649),e=y(e,t,r,s,i[o+4],6,-145523070),s=y(s,e,t,r,i[o+11],10,-1120210379),r=y(r,s,e,t,i[o+2],15,718787259),t=y(t,r,s,e,i[o+9],21,-343485551),e=w(e,d),t=w(t,c),r=w(r,p),s=w(s,u)}return[e,t,r,s]}function ne(i){let n="0123456789abcdef",e="";for(let t=0;t<i.length*4;t++)e+=n.charAt(i[t>>2]>>t%4*8+4&15)+n.charAt(i[t>>2]>>t%4*8&15);return e}function se(i){let n=[];for(let e=0;e<i.length*8;e+=8)n[e>>5]|=(i.charCodeAt(e/8)&255)<<e%32;return n}function re(i){return ne(te(se(i),i.length*8))}function T(i){let n=i.trim();return"auto_"+re(n).substring(0,12)}var ie="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption";function J(i){let n=i.closest("[data-lr-block]");if(n){let r=n.getAttribute("data-lr-block"),s=n.getAttribute("data-lr-original"),o,d=null;if(s){let c=document.createElement(n.tagName);c.innerHTML=s,o=S(c),d=S(n)}else o=S(n);return{key:r,unit:o,translatedUnit:d,element:n}}let e=i.closest(ie);if(e){let r=S(e);return{key:T(r.text),unit:r,translatedUnit:null,element:e}}let t=i.textContent?.trim();return t&&t.length>=2?{key:T(t),unit:{text:t,styles:{}},translatedUnit:null,element:i}:null}var oe=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),Y="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",A=class{constructor(n,e){a(this,"overlay");a(this,"currentTarget",null);a(this,"onSelect");a(this,"rafId",null);a(this,"active",!0);this.onSelect=e,this.overlay=document.createElement("div"),this.overlay.className="lr-overlay",n.appendChild(this.overlay),this.handleMouseOver=this.handleMouseOver.bind(this),this.handleClick=this.handleClick.bind(this),this.handleScroll=this.handleScroll.bind(this),document.addEventListener("mouseover",this.handleMouseOver,!0),document.addEventListener("click",this.handleClick,!0),window.addEventListener("scroll",this.handleScroll,!0),window.addEventListener("resize",this.handleScroll)}destroy(){this.active=!1,document.removeEventListener("mouseover",this.handleMouseOver,!0),document.removeEventListener("click",this.handleClick,!0),window.removeEventListener("scroll",this.handleScroll,!0),window.removeEventListener("resize",this.handleScroll),this.rafId!==null&&cancelAnimationFrame(this.rafId),this.overlay.remove()}clearHighlight(){this.currentTarget=null,this.overlay.classList.remove("active")}handleMouseOver(n){if(!this.active)return;let e=n.target;if(!e||!e.closest||e.closest("#__lionrapid-editor"))return;if(this.shouldSkip(e)){this.clearHighlight();return}let t=e.closest(Y)||e.closest("[data-lr-block]");if(!t){this.clearHighlight();return}t!==this.currentTarget&&(this.currentTarget=t,this.positionOverlay(t))}handleClick(n){if(!this.active)return;let e=n.target;if(!e||!e.closest||e.closest("#__lionrapid-editor"))return;let t=e.closest(Y)||e.closest("[data-lr-block]");if(!t||this.shouldSkip(t))return;n.preventDefault(),n.stopPropagation();let r=J(t);r&&this.onSelect(r)}handleScroll(){this.currentTarget&&(this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.currentTarget&&this.positionOverlay(this.currentTarget)}))}positionOverlay(n){let e=n.getBoundingClientRect();this.overlay.style.top=`${e.top}px`,this.overlay.style.left=`${e.left}px`,this.overlay.style.width=`${e.width}px`,this.overlay.style.height=`${e.height}px`,this.overlay.classList.add("active")}shouldSkip(n){let e=n;for(;e;){if(oe.has(e.tagName)||e.hasAttribute("data-no-translate")||e.getAttribute("translate")==="no")return!0;e=e.parentElement}return!1}};var I=class{constructor(n,e,t,r,s){a(this,"el");a(this,"langBtnEl");a(this,"langMenuEl");a(this,"progressEl");a(this,"expanded",!1);a(this,"currentLocale");a(this,"onLanguageChange");a(this,"onExit");a(this,"dragging",!1);a(this,"dragOffsetX",0);a(this,"dragOffsetY",0);this.onLanguageChange=r,this.onExit=s,this.currentLocale=t,this.el=document.createElement("div"),this.el.className="lr-fab";let o=document.createElement("button");o.className="lr-fab-btn",o.textContent="LR",o.addEventListener("click",u=>{this.dragging||(u.stopPropagation(),this.toggle())}),this.el.appendChild(o);let d=document.createElement("div");d.className="lr-fab-panel";let c=document.createElement("div");c.className="lr-lang-dropdown",this.langBtnEl=document.createElement("button"),this.langBtnEl.className="lr-lang-btn",this.langBtnEl.textContent=t.toUpperCase(),this.langBtnEl.addEventListener("click",u=>{u.stopPropagation(),this.langMenuEl.classList.toggle("open")}),c.appendChild(this.langBtnEl),this.langMenuEl=document.createElement("div"),this.langMenuEl.className="lr-lang-menu";for(let u of e){let l=document.createElement("button");l.className="lr-lang-item",u===t&&l.classList.add("active"),l.textContent=u.toUpperCase(),l.addEventListener("click",h=>{h.stopPropagation(),this.currentLocale=u,this.langBtnEl.textContent=u.toUpperCase(),this.langMenuEl.classList.remove("open"),this.langMenuEl.querySelectorAll(".lr-lang-item").forEach(m=>m.classList.remove("active")),l.classList.add("active"),this.onLanguageChange(u)}),this.langMenuEl.appendChild(l)}c.appendChild(this.langMenuEl),d.appendChild(c),this.progressEl=document.createElement("span"),this.progressEl.className="lr-fab-progress",d.appendChild(this.progressEl);let p=document.createElement("button");p.className="lr-fab-exit",p.textContent="Exit",p.addEventListener("click",()=>this.onExit()),d.appendChild(p),this.el.appendChild(d),n.appendChild(this.el),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this),o.addEventListener("mousedown",this.handleMouseDown)}toggle(){this.expanded=!this.expanded,this.el.classList.toggle("expanded",this.expanded)}updateProgress(n,e){this.progressEl.textContent=`${n}/${e}`}getCurrentLocale(){return this.currentLocale}destroy(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),this.el.remove()}handleMouseDown(n){this.dragging=!1,this.dragOffsetX=n.clientX-this.el.getBoundingClientRect().left,this.dragOffsetY=n.clientY-this.el.getBoundingClientRect().top,document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}handleMouseMove(n){this.dragging=!0;let e=Math.max(0,Math.min(n.clientX-this.dragOffsetX,window.innerWidth-this.el.offsetWidth)),t=Math.max(0,Math.min(n.clientY-this.dragOffsetY,window.innerHeight-this.el.offsetHeight));this.el.style.left=`${e}px`,this.el.style.top=`${t}px`,this.el.style.right="auto",this.el.style.bottom="auto"}handleMouseUp(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),this.dragging&&setTimeout(()=>{this.dragging=!1},0)}};var L=class{constructor(n={}){a(this,"styleMapper");this.styleMapper=n.styleMapper??new C}serialize(n){let{text:e,styles:t}=n,r=/<(\/?)?(\d+)(\/)?>/g,s="",o=0,d;for(;(d=r.exec(e))!==null;){s+=e.slice(o,d.index);let[c,p,u,l]=d,m=t[u]||[];if(p){let g=this.styleMapper.mapStylesToElement(m);s+=`</${g.element}>`}else if(l){let g=this.styleMapper.mapStylesToElement(m),k=this.formatAttributes(g.attrs);s+=`<${g.element}${k} />`}else{let g=this.styleMapper.mapStylesToElement(m),k=this.formatAttributes(g.attrs);s+=`<${g.element}${k}>`}o=d.index+c.length}return s+=e.slice(o),s}formatAttributes(n){let e=Object.entries(n);return e.length===0?"":" "+e.map(([t,r])=>`${t}="${this.escapeAttributeValue(r)}"`).join(" ")}escapeAttributeValue(n){return n.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}};var ae=new L;function j(i,n,e,t,r,s){i.hasAttribute("data-lr-original")||i.setAttribute("data-lr-original",i.innerHTML);let d=window.LionRapid?.autoTranslator?le():null;if(d){let c=`${r}:${s}:${t}`;d.set(c,n,e)}if(e&&Object.keys(e).length>0){let c={text:n,styles:e};i.innerHTML=ae.serialize(c)}else i.textContent=n;i.setAttribute("data-lr-block",t),i.setAttribute("data-lionrapid-client","1")}function le(){try{let i=window.LionRapid;if(!i)return null;let n=i.autoTranslator;if(!n)return null;let e=n.core;if(!e)return null;let t=e.cache;return!t||typeof t.set!="function"?null:t}catch{return null}}var de={emails:!0,urls:!0,numbers:!0,phones:!0},P={email:/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,url:/^(https?:\/\/|www\.)[^\s]+$/i,number:/^[\d\s.,+-]+$/,phone:/^[+\d][\d\s().-]{6,}$/},N=class{constructor(n={},e=2){a(this,"patterns");a(this,"minTextLength");this.patterns={...de,...n},this.minTextLength=e}shouldExclude(n){let e=n.trim();return!!(e.length<this.minTextLength||this.patterns.emails&&P.email.test(e)||this.patterns.urls&&P.url.test(e)||this.patterns.numbers&&P.number.test(e)||this.patterns.phones&&P.phone.test(e))}};var D="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",ce=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),ue=["data-lionrapid-translated","data-lionrapid-client","data-no-translate"],O=class{constructor(n={},e=[],t=2){a(this,"excludeFilter");a(this,"excludeSelectors");this.excludeFilter=new N(n,t),this.excludeSelectors=e}extract(n,e=!1){let t=[],r=n.querySelectorAll(D),s=[];n instanceof Element&&n.matches(D)&&s.push(n);for(let o=0;o<r.length;o++)s.push(r[o]);for(let o=0;o<s.length;o++){let d=s[o];if(this.isInsideSkipTag(d)||!e&&this.hasSkipAttribute(d)||this.matchesExcludeSelector(d)||d.getAttribute("translate")==="no"||d.querySelector(D))continue;let c=d.getAttribute("data-lr-block"),p=d.getAttribute("data-lr-original"),u;if(p){let m=document.createElement(d.tagName);m.innerHTML=p,u=S(m)}else u=S(d);let l=u.text.replace(/<\/?[0-9]+\/?>/g,"");if(this.excludeFilter.shouldExclude(l))continue;let h;if(c)h=c;else{let m=d.getAttribute("data-i18n");m?h=m.includes(":")?m:`common:${m}`:h=T(u.text)}t.push({element:d,unit:u,key:h})}return t}isInsideSkipTag(n){let e=n.parentElement;for(;e;){if(ce.has(e.tagName))return!0;e=e.parentElement}return!1}hasSkipAttribute(n){let e=n;for(;e;){for(let t of ue)if(e.hasAttribute(t))return!0;e=e.parentElement}return!1}matchesExcludeSelector(n){for(let e of this.excludeSelectors)try{if(n.matches(e)||n.closest(e))return!0}catch{}return!1}};var pe=new L,z=class{constructor(n,e,t,r,s,o){a(this,"el");a(this,"bodyEl");a(this,"statusEl");a(this,"api");a(this,"locale");a(this,"namespace");a(this,"defaultLocale");a(this,"current",null);a(this,"blockExtractor");a(this,"onBlockClick");a(this,"statusMap",new Map);a(this,"unsavedKeys",new Set);a(this,"onProgressUpdate",null);a(this,"lastFetchTime",0);a(this,"lastFlushTime",0);this.api=e,this.locale=t,this.namespace=r,this.defaultLocale=s,this.onBlockClick=o,this.blockExtractor=new O,this.el=document.createElement("div"),this.el.className="lr-sidebar";let d=document.createElement("div");d.className="lr-sidebar-resize",this.initResize(d),this.el.appendChild(d);let c=document.createElement("div");c.className="lr-sidebar-header";let p=document.createElement("span");p.className="lr-sidebar-title",p.textContent="Edit Translation",c.appendChild(p);let u=document.createElement("button");u.className="lr-sidebar-close",u.innerHTML="×",u.addEventListener("click",()=>this.close()),c.appendChild(u),this.el.appendChild(c),this.bodyEl=document.createElement("div"),this.bodyEl.className="lr-sidebar-body",this.el.appendChild(this.bodyEl),this.statusEl=document.createElement("div"),this.statusEl.className="lr-status",this.api.setStatusCallback((l,h)=>{this.statusEl.textContent=h||l,this.statusEl.className=`lr-status ${l}`}),this.api.setFlushedCallback(async l=>{this.lastFlushTime=Date.now();let h=await this.api.fetchStatus(l,this.locale,this.namespace);for(let[m,g]of Object.entries(h))this.statusMap.set(m,g),this.unsavedKeys.delete(m);this.refreshBlocksList(),this.emitProgress()}),n.appendChild(this.el)}open(n){this.current=n,this.el.classList.add("open"),this.renderContent(n)}close(){this.current=null,this.el.classList.remove("open")}isOpen(){return this.el.classList.contains("open")}updateLocale(n){this.locale=n,this.statusMap.clear(),this.unsavedKeys.clear()}setProgressCallback(n){this.onProgressUpdate=n}async hydrateStatus(){let n=this.blockExtractor.extract(document.body,!0),e=n.map(r=>r.key);if(e.length===0)return;let t=await this.api.fetchStatus(e,this.locale,this.namespace);for(let[r,s]of Object.entries(t))this.statusMap.set(r,s);for(let r of n){let s=this.statusMap.get(r.key);s&&s.text&&!s.isReady&&j(r.element,s.text,r.unit.styles,r.key,this.locale,this.namespace)}this.emitProgress()}getTranslatedCount(){let n=0;for(let e of this.statusMap.values())e&&e.rowState!=="empty"&&n++;return n}getTotalCount(){return this.blockExtractor.extract(document.body,!0).length}emitProgress(){this.onProgressUpdate&&this.onProgressUpdate(this.getTranslatedCount(),this.getTotalCount())}destroy(){this.el.remove()}async renderContent(n){let{key:e,unit:t,element:r}=n;if(this.bodyEl.innerHTML="",this.lastFlushTime>this.lastFetchTime||this.lastFetchTime===0){let h=this.blockExtractor.extract(document.body,!0).map(g=>g.key);h.includes(e)||h.push(e);let m=await this.api.fetchStatus(h,this.locale,this.namespace);for(let[g,k]of Object.entries(m))this.statusMap.set(g,k);this.lastFetchTime=Date.now()}else{let l=await this.api.fetchStatus([e],this.locale,this.namespace);l[e]!==void 0&&this.statusMap.set(e,l[e])}let o=this.statusMap.get(e)??null;this.addField("Key",()=>{let l=document.createElement("div");return l.className="lr-field-key",l.textContent=e,l}),this.addField("Original",()=>{let l=document.createElement("div");return l.className="lr-field-original",l.innerHTML=this.renderTextWithTags(t.text),l});let d=this.locale===this.defaultLocale,c=d||o?.isLocked||o?.isReady||!1,p=document.createElement("textarea");this.addField("Translation",()=>(p.className="lr-textarea",p.value=o?.text||n.translatedUnit?.text||"",p.placeholder=t.text,c&&(p.readOnly=!0,p.classList.add("lr-textarea-locked"),p.title=d?"Source language \u2014 switch to a target language to edit":o?.isReady?"Approved for delivery \u2014 read only":"Locked \u2014 read only"),p)),this.bodyEl.appendChild(this.statusEl);let u=document.createElement("div");this.addField("Preview",()=>(u.className="lr-preview",p.value&&(u.innerHTML=this.renderPreview(p.value,t.styles)),u)),c||p.addEventListener("input",()=>{let l=p.value;u.innerHTML=this.renderPreview(l,t.styles),l&&j(r,l,t.styles,e,this.locale,this.namespace),this.unsavedKeys.add(e),this.api.queueSave({key:e,locale:this.locale,namespace:this.namespace,text:l,styles:t.styles})}),this.renderBlocksList(),c||setTimeout(()=>p.focus(),100)}addField(n,e){let t=document.createElement("div");t.className="lr-field";let r=document.createElement("span");r.className="lr-field-label",r.textContent=n,t.appendChild(r),t.appendChild(e()),this.bodyEl.appendChild(t)}getDotClass(n){if(this.unsavedKeys.has(n))return"unsaved";let e=this.statusMap.get(n);return e?e.isLocked?"locked":e.isReady?"ready":e.isConfirmed?"confirmed":e.rowState==="edited"?"edited":e.rowState==="machine_translated"?"mt":"missing":"missing"}renderTextWithTags(n){return n.replace(/<(\/?)?(\d+)(\/)?>/g,e=>`<span class="lr-field-tag">${e}</span>`)}renderPreview(n,e){if(!n)return"";if(Object.keys(e).length>0){let t={text:n,styles:e};return pe.serialize(t)}return n}initResize(n){let e=0,t=0,r=o=>{let d=t+(e-o.clientX),c=Math.max(280,Math.min(600,d));this.el.style.width=`${c}px`},s=()=>{n.classList.remove("active"),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",s)};n.addEventListener("mousedown",o=>{o.preventDefault(),e=o.clientX,t=this.el.offsetWidth,n.classList.add("active"),document.addEventListener("mousemove",r),document.addEventListener("mouseup",s)})}refreshBlocksList(){let n=this.bodyEl.querySelector(".lr-blocks-section");n&&n.remove(),this.renderBlocksList()}renderBlocksList(){let n=document.createElement("div");n.className="lr-blocks-section";let e=this.blockExtractor.extract(document.body,!0),t=this.getTranslatedCount(),r=document.createElement("div");r.className="lr-blocks-title",r.textContent=`Blocks on this page (${t}/${e.length} translated)`,n.appendChild(r);for(let s of e){let o=document.createElement("div");o.className="lr-block-item",this.current&&s.element===this.current.element&&o.classList.add("active");let c=document.createElement("span");c.className="lr-status-dot",c.classList.add(this.getDotClass(s.key)),o.appendChild(c);let p=document.createElement("div");p.className="lr-block-text";let u=s.unit.text.replace(/<\/?[0-9]+\/?>/g,""),l=document.createElement("div");l.className="lr-block-source",l.textContent=u.length>60?u.slice(0,60)+"...":u,l.title=u,p.appendChild(l);let h=this.statusMap.get(s.key);if(h&&h.text){let m=document.createElement("div");m.className="lr-block-preview";let g=h.text.replace(/<\/?[0-9]+\/?>/g,"");m.textContent=g.length>50?g.slice(0,50)+"...":g,p.appendChild(m)}o.appendChild(p),o.addEventListener("click",()=>{s.element.scrollIntoView({behavior:"smooth",block:"center"}),this.onBlockClick({key:s.key,unit:s.unit,translatedUnit:null,element:s.element})}),n.appendChild(o)}this.bodyEl.appendChild(n)}};var $=class{constructor(n,e,t){a(this,"queue",[]);a(this,"apiBase");a(this,"sessionToken");a(this,"projectId");a(this,"flushInterval",null);a(this,"renewalInterval",null);a(this,"onStatus",()=>{});a(this,"onFlushed",()=>{});a(this,"onSessionExpired",null);a(this,"statusAbort",null);a(this,"handleVisibility",()=>{document.visibilityState==="hidden"&&this.flush()});this.apiBase=n.replace(/\/$/,""),this.sessionToken=e,this.projectId=t}setStatusCallback(n){this.onStatus=n}setFlushedCallback(n){this.onFlushed=n}setSessionExpiredCallback(n){this.onSessionExpired=n}startAutoFlush(){this.flushInterval=setInterval(()=>this.flush(),3e4),document.addEventListener("visibilitychange",this.handleVisibility),this.renewalInterval=setInterval(()=>this.maybeRenewSession(),6e4)}async stopAndFlush(){this.flushInterval&&(clearInterval(this.flushInterval),this.flushInterval=null),this.renewalInterval&&(clearInterval(this.renewalInterval),this.renewalInterval=null),document.removeEventListener("visibilitychange",this.handleVisibility),await this.flush()}queueSave(n){let e=this.queue.findIndex(t=>t.key===n.key&&t.locale===n.locale&&t.namespace===n.namespace);e>=0?this.queue[e]=n:this.queue.push(n),this.onStatus("unsaved",`${this.queue.length} unsaved`),this.queue.length>50&&this.flush()}async flush(){if(this.queue.length===0)return;let n=[...this.queue];this.onStatus("saving");try{let e=await fetch(`${this.apiBase}/api/integrations/targets/batch`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`},body:JSON.stringify({translations:n.map(r=>({key:`${r.locale}:${r.namespace}:${r.key}`,value:{text:r.text,styles:r.styles}}))})});if(e.status===401){this.handleSessionExpired();return}if(!e.ok)throw new Error(`HTTP ${e.status}`);let t=n.map(r=>r.key);for(let r of n){let s=this.queue.indexOf(r);s>=0&&this.queue.splice(s,1)}this.onFlushed(t),this.queue.length===0?this.onStatus("saved","All changes saved"):this.onStatus("unsaved",`${this.queue.length} unsaved`)}catch(e){this.onStatus("error",`Save failed: ${e.message}`)}}async fetchStatus(n,e,t){if(n.length===0)return{};this.statusAbort&&this.statusAbort.abort(),this.statusAbort=new AbortController;let r=n.slice(0,200),s=new URLSearchParams({locale:e,namespace:t,keys:r.join(",")});try{let o=await fetch(`${this.apiBase}/api/integrations/targets/status?${s}`,{headers:{Authorization:`Bearer ${this.sessionToken}`},signal:this.statusAbort.signal});return o.status===401?(this.handleSessionExpired(),{}):o.ok?(await o.json()).translations:{}}catch(o){return o.name==="AbortError"?{}:{}}}get pendingCount(){return this.queue.length}async maybeRenewSession(){let n=this.getSessionExp();!n||n*1e3-Date.now()>12e4||await this.renewSession()}async renewSession(){try{let n=await fetch(`${this.apiBase}/api/editor/renew`,{method:"POST",headers:{Authorization:`Bearer ${this.sessionToken}`}});if(n.status===401){this.handleSessionExpired();return}if(!n.ok)return;let e=await n.json();this.sessionToken=e.session_token;try{let r=(this.sessionToken.startsWith("es_")?this.sessionToken.slice(3):this.sessionToken).split(".");if(r.length===3){let s=JSON.parse(atob(r[1]));sessionStorage.setItem("__lr_editor_session",JSON.stringify({token:this.sessionToken,exp:s.exp||0}))}}catch{}}catch{}}getSessionExp(){try{let e=(this.sessionToken.startsWith("es_")?this.sessionToken.slice(3):this.sessionToken).split(".");return e.length!==3?null:JSON.parse(atob(e[1])).exp||null}catch{return null}}handleSessionExpired(){this.onStatus("error","Session expired. Please reopen the editor from the dashboard."),this.onSessionExpired&&this.onSessionExpired()}};var B="__lr_editor_session";function he(){try{let i=sessionStorage.getItem(B);if(!i)return null;let n=JSON.parse(i);return n.exp*1e3<Date.now()+3e4?(sessionStorage.removeItem(B),null):n.token}catch{return null}}function me(i){try{let e=(i.startsWith("es_")?i.slice(3):i).split(".");if(e.length!==3)return;let t=JSON.parse(atob(e[1])),r={token:i,exp:t.exp||0};sessionStorage.setItem(B,JSON.stringify(r))}catch{}}function ge(){sessionStorage.removeItem(B)}function fe(){let i=document.querySelector("script[data-grant]");if(!i){console.warn("[LionRapid Editor] No script tag with data-grant found");return}let n=i.dataset.grant||"",e=i.dataset.locale||"",t=i.dataset.api||"https://api.lionrapid.com",r=i.dataset.project||"",s=0,o=100,d=setInterval(()=>{s++;let c=window.LionRapid;c?(clearInterval(d),be(c,n,e,t,r)):s>=o&&(clearInterval(d),console.warn("[LionRapid Editor] Timed out waiting for window.LionRapid"))},100)}async function be(i,n,e,t,r){let s=window.__lionrapidConfig,o=s?.languages||[e],d=s?.namespace||"default",c=s?.defaultLocale||"en",p=e||i.getCurrentLocale(),u=t.replace(/\/$/,""),l=he();if(!l&&n)try{let x=await fetch(`${u}/api/editor/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant:n,domain:window.location.host})});if(!x.ok){console.error("[LionRapid Editor] Grant exchange failed:",x.status);return}l=(await x.json()).session_token,l&&me(l)}catch(x){console.error("[LionRapid Editor] Grant exchange error:",x);return}if(!l){console.error("[LionRapid Editor] No valid session. Please reopen the editor from the dashboard.");return}let h=document.createElement("div");h.id="__lionrapid-editor",h.setAttribute("data-no-translate",""),document.body.appendChild(h);let m=h.attachShadow({mode:"closed"}),g=document.createElement("style");g.textContent=V,m.appendChild(g);let k=document.querySelector("[data-lionrapid-switcher]");k&&(k.style.display="none");let _=new $(u,l,r);_.startAutoFlush();let q=x=>{E.open(x),U.clearHighlight()},E=new z(m,_,p,d,c,q),U=new A(m,q),H=new I(m,o,p,async x=>{if(document.querySelector('script[data-mode="dynamic-only"]')!==null){let M=new URL(window.location.href),W=M.pathname.replace(/^\/[a-z]{2}(\/|$)/,"/"),X=x===c?"":`/${x}`;M.pathname=X+(W==="/"&&X?"":W),M.searchParams.set("__lr_editor",n),window.location.href=M.toString();return}E.updateLocale(x),E.close(),U.clearHighlight(),await i.changeLanguage(x),await E.hydrateStatus()},async()=>{await _.stopAndFlush(),U.destroy(),H.destroy(),E.destroy(),h.remove(),ge()});E.setProgressCallback((x,F)=>{H.updateProgress(x,F)}),E.hydrateStatus().then(()=>{H.updateProgress(E.getTranslatedCount(),E.getTotalCount())});let K=new URL(window.location.href);K.searchParams.has("__lr_editor")&&(K.searchParams.delete("__lr_editor"),history.replaceState(null,"",K.toString()))}fe();})();
|
|
414
|
+
`;var C=class{constructor(){a(this,"elementToStyles",{b:"bold",strong:"bold",i:"italic",em:"italic",u:"underline",s:"strikethrough",del:"strikethrough",strike:"strikethrough",code:"code",mark:"highlight",sub:"subscript",sup:"superscript"});a(this,"styleToElement",{bold:"b",italic:"i",underline:"u",strikethrough:"s",code:"code",highlight:"mark",subscript:"sub",superscript:"sup",strong:"b",b:"b",em:"i",i:"i",u:"u",s:"s",del:"s",strike:"s",mark:"mark",sub:"sub",sup:"sup"})}mapElementToStyles(t,e){let n=[],r=t.toLowerCase(),s=this.elementToStyles[r];return s&&n.push(s),r==="a"&&e.href&&n.push(`hyperlink:${e.href}`),n}mapStylesToElement(t){for(let e of t)if(e.startsWith("hyperlink:"))return{element:"a",attrs:{href:e.slice(10)}};for(let e of t){let n=this.styleToElement[e];if(n)return{element:n,attrs:{}}}return{element:"span",attrs:{}}}};var ee=new C;function S(i){let t={},e=0;function n(s){if(s.nodeType===Node.TEXT_NODE)return s.nodeValue??"";if(s.nodeType!==Node.ELEMENT_NODE)return"";let o=s,d=o.tagName.toLowerCase(),c={};for(let l=0;l<o.attributes.length;l++){let h=o.attributes[l];c[h.name.toLowerCase()]=h.value}let p=ee.mapElementToStyles(d,c);if(p.length>0){e++;let l=e;t[String(l)]=p;let h="";for(let m=0;m<s.childNodes.length;m++)h+=n(s.childNodes[m]);return`<${l}>${h}</${l}>`}let u="";for(let l=0;l<s.childNodes.length;l++)u+=n(s.childNodes[l]);return u}let r="";for(let s=0;s<i.childNodes.length;s++)r+=n(i.childNodes[s]);return{text:r,styles:t}}function w(i,t){let e=(i&65535)+(t&65535);return(i>>16)+(t>>16)+(e>>16)<<16|e&65535}function te(i,t){return i<<t|i>>>32-t}function R(i,t,e,n,r,s){return w(te(w(w(t,i),w(n,s)),r),e)}function f(i,t,e,n,r,s,o){return R(t&e|~t&n,i,t,r,s,o)}function b(i,t,e,n,r,s,o){return R(t&n|e&~n,i,t,r,s,o)}function v(i,t,e,n,r,s,o){return R(t^e^n,i,t,r,s,o)}function y(i,t,e,n,r,s,o){return R(e^(t|~n),i,t,r,s,o)}function ne(i,t){i[t>>5]|=128<<t%32,i[(t+64>>>9<<4)+14]=t;let e=1732584193,n=-271733879,r=-1732584194,s=271733878;for(let o=0;o<i.length;o+=16){let d=e,c=n,p=r,u=s;e=f(e,n,r,s,i[o],7,-680876936),s=f(s,e,n,r,i[o+1],12,-389564586),r=f(r,s,e,n,i[o+2],17,606105819),n=f(n,r,s,e,i[o+3],22,-1044525330),e=f(e,n,r,s,i[o+4],7,-176418897),s=f(s,e,n,r,i[o+5],12,1200080426),r=f(r,s,e,n,i[o+6],17,-1473231341),n=f(n,r,s,e,i[o+7],22,-45705983),e=f(e,n,r,s,i[o+8],7,1770035416),s=f(s,e,n,r,i[o+9],12,-1958414417),r=f(r,s,e,n,i[o+10],17,-42063),n=f(n,r,s,e,i[o+11],22,-1990404162),e=f(e,n,r,s,i[o+12],7,1804603682),s=f(s,e,n,r,i[o+13],12,-40341101),r=f(r,s,e,n,i[o+14],17,-1502002290),n=f(n,r,s,e,i[o+15],22,1236535329),e=b(e,n,r,s,i[o+1],5,-165796510),s=b(s,e,n,r,i[o+6],9,-1069501632),r=b(r,s,e,n,i[o+11],14,643717713),n=b(n,r,s,e,i[o],20,-373897302),e=b(e,n,r,s,i[o+5],5,-701558691),s=b(s,e,n,r,i[o+10],9,38016083),r=b(r,s,e,n,i[o+15],14,-660478335),n=b(n,r,s,e,i[o+4],20,-405537848),e=b(e,n,r,s,i[o+9],5,568446438),s=b(s,e,n,r,i[o+14],9,-1019803690),r=b(r,s,e,n,i[o+3],14,-187363961),n=b(n,r,s,e,i[o+8],20,1163531501),e=b(e,n,r,s,i[o+13],5,-1444681467),s=b(s,e,n,r,i[o+2],9,-51403784),r=b(r,s,e,n,i[o+7],14,1735328473),n=b(n,r,s,e,i[o+12],20,-1926607734),e=v(e,n,r,s,i[o+5],4,-378558),s=v(s,e,n,r,i[o+8],11,-2022574463),r=v(r,s,e,n,i[o+11],16,1839030562),n=v(n,r,s,e,i[o+14],23,-35309556),e=v(e,n,r,s,i[o+1],4,-1530992060),s=v(s,e,n,r,i[o+4],11,1272893353),r=v(r,s,e,n,i[o+7],16,-155497632),n=v(n,r,s,e,i[o+10],23,-1094730640),e=v(e,n,r,s,i[o+13],4,681279174),s=v(s,e,n,r,i[o+0],11,-358537222),r=v(r,s,e,n,i[o+3],16,-722521979),n=v(n,r,s,e,i[o+6],23,76029189),e=v(e,n,r,s,i[o+9],4,-640364487),s=v(s,e,n,r,i[o+12],11,-421815835),r=v(r,s,e,n,i[o+15],16,530742520),n=v(n,r,s,e,i[o+2],23,-995338651),e=y(e,n,r,s,i[o],6,-198630844),s=y(s,e,n,r,i[o+7],10,1126891415),r=y(r,s,e,n,i[o+14],15,-1416354905),n=y(n,r,s,e,i[o+5],21,-57434055),e=y(e,n,r,s,i[o+12],6,1700485571),s=y(s,e,n,r,i[o+3],10,-1894986606),r=y(r,s,e,n,i[o+10],15,-1051523),n=y(n,r,s,e,i[o+1],21,-2054922799),e=y(e,n,r,s,i[o+8],6,1873313359),s=y(s,e,n,r,i[o+15],10,-30611744),r=y(r,s,e,n,i[o+6],15,-1560198380),n=y(n,r,s,e,i[o+13],21,1309151649),e=y(e,n,r,s,i[o+4],6,-145523070),s=y(s,e,n,r,i[o+11],10,-1120210379),r=y(r,s,e,n,i[o+2],15,718787259),n=y(n,r,s,e,i[o+9],21,-343485551),e=w(e,d),n=w(n,c),r=w(r,p),s=w(s,u)}return[e,n,r,s]}function se(i){let t="0123456789abcdef",e="";for(let n=0;n<i.length*4;n++)e+=t.charAt(i[n>>2]>>n%4*8+4&15)+t.charAt(i[n>>2]>>n%4*8&15);return e}function re(i){let t=[];for(let e=0;e<i.length*8;e+=8)t[e>>5]|=(i.charCodeAt(e/8)&255)<<e%32;return t}function ie(i){return se(ne(re(i),i.length*8))}function T(i){let t=i.trim();return"auto_"+ie(t).substring(0,12)}var oe="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption";function Y(i){let t=i.closest("[data-lr-block]");if(t){let r=t.getAttribute("data-lr-block"),s=t.getAttribute("data-lr-original"),o,d=null;if(s){let c=document.createElement(t.tagName);c.innerHTML=s,o=S(c),d=S(t)}else o=S(t);return{key:r,unit:o,translatedUnit:d,element:t}}let e=i.closest(oe);if(e){let r=S(e);return{key:T(r.text),unit:r,translatedUnit:null,element:e}}let n=i.textContent?.trim();return n&&n.length>=2?{key:T(n),unit:{text:n,styles:{}},translatedUnit:null,element:i}:null}var ae=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),G="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",A=class{constructor(t,e){a(this,"overlay");a(this,"currentTarget",null);a(this,"onSelect");a(this,"rafId",null);a(this,"active",!0);this.onSelect=e,this.overlay=document.createElement("div"),this.overlay.className="lr-overlay",t.appendChild(this.overlay),this.handleMouseOver=this.handleMouseOver.bind(this),this.handleClick=this.handleClick.bind(this),this.handleScroll=this.handleScroll.bind(this),document.addEventListener("mouseover",this.handleMouseOver,!0),document.addEventListener("click",this.handleClick,!0),window.addEventListener("scroll",this.handleScroll,!0),window.addEventListener("resize",this.handleScroll)}destroy(){this.active=!1,document.removeEventListener("mouseover",this.handleMouseOver,!0),document.removeEventListener("click",this.handleClick,!0),window.removeEventListener("scroll",this.handleScroll,!0),window.removeEventListener("resize",this.handleScroll),this.rafId!==null&&cancelAnimationFrame(this.rafId),this.overlay.remove()}clearHighlight(){this.currentTarget=null,this.overlay.classList.remove("active")}handleMouseOver(t){if(!this.active)return;let e=t.target;if(!e||!e.closest||e.closest("#__lionrapid-editor"))return;if(this.shouldSkip(e)){this.clearHighlight();return}let n=e.closest(G)||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"))return;let n=e.closest(G)||e.closest("[data-lr-block]");if(!n||this.shouldSkip(n))return;t.preventDefault(),t.stopPropagation();let r=Y(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(ae.has(e.tagName)||e.hasAttribute("data-no-translate")||e.getAttribute("translate")==="no")return!0;e=e.parentElement}return!1}};var P=class{constructor(t,e,n,r,s){a(this,"el");a(this,"langBtnEl");a(this,"langMenuEl");a(this,"progressEl");a(this,"expanded",!1);a(this,"currentLocale");a(this,"onLanguageChange");a(this,"onExit");a(this,"dragging",!1);a(this,"dragOffsetX",0);a(this,"dragOffsetY",0);this.onLanguageChange=r,this.onExit=s,this.currentLocale=n,this.el=document.createElement("div"),this.el.className="lr-fab";let o=document.createElement("button");o.className="lr-fab-btn",o.textContent="LR",o.addEventListener("click",u=>{this.dragging||(u.stopPropagation(),this.toggle())}),this.el.appendChild(o);let d=document.createElement("div");d.className="lr-fab-panel";let c=document.createElement("div");c.className="lr-lang-dropdown",this.langBtnEl=document.createElement("button"),this.langBtnEl.className="lr-lang-btn",this.langBtnEl.textContent=n.toUpperCase(),this.langBtnEl.addEventListener("click",u=>{u.stopPropagation(),this.langMenuEl.classList.toggle("open")}),c.appendChild(this.langBtnEl),this.langMenuEl=document.createElement("div"),this.langMenuEl.className="lr-lang-menu";for(let u of e){let l=document.createElement("button");l.className="lr-lang-item",u===n&&l.classList.add("active"),l.textContent=u.toUpperCase(),l.addEventListener("click",h=>{h.stopPropagation(),this.currentLocale=u,this.langBtnEl.textContent=u.toUpperCase(),this.langMenuEl.classList.remove("open"),this.langMenuEl.querySelectorAll(".lr-lang-item").forEach(m=>m.classList.remove("active")),l.classList.add("active"),this.onLanguageChange(u)}),this.langMenuEl.appendChild(l)}c.appendChild(this.langMenuEl),d.appendChild(c),this.progressEl=document.createElement("span"),this.progressEl.className="lr-fab-progress",d.appendChild(this.progressEl);let p=document.createElement("button");p.className="lr-fab-exit",p.textContent="Exit",p.addEventListener("click",()=>this.onExit()),d.appendChild(p),this.el.appendChild(d),t.appendChild(this.el),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this),o.addEventListener("mousedown",this.handleMouseDown)}toggle(){this.expanded=!this.expanded,this.el.classList.toggle("expanded",this.expanded)}updateProgress(t,e){this.progressEl.textContent=`${t}/${e}`}getCurrentLocale(){return this.currentLocale}destroy(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),this.el.remove()}handleMouseDown(t){this.dragging=!1,this.dragOffsetX=t.clientX-this.el.getBoundingClientRect().left,this.dragOffsetY=t.clientY-this.el.getBoundingClientRect().top,document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}handleMouseMove(t){this.dragging=!0;let e=Math.max(0,Math.min(t.clientX-this.dragOffsetX,window.innerWidth-this.el.offsetWidth)),n=Math.max(0,Math.min(t.clientY-this.dragOffsetY,window.innerHeight-this.el.offsetHeight));this.el.style.left=`${e}px`,this.el.style.top=`${n}px`,this.el.style.right="auto",this.el.style.bottom="auto"}handleMouseUp(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),this.dragging&&setTimeout(()=>{this.dragging=!1},0)}};var L=class{constructor(t={}){a(this,"styleMapper");this.styleMapper=t.styleMapper??new C}serialize(t){let{text:e,styles:n}=t,r=/<(\/?)?(\d+)(\/)?>/g,s="",o=0,d;for(;(d=r.exec(e))!==null;){s+=e.slice(o,d.index);let[c,p,u,l]=d,m=n[u]||[];if(p){let g=this.styleMapper.mapStylesToElement(m);s+=`</${g.element}>`}else if(l){let g=this.styleMapper.mapStylesToElement(m),k=this.formatAttributes(g.attrs);s+=`<${g.element}${k} />`}else{let g=this.styleMapper.mapStylesToElement(m),k=this.formatAttributes(g.attrs);s+=`<${g.element}${k}>`}o=d.index+c.length}return s+=e.slice(o),s}formatAttributes(t){let e=Object.entries(t);return e.length===0?"":" "+e.map(([n,r])=>`${n}="${this.escapeAttributeValue(r)}"`).join(" ")}escapeAttributeValue(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}};var le=new L;function j(i,t,e,n,r,s){i.hasAttribute("data-lr-original")||i.setAttribute("data-lr-original",i.innerHTML);let d=window.LionRapid?.autoTranslator?de():null;if(d){let c=`${r}:${s}:${n}`;d.set(c,t,e)}if(e&&Object.keys(e).length>0){let c={text:t,styles:e};i.innerHTML=le.serialize(c)}else i.textContent=t;i.setAttribute("data-lr-block",n),i.setAttribute("data-lionrapid-client","1")}function de(){try{let i=window.LionRapid;if(!i)return null;let t=i.autoTranslator;if(!t)return null;let e=t.core;if(!e)return null;let n=e.cache;return!n||typeof n.set!="function"?null:n}catch{return null}}var ce={emails:!0,urls:!0,numbers:!0,phones:!0},I={email:/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,url:/^(https?:\/\/|www\.)[^\s]+$/i,number:/^[\d\s.,+-]+$/,phone:/^[+\d][\d\s().-]{6,}$/},N=class{constructor(t={},e=2){a(this,"patterns");a(this,"minTextLength");this.patterns={...ce,...t},this.minTextLength=e}shouldExclude(t){let e=t.trim();return!!(e.length<this.minTextLength||this.patterns.emails&&I.email.test(e)||this.patterns.urls&&I.url.test(e)||this.patterns.numbers&&I.number.test(e)||this.patterns.phones&&I.phone.test(e))}};var D="p,h1,h2,h3,h4,h5,h6,li,td,th,label,button,figcaption,dt,dd,summary,caption",ue=new Set(["SCRIPT","STYLE","CODE","PRE","TEXTAREA","NOSCRIPT","SVG"]),pe=["data-lionrapid-translated","data-lionrapid-client","data-no-translate"],O=class{constructor(t={},e=[],n=2){a(this,"excludeFilter");a(this,"excludeSelectors");this.excludeFilter=new N(t,n),this.excludeSelectors=e}extract(t,e=!1){let n=[],r=t.querySelectorAll(D),s=[];t instanceof Element&&t.matches(D)&&s.push(t);for(let o=0;o<r.length;o++)s.push(r[o]);for(let o=0;o<s.length;o++){let d=s[o];if(this.isInsideSkipTag(d)||!e&&this.hasSkipAttribute(d)||this.matchesExcludeSelector(d)||d.getAttribute("translate")==="no"||d.querySelector(D))continue;let c=d.getAttribute("data-lr-block"),p=d.getAttribute("data-lr-original"),u;if(p){let m=document.createElement(d.tagName);m.innerHTML=p,u=S(m)}else u=S(d);let l=u.text.replace(/<\/?[0-9]+\/?>/g,"");if(this.excludeFilter.shouldExclude(l))continue;let h;if(c)h=c;else{let m=d.getAttribute("data-i18n");m?h=m.includes(":")?m:`common:${m}`:h=T(u.text)}n.push({element:d,unit:u,key:h})}return n}isInsideSkipTag(t){let e=t.parentElement;for(;e;){if(ue.has(e.tagName))return!0;e=e.parentElement}return!1}hasSkipAttribute(t){let e=t;for(;e;){for(let n of pe)if(e.hasAttribute(n))return!0;e=e.parentElement}return!1}matchesExcludeSelector(t){for(let e of this.excludeSelectors)try{if(t.matches(e)||t.closest(e))return!0}catch{}return!1}};var he=new L,z=class{constructor(t,e,n,r,s,o){a(this,"el");a(this,"bodyEl");a(this,"statusEl");a(this,"api");a(this,"locale");a(this,"namespace");a(this,"defaultLocale");a(this,"current",null);a(this,"blockExtractor");a(this,"onBlockClick");a(this,"statusMap",new Map);a(this,"unsavedKeys",new Set);a(this,"onProgressUpdate",null);a(this,"lastFetchTime",0);a(this,"lastFlushTime",0);this.api=e,this.locale=n,this.namespace=r,this.defaultLocale=s,this.onBlockClick=o,this.blockExtractor=new O,this.el=document.createElement("div"),this.el.className="lr-sidebar";let d=document.createElement("div");d.className="lr-sidebar-resize",this.initResize(d),this.el.appendChild(d);let c=document.createElement("div");c.className="lr-sidebar-header";let p=document.createElement("span");p.className="lr-sidebar-title",p.textContent="Edit Translation",c.appendChild(p);let u=document.createElement("button");u.className="lr-sidebar-close",u.innerHTML="×",u.addEventListener("click",()=>this.close()),c.appendChild(u),this.el.appendChild(c),this.bodyEl=document.createElement("div"),this.bodyEl.className="lr-sidebar-body",this.el.appendChild(this.bodyEl),this.statusEl=document.createElement("div"),this.statusEl.className="lr-status",this.api.setStatusCallback((l,h)=>{this.statusEl.textContent=h||l,this.statusEl.className=`lr-status ${l}`}),this.api.setFlushedCallback(async l=>{this.lastFlushTime=Date.now();let h=await this.api.fetchStatus(l,this.locale,this.namespace);for(let[m,g]of Object.entries(h))this.statusMap.set(m,g),this.unsavedKeys.delete(m);this.refreshBlocksList(),this.emitProgress()}),t.appendChild(this.el)}open(t){this.current=t,this.el.classList.add("open"),this.renderContent(t)}close(){this.current=null,this.el.classList.remove("open")}isOpen(){return this.el.classList.contains("open")}updateLocale(t){this.locale=t,this.statusMap.clear(),this.unsavedKeys.clear()}setProgressCallback(t){this.onProgressUpdate=t}async hydrateStatus(){let t=this.blockExtractor.extract(document.body,!0),e=t.map(r=>r.key);if(e.length===0)return;let n=await this.api.fetchStatus(e,this.locale,this.namespace);for(let[r,s]of Object.entries(n))this.statusMap.set(r,s);for(let r of t){let s=this.statusMap.get(r.key);s&&s.text&&!s.isReady&&j(r.element,s.text,r.unit.styles,r.key,this.locale,this.namespace)}this.emitProgress()}getTranslatedCount(){let t=0;for(let e of this.statusMap.values())e&&e.rowState!=="empty"&&t++;return t}getTotalCount(){return this.blockExtractor.extract(document.body,!0).length}emitProgress(){this.onProgressUpdate&&this.onProgressUpdate(this.getTranslatedCount(),this.getTotalCount())}destroy(){this.el.remove()}async renderContent(t){let{key:e,unit:n,element:r}=t;if(this.bodyEl.innerHTML="",this.lastFlushTime>this.lastFetchTime||this.lastFetchTime===0){let h=this.blockExtractor.extract(document.body,!0).map(g=>g.key);h.includes(e)||h.push(e);let m=await this.api.fetchStatus(h,this.locale,this.namespace);for(let[g,k]of Object.entries(m))this.statusMap.set(g,k);this.lastFetchTime=Date.now()}else{let l=await this.api.fetchStatus([e],this.locale,this.namespace);l[e]!==void 0&&this.statusMap.set(e,l[e])}let o=this.statusMap.get(e)??null;this.addField("Key",()=>{let l=document.createElement("div");return l.className="lr-field-key",l.textContent=e,l}),this.addField("Original",()=>{let l=document.createElement("div");return l.className="lr-field-original",l.innerHTML=this.renderTextWithTags(n.text),l});let d=this.locale===this.defaultLocale,c=d||o?.isLocked||o?.isReady||!1,p=document.createElement("textarea");this.addField("Translation",()=>(p.className="lr-textarea",p.value=o?.text||t.translatedUnit?.text||"",p.placeholder=n.text,c&&(p.readOnly=!0,p.classList.add("lr-textarea-locked"),p.title=d?"Source language \u2014 switch to a target language to edit":o?.isReady?"Approved for delivery \u2014 read only":"Locked \u2014 read only"),p)),this.bodyEl.appendChild(this.statusEl);let u=document.createElement("div");this.addField("Preview",()=>(u.className="lr-preview",p.value&&(u.innerHTML=this.renderPreview(p.value,n.styles)),u)),c||p.addEventListener("input",()=>{let l=p.value;u.innerHTML=this.renderPreview(l,n.styles),l&&j(r,l,n.styles,e,this.locale,this.namespace),this.unsavedKeys.add(e),this.api.queueSave({key:e,locale:this.locale,namespace:this.namespace,text:l,styles:n.styles})}),this.renderBlocksList(),c||setTimeout(()=>p.focus(),100)}addField(t,e){let n=document.createElement("div");n.className="lr-field";let r=document.createElement("span");r.className="lr-field-label",r.textContent=t,n.appendChild(r),n.appendChild(e()),this.bodyEl.appendChild(n)}getDotClass(t){if(this.unsavedKeys.has(t))return"unsaved";let e=this.statusMap.get(t);return e?e.isLocked?"locked":e.isReady?"ready":e.isConfirmed?"confirmed":e.rowState==="edited"?"edited":e.rowState==="machine_translated"?"mt":"missing":"missing"}renderTextWithTags(t){return t.replace(/<(\/?)?(\d+)(\/)?>/g,e=>`<span class="lr-field-tag">${e}</span>`)}renderPreview(t,e){if(!t)return"";if(Object.keys(e).length>0){let n={text:t,styles:e};return he.serialize(n)}return t}initResize(t){let e=0,n=0,r=o=>{let d=n+(e-o.clientX),c=Math.max(280,Math.min(600,d));this.el.style.width=`${c}px`},s=()=>{t.classList.remove("active"),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",s)};t.addEventListener("mousedown",o=>{o.preventDefault(),e=o.clientX,n=this.el.offsetWidth,t.classList.add("active"),document.addEventListener("mousemove",r),document.addEventListener("mouseup",s)})}refreshBlocksList(){let t=this.bodyEl.querySelector(".lr-blocks-section");t&&t.remove(),this.renderBlocksList()}renderBlocksList(){let t=document.createElement("div");t.className="lr-blocks-section";let e=this.blockExtractor.extract(document.body,!0),n=this.getTranslatedCount(),r=document.createElement("div");r.className="lr-blocks-title",r.textContent=`Blocks on this page (${n}/${e.length} translated)`,t.appendChild(r);for(let s of e){let o=document.createElement("div");o.className="lr-block-item",this.current&&s.element===this.current.element&&o.classList.add("active");let c=document.createElement("span");c.className="lr-status-dot",c.classList.add(this.getDotClass(s.key)),o.appendChild(c);let p=document.createElement("div");p.className="lr-block-text";let u=s.unit.text.replace(/<\/?[0-9]+\/?>/g,""),l=document.createElement("div");l.className="lr-block-source",l.textContent=u.length>60?u.slice(0,60)+"...":u,l.title=u,p.appendChild(l);let h=this.statusMap.get(s.key);if(h&&h.text){let m=document.createElement("div");m.className="lr-block-preview";let g=h.text.replace(/<\/?[0-9]+\/?>/g,"");m.textContent=g.length>50?g.slice(0,50)+"...":g,p.appendChild(m)}o.appendChild(p),o.addEventListener("click",()=>{s.element.scrollIntoView({behavior:"smooth",block:"center"}),this.onBlockClick({key:s.key,unit:s.unit,translatedUnit:null,element:s.element})}),t.appendChild(o)}this.bodyEl.appendChild(t)}};var $=class{constructor(t,e,n){a(this,"queue",[]);a(this,"apiBase");a(this,"sessionToken");a(this,"projectId");a(this,"flushInterval",null);a(this,"renewalInterval",null);a(this,"onStatus",()=>{});a(this,"onFlushed",()=>{});a(this,"onSessionExpired",null);a(this,"statusAbort",null);a(this,"handleVisibility",()=>{document.visibilityState==="hidden"&&this.flush()});this.apiBase=t.replace(/\/$/,""),this.sessionToken=e,this.projectId=n}setStatusCallback(t){this.onStatus=t}setFlushedCallback(t){this.onFlushed=t}setSessionExpiredCallback(t){this.onSessionExpired=t}startAutoFlush(){this.flushInterval=setInterval(()=>this.flush(),3e4),document.addEventListener("visibilitychange",this.handleVisibility),this.renewalInterval=setInterval(()=>this.maybeRenewSession(),6e4)}async stopAndFlush(){this.flushInterval&&(clearInterval(this.flushInterval),this.flushInterval=null),this.renewalInterval&&(clearInterval(this.renewalInterval),this.renewalInterval=null),document.removeEventListener("visibilitychange",this.handleVisibility),await this.flush()}queueSave(t){let e=this.queue.findIndex(n=>n.key===t.key&&n.locale===t.locale&&n.namespace===t.namespace);e>=0?this.queue[e]=t:this.queue.push(t),this.onStatus("unsaved",`${this.queue.length} unsaved`),this.queue.length>50&&this.flush()}async flush(){if(this.queue.length===0)return;let t=[...this.queue];this.onStatus("saving");try{let e=await fetch(`${this.apiBase}/api/integrations/targets/batch`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`},body:JSON.stringify({translations:t.map(r=>({key:`${r.locale}:${r.namespace}:${r.key}`,value:{text:r.text,styles:r.styles}}))})});if(e.status===401){this.handleSessionExpired();return}if(!e.ok)throw new Error(`HTTP ${e.status}`);let n=t.map(r=>r.key);for(let r of t){let s=this.queue.indexOf(r);s>=0&&this.queue.splice(s,1)}this.onFlushed(n),this.queue.length===0?this.onStatus("saved","All changes saved"):this.onStatus("unsaved",`${this.queue.length} unsaved`)}catch(e){this.onStatus("error",`Save failed: ${e.message}`)}}async fetchStatus(t,e,n){if(t.length===0)return{};this.statusAbort&&this.statusAbort.abort(),this.statusAbort=new AbortController;let r=t.slice(0,200),s=new URLSearchParams({locale:e,namespace:n,keys:r.join(",")});try{let o=await fetch(`${this.apiBase}/api/integrations/targets/status?${s}`,{headers:{Authorization:`Bearer ${this.sessionToken}`},signal:this.statusAbort.signal});return o.status===401?(this.handleSessionExpired(),{}):o.ok?(await o.json()).translations:{}}catch(o){return o.name==="AbortError"?{}:{}}}get pendingCount(){return this.queue.length}async maybeRenewSession(){let t=this.getSessionExp();!t||t*1e3-Date.now()>12e4||await this.renewSession()}async renewSession(){try{let t=await fetch(`${this.apiBase}/api/editor/renew`,{method:"POST",headers:{Authorization:`Bearer ${this.sessionToken}`}});if(t.status===401){this.handleSessionExpired();return}if(!t.ok)return;let e=await t.json();this.sessionToken=e.session_token;try{let r=(this.sessionToken.startsWith("es_")?this.sessionToken.slice(3):this.sessionToken).split(".");if(r.length===3){let s=JSON.parse(atob(r[1]));sessionStorage.setItem("__lr_editor_session",JSON.stringify({token:this.sessionToken,exp:s.exp||0}))}}catch{}}catch{}}getSessionExp(){try{let e=(this.sessionToken.startsWith("es_")?this.sessionToken.slice(3):this.sessionToken).split(".");return e.length!==3?null:JSON.parse(atob(e[1])).exp||null}catch{return null}}handleSessionExpired(){this.onStatus("error","Session expired. Please reopen the editor from the dashboard."),this.onSessionExpired&&this.onSessionExpired()}};var B="__lr_editor_session";function me(){try{let i=sessionStorage.getItem(B);if(!i)return null;let t=JSON.parse(i);return t.exp*1e3<Date.now()+3e4?(sessionStorage.removeItem(B),null):t.token}catch{return null}}function ge(i){try{let e=(i.startsWith("es_")?i.slice(3):i).split(".");if(e.length!==3)return;let n=JSON.parse(atob(e[1])),r={token:i,exp:n.exp||0};sessionStorage.setItem(B,JSON.stringify(r))}catch{}}function fe(){sessionStorage.removeItem(B)}function q(i){let t=document.createElement("div");t.setAttribute("data-no-translate",""),Object.assign(t.style,{position:"fixed",bottom:"24px",right:"24px",zIndex:"2147483647",background:"#1a1a2e",color:"#fff",padding:"16px 20px",borderRadius:"8px",fontFamily:"system-ui, sans-serif",fontSize:"14px",maxWidth:"360px",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"}),t.textContent=i;let e=document.createElement("button");Object.assign(e.style,{position:"absolute",top:"4px",right:"8px",background:"none",border:"none",color:"#888",cursor:"pointer",fontSize:"16px"}),e.textContent="\xD7",e.addEventListener("click",()=>t.remove()),t.appendChild(e),document.body.appendChild(t),setTimeout(()=>t.remove(),8e3)}function be(){let i=document.querySelector("script[data-grant]");if(!i){console.warn("[LionRapid Editor] No script tag with data-grant found");return}let t=i.dataset.grant||"",e=i.dataset.locale||"",n=i.dataset.api||"https://api.lionrapid.com",r=i.dataset.project||"",s=0,o=100,d=setInterval(()=>{s++;let c=window.LionRapid;c?(clearInterval(d),ve(c,t,e,n,r)):s>=o&&(clearInterval(d),console.warn("[LionRapid Editor] Timed out waiting for window.LionRapid"))},100)}async function ve(i,t,e,n,r){let s=window.__lionrapidConfig,o=s?.languages||[e],d=s?.namespace||"default",c=s?.defaultLocale||"en",p=e||i.getCurrentLocale(),u=n.replace(/\/$/,""),l=me();if(!l&&t)try{let x=await fetch(`${u}/api/editor/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant:t,domain:window.location.host})});if(!x.ok){console.error("[LionRapid Editor] Grant exchange failed:",x.status),q("Editor session expired. Please reopen the editor from the dashboard.");return}l=(await x.json()).session_token,l&&ge(l)}catch(x){console.error("[LionRapid Editor] Grant exchange error:",x),q("Could not connect to LionRapid. Please check your connection and try again.");return}if(!l){console.error("[LionRapid Editor] No valid session. Please reopen the editor from the dashboard."),q("Editor session expired. Please reopen the editor from the dashboard.");return}let h=document.createElement("div");h.id="__lionrapid-editor",h.setAttribute("data-no-translate",""),document.body.appendChild(h);let m=h.attachShadow({mode:"closed"}),g=document.createElement("style");g.textContent=J,m.appendChild(g);let k=document.querySelector("[data-lionrapid-switcher]");k&&(k.style.display="none");let _=new $(u,l,r);_.startAutoFlush();let W=x=>{E.open(x),U.clearHighlight()},E=new z(m,_,p,d,c,W),U=new A(m,W),F=new P(m,o,p,async x=>{if(document.querySelector('script[data-mode="dynamic-only"]')!==null){let M=new URL(window.location.href),X=M.pathname.replace(/^\/[a-z]{2}(\/|$)/,"/"),V=x===c?"":`/${x}`;M.pathname=V+(X==="/"&&V?"":X),M.searchParams.set("__lr_editor",t),window.location.href=M.toString();return}E.updateLocale(x),E.close(),U.clearHighlight(),await i.changeLanguage(x),await E.hydrateStatus()},async()=>{await _.stopAndFlush(),U.destroy(),F.destroy(),E.destroy(),h.remove(),fe()});E.setProgressCallback((x,K)=>{F.updateProgress(x,K)}),E.hydrateStatus().then(()=>{F.updateProgress(E.getTranslatedCount(),E.getTotalCount())});let H=new URL(window.location.href);H.searchParams.has("__lr_editor")&&(H.searchParams.delete("__lr_editor"),history.replaceState(null,"",H.toString()))}be();})();
|
|
415
415
|
//# sourceMappingURL=lionrapid.editor.min.js.map
|