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

Upload folder using huggingface_hub

Browse files
5.49.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>
5.49.1/paramviewer/Index.svelte ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import ParamViewer from "./ParamViewer.svelte";
3
+
4
+ export let value: Record<
5
+ string,
6
+ {
7
+ type: string;
8
+ description: string;
9
+ default: string;
10
+ }
11
+ >;
12
+
13
+ export let linkify: string[] = [];
14
+ export let header: string | null = null;
15
+ export let anchor_links = false;
16
+ export let max_height: number | string | undefined = undefined;
17
+ </script>
18
+
19
+ <ParamViewer docs={value} {linkify} {header} {anchor_links} {max_height} />
5.49.1/paramviewer/ParamViewer.svelte ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ border: 1px solid #eee;
265
+ overflow: hidden;
266
+ position: relative;
267
+ margin: 0;
268
+ box-shadow: var(--block-shadow);
269
+ border-width: var(--block-border-width);
270
+ border-color: var(--block-border-color);
271
+ border-radius: var(--block-radius);
272
+ width: 100%;
273
+ line-height: var(--line-sm);
274
+ color: var(--body-text-color);
275
+ display: grid;
276
+ grid-template-rows: auto 1fr;
277
+ }
278
+
279
+ .type {
280
+ position: relative;
281
+ padding: 0.7rem 1rem;
282
+ padding-left: 2rem;
283
+ background: var(--table-odd-background-fill);
284
+ border-bottom: 0px solid var(--table-border-color);
285
+ list-style: none;
286
+ }
287
+
288
+ .type::after {
289
+ content: "▼";
290
+ position: absolute;
291
+ top: 50%;
292
+ right: 15px;
293
+ transform: translateY(-50%);
294
+ transition: transform 0.3s ease;
295
+ font-size: 0.7em;
296
+ opacity: 0.7;
297
+ }
298
+
299
+ details[open] .type::after {
300
+ transform: translateY(-50%) rotate(180deg);
301
+ }
302
+
303
+ .default {
304
+ padding: 0.2rem 1rem 0.3rem 1rem;
305
+ border-bottom: 1px solid var(--table-border-color);
306
+ background: var(--block-background-fill);
307
+ }
308
+
309
+ .default.last {
310
+ border-bottom: none;
311
+ }
312
+
313
+ .description {
314
+ padding: 0.7rem 1rem;
315
+ font-size: var(--scale-00);
316
+ font-family: var(--font-sans);
317
+ background: var(--block-background-fill);
318
+ }
319
+
320
+ .param {
321
+ border-bottom: 1px solid var(--table-border-color);
322
+ }
323
+
324
+ .param:last-child {
325
+ border-bottom: none;
326
+ }
327
+
328
+ details[open] .type {
329
+ border-bottom-width: 1px;
330
+ }
331
+
332
+ .param.md code {
333
+ background: none;
334
+ }
335
+
336
+ details > summary {
337
+ cursor: pointer;
338
+ }
339
+
340
+ details > summary::-webkit-details-marker {
341
+ display: none;
342
+ }
343
+
344
+ .param-link {
345
+ opacity: 0;
346
+ position: absolute;
347
+ left: 8px;
348
+ top: 50%;
349
+ transform: translateY(-50%);
350
+ transition: opacity 0.2s;
351
+ color: var(--body-text-color);
352
+ text-decoration: none;
353
+ }
354
+
355
+ .link-icon {
356
+ font-size: 14px;
357
+ }
358
+
359
+ .type:hover .param-link {
360
+ opacity: 0.7;
361
+ }
362
+
363
+ .param-link:hover {
364
+ opacity: 1 !important;
365
+ }
366
+
367
+ .param-content {
368
+ overflow-y: auto;
369
+ }
370
+ </style>
5.49.1/paramviewer/package.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/paramviewer",
3
+ "version": "0.8.1",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "exports": {
11
+ ".": {
12
+ "gradio": "./Index.svelte",
13
+ "svelte": "./dist/Index.svelte",
14
+ "types": "./dist/Index.svelte.d.ts"
15
+ },
16
+ "./example": {
17
+ "gradio": "./Example.svelte",
18
+ "svelte": "./dist/Example.svelte",
19
+ "types": "./dist/Example.svelte.d.ts"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "dependencies": {
24
+ "@gradio/atoms": "workspace:^",
25
+ "@gradio/statustracker": "workspace:^",
26
+ "@gradio/utils": "workspace:^",
27
+ "prismjs": "^1.30.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/prismjs": "^1.26.3",
31
+ "@gradio/preview": "workspace:^"
32
+ },
33
+ "peerDependencies": {
34
+ "svelte": "^4.0.0"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/gradio-app/gradio.git",
39
+ "directory": "js/paramviewer"
40
+ }
41
+ }