@shival99/z-ui-svelte 0.1.13 → 0.1.14

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.
@@ -0,0 +1,44 @@
1
+ <script lang="ts">
2
+ import { zTranslate } from '../../i18n/translate.svelte';
3
+ import type { ZGalleryFile } from './z-gallery.types';
4
+
5
+ // A Word, Excel or PowerPoint file shown as the HTML the app renders for it (`zOfficeHtml`). The HTML runs in a sandboxed
6
+ // frame without the page's origin: its own scripts (sheet tabs, slide arrows) work, and it cannot reach the app.
7
+ interface Props {
8
+ file: ZGalleryFile;
9
+ zOfficeHtml: (file: ZGalleryFile) => Promise<string>;
10
+ onLoaded?: () => void;
11
+ onError?: (message: string) => void;
12
+ }
13
+
14
+ let { file, zOfficeHtml, onLoaded, onError }: Props = $props();
15
+
16
+ let srcdoc = $state<string | null>(null);
17
+
18
+ $effect(() => {
19
+ const target = file;
20
+ let stale = false;
21
+ srcdoc = null;
22
+ zOfficeHtml(target)
23
+ .then((html) => {
24
+ if (stale) return;
25
+ srcdoc = html;
26
+ })
27
+ .catch((error: unknown) => {
28
+ if (!stale) onError?.(error instanceof Error ? error.message : zTranslate('i18n_z_ui_gallery_preview_load_error'));
29
+ });
30
+ return () => {
31
+ stale = true;
32
+ };
33
+ });
34
+ </script>
35
+
36
+ {#if srcdoc !== null}
37
+ <iframe
38
+ title={file.name}
39
+ class="bg-card size-full border-0 transition-opacity duration-300 motion-reduce:transition-none"
40
+ sandbox="allow-scripts"
41
+ srcdoc={srcdoc}
42
+ onload={() => onLoaded?.()}
43
+ ></iframe>
44
+ {/if}
@@ -0,0 +1,10 @@
1
+ import type { ZGalleryFile } from './z-gallery.types';
2
+ interface Props {
3
+ file: ZGalleryFile;
4
+ zOfficeHtml: (file: ZGalleryFile) => Promise<string>;
5
+ onLoaded?: () => void;
6
+ onError?: (message: string) => void;
7
+ }
8
+ declare const ZGalleryOfficeHtml: import("svelte").Component<Props, {}, "">;
9
+ type ZGalleryOfficeHtml = ReturnType<typeof ZGalleryOfficeHtml>;
10
+ export default ZGalleryOfficeHtml;
@@ -23,6 +23,8 @@
23
23
  zPdfViewerConfig?: ZGalleryPdfViewerConfig;
24
24
  /** Extra origins (besides the page's own) PDFs may be loaded from. */
25
25
  zTrustedResourceOrigins?: string[];
26
+ /** Renders a Word, Excel or PowerPoint file as HTML, shown in a sandboxed frame instead of the built-in renderers. */
27
+ zOfficeHtml?: (file: ZGalleryFile) => Promise<string>;
26
28
  onClose?: () => void;
27
29
  onDownload?: (file: ZGalleryFile) => void;
28
30
  onNavigate?: (file: ZGalleryFile) => void;
@@ -36,6 +38,7 @@
36
38
  zShowToolbar = true,
37
39
  zPdfViewerConfig = {},
38
40
  zTrustedResourceOrigins = [],
41
+ zOfficeHtml,
39
42
  onClose,
40
43
  onDownload,
41
44
  onNavigate,
@@ -257,7 +260,7 @@
257
260
  data-dismiss
258
261
  >
259
262
  {#key shown.id}
260
- <ZGalleryPreviewStage file={shown} {rotation} bind:zoomed {zPdfViewerConfig} {zTrustedResourceOrigins} />
263
+ <ZGalleryPreviewStage file={shown} {rotation} bind:zoomed {zPdfViewerConfig} {zTrustedResourceOrigins} {zOfficeHtml} />
261
264
  {/key}
262
265
  </div>
263
266
  </div>
@@ -13,6 +13,8 @@ interface Props {
13
13
  zPdfViewerConfig?: ZGalleryPdfViewerConfig;
14
14
  /** Extra origins (besides the page's own) PDFs may be loaded from. */
15
15
  zTrustedResourceOrigins?: string[];
16
+ /** Renders a Word, Excel or PowerPoint file as HTML, shown in a sandboxed frame instead of the built-in renderers. */
17
+ zOfficeHtml?: (file: ZGalleryFile) => Promise<string>;
16
18
  onClose?: () => void;
17
19
  onDownload?: (file: ZGalleryFile) => void;
18
20
  onNavigate?: (file: ZGalleryFile) => void;
@@ -4,6 +4,7 @@
4
4
  import ZIcon from '../z-icon/ZIcon.svelte';
5
5
  import type { ZIcon as ZIconName } from '../z-icon/z-icon.types';
6
6
  import ZSkeleton from '../z-skeleton/ZSkeleton.svelte';
7
+ import ZGalleryOfficeHtml from './ZGalleryOfficeHtml.svelte';
7
8
  import ZGalleryOfficePreview from './ZGalleryOfficePreview.svelte';
8
9
  import ZGalleryPdfViewer from './ZGalleryPdfViewer.svelte';
9
10
  import ZGalleryTextPreview from './ZGalleryTextPreview.svelte';
@@ -25,6 +26,8 @@
25
26
  zoomed?: boolean;
26
27
  zPdfViewerConfig?: ZGalleryPdfViewerConfig;
27
28
  zTrustedResourceOrigins?: string[];
29
+ /** Renders an Office file as HTML (see ZGalleryOfficeHtml). Without it the built-in renderers are used. */
30
+ zOfficeHtml?: (file: ZGalleryFile) => Promise<string>;
28
31
  }
29
32
 
30
33
  let {
@@ -33,6 +36,7 @@
33
36
  zoomed = $bindable(false),
34
37
  zPdfViewerConfig = {},
35
38
  zTrustedResourceOrigins = [],
39
+ zOfficeHtml,
36
40
  }: Props = $props();
37
41
 
38
42
  // The lightbox keys this component by file id, so state starts fresh for every file.
@@ -214,7 +218,11 @@
214
218
  {#if loading}
215
219
  {@render loadingState()}
216
220
  {/if}
217
- <ZGalleryOfficePreview kind={officeKind} url={mediaUrl} name={file.name} onLoaded={done} onError={officeFailed} />
221
+ {#if zOfficeHtml}
222
+ <ZGalleryOfficeHtml {file} {zOfficeHtml} onLoaded={done} onError={officeFailed} />
223
+ {:else}
224
+ <ZGalleryOfficePreview kind={officeKind} url={mediaUrl} name={file.name} onLoaded={done} onError={officeFailed} />
225
+ {/if}
218
226
  {/if}
219
227
  </div>
220
228
  {:else if isTextual}
@@ -5,6 +5,8 @@ interface Props {
5
5
  zoomed?: boolean;
6
6
  zPdfViewerConfig?: ZGalleryPdfViewerConfig;
7
7
  zTrustedResourceOrigins?: string[];
8
+ /** Renders an Office file as HTML (see ZGalleryOfficeHtml). Without it the built-in renderers are used. */
9
+ zOfficeHtml?: (file: ZGalleryFile) => Promise<string>;
8
10
  }
9
11
  declare const ZGalleryPreviewStage: import("svelte").Component<Props, {}, "zoomed">;
10
12
  type ZGalleryPreviewStage = ReturnType<typeof ZGalleryPreviewStage>;
@@ -38,17 +38,22 @@ export function zTabsCancelIdle(handle) {
38
38
  window.clearTimeout(handle);
39
39
  }
40
40
  export function zTabsMeasure(button) {
41
- const container = button.offsetParent ?? button.parentElement;
41
+ const container = (button.offsetParent ?? button.parentElement);
42
42
  if (!container) {
43
43
  return { x: button.offsetLeft, y: button.offsetTop, w: button.offsetWidth, h: button.offsetHeight };
44
44
  }
45
+ // Screen rects follow transforms: a strip inside a panel that is still scaling in measured smaller, and the indicator
46
+ // stayed off until a later resize. Dividing by the container's own scale (its drawn width over its layout width) gives
47
+ // the layout geometry back, with the fractional part kept.
45
48
  const buttonRect = button.getBoundingClientRect();
46
49
  const containerRect = container.getBoundingClientRect();
50
+ const scaleX = container.offsetWidth ? containerRect.width / container.offsetWidth : 1;
51
+ const scaleY = container.offsetHeight ? containerRect.height / container.offsetHeight : 1;
47
52
  return {
48
- x: buttonRect.left - containerRect.left,
49
- y: buttonRect.top - containerRect.top,
50
- w: buttonRect.width,
51
- h: buttonRect.height,
53
+ x: (buttonRect.left - containerRect.left) / scaleX,
54
+ y: (buttonRect.top - containerRect.top) / scaleY,
55
+ w: buttonRect.width / scaleX,
56
+ h: buttonRect.height / scaleY,
52
57
  };
53
58
  }
54
59
  export function zTabsBoxEquals(a, b) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shival99/z-ui-svelte",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Z-UI component library for Svelte 5 (runes, no CDK).",
5
5
  "license": "MIT",
6
6
  "type": "module",