@cnc_cbz/usefultools-plugin-official 1.0.5 → 1.0.6

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.
Files changed (2) hide show
  1. package/dist/translator.mjs +98 -43
  2. package/package.json +1 -1
@@ -28,27 +28,32 @@ const _hoisted_14 = {
28
28
  };
29
29
  const _hoisted_15 = { class: "flex-1 grid grid-cols-1 lg:grid-cols-2 gap-4 min-h-0" };
30
30
  const _hoisted_16 = { class: "flex flex-col min-h-0" };
31
- const _hoisted_17 = { class: "flex flex-col min-h-0" };
32
- const _hoisted_18 = { class: "flex items-center gap-2 mb-2" };
33
- const _hoisted_19 = { class: "material-icons text-sm" };
34
- const _hoisted_20 = { class: "flex-1 w-full bg-deep-charcoal border-4 border-black rounded-xl p-4 overflow-auto shadow-hard min-h-[200px] text-sm leading-relaxed flex flex-col" };
35
- const _hoisted_21 = {
31
+ const _hoisted_17 = ["placeholder"];
32
+ const _hoisted_18 = { class: "flex flex-col min-h-0" };
33
+ const _hoisted_19 = { class: "flex items-center gap-2 mb-2" };
34
+ const _hoisted_20 = { class: "material-icons text-sm" };
35
+ const _hoisted_21 = { class: "flex-1 w-full bg-deep-charcoal border-4 border-black rounded-xl p-4 overflow-auto shadow-hard min-h-[200px] text-sm leading-relaxed flex flex-col" };
36
+ const _hoisted_22 = {
36
37
  key: 0,
37
- class: "text-gray-600"
38
+ class: "text-gray-400 flex items-center gap-2"
38
39
  };
39
- const _hoisted_22 = {
40
+ const _hoisted_23 = {
40
41
  key: 1,
42
+ class: "text-gray-600"
43
+ };
44
+ const _hoisted_24 = {
45
+ key: 2,
41
46
  class: "text-gray-100 whitespace-pre-wrap"
42
47
  };
43
- const _hoisted_23 = {
48
+ const _hoisted_25 = {
44
49
  key: 0,
45
50
  class: "fixed inset-0 z-50 flex items-center justify-center"
46
51
  };
47
- const _hoisted_24 = { class: "relative w-full max-w-lg bg-deep-charcoal border-4 border-black rounded-xl shadow-hard-xl p-6 flex flex-col gap-4" };
48
- const _hoisted_25 = { class: "flex items-center gap-2" };
49
- const _hoisted_26 = { class: "flex flex-col gap-1.5" };
50
- const _hoisted_27 = { class: "flex flex-col gap-1.5" };
51
- const _hoisted_28 = { class: "flex justify-end gap-3 mt-1" };
52
+ const _hoisted_26 = { class: "relative w-full max-w-lg bg-deep-charcoal border-4 border-black rounded-xl shadow-hard-xl p-6 flex flex-col gap-4" };
53
+ const _hoisted_27 = { class: "flex items-center gap-2" };
54
+ const _hoisted_28 = { class: "flex flex-col gap-1.5" };
55
+ const _hoisted_29 = { class: "flex flex-col gap-1.5" };
56
+ const _hoisted_30 = { class: "flex justify-end gap-3 mt-1" };
52
57
  const GOOGLE_KEY = "translator-google-api-key";
53
58
  const AI_KEY = "translator-ai-api-key";
54
59
  const AI_MODEL_KEY = "translator-ai-model";
@@ -250,6 +255,48 @@ ${sourceText.value}`;
250
255
  copySuccess.value = false;
251
256
  }, 1500);
252
257
  }
258
+ function detectAndSwitchTarget(text) {
259
+ if (sourceLang.value !== "auto") return;
260
+ const stripped = text.replace(/\s+/g, "");
261
+ if (!stripped) return;
262
+ const cjkCount = (stripped.match(/[\u4e00-\u9fff]/g) || []).length;
263
+ const ratio = cjkCount / stripped.length;
264
+ const newTarget = ratio > 0.3 ? "en" : "zh-CN";
265
+ if (targetLang.value !== newTarget) targetLang.value = newTarget;
266
+ }
267
+ let googleDebounceTimer = null;
268
+ function triggerGoogleAuto() {
269
+ if (engine.value !== "google") return;
270
+ if (googleDebounceTimer) clearTimeout(googleDebounceTimer);
271
+ if (!sourceText.value.trim()) {
272
+ translatedText.value = "";
273
+ loading.value = false;
274
+ return;
275
+ }
276
+ loading.value = true;
277
+ translatedText.value = "";
278
+ errorMsg.value = "";
279
+ googleDebounceTimer = setTimeout(async () => {
280
+ try {
281
+ await translateGoogle();
282
+ } catch (e) {
283
+ errorMsg.value = e.message || "翻译失败";
284
+ } finally {
285
+ loading.value = false;
286
+ }
287
+ }, 500);
288
+ }
289
+ watch(sourceText, (val) => {
290
+ detectAndSwitchTarget(val);
291
+ triggerGoogleAuto();
292
+ });
293
+ watch([sourceLang, targetLang], () => triggerGoogleAuto());
294
+ function onTextareaKeydown(e) {
295
+ if (engine.value === "ai" && e.key === "Enter" && !e.shiftKey) {
296
+ e.preventDefault();
297
+ translate();
298
+ }
299
+ }
253
300
  return (_ctx, _cache) => {
254
301
  return openBlock(), createElementBlock("div", _hoisted_1, [
255
302
  createCommentVNode(" Toolbar "),
@@ -486,24 +533,19 @@ ${sourceText.value}`;
486
533
  -1
487
534
  /* CACHED */
488
535
  )),
489
- withDirectives(createElementVNode(
490
- "textarea",
491
- {
492
- "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => sourceText.value = $event),
493
- spellcheck: "false",
494
- placeholder: "在此输入要翻译的文本...",
495
- class: "flex-1 w-full bg-deep-charcoal text-gray-100 border-4 border-black rounded-xl p-4 font-mono text-sm leading-relaxed resize-none shadow-hard focus:border-primary focus:shadow-none focus:translate-x-[4px] focus:translate-y-[4px] transition-all outline-none placeholder-gray-600 min-h-[200px]"
496
- },
497
- null,
498
- 512
499
- /* NEED_PATCH */
500
- ), [
536
+ withDirectives(createElementVNode("textarea", {
537
+ "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => sourceText.value = $event),
538
+ spellcheck: "false",
539
+ placeholder: engine.value === "google" ? "输入文本自动翻译..." : "在此输入要翻译的文本...\nEnter 翻译 / Shift+Enter 换行",
540
+ class: "flex-1 w-full bg-deep-charcoal text-gray-100 border-4 border-black rounded-xl p-4 font-mono text-sm leading-relaxed resize-none shadow-hard focus:border-primary focus:shadow-none focus:translate-x-[4px] focus:translate-y-[4px] transition-all outline-none placeholder-gray-600 min-h-[200px]",
541
+ onKeydown: onTextareaKeydown
542
+ }, null, 40, _hoisted_17), [
501
543
  [vModelText, sourceText.value]
502
544
  ])
503
545
  ]),
504
546
  createCommentVNode(" 翻译结果 "),
505
- createElementVNode("div", _hoisted_17, [
506
- createElementVNode("div", _hoisted_18, [
547
+ createElementVNode("div", _hoisted_18, [
548
+ createElementVNode("div", _hoisted_19, [
507
549
  _cache[18] || (_cache[18] = createElementVNode(
508
550
  "span",
509
551
  { class: "material-icons text-neon-green text-lg" },
@@ -528,7 +570,7 @@ ${sourceText.value}`;
528
570
  [
529
571
  createElementVNode(
530
572
  "span",
531
- _hoisted_19,
573
+ _hoisted_20,
532
574
  toDisplayString(copySuccess.value ? "check_circle" : "content_copy"),
533
575
  1
534
576
  /* TEXT */
@@ -543,10 +585,23 @@ ${sourceText.value}`;
543
585
  /* CLASS */
544
586
  )) : createCommentVNode("v-if", true)
545
587
  ]),
546
- createElementVNode("div", _hoisted_20, [
547
- !translatedText.value ? (openBlock(), createElementBlock("div", _hoisted_21, " 翻译结果将显示在这里... ")) : (openBlock(), createElementBlock(
588
+ createElementVNode("div", _hoisted_21, [
589
+ loading.value && engine.value === "google" ? (openBlock(), createElementBlock("div", _hoisted_22, [..._cache[20] || (_cache[20] = [
590
+ createElementVNode(
591
+ "span",
592
+ { class: "material-icons text-primary text-base animate-spin" },
593
+ "hourglass_top",
594
+ -1
595
+ /* CACHED */
596
+ ),
597
+ createTextVNode(
598
+ " 翻译中... ",
599
+ -1
600
+ /* CACHED */
601
+ )
602
+ ])])) : !translatedText.value ? (openBlock(), createElementBlock("div", _hoisted_23, " 翻译结果将显示在这里... ")) : (openBlock(), createElementBlock(
548
603
  "div",
549
- _hoisted_22,
604
+ _hoisted_24,
550
605
  toDisplayString(translatedText.value),
551
606
  1
552
607
  /* TEXT */
@@ -556,21 +611,21 @@ ${sourceText.value}`;
556
611
  ]),
557
612
  createCommentVNode(" API Key 设置弹窗 "),
558
613
  (openBlock(), createBlock(Teleport, { to: "body" }, [
559
- showSettings.value ? (openBlock(), createElementBlock("div", _hoisted_23, [
614
+ showSettings.value ? (openBlock(), createElementBlock("div", _hoisted_25, [
560
615
  createElementVNode("div", {
561
616
  class: "absolute inset-0 bg-black/60",
562
617
  onClick: _cache[6] || (_cache[6] = ($event) => showSettings.value = false)
563
618
  }),
564
- createElementVNode("div", _hoisted_24, [
565
- createElementVNode("div", _hoisted_25, [
566
- _cache[21] || (_cache[21] = createElementVNode(
619
+ createElementVNode("div", _hoisted_26, [
620
+ createElementVNode("div", _hoisted_27, [
621
+ _cache[22] || (_cache[22] = createElementVNode(
567
622
  "span",
568
623
  { class: "material-icons text-primary text-xl" },
569
624
  "key",
570
625
  -1
571
626
  /* CACHED */
572
627
  )),
573
- _cache[22] || (_cache[22] = createElementVNode(
628
+ _cache[23] || (_cache[23] = createElementVNode(
574
629
  "span",
575
630
  { class: "text-lg font-bold text-white" },
576
631
  "配置 API Key",
@@ -580,7 +635,7 @@ ${sourceText.value}`;
580
635
  createElementVNode("button", {
581
636
  class: "ml-auto w-8 h-8 flex items-center justify-center text-gray-400 hover:text-white transition-colors",
582
637
  onClick: _cache[7] || (_cache[7] = ($event) => showSettings.value = false)
583
- }, [..._cache[20] || (_cache[20] = [
638
+ }, [..._cache[21] || (_cache[21] = [
584
639
  createElementVNode(
585
640
  "span",
586
641
  { class: "material-icons" },
@@ -591,8 +646,8 @@ ${sourceText.value}`;
591
646
  ])])
592
647
  ]),
593
648
  createCommentVNode(" Google API Key "),
594
- createElementVNode("div", _hoisted_26, [
595
- _cache[23] || (_cache[23] = createElementVNode(
649
+ createElementVNode("div", _hoisted_28, [
650
+ _cache[24] || (_cache[24] = createElementVNode(
596
651
  "label",
597
652
  { class: "text-xs font-bold text-gray-400 uppercase tracking-wider" },
598
653
  "Google Translation API Key",
@@ -615,8 +670,8 @@ ${sourceText.value}`;
615
670
  ])
616
671
  ]),
617
672
  createCommentVNode(" SiliconFlow API Key "),
618
- createElementVNode("div", _hoisted_27, [
619
- _cache[24] || (_cache[24] = createElementVNode(
673
+ createElementVNode("div", _hoisted_29, [
674
+ _cache[25] || (_cache[25] = createElementVNode(
620
675
  "label",
621
676
  { class: "text-xs font-bold text-gray-400 uppercase tracking-wider" },
622
677
  "SiliconFlow API Key(AI 翻译)",
@@ -637,7 +692,7 @@ ${sourceText.value}`;
637
692
  ), [
638
693
  [vModelText, aiKeyInput.value]
639
694
  ]),
640
- _cache[25] || (_cache[25] = createElementVNode(
695
+ _cache[26] || (_cache[26] = createElementVNode(
641
696
  "p",
642
697
  { class: "text-[11px] text-gray-600" },
643
698
  "密钥从 cloud.siliconflow.cn 获取,保存后可在工具栏选择模型",
@@ -645,7 +700,7 @@ ${sourceText.value}`;
645
700
  /* CACHED */
646
701
  ))
647
702
  ]),
648
- createElementVNode("div", _hoisted_28, [
703
+ createElementVNode("div", _hoisted_30, [
649
704
  createElementVNode("button", {
650
705
  class: "px-4 py-2 bg-white/10 text-gray-300 font-bold border-2 border-white/20 rounded hover:border-white hover:text-white transition-all text-sm",
651
706
  onClick: _cache[10] || (_cache[10] = ($event) => showSettings.value = false)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnc_cbz/usefultools-plugin-official",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "description": "UsefulTools 官方工具插件包",
6
6
  "keywords": [