@shival99/z-ui-svelte 0.1.15 → 0.1.17

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.
@@ -16,6 +16,7 @@
16
16
  zGalleryFileCategory,
17
17
  zGalleryFormatSize,
18
18
  zGalleryIsAllowedResourceUrl,
19
+ zGalleryIsMarkdown,
19
20
  zGalleryOfficeKind,
20
21
  } from './z-gallery.utils';
21
22
 
@@ -44,6 +45,15 @@
44
45
  const category = $derived(zGalleryFileCategory(file));
45
46
  const mediaUrl = $derived(file.url || file.downloadUrl || null);
46
47
  const isTextual = $derived(category === 'text' || category === 'code');
48
+ const textLanguage = $derived.by(() => {
49
+ if (zGalleryIsMarkdown(file)) {
50
+ return 'markdown';
51
+ }
52
+ if (category === 'code') {
53
+ return zGalleryCodeLanguage(file.name);
54
+ }
55
+ return zGalleryExtension(file.name) || 'txt';
56
+ });
47
57
  const officeKind = $derived(zGalleryOfficeKind(file));
48
58
  // PDFs and Office files are loaded into an iframe / fetched, so only same-origin and trusted origins are allowed.
49
59
  const resourceAllowed = $derived(
@@ -226,11 +236,7 @@
226
236
  {:else if textError}
227
237
  {@render errorState(textError)}
228
238
  {:else}
229
- <ZGalleryTextPreview
230
- class="absolute inset-0 shadow-2xl"
231
- content={text}
232
- language={category === 'code' ? zGalleryCodeLanguage(file.name) : zGalleryExtension(file.name) || 'txt'}
233
- />
239
+ <ZGalleryTextPreview class="absolute inset-0 shadow-2xl" content={text} language={textLanguage} />
234
240
  {/if}
235
241
  </div>
236
242
  {:else}
@@ -1,6 +1,7 @@
1
1
  <script lang="ts">
2
2
  import type { ClassValue } from 'clsx';
3
3
  import { zMergeClasses } from '../../utils/merge-classes';
4
+ import { zGalleryMarkdownHtml } from './z-gallery.utils';
4
5
 
5
6
  interface Props {
6
7
  class?: ClassValue;
@@ -11,6 +12,8 @@
11
12
 
12
13
  let { class: className, content, language = 'text' }: Props = $props();
13
14
 
15
+ const isMarkdown = $derived(language.toLowerCase() === 'markdown');
16
+ const markdownHtml = $derived(isMarkdown ? zGalleryMarkdownHtml(content) : '');
14
17
  const lines = $derived(content.split(/\r?\n/));
15
18
  </script>
16
19
 
@@ -26,15 +29,121 @@
26
29
  {language}
27
30
  </div>
28
31
  <!-- svelte-ignore a11y_no_noninteractive_tabindex (scrollable region must be keyboard focusable) -->
29
- <div
30
- class="grid min-h-0 flex-1 auto-rows-min grid-cols-[auto_1fr] gap-x-4 overflow-auto p-4 font-mono text-xs leading-5"
31
- tabindex="0"
32
- role="region"
33
- aria-label={language}
34
- >
35
- {#each lines as line, index (index)}
36
- <span class="text-muted-foreground text-right select-none">{index + 1}</span>
37
- <span class="break-words whitespace-pre-wrap">{line}</span>
38
- {/each}
39
- </div>
32
+ {#if isMarkdown}
33
+ <div
34
+ class="z-gallery-markdown min-h-0 flex-1 overflow-auto p-5 text-sm leading-6"
35
+ tabindex="0"
36
+ role="region"
37
+ aria-label="Markdown preview"
38
+ >
39
+ {@html markdownHtml}
40
+ </div>
41
+ {:else}
42
+ <div
43
+ class="grid min-h-0 flex-1 auto-rows-min grid-cols-[auto_1fr] gap-x-4 overflow-auto p-4 font-mono text-xs leading-5"
44
+ tabindex="0"
45
+ role="region"
46
+ aria-label={language}
47
+ >
48
+ {#each lines as line, index (index)}
49
+ <span class="text-muted-foreground text-right select-none">{index + 1}</span>
50
+ <span class="break-words whitespace-pre-wrap">{line}</span>
51
+ {/each}
52
+ </div>
53
+ {/if}
40
54
  </div>
55
+
56
+ <style>
57
+ .z-gallery-markdown :global(:first-child) {
58
+ margin-top: 0;
59
+ }
60
+ .z-gallery-markdown :global(:last-child) {
61
+ margin-bottom: 0;
62
+ }
63
+ .z-gallery-markdown :global(h1),
64
+ .z-gallery-markdown :global(h2),
65
+ .z-gallery-markdown :global(h3),
66
+ .z-gallery-markdown :global(h4),
67
+ .z-gallery-markdown :global(h5),
68
+ .z-gallery-markdown :global(h6) {
69
+ margin: 1.25em 0 0.5em;
70
+ color: var(--foreground);
71
+ font-weight: 650;
72
+ line-height: 1.3;
73
+ }
74
+ .z-gallery-markdown :global(h1) {
75
+ font-size: 1.65em;
76
+ }
77
+ .z-gallery-markdown :global(h2) {
78
+ font-size: 1.4em;
79
+ }
80
+ .z-gallery-markdown :global(h3) {
81
+ font-size: 1.2em;
82
+ }
83
+ .z-gallery-markdown :global(p) {
84
+ margin: 0 0 0.85em;
85
+ }
86
+ .z-gallery-markdown :global(ul),
87
+ .z-gallery-markdown :global(ol) {
88
+ margin: 0 0 0.85em;
89
+ padding-left: 1.5em;
90
+ }
91
+ .z-gallery-markdown :global(ul) {
92
+ list-style: disc;
93
+ }
94
+ .z-gallery-markdown :global(ol) {
95
+ list-style: decimal;
96
+ }
97
+ .z-gallery-markdown :global(li + li) {
98
+ margin-top: 0.25em;
99
+ }
100
+ .z-gallery-markdown :global(blockquote) {
101
+ margin: 0 0 0.85em;
102
+ border-left: 3px solid var(--border);
103
+ padding-left: 0.9em;
104
+ color: var(--muted-foreground);
105
+ }
106
+ .z-gallery-markdown :global(pre) {
107
+ overflow: auto;
108
+ margin: 0 0 0.85em;
109
+ border: 1px solid var(--border);
110
+ border-radius: 0.5rem;
111
+ background: color-mix(in oklab, var(--muted) 45%, transparent);
112
+ padding: 0.8em 1em;
113
+ }
114
+ .z-gallery-markdown :global(code) {
115
+ border-radius: 0.25rem;
116
+ background: color-mix(in oklab, var(--muted) 55%, transparent);
117
+ padding: 0.1em 0.3em;
118
+ font-family: var(--font-mono);
119
+ font-size: 0.9em;
120
+ }
121
+ .z-gallery-markdown :global(pre code) {
122
+ background: transparent;
123
+ padding: 0;
124
+ }
125
+ .z-gallery-markdown :global(a) {
126
+ color: var(--primary);
127
+ text-decoration: underline;
128
+ text-underline-offset: 2px;
129
+ }
130
+ .z-gallery-markdown :global(hr) {
131
+ margin: 1.25em 0;
132
+ border-color: var(--border);
133
+ }
134
+ .z-gallery-markdown :global(table) {
135
+ width: 100%;
136
+ border-collapse: collapse;
137
+ margin-bottom: 0.85em;
138
+ }
139
+ .z-gallery-markdown :global(th),
140
+ .z-gallery-markdown :global(td) {
141
+ border: 1px solid var(--border);
142
+ padding: 0.4em 0.65em;
143
+ text-align: left;
144
+ }
145
+ .z-gallery-markdown :global(th) {
146
+ background: color-mix(in oklab, var(--muted) 45%, transparent);
147
+ font-weight: 600;
148
+ }
149
+ </style>
@@ -1,6 +1,9 @@
1
1
  import type { ZFileCategory, ZFileCategoryStyle, ZGalleryFile, ZGalleryOfficeKind } from './z-gallery.types';
2
2
  /** Lower-case extension without the dot, or `''` when the name has none. */
3
3
  export declare function zGalleryExtension(name: string): string;
4
+ export declare function zGalleryIsMarkdown(file: Pick<ZGalleryFile, 'name' | 'type'>): boolean;
5
+ /** Render Markdown files for the read-only Gallery preview and sanitize any embedded HTML. */
6
+ export declare function zGalleryMarkdownHtml(content: string): string;
4
7
  export declare function zGalleryFileCategory(file: Pick<ZGalleryFile, 'name' | 'type'>): ZFileCategory;
5
8
  export declare function zGalleryCategoryStyle(file: Pick<ZGalleryFile, 'name' | 'type'>): ZFileCategoryStyle;
6
9
  export declare function zGalleryFormatSize(bytes: number): string;
@@ -1,4 +1,6 @@
1
+ import { marked } from 'marked';
1
2
  import { Z_GALLERY_FILE_CATEGORY_STYLES } from './z-gallery.define';
3
+ import { zSafeHtml } from '../../utils/z-safe-html';
2
4
  const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp', 'ico', 'avif'];
3
5
  const VIDEO_EXTENSIONS = ['mp4', 'avi', 'mov', 'wmv', 'flv', 'webm', 'mkv'];
4
6
  const AUDIO_EXTENSIONS = ['mp3', 'wav', 'ogg', 'flac', 'aac', 'm4a'];
@@ -28,7 +30,7 @@ const CODE_EXTENSIONS = [
28
30
  'sh',
29
31
  'svelte',
30
32
  ];
31
- const TEXT_EXTENSIONS = ['txt', 'md', 'log'];
33
+ const TEXT_EXTENSIONS = ['txt', 'md', 'markdown', 'mdx', 'log'];
32
34
  const WORD_EXTENSIONS = ['doc', 'docx', 'odt', 'rtf'];
33
35
  const EXCEL_EXTENSIONS = ['xls', 'xlsx', 'csv', 'ods'];
34
36
  const POWERPOINT_EXTENSIONS = ['ppt', 'pptx', 'odp'];
@@ -51,6 +53,13 @@ export function zGalleryExtension(name) {
51
53
  const index = name.lastIndexOf('.');
52
54
  return index < 0 ? '' : name.slice(index + 1).toLowerCase();
53
55
  }
56
+ export function zGalleryIsMarkdown(file) {
57
+ return (file.type?.toLowerCase() === 'text/markdown' || ['md', 'markdown', 'mdx'].includes(zGalleryExtension(file.name)));
58
+ }
59
+ /** Render Markdown files for the read-only Gallery preview and sanitize any embedded HTML. */
60
+ export function zGalleryMarkdownHtml(content) {
61
+ return zSafeHtml(marked.parse(content, { async: false, gfm: true }));
62
+ }
54
63
  export function zGalleryFileCategory(file) {
55
64
  const type = file.type?.toLowerCase() || '';
56
65
  const ext = zGalleryExtension(file.name?.toLowerCase() || '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shival99/z-ui-svelte",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "Z-UI component library for Svelte 5 (runes, no CDK).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -55,14 +55,6 @@
55
55
  "vite": "7.3.1",
56
56
  "vitest": "4.1.10"
57
57
  },
58
- "scripts": {
59
- "package": "svelte-package && node scripts/bundle-core-styles.mjs",
60
- "prepublishOnly": "pnpm package",
61
- "check": "svelte-check --tsconfig ./tsconfig.json",
62
- "test": "vitest run",
63
- "generate:animated-icons": "node scripts/generate-animated-icons.mjs",
64
- "lint": "eslint src"
65
- },
66
58
  "dependencies": {
67
59
  "@dayflow/blossom-color-picker-svelte": "1.3.0",
68
60
  "@floating-ui/dom": "1.8.0",
@@ -91,6 +83,7 @@
91
83
  "exceljs": "^4.4.0",
92
84
  "file-saver": "^2.0.5",
93
85
  "isomorphic-dompurify": "^2.36.0",
86
+ "marked": "17.0.6",
94
87
  "overlayscrollbars": "2.16.0",
95
88
  "qrcode": "^1.5.4",
96
89
  "shiki": "^4.4.3",
@@ -118,5 +111,12 @@
118
111
  "@aiden0z/pptx-renderer": {
119
112
  "optional": true
120
113
  }
114
+ },
115
+ "scripts": {
116
+ "package": "svelte-package && node scripts/bundle-core-styles.mjs",
117
+ "check": "svelte-check --tsconfig ./tsconfig.json",
118
+ "test": "vitest run",
119
+ "generate:animated-icons": "node scripts/generate-animated-icons.mjs",
120
+ "lint": "eslint src"
121
121
  }
122
- }
122
+ }