docviewhelper 0.0.2 → 0.1.1

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/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../packages/docviewhelper/src/index.ts","../../../packages/docviewhelper/src/lib/helper.ts","../../../packages/docviewhelper/src/lib/model.ts"],"sourcesContent":["export * from './lib/helper';\nexport * from './lib/model';\n","// eslint-disable-next-line no-var\ndeclare var mammoth: any;\nimport { IFrameReloader, ViewerRecoveryPlan, ViewerType } from './model';\n\nexport const fileToArray = (url: string): Promise<ArrayBuffer> => {\n return new Promise<ArrayBuffer>((resolve, reject) => {\n try {\n const request = new XMLHttpRequest();\n request.open('GET', url, true);\n request.responseType = 'blob';\n request.onload = () => {\n const reader = new FileReader();\n reader.readAsArrayBuffer(request.response);\n reader.onloadend = () => {\n resolve(reader.result as ArrayBuffer);\n };\n };\n request.send();\n } catch {\n reject(`error while retrieving file ${url}.`);\n }\n });\n};\n\nexport const timeout = (ms: number) => {\n return new Promise((resolve) => setTimeout(resolve, ms));\n};\n\nconst reloadIFrame = (iframe: HTMLIFrameElement) => {\n if (iframe) {\n const url = iframe.src;\n iframe.src = 'about:blank';\n setTimeout(() => {\n if (iframe) {\n iframe.src = url;\n }\n }, 100);\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleFileUpload = (fileInput: any) => {\n return new Promise<string>((resolve, reject) => {\n if (fileInput.target.files && fileInput.target.files[0]) {\n const reader = new FileReader();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n reader.onload = (e: any) => {\n resolve(e.target.result);\n };\n reader.readAsDataURL(fileInput.target.files[0]);\n } else {\n reject('no files selected');\n }\n });\n};\n\nexport const getbaseUrl = (): string => {\n const pathArray = window.location.href.split('/');\n const protocol = pathArray[0];\n const host = pathArray[2];\n return protocol + '//' + host;\n};\n\nexport const getLocation = (href: string) => {\n // eslint-disable-next-line no-useless-escape\n const match = href.match(\n /^(https?\\:)\\/\\/(([^:\\/?#]*)(?:\\:([0-9]+))?)([\\/]{0,1}[^?#]*)(\\?[^#]*|)(#.*|)$/,\n );\n return (\n match && {\n href,\n protocol: match[1],\n host: match[2],\n hostname: match[3],\n port: match[4],\n pathname: match[5],\n search: match[6],\n hash: match[7],\n }\n );\n};\n\nexport const getDocxToHtml = async (url: string) => {\n if (!mammoth) {\n console.error(\n 'Please install mammoth and make sure mammoth.browser.min.js is loaded.',\n );\n }\n const arrayBuffer = await fileToArray(url);\n const resultObject = await mammoth.convertToHtml({ arrayBuffer });\n return resultObject.value;\n};\n\nexport const googleCheckSubscription = (): IFrameReloader => {\n let subscription: any = null;\n let checkCount = 0;\n return {\n subscribe: (iframe: HTMLIFrameElement, interval = 3000, maxChecks = 5) => {\n if (!iframeIsLoaded(iframe)) {\n subscription = setInterval(() => {\n checkCount++;\n if (checkCount >= maxChecks) {\n clearInterval(subscription);\n }\n reloadIFrame(iframe);\n }, interval);\n return subscription;\n } else {\n if (subscription) {\n clearInterval(subscription);\n }\n }\n },\n unsubscribe: () => {\n if (subscription) {\n clearInterval(subscription);\n }\n },\n };\n};\n\nexport const iframeIsLoaded = (iframe: HTMLIFrameElement) => {\n // its #document <html><head></head><body></body></html> when google is returning a 204\n // so if contentDocument = null then it's loaded.\n let isLoaded = false;\n try {\n if (!internetExplorer()) {\n isLoaded = !iframe?.contentDocument;\n } else {\n isLoaded = !iframe?.contentWindow?.document;\n }\n } catch {\n // ignore message Blocked a frame with origin \"http://...\" from accessing a cross-origin frame.\n }\n return isLoaded;\n};\n\nconst internetExplorer = () =>\n /MSIE (\\d+\\.\\d+);/.test(navigator.userAgent) ||\n navigator.userAgent.indexOf('Trident/') > -1;\n\nexport const getViewerDetails = (\n url: string,\n configuredViewer: ViewerType = 'google',\n queryParams = '',\n viewerUrl = '',\n) => {\n switch (configuredViewer) {\n case 'google':\n viewerUrl = `https://docs.google.com/gview?url=%URL%&embedded=true`;\n break;\n case 'office': {\n viewerUrl = `https://view.officeapps.live.com/op/embed.aspx?src=%URL%`;\n break;\n }\n case 'pdf': {\n viewerUrl = '';\n break;\n }\n }\n const externalViewer =\n configuredViewer === 'google' ||\n configuredViewer === 'office' ||\n configuredViewer === 'url';\n\n const u = url?.indexOf('/') ? encodeURIComponent(url) : url;\n let fullUrl = viewerUrl ? viewerUrl.replace('%URL%', u) : url;\n if (queryParams && externalViewer && configuredViewer !== 'url') {\n const start = queryParams.startsWith('&') ? '' : '&';\n fullUrl = `${fullUrl}${start}${queryParams}`;\n }\n return {\n url: fullUrl,\n externalViewer,\n };\n};\n\nexport const getViewerRecoveryPlan = ({\n viewer,\n googleCheckContentLoaded = true,\n googleFinalRetryDelay = 0,\n officeAutoRetry = false,\n}: {\n viewer: ViewerType;\n googleCheckContentLoaded?: boolean;\n googleFinalRetryDelay?: number;\n officeAutoRetry?: boolean;\n}): ViewerRecoveryPlan => {\n const modes: ViewerRecoveryPlan['modes'] = [];\n\n if (viewer === 'google' && googleCheckContentLoaded) {\n modes.push('google-probe');\n }\n\n if (viewer === 'google' && googleFinalRetryDelay > 0) {\n modes.push('google-final-retry');\n }\n\n if (viewer === 'office' && officeAutoRetry) {\n modes.push('office-auto-retry');\n }\n\n return { modes };\n};\n\nexport const replaceLocalUrl = (url: string, overrideLocalhost: string) => {\n const loc = getLocation(url);\n const locReplace = getLocation(overrideLocalhost);\n if (loc && locReplace) {\n return url.replace(\n loc.port ? `${loc.hostname}:${loc.port}` : loc.hostname,\n locReplace.port\n ? `${locReplace.hostname}:${locReplace.port}`\n : locReplace.hostname,\n );\n }\n return url;\n};\n\nconst getBlobFromUrl = (url: string) => {\n return new Promise<File>((resolve, reject) => {\n const request = new XMLHttpRequest();\n request.open('GET', url, true);\n request.responseType = 'blob';\n request.onload = () => {\n resolve(request.response as File);\n };\n request.onerror = reject;\n request.send();\n });\n};\n\nexport const uploadToCloud = (fileUrl: string, api: string) =>\n new Promise((resolve, reject) => {\n getBlobFromUrl(fileUrl).then((blob) => {\n const loc = getLocation(fileUrl);\n const name = loc?.pathname\n ? loc?.pathname?.split('/')[loc?.pathname?.split('/').length - 1]\n : '';\n const formData = new FormData();\n const request = new XMLHttpRequest();\n formData.append('file', blob, name);\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n request.onreadystatechange = (e) => {\n if (request.readyState === XMLHttpRequest.DONE) {\n if (request.status === 200) {\n resolve(request.responseText);\n } else {\n reject(request.responseText);\n }\n }\n };\n request.onerror = reject;\n request.open('post', api, true);\n request.send(formData);\n });\n });\n\nexport const isLocalFile = (file: string) => {\n const loc = getLocation(file);\n const hostname = loc?.hostname || '';\n return (\n ['localhost', '127.0.0.1', '', '::1'].includes(hostname) ||\n hostname.startsWith('192.168.') ||\n hostname.startsWith('10.0.') ||\n hostname.endsWith('.local')\n );\n};\n","export type ViewerType = 'google' | 'office' | 'mammoth' | 'pdf' | 'url';\nexport type ViewerRenderPhase = 'idle' | 'loading' | 'ready' | 'error';\nexport type ViewerRecoveryMode =\n | 'google-probe'\n | 'google-final-retry'\n | 'office-auto-retry';\n\nexport interface ViewerRecoveryPlan {\n modes: ViewerRecoveryMode[];\n}\n\ninterface Props {\n loaded?: () => void;\n url: string;\n queryParams?: string;\n viewerUrl?: string;\n googleCheckInterval?: number;\n disableContent?: 'none' | 'all' | 'poput' | 'popout-hide';\n googleCheckContentLoaded?: boolean;\n viewer?: ViewerType;\n}\n\nexport interface IFrameReloader {\n subscribe: (\n iframe: HTMLIFrameElement,\n interval?: number,\n maxChecks?: number\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) => any;\n unsubscribe: () => void;\n}\n\nexport const defaultProps: Props = {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n loaded: () => {},\n disableContent: 'none',\n googleCheckContentLoaded: true,\n googleCheckInterval: 3000,\n queryParams: '',\n url: '',\n viewer: 'google',\n viewerUrl: '',\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AA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AU;AAClB,YAAQ,KAAK,QAAQ,KAAK,IAAI;AAC9B,YAAQ,KAAK,QAAQ;AAAA,EACvB,CAAC;AACH,CAAC;AAEI,IAAM,cAAc,CAAC,SAAiB;AAC3C,QAAM,MAAM,YAAY,IAAI;AAC5B,QAAM,WAAW,KAAK,YAAY;AAClC,SACE,CAAC,aAAa,aAAa,IAAI,KAAK,EAAE,SAAS,QAAQ,KACvD,SAAS,WAAW,UAAU,KAC9B,SAAS,WAAW,OAAO,KAC3B,SAAS,SAAS,QAAQ;AAE9B;;;AC3OO,IAAM,eAAsB;AAAA;AAAA,EAEjC,QAAQ,MAAM;AAAA,EAAC;AAAA,EACf,gBAAgB;AAAA,EAChB,0BAA0B;AAAA,EAC1B,qBAAqB;AAAA,EACrB,aAAa;AAAA,EACb,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,WAAW;AACb;","names":[]}
package/index.mjs ADDED
@@ -0,0 +1,242 @@
1
+ // src/lib/helper.ts
2
+ var fileToArray = (url) => {
3
+ return new Promise((resolve, reject) => {
4
+ try {
5
+ const request = new XMLHttpRequest();
6
+ request.open("GET", url, true);
7
+ request.responseType = "blob";
8
+ request.onload = () => {
9
+ const reader = new FileReader();
10
+ reader.readAsArrayBuffer(request.response);
11
+ reader.onloadend = () => {
12
+ resolve(reader.result);
13
+ };
14
+ };
15
+ request.send();
16
+ } catch {
17
+ reject(`error while retrieving file ${url}.`);
18
+ }
19
+ });
20
+ };
21
+ var timeout = (ms) => {
22
+ return new Promise((resolve) => setTimeout(resolve, ms));
23
+ };
24
+ var reloadIFrame = (iframe) => {
25
+ if (iframe) {
26
+ const url = iframe.src;
27
+ iframe.src = "about:blank";
28
+ setTimeout(() => {
29
+ if (iframe) {
30
+ iframe.src = url;
31
+ }
32
+ }, 100);
33
+ }
34
+ };
35
+ var handleFileUpload = (fileInput) => {
36
+ return new Promise((resolve, reject) => {
37
+ if (fileInput.target.files && fileInput.target.files[0]) {
38
+ const reader = new FileReader();
39
+ reader.onload = (e) => {
40
+ resolve(e.target.result);
41
+ };
42
+ reader.readAsDataURL(fileInput.target.files[0]);
43
+ } else {
44
+ reject("no files selected");
45
+ }
46
+ });
47
+ };
48
+ var getbaseUrl = () => {
49
+ const pathArray = window.location.href.split("/");
50
+ const protocol = pathArray[0];
51
+ const host = pathArray[2];
52
+ return protocol + "//" + host;
53
+ };
54
+ var getLocation = (href) => {
55
+ const match = href.match(
56
+ /^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/
57
+ );
58
+ return match && {
59
+ href,
60
+ protocol: match[1],
61
+ host: match[2],
62
+ hostname: match[3],
63
+ port: match[4],
64
+ pathname: match[5],
65
+ search: match[6],
66
+ hash: match[7]
67
+ };
68
+ };
69
+ var getDocxToHtml = async (url) => {
70
+ if (!mammoth) {
71
+ console.error(
72
+ "Please install mammoth and make sure mammoth.browser.min.js is loaded."
73
+ );
74
+ }
75
+ const arrayBuffer = await fileToArray(url);
76
+ const resultObject = await mammoth.convertToHtml({ arrayBuffer });
77
+ return resultObject.value;
78
+ };
79
+ var googleCheckSubscription = () => {
80
+ let subscription = null;
81
+ let checkCount = 0;
82
+ return {
83
+ subscribe: (iframe, interval = 3e3, maxChecks = 5) => {
84
+ if (!iframeIsLoaded(iframe)) {
85
+ subscription = setInterval(() => {
86
+ checkCount++;
87
+ if (checkCount >= maxChecks) {
88
+ clearInterval(subscription);
89
+ }
90
+ reloadIFrame(iframe);
91
+ }, interval);
92
+ return subscription;
93
+ } else {
94
+ if (subscription) {
95
+ clearInterval(subscription);
96
+ }
97
+ }
98
+ },
99
+ unsubscribe: () => {
100
+ if (subscription) {
101
+ clearInterval(subscription);
102
+ }
103
+ }
104
+ };
105
+ };
106
+ var iframeIsLoaded = (iframe) => {
107
+ let isLoaded = false;
108
+ try {
109
+ if (!internetExplorer()) {
110
+ isLoaded = !iframe?.contentDocument;
111
+ } else {
112
+ isLoaded = !iframe?.contentWindow?.document;
113
+ }
114
+ } catch {
115
+ }
116
+ return isLoaded;
117
+ };
118
+ var internetExplorer = () => /MSIE (\d+\.\d+);/.test(navigator.userAgent) || navigator.userAgent.indexOf("Trident/") > -1;
119
+ var getViewerDetails = (url, configuredViewer = "google", queryParams = "", viewerUrl = "") => {
120
+ switch (configuredViewer) {
121
+ case "google":
122
+ viewerUrl = `https://docs.google.com/gview?url=%URL%&embedded=true`;
123
+ break;
124
+ case "office": {
125
+ viewerUrl = `https://view.officeapps.live.com/op/embed.aspx?src=%URL%`;
126
+ break;
127
+ }
128
+ case "pdf": {
129
+ viewerUrl = "";
130
+ break;
131
+ }
132
+ }
133
+ const externalViewer = configuredViewer === "google" || configuredViewer === "office" || configuredViewer === "url";
134
+ const u = url?.indexOf("/") ? encodeURIComponent(url) : url;
135
+ let fullUrl = viewerUrl ? viewerUrl.replace("%URL%", u) : url;
136
+ if (queryParams && externalViewer && configuredViewer !== "url") {
137
+ const start = queryParams.startsWith("&") ? "" : "&";
138
+ fullUrl = `${fullUrl}${start}${queryParams}`;
139
+ }
140
+ return {
141
+ url: fullUrl,
142
+ externalViewer
143
+ };
144
+ };
145
+ var getViewerRecoveryPlan = ({
146
+ viewer,
147
+ googleCheckContentLoaded = true,
148
+ googleFinalRetryDelay = 0,
149
+ officeAutoRetry = false
150
+ }) => {
151
+ const modes = [];
152
+ if (viewer === "google" && googleCheckContentLoaded) {
153
+ modes.push("google-probe");
154
+ }
155
+ if (viewer === "google" && googleFinalRetryDelay > 0) {
156
+ modes.push("google-final-retry");
157
+ }
158
+ if (viewer === "office" && officeAutoRetry) {
159
+ modes.push("office-auto-retry");
160
+ }
161
+ return { modes };
162
+ };
163
+ var replaceLocalUrl = (url, overrideLocalhost) => {
164
+ const loc = getLocation(url);
165
+ const locReplace = getLocation(overrideLocalhost);
166
+ if (loc && locReplace) {
167
+ return url.replace(
168
+ loc.port ? `${loc.hostname}:${loc.port}` : loc.hostname,
169
+ locReplace.port ? `${locReplace.hostname}:${locReplace.port}` : locReplace.hostname
170
+ );
171
+ }
172
+ return url;
173
+ };
174
+ var getBlobFromUrl = (url) => {
175
+ return new Promise((resolve, reject) => {
176
+ const request = new XMLHttpRequest();
177
+ request.open("GET", url, true);
178
+ request.responseType = "blob";
179
+ request.onload = () => {
180
+ resolve(request.response);
181
+ };
182
+ request.onerror = reject;
183
+ request.send();
184
+ });
185
+ };
186
+ var uploadToCloud = (fileUrl, api) => new Promise((resolve, reject) => {
187
+ getBlobFromUrl(fileUrl).then((blob) => {
188
+ const loc = getLocation(fileUrl);
189
+ const name = loc?.pathname ? loc?.pathname?.split("/")[loc?.pathname?.split("/").length - 1] : "";
190
+ const formData = new FormData();
191
+ const request = new XMLHttpRequest();
192
+ formData.append("file", blob, name);
193
+ request.onreadystatechange = (e) => {
194
+ if (request.readyState === XMLHttpRequest.DONE) {
195
+ if (request.status === 200) {
196
+ resolve(request.responseText);
197
+ } else {
198
+ reject(request.responseText);
199
+ }
200
+ }
201
+ };
202
+ request.onerror = reject;
203
+ request.open("post", api, true);
204
+ request.send(formData);
205
+ });
206
+ });
207
+ var isLocalFile = (file) => {
208
+ const loc = getLocation(file);
209
+ const hostname = loc?.hostname || "";
210
+ return ["localhost", "127.0.0.1", "", "::1"].includes(hostname) || hostname.startsWith("192.168.") || hostname.startsWith("10.0.") || hostname.endsWith(".local");
211
+ };
212
+
213
+ // src/lib/model.ts
214
+ var defaultProps = {
215
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
216
+ loaded: () => {
217
+ },
218
+ disableContent: "none",
219
+ googleCheckContentLoaded: true,
220
+ googleCheckInterval: 3e3,
221
+ queryParams: "",
222
+ url: "",
223
+ viewer: "google",
224
+ viewerUrl: ""
225
+ };
226
+ export {
227
+ defaultProps,
228
+ fileToArray,
229
+ getDocxToHtml,
230
+ getLocation,
231
+ getViewerDetails,
232
+ getViewerRecoveryPlan,
233
+ getbaseUrl,
234
+ googleCheckSubscription,
235
+ handleFileUpload,
236
+ iframeIsLoaded,
237
+ isLocalFile,
238
+ replaceLocalUrl,
239
+ timeout,
240
+ uploadToCloud
241
+ };
242
+ //# sourceMappingURL=index.mjs.map
package/index.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../packages/docviewhelper/src/lib/helper.ts","../../../packages/docviewhelper/src/lib/model.ts"],"sourcesContent":["// eslint-disable-next-line no-var\ndeclare var mammoth: any;\nimport { IFrameReloader, ViewerRecoveryPlan, ViewerType } from './model';\n\nexport const fileToArray = (url: string): Promise<ArrayBuffer> => {\n return new Promise<ArrayBuffer>((resolve, reject) => {\n try {\n const request = new XMLHttpRequest();\n request.open('GET', url, true);\n request.responseType = 'blob';\n request.onload = () => {\n const reader = new FileReader();\n reader.readAsArrayBuffer(request.response);\n reader.onloadend = () => {\n resolve(reader.result as ArrayBuffer);\n };\n };\n request.send();\n } catch {\n reject(`error while retrieving file ${url}.`);\n }\n });\n};\n\nexport const timeout = (ms: number) => {\n return new Promise((resolve) => setTimeout(resolve, ms));\n};\n\nconst reloadIFrame = (iframe: HTMLIFrameElement) => {\n if (iframe) {\n const url = iframe.src;\n iframe.src = 'about:blank';\n setTimeout(() => {\n if (iframe) {\n iframe.src = url;\n }\n }, 100);\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleFileUpload = (fileInput: any) => {\n return new Promise<string>((resolve, reject) => {\n if (fileInput.target.files && fileInput.target.files[0]) {\n const reader = new FileReader();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n reader.onload = (e: any) => {\n resolve(e.target.result);\n };\n reader.readAsDataURL(fileInput.target.files[0]);\n } else {\n reject('no files selected');\n }\n });\n};\n\nexport const getbaseUrl = (): string => {\n const pathArray = window.location.href.split('/');\n const protocol = pathArray[0];\n const host = pathArray[2];\n return protocol + '//' + host;\n};\n\nexport const getLocation = (href: string) => {\n // eslint-disable-next-line no-useless-escape\n const match = href.match(\n /^(https?\\:)\\/\\/(([^:\\/?#]*)(?:\\:([0-9]+))?)([\\/]{0,1}[^?#]*)(\\?[^#]*|)(#.*|)$/,\n );\n return (\n match && {\n href,\n protocol: match[1],\n host: match[2],\n hostname: match[3],\n port: match[4],\n pathname: match[5],\n search: match[6],\n hash: match[7],\n }\n );\n};\n\nexport const getDocxToHtml = async (url: string) => {\n if (!mammoth) {\n console.error(\n 'Please install mammoth and make sure mammoth.browser.min.js is loaded.',\n );\n }\n const arrayBuffer = await fileToArray(url);\n const resultObject = await mammoth.convertToHtml({ arrayBuffer });\n return resultObject.value;\n};\n\nexport const googleCheckSubscription = (): IFrameReloader => {\n let subscription: any = null;\n let checkCount = 0;\n return {\n subscribe: (iframe: HTMLIFrameElement, interval = 3000, maxChecks = 5) => {\n if (!iframeIsLoaded(iframe)) {\n subscription = setInterval(() => {\n checkCount++;\n if (checkCount >= maxChecks) {\n clearInterval(subscription);\n }\n reloadIFrame(iframe);\n }, interval);\n return subscription;\n } else {\n if (subscription) {\n clearInterval(subscription);\n }\n }\n },\n unsubscribe: () => {\n if (subscription) {\n clearInterval(subscription);\n }\n },\n };\n};\n\nexport const iframeIsLoaded = (iframe: HTMLIFrameElement) => {\n // its #document <html><head></head><body></body></html> when google is returning a 204\n // so if contentDocument = null then it's loaded.\n let isLoaded = false;\n try {\n if (!internetExplorer()) {\n isLoaded = !iframe?.contentDocument;\n } else {\n isLoaded = !iframe?.contentWindow?.document;\n }\n } catch {\n // ignore message Blocked a frame with origin \"http://...\" from accessing a cross-origin frame.\n }\n return isLoaded;\n};\n\nconst internetExplorer = () =>\n /MSIE (\\d+\\.\\d+);/.test(navigator.userAgent) ||\n navigator.userAgent.indexOf('Trident/') > -1;\n\nexport const getViewerDetails = (\n url: string,\n configuredViewer: ViewerType = 'google',\n queryParams = '',\n viewerUrl = '',\n) => {\n switch (configuredViewer) {\n case 'google':\n viewerUrl = `https://docs.google.com/gview?url=%URL%&embedded=true`;\n break;\n case 'office': {\n viewerUrl = `https://view.officeapps.live.com/op/embed.aspx?src=%URL%`;\n break;\n }\n case 'pdf': {\n viewerUrl = '';\n break;\n }\n }\n const externalViewer =\n configuredViewer === 'google' ||\n configuredViewer === 'office' ||\n configuredViewer === 'url';\n\n const u = url?.indexOf('/') ? encodeURIComponent(url) : url;\n let fullUrl = viewerUrl ? viewerUrl.replace('%URL%', u) : url;\n if (queryParams && externalViewer && configuredViewer !== 'url') {\n const start = queryParams.startsWith('&') ? '' : '&';\n fullUrl = `${fullUrl}${start}${queryParams}`;\n }\n return {\n url: fullUrl,\n externalViewer,\n };\n};\n\nexport const getViewerRecoveryPlan = ({\n viewer,\n googleCheckContentLoaded = true,\n googleFinalRetryDelay = 0,\n officeAutoRetry = false,\n}: {\n viewer: ViewerType;\n googleCheckContentLoaded?: boolean;\n googleFinalRetryDelay?: number;\n officeAutoRetry?: boolean;\n}): ViewerRecoveryPlan => {\n const modes: ViewerRecoveryPlan['modes'] = [];\n\n if (viewer === 'google' && googleCheckContentLoaded) {\n modes.push('google-probe');\n }\n\n if (viewer === 'google' && googleFinalRetryDelay > 0) {\n modes.push('google-final-retry');\n }\n\n if (viewer === 'office' && officeAutoRetry) {\n modes.push('office-auto-retry');\n }\n\n return { modes };\n};\n\nexport const replaceLocalUrl = (url: string, overrideLocalhost: string) => {\n const loc = getLocation(url);\n const locReplace = getLocation(overrideLocalhost);\n if (loc && locReplace) {\n return url.replace(\n loc.port ? `${loc.hostname}:${loc.port}` : loc.hostname,\n locReplace.port\n ? `${locReplace.hostname}:${locReplace.port}`\n : locReplace.hostname,\n );\n }\n return url;\n};\n\nconst getBlobFromUrl = (url: string) => {\n return new Promise<File>((resolve, reject) => {\n const request = new XMLHttpRequest();\n request.open('GET', url, true);\n request.responseType = 'blob';\n request.onload = () => {\n resolve(request.response as File);\n };\n request.onerror = reject;\n request.send();\n });\n};\n\nexport const uploadToCloud = (fileUrl: string, api: string) =>\n new Promise((resolve, reject) => {\n getBlobFromUrl(fileUrl).then((blob) => {\n const loc = getLocation(fileUrl);\n const name = loc?.pathname\n ? loc?.pathname?.split('/')[loc?.pathname?.split('/').length - 1]\n : '';\n const formData = new FormData();\n const request = new XMLHttpRequest();\n formData.append('file', blob, name);\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n request.onreadystatechange = (e) => {\n if (request.readyState === XMLHttpRequest.DONE) {\n if (request.status === 200) {\n resolve(request.responseText);\n } else {\n reject(request.responseText);\n }\n }\n };\n request.onerror = reject;\n request.open('post', api, true);\n request.send(formData);\n });\n });\n\nexport const isLocalFile = (file: string) => {\n const loc = getLocation(file);\n const hostname = loc?.hostname || '';\n return (\n ['localhost', '127.0.0.1', '', '::1'].includes(hostname) ||\n hostname.startsWith('192.168.') ||\n hostname.startsWith('10.0.') ||\n hostname.endsWith('.local')\n );\n};\n","export type ViewerType = 'google' | 'office' | 'mammoth' | 'pdf' | 'url';\nexport type ViewerRenderPhase = 'idle' | 'loading' | 'ready' | 'error';\nexport type ViewerRecoveryMode =\n | 'google-probe'\n | 'google-final-retry'\n | 'office-auto-retry';\n\nexport interface ViewerRecoveryPlan {\n modes: ViewerRecoveryMode[];\n}\n\ninterface Props {\n loaded?: () => void;\n url: string;\n queryParams?: string;\n viewerUrl?: string;\n googleCheckInterval?: number;\n disableContent?: 'none' | 'all' | 'poput' | 'popout-hide';\n googleCheckContentLoaded?: boolean;\n viewer?: ViewerType;\n}\n\nexport interface IFrameReloader {\n subscribe: (\n iframe: HTMLIFrameElement,\n interval?: number,\n maxChecks?: number\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) => any;\n unsubscribe: () => void;\n}\n\nexport const defaultProps: Props = {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n loaded: () => {},\n disableContent: 'none',\n googleCheckContentLoaded: true,\n googleCheckInterval: 3000,\n queryParams: '',\n url: '',\n viewer: 'google',\n viewerUrl: '',\n};\n"],"mappings":";AAIO,IAAM,cAAc,CAAC,QAAsC;AAChE,SAAO,IAAI,QAAqB,CAAC,SAAS,WAAW;AACnD,QAAI;AACF,YAAM,UAAU,IAAI,eAAe;AACnC,cA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,aAAa,aAAa,IAAI,KAAK,EAAE,SAAS,QAAQ,KACvD,SAAS,WAAW,UAAU,KAC9B,SAAS,WAAW,OAAO,KAC3B,SAAS,SAAS,QAAQ;AAE9B;;;AC3OO,IAAM,eAAsB;AAAA;AAAA,EAEjC,QAAQ,MAAM;AAAA,EAAC;AAAA,EACf,gBAAgB;AAAA,EAChB,0BAA0B;AAAA,EAC1B,qBAAqB;AAAA,EACrB,aAAa;AAAA,EACb,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,WAAW;AACb;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docviewhelper",
3
- "version": "0.0.2",
3
+ "version": "0.1.1",
4
4
  "license": "MIT",
