freddyaboulton HF Staff commited on
Commit
cc8154f
·
verified ·
1 Parent(s): dfae5af

Upload folder using huggingface_hub

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