@lizardbyte/shared-web 2026.811.210538 → 2026.812.190302
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/crowdin.js +1 -1
- package/dist/crowdin.js.map +1 -1
- package/package.json +3 -3
- package/src/js/crowdin.js +50 -13
- package/tests/crowdin.test.js +21 -0
package/dist/crowdin.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var e={714(e,t,n){const i=n(836),o=["a","abbr","b","cite","code","del","em","i","ins","kbd","mark","q","s","samp","small","span","strong","sub","sup","time","u","var"].join(",");function s(e){const t=new globalThis.MutationObserver(n);function n(){t.disconnect(),function(e){e.forEach(e=>{const t=function(e){if(e.node.isConnected)return e.node;const t=e.previousInline?.nextSibling;if(t instanceof globalThis.Text&&t.isConnected)return e.node=t,e.node;const n=e.nextInline?.previousSibling;if(n instanceof globalThis.Text&&n.isConnected)return e.node=n,e.node;if(!e.whitespaceOnly)return null;const i=document.createTextNode("");if(e.previousInline?.isConnected)e.previousInline.after(i);else{if(!e.nextInline?.isConnected)return null;e.nextInline.before(i)}return e.node=i,e.node}(e);null
|
|
1
|
+
(()=>{var e={714(e,t,n){const i=n(836),o=["a","abbr","b","cite","code","del","em","i","ins","kbd","mark","q","s","samp","small","span","strong","sub","sup","time","u","var"].join(",");function s(e){return e instanceof globalThis.Element&&e.matches(o)?e:null}function r(e){const t=e.trimStart();return e.slice(0,e.length-t.length)}function l(e){const t=e.trimEnd();return e.slice(t.length)}function a(e){const t=new globalThis.MutationObserver(n);function n(){t.disconnect(),function(e){e.forEach(e=>{const t=function(e){if(e.node.isConnected)return e.node;const t=e.previousInline?.nextSibling;if(t instanceof globalThis.Text&&t.isConnected)return e.node=t,e.node;const n=e.nextInline?.previousSibling;if(n instanceof globalThis.Text&&n.isConnected)return e.node=n,e.node;if(!e.whitespaceOnly)return null;const i=document.createTextNode("");if(e.previousInline?.isConnected)e.previousInline.after(i);else{if(!e.nextInline?.isConnected)return null;e.nextInline.before(i)}return e.node=i,e.node}(e);if(null===t)return;const n=r(t.data);e.leading&&n!==e.leadingWhitespace&&(t.data=e.leadingWhitespace+t.data.slice(n.length));const i=l(t.data);if(e.trailing&&i!==e.trailingWhitespace){const n=t.data.length-i.length;t.data=t.data.slice(0,n)+e.trailingWhitespace}})}(e),t.observe(document.body,{characterData:!0,childList:!0,subtree:!0})}return n}function c(e,t){t>=100||globalThis.setTimeout(function(){d(e,t+1)},50)}function d(e,t=0){const n=document.getElementById("crowdin-language-picker");if("sphinx"===e){const i=document.getElementsByClassName("cr-picker-button")[0],o=document.getElementsByClassName("sidebar-sticky")[0];return null===n||void 0===i||void 0===o?void c(e,t):(n.classList.remove("cr-position-bottom-left"),n.style.width=i.offsetWidth+10+"px",n.style.position="relative",n.style.left="10px",n.style.bottom="10px",void o.appendChild(n))}const i=document.querySelector(".sidebar .sidebar-elems")||document.querySelector(".sidebar");null!==n&&null!==i?(n.classList.remove("cr-position-bottom-left"),n.classList.add("rustdoc-crowdin-picker"),n.style.position="static",n.style.left="auto",n.style.bottom="auto",i.appendChild(n)):c(e,t)}function u(e="LizardByte",t=null){["LizardByte","LizardByte-docs"].includes(e)?["sphinx","rustdoc",null].includes(t)?(function(){if("function"!=typeof globalThis.fetch)return;if(globalThis._crowdinMirrorInstalled)return;globalThis._crowdinMirrorInstalled=!0;const e=globalThis.fetch.bind(globalThis);globalThis.fetch=function(t,n){if("string"==typeof t){let i;try{i=new URL(t)}catch{}if("https:"===i?.protocol&&"distributions.crowdin.net"===i.hostname){const t="https://cdn.jsdelivr.net/gh/LizardByte/i18n@dist"+i.pathname+i.search+i.hash;return e(t,n)}}return e(t,n)}}(),i("https://website-translator.app.crowdin.net/assets/proxy-translator.js",function(){let n={bg:"Български (Bulgarian)",cs:"Čeština (Czech)",de:"Deutsch (German)",en:"English","en-GB":"English, United Kingdom","en-US":"English, United States","es-ES":"Español (Spanish)",fr:"Français (French)",hu:"Magyar (Hungarian)",it:"Italiano (Italian)",ja:"日本語 (Japanese)",ko:"한국어 (Korean)",pl:"Polski (Polish)","pt-BR":"Português, Brasileiro (Portuguese, Brazilian)","pt-PT":"Português (Portuguese)",ru:"Русский (Russian)","sv-SE":"svenska (Swedish)",tr:"Türkçe (Turkish)",uk:"Українська (Ukranian)",vi:"Tiếng Việt (Vietnamese)","zh-CN":"简体中文 (Chinese Simplified)","zh-TW":"繁體中文 (Chinese Traditional)"};n=Object.fromEntries(Object.entries(n).sort((e,t)=>e[1].localeCompare(t[1])));let i=globalThis.location.origin;const o=function(){const e=[],t=document.createTreeWalker(document.body,globalThis.NodeFilter.SHOW_TEXT);let n=t.nextNode();for(;null!==n;){const i=s(n.previousSibling),o=s(n.nextSibling),a=null===i?"":r(n.data),c=null===o?"":l(n.data),d=""!==a,u=""!==c;(d||u)&&e.push({node:n,leading:d,leadingWhitespace:a,trailing:u,trailingWhitespace:c,previousInline:i,nextInline:o,whitespaceOnly:""===n.data.trim()}),n=t.nextNode()}return e}();globalThis.proxyTranslator.init({baseUrl:i,callback:a(o),distribution:{LizardByte:{baseUrl:"https://app.lizardbyte.dev",distribution:"458f881791aebba1d4dde491bw4"},"LizardByte-docs":{baseUrl:"https://docs.lizardbyte.dev",distribution:"d6c830ba4b41106fefe5d391bw4"}}[e].distribution,defaultLanguage:"en",languageTitles:n,showDefaultLanguageInUrl:!1,languageRoutingMethod:"query",position:"bottom-left",submenuPosition:"top-left",poweredBy:!1}),null!==t&&d(t)})):console.error('Invalid UI. Must be "sphinx", "rustdoc", or null'):console.error('Invalid project. Must be "LizardByte" or "LizardByte-docs"')}void 0!==globalThis.window&&(globalThis.initCrowdIn=u),e.exports=u},836(e){function t(e,t){const n=document.createElement("script");n.src=e,n.async=!0,n.onload=()=>{t&&t(null,n)},n.onerror=()=>{t&&t(new Error(`Failed to load script: ${e}`))},document.head.appendChild(n)}void 0!==globalThis.window&&(globalThis.loadScript=t),e.exports=t}};const t={};!function n(i){const o=t[i];if(void 0!==o)return o.exports;const s=t[i]={exports:{}};return e[i](s,s.exports,n),s.exports}(714)})();
|
|
2
2
|
//# sourceMappingURL=crowdin.js.map
|
package/dist/crowdin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crowdin.js","mappings":"wBAAA,MAAMA,EAAaC,EAAQ,KAarBC,EAAkC,CACpC,IACA,OACA,IACA,OACA,OACA,MACA,KACA,IACA,MACA,MACA,OACA,IACA,IACA,OACA,QACA,OACA,SACA,MACA,MACA,OACA,IACA,OACFC,KAAK,KAmGP,SAASC,EAAkCC,GACvC,MAAMC,EAAsB,IAAIC,WAAWC,iBAAiBC,GAE5D,SAASA,IACLH,EAAoBI,aAvB5B,SAA6CL,GACzCA,EAAWM,QAASC,IAChB,MAAMC,EAlCd,SAAuCD,GACnC,GAAIA,EAASC,KAAKC,YAAa,OAAOF,EAASC,KAE/C,MAAME,EAAsBH,EAASI,gBAAgBC,YACrD,GAAIF,aAA+BR,WAAWW,MAAQH,EAAoBD,YAEtE,OADAF,EAASC,KAAOE,EACTH,EAASC,KAEpB,MAAMM,EAAkBP,EAASQ,YAAYC,gBAC7C,GAAIF,aAA2BZ,WAAWW,MAAQC,EAAgBL,YAE9D,OADAF,EAASC,KAAOM,EACTP,EAASC,KAEpB,IAAKD,EAASU,eAAgB,OAAO,KAErC,MAAMC,EAAcC,SAASC,eAAe,IAC5C,GAAIb,EAASI,gBAAgBF,YACzBF,EAASI,eAAeU,MAAMH,OAC3B,KAAIX,EAASQ,YAAYN,YAG5B,OAAO,KAFPF,EAASQ,WAAWO,OAAOJ,EAG/B,CAGA,OADAX,EAASC,KAAOU,EACTX,EAASC,IACpB,CAQqBe,CAA8BhB,GAC9B,OAATC,IAEAD,EAASiB,UAAY,MAAMC,KAAKjB,EAAKkB,QACrClB,EAAKkB,KAAO,IAAMlB,EAAKkB,MAEvBnB,EAASoB,WAAa,MAAMF,KAAKjB,EAAKkB,QACtClB,EAAKkB,MAAQ,OAGzB,CAYQE,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AAA,IAOA,OAHAY,EAAAF,GAAAX,EAAAA,EAAAC,QAAAlI,GAGAiI,EAAAC,OACA,CCnBAlI,CAAA","sources":["webpack://@lizardbyte/shared-web/./src/js/crowdin.js","webpack://@lizardbyte/shared-web/./src/js/load-script.js","webpack://@lizardbyte/shared-web/webpack/bootstrap","webpack://@lizardbyte/shared-web/webpack/startup"],"sourcesContent":["const loadScript = require('./load-script');\n\n/**\n * jsDelivr CDN URL serving Crowdin distribution files from the crowdin-dist\n * git branch. jsDelivr unconditionally sets Access-Control-Allow-Origin: *,\n * so cross-origin fetch() calls succeed without any browser plugin.\n * The branch is refreshed daily by the \"Sync Crowdin Distribution\" workflow.\n * Structure mirrors https://distributions.crowdin.net/<hash>/… exactly.\n * @type {string}\n */\nconst CROWDIN_DIST_MIRROR = 'https://cdn.jsdelivr.net/gh/LizardByte/i18n@dist';\nconst CROWDIN_PLATFORM_STYLING_MAX_ATTEMPTS = 100;\nconst CROWDIN_PLATFORM_STYLING_RETRY_DELAY_MS = 50;\nconst CROWDIN_INLINE_ELEMENT_SELECTOR = [\n 'a',\n 'abbr',\n 'b',\n 'cite',\n 'code',\n 'del',\n 'em',\n 'i',\n 'ins',\n 'kbd',\n 'mark',\n 'q',\n 's',\n 'samp',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'sup',\n 'time',\n 'u',\n 'var',\n].join(',');\n\n/**\n * Records whitespace that separates text from inline elements before Crowdin translates the page.\n * @returns {Array<{\n * node: Text,\n * leading: boolean,\n * trailing: boolean,\n * previousInline: Element|null,\n * nextInline: Element|null,\n * whitespaceOnly: boolean\n * }>} Recorded text-node boundaries.\n */\nfunction _captureCrowdinWhitespaceBoundaries() {\n const boundaries = [];\n const walker = document.createTreeWalker(document.body, globalThis.NodeFilter.SHOW_TEXT);\n let node = walker.nextNode();\n\n while (node !== null) {\n const previousIsInline = node.previousSibling instanceof globalThis.Element &&\n node.previousSibling.matches(CROWDIN_INLINE_ELEMENT_SELECTOR);\n const nextIsInline = node.nextSibling instanceof globalThis.Element &&\n node.nextSibling.matches(CROWDIN_INLINE_ELEMENT_SELECTOR);\n const leading = previousIsInline && /^\\s/.test(node.data);\n const trailing = nextIsInline && /\\s$/.test(node.data);\n\n if (leading || trailing) {\n boundaries.push({\n node,\n leading,\n trailing,\n previousInline: previousIsInline ? node.previousSibling : null,\n nextInline: nextIsInline ? node.nextSibling : null,\n whitespaceOnly: /^\\s*$/.test(node.data),\n });\n }\n\n node = walker.nextNode();\n }\n\n return boundaries;\n}\n\n/**\n * Finds the current text node for a boundary after Crowdin changes the DOM.\n * @param {Object} boundary Recorded whitespace boundary.\n * @returns {Text|null} Current or recreated text node.\n */\nfunction _resolveCrowdinWhitespaceNode(boundary) {\n if (boundary.node.isConnected) return boundary.node;\n\n const previousReplacement = boundary.previousInline?.nextSibling;\n if (previousReplacement instanceof globalThis.Text && previousReplacement.isConnected) {\n boundary.node = previousReplacement;\n return boundary.node;\n }\n const nextReplacement = boundary.nextInline?.previousSibling;\n if (nextReplacement instanceof globalThis.Text && nextReplacement.isConnected) {\n boundary.node = nextReplacement;\n return boundary.node;\n }\n if (!boundary.whitespaceOnly) return null;\n\n const replacement = document.createTextNode('');\n if (boundary.previousInline?.isConnected) {\n boundary.previousInline.after(replacement);\n } else if (boundary.nextInline?.isConnected) {\n boundary.nextInline.before(replacement);\n } else {\n return null;\n }\n\n boundary.node = replacement;\n return boundary.node;\n}\n\n/**\n * Restores whitespace that Crowdin removed from translated text-node boundaries.\n * @param {Array<Object>} boundaries Recorded text-node boundaries.\n */\nfunction _restoreCrowdinWhitespaceBoundaries(boundaries) {\n boundaries.forEach((boundary) => {\n const node = _resolveCrowdinWhitespaceNode(boundary);\n if (node === null) return;\n\n if (boundary.leading && !/^\\s/.test(node.data)) {\n node.data = ' ' + node.data;\n }\n if (boundary.trailing && !/\\s$/.test(node.data)) {\n node.data += ' ';\n }\n });\n}\n\n/**\n * Creates the Website Translator callback and observes later translation mutations.\n * @param {Array<Object>} boundaries Recorded text-node boundaries.\n * @returns {Function} Website Translator callback.\n */\nfunction _createCrowdinTranslationCallback(boundaries) {\n const translationObserver = new globalThis.MutationObserver(restoreAndObserve);\n\n function restoreAndObserve() {\n translationObserver.disconnect();\n _restoreCrowdinWhitespaceBoundaries(boundaries);\n translationObserver.observe(document.body, {\n characterData: true,\n childList: true,\n subtree: true,\n });\n }\n\n return restoreAndObserve;\n}\n\n/**\n * Monkey-patches globalThis.fetch to redirect Crowdin distribution requests to\n * the self-hosted GitHub Pages mirror.\n *\n * Must be called BEFORE proxy-translator.js is loaded so that every fetch()\n * the script makes is already intercepted.\n *\n * Idempotent – installs the interceptor at most once per page.\n */\nfunction _installCrowdinFetchInterceptor() {\n if (typeof globalThis.fetch !== 'function') return;\n if (globalThis._crowdinMirrorInstalled) return;\n globalThis._crowdinMirrorInstalled = true;\n\n const _origFetch = globalThis.fetch.bind(globalThis);\n\n globalThis.fetch = function crowdinMirrorFetch(url, options) {\n if (typeof url === 'string') {\n let parsed;\n try {\n parsed = new URL(url);\n } catch {\n // Not a valid absolute URL – pass through unchanged.\n }\n // Use exact hostname comparison to avoid prefix-match bypasses\n // (e.g. distributions.crowdin.net.evil.com) that would be flagged\n // by incomplete URL sanitisation checks.\n if (parsed?.protocol === 'https:' && parsed.hostname === 'distributions.crowdin.net') {\n const mirroredUrl = CROWDIN_DIST_MIRROR + parsed.pathname + parsed.search + parsed.hash;\n return _origFetch(mirroredUrl, options);\n }\n }\n return _origFetch(url, options);\n };\n}\n\n/**\n * Re-attempts platform styling while Crowdin inserts the language picker.\n * @param {string} platform - UI platform ('sphinx' or 'rustdoc').\n * @param {number} attempt - Current retry count.\n */\nfunction _retryCrowdinPlatformStyling(platform, attempt) {\n if (attempt >= CROWDIN_PLATFORM_STYLING_MAX_ATTEMPTS) {\n return;\n }\n\n globalThis.setTimeout(function() {\n _applyCrowdinPlatformStyling(platform, attempt + 1);\n }, CROWDIN_PLATFORM_STYLING_RETRY_DELAY_MS);\n}\n\n/**\n * Applies platform-specific placement after the Crowdin picker exists.\n * @param {string} platform - UI platform ('sphinx' or 'rustdoc').\n * @param {number} attempt - Current retry count.\n */\nfunction _applyCrowdinPlatformStyling(platform, attempt = 0) {\n const container = document.getElementById('crowdin-language-picker');\n\n if (platform === 'sphinx') {\n const button = document.getElementsByClassName('cr-picker-button')[0];\n const sidebar = document.getElementsByClassName('sidebar-sticky')[0];\n\n if (container === null || button === undefined || sidebar === undefined) {\n _retryCrowdinPlatformStyling(platform, attempt);\n return;\n }\n\n container.classList.remove('cr-position-bottom-left');\n container.style.width = button.offsetWidth + 10 + 'px';\n container.style.position = 'relative';\n container.style.left = '10px';\n container.style.bottom = '10px';\n\n // move button to related pages\n sidebar.appendChild(container);\n return;\n }\n\n const sidebar = document.querySelector('.sidebar .sidebar-elems') || document.querySelector('.sidebar');\n\n if (container === null || sidebar === null) {\n _retryCrowdinPlatformStyling(platform, attempt);\n return;\n }\n\n container.classList.remove('cr-position-bottom-left');\n container.classList.add('rustdoc-crowdin-picker');\n container.style.position = 'static';\n container.style.left = 'auto';\n container.style.bottom = 'auto';\n\n sidebar.appendChild(container);\n}\n\n/**\n * Initializes Crowdin translation widget based on project and UI platform.\n * @param {string} project - Project name ('LizardByte' or 'LizardByte-docs').\n * @param {string|null} platform - UI platform ('sphinx', 'rustdoc', or null).\n */\nfunction initCrowdIn(project = 'LizardByte', platform = null) {\n // Input validation\n if (!['LizardByte', 'LizardByte-docs'].includes(project)) {\n console.error('Invalid project. Must be \"LizardByte\" or \"LizardByte-docs\"');\n return;\n }\n if (!['sphinx', 'rustdoc', null].includes(platform)) {\n console.error('Invalid UI. Must be \"sphinx\", \"rustdoc\", or null');\n return;\n }\n\n // Redirect distribution CDN requests to our self-hosted GitHub Pages mirror\n // before the script is even loaded so every fetch() it makes is intercepted.\n _installCrowdinFetchInterceptor();\n\n loadScript('https://website-translator.app.crowdin.net/assets/proxy-translator.js', function() {\n // Configure base settings based on project\n const projectSettings = {\n 'LizardByte': {\n baseUrl: \"https://app.lizardbyte.dev\",\n distribution: \"458f881791aebba1d4dde491bw4\",\n },\n 'LizardByte-docs': {\n baseUrl: \"https://docs.lizardbyte.dev\",\n distribution: \"d6c830ba4b41106fefe5d391bw4\",\n }\n };\n\n let languageTitles = {\n \"bg\": \"Български (Bulgarian)\",\n \"cs\": \"Čeština (Czech)\",\n \"de\": \"Deutsch (German)\",\n \"en\": \"English\",\n \"en-GB\": \"English, United Kingdom\",\n \"en-US\": \"English, United States\",\n \"es-ES\": \"Español (Spanish)\",\n \"fr\": \"Français (French)\",\n \"hu\": \"Magyar (Hungarian)\",\n \"it\": \"Italiano (Italian)\",\n \"ja\": \"日本語 (Japanese)\",\n \"ko\": \"한국어 (Korean)\",\n \"pl\": \"Polski (Polish)\",\n \"pt-BR\": \"Português, Brasileiro (Portuguese, Brazilian)\",\n \"pt-PT\": \"Português (Portuguese)\",\n \"ru\": \"Русский (Russian)\",\n \"sv-SE\": \"svenska (Swedish)\",\n \"tr\": \"Türkçe (Turkish)\",\n \"uk\": \"Українська (Ukranian)\",\n \"vi\": \"Tiếng Việt (Vietnamese)\",\n \"zh-CN\": \"简体中文 (Chinese Simplified)\",\n \"zh-TW\": \"繁體中文 (Chinese Traditional)\",\n };\n // sort languages by name\n languageTitles = Object.fromEntries(Object.entries(languageTitles).sort((a, b) => a[1].localeCompare(b[1])));\n\n // use this to allow translations to work on PR preview builds\n let currentBaseUrl = globalThis.location.origin;\n\n // Initialize Crowdin translator\n const whitespaceBoundaries = _captureCrowdinWhitespaceBoundaries();\n\n globalThis.proxyTranslator.init({\n baseUrl: currentBaseUrl,\n callback: _createCrowdinTranslationCallback(whitespaceBoundaries),\n distribution: projectSettings[project].distribution,\n defaultLanguage: \"en\",\n languageTitles: languageTitles,\n showDefaultLanguageInUrl: false,\n languageRoutingMethod: \"query\",\n position: \"bottom-left\",\n submenuPosition: \"top-left\",\n poweredBy: false,\n });\n\n // Apply styling based on UI framework\n if (platform === null) {\n return;\n }\n\n _applyCrowdinPlatformStyling(platform);\n });\n}\n\n// Expose to the global scope\nif (globalThis.window !== undefined) {\n globalThis.initCrowdIn = initCrowdIn;\n}\n\nmodule.exports = initCrowdIn;\n","/**\n * Load a script asynchronously, and add it to the DOM. Optionally, call a callback when the script has loaded.\n * @param {string} url The URL of the script to load.\n * @param {Function} callback An optional callback to call when the script has loaded.\n */\nfunction loadScript(url, callback) {\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n\n script.onload = () => {\n if (callback) callback(null, script);\n };\n\n script.onerror = () => {\n if (callback) callback(new Error(`Failed to load script: ${url}`));\n };\n\n document.head.appendChild(script);\n}\n\n// Expose to the global scope\nif (globalThis.window !== undefined) {\n globalThis.loadScript = loadScript;\n}\n\nmodule.exports = loadScript;\n","// The module cache\nconst __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tconst cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tconst module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nlet __webpack_exports__ = __webpack_require__(714);\n"],"names":["loadScript","__webpack_require__","CROWDIN_INLINE_ELEMENT_SELECTOR","join","_createCrowdinTranslationCallback","boundaries","translationObserver","globalThis","MutationObserver","restoreAndObserve","disconnect","forEach","boundary","node","isConnected","previousReplacement","previousInline","nextSibling","Text","nextReplacement","nextInline","previousSibling","whitespaceOnly","replacement","document","createTextNode","after","before","_resolveCrowdinWhitespaceNode","leading","test","data","trailing","_restoreCrowdinWhitespaceBoundaries","observe","body","characterData","childList","subtree","_retryCrowdinPlatformStyling","platform","attempt","setTimeout","_applyCrowdinPlatformStyling","container","getElementById","button","getElementsByClassName","sidebar","undefined","classList","remove","style","width","offsetWidth","position","left","bottom","appendChild","querySelector","add","initCrowdIn","project","includes","fetch","_crowdinMirrorInstalled","_origFetch","bind","url","options","parsed","URL","protocol","hostname","mirroredUrl","pathname","search","hash","_installCrowdinFetchInterceptor","languageTitles","bg","cs","de","en","fr","hu","it","ja","ko","pl","ru","tr","uk","vi","Object","fromEntries","entries","sort","a","b","localeCompare","currentBaseUrl","location","origin","whitespaceBoundaries","walker","createTreeWalker","NodeFilter","SHOW_TEXT","nextNode","previousIsInline","Element","matches","nextIsInline","push","_captureCrowdinWhitespaceBoundaries","proxyTranslator","init","baseUrl","callback","distribution","LizardByte","defaultLanguage","showDefaultLanguageInUrl","languageRoutingMethod","submenuPosition","poweredBy","console","error","window","module","exports","script","createElement","src","async","onload","onerror","Error","head","__webpack_module_cache__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"crowdin.js","mappings":"wBAAA,MAAMA,EAAaC,EAAQ,KAarBC,EAAkC,CACpC,IACA,OACA,IACA,OACA,OACA,MACA,KACA,IACA,MACA,MACA,OACA,IACA,IACA,OACA,QACA,OACA,SACA,MACA,MACA,OACA,IACA,OACFC,KAAK,KAOP,SAASC,EAAyBC,GAC9B,OAAMA,aAAmBC,WAAWC,SAC7BF,EAAQG,QAAQN,GAAmCG,EADL,IAEzD,CAOA,SAASI,EAAsBC,GAC3B,MAAMC,EAAcD,EAAKE,YACzB,OAAOF,EAAKG,MAAM,EAAGH,EAAKI,OAASH,EAAYG,OACnD,CAOA,SAASC,EAAuBL,GAC5B,MAAMC,EAAcD,EAAKM,UACzB,OAAON,EAAKG,MAAMF,EAAYG,OAClC,CA0GA,SAASG,EAAkCC,GACvC,MAAMC,EAAsB,IAAIb,WAAWc,iBAAiBC,GAE5D,SAASA,IACLF,EAAoBG,aA1B5B,SAA6CJ,GACzCA,EAAWK,QAASC,IAChB,MAAMC,EAlC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C,QAASd,EACTe,SAAUnH,EAAkCuG,GAC5Ca,aA/CoB,CACpBC,WAAc,CACVH,QAAS,6BACTE,aAAc,+BAElB,kBAAmB,CACfF,QAAS,8BACTE,aAAc,gCAwCYvD,GAASuD,aACvCE,gBAAiB,KACjBxC,eAAgBA,EAChByC,0BAA0B,EAC1BC,sBAAuB,QACvBlE,SAAU,cACVmE,gBAAiB,WACjBC,WAAW,IAIE,OAAbnF,GAIJG,EAA6BH,EACjC,IAzEIoF,QAAQC,MAAM,oDAJdD,QAAQC,MAAM,6DA8EtB,MAG0B5E,IAAtB3D,WAAWwI,SACXxI,WAAWuE,YAAcA,GAG7BkE,EAAOC,QAAUnE,UCnXjB,SAAS7E,EAAWoF,EAAKgD,GACrB,MAAMa,EAAS7G,SAAS8G,cAAc,UACtCD,EAAOE,IAAM/D,EACb6D,EAAOG,OAAQ,EAEfH,EAAOI,OAAS,KACRjB,GAAUA,EAAS,KAAMa,IAGjCA,EAAOK,QAAU,KACTlB,GAAUA,EAAS,IAAImB,MAAM,0BAA0BnE,OAG/DhD,SAASoH,KAAK9E,YAAYuE,EAC9B,MAG0BhF,IAAtB3D,WAAWwI,SACXxI,WAAWN,WAAaA,GAG5B+I,EAAOC,QAAUhJ,ICzBjB,MAAAyJ,EAAA,IAGA,SAAAxJ,EAAAyJ,GAEA,MAAAC,EAAAF,EAAAC,GACA,QAAAzF,IAAA0F,EACA,OAAAA,EAAAX,QAGA,MAAAD,EAAAU,EAAAC,GAAA,CAGAV,QAAA,IAOA,OAHAY,EAAAF,GAAAX,EAAAA,EAAAC,QAAA/I,GAGA8I,EAAAC,OACA,CCnBA/I,CAAA","sources":["webpack://@lizardbyte/shared-web/./src/js/crowdin.js","webpack://@lizardbyte/shared-web/./src/js/load-script.js","webpack://@lizardbyte/shared-web/webpack/bootstrap","webpack://@lizardbyte/shared-web/webpack/startup"],"sourcesContent":["const loadScript = require('./load-script');\n\n/**\n * jsDelivr CDN URL serving Crowdin distribution files from the crowdin-dist\n * git branch. jsDelivr unconditionally sets Access-Control-Allow-Origin: *,\n * so cross-origin fetch() calls succeed without any browser plugin.\n * The branch is refreshed daily by the \"Sync Crowdin Distribution\" workflow.\n * Structure mirrors https://distributions.crowdin.net/<hash>/… exactly.\n * @type {string}\n */\nconst CROWDIN_DIST_MIRROR = 'https://cdn.jsdelivr.net/gh/LizardByte/i18n@dist';\nconst CROWDIN_PLATFORM_STYLING_MAX_ATTEMPTS = 100;\nconst CROWDIN_PLATFORM_STYLING_RETRY_DELAY_MS = 50;\nconst CROWDIN_INLINE_ELEMENT_SELECTOR = [\n 'a',\n 'abbr',\n 'b',\n 'cite',\n 'code',\n 'del',\n 'em',\n 'i',\n 'ins',\n 'kbd',\n 'mark',\n 'q',\n 's',\n 'samp',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'sup',\n 'time',\n 'u',\n 'var',\n].join(',');\n\n/**\n * Returns a sibling when it is an inline element whose boundary Crowdin may rewrite.\n * @param {Node|null} sibling Candidate sibling.\n * @returns {Element|null} Matching inline element.\n */\nfunction _getCrowdinInlineSibling(sibling) {\n if (!(sibling instanceof globalThis.Element)) return null;\n return sibling.matches(CROWDIN_INLINE_ELEMENT_SELECTOR) ? sibling : null;\n}\n\n/**\n * Returns the exact whitespace at the start of a string.\n * @param {string} text Text to inspect.\n * @returns {string} Leading whitespace.\n */\nfunction _getLeadingWhitespace(text) {\n const trimmedText = text.trimStart();\n return text.slice(0, text.length - trimmedText.length);\n}\n\n/**\n * Returns the exact whitespace at the end of a string.\n * @param {string} text Text to inspect.\n * @returns {string} Trailing whitespace.\n */\nfunction _getTrailingWhitespace(text) {\n const trimmedText = text.trimEnd();\n return text.slice(trimmedText.length);\n}\n\n/**\n * Records whitespace that separates text from inline elements before Crowdin translates the page.\n * @returns {Array<{\n * node: Text,\n * leading: boolean,\n * leadingWhitespace: string,\n * trailing: boolean,\n * trailingWhitespace: string,\n * previousInline: Element|null,\n * nextInline: Element|null,\n * whitespaceOnly: boolean\n * }>} Recorded text-node boundaries.\n */\nfunction _captureCrowdinWhitespaceBoundaries() {\n const boundaries = [];\n const walker = document.createTreeWalker(document.body, globalThis.NodeFilter.SHOW_TEXT);\n let node = walker.nextNode();\n\n while (node !== null) {\n const previousInline = _getCrowdinInlineSibling(node.previousSibling);\n const nextInline = _getCrowdinInlineSibling(node.nextSibling);\n const leadingWhitespace = previousInline === null ? '' : _getLeadingWhitespace(node.data);\n const trailingWhitespace = nextInline === null ? '' : _getTrailingWhitespace(node.data);\n const leading = leadingWhitespace !== '';\n const trailing = trailingWhitespace !== '';\n\n if (leading || trailing) {\n boundaries.push({\n node,\n leading,\n leadingWhitespace,\n trailing,\n trailingWhitespace,\n previousInline,\n nextInline,\n whitespaceOnly: node.data.trim() === '',\n });\n }\n\n node = walker.nextNode();\n }\n\n return boundaries;\n}\n\n/**\n * Finds the current text node for a boundary after Crowdin changes the DOM.\n * @param {Object} boundary Recorded whitespace boundary.\n * @returns {Text|null} Current or recreated text node.\n */\nfunction _resolveCrowdinWhitespaceNode(boundary) {\n if (boundary.node.isConnected) return boundary.node;\n\n const previousReplacement = boundary.previousInline?.nextSibling;\n if (previousReplacement instanceof globalThis.Text && previousReplacement.isConnected) {\n boundary.node = previousReplacement;\n return boundary.node;\n }\n const nextReplacement = boundary.nextInline?.previousSibling;\n if (nextReplacement instanceof globalThis.Text && nextReplacement.isConnected) {\n boundary.node = nextReplacement;\n return boundary.node;\n }\n if (!boundary.whitespaceOnly) return null;\n\n const replacement = document.createTextNode('');\n if (boundary.previousInline?.isConnected) {\n boundary.previousInline.after(replacement);\n } else if (boundary.nextInline?.isConnected) {\n boundary.nextInline.before(replacement);\n } else {\n return null;\n }\n\n boundary.node = replacement;\n return boundary.node;\n}\n\n/**\n * Restores whitespace that Crowdin removed from translated text-node boundaries.\n * @param {Array<Object>} boundaries Recorded text-node boundaries.\n */\nfunction _restoreCrowdinWhitespaceBoundaries(boundaries) {\n boundaries.forEach((boundary) => {\n const node = _resolveCrowdinWhitespaceNode(boundary);\n if (node === null) return;\n\n const currentLeadingWhitespace = _getLeadingWhitespace(node.data);\n if (boundary.leading && currentLeadingWhitespace !== boundary.leadingWhitespace) {\n node.data = boundary.leadingWhitespace + node.data.slice(currentLeadingWhitespace.length);\n }\n const currentTrailingWhitespace = _getTrailingWhitespace(node.data);\n if (boundary.trailing && currentTrailingWhitespace !== boundary.trailingWhitespace) {\n const translatedTextEnd = node.data.length - currentTrailingWhitespace.length;\n node.data = node.data.slice(0, translatedTextEnd) + boundary.trailingWhitespace;\n }\n });\n}\n\n/**\n * Creates the Website Translator callback and observes later translation mutations.\n * @param {Array<Object>} boundaries Recorded text-node boundaries.\n * @returns {Function} Website Translator callback.\n */\nfunction _createCrowdinTranslationCallback(boundaries) {\n const translationObserver = new globalThis.MutationObserver(restoreAndObserve);\n\n function restoreAndObserve() {\n translationObserver.disconnect();\n _restoreCrowdinWhitespaceBoundaries(boundaries);\n translationObserver.observe(document.body, {\n characterData: true,\n childList: true,\n subtree: true,\n });\n }\n\n return restoreAndObserve;\n}\n\n/**\n * Monkey-patches globalThis.fetch to redirect Crowdin distribution requests to\n * the self-hosted GitHub Pages mirror.\n *\n * Must be called BEFORE proxy-translator.js is loaded so that every fetch()\n * the script makes is already intercepted.\n *\n * Idempotent – installs the interceptor at most once per page.\n */\nfunction _installCrowdinFetchInterceptor() {\n if (typeof globalThis.fetch !== 'function') return;\n if (globalThis._crowdinMirrorInstalled) return;\n globalThis._crowdinMirrorInstalled = true;\n\n const _origFetch = globalThis.fetch.bind(globalThis);\n\n globalThis.fetch = function crowdinMirrorFetch(url, options) {\n if (typeof url === 'string') {\n let parsed;\n try {\n parsed = new URL(url);\n } catch {\n // Not a valid absolute URL – pass through unchanged.\n }\n // Use exact hostname comparison to avoid prefix-match bypasses\n // (e.g. distributions.crowdin.net.evil.com) that would be flagged\n // by incomplete URL sanitisation checks.\n if (parsed?.protocol === 'https:' && parsed.hostname === 'distributions.crowdin.net') {\n const mirroredUrl = CROWDIN_DIST_MIRROR + parsed.pathname + parsed.search + parsed.hash;\n return _origFetch(mirroredUrl, options);\n }\n }\n return _origFetch(url, options);\n };\n}\n\n/**\n * Re-attempts platform styling while Crowdin inserts the language picker.\n * @param {string} platform - UI platform ('sphinx' or 'rustdoc').\n * @param {number} attempt - Current retry count.\n */\nfunction _retryCrowdinPlatformStyling(platform, attempt) {\n if (attempt >= CROWDIN_PLATFORM_STYLING_MAX_ATTEMPTS) {\n return;\n }\n\n globalThis.setTimeout(function() {\n _applyCrowdinPlatformStyling(platform, attempt + 1);\n }, CROWDIN_PLATFORM_STYLING_RETRY_DELAY_MS);\n}\n\n/**\n * Applies platform-specific placement after the Crowdin picker exists.\n * @param {string} platform - UI platform ('sphinx' or 'rustdoc').\n * @param {number} attempt - Current retry count.\n */\nfunction _applyCrowdinPlatformStyling(platform, attempt = 0) {\n const container = document.getElementById('crowdin-language-picker');\n\n if (platform === 'sphinx') {\n const button = document.getElementsByClassName('cr-picker-button')[0];\n const sidebar = document.getElementsByClassName('sidebar-sticky')[0];\n\n if (container === null || button === undefined || sidebar === undefined) {\n _retryCrowdinPlatformStyling(platform, attempt);\n return;\n }\n\n container.classList.remove('cr-position-bottom-left');\n container.style.width = button.offsetWidth + 10 + 'px';\n container.style.position = 'relative';\n container.style.left = '10px';\n container.style.bottom = '10px';\n\n // move button to related pages\n sidebar.appendChild(container);\n return;\n }\n\n const sidebar = document.querySelector('.sidebar .sidebar-elems') || document.querySelector('.sidebar');\n\n if (container === null || sidebar === null) {\n _retryCrowdinPlatformStyling(platform, attempt);\n return;\n }\n\n container.classList.remove('cr-position-bottom-left');\n container.classList.add('rustdoc-crowdin-picker');\n container.style.position = 'static';\n container.style.left = 'auto';\n container.style.bottom = 'auto';\n\n sidebar.appendChild(container);\n}\n\n/**\n * Initializes Crowdin translation widget based on project and UI platform.\n * @param {string} project - Project name ('LizardByte' or 'LizardByte-docs').\n * @param {string|null} platform - UI platform ('sphinx', 'rustdoc', or null).\n */\nfunction initCrowdIn(project = 'LizardByte', platform = null) {\n // Input validation\n if (!['LizardByte', 'LizardByte-docs'].includes(project)) {\n console.error('Invalid project. Must be \"LizardByte\" or \"LizardByte-docs\"');\n return;\n }\n if (!['sphinx', 'rustdoc', null].includes(platform)) {\n console.error('Invalid UI. Must be \"sphinx\", \"rustdoc\", or null');\n return;\n }\n\n // Redirect distribution CDN requests to our self-hosted GitHub Pages mirror\n // before the script is even loaded so every fetch() it makes is intercepted.\n _installCrowdinFetchInterceptor();\n\n loadScript('https://website-translator.app.crowdin.net/assets/proxy-translator.js', function() {\n // Configure base settings based on project\n const projectSettings = {\n 'LizardByte': {\n baseUrl: \"https://app.lizardbyte.dev\",\n distribution: \"458f881791aebba1d4dde491bw4\",\n },\n 'LizardByte-docs': {\n baseUrl: \"https://docs.lizardbyte.dev\",\n distribution: \"d6c830ba4b41106fefe5d391bw4\",\n }\n };\n\n let languageTitles = {\n \"bg\": \"Български (Bulgarian)\",\n \"cs\": \"Čeština (Czech)\",\n \"de\": \"Deutsch (German)\",\n \"en\": \"English\",\n \"en-GB\": \"English, United Kingdom\",\n \"en-US\": \"English, United States\",\n \"es-ES\": \"Español (Spanish)\",\n \"fr\": \"Français (French)\",\n \"hu\": \"Magyar (Hungarian)\",\n \"it\": \"Italiano (Italian)\",\n \"ja\": \"日本語 (Japanese)\",\n \"ko\": \"한국어 (Korean)\",\n \"pl\": \"Polski (Polish)\",\n \"pt-BR\": \"Português, Brasileiro (Portuguese, Brazilian)\",\n \"pt-PT\": \"Português (Portuguese)\",\n \"ru\": \"Русский (Russian)\",\n \"sv-SE\": \"svenska (Swedish)\",\n \"tr\": \"Türkçe (Turkish)\",\n \"uk\": \"Українська (Ukranian)\",\n \"vi\": \"Tiếng Việt (Vietnamese)\",\n \"zh-CN\": \"简体中文 (Chinese Simplified)\",\n \"zh-TW\": \"繁體中文 (Chinese Traditional)\",\n };\n // sort languages by name\n languageTitles = Object.fromEntries(Object.entries(languageTitles).sort((a, b) => a[1].localeCompare(b[1])));\n\n // use this to allow translations to work on PR preview builds\n let currentBaseUrl = globalThis.location.origin;\n\n // Initialize Crowdin translator\n const whitespaceBoundaries = _captureCrowdinWhitespaceBoundaries();\n\n globalThis.proxyTranslator.init({\n baseUrl: currentBaseUrl,\n callback: _createCrowdinTranslationCallback(whitespaceBoundaries),\n distribution: projectSettings[project].distribution,\n defaultLanguage: \"en\",\n languageTitles: languageTitles,\n showDefaultLanguageInUrl: false,\n languageRoutingMethod: \"query\",\n position: \"bottom-left\",\n submenuPosition: \"top-left\",\n poweredBy: false,\n });\n\n // Apply styling based on UI framework\n if (platform === null) {\n return;\n }\n\n _applyCrowdinPlatformStyling(platform);\n });\n}\n\n// Expose to the global scope\nif (globalThis.window !== undefined) {\n globalThis.initCrowdIn = initCrowdIn;\n}\n\nmodule.exports = initCrowdIn;\n","/**\n * Load a script asynchronously, and add it to the DOM. Optionally, call a callback when the script has loaded.\n * @param {string} url The URL of the script to load.\n * @param {Function} callback An optional callback to call when the script has loaded.\n */\nfunction loadScript(url, callback) {\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n\n script.onload = () => {\n if (callback) callback(null, script);\n };\n\n script.onerror = () => {\n if (callback) callback(new Error(`Failed to load script: ${url}`));\n };\n\n document.head.appendChild(script);\n}\n\n// Expose to the global scope\nif (globalThis.window !== undefined) {\n globalThis.loadScript = loadScript;\n}\n\nmodule.exports = loadScript;\n","// The module cache\nconst __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tconst cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tconst module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nlet __webpack_exports__ = __webpack_require__(714);\n"],"names":["loadScript","__webpack_require__","CROWDIN_INLINE_ELEMENT_SELECTOR","join","_getCrowdinInlineSibling","sibling","globalThis","Element","matches","_getLeadingWhitespace","text","trimmedText","trimStart","slice","length","_getTrailingWhitespace","trimEnd","_createCrowdinTranslationCallback","boundaries","translationObserver","MutationObserver","restoreAndObserve","disconnect","forEach","boundary","node","isConnected","previousReplacement","previousInline","nextSibling","Text","nextReplacement","nextInline","previousSibling","whitespaceOnly","replacement","document","createTextNode","after","before","_resolveCrowdinWhitespaceNode","currentLeadingWhitespace","data","leading","leadingWhitespace","currentTrailingWhitespace","trailing","trailingWhitespace","translatedTextEnd","_restoreCrowdinWhitespaceBoundaries","observe","body","characterData","childList","subtree","_retryCrowdinPlatformStyling","platform","attempt","setTimeout","_applyCrowdinPlatformStyling","container","getElementById","button","getElementsByClassName","sidebar","undefined","classList","remove","style","width","offsetWidth","position","left","bottom","appendChild","querySelector","add","initCrowdIn","project","includes","fetch","_crowdinMirrorInstalled","_origFetch","bind","url","options","parsed","URL","protocol","hostname","mirroredUrl","pathname","search","hash","_installCrowdinFetchInterceptor","languageTitles","bg","cs","de","en","fr","hu","it","ja","ko","pl","ru","tr","uk","vi","Object","fromEntries","entries","sort","a","b","localeCompare","currentBaseUrl","location","origin","whitespaceBoundaries","walker","createTreeWalker","NodeFilter","SHOW_TEXT","nextNode","push","trim","_captureCrowdinWhitespaceBoundaries","proxyTranslator","init","baseUrl","callback","distribution","LizardByte","defaultLanguage","showDefaultLanguageInUrl","languageRoutingMethod","submenuPosition","poweredBy","console","error","window","module","exports","script","createElement","src","async","onload","onerror","Error","head","__webpack_module_cache__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "git",
|
|
5
5
|
"url": "git+https://github.com/LizardByte/shared-web.git"
|
|
6
6
|
},
|
|
7
|
-
"version": "2026.
|
|
7
|
+
"version": "2026.812.190302",
|
|
8
8
|
"description": "Shared web assets for LizardByte projects",
|
|
9
9
|
"license": "AGPL-3.0-only",
|
|
10
10
|
"funding": "https://app.lizardbyte.dev",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"cross-env": "10.1.0",
|
|
34
34
|
"css-loader": "7.1.4",
|
|
35
35
|
"eslint": "10.8.1",
|
|
36
|
-
"eslint-plugin-jest": "29.16.
|
|
37
|
-
"globals": "17.
|
|
36
|
+
"eslint-plugin-jest": "29.16.1",
|
|
37
|
+
"globals": "17.11.0",
|
|
38
38
|
"jest": "30.4.2",
|
|
39
39
|
"jest-environment-jsdom": "30.4.1",
|
|
40
40
|
"jest-junit": "17.0.0",
|
package/src/js/crowdin.js
CHANGED
|
@@ -36,12 +36,44 @@ const CROWDIN_INLINE_ELEMENT_SELECTOR = [
|
|
|
36
36
|
'var',
|
|
37
37
|
].join(',');
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Returns a sibling when it is an inline element whose boundary Crowdin may rewrite.
|
|
41
|
+
* @param {Node|null} sibling Candidate sibling.
|
|
42
|
+
* @returns {Element|null} Matching inline element.
|
|
43
|
+
*/
|
|
44
|
+
function _getCrowdinInlineSibling(sibling) {
|
|
45
|
+
if (!(sibling instanceof globalThis.Element)) return null;
|
|
46
|
+
return sibling.matches(CROWDIN_INLINE_ELEMENT_SELECTOR) ? sibling : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Returns the exact whitespace at the start of a string.
|
|
51
|
+
* @param {string} text Text to inspect.
|
|
52
|
+
* @returns {string} Leading whitespace.
|
|
53
|
+
*/
|
|
54
|
+
function _getLeadingWhitespace(text) {
|
|
55
|
+
const trimmedText = text.trimStart();
|
|
56
|
+
return text.slice(0, text.length - trimmedText.length);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Returns the exact whitespace at the end of a string.
|
|
61
|
+
* @param {string} text Text to inspect.
|
|
62
|
+
* @returns {string} Trailing whitespace.
|
|
63
|
+
*/
|
|
64
|
+
function _getTrailingWhitespace(text) {
|
|
65
|
+
const trimmedText = text.trimEnd();
|
|
66
|
+
return text.slice(trimmedText.length);
|
|
67
|
+
}
|
|
68
|
+
|
|
39
69
|
/**
|
|
40
70
|
* Records whitespace that separates text from inline elements before Crowdin translates the page.
|
|
41
71
|
* @returns {Array<{
|
|
42
72
|
* node: Text,
|
|
43
73
|
* leading: boolean,
|
|
74
|
+
* leadingWhitespace: string,
|
|
44
75
|
* trailing: boolean,
|
|
76
|
+
* trailingWhitespace: string,
|
|
45
77
|
* previousInline: Element|null,
|
|
46
78
|
* nextInline: Element|null,
|
|
47
79
|
* whitespaceOnly: boolean
|
|
@@ -53,21 +85,23 @@ function _captureCrowdinWhitespaceBoundaries() {
|
|
|
53
85
|
let node = walker.nextNode();
|
|
54
86
|
|
|
55
87
|
while (node !== null) {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const leading =
|
|
61
|
-
const trailing =
|
|
88
|
+
const previousInline = _getCrowdinInlineSibling(node.previousSibling);
|
|
89
|
+
const nextInline = _getCrowdinInlineSibling(node.nextSibling);
|
|
90
|
+
const leadingWhitespace = previousInline === null ? '' : _getLeadingWhitespace(node.data);
|
|
91
|
+
const trailingWhitespace = nextInline === null ? '' : _getTrailingWhitespace(node.data);
|
|
92
|
+
const leading = leadingWhitespace !== '';
|
|
93
|
+
const trailing = trailingWhitespace !== '';
|
|
62
94
|
|
|
63
95
|
if (leading || trailing) {
|
|
64
96
|
boundaries.push({
|
|
65
97
|
node,
|
|
66
98
|
leading,
|
|
99
|
+
leadingWhitespace,
|
|
67
100
|
trailing,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
101
|
+
trailingWhitespace,
|
|
102
|
+
previousInline,
|
|
103
|
+
nextInline,
|
|
104
|
+
whitespaceOnly: node.data.trim() === '',
|
|
71
105
|
});
|
|
72
106
|
}
|
|
73
107
|
|
|
@@ -119,11 +153,14 @@ function _restoreCrowdinWhitespaceBoundaries(boundaries) {
|
|
|
119
153
|
const node = _resolveCrowdinWhitespaceNode(boundary);
|
|
120
154
|
if (node === null) return;
|
|
121
155
|
|
|
122
|
-
|
|
123
|
-
|
|
156
|
+
const currentLeadingWhitespace = _getLeadingWhitespace(node.data);
|
|
157
|
+
if (boundary.leading && currentLeadingWhitespace !== boundary.leadingWhitespace) {
|
|
158
|
+
node.data = boundary.leadingWhitespace + node.data.slice(currentLeadingWhitespace.length);
|
|
124
159
|
}
|
|
125
|
-
|
|
126
|
-
|
|
160
|
+
const currentTrailingWhitespace = _getTrailingWhitespace(node.data);
|
|
161
|
+
if (boundary.trailing && currentTrailingWhitespace !== boundary.trailingWhitespace) {
|
|
162
|
+
const translatedTextEnd = node.data.length - currentTrailingWhitespace.length;
|
|
163
|
+
node.data = node.data.slice(0, translatedTextEnd) + boundary.trailingWhitespace;
|
|
127
164
|
}
|
|
128
165
|
});
|
|
129
166
|
}
|
package/tests/crowdin.test.js
CHANGED
|
@@ -175,6 +175,27 @@ describe('initCrowdIn', () => {
|
|
|
175
175
|
expect(nextAnchor.textContent).toBe(' kept');
|
|
176
176
|
});
|
|
177
177
|
|
|
178
|
+
it('should restore line breaks between translated syntax-highlighted lines', () => {
|
|
179
|
+
globalThis.document.body.innerHTML = [
|
|
180
|
+
'<pre id="code-block"><span></span><span class="k">- [x]</span> This is a complete item\n',
|
|
181
|
+
'<span class="k">- [ ]</span> This is an incomplete item\n</pre>',
|
|
182
|
+
].join('');
|
|
183
|
+
|
|
184
|
+
initCrowdIn();
|
|
185
|
+
jest.runAllTimers();
|
|
186
|
+
|
|
187
|
+
const options = globalThis.proxyTranslator.init.mock.calls[0][0];
|
|
188
|
+
const codeBlock = globalThis.document.getElementById('code-block');
|
|
189
|
+
const firstLineText = codeBlock.querySelector('.k').nextSibling;
|
|
190
|
+
|
|
191
|
+
firstLineText.data = firstLineText.data.trim();
|
|
192
|
+
options.callback();
|
|
193
|
+
|
|
194
|
+
expect(codeBlock.textContent).toBe(
|
|
195
|
+
'- [x] This is a complete item\n- [ ] This is an incomplete item\n'
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
|
|
178
199
|
it('should restore whitespace after later asynchronous DOM changes', async () => {
|
|
179
200
|
globalThis.document.body.innerHTML = '<p id="translated">Use <a href="#">this link</a> here.</p>';
|
|
180
201
|
|