Deploying to gh-pages from @ fishjar/kiss-translator@13e7c1b754 🚀

This commit is contained in:
fishjar
2023-08-29 09:37:31 +00:00
parent 2f28fac3aa
commit 609914b750

View File

@@ -28236,11 +28236,11 @@ function LoadingIcon(){return/*#__PURE__*/(0,jsx_runtime.jsxs)("svg",{viewBox:"0
*/function useTranslate(q,rule){var _useState=(0,react.useState)(""),_useState2=(0,slicedToArray/* default */.Z)(_useState,2),text=_useState2[0],setText=_useState2[1];var _useState3=(0,react.useState)(false),_useState4=(0,slicedToArray/* default */.Z)(_useState3,2),loading=_useState4[0],setLoading=_useState4[1];var _useState5=(0,react.useState)(false),_useState6=(0,slicedToArray/* default */.Z)(_useState5,2),sameLang=_useState6[0],setSamelang=_useState6[1];var translator=rule.translator,fromLang=rule.fromLang,toLang=rule.toLang;(0,react.useEffect)(function(){asyncToGenerator_asyncToGenerator(/*#__PURE__*/regeneratorRuntime_regeneratorRuntime().mark(function _callee(){var deLang,_yield$apiTranslate,_yield$apiTranslate2,trText,isSame;return regeneratorRuntime_regeneratorRuntime().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:_context.prev=0;setLoading(true);_context.next=4;return detectLang(q);case 4:deLang=_context.sent;if(!toLang.includes(deLang)){_context.next=9;break;}setSamelang(true);_context.next=17;break;case 9:_context.next=11;return apiTranslate({translator:translator,q:q,fromLang:fromLang,toLang:toLang});case 11:_yield$apiTranslate=_context.sent;_yield$apiTranslate2=(0,slicedToArray/* default */.Z)(_yield$apiTranslate,2);trText=_yield$apiTranslate2[0];isSame=_yield$apiTranslate2[1];setText(trText);setSamelang(isSame);case 17:_context.next=22;break;case 19:_context.prev=19;_context.t0=_context["catch"](0);console.log("[translate]",_context.t0);case 22:_context.prev=22;setLoading(false);return _context.finish(22);case 25:case"end":return _context.stop();}},_callee,null,[[0,19,22,25]]);}))();},[q,translator,fromLang,toLang]);return{text:text,sameLang:sameLang,loading:loading};}
;// CONCATENATED MODULE: ./src/views/Content/index.js
function Content(_ref){var q=_ref.q,translator=_ref.translator;var _useState=(0,react.useState)(translator.rule),_useState2=(0,slicedToArray/* default */.Z)(_useState,2),rule=_useState2[0],setRule=_useState2[1];var _useState3=(0,react.useState)(false),_useState4=(0,slicedToArray/* default */.Z)(_useState3,2),hover=_useState4[0],setHover=_useState4[1];var _useTranslate=useTranslate(q,rule),text=_useTranslate.text,sameLang=_useTranslate.sameLang,loading=_useTranslate.loading;var textStyle=rule.textStyle,bgColor=rule.bgColor;var handleMouseEnter=function handleMouseEnter(){setHover(true);};var handleMouseLeave=function handleMouseLeave(){setHover(false);};var handleKissEvent=function handleKissEvent(e){var _e$detail=e.detail,action=_e$detail.action,args=_e$detail.args;switch(action){case MSG_TRANS_CURRULE:setRule(args);break;default:// console.log(`[popup] kissEvent action skip: ${action}`);
}};(0,react.useEffect)(function(){window.addEventListener(EVENT_KISS,handleKissEvent);return function(){window.removeEventListener(EVENT_KISS,handleKissEvent);};},[]);var style=(0,react.useMemo)(function(){var lineColor=bgColor||"";switch(textStyle){case OPT_STYLE_LINE:// 下划线
return{opacity:hover?1:0.6,textDecoration:"underline 2px ".concat(lineColor),WebkitTextDecoration:"underline 2px ".concat(lineColor),textUnderlineOffset:"0.3em"};case OPT_STYLE_DOTLINE:// 点状线
return{opacity:hover?1:0.6,textDecoration:"dotted underline 2px ".concat(lineColor),WebkitTextDecoration:"dotted underline 2px ".concat(lineColor),textUnderlineOffset:"0.3em"};case OPT_STYLE_DASHLINE:// 虚线
return{opacity:hover?1:0.6,textDecoration:"dashed underline 2px ".concat(lineColor),WebkitTextDecoration:"dashed underline 2px ".concat(lineColor),textUnderlineOffset:"0.3em"};case OPT_STYLE_WAVYLINE:// 波浪线
return{opacity:hover?1:0.6,textDecoration:"wavy underline 2px ".concat(lineColor),WebkitTextDecoration:"wavy underline 2px ".concat(lineColor),textUnderlineOffset:"0.3em"};case OPT_STYLE_FUZZY:// 模糊
}};(0,react.useEffect)(function(){window.addEventListener(EVENT_KISS,handleKissEvent);return function(){window.removeEventListener(EVENT_KISS,handleKissEvent);};},[]);var style=(0,react.useMemo)(function(){var lineColor=bgColor||"";var underlineStyle=function underlineStyle(st){return{opacity:hover?1:0.6,textDecorationLine:"underline",textDecorationColor:lineColor,textDecorationStyle:st,textDecorationThickness:"2px",textUnderlineOffset:"0.3em",WebkittextDecorationLine:"underline",WebkittextDecorationColor:lineColor,WebkittextDecorationStyle:st,WebkittextDecorationThickness:"2px",WebkittextTextUnderlineOffset:"0.3em"};};switch(textStyle){case OPT_STYLE_LINE:// 下划线
return underlineStyle("solid");case OPT_STYLE_DOTLINE:// 点状线
return underlineStyle("dotted");case OPT_STYLE_DASHLINE:// 虚线
return underlineStyle("dashed");case OPT_STYLE_WAVYLINE:// 波浪线
return underlineStyle("wavy");case OPT_STYLE_FUZZY:// 模糊
return{filter:hover?"none":"blur(5px)",transition:"filter 0.2s ease-in-out"};case OPT_STYLE_HIGHTLIGHT:// 高亮
return{color:"#FFF",backgroundColor:bgColor||DEFAULT_COLOR};default:return{};}},[textStyle,hover,bgColor]);if(loading){return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[q.length>40?/*#__PURE__*/(0,jsx_runtime.jsx)("br",{}):" ",/*#__PURE__*/(0,jsx_runtime.jsx)(LoadingIcon,{})]});}if(text&&!sameLang){return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[q.length>40?/*#__PURE__*/(0,jsx_runtime.jsx)("br",{}):" ",/*#__PURE__*/(0,jsx_runtime.jsx)("span",{style:style,onMouseEnter:handleMouseEnter,onMouseLeave:handleMouseLeave,children:text})]});}}
;// CONCATENATED MODULE: ./src/libs/translator.js