gradio-pr-bot commited on
Commit
2358d2c
·
verified ·
1 Parent(s): 4fbe614

Upload folder using huggingface_hub

Browse files
6.22.1/paramviewer/Example.svelte ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: string;
3
+ export let type: "gallery" | "table";
4
+ export let selected = false;
5
+ </script>
6
+
7
+ <div
8
+ class:table={type === "table"}
9
+ class:gallery={type === "gallery"}
10
+ class:selected
11
+ >
12
+ <pre>{JSON.stringify(value, null, 2)}</pre>
13
+ </div>
14
+
15
+ <style>
16
+ .gallery {
17
+ padding: var(--size-1) var(--size-2);
18
+ }
19
+ </style>
6.22.1/paramviewer/Index.svelte ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { ParamViewerProps, ParamViewerEvents } from "./types";
3
+ import { Gradio } from "@gradio/utils";
4
+ import ParamViewer from "./ParamViewer.svelte";
5
+
6
+ const props = $props();
7
+ const gradio = new Gradio<ParamViewerEvents, ParamViewerProps>(props);
8
+ </script>
9
+
10
+ <ParamViewer
11
+ docs={gradio.props.value}
12
+ linkify={gradio.props.linkify}
13
+ header={gradio.props.header}
14
+ anchor_links={gradio.props.anchor_links}
15
+ max_height={gradio.props.max_height}
16
+ />
6.22.1/paramviewer/ParamViewer.svelte ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script module lang="ts">
2
+ type PrismApi = typeof import("prismjs");
3
+
4
+ let prism: PrismApi | null = null;
5
+ let prism_languages: Promise<PrismApi> | null = null;
6
+
7
+ function load_prism_languages(): Promise<PrismApi> {
8
+ if (prism_languages) return prism_languages;
9
+
10
+ prism_languages = (async () => {
11
+ // Prism checks this pre-existing global while its module evaluates.
12
+ // Manual mode prevents its scheduled highlightAll() from rewriting
13
+ // Svelte's hydration markers before the grammars are ready.
14
+ (globalThis as any).Prism = { manual: true };
15
+ const prism_module = await import("prismjs");
16
+ const loaded_prism =
17
+ (
18
+ prism_module as unknown as {
19
+ default?: PrismApi;
20
+ }
21
+ ).default ?? (prism_module as PrismApi);
22
+ loaded_prism.manual = true;
23
+ (globalThis as any).Prism = loaded_prism;
24
+ // @ts-expect-error Prism component modules do not ship declarations.
25
+ await import("prismjs/components/prism-python");
26
+ // @ts-expect-error Prism component modules do not ship declarations.
27
+ await import("prismjs/components/prism-typescript");
28
+ prism = loaded_prism;
29
+ return loaded_prism;
30
+ })();
31
+ return prism_languages;
32
+ }
33
+ </script>
34
+
35
+ <script lang="ts">
36
+ import "./prism.css";
37
+
38
+ import { onMount, tick } from "svelte";
39
+
40
+ interface Param {
41
+ type: string | null;
42
+ description: string;
43
+ default: string | null;
44
+ name?: string;
45
+ }
46
+
47
+ let {
48
+ docs,
49
+ linkify = [],
50
+ header,
51
+ anchor_links,
52
+ max_height
53
+ }: {
54
+ docs: Record<string, Param>;
55
+ linkify: string[];
56
+ header: string | null;
57
+ anchor_links: string | boolean;
58
+ max_height: number | string | undefined;
59
+ } = $props();
60
+
61
+ let component_root: HTMLElement;
62
+ let all_open = $state(false);
63
+ let lang: "python" | "typescript" = "python";
64
+ let prism_ready = $state(prism !== null);
65
+
66
+ $effect(() => {
67
+ let active = true;
68
+ load_prism_languages()
69
+ .then(() => {
70
+ if (active) prism_ready = true;
71
+ })
72
+ .catch((e) => {
73
+ console.error("failed to load Prism grammars", e);
74
+ });
75
+ return () => {
76
+ active = false;
77
+ };
78
+ });
79
+
80
+ let _docs = $derived(highlight_code(docs, lang, prism_ready));
81
+
82
+ function create_slug(name: string, anchor_links: string | boolean): string {
83
+ let prefix = "param-";
84
+ if (typeof anchor_links === "string") {
85
+ prefix += anchor_links + "-";
86
+ }
87
+ return prefix + name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
88
+ }
89
+
90
+ function highlight(code: string, lang: "python" | "typescript"): string {
91
+ let highlighted = prism?.languages[lang]
92
+ ? prism.highlight(code, prism.languages[lang], lang)
93
+ : code;
94
+
95
+ for (const link of linkify) {
96
+ highlighted = highlighted.replace(
97
+ new RegExp(link, "g"),
98
+ `<a href="#h-${link.toLocaleLowerCase()}">${link}</a>`
99
+ );
100
+ }
101
+
102
+ return highlighted;
103
+ }
104
+
105
+ function highlight_code(
106
+ _docs: typeof docs,
107
+ lang: "python" | "typescript",
108
+ _prism_ready: boolean
109
+ ): Param[] {
110
+ if (!_docs) {
111
+ return [];
112
+ }
113
+ return Object.entries(_docs).map(
114
+ ([name, { type, description, default: _default }]) => ({
115
+ name,
116
+ type: type ? highlight(type, lang) : null,
117
+ description,
118
+ default: _default ? highlight(_default, lang) : null
119
+ })
120
+ );
121
+ }
122
+
123
+ function toggle_all(): void {
124
+ all_open = !all_open;
125
+ const details = component_root.querySelectorAll(".param");
126
+ details.forEach((detail) => {
127
+ if (detail instanceof HTMLDetailsElement) {
128
+ detail.open = all_open;
129
+ }
130
+ });
131
+ }
132
+
133
+ function render_links(description: string): string {
134
+ const escaped = description
135
+ .replace(/&/g, "&amp;")
136
+ .replace(/</g, "&lt;")
137
+ .replace(/>/g, "&gt;")
138
+ .replace(/"/g, "&quot;")
139
+ .replace(/'/g, "&#039;");
140
+
141
+ const markdown_links = escaped.replace(
142
+ /\[([^\]]+)\]\(([^)]+)\)/g,
143
+ '<a href="$2" target="_blank">$1</a>'
144
+ );
145
+ return markdown_links;
146
+ }
147
+
148
+ onMount(() => {
149
+ if (window.location.hash) {
150
+ open_parameter_from_hash(window.location.hash);
151
+ }
152
+
153
+ window.addEventListener("hashchange", (e) => {
154
+ open_parameter_from_hash(window.location.hash);
155
+ });
156
+ });
157
+
158
+ function open_parameter_from_hash(hash: string): void {
159
+ if (!component_root) return;
160
+
161
+ const id = hash.slice(1);
162
+ const detail = component_root.querySelector(`#${id}`);
163
+
164
+ if (detail instanceof HTMLDetailsElement) {
165
+ detail.open = true;
166
+ detail.scrollIntoView({ behavior: "smooth" });
167
+ }
168
+ }
169
+
170
+ const get_dimension = (
171
+ dimension_value: string | number | undefined
172
+ ): string | undefined => {
173
+ if (dimension_value === undefined) {
174
+ return undefined;
175
+ }
176
+ if (typeof dimension_value === "number") {
177
+ return dimension_value + "px";
178
+ } else if (typeof dimension_value === "string") {
179
+ return dimension_value;
180
+ }
181
+ };
182
+ </script>
183
+
184
+ <div
185
+ class="wrap"
186
+ bind:this={component_root}
187
+ style:max-height={get_dimension(max_height)}
188
+ >
189
+ <div class="header">
190
+ {#if header !== null}
191
+ <span class="title">{header}</span>
192
+ {/if}
193
+ <button
194
+ class="toggle-all"
195
+ on:click={toggle_all}
196
+ title={all_open ? "Close All" : "Open All"}
197
+ >
198
+ {all_open ? "▲" : "▼"}
199
+ </button>
200
+ </div>
201
+ {#if _docs}
202
+ <div class="param-content">
203
+ {#each _docs as { type, description, default: _default, name } (name)}
204
+ <details
205
+ class="param md"
206
+ id={anchor_links ? create_slug(name || "", anchor_links) : undefined}
207
+ >
208
+ <summary class="type">
209
+ {#if anchor_links}
210
+ <a
211
+ href="#{create_slug(name || '', anchor_links)}"
212
+ class="param-link"
213
+ >
214
+ <span class="link-icon">🔗</span>
215
+ </a>
216
+ {/if}
217
+ <pre class="language-{lang}"><code
218
+ >{name}{#if type}: {@html type}{/if}</code
219
+ ></pre>
220
+ </summary>
221
+ {#if _default}
222
+ <div class="default" class:last={!description}>
223
+ <span style:padding-right={"4px"}>default</span>
224
+ <code>= {@html _default}</code>
225
+ </div>
226
+ {/if}
227
+ {#if description}
228
+ <div class="description">
229
+ <p>{@html render_links(description)}</p>
230
+ </div>
231
+ {/if}
232
+ </details>
233
+ {/each}
234
+ </div>
235
+ {/if}
236
+ </div>
237
+
238
+ <style>
239
+ .header {
240
+ display: flex;
241
+ justify-content: space-between;
242
+ align-items: center;
243
+ padding: 0.7rem 1rem;
244
+ border-bottom: 1px solid var(--table-border-color);
245
+ }
246
+
247
+ .title {
248
+ font-size: var(--scale-0);
249
+ font-weight: 600;
250
+ color: var(--body-text-color);
251
+ }
252
+
253
+ .toggle-all {
254
+ background: none;
255
+ border: none;
256
+ cursor: pointer;
257
+ padding: 0;
258
+ color: var(--body-text-color);
259
+ font-size: 0.7em;
260
+ line-height: 1;
261
+ opacity: 0.7;
262
+ transition:
263
+ opacity 0.2s ease,
264
+ transform 0.3s ease;
265
+ }
266
+
267
+ .toggle-all:hover {
268
+ opacity: 1;
269
+ }
270
+
271
+ :global(.wrap[data-all-open="true"]) .toggle-all {
272
+ transform: rotate(180deg);
273
+ }
274
+
275
+ .default :global(pre),
276
+ .default :global(.highlight) {
277
+ display: inline-block;
278
+ }
279
+
280
+ .wrap :global(pre),
281
+ .wrap :global(.highlight) {
282
+ margin: 0 !important;
283
+ background: transparent !important;
284
+ font-family: var(--font-mono);
285
+ font-weight: 400;
286
+ padding: 0 !important;
287
+ }
288
+
289
+ .wrap :global(pre a) {
290
+ color: var(--link-text-color-hover);
291
+ text-decoration: underline;
292
+ }
293
+
294
+ .wrap :global(pre a:hover) {
295
+ color: var(--link-text-color-hover);
296
+ }
297
+
298
+ .default > span {
299
+ text-transform: uppercase;
300
+ font-size: 0.7rem;
301
+ font-weight: 600;
302
+ }
303
+
304
+ .default > code {
305
+ border: none;
306
+ }
307
+ code {
308
+ background: none;
309
+ font-family: var(--font-mono);
310
+ }
311
+
312
+ .wrap {
313
+ padding: 0rem;
314
+ border-radius: 5px;
315
+ overflow: hidden;
316
+ position: relative;
317
+ margin: 0;
318
+ box-shadow: var(--block-shadow);
319
+ border-width: var(--block-border-width);
320
+ border-color: var(--block-border-color);
321
+ border-radius: var(--block-radius);
322
+ width: 100%;
323
+ line-height: var(--line-sm);
324
+ color: var(--body-text-color);
325
+ display: grid;
326
+ grid-template-rows: auto 1fr;
327
+ }
328
+
329
+ .type {
330
+ position: relative;
331
+ padding: 0.7rem 1rem;
332
+ padding-left: 2rem;
333
+ background: var(--table-odd-background-fill);
334
+ border-bottom: 0px solid var(--table-border-color);
335
+ list-style: none;
336
+ }
337
+
338
+ .type::after {
339
+ content: "▼";
340
+ position: absolute;
341
+ top: 50%;
342
+ right: 15px;
343
+ transform: translateY(-50%);
344
+ transition: transform 0.3s ease;
345
+ font-size: 0.7em;
346
+ opacity: 0.7;
347
+ }
348
+
349
+ details[open] .type::after {
350
+ transform: translateY(-50%) rotate(180deg);
351
+ }
352
+
353
+ .default {
354
+ padding: 0.2rem 1rem 0.3rem 1rem;
355
+ border-bottom: 1px solid var(--table-border-color);
356
+ background: var(--block-background-fill);
357
+ }
358
+
359
+ .default.last {
360
+ border-bottom: none;
361
+ }
362
+
363
+ .description {
364
+ padding: 0.7rem 1rem;
365
+ font-size: var(--scale-00);
366
+ font-family: var(--font-sans);
367
+ background: var(--block-background-fill);
368
+ }
369
+
370
+ .param {
371
+ border-bottom: 1px solid var(--table-border-color);
372
+ }
373
+
374
+ .param:last-child {
375
+ border-bottom: none;
376
+ }
377
+
378
+ details[open] .type {
379
+ border-bottom-width: 1px;
380
+ }
381
+
382
+ .param.md code {
383
+ background: none;
384
+ }
385
+
386
+ details > summary {
387
+ cursor: pointer;
388
+ }
389
+
390
+ details > summary::-webkit-details-marker {
391
+ display: none;
392
+ }
393
+
394
+ .param-link {
395
+ opacity: 0;
396
+ position: absolute;
397
+ left: 8px;
398
+ top: 50%;
399
+ transform: translateY(-50%);
400
+ transition: opacity 0.2s;
401
+ color: var(--body-text-color);
402
+ text-decoration: none;
403
+ }
404
+
405
+ .link-icon {
406
+ font-size: 14px;
407
+ }
408
+
409
+ .type:hover .param-link {
410
+ opacity: 0.7;
411
+ }
412
+
413
+ .param-link:hover {
414
+ opacity: 1 !important;
415
+ }
416
+
417
+ .param-content {
418
+ overflow-y: auto;
419
+ }
420
+ </style>
6.22.1/paramviewer/package.json ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/paramviewer",
3
+ "version": "0.12.0",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "main": "./Index.svelte",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/Index.svelte.d.ts",
14
+ "gradio": "./Index.svelte",
15
+ "svelte": "./dist/Index.svelte",
16
+ "default": "./dist/Index.svelte"
17
+ },
18
+ "./ParamViewer": {
19
+ "types": "./dist/ParamViewer.svelte.d.ts",
20
+ "gradio": "./ParamViewer.svelte",
21
+ "svelte": "./dist/ParamViewer.svelte",
22
+ "default": "./dist/ParamViewer.svelte"
23
+ },
24
+ "./example": {
25
+ "types": "./dist/Example.svelte.d.ts",
26
+ "gradio": "./Example.svelte",
27
+ "svelte": "./dist/Example.svelte",
28
+ "default": "./dist/Example.svelte"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "dependencies": {
33
+ "@gradio/atoms": "workspace:^",
34
+ "@gradio/statustracker": "workspace:^",
35
+ "@gradio/utils": "workspace:^",
36
+ "prismjs": "^1.30.0"
37
+ },
38
+ "devDependencies": {
39
+ "@gradio/preview": "workspace:^",
40
+ "@types/prismjs": "^1.26.5"
41
+ },
42
+ "peerDependencies": {
43
+ "svelte": "^5.48.0"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/gradio-app/gradio.git",
48
+ "directory": "js/paramviewer"
49
+ }
50
+ }
6.22.1/paramviewer/types.ts ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export interface ParamViewerProps {
2
+ value: Record<
3
+ string,
4
+ {
5
+ type: string;
6
+ description: string;
7
+ default: string;
8
+ }
9
+ >;
10
+ linkify: string[];
11
+ header: string | null;
12
+ anchor_links: boolean | string;
13
+ max_height: number | string | undefined;
14
+ }
15
+
16
+ export interface ParamViewerEvents {
17
+ change: never;
18
+ upload: never;
19
+ clear_status: never;
20
+ }