@eternalheart/vue-file-preview 1.3.6 → 1.3.8

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 (61) hide show
  1. package/lib/FilePreviewContent.vue.d.ts.map +1 -1
  2. package/lib/FilePreviewEmbed.vue.d.ts.map +1 -1
  3. package/lib/FilePreviewModal.vue.d.ts.map +1 -1
  4. package/lib/chunks/index-5Smm2vx0.mjs +77 -0
  5. package/lib/chunks/index-5Smm2vx0.mjs.map +1 -0
  6. package/lib/chunks/index-BCkcZs4y.mjs +84 -0
  7. package/lib/chunks/index-BCkcZs4y.mjs.map +1 -0
  8. package/lib/chunks/index-BM9FaQUl.mjs +134 -0
  9. package/lib/chunks/index-BM9FaQUl.mjs.map +1 -0
  10. package/lib/chunks/index-BYzQg-jL.mjs +152 -0
  11. package/lib/chunks/index-BYzQg-jL.mjs.map +1 -0
  12. package/lib/chunks/index-BoL1b2w-.mjs +129 -0
  13. package/lib/chunks/index-BoL1b2w-.mjs.map +1 -0
  14. package/lib/chunks/index-Bri7VeRx.mjs +203 -0
  15. package/lib/chunks/index-Bri7VeRx.mjs.map +1 -0
  16. package/lib/chunks/index-C324a7kV.mjs +2017 -0
  17. package/lib/chunks/index-C324a7kV.mjs.map +1 -0
  18. package/lib/chunks/index-C7uOM7XL.mjs +139 -0
  19. package/lib/chunks/index-C7uOM7XL.mjs.map +1 -0
  20. package/lib/chunks/index-CTsscgqY.mjs +136 -0
  21. package/lib/chunks/index-CTsscgqY.mjs.map +1 -0
  22. package/lib/chunks/index-Ch7AEfnk.mjs +116 -0
  23. package/lib/chunks/index-Ch7AEfnk.mjs.map +1 -0
  24. package/lib/chunks/index-D9wf6m37.mjs +249 -0
  25. package/lib/chunks/index-D9wf6m37.mjs.map +1 -0
  26. package/lib/chunks/index-DAEQe-RI.mjs +111 -0
  27. package/lib/chunks/index-DAEQe-RI.mjs.map +1 -0
  28. package/lib/chunks/index-DAo-7spn.mjs +103 -0
  29. package/lib/chunks/index-DAo-7spn.mjs.map +1 -0
  30. package/lib/chunks/index-DXlcF1Dk.mjs +113 -0
  31. package/lib/chunks/index-DXlcF1Dk.mjs.map +1 -0
  32. package/lib/chunks/index-ELyTQZeF.mjs +281 -0
  33. package/lib/chunks/index-ELyTQZeF.mjs.map +1 -0
  34. package/lib/chunks/index-cZn4ih-x.mjs +111 -0
  35. package/lib/chunks/index-cZn4ih-x.mjs.map +1 -0
  36. package/lib/chunks/index-dzB4jd9b.mjs +353 -0
  37. package/lib/chunks/index-dzB4jd9b.mjs.map +1 -0
  38. package/lib/chunks/index-lHlugUBI.mjs +391 -0
  39. package/lib/chunks/index-lHlugUBI.mjs.map +1 -0
  40. package/lib/composables/useResolvedTheme.d.ts +15 -0
  41. package/lib/composables/useResolvedTheme.d.ts.map +1 -0
  42. package/lib/index.cjs +24 -499
  43. package/lib/index.cjs.map +1 -1
  44. package/lib/index.css +1 -1
  45. package/lib/index.mjs +12 -44597
  46. package/lib/index.mjs.map +1 -1
  47. package/lib/renderers/Audio/index.vue.d.ts.map +1 -1
  48. package/lib/renderers/Csv/index.vue.d.ts.map +1 -1
  49. package/lib/renderers/Json/index.vue.d.ts.map +1 -1
  50. package/lib/renderers/Markdown/index.vue.d.ts.map +1 -1
  51. package/lib/renderers/Pptx/index.vue.d.ts.map +1 -1
  52. package/lib/renderers/RendererLoading.vue.d.ts +3 -0
  53. package/lib/renderers/RendererLoading.vue.d.ts.map +1 -0
  54. package/lib/renderers/Text/index.vue.d.ts.map +1 -1
  55. package/lib/renderers/Video/index.vue.d.ts.map +1 -1
  56. package/lib/renderers/Xlsx/index.vue.d.ts.map +1 -1
  57. package/lib/renderers/Xml/index.vue.d.ts.map +1 -1
  58. package/lib/renderers/Zip/index.vue.d.ts.map +1 -1
  59. package/lib/renderers/lazy.d.ts +19 -0
  60. package/lib/renderers/lazy.d.ts.map +1 -0
  61. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"FilePreviewContent.vue.d.ts","sourceRoot":"","sources":["../src/FilePreviewContent.vue"],"names":[],"mappings":"AA2vBA,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,KAAK,0BAA0B,EAChC,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAyB,MAAM,SAAS,CAAC;AA+BrE,UAAU,KAAK;IACb,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;IACnC,kCAAkC;IAClC,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IACzB,qCAAqC;IACrC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS;IACT,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtD,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;;;;;;;;;;UAXQ,OAAO,GAAG,OAAO;WAUhB,KAAK;qBAZK,cAAc,EAAE;qBAIhB,MAAM;YAEf,MAAM;cAEJ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;cAE1C,OAAO;;AAulCpB,wBAQG"}
