1((t,e)=>{"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Tranzy={})})(this,function(t){let n=["style","script","noscript","kbd","code","pre","input","textarea",'[contenteditable="true"]',".tranzy-ignore"],i={toLang:navigator.language||"",fromLang:"",ignore:[],force:[],doneClass:"tranzy-done",pendingClass:"tranzy-pending",translateFn:e,manualDict:{},beforeTranslate:null,afterTranslate:null};class s{constructor(t,e=""){this.dbName="tranzy-"+t+(e?"-"+e:""),this.storeName="translations",this.db=null,this.initPromise=this._initDatabase()}_generateHash(e){let n=2166136261;for(let t=0;t<e.length;t++)n=(n^e.charCodeAt(t))*16777619;return n.toString(36)}async _initDatabase(){return new Promise((e,n)=>{var t=indexedDB.open(this.dbName,1);t.onupgradeneeded=t=>{t=t.target.result;t.objectStoreNames.contains(this.storeName)||t.createObjectStore(this.storeName,{keyPath:"id"})},t.onsuccess=t=>{this.db=t.target.result,e()},t.onerror=t=>{this.dbName,t.target.error,n(t.target.error)}})}async get(t){await this.initPromise;let n=this._generateHash(t);return new Promise(e=>{var t;this.db?((t=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName).get(n)).onsuccess=t=>{e(t.target.result?.value||null)},t.onerror=()=>{e(null)}):e(null)})}async set(t,n){await this.initPromise;let i=this._generateHash(t);return new Promise(t=>{var e;this.db?((e=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).put({id:i,value:n})).onsuccess=()=>{t()},e.onerror=()=>{t()}):t()})}async setBatch(t,n){await this.initPromise,await Promise.all(t.map((t,e)=>this.set(t,n[e])))}destroy(){this.db&&(this.db.close(),this.db=null)}}function r(){try{sessionStorage.removeItem("tranzy_auth_token")}catch(t){}}async function l(){let n=Date.now(),{token:t,timestamp:e}=(()=>{try{var t=sessionStorage.getItem("tranzy_auth_token");if(t){var{token:e,timestamp:n}=JSON.parse(t),i=Date.now();if(e&&i-n<6e5)return{token:e,timestamp:n};r()}}catch(t){r()}return{token:null,timestamp:0}})();if(t&&n-e<6e5)return t;try{let t=await fetch("https://edge.microsoft.com/translate/auth",{method:"GET",headers:{"Content-Type":"application/json"}});if(!t.ok)return t.status,t.statusText,null;let e=await t.text();var i=e,s=n;try{sessionStorage.setItem("tranzy_auth_token",JSON.stringify({token:i,timestamp:s}))}catch(i){}return e}catch(n){throw r(),n}}async function e(t,e=navigator.language,n=""){try{var i,s,r,a,o=t.filter(t=>t?.trim());return 0===o.length?[]:(i=await l(),s=`https://api.cognitive.microsofttranslator.com/translate?${n?`from=${n}&`:""}to=${e}&api-version=3.0`,r=o.map(t=>({Text:t})),(a=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+i},body:JSON.stringify(r)})).ok?(await a.json()).map(t=>t.translations[0].text):(a.status,a.statusText,t))}catch(t){throw t}}class a{constructor(t={}){this.config={...i,...t},this.config.manualDict[this.config.toLang]={...this.config.manualDict.all||{},...this.config.manualDict[this.config.toLang]||{}};var e=this.config.manualDict[this.config.toLang];for(let t of Object.keys(e))"string"==typeof e[t]&&(e[t]={to:e[t],standalone:!0,case:!0});this.observer=null,this.translationCache=new s(this.config.toLang,this.config.fromLang),this.config.ignore=[...new Set([...n,...this.config.ignore||[]])],this.config.force=this.config.force||[],this.forceSelectorString=this.config.force.length?this.config.force.join(","):"",this.ignoreSelectorString=this.config.ignore.length?this.config.ignore.join(","):"",this.isTranslating=!1,this.pendingElements=new Set,this.observerConfig={childList:!0,subtree:!0,characterData:!0}}_createNodeFilter(){return{acceptNode:function(n){if(n.classList.contains(this.config.doneClass))return NodeFilter.FILTER_SKIP;if(!this.forceSelectorString||!n.matches(this.forceSelectorString)){if(this.forceSelectorString){let t=n.parentNode;for(;t&&t!==document;){if(t.matches(this.forceSelectorString))return NodeFilter.FILTER_ACCEPT;t=t.parentNode}}let e=!1;
1if(this.forceSelectorString&&0<n.children.length&&(e=n.querySelector(this.forceSelectorString)),this.ignoreSelectorString&&n.matches(this.ignoreSelectorString))return e?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_REJECT;if(this.ignoreSelectorString){let t=n.parentNode;for(;t&&t!==document;){if(t.matches(this.ignoreSelectorString))return e?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_REJECT;t=t.parentNode}}}return NodeFilter.FILTER_ACCEPT}.bind(this)}}startObserver(t="body"){return this.config.fromLang!==this.config.toLang&&(this.observer&&this.observer.disconnect(),this.observer=new MutationObserver(t=>{let i=!1;for(var s of t){if("childList"===s.type&&0<s.addedNodes.length)for(let e of s.addedNodes)if(e.nodeType===Node.ELEMENT_NODE){var n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,this._createNodeFilter());let t=n.nextNode();for(;t;)this.pendingElements.add(t),i=!0,t=n.nextNode()}if("characterData"===s.type){let n=s.target.parentNode;if(n&&n.nodeType===Node.ELEMENT_NODE&&!n.classList.contains(this.config.pendingClass)){let t=!1,e=n;for(;e;){if(this.ignoreSelectorString&&e.matches(this.ignoreSelectorString)&&(!this.forceSelectorString||!e.matches(this.forceSelectorString))){t=!0;break}if(!(e=e.parentNode)||e===document)break}t||(this.pendingElements.add(n),i=!0)}}}i&&this._translatePending()}),this.observer.observe(document.querySelector(t),this.observerConfig)),this}stopObserver(){return this.observer&&(this.observer.disconnect(),this.observer=null),this}async _translatePending(t=!1){0===this.pendingElements.size||this.isTranslating||(t||"function"!=typeof this.config.beforeTranslate||this.config.beforeTranslate(),this.isTranslating=!0,t=Array.from(this.pendingElements),this.pendingElements.clear(),await this._translateElements(t),this.isTranslating=!1,0<this.pendingElements.size?this._translatePending(!0):"function"==typeof this.config.afterTranslate&&this.config.afterTranslate())}async translatePage(s="body"){if(!this.isTranslating&&this.config.fromLang!==this.config.toLang){this.isTranslating=!0;let t=!!this.observer;t&&this.stopObserver(),"function"==typeof this.config.beforeTranslate&&this.config.beforeTranslate();try{let t=[],e=document.querySelector(s),n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,this._createNodeFilter()),i=n.nextNode();for(;i;)t.push(i),i=n.nextNode();await this._translateElements(t)}catch(s){}finally{"function"==typeof this.config.afterTranslate&&this.config.afterTranslate(),this.isTranslating=!1,t&&this.startObserver(s)}}return this}async _translateElements(t){var e,n=[],i=[];for(e of t){let t=this._getElementText(e);t&&(n.push(e),i.push(t))}if(0!==n.length)for(let t=0;t<n.length;t+=100){var s=n.slice(t,t+100),r=i.slice(t,t+100);await this._translateElementBatch(s,r)}}_splitByTerms(n){let i=this.config.manualDict[this.config.toLang];if(!i)return[n];let s=Object.keys(i).sort((t,e)=>e.length-t.length);for(let e of s){let t=i[e];if(!1!==t.standalone&&(!1===t.case?n.toLowerCase()===e.toLowerCase():n===e))return[n]}let e=!1;for(let t of s)if(!1===i[t].case?n.toLowerCase().includes(t.toLowerCase()):n.includes(t)){e=!0;break}if(!e)return[n];let r=[],a=n;for(;0<a.length;){let n=!1;for(let e of s){let t=i[e];if(!1===t.standalone){var o=!1===t.case?"gi":"g",o=new RegExp(`\\b${e}\\b`,o).exec(a);if(o){let t=o.index;0<t&&r.push(a.substring(0,t)),r.push(e),a=a.substring(t+e.length),n=!0;break}}}if(!n){r.push(a);break}}return r}_getDirectTextNodes(e){var n=[],i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode:t=>t.parentNode!==e?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT});let s=i.nextNode();for(;s;){let t=s.textContent,e=t.trim();e&&n.push({node:s,text:e,leadingSpaces:t.match(/^\s*/)[0],trailingSpaces:t.match(/\s*$/)[0]}),s=i.nextNode()}return n}async _translateElementBatch(c,i){let h=[],g=[];for(let n=0;n<c.length;n++){let t=c[n],e=i[n];h.push(t),g.push(e),t.classList.add(this.config.pendingClass)}if(0!==g.length){let i=new Map;for(let n=0;n<h.length;n++){let t=h[n];if(0<t.childElementCount){let e=this._getDirectTextNodes(t);if(1<e.length){i.set(t,e);for(let t of e)g.push(t.text),h.push({isTextNode:!0,nodeInfo:t});g[n]=null}}}let t=h.filter((t,e)=>null!==g[e]),n=g.filter(t=>null!==t),s=[],r=new Map;for(let t of n)if(t){let e=this._splitByTerms(t);if(1<e.length){r.set(t,e);for(let t of e)s.push(t)}else s.push(t)}let e=[...new Set(s)],a={},o=[];for(let n of e){let t=this.config.manualDict[this.config.toLang],e=t&&(t[n]||(!1===t[n.toLowerCase()]?.case?t[n.toLowerCase()]:null));if(e)a[n]=e.to;else{let t=await this.translationCache.get(n);t?a[n]=t:o.push(n)}}if(0<(o=o.filter(t=>/^(?![\d\s\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E\r\nï¼ãï¼ï¼ï¼ï¼ââââããï¼ï¼Â·ããâ¦]*$).+/.test(t))).length)try{let e=await this.config.translateFn(o,this.config.toLang,this.config.fromLang);await this.translationCache.setBatch(o,e);for(let t=0;t<o.length;t++)a[o[t]]=e[t]}catch(c){for(let t of o)a[t]=t}let l=new Map;for(let[e,n]of r.entries()){let t=n.map(t=>a[t]||t);l.set(e,t.join(""))}for(let t of n)t&&!r.has(t)&&l.set(t,a[t]||t);t.forEach((s,t)=>{let e=n[t];if(e){var r=l.get(e);if(r)if(s.isTextNode){let{node:t,leadingSpaces:e,trailingSpaces:n}=s.nodeInfo,i=(t.textContent=e+r+n,t.parentNode);i&&queueMicrotask(()=>
1{i.classList.remove(this.config.pendingClass),i.classList.add(this.config.doneClass)})}else i.has(s)||this._applyTranslation(s,e,r),queueMicrotask(()=>{s.classList.remove(this.config.pendingClass),s.classList.add(this.config.doneClass)})}})}}_getElementText(e){let n="";var i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode:t=>t.parentNode!==e?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT});let s=i.nextNode();for(;s;){let t=s.textContent.trim();t&&(n+=t+" "),s=i.nextNode()}return n=n.trim()}_applyTranslation(n,t,c){if(c&&t!==c)if(n.classList.add(this.config.doneClass),0<n.childElementCount){let l=this._getDirectTextNodes(n);if(0!==l.length)if(1===l.length){let{node:t,leadingSpaces:e,trailingSpaces:n}=l[0];void(t.textContent=e+c+n)}else{let a=l.reduce((t,e)=>t+e.text.length,0),o=0;l.forEach((t,e)=>{var{node:t,text:n,leadingSpaces:i,trailingSpaces:s}=t;let r;if(e===l.length-1)r=c.substring(o);else{let t=n.length/a,e=Math.round(c.length*t);r=c.substring(o,o+e),o+=e}t.textContent=i+r+s})}}else{let t=n.textContent.match(/^\s*/)[0],e=n.textContent.match(/\s*$/)[0];n.textContent=t+c+e}}destroy(){return this.stopObserver(),this.pendingElements.clear(),this.translationCache&&(this.translationCache.destroy(),this.translationCache=null),this.isTranslating=!1,this}}t.Translator=a,t.default=a,t.detectLang=async function(t){try{var e,n,i,s=(Array.isArray(t)?t:[t]).filter(t=>t?.trim());return 0===s.length?[]:(e=await l(),n=s.map(t=>({Text:t})),(i=await fetch("https://api.cognitive.microsofttranslator.com/detect?api-version=3.0",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+e},body:JSON.stringify(n)})).ok?await i.json():(i.status,i.statusText,[]))}catch(t){throw t}},t.getBrowserLang=async function(){try{var t=navigator.language,e=await l(),n=await fetch(`https://api.cognitive.microsofttranslator.com/translate?to=${t}&api-version=3.0`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+e},body:JSON.stringify([{Text:""}])});return n.ok?(await n.json())[0].translations[0].to:(n.status,n.statusText,navigator.language||"en")}catch(t){throw t}},t.getSupportedLangs=async function(t=""){try{var e={"Content-Type":"application/json"},n=(t&&(e["Accept-Language"]=t),await fetch("https://api.cognitive.microsofttranslator.com/languages?api-version=3.0",{method:"GET",headers:e}));return n.ok?(await n.json()).translation:(n.status,n.statusText,{})}catch(t){throw t}},t.translateText=e,Object.defineProperty(t,"__esModule",{value:!0})});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.