jit-viewer 1.1.2 → 1.1.4
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/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/dist/iife/jit-viewer.min.css +1 -1
- package/dist/iife/jit-viewer.min.js +1 -1
- package/dist/index.cjs +10 -10
- package/dist/index.d.ts +5 -4
- package/dist/index.js +248 -124
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -479,7 +479,7 @@ export declare function createViewerState(options?: {
|
|
|
479
479
|
setMounted: (value: boolean) => void;
|
|
480
480
|
setLoading: (value: boolean) => void;
|
|
481
481
|
setError: (err: Error | null) => void;
|
|
482
|
-
setFile: (source: FileSource, name?: string) => void;
|
|
482
|
+
setFile: (source: FileSource, name?: string, explicitType?: FileType) => void;
|
|
483
483
|
clearFile: () => void;
|
|
484
484
|
setZoom: (value: number) => void;
|
|
485
485
|
setRotate: (value: number) => void;
|
|
@@ -858,7 +858,7 @@ export declare type RequestAdapter = (url: string, options?: {
|
|
|
858
858
|
body?: BodyInit;
|
|
859
859
|
}) => Promise<ArrayBuffer>;
|
|
860
860
|
|
|
861
|
-
declare function setFileInternal(file: FileSource, filename?: string): Promise<void>;
|
|
861
|
+
declare function setFileInternal(file: FileSource, filename?: string, type?: Props['type']): Promise<void>;
|
|
862
862
|
|
|
863
863
|
export declare const TextRender: DefineComponent<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_7<Props_7>>, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
864
864
|
error: (error: Error) => void;
|
|
@@ -1169,7 +1169,7 @@ export declare function useViewerState(): {
|
|
|
1169
1169
|
setMounted: (value: boolean) => void;
|
|
1170
1170
|
setLoading: (value: boolean) => void;
|
|
1171
1171
|
setError: (err: Error | null) => void;
|
|
1172
|
-
setFile: (source: FileSource, name?: string) => void;
|
|
1172
|
+
setFile: (source: FileSource, name?: string, explicitType?: FileType) => void;
|
|
1173
1173
|
clearFile: () => void;
|
|
1174
1174
|
setZoom: (value: number) => void;
|
|
1175
1175
|
setRotate: (value: number) => void;
|
|
@@ -1309,7 +1309,7 @@ total: number;
|
|
|
1309
1309
|
print: () => void;
|
|
1310
1310
|
download: () => Promise<void>;
|
|
1311
1311
|
setTheme: (newTheme: Theme) => void;
|
|
1312
|
-
setLocale: (
|
|
1312
|
+
setLocale: (newLocale: Locale) => void;
|
|
1313
1313
|
setToolbar: (config: ToolbarConfig | boolean) => void;
|
|
1314
1314
|
on: (event: string, handler: EventHandler) => void;
|
|
1315
1315
|
off: (event: string, handler: EventHandler) => void;
|
|
@@ -1342,6 +1342,7 @@ export declare interface ViewerInstance {
|
|
|
1342
1342
|
mount: (target?: HTMLElement | string) => Promise<void>;
|
|
1343
1343
|
destroy: () => void;
|
|
1344
1344
|
setFile: (file: FileSource, filename?: string) => Promise<void>;
|
|
1345
|
+
setOptions: (options: Partial<ViewerOptions>) => Promise<void>;
|
|
1345
1346
|
getFile: () => {
|
|
1346
1347
|
source: FileSource;
|
|
1347
1348
|
type: FileType;
|
package/dist/index.js
CHANGED
|
@@ -58,6 +58,13 @@ const MIME_MAP = {
|
|
|
58
58
|
"image/x-icon": "image",
|
|
59
59
|
"image/vnd.microsoft.icon": "image"
|
|
60
60
|
};
|
|
61
|
+
function normalizeMimeType(mimeType) {
|
|
62
|
+
var _a;
|
|
63
|
+
return ((_a = mimeType == null ? void 0 : mimeType.split(";")[0]) == null ? void 0 : _a.trim().toLowerCase()) || "";
|
|
64
|
+
}
|
|
65
|
+
function isInlineLocalUrl(url) {
|
|
66
|
+
return url.startsWith("blob:") || url.startsWith("data:");
|
|
67
|
+
}
|
|
61
68
|
function getFileExtension(filename) {
|
|
62
69
|
const match = filename.toLowerCase().match(/\.([a-z0-9]+)$/);
|
|
63
70
|
return match ? match[1] : "";
|
|
@@ -75,7 +82,7 @@ function getFilenameFromUrl(url) {
|
|
|
75
82
|
}
|
|
76
83
|
function detectFileType(source, filename) {
|
|
77
84
|
if (source instanceof File) {
|
|
78
|
-
const mimeType = source.type;
|
|
85
|
+
const mimeType = normalizeMimeType(source.type);
|
|
79
86
|
if (mimeType && MIME_MAP[mimeType]) {
|
|
80
87
|
return MIME_MAP[mimeType];
|
|
81
88
|
}
|
|
@@ -90,7 +97,7 @@ function detectFileType(source, filename) {
|
|
|
90
97
|
return EXTENSION_MAP[getFileExtension(name)] || "unknown";
|
|
91
98
|
}
|
|
92
99
|
if (source instanceof Blob) {
|
|
93
|
-
const mimeType = source.type;
|
|
100
|
+
const mimeType = normalizeMimeType(source.type);
|
|
94
101
|
if (mimeType && MIME_MAP[mimeType]) {
|
|
95
102
|
return MIME_MAP[mimeType];
|
|
96
103
|
}
|
|
@@ -155,6 +162,13 @@ async function fetchWithProxy(url, fetchOptions, proxyOptions) {
|
|
|
155
162
|
if (proxyOptions == null ? void 0 : proxyOptions.requestAdapter) {
|
|
156
163
|
return proxyOptions.requestAdapter(url, fetchOptions);
|
|
157
164
|
}
|
|
165
|
+
if (isInlineLocalUrl(url)) {
|
|
166
|
+
const response = await fetch(url);
|
|
167
|
+
if (!response.ok) {
|
|
168
|
+
throw new Error(`Failed to fetch local file: ${response.status} ${response.statusText}`);
|
|
169
|
+
}
|
|
170
|
+
return response.arrayBuffer();
|
|
171
|
+
}
|
|
158
172
|
if (proxyOptions == null ? void 0 : proxyOptions.proxyUrl) {
|
|
159
173
|
return fetchViaProxy(url, fetchOptions, proxyOptions.proxyUrl);
|
|
160
174
|
}
|
|
@@ -13702,9 +13716,9 @@ function createViewerState(options = {}) {
|
|
|
13702
13716
|
const setError = (err) => {
|
|
13703
13717
|
error.value = err;
|
|
13704
13718
|
};
|
|
13705
|
-
const setFile = (source, name) => {
|
|
13719
|
+
const setFile = (source, name, explicitType) => {
|
|
13706
13720
|
fileSource.value = source;
|
|
13707
|
-
fileType.value = detectFileType(source, name);
|
|
13721
|
+
fileType.value = explicitType && explicitType !== "unknown" ? explicitType : detectFileType(source, name);
|
|
13708
13722
|
filename.value = name || getFilename(source);
|
|
13709
13723
|
zoom.value = fileType.value === "ofd" ? 0.7 : initialZoom;
|
|
13710
13724
|
rotate.value = initialRotate;
|
|
@@ -128682,10 +128696,12 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
128682
128696
|
height: `${100 / props.zoom}%`
|
|
128683
128697
|
};
|
|
128684
128698
|
});
|
|
128699
|
+
function handleIframeLoad() {
|
|
128700
|
+
loading.value = false;
|
|
128701
|
+
emit2("load");
|
|
128702
|
+
}
|
|
128685
128703
|
async function loadContent() {
|
|
128686
|
-
console.log("[HtmlRender] loadContent called, iframe ready:", !!iframeRef.value, "source:", props.source);
|
|
128687
128704
|
if (!iframeRef.value) {
|
|
128688
|
-
console.log("[HtmlRender] iframe not ready, retrying in 100ms...");
|
|
128689
128705
|
setTimeout(() => loadContent(), 100);
|
|
128690
128706
|
return;
|
|
128691
128707
|
}
|
|
@@ -128693,64 +128709,67 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
128693
128709
|
error.value = "";
|
|
128694
128710
|
try {
|
|
128695
128711
|
if (!props.source) {
|
|
128696
|
-
console.log("[HtmlRender] no source provided");
|
|
128697
128712
|
loading.value = false;
|
|
128698
128713
|
return;
|
|
128699
128714
|
}
|
|
128700
|
-
|
|
128701
|
-
|
|
128702
|
-
|
|
128703
|
-
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
128704
|
-
console.log("[HtmlRender] loading web URL:", url);
|
|
128705
|
-
iframeRef.value.src = url;
|
|
128706
|
-
loading.value = false;
|
|
128707
|
-
emit2("load");
|
|
128708
|
-
return;
|
|
128709
|
-
}
|
|
128710
|
-
if (url.startsWith("data:") || url.startsWith("blob:")) {
|
|
128711
|
-
iframeRef.value.src = url;
|
|
128712
|
-
loading.value = false;
|
|
128713
|
-
emit2("load");
|
|
128714
|
-
return;
|
|
128715
|
-
}
|
|
128716
|
-
}
|
|
128717
|
-
if (props.source instanceof File || props.source instanceof Blob) {
|
|
128718
|
-
console.log("[HtmlRender] source is File/Blob");
|
|
128719
|
-
const htmlContent = await readHtmlContent(props.source);
|
|
128720
|
-
console.log("[HtmlRender] read content length:", htmlContent.length);
|
|
128721
|
-
writeHtmlToIframe(htmlContent);
|
|
128715
|
+
const resolved = await resolveHtmlContent(props.source);
|
|
128716
|
+
if (resolved) {
|
|
128717
|
+
writeHtmlToIframe(resolved.html, resolved.baseUrl);
|
|
128722
128718
|
return;
|
|
128723
128719
|
}
|
|
128724
|
-
|
|
128725
|
-
|
|
128726
|
-
|
|
128727
|
-
const htmlContent = decoder.decode(props.source);
|
|
128728
|
-
writeHtmlToIframe(htmlContent);
|
|
128720
|
+
throw new Error("Unsupported HTML source");
|
|
128721
|
+
} catch (err) {
|
|
128722
|
+
if (tryFallbackToIframeUrl(props.source)) {
|
|
128729
128723
|
return;
|
|
128730
128724
|
}
|
|
128731
|
-
if (typeof props.source === "object" && "url" in props.source) {
|
|
128732
|
-
console.log("[HtmlRender] source is config object");
|
|
128733
|
-
const { url } = props.source;
|
|
128734
|
-
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
128735
|
-
iframeRef.value.src = url;
|
|
128736
|
-
loading.value = false;
|
|
128737
|
-
emit2("load");
|
|
128738
|
-
return;
|
|
128739
|
-
}
|
|
128740
|
-
const buffer2 = await fileToArrayBuffer(props.source, {
|
|
128741
|
-
proxyUrl: props.proxyUrl,
|
|
128742
|
-
requestAdapter: props.requestAdapter
|
|
128743
|
-
});
|
|
128744
|
-
const decoder = new TextDecoder();
|
|
128745
|
-
const htmlContent = decoder.decode(buffer2);
|
|
128746
|
-
writeHtmlToIframe(htmlContent);
|
|
128747
|
-
}
|
|
128748
|
-
console.log("[HtmlRender] unknown source type");
|
|
128749
|
-
} catch (err) {
|
|
128750
|
-
console.error("[HtmlRender] load error:", err);
|
|
128751
128725
|
handleError2(err);
|
|
128752
128726
|
}
|
|
128753
128727
|
}
|
|
128728
|
+
async function resolveHtmlContent(source) {
|
|
128729
|
+
if (source instanceof File || source instanceof Blob) {
|
|
128730
|
+
return {
|
|
128731
|
+
html: await readHtmlContent(source)
|
|
128732
|
+
};
|
|
128733
|
+
}
|
|
128734
|
+
if (source instanceof ArrayBuffer) {
|
|
128735
|
+
return {
|
|
128736
|
+
html: new TextDecoder().decode(source)
|
|
128737
|
+
};
|
|
128738
|
+
}
|
|
128739
|
+
if (typeof source === "string") {
|
|
128740
|
+
if (source.startsWith("data:text/html")) {
|
|
128741
|
+
const response = await fetch(source);
|
|
128742
|
+
return {
|
|
128743
|
+
html: await response.text()
|
|
128744
|
+
};
|
|
128745
|
+
}
|
|
128746
|
+
if (source.startsWith("blob:") || source.startsWith("data:")) {
|
|
128747
|
+
const response = await fetch(source);
|
|
128748
|
+
return {
|
|
128749
|
+
html: await response.text()
|
|
128750
|
+
};
|
|
128751
|
+
}
|
|
128752
|
+
const buffer2 = await fileToArrayBuffer(source, {
|
|
128753
|
+
proxyUrl: props.proxyUrl,
|
|
128754
|
+
requestAdapter: props.requestAdapter
|
|
128755
|
+
});
|
|
128756
|
+
return {
|
|
128757
|
+
html: new TextDecoder().decode(buffer2),
|
|
128758
|
+
baseUrl: resolveBaseUrl(source)
|
|
128759
|
+
};
|
|
128760
|
+
}
|
|
128761
|
+
if (typeof source === "object" && "url" in source) {
|
|
128762
|
+
const buffer2 = await fileToArrayBuffer(source, {
|
|
128763
|
+
proxyUrl: props.proxyUrl,
|
|
128764
|
+
requestAdapter: props.requestAdapter
|
|
128765
|
+
});
|
|
128766
|
+
return {
|
|
128767
|
+
html: new TextDecoder().decode(buffer2),
|
|
128768
|
+
baseUrl: resolveBaseUrl(source.url)
|
|
128769
|
+
};
|
|
128770
|
+
}
|
|
128771
|
+
return null;
|
|
128772
|
+
}
|
|
128754
128773
|
async function readHtmlContent(source) {
|
|
128755
128774
|
return new Promise((resolve2, reject) => {
|
|
128756
128775
|
const reader = new FileReader();
|
|
@@ -128759,31 +128778,130 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
128759
128778
|
reader.readAsText(source);
|
|
128760
128779
|
});
|
|
128761
128780
|
}
|
|
128762
|
-
function
|
|
128781
|
+
function resolveBaseUrl(url) {
|
|
128782
|
+
if (url.startsWith("data:") || url.startsWith("blob:")) {
|
|
128783
|
+
return void 0;
|
|
128784
|
+
}
|
|
128785
|
+
try {
|
|
128786
|
+
return new URL(url, window.location.href).href;
|
|
128787
|
+
} catch {
|
|
128788
|
+
return void 0;
|
|
128789
|
+
}
|
|
128790
|
+
}
|
|
128791
|
+
function tryFallbackToIframeUrl(source) {
|
|
128792
|
+
if (!iframeRef.value) {
|
|
128793
|
+
return false;
|
|
128794
|
+
}
|
|
128795
|
+
const url = typeof source === "string" ? source : typeof source === "object" && "url" in source ? source.url : "";
|
|
128796
|
+
if (!url) {
|
|
128797
|
+
return false;
|
|
128798
|
+
}
|
|
128799
|
+
try {
|
|
128800
|
+
iframeRef.value.removeAttribute("srcdoc");
|
|
128801
|
+
iframeRef.value.src = url;
|
|
128802
|
+
return true;
|
|
128803
|
+
} catch {
|
|
128804
|
+
return false;
|
|
128805
|
+
}
|
|
128806
|
+
}
|
|
128807
|
+
function normalizeHtmlDocument(html, baseUrl) {
|
|
128808
|
+
const parser = new DOMParser();
|
|
128809
|
+
const document2 = parser.parseFromString(html, "text/html");
|
|
128810
|
+
if (!document2.head) {
|
|
128811
|
+
const head = document2.createElement("head");
|
|
128812
|
+
document2.documentElement.insertBefore(head, document2.body || null);
|
|
128813
|
+
}
|
|
128814
|
+
if (!document2.body) {
|
|
128815
|
+
document2.documentElement.appendChild(document2.createElement("body"));
|
|
128816
|
+
}
|
|
128817
|
+
if (baseUrl && !document2.head.querySelector("base")) {
|
|
128818
|
+
const base = document2.createElement("base");
|
|
128819
|
+
base.setAttribute("href", baseUrl);
|
|
128820
|
+
document2.head.prepend(base);
|
|
128821
|
+
}
|
|
128822
|
+
if (!document2.head.querySelector('meta[name="viewport"]')) {
|
|
128823
|
+
const viewport = document2.createElement("meta");
|
|
128824
|
+
viewport.setAttribute("name", "viewport");
|
|
128825
|
+
viewport.setAttribute("content", "width=device-width, initial-scale=1.0");
|
|
128826
|
+
document2.head.appendChild(viewport);
|
|
128827
|
+
}
|
|
128828
|
+
const existingStyle = document2.head.querySelector("style[data-jv-html-preview]");
|
|
128829
|
+
if (existingStyle) {
|
|
128830
|
+
existingStyle.remove();
|
|
128831
|
+
}
|
|
128832
|
+
const style = document2.createElement("style");
|
|
128833
|
+
style.setAttribute("data-jv-html-preview", "true");
|
|
128834
|
+
style.textContent = `
|
|
128835
|
+
:root {
|
|
128836
|
+
color-scheme: light;
|
|
128837
|
+
}
|
|
128838
|
+
|
|
128839
|
+
html {
|
|
128840
|
+
background: #edf3f7;
|
|
128841
|
+
}
|
|
128842
|
+
|
|
128843
|
+
html,
|
|
128844
|
+
body {
|
|
128845
|
+
width: 100%;
|
|
128846
|
+
max-width: 100%;
|
|
128847
|
+
overflow-x: hidden;
|
|
128848
|
+
}
|
|
128849
|
+
|
|
128850
|
+
body {
|
|
128851
|
+
margin: 0;
|
|
128852
|
+
min-height: 100vh;
|
|
128853
|
+
padding: 24px;
|
|
128854
|
+
box-sizing: border-box;
|
|
128855
|
+
background:
|
|
128856
|
+
radial-gradient(circle at top right, rgba(31, 111, 139, 0.08), transparent 28%),
|
|
128857
|
+
linear-gradient(180deg, #f9fbfd 0%, #edf3f7 100%);
|
|
128858
|
+
}
|
|
128859
|
+
|
|
128860
|
+
body > * {
|
|
128861
|
+
box-sizing: border-box;
|
|
128862
|
+
max-width: min(100%, 1100px);
|
|
128863
|
+
margin-left: auto;
|
|
128864
|
+
margin-right: auto;
|
|
128865
|
+
}
|
|
128866
|
+
|
|
128867
|
+
img,
|
|
128868
|
+
svg,
|
|
128869
|
+
canvas,
|
|
128870
|
+
video,
|
|
128871
|
+
iframe,
|
|
128872
|
+
object,
|
|
128873
|
+
embed {
|
|
128874
|
+
max-width: 100% !important;
|
|
128875
|
+
height: auto;
|
|
128876
|
+
}
|
|
128877
|
+
|
|
128878
|
+
table {
|
|
128879
|
+
width: 100% !important;
|
|
128880
|
+
max-width: 100%;
|
|
128881
|
+
display: block;
|
|
128882
|
+
overflow-x: auto;
|
|
128883
|
+
box-sizing: border-box;
|
|
128884
|
+
}
|
|
128885
|
+
|
|
128886
|
+
pre,
|
|
128887
|
+
code {
|
|
128888
|
+
max-width: 100%;
|
|
128889
|
+
overflow-wrap: anywhere;
|
|
128890
|
+
}
|
|
128891
|
+
`;
|
|
128892
|
+
document2.head.appendChild(style);
|
|
128893
|
+
return `<!DOCTYPE html>
|
|
128894
|
+
${document2.documentElement.outerHTML}`;
|
|
128895
|
+
}
|
|
128896
|
+
function writeHtmlToIframe(html, baseUrl) {
|
|
128763
128897
|
if (!iframeRef.value) {
|
|
128764
128898
|
handleError2(new Error("iframe not ready"));
|
|
128765
128899
|
return;
|
|
128766
128900
|
}
|
|
128767
|
-
console.log("[HtmlRender] writing HTML to iframe, length:", html.length);
|
|
128768
128901
|
try {
|
|
128769
|
-
iframeRef.value.
|
|
128770
|
-
|
|
128771
|
-
var _a;
|
|
128772
|
-
try {
|
|
128773
|
-
const doc2 = (_a = iframeRef.value) == null ? void 0 : _a.contentDocument;
|
|
128774
|
-
if (doc2) {
|
|
128775
|
-
doc2.open();
|
|
128776
|
-
doc2.write(html);
|
|
128777
|
-
doc2.close();
|
|
128778
|
-
}
|
|
128779
|
-
} catch (e) {
|
|
128780
|
-
console.warn("[HtmlRender] document write failed, but srcdoc is set");
|
|
128781
|
-
}
|
|
128782
|
-
loading.value = false;
|
|
128783
|
-
emit2("load");
|
|
128784
|
-
});
|
|
128902
|
+
iframeRef.value.removeAttribute("src");
|
|
128903
|
+
iframeRef.value.srcdoc = normalizeHtmlDocument(html, baseUrl);
|
|
128785
128904
|
} catch (err) {
|
|
128786
|
-
console.error("[HtmlRender] write error:", err);
|
|
128787
128905
|
handleError2(err);
|
|
128788
128906
|
}
|
|
128789
128907
|
}
|
|
@@ -128794,11 +128912,11 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
128794
128912
|
}
|
|
128795
128913
|
watch(() => props.source, (newSource, oldSource) => {
|
|
128796
128914
|
if (newSource !== oldSource) {
|
|
128797
|
-
|
|
128915
|
+
loadContent();
|
|
128798
128916
|
}
|
|
128799
128917
|
}, { immediate: false });
|
|
128800
128918
|
onMounted(() => {
|
|
128801
|
-
|
|
128919
|
+
loadContent();
|
|
128802
128920
|
});
|
|
128803
128921
|
return (_ctx, _cache) => {
|
|
128804
128922
|
return openBlock(), createElementBlock("div", {
|
|
@@ -128811,8 +128929,9 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
128811
128929
|
ref: iframeRef,
|
|
128812
128930
|
class: "jv-html-iframe",
|
|
128813
128931
|
style: normalizeStyle(renderStyle.value),
|
|
128932
|
+
onLoad: handleIframeLoad,
|
|
128814
128933
|
sandbox: "allow-scripts allow-same-origin allow-popups allow-forms allow-top-navigation"
|
|
128815
|
-
}, null,
|
|
128934
|
+
}, null, 36),
|
|
128816
128935
|
withDirectives(createBaseVNode("div", _hoisted_1$3, [..._cache[0] || (_cache[0] = [
|
|
128817
128936
|
createBaseVNode("div", { class: "jv-loading-spinner" }, null, -1),
|
|
128818
128937
|
createBaseVNode("span", null, "加载中...", -1)
|
|
@@ -128826,7 +128945,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
128826
128945
|
};
|
|
128827
128946
|
}
|
|
128828
128947
|
});
|
|
128829
|
-
const HtmlRender = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-
|
|
128948
|
+
const HtmlRender = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-be7a9198"]]);
|
|
128830
128949
|
const _hoisted_1$2 = {
|
|
128831
128950
|
key: 0,
|
|
128832
128951
|
class: "jv-image-loading"
|
|
@@ -129411,7 +129530,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
129411
129530
|
let copyrightObserver = null;
|
|
129412
129531
|
let copyrightCheckInterval = null;
|
|
129413
129532
|
const events = createEventBus();
|
|
129414
|
-
const { t } = useLocaleProvider(props.locale);
|
|
129533
|
+
const { t, setLocale } = useLocaleProvider(props.locale);
|
|
129415
129534
|
const viewerRefForTheme = computed(() => viewerRef.value || null);
|
|
129416
129535
|
const { theme: currentTheme, setTheme } = useThemeProvider(props.theme, viewerRefForTheme);
|
|
129417
129536
|
const state = createViewerState({
|
|
@@ -129643,17 +129762,17 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
129643
129762
|
}
|
|
129644
129763
|
setMounted(true);
|
|
129645
129764
|
if (props.file) {
|
|
129646
|
-
await setFileInternal(props.file, props.filename);
|
|
129765
|
+
await setFileInternal(props.file, props.filename, props.type);
|
|
129647
129766
|
}
|
|
129648
129767
|
emit2("ready");
|
|
129649
129768
|
events.emit("ready");
|
|
129650
129769
|
(_a2 = props.onReady) == null ? void 0 : _a2.call(props);
|
|
129651
129770
|
}
|
|
129652
|
-
async function setFileInternal(file, filename) {
|
|
129771
|
+
async function setFileInternal(file, filename, type) {
|
|
129653
129772
|
try {
|
|
129654
129773
|
setLoading(true);
|
|
129655
129774
|
setError(null);
|
|
129656
|
-
setFile(file, filename);
|
|
129775
|
+
setFile(file, filename, type);
|
|
129657
129776
|
} catch (err) {
|
|
129658
129777
|
handleError2(err);
|
|
129659
129778
|
}
|
|
@@ -129666,9 +129785,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
129666
129785
|
(_a2 = props.onDestroy) == null ? void 0 : _a2.call(props);
|
|
129667
129786
|
}
|
|
129668
129787
|
watch(() => props.theme, setTheme);
|
|
129669
|
-
watch(() => props.
|
|
129788
|
+
watch(() => props.locale, setLocale);
|
|
129789
|
+
watch([() => props.file, () => props.filename, () => props.type], ([file, filename, type]) => {
|
|
129670
129790
|
if (file) {
|
|
129671
|
-
setFileInternal(file,
|
|
129791
|
+
setFileInternal(file, filename, type);
|
|
129672
129792
|
}
|
|
129673
129793
|
});
|
|
129674
129794
|
watch(fileType, syncPageController, { immediate: true });
|
|
@@ -129682,7 +129802,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
129682
129802
|
});
|
|
129683
129803
|
setMounted(true);
|
|
129684
129804
|
if (props.file) {
|
|
129685
|
-
setFileInternal(props.file, props.filename);
|
|
129805
|
+
setFileInternal(props.file, props.filename, props.type);
|
|
129686
129806
|
}
|
|
129687
129807
|
startCopyrightProtection();
|
|
129688
129808
|
emit2("ready");
|
|
@@ -129727,9 +129847,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
129727
129847
|
}
|
|
129728
129848
|
},
|
|
129729
129849
|
setTheme,
|
|
129730
|
-
setLocale
|
|
129731
|
-
useLocaleProvider(locale);
|
|
129732
|
-
},
|
|
129850
|
+
setLocale,
|
|
129733
129851
|
setToolbar: (config) => {
|
|
129734
129852
|
},
|
|
129735
129853
|
on: events.on,
|
|
@@ -129751,32 +129869,18 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
129751
129869
|
config: toolbarConfig.value,
|
|
129752
129870
|
visible: toolbarVisible.value
|
|
129753
129871
|
}, null, 8, ["config", "visible"])) : createCommentVNode("", true),
|
|
129754
|
-
createBaseVNode("div", {
|
|
129755
|
-
class: "jv-viewer__branding",
|
|
129756
|
-
ref_key: "brandingRef",
|
|
129757
|
-
ref: brandingRef
|
|
129758
|
-
}, [..._cache[0] || (_cache[0] = [
|
|
129759
|
-
createBaseVNode("a", {
|
|
129760
|
-
href: "https://github.com/jitOffice/jit-viewer-sdk",
|
|
129761
|
-
target: "_blank",
|
|
129762
|
-
rel: "noopener noreferrer",
|
|
129763
|
-
class: "jv-branding-link"
|
|
129764
|
-
}, "JitViewer", -1),
|
|
129765
|
-
createTextVNode("提供文档预览支持 ", -1)
|
|
129766
|
-
])], 512),
|
|
129767
129872
|
createBaseVNode("div", {
|
|
129768
129873
|
ref_key: "contentRef",
|
|
129769
129874
|
ref: contentRef,
|
|
129770
129875
|
class: "jv-viewer__content"
|
|
129771
129876
|
}, [
|
|
129772
|
-
|
|
129773
|
-
key: 0,
|
|
129877
|
+
createVNode(unref(Watermark), {
|
|
129774
129878
|
watermark: __props.watermark,
|
|
129775
129879
|
style: { width: "100%", height: "100%" }
|
|
129776
129880
|
}, {
|
|
129777
129881
|
default: withCtx(() => [
|
|
129778
129882
|
unref(error) ? (openBlock(), createElementBlock("div", _hoisted_1, [
|
|
129779
|
-
_cache[
|
|
129883
|
+
_cache[0] || (_cache[0] = createBaseVNode("svg", {
|
|
129780
129884
|
class: "jv-error-icon",
|
|
129781
129885
|
viewBox: "0 0 24 24",
|
|
129782
129886
|
fill: "none",
|
|
@@ -129810,7 +129914,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
129810
129914
|
style: normalizeStyle(renderStyle.value)
|
|
129811
129915
|
}, [
|
|
129812
129916
|
withDirectives(createBaseVNode("div", _hoisted_5, [
|
|
129813
|
-
_cache[
|
|
129917
|
+
_cache[1] || (_cache[1] = createBaseVNode("div", { class: "jv-loading-spinner" }, null, -1)),
|
|
129814
129918
|
createBaseVNode("span", _hoisted_6, toDisplayString(unref(t)("loading")), 1)
|
|
129815
129919
|
], 512), [
|
|
129816
129920
|
[vShow, unref(loading)]
|
|
@@ -129883,7 +129987,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
129883
129987
|
zoom: unref(zoom),
|
|
129884
129988
|
onLoad: handleLoad,
|
|
129885
129989
|
onError: handleError2
|
|
129886
|
-
}, null, 8, ["source", "zoom"])) : unref(fileType) === "unknown" && unref(fileSource) ? (openBlock(), createElementBlock("div", _hoisted_7, [..._cache[
|
|
129990
|
+
}, null, 8, ["source", "zoom"])) : unref(fileType) === "unknown" && unref(fileSource) ? (openBlock(), createElementBlock("div", _hoisted_7, [..._cache[2] || (_cache[2] = [
|
|
129887
129991
|
createBaseVNode("span", null, "未知文件类型", -1)
|
|
129888
129992
|
])])) : (openBlock(), createElementBlock("div", _hoisted_8, [
|
|
129889
129993
|
createBaseVNode("span", null, toDisplayString(unref(t)("error.unsupportedType")), 1)
|
|
@@ -129891,44 +129995,62 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
129891
129995
|
], 4))
|
|
129892
129996
|
]),
|
|
129893
129997
|
_: 1
|
|
129894
|
-
}, 8, ["watermark"])
|
|
129895
|
-
], 512)
|
|
129998
|
+
}, 8, ["watermark"])
|
|
129999
|
+
], 512),
|
|
130000
|
+
createBaseVNode("div", {
|
|
130001
|
+
ref_key: "brandingRef",
|
|
130002
|
+
ref: brandingRef,
|
|
130003
|
+
class: "jv-viewer__branding"
|
|
130004
|
+
}, [..._cache[3] || (_cache[3] = [
|
|
130005
|
+
createBaseVNode("a", {
|
|
130006
|
+
href: "https://github.com/jitOffice/jit-viewer-sdk",
|
|
130007
|
+
target: "_blank",
|
|
130008
|
+
rel: "noopener noreferrer",
|
|
130009
|
+
class: "jv-branding-link"
|
|
130010
|
+
}, "JitViewer", -1),
|
|
130011
|
+
createBaseVNode("span", { class: "jv-branding-text" }, "提供文档预览支持", -1)
|
|
130012
|
+
])], 512)
|
|
129896
130013
|
], 6);
|
|
129897
130014
|
};
|
|
129898
130015
|
}
|
|
129899
130016
|
});
|
|
129900
|
-
const Viewer = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-
|
|
130017
|
+
const Viewer = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-4a7f7368"]]);
|
|
129901
130018
|
function createViewer(options) {
|
|
129902
130019
|
const events = createEventBus();
|
|
129903
130020
|
let app = null;
|
|
129904
130021
|
let container = null;
|
|
129905
130022
|
let viewerComponent = null;
|
|
130023
|
+
const runtimeOptions = /* @__PURE__ */ reactive({ ...options });
|
|
130024
|
+
const updateOptions = async (nextOptions) => {
|
|
130025
|
+
Object.assign(runtimeOptions, nextOptions);
|
|
130026
|
+
await nextTick();
|
|
130027
|
+
};
|
|
129906
130028
|
const mergedOptions = {
|
|
129907
|
-
...
|
|
130029
|
+
...runtimeOptions,
|
|
129908
130030
|
onReady: () => {
|
|
129909
130031
|
var _a;
|
|
129910
|
-
(_a =
|
|
130032
|
+
(_a = runtimeOptions.onReady) == null ? void 0 : _a.call(runtimeOptions);
|
|
129911
130033
|
events.emit("ready");
|
|
129912
130034
|
},
|
|
129913
130035
|
onLoad: () => {
|
|
129914
130036
|
var _a;
|
|
129915
|
-
(_a =
|
|
130037
|
+
(_a = runtimeOptions.onLoad) == null ? void 0 : _a.call(runtimeOptions);
|
|
129916
130038
|
events.emit("load");
|
|
129917
130039
|
},
|
|
129918
130040
|
onError: (error) => {
|
|
129919
130041
|
var _a;
|
|
129920
|
-
(_a =
|
|
130042
|
+
(_a = runtimeOptions.onError) == null ? void 0 : _a.call(runtimeOptions, error);
|
|
129921
130043
|
events.emit("error", error);
|
|
129922
130044
|
},
|
|
129923
130045
|
onDestroy: () => {
|
|
129924
130046
|
var _a;
|
|
129925
|
-
(_a =
|
|
130047
|
+
(_a = runtimeOptions.onDestroy) == null ? void 0 : _a.call(runtimeOptions);
|
|
129926
130048
|
events.emit("destroy");
|
|
129927
130049
|
}
|
|
129928
130050
|
};
|
|
129929
130051
|
const instance = {
|
|
129930
130052
|
async mount(target) {
|
|
129931
|
-
const el = target ? getElement(target) : typeof
|
|
130053
|
+
const el = target ? getElement(target) : typeof runtimeOptions.target === "string" ? getElement(runtimeOptions.target) : runtimeOptions.target;
|
|
129932
130054
|
if (!el) {
|
|
129933
130055
|
throw new Error("Target element not found");
|
|
129934
130056
|
}
|
|
@@ -129936,7 +130058,11 @@ function createViewer(options) {
|
|
|
129936
130058
|
app = createApp({
|
|
129937
130059
|
render() {
|
|
129938
130060
|
return h(Viewer, {
|
|
129939
|
-
...
|
|
130061
|
+
...runtimeOptions,
|
|
130062
|
+
onReady: mergedOptions.onReady,
|
|
130063
|
+
onLoad: mergedOptions.onLoad,
|
|
130064
|
+
onError: mergedOptions.onError,
|
|
130065
|
+
onDestroy: mergedOptions.onDestroy,
|
|
129940
130066
|
ref: (ref2) => {
|
|
129941
130067
|
viewerComponent = ref2;
|
|
129942
130068
|
}
|
|
@@ -129955,9 +130081,10 @@ function createViewer(options) {
|
|
|
129955
130081
|
container = null;
|
|
129956
130082
|
},
|
|
129957
130083
|
async setFile(file, filename) {
|
|
129958
|
-
|
|
129959
|
-
|
|
129960
|
-
|
|
130084
|
+
await updateOptions({ file, filename });
|
|
130085
|
+
},
|
|
130086
|
+
async setOptions(nextOptions) {
|
|
130087
|
+
await updateOptions(nextOptions);
|
|
129961
130088
|
},
|
|
129962
130089
|
getFile() {
|
|
129963
130090
|
var _a;
|
|
@@ -130007,16 +130134,13 @@ function createViewer(options) {
|
|
|
130007
130134
|
}
|
|
130008
130135
|
},
|
|
130009
130136
|
setTheme(theme) {
|
|
130010
|
-
|
|
130011
|
-
(_a = viewerComponent == null ? void 0 : viewerComponent.setTheme) == null ? void 0 : _a.call(viewerComponent, theme);
|
|
130137
|
+
updateOptions({ theme });
|
|
130012
130138
|
},
|
|
130013
130139
|
setLocale(locale) {
|
|
130014
|
-
|
|
130015
|
-
(_a = viewerComponent == null ? void 0 : viewerComponent.setLocale) == null ? void 0 : _a.call(viewerComponent, locale);
|
|
130140
|
+
updateOptions({ locale });
|
|
130016
130141
|
},
|
|
130017
130142
|
setToolbar(config) {
|
|
130018
|
-
|
|
130019
|
-
(_a = viewerComponent == null ? void 0 : viewerComponent.setToolbar) == null ? void 0 : _a.call(viewerComponent, config);
|
|
130143
|
+
updateOptions({ toolbar: config });
|
|
130020
130144
|
},
|
|
130021
130145
|
on(event, handler) {
|
|
130022
130146
|
events.on(event, handler);
|