From 0044c243db5c8059b8ae7d5379d52bdeb982a734 Mon Sep 17 00:00:00 2001 From: pngwn Date: Wed, 2 Mar 2022 16:42:43 +0000 Subject: [PATCH] pull all components into packages --- .../src/components/input/Audio/Audio.svelte | 2 +- ui/packages/audio/src/Audio.svelte | 1 - ui/packages/button/package.json | 5 +- ui/packages/carousel/README.md | 17 + ui/packages/carousel/package.json | 10 + ui/packages/carousel/src/Carousel.svelte | 78 ++++ ui/packages/carousel/src/CarouselItem.svelte | 22 + ui/packages/carousel/src/index.ts | 2 + ui/packages/chart/README.md | 1 + ui/packages/chart/package.json | 16 + ui/packages/chart/src/Chart.svelte | 162 +++++++ ui/packages/chart/src/index.ts | 1 + ui/packages/chart/src/utils.ts | 92 ++++ ui/packages/chatbot/README.md | 11 + ui/packages/chatbot/package.json | 10 + ui/packages/chatbot/src/ChatBot.svelte | 33 ++ ui/packages/chatbot/src/index.ts | 1 + ui/packages/file/README.md | 11 + ui/packages/file/package.json | 13 + ui/packages/file/src/File.svelte | 61 +++ ui/packages/file/src/index.ts | 1 + ui/packages/file/src/utils.ts | 10 + ui/packages/form/README.md | 11 + ui/packages/{components => form}/package.json | 2 +- ui/packages/form/src/Checkbox.svelte | 62 +++ ui/packages/form/src/CheckboxGroup.svelte | 73 ++++ ui/packages/form/src/Dropdown.svelte | 55 +++ ui/packages/form/src/Number.svelte | 38 ++ ui/packages/form/src/Radio.svelte | 47 ++ ui/packages/form/src/Textbox.svelte | 50 +++ ui/packages/form/src/index.ts | 6 + ui/packages/form/src/utils.ts | 9 + ui/packages/highlighted-text/README.md | 11 + ui/packages/highlighted-text/package.json | 10 + .../src/HighlightedText.svelte | 130 ++++++ ui/packages/highlighted-text/src/index.ts | 1 + ui/packages/highlighted-text/src/utils.ts | 36 ++ ui/packages/html/README.md | 11 + ui/packages/html/package.json | 10 + ui/packages/html/src/HTML.svelte | 8 + ui/packages/html/src/index.ts | 1 + ui/packages/image/README.md | 11 + ui/packages/image/package.json | 17 + ui/packages/image/src/Cropper.svelte | 27 ++ ui/packages/image/src/Image.svelte | 103 +++++ ui/packages/image/src/ImageEditor.svelte | 46 ++ ui/packages/image/src/ModifySketch.svelte | 23 + ui/packages/image/src/Sketch.svelte | 365 ++++++++++++++++ ui/packages/image/src/Webcam.svelte | 74 ++++ ui/packages/image/src/camera.svg | 1 + ui/packages/image/src/clear.svg | 67 +++ ui/packages/image/src/index.ts | 1 + ui/packages/image/src/undo-solid.svg | 1 + ui/packages/json/README.md | 11 + ui/packages/json/package.json | 10 + ui/packages/json/src/JSON.svelte | 16 + ui/packages/json/src/JSONNode.svelte | 84 ++++ ui/packages/json/src/index.ts | 1 + ui/packages/label/README.md | 11 + ui/packages/label/package.json | 10 + ui/packages/label/src/Label.svelte | 55 +++ ui/packages/label/src/index.ts | 1 + ui/packages/table/README.md | 1 + ui/packages/table/package.json | 10 + ui/packages/table/src/Table.svelte | 400 ++++++++++++++++++ ui/packages/table/src/index.ts | 1 + ui/packages/theme/package.json | 5 +- ui/packages/tooltip/README.md | 11 + ui/packages/tooltip/package.json | 10 + ui/packages/tooltip/src/Tooltip.svelte | 20 + ui/packages/tooltip/src/index.ts | 1 + ui/packages/tooltip/src/tooltip.ts | 49 +++ ui/packages/upload/src/ModifyUpload.svelte | 4 +- ui/packages/upload/src/Upload.svelte | 12 +- ui/packages/upload/src/index.ts | 1 + ui/packages/upload/src/types.ts | 6 + ui/packages/video/README.md | 11 + ui/packages/video/package.json | 13 + ui/packages/video/src/Video.svelte | 62 +++ ui/packages/video/src/index.ts | 1 + ui/packages/video/src/utils.ts | 17 + ui/packages/workbench/package.json | 15 +- ui/packages/workbench/src/assets/cheetah1.jpg | Bin 0 -> 20552 bytes ui/packages/workbench/src/assets/time.csv | 8 + ui/packages/workbench/src/routes/_Nav.svelte | 6 +- ui/packages/workbench/src/routes/audio.svelte | 1 - .../workbench/src/routes/carousel.svelte | 13 + ui/packages/workbench/src/routes/chart.svelte | 14 + .../workbench/src/routes/chatbot.svelte | 14 + ui/packages/workbench/src/routes/file.svelte | 5 + ui/packages/workbench/src/routes/forms.svelte | 31 ++ .../src/routes/highlightedtext.svelte | 51 +++ ui/packages/workbench/src/routes/html.svelte | 7 + ui/packages/workbench/src/routes/image.svelte | 20 + ui/packages/workbench/src/routes/json.svelte | 34 ++ ui/packages/workbench/src/routes/label.svelte | 20 + ui/packages/workbench/src/routes/table.svelte | 5 + .../workbench/src/routes/upload.svelte | 7 + ui/packages/workbench/src/routes/video.svelte | 5 + ui/pnpm-lock.yaml | 133 +++++- 100 files changed, 3048 insertions(+), 42 deletions(-) create mode 100644 ui/packages/carousel/README.md create mode 100644 ui/packages/carousel/package.json create mode 100644 ui/packages/carousel/src/Carousel.svelte create mode 100644 ui/packages/carousel/src/CarouselItem.svelte create mode 100644 ui/packages/carousel/src/index.ts create mode 100644 ui/packages/chart/README.md create mode 100644 ui/packages/chart/package.json create mode 100644 ui/packages/chart/src/Chart.svelte create mode 100644 ui/packages/chart/src/index.ts create mode 100644 ui/packages/chart/src/utils.ts create mode 100644 ui/packages/chatbot/README.md create mode 100644 ui/packages/chatbot/package.json create mode 100644 ui/packages/chatbot/src/ChatBot.svelte create mode 100644 ui/packages/chatbot/src/index.ts create mode 100644 ui/packages/file/README.md create mode 100644 ui/packages/file/package.json create mode 100644 ui/packages/file/src/File.svelte create mode 100644 ui/packages/file/src/index.ts create mode 100644 ui/packages/file/src/utils.ts create mode 100644 ui/packages/form/README.md rename ui/packages/{components => form}/package.json (86%) create mode 100644 ui/packages/form/src/Checkbox.svelte create mode 100644 ui/packages/form/src/CheckboxGroup.svelte create mode 100644 ui/packages/form/src/Dropdown.svelte create mode 100644 ui/packages/form/src/Number.svelte create mode 100644 ui/packages/form/src/Radio.svelte create mode 100644 ui/packages/form/src/Textbox.svelte create mode 100644 ui/packages/form/src/index.ts create mode 100644 ui/packages/form/src/utils.ts create mode 100644 ui/packages/highlighted-text/README.md create mode 100644 ui/packages/highlighted-text/package.json create mode 100644 ui/packages/highlighted-text/src/HighlightedText.svelte create mode 100644 ui/packages/highlighted-text/src/index.ts create mode 100644 ui/packages/highlighted-text/src/utils.ts create mode 100644 ui/packages/html/README.md create mode 100644 ui/packages/html/package.json create mode 100644 ui/packages/html/src/HTML.svelte create mode 100644 ui/packages/html/src/index.ts create mode 100644 ui/packages/image/README.md create mode 100644 ui/packages/image/package.json create mode 100644 ui/packages/image/src/Cropper.svelte create mode 100644 ui/packages/image/src/Image.svelte create mode 100644 ui/packages/image/src/ImageEditor.svelte create mode 100644 ui/packages/image/src/ModifySketch.svelte create mode 100644 ui/packages/image/src/Sketch.svelte create mode 100644 ui/packages/image/src/Webcam.svelte create mode 100644 ui/packages/image/src/camera.svg create mode 100644 ui/packages/image/src/clear.svg create mode 100644 ui/packages/image/src/index.ts create mode 100644 ui/packages/image/src/undo-solid.svg create mode 100644 ui/packages/json/README.md create mode 100644 ui/packages/json/package.json create mode 100644 ui/packages/json/src/JSON.svelte create mode 100644 ui/packages/json/src/JSONNode.svelte create mode 100644 ui/packages/json/src/index.ts create mode 100644 ui/packages/label/README.md create mode 100644 ui/packages/label/package.json create mode 100644 ui/packages/label/src/Label.svelte create mode 100644 ui/packages/label/src/index.ts create mode 100644 ui/packages/table/README.md create mode 100644 ui/packages/table/package.json create mode 100644 ui/packages/table/src/Table.svelte create mode 100644 ui/packages/table/src/index.ts create mode 100644 ui/packages/tooltip/README.md create mode 100644 ui/packages/tooltip/package.json create mode 100644 ui/packages/tooltip/src/Tooltip.svelte create mode 100644 ui/packages/tooltip/src/index.ts create mode 100644 ui/packages/tooltip/src/tooltip.ts create mode 100644 ui/packages/upload/src/types.ts create mode 100644 ui/packages/video/README.md create mode 100644 ui/packages/video/package.json create mode 100644 ui/packages/video/src/Video.svelte create mode 100644 ui/packages/video/src/index.ts create mode 100644 ui/packages/video/src/utils.ts create mode 100644 ui/packages/workbench/src/assets/cheetah1.jpg create mode 100644 ui/packages/workbench/src/assets/time.csv create mode 100644 ui/packages/workbench/src/routes/carousel.svelte create mode 100644 ui/packages/workbench/src/routes/chart.svelte create mode 100644 ui/packages/workbench/src/routes/chatbot.svelte create mode 100644 ui/packages/workbench/src/routes/file.svelte create mode 100644 ui/packages/workbench/src/routes/forms.svelte create mode 100644 ui/packages/workbench/src/routes/highlightedtext.svelte create mode 100644 ui/packages/workbench/src/routes/html.svelte create mode 100644 ui/packages/workbench/src/routes/image.svelte create mode 100644 ui/packages/workbench/src/routes/json.svelte create mode 100644 ui/packages/workbench/src/routes/label.svelte create mode 100644 ui/packages/workbench/src/routes/table.svelte create mode 100644 ui/packages/workbench/src/routes/upload.svelte create mode 100644 ui/packages/workbench/src/routes/video.svelte diff --git a/ui/packages/app/src/components/input/Audio/Audio.svelte b/ui/packages/app/src/components/input/Audio/Audio.svelte index fb483a8774..7c8c61af00 100644 --- a/ui/packages/app/src/components/input/Audio/Audio.svelte +++ b/ui/packages/app/src/components/input/Audio/Audio.svelte @@ -128,7 +128,7 @@ {:else} + + + + + + diff --git a/ui/packages/carousel/src/CarouselItem.svelte b/ui/packages/carousel/src/CarouselItem.svelte new file mode 100644 index 0000000000..50a90df43f --- /dev/null +++ b/ui/packages/carousel/src/CarouselItem.svelte @@ -0,0 +1,22 @@ + + +{#if $current === id} +
+ {#if label} +
{label}
+ {/if} + +
+{/if} diff --git a/ui/packages/carousel/src/index.ts b/ui/packages/carousel/src/index.ts new file mode 100644 index 0000000000..e2024e29fe --- /dev/null +++ b/ui/packages/carousel/src/index.ts @@ -0,0 +1,2 @@ +export { default as Carousel } from "./Carousel.svelte"; +export { default as CarouselItem } from "./CarouselItem.svelte"; diff --git a/ui/packages/chart/README.md b/ui/packages/chart/README.md new file mode 100644 index 0000000000..7bae7bb394 --- /dev/null +++ b/ui/packages/chart/README.md @@ -0,0 +1 @@ +# `@gradio/chart` diff --git a/ui/packages/chart/package.json b/ui/packages/chart/package.json new file mode 100644 index 0000000000..aa7c712dcd --- /dev/null +++ b/ui/packages/chart/package.json @@ -0,0 +1,16 @@ +{ + "name": "@gradio/chart", + "version": "0.0.1", + "description": "Gradio UI packages", + "type": "module", + "main": "src/index.ts", + "author": "", + "license": "ISC", + "private": true, + "dependencies": { + "@gradio/tooltip": "workspace:^0.0.1", + "d3-dsv": "^3.0.1", + "d3-scale": "^4.0.2", + "d3-shape": "^3.1.0" + } +} diff --git a/ui/packages/chart/src/Chart.svelte b/ui/packages/chart/src/Chart.svelte new file mode 100644 index 0000000000..28996a4d5a --- /dev/null +++ b/ui/packages/chart/src/Chart.svelte @@ -0,0 +1,162 @@ + + +
+
+ {#each _y as { name }} +
+ + {name} +
+ {/each} +
+ + + {#each x_ticks as tick} + y_ticks[y_ticks.length - 1] + ? y_domain[1] + : y_ticks[y_ticks.length - 1] + )} + stroke="#aaa" + /> + + {tick} + + {/each} + + {#each y_ticks as tick} + x_ticks[x_ticks.length - 1] + ? x_domain[1] + : x_ticks[x_ticks.length - 1] + )} + stroke="#aaa" + /> + + + {tick} + + {/each} + + {#if y_domain[1] > y_ticks[y_ticks.length - 1]} + + + {y_domain[1]} + + {/if} + + + {#each _y as { name, values }} + {@const color = colors[name]} + {#each values as { x, y }} + + {/each} + [scale_x(x), scale_y(y)]) + )} + fill="none" + stroke={color} + stroke-width="3" + /> + {/each} + + {#each _y as { name, values }} + {@const color = colors[name]} + {#each values as { x, y }} + + {/each} + {/each} + + +
+ {_x.name} +
+
diff --git a/ui/packages/chart/src/index.ts b/ui/packages/chart/src/index.ts new file mode 100644 index 0000000000..0659e3e8d4 --- /dev/null +++ b/ui/packages/chart/src/index.ts @@ -0,0 +1 @@ +export { default as Chart } from "./Chart.svelte"; diff --git a/ui/packages/chart/src/utils.ts b/ui/packages/chart/src/utils.ts new file mode 100644 index 0000000000..32bcd4e76a --- /dev/null +++ b/ui/packages/chart/src/utils.ts @@ -0,0 +1,92 @@ +interface XYValue { + x: number; + y: number; +} + +interface ObjectValue { + values: XYValue[]; +} + +export function get_domains( + values: ObjectValue[] | { values: number[] } +): [number, number] { + let _vs: number[]; + if (Array.isArray(values)) { + _vs = values.reduce((acc, { values }) => { + return [...acc, ...values.map(({ x, y }) => y)]; + }, []); + } else { + _vs = values.values; + } + return [Math.min(..._vs), Math.max(..._vs)]; +} + +interface Row { + name: string; + values: number[]; +} + +interface RowPoint { + name: string; + values: Array<{ x: number; y: number }>; +} + +interface TransformedValues { + x: Row; + y: Array; +} + +export function transform_values( + values: Array>, + x?: string, + y?: string[] +) { + const transformed_values = Object.entries( + values[0] + ).reduce( + (acc, next, i) => { + if ((!x && i === 0) || (x && next[0] === x)) { + acc.x.name = next[0]; + } else if (!y || (y && y.includes(next[0]))) { + acc.y.push({ name: next[0], values: [] }); + } + return acc; + }, + { x: { name: "", values: [] }, y: [] } + ); + + for (let i = 0; i < values.length; i++) { + const _a = Object.entries(values[i]); + for (let j = 0; j < _a.length; j++) { + let [name, x] = _a[j]; + if (name === transformed_values.x.name) { + transformed_values.x.values.push(parseInt(x, 10)); + } else { + transformed_values.y[j - 1].values.push({ + y: parseInt(_a[j][1], 10), + x: parseInt(_a[0][1], 10) + }); + } + } + } + + return transformed_values; +} + +let c = 0; +export function get_color(): string { + let default_colors = [ + [255, 99, 132], + [54, 162, 235], + [240, 176, 26], + [153, 102, 255], + [75, 192, 192], + [255, 159, 64] + ]; + + if (c >= default_colors.length) c = 0; + + const [r, g, b] = default_colors[c++]; + + return `rgb(${r},${g},${b})`; +} diff --git a/ui/packages/chatbot/README.md b/ui/packages/chatbot/README.md new file mode 100644 index 0000000000..e5b427fdb3 --- /dev/null +++ b/ui/packages/chatbot/README.md @@ -0,0 +1,11 @@ +# `@gradio/button` + +```html + + + +``` diff --git a/ui/packages/chatbot/package.json b/ui/packages/chatbot/package.json new file mode 100644 index 0000000000..34179cf419 --- /dev/null +++ b/ui/packages/chatbot/package.json @@ -0,0 +1,10 @@ +{ + "name": "@gradio/chatbot", + "version": "0.0.1", + "description": "Gradio UI packages", + "type": "module", + "main": "src/index.ts", + "author": "", + "license": "ISC", + "private": true +} diff --git a/ui/packages/chatbot/src/ChatBot.svelte b/ui/packages/chatbot/src/ChatBot.svelte new file mode 100644 index 0000000000..9bd80835f7 --- /dev/null +++ b/ui/packages/chatbot/src/ChatBot.svelte @@ -0,0 +1,33 @@ + + +
+
+ {#each value as message} +
+ {message[0]} +
+
+ {message[1]} +
+ {/each} +
+
diff --git a/ui/packages/chatbot/src/index.ts b/ui/packages/chatbot/src/index.ts new file mode 100644 index 0000000000..e010050bf8 --- /dev/null +++ b/ui/packages/chatbot/src/index.ts @@ -0,0 +1 @@ +export { default as ChatBot } from "./ChatBot.svelte"; diff --git a/ui/packages/file/README.md b/ui/packages/file/README.md new file mode 100644 index 0000000000..e5b427fdb3 --- /dev/null +++ b/ui/packages/file/README.md @@ -0,0 +1,11 @@ +# `@gradio/button` + +```html + + + +``` diff --git a/ui/packages/file/package.json b/ui/packages/file/package.json new file mode 100644 index 0000000000..a178b92870 --- /dev/null +++ b/ui/packages/file/package.json @@ -0,0 +1,13 @@ +{ + "name": "@gradio/file", + "version": "0.0.1", + "description": "Gradio UI packages", + "type": "module", + "main": "src/index.ts", + "author": "", + "license": "ISC", + "private": true, + "dependencies": { + "@gradio/upload": "workspace:^0.0.1" + } +} diff --git a/ui/packages/file/src/File.svelte b/ui/packages/file/src/File.svelte new file mode 100644 index 0000000000..9634a202d1 --- /dev/null +++ b/ui/packages/file/src/File.svelte @@ -0,0 +1,61 @@ + + +
+ {#if value === null} + + {drop_text} +
- {or_text} -
+ {upload_text} +
+ {:else} +
+ + + + + +
{value.name}
+
+ {prettyBytes(value.size)} +
+
+ {/if} +
+ + diff --git a/ui/packages/file/src/index.ts b/ui/packages/file/src/index.ts new file mode 100644 index 0000000000..837b16f85d --- /dev/null +++ b/ui/packages/file/src/index.ts @@ -0,0 +1 @@ +export { default as File } from "./File.svelte"; diff --git a/ui/packages/file/src/utils.ts b/ui/packages/file/src/utils.ts new file mode 100644 index 0000000000..8a7dd00218 --- /dev/null +++ b/ui/packages/file/src/utils.ts @@ -0,0 +1,10 @@ +export const prettyBytes = (bytes: number): string => { + let units = ["B", "KB", "MB", "GB", "PB"]; + let i = 0; + while (bytes > 1024) { + bytes /= 1024; + i++; + } + let unit = units[i]; + return bytes.toFixed(1) + " " + unit; +}; diff --git a/ui/packages/form/README.md b/ui/packages/form/README.md new file mode 100644 index 0000000000..e5b427fdb3 --- /dev/null +++ b/ui/packages/form/README.md @@ -0,0 +1,11 @@ +# `@gradio/button` + +```html + + + +``` diff --git a/ui/packages/components/package.json b/ui/packages/form/package.json similarity index 86% rename from ui/packages/components/package.json rename to ui/packages/form/package.json index eb6bcb3311..fab79daf59 100644 --- a/ui/packages/components/package.json +++ b/ui/packages/form/package.json @@ -1,5 +1,5 @@ { - "name": "~name~", + "name": "@gradio/form", "version": "0.0.1", "description": "Gradio UI packages", "type": "module", diff --git a/ui/packages/form/src/Checkbox.svelte b/ui/packages/form/src/Checkbox.svelte new file mode 100644 index 0000000000..bc44859e2c --- /dev/null +++ b/ui/packages/form/src/Checkbox.svelte @@ -0,0 +1,62 @@ + + +
+ +
+ + diff --git a/ui/packages/form/src/CheckboxGroup.svelte b/ui/packages/form/src/CheckboxGroup.svelte new file mode 100644 index 0000000000..439eb803d4 --- /dev/null +++ b/ui/packages/form/src/CheckboxGroup.svelte @@ -0,0 +1,73 @@ + + +
+ {#each choices as choice, i} + + {/each} +
+ + diff --git a/ui/packages/form/src/Dropdown.svelte b/ui/packages/form/src/Dropdown.svelte new file mode 100644 index 0000000000..26fd994c84 --- /dev/null +++ b/ui/packages/form/src/Dropdown.svelte @@ -0,0 +1,55 @@ + + +
+ + +
+ + diff --git a/ui/packages/form/src/Number.svelte b/ui/packages/form/src/Number.svelte new file mode 100644 index 0000000000..57d265d975 --- /dev/null +++ b/ui/packages/form/src/Number.svelte @@ -0,0 +1,38 @@ + + + + + diff --git a/ui/packages/form/src/Radio.svelte b/ui/packages/form/src/Radio.svelte new file mode 100644 index 0000000000..878d2d5ef6 --- /dev/null +++ b/ui/packages/form/src/Radio.svelte @@ -0,0 +1,47 @@ + + +
+ {#each choices as choice} + + {/each} +
+ + diff --git a/ui/packages/form/src/Textbox.svelte b/ui/packages/form/src/Textbox.svelte new file mode 100644 index 0000000000..7c0b21b0c8 --- /dev/null +++ b/ui/packages/form/src/Textbox.svelte @@ -0,0 +1,50 @@ + + +{#if lines > 1} +