Commit ·
d9f7125
1
Parent(s): 982847c
added hashchange listener for parent
Browse files- dist/assets/{index-DbyRltTg.js → index-BxDPT5hG.js} +1 -1
- dist/index.html +1 -1
- package.json +1 -1
- src/Translate.tsx +1 -2
dist/assets/{index-DbyRltTg.js → index-BxDPT5hG.js}
RENAMED
|
@@ -121,7 +121,7 @@ Error generating stack: `+l.message+`
|
|
| 121 |
*
|
| 122 |
* This source code is licensed under the ISC license.
|
| 123 |
* See the LICENSE file in the root directory of this source tree.
|
| 124 |
-
*/const RE=[["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],UE=Ki("trash",RE),Sh=(...e)=>e.map(n=>typeof n=="string"?n:Object.entries(n||{}).filter(([,r])=>r).map(([r])=>r).join(" ")).filter(n=>n!=="").join(" ");function rg({variant:e="primary",icon:n,iconPosition:r="left",children:s,className:o="",...c}){const u="inline-flex items-center justify-center font-medium text-sm transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2",d={primary:"bg-primary text-primary-foreground hover:bg-primary-600 active:bg-primary-700 rounded-md shadow-sm hover:shadow focus:ring-primary/50",outlined:"bg-transparent text-primary hover:bg-muted active:bg-primary-50 border border-border rounded-[48px] focus:ring-primary/30",pill:"bg-transparent text-primary hover:bg-primary-50 active:bg-muted border border-border rounded-[48px] focus:ring-primary/30","pill-selected":"bg-primary-100 text-primary-800 hover:bg-primary-200 active:bg-primary-200 border border-primary-100 rounded-[48px] shadow-sm focus:ring-primary-800/30",text:"bg-transparent text-primary hover:bg-muted active:bg-primary-50 rounded-md focus:ring-primary/30",ghost:"bg-transparent text-muted-foreground hover:bg-muted hover:text-primary active:bg-primary-50 rounded-md focus:ring-primary/30"},h={primary:"[padding:0.625em_1.5em] [gap:0.5em]",outlined:"[padding:0.5em_0.75em] [gap:0.5em]",pill:"[padding:0.5em_0.75em] [gap:0.5em]","pill-selected":"[padding:0.5em_0.75em] [gap:0.5em]",text:"[padding:0.375em_0.5em] [gap:0.5em]",ghost:"[padding:0.5em_0.75em] [gap:0.5em]"};return _e.jsxs("button",{className:Sh("cursor-pointer",u,d[e],h[e],"disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-current disabled:hover:shadow-none",o),...c,children:[n&&r==="left"&&_e.jsx(n,{className:"[width:1.25em] [height:1.25em]"}),s,n&&r==="right"&&_e.jsx(n,{className:"[width:1.25em] [height:1.25em]"})]})}function xb({variant:e="default",error:n=!1,className:r="",value:s,...o}){const c="w-full font-sans transition-all duration-200 resize-none focus:outline-none",u={default:"px-4 py-3 border border-border rounded-md bg-white hover:border-primary-300 focus:border-primary focus:ring-2 focus:ring-primary/20",minimal:"px-4 py-3 border-0 bg-transparent hover:bg-muted/30 focus:bg-white focus:shadow-sm rounded-md"},d=n?"border-destructive focus:border-destructive focus:ring-destructive/20":"",h="disabled:cursor-default",p=Mt.useMemo(()=>{const g=typeof s=="string"?s.length:0;return console.log(g),g===0||g<50?"text-2xl":g<200?"text-xl":g<300?"text-lg":"text-base"},[s]);return _e.jsx("textarea",{className:Sh(c,u[e],d,h,p,r),value:s,...o})}function IE({size:e=20,className:n=""}){return _e.jsx(FE,{className:`animate-spin text-primary ${n}`,style:{width:e,height:e}})}const Mg=[{code:"ar_EG",name:"Arabic (Egypt)"},{code:"ar_SA",name:"Arabic (Saudi Arabia)"},{code:"bg_BG",name:"Bulgarian"},{code:"bn_IN",name:"Bengali"},{code:"ca_ES",name:"Catalan"},{code:"cs_CZ",name:"Czech"},{code:"da_DK",name:"Danish"},{code:"de_DE",name:"German"},{code:"el_GR",name:"Greek"},{code:"en",name:"English"},{code:"es_XX",name:"Spanish"},{code:"et_EE",name:"Estonian"},{code:"fa_IR",name:"Persian"},{code:"fi_FI",name:"Finnish"},{code:"fil_PH",name:"Filipino"},{code:"fr_CA",name:"French (Canada)"},{code:"fr_FR",name:"French"},{code:"gu_IN",name:"Gujarati"},{code:"he_IL",name:"Hebrew"},{code:"hi_IN",name:"Hindi"},{code:"hr_HR",name:"Croatian"},{code:"hu_HU",name:"Hungarian"},{code:"id_ID",name:"Indonesian"},{code:"is_IS",name:"Icelandic"},{code:"it_IT",name:"Italian"},{code:"ja_JP",name:"Japanese"},{code:"kn_IN",name:"Kannada"},{code:"ko_KR",name:"Korean"},{code:"lt_LT",name:"Lithuanian"},{code:"lv_LV",name:"Latvian"},{code:"ml_IN",name:"Malayalam"},{code:"mr_IN",name:"Marathi"},{code:"nl_NL",name:"Dutch"},{code:"no_NO",name:"Norwegian"},{code:"pa_IN",name:"Punjabi"},{code:"pl_PL",name:"Polish"},{code:"pt_BR",name:"Portuguese (Brazil)"},{code:"pt_PT",name:"Portuguese (Portugal)"},{code:"ro_RO",name:"Romanian"},{code:"ru_RU",name:"Russian"},{code:"sk_SK",name:"Slovak"},{code:"sl_SI",name:"Slovenian"},{code:"sr_RS",name:"Serbian"},{code:"sv_SE",name:"Swedish"},{code:"sw_KE",name:"Swahili"},{code:"sw_TZ",name:"Swahili (Tanzania)"},{code:"ta_IN",name:"Tamil"},{code:"te_IN",name:"Telugu"},{code:"th_TH",name:"Thai"},{code:"tr_TR",name:"Turkish"},{code:"uk_UA",name:"Ukrainian"},{code:"ur_PK",name:"Urdu"},{code:"vi_VN",name:"Vietnamese"},{code:"zh_CN",name:"Chinese (Simplified)"},{code:"zh_TW",name:"Chinese (Traditional)"},{code:"zu_ZA",name:"Zulu"}],GE=[{code:"auto",name:"Auto"},...Mg];function Tb({value:e,onChange:n,includeAuto:r=!1}){const[s,o]=Mt.useState(!1),[c,u]=Mt.useState(""),d=Mt.useRef(null),h=Mt.useRef(null),p=r?GE:Mg,g=S=>{var E;return((E=p.find(O=>O.code===S))==null?void 0:E.name)||S},w=c?(S=>{const E=S.toLowerCase();return p.filter(O=>O.name.toLowerCase().includes(E)||O.code.toLowerCase().includes(E))})(c):p,b=S=>{n(S),o(!1),u("")};return Mt.useEffect(()=>{const S=E=>{d.current&&!d.current.contains(E.target)&&(o(!1),u(""))};return s&&(document.addEventListener("mousedown",S),setTimeout(()=>{var E;return(E=h.current)==null?void 0:E.focus()},0)),()=>{document.removeEventListener("mousedown",S)}},[s]),_e.jsxs("div",{className:"relative",ref:d,children:[_e.jsxs("button",{onClick:()=>o(!s),className:"inline-flex items-center gap-2 px-3 py-2 text-sm font-medium text-primary hover:bg-muted rounded-md transition-colors",children:[_e.jsx("span",{children:g(e)}),_e.jsx(zE,{className:`w-4 h-4 transition-transform ${s?"rotate-180":""}`})]}),s&&_e.jsxs("div",{className:"absolute top-full left-0 mt-2 w-64 bg-white border border-border rounded-md shadow-lg z-50",children:[_e.jsx("div",{className:"p-2 border-b border-border",children:_e.jsx("input",{ref:h,type:"text",placeholder:"Search languages...",value:c,onChange:S=>u(S.target.value),className:"w-full px-3 py-2 text-sm border border-border rounded-md focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"})}),_e.jsxs("div",{className:"max-h-60 overflow-auto",children:[w.map(S=>_e.jsx("button",{onClick:()=>b(S.code),className:`w-full px-3 py-2 text-left text-sm hover:bg-muted transition-colors ${e===S.code?"bg-primary-50 text-primary-800":""}`,children:S.name},S.code)),w.length===0&&_e.jsx("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:"No languages found"})]})]})]})}function jE(e,n=1){const s=["Bytes","KB","MB","GB","TB","PB"],o=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,o)).toFixed(n))}${s[o]}`}function VE(e){if(e<1e3)return`${Math.round(e)}ms`;const n=e/1e3;if(n<60)return`${n.toFixed(1)}s`;const r=Math.floor(n/60),s=Math.round(n%60);return`${r}m ${s}s`}function Xm(e){return new Intl.NumberFormat("en-US").format(e)}function qE(e){return!e||e.trim().length===0?0:e.trim().split(/\s+/).filter(r=>r.length>0).length}const Sb=1e3;function $E({className:e="",translator:n}){const s=(()=>{const me=window.location.hash.slice(1),pe=new URLSearchParams(me),ne=pe.get("sl"),ee=pe.get("tl"),Me=pe.get("text"),V=W=>W?Mg.some(I=>I.code===W):!1;return{sourceLanguage:V(ne)?ne:"en",targetLanguage:V(ee)?ee:"de_DE",sourceText:Me?decodeURIComponent(Me):""}})(),[o,c]=Mt.useState(s.sourceText),[u,d]=Mt.useState(""),[h,p]=Mt.useState(s.sourceLanguage),[g,y]=Mt.useState(s.targetLanguage),[w,b]=Mt.useState(!1),[S,E]=Mt.useState(!1),[O,z]=Mt.useState(!1),D=Mt.useRef(null),[P,j]=Mt.useState(0),[G,K]=Mt.useState(0),k=()=>{p(g),y(h),c(u),d(o)},ce=async()=>{if(u)try{await navigator.clipboard.writeText(u),E(!0),setTimeout(()=>E(!1),2e3)}catch(me){console.error("Failed to copy:",me)}},oe=async()=>{try{const me=window.location.href;await navigator.clipboard.writeText(me),z(!0),setTimeout(()=>z(!1),2e3)}catch(me){console.error("Failed to share:",me)}},he=async(me,pe,ne)=>{if(!me.trim()){d(""),j(0),K(0);return}const ee=performance.now();D.current&&D.current.abort(),D.current=new AbortController;const Me=D.current;b(!0);try{const V=await n.translate(me,pe,ne);Me.signal.aborted||(d(V),j(Math.round(performance.now()-ee)),K(qE(me)))}catch(V){Me.signal.aborted||console.error("Translation error:",V)}finally{Me.signal.aborted||b(!1)}};return Mt.useEffect(()=>{const me=new URLSearchParams;me.set("sl",h),me.set("tl",g),o&&me.set("text",encodeURIComponent(o));const pe=`#${me.toString()}`;window.history.replaceState({},"",pe)},[h,g,o]),Mt.useEffect(()=>{const me=setTimeout(()=>{he(o,h,g)},500);return()=>{clearTimeout(me)}},[o,h,g]),_e.jsx("div",{className:Sh("max-w-6xl mx-auto p-2 md:p-4 relative",e),children:_e.jsxs("div",{className:"flex flex-col md:flex-row w-full gap-4 md:gap-8",children:[_e.jsxs("div",{className:"flex flex-col gap-3 w-full md:w-1/2 relative",children:[_e.jsx(Tb,{value:h,onChange:p}),_e.jsx(xb,{value:o,onChange:me=>c(me.target.value),placeholder:"Enter text to translate...",className:"h-48 md:h-70 pb-10",variant:"default",maxLength:Sb}),_e.jsxs("div",{className:"p-2 flex justify-between items-center -mt-4",children:[_e.jsxs("p",{className:"text-xs text-muted-foreground opacity-70",children:[Xm(o.length)," /"," ",Xm(Sb)]}),_e.jsxs("div",{className:"flex gap-2",children:[_e.jsx("button",{onClick:oe,className:"p-2 text-muted-foreground hover:text-primary hover:bg-muted rounded-md transition-colors","aria-label":"Share translation",children:O?_e.jsxs("span",{className:"flex text-xs gap-2",children:["link copied",_e.jsx(Mb,{className:"w-4 h-4 text-primary"})]}):_e.jsx(PE,{className:"w-4 h-4"})}),_e.jsx("button",{onClick:()=>c(""),className:"p-2 text-muted-foreground hover:text-primary hover:bg-muted rounded-md transition-colors","aria-label":"clear text",children:_e.jsx(UE,{className:"w-4 h-4"})})]})]})]}),_e.jsx("div",{className:"hidden md:block absolute left-1/2 top-5 -translate-x-1/2",children:_e.jsx(rg,{variant:"ghost",icon:bb,onClick:k,"aria-label":"Swap languages"})}),_e.jsx("div",{className:"flex md:hidden justify-center -my-2",children:_e.jsx(rg,{variant:"ghost",icon:bb,onClick:k,"aria-label":"Swap languages",className:"rotate-90"})}),_e.jsxs("div",{className:"flex flex-col gap-3 w-full md:w-1/2",children:[_e.jsxs("div",{className:"flex items-center justify-between",children:[_e.jsx(Tb,{value:g,onChange:y}),w&&_e.jsx(IE,{size:20})]}),_e.jsxs("div",{children:[_e.jsx(xb,{value:u,disabled:!0,placeholder:"Translation will appear here...",className:"h-48 md:h-70",variant:"default"}),_e.jsxs("div",{className:"p-2 flex justify-between items-center -mt-4",children:[P>0?_e.jsxs("p",{className:"text-xs text-muted-foreground opacity-70",children:["Translated ",_e.jsxs("b",{children:[Xm(G)," words"]})," in"," ",_e.jsx("b",{children:VE(P)})]}):_e.jsx("p",{}),_e.jsx("div",{children:_e.jsx("button",{onClick:ce,className:"p-2 text-muted-foreground hover:text-primary hover:bg-muted rounded-md transition-colors","aria-label":"Copy translation",children:S?_e.jsxs("span",{className:"flex text-xs gap-2",children:["translation copied",_e.jsx(Mb,{className:"w-4 h-4 text-primary"})]}):_e.jsx(NE,{className:"w-4 h-4"})})})]})]})]})]})})}/*!
|
| 125 |
* ONNX Runtime Web v1.25.0-dev.20260212-1a71a5f46e
|
| 126 |
* Copyright (c) Microsoft Corporation. All rights reserved.
|
| 127 |
* Licensed under the MIT License.
|
|
|
|
| 121 |
*
|
| 122 |
* This source code is licensed under the ISC license.
|
| 123 |
* See the LICENSE file in the root directory of this source tree.
|
| 124 |
+
*/const RE=[["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],UE=Ki("trash",RE),Sh=(...e)=>e.map(n=>typeof n=="string"?n:Object.entries(n||{}).filter(([,r])=>r).map(([r])=>r).join(" ")).filter(n=>n!=="").join(" ");function rg({variant:e="primary",icon:n,iconPosition:r="left",children:s,className:o="",...c}){const u="inline-flex items-center justify-center font-medium text-sm transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2",d={primary:"bg-primary text-primary-foreground hover:bg-primary-600 active:bg-primary-700 rounded-md shadow-sm hover:shadow focus:ring-primary/50",outlined:"bg-transparent text-primary hover:bg-muted active:bg-primary-50 border border-border rounded-[48px] focus:ring-primary/30",pill:"bg-transparent text-primary hover:bg-primary-50 active:bg-muted border border-border rounded-[48px] focus:ring-primary/30","pill-selected":"bg-primary-100 text-primary-800 hover:bg-primary-200 active:bg-primary-200 border border-primary-100 rounded-[48px] shadow-sm focus:ring-primary-800/30",text:"bg-transparent text-primary hover:bg-muted active:bg-primary-50 rounded-md focus:ring-primary/30",ghost:"bg-transparent text-muted-foreground hover:bg-muted hover:text-primary active:bg-primary-50 rounded-md focus:ring-primary/30"},h={primary:"[padding:0.625em_1.5em] [gap:0.5em]",outlined:"[padding:0.5em_0.75em] [gap:0.5em]",pill:"[padding:0.5em_0.75em] [gap:0.5em]","pill-selected":"[padding:0.5em_0.75em] [gap:0.5em]",text:"[padding:0.375em_0.5em] [gap:0.5em]",ghost:"[padding:0.5em_0.75em] [gap:0.5em]"};return _e.jsxs("button",{className:Sh("cursor-pointer",u,d[e],h[e],"disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-current disabled:hover:shadow-none",o),...c,children:[n&&r==="left"&&_e.jsx(n,{className:"[width:1.25em] [height:1.25em]"}),s,n&&r==="right"&&_e.jsx(n,{className:"[width:1.25em] [height:1.25em]"})]})}function xb({variant:e="default",error:n=!1,className:r="",value:s,...o}){const c="w-full font-sans transition-all duration-200 resize-none focus:outline-none",u={default:"px-4 py-3 border border-border rounded-md bg-white hover:border-primary-300 focus:border-primary focus:ring-2 focus:ring-primary/20",minimal:"px-4 py-3 border-0 bg-transparent hover:bg-muted/30 focus:bg-white focus:shadow-sm rounded-md"},d=n?"border-destructive focus:border-destructive focus:ring-destructive/20":"",h="disabled:cursor-default",p=Mt.useMemo(()=>{const g=typeof s=="string"?s.length:0;return console.log(g),g===0||g<50?"text-2xl":g<200?"text-xl":g<300?"text-lg":"text-base"},[s]);return _e.jsx("textarea",{className:Sh(c,u[e],d,h,p,r),value:s,...o})}function IE({size:e=20,className:n=""}){return _e.jsx(FE,{className:`animate-spin text-primary ${n}`,style:{width:e,height:e}})}const Mg=[{code:"ar_EG",name:"Arabic (Egypt)"},{code:"ar_SA",name:"Arabic (Saudi Arabia)"},{code:"bg_BG",name:"Bulgarian"},{code:"bn_IN",name:"Bengali"},{code:"ca_ES",name:"Catalan"},{code:"cs_CZ",name:"Czech"},{code:"da_DK",name:"Danish"},{code:"de_DE",name:"German"},{code:"el_GR",name:"Greek"},{code:"en",name:"English"},{code:"es_XX",name:"Spanish"},{code:"et_EE",name:"Estonian"},{code:"fa_IR",name:"Persian"},{code:"fi_FI",name:"Finnish"},{code:"fil_PH",name:"Filipino"},{code:"fr_CA",name:"French (Canada)"},{code:"fr_FR",name:"French"},{code:"gu_IN",name:"Gujarati"},{code:"he_IL",name:"Hebrew"},{code:"hi_IN",name:"Hindi"},{code:"hr_HR",name:"Croatian"},{code:"hu_HU",name:"Hungarian"},{code:"id_ID",name:"Indonesian"},{code:"is_IS",name:"Icelandic"},{code:"it_IT",name:"Italian"},{code:"ja_JP",name:"Japanese"},{code:"kn_IN",name:"Kannada"},{code:"ko_KR",name:"Korean"},{code:"lt_LT",name:"Lithuanian"},{code:"lv_LV",name:"Latvian"},{code:"ml_IN",name:"Malayalam"},{code:"mr_IN",name:"Marathi"},{code:"nl_NL",name:"Dutch"},{code:"no_NO",name:"Norwegian"},{code:"pa_IN",name:"Punjabi"},{code:"pl_PL",name:"Polish"},{code:"pt_BR",name:"Portuguese (Brazil)"},{code:"pt_PT",name:"Portuguese (Portugal)"},{code:"ro_RO",name:"Romanian"},{code:"ru_RU",name:"Russian"},{code:"sk_SK",name:"Slovak"},{code:"sl_SI",name:"Slovenian"},{code:"sr_RS",name:"Serbian"},{code:"sv_SE",name:"Swedish"},{code:"sw_KE",name:"Swahili"},{code:"sw_TZ",name:"Swahili (Tanzania)"},{code:"ta_IN",name:"Tamil"},{code:"te_IN",name:"Telugu"},{code:"th_TH",name:"Thai"},{code:"tr_TR",name:"Turkish"},{code:"uk_UA",name:"Ukrainian"},{code:"ur_PK",name:"Urdu"},{code:"vi_VN",name:"Vietnamese"},{code:"zh_CN",name:"Chinese (Simplified)"},{code:"zh_TW",name:"Chinese (Traditional)"},{code:"zu_ZA",name:"Zulu"}],GE=[{code:"auto",name:"Auto"},...Mg];function Tb({value:e,onChange:n,includeAuto:r=!1}){const[s,o]=Mt.useState(!1),[c,u]=Mt.useState(""),d=Mt.useRef(null),h=Mt.useRef(null),p=r?GE:Mg,g=S=>{var E;return((E=p.find(O=>O.code===S))==null?void 0:E.name)||S},w=c?(S=>{const E=S.toLowerCase();return p.filter(O=>O.name.toLowerCase().includes(E)||O.code.toLowerCase().includes(E))})(c):p,b=S=>{n(S),o(!1),u("")};return Mt.useEffect(()=>{const S=E=>{d.current&&!d.current.contains(E.target)&&(o(!1),u(""))};return s&&(document.addEventListener("mousedown",S),setTimeout(()=>{var E;return(E=h.current)==null?void 0:E.focus()},0)),()=>{document.removeEventListener("mousedown",S)}},[s]),_e.jsxs("div",{className:"relative",ref:d,children:[_e.jsxs("button",{onClick:()=>o(!s),className:"inline-flex items-center gap-2 px-3 py-2 text-sm font-medium text-primary hover:bg-muted rounded-md transition-colors",children:[_e.jsx("span",{children:g(e)}),_e.jsx(zE,{className:`w-4 h-4 transition-transform ${s?"rotate-180":""}`})]}),s&&_e.jsxs("div",{className:"absolute top-full left-0 mt-2 w-64 bg-white border border-border rounded-md shadow-lg z-50",children:[_e.jsx("div",{className:"p-2 border-b border-border",children:_e.jsx("input",{ref:h,type:"text",placeholder:"Search languages...",value:c,onChange:S=>u(S.target.value),className:"w-full px-3 py-2 text-sm border border-border rounded-md focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"})}),_e.jsxs("div",{className:"max-h-60 overflow-auto",children:[w.map(S=>_e.jsx("button",{onClick:()=>b(S.code),className:`w-full px-3 py-2 text-left text-sm hover:bg-muted transition-colors ${e===S.code?"bg-primary-50 text-primary-800":""}`,children:S.name},S.code)),w.length===0&&_e.jsx("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:"No languages found"})]})]})]})}function jE(e,n=1){const s=["Bytes","KB","MB","GB","TB","PB"],o=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,o)).toFixed(n))}${s[o]}`}function VE(e){if(e<1e3)return`${Math.round(e)}ms`;const n=e/1e3;if(n<60)return`${n.toFixed(1)}s`;const r=Math.floor(n/60),s=Math.round(n%60);return`${r}m ${s}s`}function Xm(e){return new Intl.NumberFormat("en-US").format(e)}function qE(e){return!e||e.trim().length===0?0:e.trim().split(/\s+/).filter(r=>r.length>0).length}const Sb=1e3;function $E({className:e="",translator:n}){const s=(()=>{const me=window.location.hash.slice(1),pe=new URLSearchParams(me),ne=pe.get("sl"),ee=pe.get("tl"),Me=pe.get("text"),V=W=>W?Mg.some(I=>I.code===W):!1;return{sourceLanguage:V(ne)?ne:"en",targetLanguage:V(ee)?ee:"de_DE",sourceText:Me?decodeURIComponent(Me):""}})(),[o,c]=Mt.useState(s.sourceText),[u,d]=Mt.useState(""),[h,p]=Mt.useState(s.sourceLanguage),[g,y]=Mt.useState(s.targetLanguage),[w,b]=Mt.useState(!1),[S,E]=Mt.useState(!1),[O,z]=Mt.useState(!1),D=Mt.useRef(null),[P,j]=Mt.useState(0),[G,K]=Mt.useState(0),k=()=>{p(g),y(h),c(u),d(o)},ce=async()=>{if(u)try{await navigator.clipboard.writeText(u),E(!0),setTimeout(()=>E(!1),2e3)}catch(me){console.error("Failed to copy:",me)}},oe=async()=>{try{const me=window.location.href;await navigator.clipboard.writeText(me),z(!0),setTimeout(()=>z(!1),2e3)}catch(me){console.error("Failed to share:",me)}},he=async(me,pe,ne)=>{if(!me.trim()){d(""),j(0),K(0);return}const ee=performance.now();D.current&&D.current.abort(),D.current=new AbortController;const Me=D.current;b(!0);try{const V=await n.translate(me,pe,ne);Me.signal.aborted||(d(V),j(Math.round(performance.now()-ee)),K(qE(me)))}catch(V){Me.signal.aborted||console.error("Translation error:",V)}finally{Me.signal.aborted||b(!1)}};return Mt.useEffect(()=>{const me=new URLSearchParams;me.set("sl",h),me.set("tl",g),o&&me.set("text",encodeURIComponent(o)),window.location.hash=`#${me.toString()}`},[h,g,o]),Mt.useEffect(()=>{const me=setTimeout(()=>{he(o,h,g)},500);return()=>{clearTimeout(me)}},[o,h,g]),_e.jsx("div",{className:Sh("max-w-6xl mx-auto p-2 md:p-4 relative",e),children:_e.jsxs("div",{className:"flex flex-col md:flex-row w-full gap-4 md:gap-8",children:[_e.jsxs("div",{className:"flex flex-col gap-3 w-full md:w-1/2 relative",children:[_e.jsx(Tb,{value:h,onChange:p}),_e.jsx(xb,{value:o,onChange:me=>c(me.target.value),placeholder:"Enter text to translate...",className:"h-48 md:h-70 pb-10",variant:"default",maxLength:Sb}),_e.jsxs("div",{className:"p-2 flex justify-between items-center -mt-4",children:[_e.jsxs("p",{className:"text-xs text-muted-foreground opacity-70",children:[Xm(o.length)," /"," ",Xm(Sb)]}),_e.jsxs("div",{className:"flex gap-2",children:[_e.jsx("button",{onClick:oe,className:"p-2 text-muted-foreground hover:text-primary hover:bg-muted rounded-md transition-colors","aria-label":"Share translation",children:O?_e.jsxs("span",{className:"flex text-xs gap-2",children:["link copied",_e.jsx(Mb,{className:"w-4 h-4 text-primary"})]}):_e.jsx(PE,{className:"w-4 h-4"})}),_e.jsx("button",{onClick:()=>c(""),className:"p-2 text-muted-foreground hover:text-primary hover:bg-muted rounded-md transition-colors","aria-label":"clear text",children:_e.jsx(UE,{className:"w-4 h-4"})})]})]})]}),_e.jsx("div",{className:"hidden md:block absolute left-1/2 top-5 -translate-x-1/2",children:_e.jsx(rg,{variant:"ghost",icon:bb,onClick:k,"aria-label":"Swap languages"})}),_e.jsx("div",{className:"flex md:hidden justify-center -my-2",children:_e.jsx(rg,{variant:"ghost",icon:bb,onClick:k,"aria-label":"Swap languages",className:"rotate-90"})}),_e.jsxs("div",{className:"flex flex-col gap-3 w-full md:w-1/2",children:[_e.jsxs("div",{className:"flex items-center justify-between",children:[_e.jsx(Tb,{value:g,onChange:y}),w&&_e.jsx(IE,{size:20})]}),_e.jsxs("div",{children:[_e.jsx(xb,{value:u,disabled:!0,placeholder:"Translation will appear here...",className:"h-48 md:h-70",variant:"default"}),_e.jsxs("div",{className:"p-2 flex justify-between items-center -mt-4",children:[P>0?_e.jsxs("p",{className:"text-xs text-muted-foreground opacity-70",children:["Translated ",_e.jsxs("b",{children:[Xm(G)," words"]})," in"," ",_e.jsx("b",{children:VE(P)})]}):_e.jsx("p",{}),_e.jsx("div",{children:_e.jsx("button",{onClick:ce,className:"p-2 text-muted-foreground hover:text-primary hover:bg-muted rounded-md transition-colors","aria-label":"Copy translation",children:S?_e.jsxs("span",{className:"flex text-xs gap-2",children:["translation copied",_e.jsx(Mb,{className:"w-4 h-4 text-primary"})]}):_e.jsx(NE,{className:"w-4 h-4"})})})]})]})]})]})})}/*!
|
| 125 |
* ONNX Runtime Web v1.25.0-dev.20260212-1a71a5f46e
|
| 126 |
* Copyright (c) Microsoft Corporation. All rights reserved.
|
| 127 |
* Licensed under the MIT License.
|
dist/index.html
CHANGED
|
@@ -43,7 +43,7 @@
|
|
| 43 |
href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap"
|
| 44 |
rel="stylesheet"
|
| 45 |
/>
|
| 46 |
-
<script type="module" crossorigin src="/assets/index-
|
| 47 |
<link rel="stylesheet" crossorigin href="/assets/index-ChiydTZJ.css">
|
| 48 |
</head>
|
| 49 |
<body>
|
|
|
|
| 43 |
href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap"
|
| 44 |
rel="stylesheet"
|
| 45 |
/>
|
| 46 |
+
<script type="module" crossorigin src="/assets/index-BxDPT5hG.js"></script>
|
| 47 |
<link rel="stylesheet" crossorigin href="/assets/index-ChiydTZJ.css">
|
| 48 |
</head>
|
| 49 |
<body>
|
package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"name": "transformersjs-translategemma",
|
| 3 |
"private": true,
|
| 4 |
-
"version": "0.0.
|
| 5 |
"type": "module",
|
| 6 |
"scripts": {
|
| 7 |
"dev": "vite",
|
|
|
|
| 1 |
{
|
| 2 |
"name": "transformersjs-translategemma",
|
| 3 |
"private": true,
|
| 4 |
+
"version": "0.0.2",
|
| 5 |
"type": "module",
|
| 6 |
"scripts": {
|
| 7 |
"dev": "vite",
|
src/Translate.tsx
CHANGED
|
@@ -150,8 +150,7 @@ export default function Translate({
|
|
| 150 |
params.set("text", encodeURIComponent(sourceText));
|
| 151 |
}
|
| 152 |
|
| 153 |
-
|
| 154 |
-
window.history.replaceState({}, "", newHash);
|
| 155 |
}, [sourceLanguage, targetLanguage, sourceText]);
|
| 156 |
|
| 157 |
useEffect(() => {
|
|
|
|
| 150 |
params.set("text", encodeURIComponent(sourceText));
|
| 151 |
}
|
| 152 |
|
| 153 |
+
window.location.hash = `#${params.toString()}`;
|
|
|
|
| 154 |
}, [sourceLanguage, targetLanguage, sourceText]);
|
| 155 |
|
| 156 |
useEffect(() => {
|