gradio-pr-bot commited on
Commit
8c79257
·
verified ·
1 Parent(s): fb06d00

Upload folder using huggingface_hub

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