5
5
  "description": "Helper for ngx-doc-viewer and react-documents.",
6
6
  "author": {
@@ -17,11 +17,17 @@
17
17
  "react-documents"
18
18
  ],
19
19
  "main": "./index.js",
20
- "types": "./src/index.d.ts",
20
+ "module": "./index.mjs",
21
+ "types": "./index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./index.d.ts",
25
+ "import": "./index.mjs",
26
+ "require": "./index.js"
27
+ }
28
+ },
21
29
  "bugs": {
22
30
  "url": "https://github.com/Marcelh1983/document-viewer/issues"
23
31
  },
24
- "homepage": "https://github.com/Marcelh1983/document-viewer/tree/main/packages/docviewhelper",
25
- "module": "./index.js",
26
- "type": "module"
32
+ "homepage": "https://github.com/Marcelh1983/document-viewer/tree/main/packages/docviewhelper"
27
33
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # docviewer-helper
2
-
3
- This library is created to share helper functions to view documents in as well ngx-doc-viewer and react-documents
package/src/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './lib/helper';
2
- export * from './lib/model';
@@ -1,25 +0,0 @@
1
- import { IFrameReloader, ViewerType } from './model';
2
- export declare const fileToArray: (url: string) => Promise<ArrayBuffer>;
3
- export declare const timeout: (ms: number) => Promise<unknown>;
4
- export declare const handleFileUpload: (fileInput: any) => Promise<string>;
5
- export declare const getbaseUrl: () => string;
6
- export declare const getLocation: (href: string) => {
7
- href: string;
8
- protocol: string;
9
- host: string;
10
- hostname: string;
11
- port: string;
12
- pathname: string;
13
- search: string;
14
- hash: string;
15
- } | null;
16
- export declare const getDocxToHtml: (url: string) => Promise<any>;
17
- export declare const googleCheckSubscription: () => IFrameReloader;
18
- export declare const iframeIsLoaded: (iframe: HTMLIFrameElement) => boolean;
19
- export declare const getViewerDetails: (url: string, configuredViewer?: ViewerType, queryParams?: string, viewerUrl?: string) => {
20
- url: string;
21
- externalViewer: boolean;
22
- };
23
- export declare const replaceLocalUrl: (url: string, overrideLocalhost: string) => string;
24
- export declare const uploadToCloud: (fileUrl: string, api: string) => Promise<unknown>;
25
- export declare const isLocalFile: (file: string) => boolean;
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- export declare type ViewerType = 'google' | 'office' | 'mammoth' | 'pdf' | 'url';
2
- interface Props {
3
- loaded?: () => void;
4
- url: string;
5
- queryParams?: string;
6
- viewerUrl?: string;
7
- googleCheckInterval?: number;
8
- disableContent?: 'none' | 'all' | 'poput' | 'popout-hide';
9
- googleCheckContentLoaded?: boolean;
10
- viewer?: ViewerType;
11
- }
12
- export interface IFrameReloader {
13
- subscribe: (iframe: HTMLIFrameElement, interval?: number, maxChecks?: number) => any;
14
- unsubscribe: () => void;
15
- }
16
- export declare const defaultProps: Props;
17
- export {};