1
+ {"version":3,"file":"FilePreviewContent.vue.d.ts","sourceRoot":"","sources":["../src/FilePreviewContent.vue"],"names":[],"mappings":"AAmvBA,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,KAAK,0BAA0B,EAChC,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAyB,MAAM,S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QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;;;;;;;;YATU,MAAM,GAAG,MAAM;WAFhB,MAAM,GAAG,MAAM;WAUf,KAAK;kBAbE,MAAM;qBACH,cAAc,EAAE;YAMzB,MAAM;cAEJ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;cAE1C,OAAO;;AAwJpB,wBAQG"}
@@ -1 +1 @@
1
- {"version":3,"file":"FilePreviewModal.vue.d.ts","sourceRoot":"","sources":["../src/FilePreviewModal.vue"],"names":[],"mappings":"AAqHA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7H,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C,UAAU,KAAK;IACb,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;IACnC,SAAS;IACT,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtD,sBAAsB;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;;;;;;;;;;WADS,KAAK;qBARK,cAAc,EAAE;YAEzB,MAAM;cAEJ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;cAE1C,OAAO;;AAkMpB,wBAQG"}
1
+ {"version":3,"file":"FilePreviewModal.vue.d.ts","sourceRoot":"","sources":["../src/FilePreviewModal.vue"],"names":[],"mappings":"AAoHA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7H,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C,UAAU,KAAK;IACb,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;IACnC,SAAS;IACT,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtD,sBAAsB;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;;;;;;;;;;WADS,KAAK;qBARK,cAAc,EAAE;YAEzB,MAAM;cAEJ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;cAE1C,OAAO;;AAyMpB,wBAQG"}
@@ -0,0 +1,77 @@
1
+ import { defineComponent as x, ref as n, computed as y, watch as h, openBlock as e, createElementBlock as t, createElementVNode as v, toDisplayString as m, normalizeClass as w } from "vue";
2
+ import { u as _, b, j as k, h as T, _ as B } from "./index-C324a7kV.mjs";
3
+ import { codeToHtml as N } from "shiki";
4
+ const j = {
5
+ key: 0,
6
+ class: "vfp-flex vfp-items-center vfp-justify-center vfp-w-full vfp-h-full"
7
+ }, H = {
8
+ key: 1,
9
+ class: "vfp-flex vfp-items-center vfp-justify-center vfp-w-full vfp-h-full"
10
+ }, W = { class: "vfp-text-fg-secondary vfp-text-center" }, C = { class: "vfp-text-lg" }, E = {
11
+ key: 2,
12
+ class: "vfp-w-full vfp-h-full vfp-bg-surface-toolbar"
13
+ }, L = ["srcdoc", "title"], M = {
14
+ key: 3,
15
+ class: "vfp-w-full vfp-h-full vfp-overflow-auto",
16
+ style: { background: "var(--fp-code-bg)" }
17
+ }, P = ["innerHTML"], z = /* @__PURE__ */ x({
18
+ __name: "index",
19
+ props: {
20
+ url: {},
21
+ fileName: {},
22
+ wordWrap: { type: Boolean, default: !0 },
23
+ htmlPreview: { type: Boolean, default: !1 }
24
+ },
25
+ setup(l) {
26
+ const i = l, { t: g } = _(), u = b(), o = n(""), a = n(""), p = n(!0), r = n(null), f = y(() => k(i.fileName)), c = async () => {
27
+ p.value = !0, r.value = null;
28
+ try {
29
+ const s = await T(i.url);
30
+ if (o.value = s, f.value !== "text")
31
+ try {
32
+ a.value = await N(s, {
33
+ lang: f.value,
34
+ theme: u.value === "light" ? "github-light" : "dark-plus"
35
+ });
36
+ } catch {
37
+ a.value = "";
38
+ }
39
+ else
40
+ a.value = "";
41
+ } catch (s) {
42
+ console.error(s), r.value = g.value("text.load_failed");
43
+ } finally {
44
+ p.value = !1;
45
+ }
46
+ };
47
+ return h(() => i.url, c, { immediate: !0 }), h(u, () => {
48
+ o.value && f.value !== "text" && c();
49
+ }), (s, d) => p.value ? (e(), t("div", j, [...d[0] || (d[0] = [
50
+ v("div", { class: "vfp-w-12 vfp-h-12 vfp-border-4 vfp-border-line-strong vfp-border-t-spinner-head vfp-rounded-full vfp-animate-spin" }, null, -1)
51
+ ])])) : r.value ? (e(), t("div", H, [
52
+ v("div", W, [
53
+ v("p", C, m(r.value), 1)
54
+ ])
55
+ ])) : l.htmlPreview && f.value === "html" ? (e(), t("div", E, [
56
+ v("iframe", {
57
+ srcdoc: o.value,
58
+ sandbox: "allow-same-origin",
59
+ class: "vfp-w-full vfp-h-full vfp-border-0",
60
+ title: l.fileName
61
+ }, null, 8, L)
62
+ ])) : (e(), t("div", M, [
63
+ a.value ? (e(), t("div", {
64
+ key: 1,
65
+ class: w(["shiki-wrapper", { "no-wrap": !l.wordWrap }]),
66
+ innerHTML: a.value
67
+ }, null, 10, P)) : (e(), t("pre", {
68
+ key: 0,
69
+ class: w(["vfp-p-6 vfp-text-fg-primary vfp-font-mono vfp-text-sm", l.wordWrap ? "vfp-whitespace-pre-wrap vfp-break-words" : "vfp-whitespace-pre"])
70
+ }, m(o.value), 3))
71
+ ]));
72
+ }
73
+ }), S = /* @__PURE__ */ B(z, [["__scopeId", "data-v-22859c1e"]]);
74
+ export {
75
+ S as default
76
+ };
77
+ //# sourceMappingURL=index-5Smm2vx0.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-5Smm2vx0.mjs","sources":["../../src/renderers/Text/index.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ref, computed, watch } from 'vue';\nimport { getLanguageFromFileName, fetchTextUtf8 } from '@eternalheart/file-preview-core';\nimport { codeToHtml } from 'shiki';\nimport { useTranslator } from '../../composables/useTranslator';\nimport { useResolvedTheme } from '../../composables/useResolvedTheme';\n\nconst props = withDefaults(defineProps<{\n url: string;\n fileName: string;\n wordWrap?: boolean;\n htmlPreview?: boolean;\n}>(), {\n wordWrap: true,\n htmlPreview: false,\n});\n\nconst { t } = useTranslator();\nconst resolvedTheme = useResolvedTheme();\n\nconst content = ref<string>('');\nconst highlighted = ref<string>('');\nconst loading = ref(true);\nconst error = ref<string | null>(null);\n\nconst language = computed(() => getLanguageFromFileName(props.fileName));\n\nconst loadText = async () => {\n loading.value = true;\n error.value = null;\n try {\n const text = await fetchTextUtf8(props.url);\n content.value = text;\n\n if (language.value !== 'text') {\n try {\n highlighted.value = await codeToHtml(text, {\n lang: language.value,\n theme: resolvedTheme.value === 'light' ? 'github-light' : 'dark-plus',\n });\n } catch {\n highlighted.value = '';\n }\n } else {\n highlighted.value = '';\n }\n } catch (err) {\n console.error(err);\n error.value = t.value('text.load_failed');\n } finally {\n loading.value = false;\n }\n};\n\nwatch(() => props.url, loadText, { immediate: true });\nwatch(resolvedTheme, () => {\n // 主题切换时重新高亮\n if (content.value && language.value !== 'text') {\n loadText();\n }\n});\n</script>\n\n<template>\n <div v-if=\"loading\" class=\"vfp-flex vfp-items-center vfp-justify-center vfp-w-full vfp-h-full\">\n <div\n class=\"vfp-w-12 vfp-h-12 vfp-border-4 vfp-border-line-strong vfp-border-t-spinner-head vfp-rounded-full vfp-animate-spin\"\n />\n </div>\n\n <div v-else-if=\"error\" class=\"vfp-flex vfp-items-center vfp-justify-center vfp-w-full vfp-h-full\">\n <div class=\"vfp-text-fg-secondary vfp-text-center\">\n <p class=\"vfp-text-lg\">{{ error }}</p>\n </div>\n </div>\n\n <!-- HTML 预览模式 -->\n <div v-else-if=\"htmlPreview && language === 'html'\" class=\"vfp-w-full vfp-h-full vfp-bg-surface-toolbar\">\n <iframe\n :srcdoc=\"content\"\n sandbox=\"allow-same-origin\"\n class=\"vfp-w-full vfp-h-full vfp-border-0\"\n :title=\"fileName\"\n />\n </div>\n\n <!-- 源码模式 -->\n <div v-else class=\"vfp-w-full vfp-h-full vfp-overflow-auto\" style=\"background: var(--fp-code-bg);\">\n <pre\n v-if=\"!highlighted\"\n class=\"vfp-p-6 vfp-text-fg-primary vfp-font-mono vfp-text-sm\"\n :class=\"wordWrap ? 'vfp-whitespace-pre-wrap vfp-break-words' : 'vfp-whitespace-pre'\"\n >{{ content }}</pre>\n <div v-else class=\"shiki-wrapper\" :class=\"{ 'no-wrap': !wordWrap }\" v-html=\"highlighted\" />\n </div>\n</template>\n\n<style scoped>\n.shiki-wrapper :deep(pre) {\n margin: 0;\n padding: 1.5rem 1.5rem 1.5rem 0;\n background: transparent !important;\n font-size: 0.875rem;\n overflow-x: auto;\n}\n.shiki-wrapper :deep(code) {\n font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n counter-reset: line;\n}\n.shiki-wrapper :deep(code .line) {\n counter-increment: line;\n}\n.shiki-wrapper :deep(code .line::before) {\n content: counter(line);\n display: inline-block;\n width: 3em;\n padding-right: 1em;\n margin-right: 0.5em;\n text-align: right;\n color: var(--fp-fg-disabled);\n user-select: none;\n border-right: 1px solid var(--fp-line);\n}\n.shiki-wrapper.no-wrap :deep(code) {\n white-space: pre;\n word-break: normal;\n overflow-wrap: normal;\n}\n.shiki-wrapper:not(.no-wrap) :deep(code) {\n white-space: pre-wrap;\n word-break: break-word;\n overflow-wrap: break-word;\n}\n</style>\n"],"names":["props","__props","t","useTranslator","resolvedTheme","useResolvedTheme","content","ref","highlighted","loading","error","language","computed","getLanguageFromFileName","loadText","text","fetchTextUtf8","codeToHtml","err","watch","_openBlock","_createElementBlock","_hoisted_1","_cache","_createElementVNode","_hoisted_2","_hoisted_3","_hoisted_4","_toDisplayString","_hoisted_5","_hoisted_7","_normalizeClass"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAOA,UAAMA,IAAQC,GAUR,EAAE,GAAAC,EAAA,IAAMC,EAAA,GACRC,IAAgBC,EAAA,GAEhBC,IAAUC,EAAY,EAAE,GACxBC,IAAcD,EAAY,EAAE,GAC5BE,IAAUF,EAAI,EAAI,GAClBG,IAAQH,EAAmB,IAAI,GAE/BI,IAAWC,EAAS,MAAMC,EAAwBb,EAAM,QAAQ,CAAC,GAEjEc,IAAW,YAAY;AAC3B,MAAAL,EAAQ,QAAQ,IAChBC,EAAM,QAAQ;AACd,UAAI;AACF,cAAMK,IAAO,MAAMC,EAAchB,EAAM,GAAG;AAG1C,YAFAM,EAAQ,QAAQS,GAEZJ,EAAS,UAAU;AACrB,cAAI;AACF,YAAAH,EAAY,QAAQ,MAAMS,EAAWF,GAAM;AAAA,cACzC,MAAMJ,EAAS;AAAA,cACf,OAAOP,EAAc,UAAU,UAAU,iBAAiB;AAAA,YAAA,CAC3D;AAAA,UACH,QAAQ;AACN,YAAAI,EAAY,QAAQ;AAAA,UACtB;AAAA;AAEA,UAAAA,EAAY,QAAQ;AAAA,MAExB,SAASU,GAAK;AACZ,gBAAQ,MAAMA,CAAG,GACjBR,EAAM,QAAQR,EAAE,MAAM,kB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
+ import { u as M, b as S, h as $, _ as D } from "./index-C324a7kV.mjs";
3
+ import { codeToHtml as j } from "shiki";
4
+ const H = {
5
+ key: 0,
6
+ class: "vfp-flex vfp-items-center vfp-justify-center vfp-w-full vfp-h-full"
7
+ }, L = {
8
+ key: 1,
9
+ class: "vfp-flex vfp-items-center vfp-justify-center vfp-w-full vfp-h-full"
10
+ }, N = { class: "vfp-text-fg-secondary vfp-text-center" }, P = { class: "vfp-text-lg" }, X = {
11
+ key: 2,
12
+ class: "vfp-w-full vfp-h-full vfp-overflow-auto",
13
+ style: { background: "var(--fp-code-bg)" }
14
+ }, B = {
15
+ key: 0,
16
+ class: "vfp-p-6 vfp-text-fg-primary vfp-font-mono vfp-text-sm vfp-whitespace-pre-wrap vfp-break-words"
17
+ }, E = ["innerHTML"], I = /* @__PURE__ */ z({
18
+ __name: "index",
19
+ props: {
20
+ url: {},
21
+ fileName: {}
22
+ },
23
+ setup(w) {
24
+ const u = w, { t: x } = M(), d = S(), l = c(""), n = c(""), f = c(!0), o = c(null), k = (e) => {
25
+ const r = " ", i = /(>)(<)(\/*)/g, h = e.replace(i, `$1
26
+ $2$3`);
27
+ let t = 0;
28
+ return h.split(`
29
+ `).map((p) => {
30
+ let _ = 0;
31
+ /^<\/\w/.test(p) ? t = Math.max(t - 1, 0) : /^<\w[^>]*[^/]>.*$/.test(p) && !/<.+<\/.+>$/.test(p) && (_ = 1);
32
+ const T = r.repeat(t) + p;
33
+ return t += _, T;
34
+ }).join(`
35
+ `);
36
+ }, b = (e) => {
37
+ try {
38
+ const i = new DOMParser().parseFromString(e, "application/xml");
39
+ if (i.querySelector("parsererror")) return e;
40
+ const t = new XMLSerializer().serializeToString(i);
41
+ return k(t);
42
+ } catch {
43
+ return e;
44
+ }
45
+ }, m = async () => {
46
+ f.value = !0, o.value = null;
47
+ try {
48
+ const e = await $(u.url);
49
+ l.value = b(e);
50
+ try {
51
+ n.value = await j(l.value, {
52
+ lang: "xml",
53
+ theme: d.value === "light" ? "github-light" : "dark-plus"
54
+ });
55
+ } catch {
56
+ n.value = "";
57
+ }
58
+ } catch (e) {
59
+ console.error(e), o.value = x.value("xml.load_failed");
60
+ } finally {
61
+ f.value = !1;
62
+ }
63
+ };
64
+ return g(() => u.url, m, { immediate: !0 }), g(d, () => {
65
+ l.value && m();
66
+ }), (e, r) => f.value ? (s(), a("div", H, [...r[0] || (r[0] = [
67
+ v("div", { class: "vfp-w-12 vfp-h-12 vfp-border-4 vfp-border-line-strong vfp-border-t-spinner-head vfp-rounded-full vfp-animate-spin" }, null, -1)
68
+ ])])) : o.value ? (s(), a("div", L, [
69
+ v("div", N, [
70
+ v("p", P, y(o.value), 1)
71
+ ])
72
+ ])) : (s(), a("div", X, [
73
+ n.value ? (s(), a("div", {
74
+ key: 1,
75
+ class: "shiki-wrapper",
76
+ innerHTML: n.value
77
+ }, null, 8, E)) : (s(), a("pre", B, y(l.value), 1))
78
+ ]));
79
+ }
80
+ }), F = /* @__PURE__ */ D(I, [["__scopeId", "data-v-3249ae32"]]);
81
+ export {
82
+ F as default
83
+ };
84
+ //# sourceMappingURL=index-BCkcZs4y.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BCkcZs4y.mjs","sources":["../../src/renderers/Xml/index.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ref, watch } from 'vue';\nimport { fetchTextUtf8 } from '@eternalheart/file-preview-core';\nimport { codeToHtml } from 'shiki';\nimport { useTranslator } from '../../composables/useTranslator';\nimport { useResolvedTheme } from '../../composables/useResolvedTheme';\n\nconst props = defineProps<{\n url: string;\n fileName: string;\n}>();\n\nconst { t } = useTranslator();\nconst resolvedTheme = useResolvedTheme();\n\nconst content = ref<string>('');\nconst highlighted = ref<string>('');\nconst loading = ref(true);\nconst error = ref<string | null>(null);\n\nconst indentXml = (xml: string): string => {\n const PADDING = ' ';\n const reg = /(>)(<)(\\/*)/g;\n const formatted = xml.replace(reg, '$1\\n$2$3');\n let pad = 0;\n return formatted\n .split('\\n')\n .map((line) => {\n let indent = 0;\n if (/^<\\/\\w/.test(line)) {\n pad = Math.max(pad - 1, 0);\n } else if (/^<\\w[^>]*[^/]>.*$/.test(line) && !/<.+<\\/.+>$/.test(line)) {\n indent = 1;\n }\n const padded = PADDING.repeat(pad) + line;\n pad += indent;\n return padded;\n })\n .join('\\n');\n};\n\nconst prettyPrintXml = (xml: string): string => {\n try {\n const parser = new DOMParser();\n const doc = parser.parseFromString(xml, 'application/xml');\n if (doc.querySelector('parsererror')) return xml;\n const serializer = new XMLSerializer();\n const serialized = serializer.serializeToString(doc);\n return indentXml(serialized);\n } catch {\n return xml;\n }\n};\n\nconst load = async () => {\n loading.value = true;\n error.value = null;\n try {\n const raw = await fetchTextUtf8(props.url);\n content.value = prettyPrintXml(raw);\n try {\n highlighted.value = await codeToHtml(content.value, {\n lang: 'xml',\n theme: resolvedTheme.value === 'light' ? 'github-light' : 'dark-plus',\n });\n } catch {\n highlighted.value = '';\n }\n } catch (err) {\n console.error(err);\n error.value = t.value('xml.load_failed');\n } finally {\n loading.value = false;\n }\n};\n\nwatch(() => props.url, load, { immediate: true });\nwatch(resolvedTheme, () => {\n if (content.value) load();\n});\n</script>\n\n<template>\n <div v-if=\"loading\" class=\"vfp-flex vfp-items-center vfp-justify-center vfp-w-full vfp-h-full\">\n <div\n class=\"vfp-w-12 vfp-h-12 vfp-border-4 vfp-border-line-strong vfp-border-t-spinner-head vfp-rounded-full vfp-animate-spin\"\n />\n </div>\n\n <div v-else-if=\"error\" class=\"vfp-flex vfp-items-center vfp-justify-center vfp-w-full vfp-h-full\">\n <div class=\"vfp-text-fg-secondary vfp-text-center\">\n <p class=\"vfp-text-lg\">{{ error }}</p>\n </div>\n </div>\n\n <div v-else class=\"vfp-w-full vfp-h-full vfp-overflow-auto\" style=\"background: var(--fp-code-bg);\">\n <pre\n v-if=\"!highlighted\"\n class=\"vfp-p-6 vfp-text-fg-primary vfp-font-mono vfp-text-sm vfp-whitespace-pre-wrap vfp-break-words\"\n >{{ content }}</pre\n >\n <div v-else class=\"shiki-wrapper\" v-html=\"highlighted\" />\n </div>\n</template>\n\n<style scoped>\n.shiki-wrapper :deep(pre) {\n margin: 0;\n padding: 1.5rem;\n background: transparent !important;\n font-size: 0.875rem;\n overflow-x: auto;\n}\n.shiki-wrapper :deep(code) {\n font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n}\n</style>\n"],"names":["props","__props","t","useTranslator","resolvedTheme","useResolvedTheme","content","ref","highlighted","loading","error","indentXml","xml","PADDING","reg","formatted","pad","line","indent","padded","prettyPrintXml","doc","serialized","load","raw","fetchTextUtf8","codeToHtml","err","watch","_openBlock","_createElementBlock","_hoisted_1","_cache","_createElementVNode","_hoisted_2","_hoisted_3","_hoisted_4","_toDisplayString","_hoisted_5","_hoisted_6"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAOA,UAAMA,IAAQC,GAKR,EAAE,GAAAC,EAAA,IAAMC,EAAA,GACRC,IAAgBC,EAAA,GAEhBC,IAAUC,EAAY,EAAE,GACxBC,IAAcD,EAAY,EAAE,GAC5BE,IAAUF,EAAI,EAAI,GAClBG,IAAQH,EAAmB,IAAI,GAE/BI,IAAY,CAACC,MAAwB;AACzC,YAAMC,IAAU,MACVC,IAAM,gBACNC,IAAYH,EAAI,QAAQE,GAAK;AAAA,KAAU;AAC7C,UAAIE,IAAM;AACV,aAAOD,EACJ,MAAM;AAAA,CAAI,EACV,IAAI,CAACE,MAAS;AACb,YAAIC,IAAS;AACb,QAAI,SAAS,KAAKD,CAAI,IACpBD,IAAM,KAAK,IAAIA,IAAM,GAAG,CAAC,IAChB,oBAAoB,KAAKC,CAAI,KAAK,CAAC,aAAa,KAAKA,CAAI,MAClEC,IAAS;AAEX,cAAMC,IAASN,EAAQ,OAAOG,CAAG,IAAIC;AACrC,eAAAD,KAAOE,GACAC;AAAA,MACT,CAAC,EACA,KAAK;AAAA,CAAI;AAAA,IACd,GAEMC,IAAiB,CAACR,MAAwB;AA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AAZ3B,EAAA,KAAK,GAAA,CAAA;AAAA,MAAA;WAInCmB,EAAA,GAAAC,EAOM,OAPNQ,GAOM;AAAA,MALK9B,EAAA,cAITsB,EAAyD,OAAA;AAAA;QAA7C,OAAM;AAAA,QAAgB,WAAQtB,EAAA;AAAA,MAAA,wBAL1CsB,EAIC,OAJDS,GAICF,EADK/B,EAAA,KAAO,GAAA,CAAA;AAAA;;;"}
@@ -0,0 +1,134 @@
1
+ import { defineComponent as U, ref as o, watch as z, onMounted as V, onBeforeUnmount as O, computed as E, openBlock as x, createElementBlock as y, normalizeStyle as Y, createElementVNode as C, createCommentVNode as k, toDisplayString as w, normalizeClass as Z } from "vue";
2
+ import { u as q, p as A } from "./index-C324a7kV.mjs";
3
+ const F = {
4
+ key: 0,
5
+ class: "vfp-flex vfp-items-center vfp-justify-center"
6
+ }, G = {
7
+ key: 1,
8
+ class: "vfp-text-fg-secondary vfp-text-center"
9
+ }, I = { class: "vfp-text-lg" }, J = ["src"], Q = {
10
+ key: 2,
11
+ class: "vfp-absolute vfp-bottom-2 vfp-right-3 vfp-text-[10px] vfp-text-fg-disabled hover:vfp-text-fg-secondary vfp-transition-colors vfp-pointer-events-auto vfp-select-none vfp-cursor-default"
12
+ }, ne = /* @__PURE__ */ U({
13
+ __name: "index",
14
+ props: {
15
+ url: {},
16
+ zoom: {},
17
+ rotation: {},
18
+ resetKey: {},
19
+ fileSize: {}
20
+ },
21
+ emits: ["zoomChange", "naturalWidthChange", "naturalHeightChange"],
22
+ setup(S, { emit: R }) {
23
+ const u = S, m = R, { t: X } = q(), l = o(!1), v = o(null), n = o({ x: 0, y: 0 }), f = o(!1);
24
+ let M = { x: 0, y: 0 };
25
+ const r = o(1), s = o({ width: 0, height: 0 }), $ = o(null), d = o(null);
26
+ z(
27
+ () => u.url,
28
+ () => {
29
+ l.value = !1, v.value = null, n.value = { x: 0, y: 0 }, r.value = 1;
30
+ }
31
+ ), z(
32
+ () => u.zoom,
33
+ (e) => {
34
+ r.value = e;
35
+ }
36
+ ), z(
37
+ () => u.resetKey,
38
+ () => {
39
+ n.value = { x: 0, y: 0 };
40
+ }
41
+ );
42
+ const W = (e, t) => {
43
+ const a = d.value;
44
+ if (!a || s.value.width === 0) return e;
45
+ const h = a.clientWidth, p = a.clientHeight, _ = s.value.width * t, g = s.value.height * t, i = Math.min(80, h * 0.15, p * 0.15), c = (h + _) / 2 - i, b = (p + g) / 2 - i;
46
+ return {
47
+ x: c > 0 ? Math.max(-c, Math.min(c, e.x)) : 0,
48
+ y: b > 0 ? Math.max(-b, Math.min(b, e.y)) : 0
49
+ };
50
+ }, B = (e) => {
51
+ l.value = !0;
52
+ const t = e.currentTarget;
53
+ s.value = { width: t.naturalWidth, height: t.naturalHeight }, m("naturalWidthChange", t.naturalWidth), m("naturalHeightChange", t.naturalHeight);
54
+ }, L = () => {
55
+ v.value = X.value("image.load_failed"), l.value = !0;
56
+ }, N = () => {
57
+ n.value = { x: 0, y: 0 }, r.value = 1, m("zoomChange", 1);
58
+ }, H = (e) => {
59
+ e.preventDefault(), e.stopPropagation();
60
+ const t = d.value;
61
+ if (!t) return;
62
+ const a = t.getBoundingClientRect(), h = e.clientX - a.left - a.width / 2, p = e.clientY - a.top - a.height / 2, _ = e.deltaY > 0 ? -0.05 : 0.05, g = r.value, i = Math.max(0.01, Math.min(10, g + _)), c = i / g;
63
+ n.value = W(
64
+ {
65
+ x: h - c * (h - n.value.x),
66
+ y: p - c * (p - n.value.y)
67
+ },
68
+ i
69
+ ), r.value = i, m("zoomChange", i);
70
+ };
71
+ V(() => {
72
+ const e = d.value;
73
+ e && e.addEventListener("wheel", H, { passive: !1 });
74
+ }), O(() => {
75
+ const e = d.value;
76
+ e && e.removeEventListener("wheel", H);
77
+ });
78
+ const P = (e) => {
79
+ e.button === 0 && (f.value = !0, M = {
80
+ x: e.clientX - n.value.x,
81
+ y: e.clientY - n.value.y
82
+ });
83
+ }, T = (e) => {
84
+ f.value && (n.value = W(
85
+ {
86
+ x: e.clientX - M.x,
87
+ y: e.clientY - M.y
88
+ },
89
+ r.value
90
+ ));
91
+ }, D = () => {
92
+ f.value = !1;
93
+ }, j = E(() => ({
94
+ transform: `translate(${n.value.x}px, ${n.value.y}px) scale(${r.value}) rotate(${u.rotation}deg)`,
95
+ transformOrigin: "center",
96
+ transition: f.value ? "none" : "transform 0.3s ease-out",
97
+ opacity: l.value ? 1 : 0
98
+ })), K = E(() => u.fileSize == null ? "" : ` · ${A(u.fileSize)}`);
99
+ return (e, t) => (x(), y("div", {
100
+ ref_key: "containerRef",
101
+ ref: d,
102
+ class: "vfp-relative vfp-flex vfp-items-center vfp-justify-center vfp-w-full vfp-h-full vfp-overflow-hidden",
103
+ style: Y({ cursor: f.value ? "grabbing" : "grab" }),
104
+ onMousedown: P,
105
+ onMousemove: T,
106
+ onMouseup: D,
107
+ onMouseleave: D
108
+ }, [
109
+ !l.value && !v.value ? (x(), y("div", F, [...t[0] || (t[0] = [
110
+ C("div", { class: "vfp-w-12 vfp-h-12 vfp-border-4 vfp-border-line-strong vfp-border-t-spinner-head vfp-rounded-full vfp-animate-spin" }, null, -1)
111
+ ])])) : k("", !0),
112
+ v.value ? (x(), y("div", G, [
113
+ C("p", I, w(v.value), 1)
114
+ ])) : k("", !0),
115
+ C("img", {
116
+ ref_key: "imgRef",
117
+ ref: $,
118
+ src: S.url,
119
+ alt: "Preview",
120
+ class: Z(["vfp-max-w-none vfp-select-none", !l.value && "vfp-hidden"]),
121
+ style: Y(j.value),
122
+ draggable: !1,
123
+ onLoad: B,
124
+ onError: L,
125
+ onDblclick: N
126
+ }, null, 46, J),
127
+ l.value && !v.value && s.value.width > 0 ? (x(), y("div", Q, w(s.value.width) + " × " + w(s.value.height) + w(K.value), 1)) : k("", !0)
128
+ ], 36));
129
+ }
130
+ });
131
+ export {
132
+ ne as default
133
+ };
134
+ //# sourceMappingURL=index-BM9FaQUl.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BM9FaQUl.mjs","sources":["../../src/renderers/Image/index.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ref, watch, onMounted, onBeforeUnmount, computed } from 'vue';\nimport { formatFileSize } from '@eternalheart/file-preview-core';\nimport { useTranslator } from '../../composables/useTranslator';\n\nconst props = defineProps<{\n url: string;\n zoom: number;\n rotation: number;\n resetKey?: number;\n fileSize?: number;\n}>();\n\nconst emit = defineEmits<{\n (e: 'zoomChange', zoom: number): void;\n (e: 'naturalWidthChange', width: number): void;\n (e: 'naturalHeightChange', height: number): void;\n}>();\n\nconst { t } = useTranslator();\n\nconst loaded = ref(false);\nconst error = ref<string | null>(null);\nconst position = ref({ x: 0, y: 0 });\nconst isDragging = ref(false);\nlet dragStart = { x: 0, y: 0 };\nconst internalZoom = ref(1);\nconst naturalSize = ref({ width: 0, height: 0 });\n\nconst imgRef = ref<HTMLImageElement | null>(null);\nconst containerRef = ref<HTMLDivElement | null>(null);\n\nwatch(\n () => props.url,\n () => {\n loaded.value = false;\n error.value = null;\n position.value = { x: 0, y: 0 };\n internalZoom.value = 1;\n }\n);\n\nwatch(\n () => props.zoom,\n (z) => {\n internalZoom.value = z;\n }\n);\n\nwatch(\n () => props.resetKey,\n () => {\n position.value = { x: 0, y: 0 };\n }\n);\n\nconst clampPosition = (pos: { x: number; y: number }, currentZoom: number) => {\n const container = containerRef.value;\n if (!container || naturalSize.value.width === 0) return pos;\n\n const containerW = container.clientWidth;\n const containerH = container.clientHeight;\n const imgW = naturalSize.value.width * currentZoom;\n const imgH = naturalSize.value.height * currentZoom;\n\n const margin = Math.min(80, containerW * 0.15, containerH * 0.15);\n const rangeX = (containerW + imgW) / 2 - margin;\n const rangeY = (containerH + imgH) / 2 - margin;\n\n return {\n x: rangeX > 0 ? Math.max(-rangeX, Math.min(rangeX, pos.x)) : 0,\n y: rangeY > 0 ? Math.max(-rangeY, Math.min(rangeY, pos.y)) : 0,\n };\n};\n\nconst handleLoad = (e: Event) => {\n loaded.value = true;\n const img = e.currentTarget as HTMLImageElement;\n naturalSize.value = { width: img.naturalWidth, height: img.naturalHeight };\n emit('naturalWidthChange', img.naturalWidth);\n emit('naturalHeightChange', img.naturalHeight);\n};\n\nconst handleError = () => {\n error.value = t.value('image.load_failed');\n loaded.value = true;\n};\n\nconst handleDoubleClick = () => {\n position.value = { x: 0, y: 0 };\n internalZoom.value = 1;\n emit('zoomChange', 1);\n};\n\n// 鼠标滚轮缩放\nconst handleWheelNative = (e: WheelEvent) => {\n e.preventDefault();\n e.stopPropagation();\n\n const container = containerRef.value;\n if (!container) return;\n\n const rect = container.getBoundingClientRect();\n const mouseX = e.clientX - rect.left - rect.width / 2;\n const mouseY = e.clientY - rect.top - rect.height / 2;\n\n const delta = e.deltaY > 0 ? -0.05 : 0.05;\n const prev = internalZoom.value;\n const newZoom = Math.max(0.01, Math.min(10, prev + delta));\n const scale = newZoom / prev;\n\n position.value = clampPosition(\n {\n x: mouseX - scale * (mouseX - position.value.x),\n y: mouseY - scale * (mouseY - position.value.y),\n },\n newZoom\n );\n\n internalZoom.value = newZoom;\n emit('zoomChange', newZoom);\n};\n\nonMounted(() => {\n const container = containerRef.value;\n if (container) {\n container.addEventListener('wheel', handleWheelNative, { passive: false });\n }\n});\n\nonBeforeUnmount(() => {\n const container = containerRef.value;\n if (container) {\n container.removeEventListener('wheel', handleWheelNative);\n }\n});\n\nconst handleMouseDown = (e: MouseEvent) => {\n if (e.button !== 0) return;\n isDragging.value = true;\n dragStart = {\n x: e.clientX - position.value.x,\n y: e.clientY - position.value.y,\n };\n};\n\nconst handleMouseMove = (e: MouseEvent) => {\n if (!isDragging.value) return;\n position.value = clampPosition(\n {\n x: e.clientX - dragStart.x,\n y: e.clientY - dragStart.y,\n },\n internalZoom.value\n );\n};\n\nconst handleMouseUp = () => {\n isDragging.value = false;\n};\n\nconst transformStyle = computed(() => ({\n transform: `translate(${position.value.x}px, ${position.value.y}px) scale(${internalZoom.value}) rotate(${props.rotation}deg)`,\n transformOrigin: 'center',\n transition: isDragging.value ? 'none' : 'transform 0.3s ease-out',\n opacity: loaded.value ? 1 : 0,\n}));\n\nconst sizeText = computed(() => {\n if (props.fileSize == null) return '';\n return ` · ${formatFileSize(props.fileSize)}`;\n});\n</script>\n\n<template>\n <div\n ref=\"containerRef\"\n class=\"vfp-relative vfp-flex vfp-items-center vfp-justify-center vfp-w-full vfp-h-full vfp-overflow-hidden\"\n :style=\"{ cursor: isDragging ? 'grabbing' : 'grab' }\"\n @mousedown=\"handleMouseDown\"\n @mousemove=\"handleMouseMove\"\n @mouseup=\"handleMouseUp\"\n @mouseleave=\"handleMouseUp\"\n >\n <div v-if=\"!loaded && !error\" class=\"vfp-flex vfp-items-center vfp-justify-center\">\n <div\n class=\"vfp-w-12 vfp-h-12 vfp-border-4 vfp-border-line-strong vfp-border-t-spinner-head vfp-rounded-full vfp-animate-spin\"\n />\n </div>\n\n <div v-if=\"error\" class=\"vfp-text-fg-secondary vfp-text-center\">\n <p class=\"vfp-text-lg\">{{ error }}</p>\n </div>\n\n <img\n ref=\"imgRef\"\n :src=\"url\"\n alt=\"Preview\"\n :class=\"['vfp-max-w-none vfp-select-none', !loaded && 'vfp-hidden']\"\n :style=\"transformStyle\"\n :draggable=\"false\"\n @load=\"handleLoad\"\n @error=\"handleError\"\n @dblclick=\"handleDoubleClick\"\n />\n\n <div\n v-if=\"loaded && !error && naturalSize.width > 0\"\n class=\"vfp-absolute vfp-bottom-2 vfp-right-3 vfp-text-[10px] vfp-text-fg-disabled hover:vfp-text-fg-secondary vfp-transition-colors vfp-pointer-events-auto vfp-select-none vfp-cursor-default\"\n >\n {{ naturalSize.width }} × {{ naturalSize.height }}{{ sizeText }}\n </div>\n </div>\n</template>\n"],"names":["props","__props","emit","__emit","t","useTranslator","loaded","ref","error","position","isDragging","dragStart","internalZoom","naturalSize","imgRef","containerRef","watch","z","clampPosition","pos","currentZoom","container","containerW","containerH","imgW","imgH","margin","rangeX","rangeY","handleLoad","img","handleError","handleDoubleClick","handleWheelNative","rect","mouseX","mouseY","delta","prev","newZoom","scale","onMounted","onBeforeUnmount","handleMouseDown","handleMouseMove","handleMouseUp","transformStyle","computed","sizeText","formatFileSize","_createElementBlock","_openBlock","_hoisted_1","_cache","_createElementVNode","_hoisted_2","_hoisted_3","_toDisplayString","_hoisted_5"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAKA,UAAMA,IAAQC,GAQRC,IAAOC,GAMP,EAAE,GAAAC,EAAA,IAAMC,EAAA,GAERC,IAASC,EAAI,EAAK,GAClBC,IAAQD,EAAmB,IAAI,GAC/BE,IAAWF,EAAI,EAAE,GAAG,GAAG,GAAG,GAAG,GAC7BG,IAAaH,EAAI,EAAK;AAC5B,QAAII,IAAY,EAAE,GAAG,GAAG,GAAG,EAAA;AAC3B,UAAMC,IAAeL,EAAI,CAAC,GACpBM,IAAcN,EAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,GAEzCO,IAASP,EAA6B,IAAI,GAC1CQ,IAAeR,EAA2B,IAAI;AAEpD,IAAAS;AAAA,MACE,MAAMhB,EAAM;AAAA,MACZ,MAAM;AACJ,QAAAM,EAAO,QAAQ,IACfE,EAAM,QAAQ,MACdC,EAAS,QAAQ,EAAE,GAAG,GAAG,GAAG,EAAA,GAC5BG,EAAa,QAAQ;AAAA,MACvB;AAAA,IAAA,GAGFI;AAAA,MACE,MAAMhB,EAAM;AAAA,MACZ,CAACiB,MAAM;AACL,QAAAL,EAAa,QAAQK;AAAA,MACvB;AAAA,IAAA,GAGFD;AAAA,MACE,MAAMhB,EAAM;AAAA,MACZ,MAAM;AACJ,QAAAS,EAAS,QAAQ,EAAE,GAAG,GAAG,GAAG,EAAA;AAAA,MAC9B;AAAA,IAAA;AAGF,UAAMS,IAAgB,CAACC,GAA+BC,MAAwB;AAC5E,YAAMC,IAAYN,EAAa;AAC/B,UAAI,CAACM,KAAaR,EAAY,MAAM,UAAU,EAAG,QAAOM;AAExD,YAAMG,IAAaD,EAAU,aACvBE,IAAaF,EAAU,cACvBG,IAAOX,EAAY,MAAM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, watch as W, onBeforeUnmount as R, openBlock as g, createElementBlock as b, createElementVNode as f, toDisplayString as E, unref as T, createCommentVNode as k, createVNode as j, normalizeStyle as L } from "vue";
2
+ import { Presentation as N } from "lucide-vue-next";
3
+ import { init as D } from "pptx-preview";
4
+ import { u as S } from "./index-C324a7kV.mjs";
5
+ const V = { class: "vfp-relative vfp-flex vfp-flex-col vfp-items-center vfp-w-full vfp-h-full" }, q = {
6
+ key: 0,
7
+ class: "vfp-absolute vfp-inset-0 vfp-flex vfp-items-center vfp-justify-center vfp-bg-surface-toolbar vfp-backdrop-blur-sm vfp-z-10"
8
+ }, A = { class: "vfp-text-center" }, F = { class: "vfp-text-xs md:vfp-text-sm vfp-text-fg-secondary vfp-font-medium" }, H = {
9
+ key: 1,
10
+ class: "vfp-absolute vfp-inset-0 vfp-flex vfp-items-center vfp-justify-center vfp-bg-surface-toolbar vfp-backdrop-blur-sm vfp-z-10"
11
+ }, I = { class: "vfp-text-center vfp-max-w-sm md:vfp-max-w-md vfp-px-4" }, O = { class: "vfp-w-24 vfp-h-24 md:vfp-w-32 md:vfp-h-32 vfp-mx-auto vfp-mb-4 md:vfp-mb-6 vfp-rounded-2xl md:vfp-rounded-3xl vfp-bg-gradient-to-br vfp-from-orange-500 vfp-via-red-500 vfp-to-pink-500 vfp-flex vfp-items-center vfp-justify-center vfp-shadow-2xl" }, U = { class: "vfp-text-lg md:vfp-text-xl vfp-text-fg-primary vfp-mb-2 md:vfp-mb-3 vfp-font-medium" }, $ = { class: "vfp-text-xs md:vfp-text-sm vfp-text-fg-tertiary vfp-mb-4 md:vfp-mb-6" }, G = ["href"], Y = /* @__PURE__ */ C({
12
+ __name: "index",
13
+ props: {
14
+ url: {},
15
+ tiled: { type: Boolean, default: !0 }
16
+ },
17
+ setup(M) {
18
+ const a = M, { t: l } = S(), s = y(!0), p = y(null), c = y(0), r = y(null);
19
+ let o = null, m = null, d = null, u = null, h = { width: 0, height: 0 };
20
+ const w = () => {
21
+ var v;
22
+ if (!r.value) return { width: 960, height: 540 };
23
+ const t = r.value.clientWidth, e = ((v = r.value.parentElement) == null ? void 0 : v.clientWidth) || 0, i = t > 100 ? t : e > 100 ? e : 300, n = Math.floor(i * 9 / 16);
24
+ return { width: i, height: n };
25
+ }, B = async () => {
26
+ if (!(!r.value || !d || c.value === 0))
27
+ try {
28
+ if (o)
29
+ try {
30
+ o.destroy();
31
+ } catch {
32
+ }
33
+ r.value.innerHTML = "";
34
+ const t = w();
35
+ o = D(r.value, {
36
+ width: t.width,
37
+ height: a.tiled ? t.height * c.value : t.height,
38
+ mode: a.tiled ? "list" : "slide"
39
+ }), await o.preview(d);
40
+ } catch {
41
+ }
42
+ }, z = async () => {
43
+ if (!r.value) return;
44
+ s.value = !0, p.value = null;
45
+ let t = window.setTimeout(() => {
46
+ p.value = l.value("pptx.timeout"), s.value = !1;
47
+ }, 3e4);
48
+ try {
49
+ const e = await fetch(a.url, {
50
+ mode: "cors",
51
+ credentials: "omit",
52
+ redirect: "follow"
53
+ });
54
+ if (!e.ok)
55
+ throw e.status === 404 ? new Error(l.value("pptx.not_found")) : e.status === 403 ? new Error("无权限访问此文件") : e.status >= 500 ? new Error("服务器错误,请稍后重试") : new Error(`文件加载失败 (${e.status})`);
56
+ const i = await e.arrayBuffer();
57
+ if (i.byteLength === 0) throw new Error("文件为空");
58
+ d = i;
59
+ const n = document.createElement("div");
60
+ n.style.cssText = "position:absolute;left:-9999px;top:-9999px;visibility:hidden", document.body.appendChild(n);
61
+ try {
62
+ const v = D(n, {
63
+ width: 100,
64
+ height: 100,
65
+ mode: "slide"
66
+ });
67
+ try {
68
+ await v.preview(i);
69
+ } catch {
70
+ throw new Error(l.value("pptx.invalid_format"));
71
+ }
72
+ const x = v.slideCount;
73
+ if (!x || x === 0) throw new Error(l.value("pptx.no_pages"));
74
+ v.destroy(), c.value = x, r.value && (r.value.innerHTML = "");
75
+ const _ = w();
76
+ o = D(r.value, {
77
+ width: _.width,
78
+ height: a.tiled ? _.height * x : _.height,
79
+ mode: a.tiled ? "list" : "slide"
80
+ }), await o.preview(i), t !== null && (clearTimeout(t), t = null), s.value = !1;
81
+ } finally {
82
+ document.body.contains(n) && document.body.removeChild(n);
83
+ }
84
+ } catch (e) {
85
+ t !== null && clearTimeout(t);
86
+ let i = l.value("pptx.parse_failed");
87
+ e instanceof Error ? i = e.message : typeof e == "string" && (i = e), p.value = i, s.value = !1;
88
+ }
89
+ };
90
+ return P(() => {
91
+ if (!r.value) return;
92
+ let t = !0;
93
+ m = new ResizeObserver(() => {
94
+ if (t) {
95
+ t = !1, h = w();
96
+ return;
97
+ }
98
+ const e = w(), i = Math.abs(h.width - e.width), n = Math.abs(h.height - e.height);
99
+ i < 10 && n < 10 || (h = e, u !== null && clearTimeout(u), u = window.setTimeout(() => {
100
+ o && d && B();
101
+ }, 800));
102
+ }), m.observe(r.value), setTimeout(() => {
103
+ requestAnimationFrame(() => requestAnimationFrame(() => z()));
104
+ }, 150);
105
+ }), W(
106
+ () => a.url,
107
+ () => {
108
+ z();
109
+ }
110
+ ), R(() => {
111
+ if (m && m.disconnect(), u !== null && clearTimeout(u), d = null, c.value = 0, o)
112
+ try {
113
+ o.destroy();
114
+ } catch {
115
+ }
116
+ o = null;
117
+ }), (t, e) => (g(), b("div", V, [
118
+ s.value ? (g(), b("div", q, [
119
+ f("div", A, [
120
+ e[0] || (e[0] = f("div", { class: "vfp-w-10 vfp-h-10 md:vfp-w-12 md:vfp-h-12 vfp-mx-auto vfp-mb-3 vfp-border-4 vfp-border-line-strong vfp-border-t-spinner-head vfp-rounded-full vfp-animate-spin" }, null, -1)),
121
+ f("p", F, E(T(l)("pptx.loading")), 1)
122
+ ])
123
+ ])) : k("", !0),
124
+ p.value && !s.value ? (g(), b("div", H, [
125
+ f("div", I, [
126
+ f("div", O, [
127
+ j(T(N), { class: "vfp-w-12 vfp-h-12 md:vfp-w-16 md:vfp-h-16 vfp-text-fg-primary" })
128
+ ]),
129
+ f("p", U, E(T(l)("pptx.load_failed")), 1),
130
+ f("p", $, E(p.value), 1),
131
+ f("a", {
132
+ href: M.url,
133
+ download: "",
134
+ class: "vfp-inline-flex vfp-items-center vfp-gap-2 vfp-px-4 vfp-py-2 md:vfp-px-6 md:vfp-py-3 vfp-bg-gradient-to-r vfp-from-purple-500 vfp-to-pink-500 vfp-text-fg-primary vfp-text-sm md:vfp-text-base vfp-rounded-lg md:vfp-rounded-xl hover:vfp-scale-105 vfp-transition-all vfp-shadow-lg"
135
+ }, " 下载文件 ", 8, G),
136
+ e[1] || (e[1] = f("p", { class: "vfp-text-xs vfp-text-fg-muted vfp-mt-3 md:vfp-mt-4" }, " 提示:可以使用 Microsoft PowerPoint 或 WPS 打开 ", -1))
137
+ ])
138
+ ])) : k("", !0),
139
+ p.value ? k("", !0) : (g(), b("div", {
140
+ key: 2,
141
+ ref_key: "containerRef",
142
+ ref: r,
143
+ class: "pptx-wrapper vfp-w-full vfp-max-w-full md:vfp-max-w-6xl",
144
+ style: L({ opacity: s.value ? 0 : 1 })
145
+ }, null, 4))
146
+ ]));
147
+ }
148
+ });
149
+ export {
150
+ Y as default
151
+ };
152
+ //# sourceMappingURL=index-BYzQg-jL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BYzQg-jL.mjs","sources":["../../src/renderers/Pptx/index.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ref, watch, onMounted, onBeforeUnmount } from 'vue';\nimport { Presentation } from 'lucide-vue-next';\nimport { init } from 'pptx-preview';\nimport { useTranslator } from '../../composables/useTranslator';\n\nconst props = withDefaults(\n defineProps<{\n url: string;\n tiled?: boolean;\n }>(),\n { tiled: true }\n);\n\nconst { t } = useTranslator();\n\nconst loading = ref(true);\nconst error = ref<string | null>(null);\nconst slideCount = ref(0);\nconst containerRef = ref<HTMLDivElement | null>(null);\nlet previewer: ReturnType<typeof init> | null = null;\nlet resizeObserver: ResizeObserver | null = null;\nlet arrayBufferRef: ArrayBuffer | null = null;\nlet resizeTimeout: number | null = null;\nlet lastDimensions = { width: 0, height: 0 };\n\nconst calculateDimensions = () => {\n if (!containerRef.value) return { width: 960, height: 540 };\n const rawWidth = containerRef.value.clientWidth;\n const parentWidth = containerRef.value.parentElement?.clientWidth || 0;\n const containerWidth = rawWidth > 100 ? rawWidth : parentWidth > 100 ? parentWidth : 300;\n const height = Math.floor((containerWidth * 9) / 16);\n return { width: containerWidth, height };\n};\n\nconst reinitializePreviewer = async () => {\n if (!containerRef.value || !arrayBufferRef || slideCount.value === 0) return;\n\n try {\n if (previewer) {\n try {\n previewer.destroy();\n } catch {\n // ignore\n }\n }\n\n containerRef.value.innerHTML = '';\n\n const currentDimensions = calculateDimensions();\n previewer = init(containerRef.value, {\n width: currentDimensions.width,\n height: props.tiled ? currentDimensions.height * slideCount.value : currentDimensions.height,\n mode: props.tiled ? 'list' : 'slide',\n });\n\n await previewer.preview(arrayBufferRef);\n } catch {\n // 静默处理\n }\n};\n\nconst loadPptx = async () => {\n if (!containerRef.value) return;\n\n loading.value = true;\n error.value = null;\n\n let timeoutId: number | null = window.setTimeout(() => {\n error.value = t.value('pptx.timeout');\n loading.value = false;\n }, 30000);\n\n try {\n const response = await fetch(props.url, {\n mode: 'cors',\n credentials: 'omit',\n redirect: 'follow',\n });\n\n if (!response.ok) {\n if (response.status === 404) throw new Error(t.value('pptx.not_found'));\n if (response.status === 403) throw new Error('无权限访问此文件');\n if (response.status >= 500) throw new Error('服务器错误,请稍后重试');\n throw new Error(`文件加载失败 (${response.status})`);\n }\n\n const arrayBuffer = await response.arrayBuffer();\n if (arrayBuffer.byteLength === 0) throw new Error('文件为空');\n\n arrayBufferRef = arrayBuffer;\n\n // 步骤 1: 创建隐藏容器获取 slideCount\n const hiddenContainer = document.createElement('div');\n hiddenContainer.style.cssText = 'position:absolute;left:-9999px;top:-9999px;visibility:hidden';\n document.body.appendChild(hiddenContainer);\n\n try {\n const tempPreviewer = init(hiddenContainer, {\n width: 100,\n height: 100,\n mode: 'slide',\n });\n\n try {\n await tempPreviewer.preview(arrayBuffer);\n } catch {\n throw new Error(t.value('pptx.invalid_format'));\n }\n\n const count = tempPreviewer.slideCount;\n if (!count || count === 0) throw new Error(t.value('pptx.no_pages'));\n\n tempPreviewer.destroy();\n\n slideCount.value = count;\n\n if (containerRef.value) {\n containerRef.value.innerHTML = '';\n }\n\n const currentDimensions = calculateDimensions();\n previewer = init(containerRef.value, {\n width: currentDimensions.width,\n height: props.tiled ? currentDimensions.height * count : currentDimensions.height,\n mode: props.tiled ? 'list' : 'slide',\n });\n\n await previewer.preview(arrayBuffer);\n\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n\n loading.value = false;\n } finally {\n if (document.body.contains(hiddenContainer)) {\n document.body.removeChild(hiddenContainer);\n }\n }\n } catch (err) {\n if (timeoutId !== null) clearTimeout(timeoutId);\n let errorMsg = t.value('pptx.parse_failed');\n if (err instanceof Error) errorMsg = err.message;\n else if (typeof err === 'string') errorMsg = err;\n error.value = errorMsg;\n loading.value = false;\n }\n};\n\nonMounted(() => {\n if (!containerRef.value) return;\n\n let isInitialRender = true;\n\n resizeObserver = new ResizeObserver(() => {\n if (isInitialRender) {\n isInitialRender = false;\n lastDimensions = calculateDimensions();\n return;\n }\n\n const newDimensions = calculateDimensions();\n const widthDiff = Math.abs(lastDimensions.width - newDimensions.width);\n const heightDiff = Math.abs(lastDimensions.height - newDimensions.height);\n\n if (widthDiff < 10 && heightDiff < 10) return;\n\n lastDimensions = newDimensions;\n\n if (resizeTimeout !== null) clearTimeout(resizeTimeout);\n\n resizeTimeout = window.setTimeout(() => {\n if (previewer && arrayBufferRef) reinitializePreviewer();\n }, 800);\n });\n\n resizeObserver.observe(containerRef.value);\n\n setTimeout(() => {\n requestAnimationFrame(() => requestAnimationFrame(() => loadPptx()));\n }, 150);\n});\n\nwatch(\n () => props.url,\n () => {\n loadPptx();\n }\n);\n\nonBeforeUnmount(() => {\n if (resizeObserver) resizeObserver.disconnect();\n if (resizeTimeout !== null) clearTimeout(resizeTimeout);\n arrayBufferRef = null;\n slideCount.value = 0;\n if (previewer) {\n try {\n previewer.destroy();\n } catch {\n // ignore\n }\n }\n previewer = null;\n});\n</script>\n\n<template>\n <div class=\"vfp-relative vfp-flex vfp-flex-col vfp-items-center vfp-w-full vfp-h-full\">\n <div\n v-if=\"loading\"\n class=\"vfp-absolute vfp-inset-0 vfp-flex vfp-items-center vfp-justify-center vfp-bg-surface-toolbar vfp-backdrop-blur-sm vfp-z-10\"\n >\n <div class=\"vfp-text-center\">\n <div\n class=\"vfp-w-10 vfp-h-10 md:vfp-w-12 md:vfp-h-12 vfp-mx-auto vfp-mb-3 vfp-border-4 vfp-border-line-strong vfp-border-t-spinner-head vfp-rounded-full vfp-animate-spin\"\n />\n <p class=\"vfp-text-xs md:vfp-text-sm vfp-text-fg-secondary vfp-font-medium\">{{ t('pptx.loading') }}</p>\n </div>\n </div>\n\n <div\n v-if=\"error && !loading\"\n class=\"vfp-absolute vfp-inset-0 vfp-flex vfp-items-center vfp-justify-center vfp-bg-surface-toolbar vfp-backdrop-blur-sm vfp-z-10\"\n >\n <div class=\"vfp-text-center vfp-max-w-sm md:vfp-max-w-md vfp-px-4\">\n <div\n class=\"vfp-w-24 vfp-h-24 md:vfp-w-32 md:vfp-h-32 vfp-mx-auto vfp-mb-4 md:vfp-mb-6 vfp-rounded-2xl md:vfp-rounded-3xl vfp-bg-gradient-to-br vfp-from-orange-500 vfp-via-red-500 vfp-to-pink-500 vfp-flex vfp-items-center vfp-justify-center vfp-shadow-2xl\"\n >\n <Presentation class=\"vfp-w-12 vfp-h-12 md:vfp-w-16 md:vfp-h-16 vfp-text-fg-primary\" />\n </div>\n <p class=\"vfp-text-lg md:vfp-text-xl vfp-text-fg-primary vfp-mb-2 md:vfp-mb-3 vfp-font-medium\">\n {{ t('pptx.load_failed') }}\n </p>\n <p class=\"vfp-text-xs md:vfp-text-sm vfp-text-fg-tertiary vfp-mb-4 md:vfp-mb-6\">{{ error }}</p>\n <a\n :href=\"url\"\n download\n class=\"vfp-inline-flex vfp-items-center vfp-gap-2 vfp-px-4 vfp-py-2 md:vfp-px-6 md:vfp-py-3 vfp-bg-gradient-to-r vfp-from-purple-500 vfp-to-pink-500 vfp-text-fg-primary vfp-text-sm md:vfp-text-base vfp-rounded-lg md:vfp-rounded-xl hover:vfp-scale-105 vfp-transition-all vfp-shadow-lg\"\n >\n 下载文件\n </a>\n <p class=\"vfp-text-xs vfp-text-fg-muted vfp-mt-3 md:vfp-mt-4\">\n 提示:可以使用 Microsoft PowerPoint 或 WPS 打开\n </p>\n </div>\n </div>\n\n <div\n v-if=\"!error\"\n ref=\"containerRef\"\n class=\"pptx-wrapper vfp-w-full vfp-max-w-full md:vfp-max-w-6xl\"\n :style=\"{ opacity: loading ? 0 : 1 }\"\n />\n </div>\n</template>\n"],"names":["props","__props","t","useTranslator","loading","ref","error","slideCount","containerRef","previewer","resizeObserver","arrayBufferRef","resizeTimeout","lastDimensions","calculateDimensions","rawWidth","parentWidth","_a","containerWidth","height","reinitializePreviewer","currentDimensions","init","loadPptx","timeoutId","response","arrayBuffer","hiddenContainer","tempPreviewer","count","err","errorMsg","onMounted","isInitialRender","newDimensions","widthDiff","heightDiff","watch","onBeforeUnmount","_openBlock","_createElementBlock","_hoisted_1","_hoisted_2","_createElementVNode","_hoisted_3","_hoisted_4","_toDisplayString","_unref","_hoisted_5","_hoisted_6","_hoisted_7","_createVNode","Presentation","_hoisted_8","_hoisted_9","_hoisted_10","_cache"],"mappings":";;;;;;;;;;;;;;;;;AAMA,UAAMA,IAAQC,GAQR,EAAE,GAAAC,EAAA,IAAMC,EAAA,GAERC,IAAUC,EAAI,EAAI,GAClBC,IAAQD,EAAmB,IAAI,GAC/BE,IAAaF,EAAI,CAAC,GAClBG,IAAeH,EAA2B,IAAI;AACpD,QAAII,IAA4C,MAC5CC,IAAwC,MACxCC,IAAqC,MACrCC,IAA+B,MAC/BC,IAAiB,EAAE,OAAO,GAAG,QAAQ,EAAA;AAEzC,UAA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