Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/build/package.json +27 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/build/src/index.ts +400 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/ButtonPanel.svelte +119 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/Component.svelte +86 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/Copy.svelte +52 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/Remove.svelte +11 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/ThumbDownDefault.svelte +12 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/ThumbUpActive.svelte +12 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/column/Index.svelte +75 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/file/Example.svelte +30 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/file/Index.svelte +126 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/file/shared/File.svelte +27 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/file/shared/FilePreview.svelte +201 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/fileexplorer/icons/light-file.svg +1 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/fileexplorer/icons/light-folder.svg +124 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/fileexplorer/package.json +44 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/image/shared/Image.svelte +44 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/Example.svelte +44 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/Index.svelte +226 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/package.json +48 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/Controls.svelte +78 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/ImageEditor.svelte +429 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/InteractiveImageEditor.svelte +331 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/layers/Layers.svelte +235 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/layers/utils.ts +263 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/Brush.svelte +278 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/BrushOptions.svelte +180 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/BrushSize.svelte +68 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/ColorField.svelte +172 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/ColorPicker.svelte +205 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/ColorSwatch.svelte +203 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/Crop.svelte +189 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/Handle.svelte +289 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/IconButton.svelte +133 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/Sources.svelte +276 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/Tools.svelte +162 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/brush.ts +247 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/crop.ts +215 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/index.ts +5 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/sources.ts +114 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/types.ts +1 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/utils/commands.ts +162 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/utils/events.ts +30 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/utils/parse_placeholder.ts +27 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/utils/pixi.ts +298 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/label/shared/Label.svelte +158 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/model3D/Example.svelte +19 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/model3D/shared/Canvas3DGS.svelte +130 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/model3D/shared/Model3D.svelte +136 -0
- evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/model3D/shared/Model3DUpload.svelte +154 -0
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/build/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@self/build",
|
| 3 |
+
"version": "0.1.0",
|
| 4 |
+
"description": "Gradio UI packages",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"main": "out/index.js",
|
| 7 |
+
"private": "true",
|
| 8 |
+
"author": "",
|
| 9 |
+
"license": "ISC",
|
| 10 |
+
"scripts": {
|
| 11 |
+
"build": "esbuild src/index.ts --platform=node --format=esm --target=node18 --bundle --packages=external --outfile=out/index.js && cp src/component_loader.js out/"
|
| 12 |
+
},
|
| 13 |
+
"dependencies": {
|
| 14 |
+
"@gradio/theme": "workspace:^",
|
| 15 |
+
"esbuild": "^0.21.0",
|
| 16 |
+
"svelte-i18n": "^3.6.0"
|
| 17 |
+
},
|
| 18 |
+
"peerDependencies": {
|
| 19 |
+
"svelte": "^4.0.0"
|
| 20 |
+
},
|
| 21 |
+
"main_changeset": true,
|
| 22 |
+
"repository": {
|
| 23 |
+
"type": "git",
|
| 24 |
+
"url": "git+https://github.com/gradio-app/gradio.git",
|
| 25 |
+
"directory": "js/build"
|
| 26 |
+
}
|
| 27 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/build/src/index.ts
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Plugin } from "vite";
|
| 2 |
+
import { parse, HTMLElement } from "node-html-parser";
|
| 3 |
+
|
| 4 |
+
import { join } from "path";
|
| 5 |
+
import { writeFileSync } from "fs";
|
| 6 |
+
|
| 7 |
+
export function inject_ejs(): Plugin {
|
| 8 |
+
return {
|
| 9 |
+
name: "inject-ejs",
|
| 10 |
+
enforce: "post",
|
| 11 |
+
transformIndexHtml: (html) => {
|
| 12 |
+
const replace_gradio_info_info_html = html.replace(
|
| 13 |
+
/%gradio_api_info%/,
|
| 14 |
+
`<script>window.gradio_api_info = {{ gradio_api_info | toorjson }};</script>`
|
| 15 |
+
);
|
| 16 |
+
return replace_gradio_info_info_html.replace(
|
| 17 |
+
/%gradio_config%/,
|
| 18 |
+
`<script>window.gradio_config = {{ config | toorjson }};</script>`
|
| 19 |
+
);
|
| 20 |
+
}
|
| 21 |
+
};
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
export function generate_cdn_entry({
|
| 25 |
+
version,
|
| 26 |
+
cdn_base
|
| 27 |
+
}: {
|
| 28 |
+
version: string;
|
| 29 |
+
cdn_base: string;
|
| 30 |
+
}): Plugin {
|
| 31 |
+
return {
|
| 32 |
+
name: "generate-cdn-entry",
|
| 33 |
+
enforce: "post",
|
| 34 |
+
writeBundle(config, bundle) {
|
| 35 |
+
if (
|
| 36 |
+
!config.dir ||
|
| 37 |
+
!bundle["index.html"] ||
|
| 38 |
+
bundle["index.html"].type !== "asset"
|
| 39 |
+
)
|
| 40 |
+
return;
|
| 41 |
+
|
| 42 |
+
const source = bundle["index.html"].source as string;
|
| 43 |
+
const tree = parse(source);
|
| 44 |
+
|
| 45 |
+
const script = Array.from(
|
| 46 |
+
tree.querySelectorAll("script[type=module]")
|
| 47 |
+
).find((node) => node.attributes.src?.includes("assets"));
|
| 48 |
+
|
| 49 |
+
const output_location = join(config.dir, "gradio.js");
|
| 50 |
+
|
| 51 |
+
writeFileSync(output_location, make_entry(script?.attributes.src || ""));
|
| 52 |
+
|
| 53 |
+
if (!script) return;
|
| 54 |
+
|
| 55 |
+
const transformed_html =
|
| 56 |
+
(bundle["index.html"].source as string).substring(0, script?.range[0]) +
|
| 57 |
+
`<script type="module" crossorigin src="${cdn_base}/${version}/gradio.js"></script>` +
|
| 58 |
+
(bundle["index.html"].source as string).substring(
|
| 59 |
+
script?.range[1],
|
| 60 |
+
source.length
|
| 61 |
+
);
|
| 62 |
+
|
| 63 |
+
const share_html_location = join(config.dir, "share.html");
|
| 64 |
+
writeFileSync(share_html_location, transformed_html);
|
| 65 |
+
}
|
| 66 |
+
};
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
const RE_SVELTE_IMPORT =
|
| 70 |
+
/import\s+([\w*{},\s]+)\s+from\s+['"](svelte|svelte\/internal)['"]/g;
|
| 71 |
+
|
| 72 |
+
export function generate_dev_entry({ enable }: { enable: boolean }): Plugin {
|
| 73 |
+
return {
|
| 74 |
+
name: "generate-dev-entry",
|
| 75 |
+
transform(code, id) {
|
| 76 |
+
if (!enable) return;
|
| 77 |
+
|
| 78 |
+
const new_code = code.replace(RE_SVELTE_IMPORT, (str, $1, $2) => {
|
| 79 |
+
return `const ${$1
|
| 80 |
+
.replace(/\* as /, "")
|
| 81 |
+
.replace(/ as /g, ": ")} = window.__gradio__svelte__internal;`;
|
| 82 |
+
});
|
| 83 |
+
|
| 84 |
+
return {
|
| 85 |
+
code: new_code,
|
| 86 |
+
map: null
|
| 87 |
+
};
|
| 88 |
+
}
|
| 89 |
+
};
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
function make_entry(script: string): string {
|
| 93 |
+
return `import("${script}");
|
| 94 |
+
`;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
export function handle_ce_css(): Plugin {
|
| 98 |
+
return {
|
| 99 |
+
enforce: "post",
|
| 100 |
+
name: "custom-element-css",
|
| 101 |
+
|
| 102 |
+
writeBundle(config, bundle) {
|
| 103 |
+
let file_to_insert = {
|
| 104 |
+
filename: "",
|
| 105 |
+
source: ""
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
if (
|
| 109 |
+
!config.dir ||
|
| 110 |
+
!bundle["index.html"] ||
|
| 111 |
+
bundle["index.html"].type !== "asset"
|
| 112 |
+
)
|
| 113 |
+
return;
|
| 114 |
+
|
| 115 |
+
for (const key in bundle) {
|
| 116 |
+
const chunk = bundle[key];
|
| 117 |
+
if (chunk.type === "chunk") {
|
| 118 |
+
const _chunk = chunk;
|
| 119 |
+
|
| 120 |
+
const found = _chunk.code?.indexOf("ENTRY_CSS");
|
| 121 |
+
|
| 122 |
+
if (found > -1)
|
| 123 |
+
file_to_insert = {
|
| 124 |
+
filename: join(config.dir, key),
|
| 125 |
+
source: _chunk.code
|
| 126 |
+
};
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
const tree = parse(bundle["index.html"].source as string);
|
| 131 |
+
|
| 132 |
+
const { style, fonts } = Array.from(
|
| 133 |
+
tree.querySelectorAll("link[rel=stylesheet]")
|
| 134 |
+
).reduce(
|
| 135 |
+
(acc, next) => {
|
| 136 |
+
if (/.*\/index(.*?)\.css/.test(next.attributes.href)) {
|
| 137 |
+
return { ...acc, style: next };
|
| 138 |
+
}
|
| 139 |
+
return { ...acc, fonts: [...acc.fonts, next.attributes.href] };
|
| 140 |
+
},
|
| 141 |
+
{ fonts: [], style: undefined } as {
|
| 142 |
+
fonts: string[];
|
| 143 |
+
style: HTMLElement | undefined;
|
| 144 |
+
}
|
| 145 |
+
);
|
| 146 |
+
|
| 147 |
+
writeFileSync(
|
| 148 |
+
file_to_insert.filename,
|
| 149 |
+
file_to_insert.source
|
| 150 |
+
.replace("__ENTRY_CSS__", style!.attributes.href)
|
| 151 |
+
.replace(
|
| 152 |
+
'"__FONTS_CSS__"',
|
| 153 |
+
`[${fonts.map((f) => `"${f}"`).join(",")}]`
|
| 154 |
+
)
|
| 155 |
+
);
|
| 156 |
+
|
| 157 |
+
const share_html_location = join(config.dir, "share.html");
|
| 158 |
+
const share_html = readFileSync(share_html_location, "utf8");
|
| 159 |
+
const share_tree = parse(share_html);
|
| 160 |
+
const node = Array.from(
|
| 161 |
+
share_tree.querySelectorAll("link[rel=stylesheet]")
|
| 162 |
+
).find((node) => /.*\/index(.*?)\.css/.test(node.attributes.href));
|
| 163 |
+
|
| 164 |
+
if (!node) return;
|
| 165 |
+
const transformed_html =
|
| 166 |
+
share_html.substring(0, node.range[0]) +
|
| 167 |
+
share_html.substring(node.range[1], share_html.length);
|
| 168 |
+
|
| 169 |
+
writeFileSync(share_html_location, transformed_html);
|
| 170 |
+
}
|
| 171 |
+
};
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
// generate component importsy
|
| 175 |
+
|
| 176 |
+
import * as url from "url";
|
| 177 |
+
const __filename = url.fileURLToPath(import.meta.url);
|
| 178 |
+
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
| 179 |
+
|
| 180 |
+
import { readdirSync, existsSync, readFileSync, statSync } from "fs";
|
| 181 |
+
|
| 182 |
+
function get_export_path(
|
| 183 |
+
path: string,
|
| 184 |
+
root: string,
|
| 185 |
+
pkg_json: Record<string, any>
|
| 186 |
+
): boolean {
|
| 187 |
+
if (!pkg_json.exports) return false;
|
| 188 |
+
if ( typeof pkg_json.exports[`${path}`] === "object") return true;
|
| 189 |
+
const _path = join(root, "..", `${pkg_json.exports[`${path}`]}`);
|
| 190 |
+
|
| 191 |
+
return existsSync(_path);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
const ignore_list = [
|
| 195 |
+
"tootils",
|
| 196 |
+
"_cdn-test",
|
| 197 |
+
"_spaces-test",
|
| 198 |
+
"_website",
|
| 199 |
+
"app",
|
| 200 |
+
"atoms",
|
| 201 |
+
"fallback",
|
| 202 |
+
"icons",
|
| 203 |
+
"lite",
|
| 204 |
+
"preview",
|
| 205 |
+
"simpledropdown",
|
| 206 |
+
"simpleimage",
|
| 207 |
+
"simpletextbox",
|
| 208 |
+
"storybook",
|
| 209 |
+
"theme",
|
| 210 |
+
"timeseries",
|
| 211 |
+
"tooltip",
|
| 212 |
+
"upload",
|
| 213 |
+
"utils",
|
| 214 |
+
"wasm"
|
| 215 |
+
];
|
| 216 |
+
function generate_component_imports(): string {
|
| 217 |
+
const exports = readdirSync(join(__dirname, "..", ".."))
|
| 218 |
+
.map((dir) => {
|
| 219 |
+
if (ignore_list.includes(dir)) return undefined;
|
| 220 |
+
if (!statSync(join(__dirname, "..","..", dir)).isDirectory()) return undefined;
|
| 221 |
+
|
| 222 |
+
const package_json_path = join(__dirname, "..","..", dir, "package.json");
|
| 223 |
+
if (existsSync(package_json_path)) {
|
| 224 |
+
const package_json = JSON.parse(
|
| 225 |
+
readFileSync(package_json_path, "utf8")
|
| 226 |
+
);
|
| 227 |
+
|
| 228 |
+
const component = get_export_path(".", package_json_path, package_json);
|
| 229 |
+
const example = get_export_path(
|
| 230 |
+
"./example",
|
| 231 |
+
package_json_path,
|
| 232 |
+
package_json
|
| 233 |
+
);
|
| 234 |
+
|
| 235 |
+
const base = get_export_path("./base", package_json_path, package_json);
|
| 236 |
+
|
| 237 |
+
if (!component && !example) return undefined;
|
| 238 |
+
|
| 239 |
+
return {
|
| 240 |
+
name: package_json.name,
|
| 241 |
+
component,
|
| 242 |
+
example,
|
| 243 |
+
base
|
| 244 |
+
};
|
| 245 |
+
}
|
| 246 |
+
return undefined;
|
| 247 |
+
})
|
| 248 |
+
.filter((x) => x !== undefined);
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
const imports = exports.reduce((acc, _export) => {
|
| 252 |
+
if (!_export) return acc;
|
| 253 |
+
|
| 254 |
+
const example = _export.example
|
| 255 |
+
? `example: () => import("${_export.name}/example"),\n`
|
| 256 |
+
: "";
|
| 257 |
+
const base = _export.base
|
| 258 |
+
? `base: () => import("${_export.name}/base"),\n`
|
| 259 |
+
: "";
|
| 260 |
+
return `${acc}"${_export.name.replace("@gradio/", "")}": {
|
| 261 |
+
${base}
|
| 262 |
+
${example}
|
| 263 |
+
component: () => import("${_export.name}")
|
| 264 |
+
},\n`;
|
| 265 |
+
}, "");
|
| 266 |
+
|
| 267 |
+
return imports;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
function load_virtual_component_loader(mode: string): string {
|
| 271 |
+
const loader_path = join(__dirname, "component_loader.js");
|
| 272 |
+
let component_map = "";
|
| 273 |
+
|
| 274 |
+
if (mode === "test") {
|
| 275 |
+
component_map = `
|
| 276 |
+
const component_map = {
|
| 277 |
+
"test-component-one": {
|
| 278 |
+
component: () => import("@gradio-test/test-one"),
|
| 279 |
+
example: () => import("@gradio-test/test-one/example")
|
| 280 |
+
},
|
| 281 |
+
"dataset": {
|
| 282 |
+
component: () => import("@gradio-test/test-two"),
|
| 283 |
+
example: () => import("@gradio-test/test-two/example")
|
| 284 |
+
},
|
| 285 |
+
"image": {
|
| 286 |
+
component: () => import("@gradio/image"),
|
| 287 |
+
example: () => import("@gradio/image/example"),
|
| 288 |
+
base: () => import("@gradio/image/base")
|
| 289 |
+
},
|
| 290 |
+
"audio": {
|
| 291 |
+
component: () => import("@gradio/audio"),
|
| 292 |
+
example: () => import("@gradio/audio/example"),
|
| 293 |
+
base: () => import("@gradio/audio/base")
|
| 294 |
+
},
|
| 295 |
+
"video": {
|
| 296 |
+
component: () => import("@gradio/video"),
|
| 297 |
+
example: () => import("@gradio/video/example"),
|
| 298 |
+
base: () => import("@gradio/video/base")
|
| 299 |
+
},
|
| 300 |
+
// "test-component-one": {
|
| 301 |
+
// component: () => import("@gradio-test/test-one"),
|
| 302 |
+
// example: () => import("@gradio-test/test-one/example")
|
| 303 |
+
// },
|
| 304 |
+
};
|
| 305 |
+
`;
|
| 306 |
+
} else {
|
| 307 |
+
component_map = `
|
| 308 |
+
const component_map = {
|
| 309 |
+
${generate_component_imports()}
|
| 310 |
+
};
|
| 311 |
+
`;
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
return `${component_map}\n\n${readFileSync(loader_path, "utf8")}`;
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
export function inject_component_loader({ mode }: { mode: string }): Plugin {
|
| 318 |
+
const v_id = "virtual:component-loader";
|
| 319 |
+
const resolved_v_id = "\0" + v_id;
|
| 320 |
+
|
| 321 |
+
return {
|
| 322 |
+
name: "inject-component-loader",
|
| 323 |
+
enforce: "pre",
|
| 324 |
+
resolveId(id: string) {
|
| 325 |
+
if (id === v_id) return resolved_v_id;
|
| 326 |
+
},
|
| 327 |
+
load(id: string) {
|
| 328 |
+
this.addWatchFile(join(__dirname, "component_loader.js"));
|
| 329 |
+
if (id === resolved_v_id) {
|
| 330 |
+
return load_virtual_component_loader(mode);
|
| 331 |
+
}
|
| 332 |
+
}
|
| 333 |
+
};
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
export function resolve_svelte(enable: boolean): Plugin {
|
| 337 |
+
return {
|
| 338 |
+
enforce: "pre",
|
| 339 |
+
name: "resolve-svelte",
|
| 340 |
+
async resolveId(id: string) {
|
| 341 |
+
if (!enable) return;
|
| 342 |
+
|
| 343 |
+
if (
|
| 344 |
+
id === "./svelte/svelte.js" ||
|
| 345 |
+
id === "svelte" ||
|
| 346 |
+
id === "svelte/internal"
|
| 347 |
+
) {
|
| 348 |
+
const mod = join(
|
| 349 |
+
__dirname,
|
| 350 |
+
"..",
|
| 351 |
+
"..",
|
| 352 |
+
"..",
|
| 353 |
+
"gradio",
|
| 354 |
+
"templates",
|
| 355 |
+
"frontend",
|
| 356 |
+
"assets",
|
| 357 |
+
"svelte",
|
| 358 |
+
"svelte.js"
|
| 359 |
+
);
|
| 360 |
+
return { id: mod, external: "absolute" };
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
};
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
export function mock_modules(): Plugin {
|
| 367 |
+
const v_id_1 = "@gradio-test/test-one";
|
| 368 |
+
const v_id_2 = "@gradio-test/test-two";
|
| 369 |
+
const v_id_1_example = "@gradio-test/test-one/example";
|
| 370 |
+
const v_id_2_example = "@gradio-test/test-two/example";
|
| 371 |
+
const resolved_v_id = "\0" + v_id_1;
|
| 372 |
+
const resolved_v_id_2 = "\0" + v_id_2;
|
| 373 |
+
const resolved_v_id_1_example = "\0" + v_id_1_example;
|
| 374 |
+
const resolved_v_id_2_example = "\0" + v_id_2_example;
|
| 375 |
+
const fallback_example = "@gradio/fallback/example";
|
| 376 |
+
const resolved_fallback_example = "\0" + fallback_example;
|
| 377 |
+
|
| 378 |
+
return {
|
| 379 |
+
name: "mock-modules",
|
| 380 |
+
enforce: "pre",
|
| 381 |
+
resolveId(id: string) {
|
| 382 |
+
if (id === v_id_1) return resolved_v_id;
|
| 383 |
+
if (id === v_id_2) return resolved_v_id_2;
|
| 384 |
+
if (id === v_id_1_example) return resolved_v_id_1_example;
|
| 385 |
+
if (id === v_id_2_example) return resolved_v_id_2_example;
|
| 386 |
+
if (id === fallback_example) return resolved_fallback_example;
|
| 387 |
+
},
|
| 388 |
+
load(id: string) {
|
| 389 |
+
if (
|
| 390 |
+
id === resolved_v_id ||
|
| 391 |
+
id === resolved_v_id_2 ||
|
| 392 |
+
id === resolved_v_id_1_example ||
|
| 393 |
+
id === resolved_v_id_2_example ||
|
| 394 |
+
id === resolved_fallback_example
|
| 395 |
+
) {
|
| 396 |
+
return `export default {}`;
|
| 397 |
+
}
|
| 398 |
+
}
|
| 399 |
+
};
|
| 400 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/ButtonPanel.svelte
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import LikeDislike from "./LikeDislike.svelte";
|
| 3 |
+
import Copy from "./Copy.svelte";
|
| 4 |
+
import type { FileData } from "@gradio/client";
|
| 5 |
+
import DownloadIcon from "./Download.svelte";
|
| 6 |
+
import { DownloadLink } from "@gradio/wasm/svelte";
|
| 7 |
+
import type { NormalisedMessage, TextMessage } from "../types";
|
| 8 |
+
import { is_component_message } from "./utils";
|
| 9 |
+
import { Retry, Undo } from "@gradio/icons";
|
| 10 |
+
import { IconButtonWrapper, IconButton } from "@gradio/atoms";
|
| 11 |
+
|
| 12 |
+
export let likeable: boolean;
|
| 13 |
+
export let show_retry: boolean;
|
| 14 |
+
export let show_undo: boolean;
|
| 15 |
+
export let show_copy_button: boolean;
|
| 16 |
+
export let show: boolean;
|
| 17 |
+
export let message: NormalisedMessage | NormalisedMessage[];
|
| 18 |
+
export let position: "right" | "left";
|
| 19 |
+
export let avatar: FileData | null;
|
| 20 |
+
export let generating: boolean;
|
| 21 |
+
|
| 22 |
+
export let handle_action: (selected: string | null) => void;
|
| 23 |
+
export let layout: "bubble" | "panel";
|
| 24 |
+
|
| 25 |
+
function is_all_text(
|
| 26 |
+
message: NormalisedMessage[] | NormalisedMessage
|
| 27 |
+
): message is TextMessage[] | TextMessage {
|
| 28 |
+
return (
|
| 29 |
+
(Array.isArray(message) &&
|
| 30 |
+
message.every((m) => typeof m.content === "string")) ||
|
| 31 |
+
(!Array.isArray(message) && typeof message.content === "string")
|
| 32 |
+
);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
function all_text(message: TextMessage[] | TextMessage): string {
|
| 36 |
+
if (Array.isArray(message)) {
|
| 37 |
+
return message.map((m) => m.content).join("\n");
|
| 38 |
+
}
|
| 39 |
+
return message.content;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
$: message_text = is_all_text(message) ? all_text(message) : "";
|
| 43 |
+
|
| 44 |
+
$: show_copy = show_copy_button && message && is_all_text(message);
|
| 45 |
+
$: show_download =
|
| 46 |
+
!Array.isArray(message) &&
|
| 47 |
+
is_component_message(message) &&
|
| 48 |
+
message.content.value?.url;
|
| 49 |
+
</script>
|
| 50 |
+
|
| 51 |
+
{#if show}
|
| 52 |
+
<div
|
| 53 |
+
class="message-buttons-{position} {layout} message-buttons {avatar !==
|
| 54 |
+
null && 'with-avatar'}"
|
| 55 |
+
>
|
| 56 |
+
<IconButtonWrapper top_panel={false}>
|
| 57 |
+
{#if show_copy}
|
| 58 |
+
<Copy value={message_text} />
|
| 59 |
+
{/if}
|
| 60 |
+
{#if show_download && !Array.isArray(message) && is_component_message(message)}
|
| 61 |
+
<DownloadLink
|
| 62 |
+
href={message?.content?.value.url}
|
| 63 |
+
download={message.content.value.orig_name || "image"}
|
| 64 |
+
>
|
| 65 |
+
<IconButton Icon={DownloadIcon} />
|
| 66 |
+
</DownloadLink>
|
| 67 |
+
{/if}
|
| 68 |
+
{#if show_retry}
|
| 69 |
+
<IconButton
|
| 70 |
+
Icon={Retry}
|
| 71 |
+
label="Retry"
|
| 72 |
+
on:click={() => handle_action("retry")}
|
| 73 |
+
disabled={generating}
|
| 74 |
+
/>
|
| 75 |
+
{/if}
|
| 76 |
+
{#if show_undo}
|
| 77 |
+
<IconButton
|
| 78 |
+
label="Undo"
|
| 79 |
+
Icon={Undo}
|
| 80 |
+
on:click={() => handle_action("undo")}
|
| 81 |
+
disabled={generating}
|
| 82 |
+
/>
|
| 83 |
+
{/if}
|
| 84 |
+
{#if likeable}
|
| 85 |
+
<LikeDislike {handle_action} />
|
| 86 |
+
{/if}
|
| 87 |
+
</IconButtonWrapper>
|
| 88 |
+
</div>
|
| 89 |
+
{/if}
|
| 90 |
+
|
| 91 |
+
<style>
|
| 92 |
+
.bubble :global(.icon-button-wrapper) {
|
| 93 |
+
margin: 0px calc(var(--spacing-xl) * 2);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
.message-buttons-left {
|
| 97 |
+
align-self: flex-start;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
.bubble.message-buttons-right {
|
| 101 |
+
align-self: flex-end;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
.message-buttons-right :global(.icon-button-wrapper) {
|
| 105 |
+
margin-left: auto;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.bubble.with-avatar {
|
| 109 |
+
margin-left: calc(var(--spacing-xl) * 5);
|
| 110 |
+
margin-right: calc(var(--spacing-xl) * 5);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.panel {
|
| 114 |
+
display: flex;
|
| 115 |
+
align-self: flex-start;
|
| 116 |
+
padding: 0 var(--spacing-xl);
|
| 117 |
+
z-index: var(--layer-1);
|
| 118 |
+
}
|
| 119 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/Component.svelte
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export let type: "gallery" | "plot" | "audio" | "video" | "image" | string;
|
| 3 |
+
export let components;
|
| 4 |
+
export let value;
|
| 5 |
+
export let target;
|
| 6 |
+
export let theme_mode;
|
| 7 |
+
export let props;
|
| 8 |
+
export let i18n;
|
| 9 |
+
export let upload;
|
| 10 |
+
export let _fetch;
|
| 11 |
+
</script>
|
| 12 |
+
|
| 13 |
+
{#if type === "gallery"}
|
| 14 |
+
<svelte:component
|
| 15 |
+
this={components[type]}
|
| 16 |
+
{value}
|
| 17 |
+
show_label={false}
|
| 18 |
+
{i18n}
|
| 19 |
+
label=""
|
| 20 |
+
{_fetch}
|
| 21 |
+
allow_preview={false}
|
| 22 |
+
interactive={false}
|
| 23 |
+
mode="minimal"
|
| 24 |
+
fixed_height={1}
|
| 25 |
+
on:load
|
| 26 |
+
/>
|
| 27 |
+
{:else if type === "plot"}
|
| 28 |
+
<svelte:component
|
| 29 |
+
this={components[type]}
|
| 30 |
+
{value}
|
| 31 |
+
{target}
|
| 32 |
+
{theme_mode}
|
| 33 |
+
bokeh_version={props.bokeh_version}
|
| 34 |
+
caption=""
|
| 35 |
+
show_actions_button={true}
|
| 36 |
+
on:load
|
| 37 |
+
/>
|
| 38 |
+
{:else if type === "audio"}
|
| 39 |
+
<svelte:component
|
| 40 |
+
this={components[type]}
|
| 41 |
+
{value}
|
| 42 |
+
show_label={false}
|
| 43 |
+
show_share_button={true}
|
| 44 |
+
{i18n}
|
| 45 |
+
label=""
|
| 46 |
+
waveform_settings={{}}
|
| 47 |
+
waveform_options={{}}
|
| 48 |
+
show_download_button={false}
|
| 49 |
+
on:load
|
| 50 |
+
/>
|
| 51 |
+
{:else if type === "video"}
|
| 52 |
+
<svelte:component
|
| 53 |
+
this={components[type]}
|
| 54 |
+
autoplay={true}
|
| 55 |
+
value={value.video || value}
|
| 56 |
+
show_label={false}
|
| 57 |
+
show_share_button={true}
|
| 58 |
+
{i18n}
|
| 59 |
+
{upload}
|
| 60 |
+
show_download_button={false}
|
| 61 |
+
on:load
|
| 62 |
+
>
|
| 63 |
+
<track kind="captions" />
|
| 64 |
+
</svelte:component>
|
| 65 |
+
{:else if type === "image"}
|
| 66 |
+
<svelte:component
|
| 67 |
+
this={components[type]}
|
| 68 |
+
{value}
|
| 69 |
+
show_label={false}
|
| 70 |
+
label="chatbot-image"
|
| 71 |
+
show_download_button={false}
|
| 72 |
+
on:load
|
| 73 |
+
{i18n}
|
| 74 |
+
/>
|
| 75 |
+
{:else if type === "html"}
|
| 76 |
+
<svelte:component
|
| 77 |
+
this={components[type]}
|
| 78 |
+
{value}
|
| 79 |
+
show_label={false}
|
| 80 |
+
label="chatbot-image"
|
| 81 |
+
show_share_button={true}
|
| 82 |
+
{i18n}
|
| 83 |
+
gradio={{ dispatch: () => {} }}
|
| 84 |
+
on:load
|
| 85 |
+
/>
|
| 86 |
+
{/if}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/Copy.svelte
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { onDestroy } from "svelte";
|
| 3 |
+
import { Copy, Check } from "@gradio/icons";
|
| 4 |
+
import { IconButton } from "@gradio/atoms";
|
| 5 |
+
|
| 6 |
+
let copied = false;
|
| 7 |
+
export let value: string;
|
| 8 |
+
let timer: NodeJS.Timeout;
|
| 9 |
+
|
| 10 |
+
function copy_feedback(): void {
|
| 11 |
+
copied = true;
|
| 12 |
+
if (timer) clearTimeout(timer);
|
| 13 |
+
timer = setTimeout(() => {
|
| 14 |
+
copied = false;
|
| 15 |
+
}, 2000);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
async function handle_copy(): Promise<void> {
|
| 19 |
+
if ("clipboard" in navigator) {
|
| 20 |
+
await navigator.clipboard.writeText(value);
|
| 21 |
+
copy_feedback();
|
| 22 |
+
} else {
|
| 23 |
+
const textArea = document.createElement("textarea");
|
| 24 |
+
textArea.value = value;
|
| 25 |
+
|
| 26 |
+
textArea.style.position = "absolute";
|
| 27 |
+
textArea.style.left = "-999999px";
|
| 28 |
+
|
| 29 |
+
document.body.prepend(textArea);
|
| 30 |
+
textArea.select();
|
| 31 |
+
|
| 32 |
+
try {
|
| 33 |
+
document.execCommand("copy");
|
| 34 |
+
copy_feedback();
|
| 35 |
+
} catch (error) {
|
| 36 |
+
console.error(error);
|
| 37 |
+
} finally {
|
| 38 |
+
textArea.remove();
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
onDestroy(() => {
|
| 44 |
+
if (timer) clearTimeout(timer);
|
| 45 |
+
});
|
| 46 |
+
</script>
|
| 47 |
+
|
| 48 |
+
<IconButton
|
| 49 |
+
on:click={handle_copy}
|
| 50 |
+
label={copied ? "Copied message" : "Copy message"}
|
| 51 |
+
Icon={copied ? Check : Copy}
|
| 52 |
+
/>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/Remove.svelte
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg
|
| 2 |
+
id="fi_3502539"
|
| 3 |
+
fill="currentColor"
|
| 4 |
+
height="100%"
|
| 5 |
+
viewBox="0 0 24 24"
|
| 6 |
+
width="100%"
|
| 7 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 8 |
+
><path
|
| 9 |
+
d="m7 16a1 1 0 0 0 .71-.3 1 1 0 0 0 0-1.41l-3.33-3.29h10.13a4.49 4.49 0 0 1 0 9h-2.51a1 1 0 0 0 0 2h2.51a6.49 6.49 0 0 0 0-13h-10.14l3.33-3.29a1 1 0 0 0 -1.4-1.42l-5.07 5a1 1 0 0 0 -.29.71 1 1 0 0 0 .3.71l5.06 5a1 1 0 0 0 .7.29z"
|
| 10 |
+
></path></svg
|
| 11 |
+
>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/ThumbDownDefault.svelte
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg
|
| 2 |
+
width="100%"
|
| 3 |
+
height="100%"
|
| 4 |
+
viewBox="0 0 12 12"
|
| 5 |
+
fill="none"
|
| 6 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 7 |
+
>
|
| 8 |
+
<path
|
| 9 |
+
d="M2.25 8.11523H4.5V10.3652C4.5003 10.6635 4.61892 10.9495 4.82983 11.1604C5.04075 11.3713 5.32672 11.4899 5.625 11.4902H6.42488C6.60519 11.4895 6.77926 11.4241 6.91549 11.3059C7.05172 11.1878 7.14109 11.0248 7.16737 10.8464L7.48425 8.62748L8.82562 6.61523H11.25V1.36523H3.375C2.67911 1.36623 2.01201 1.64311 1.51994 2.13517C1.02787 2.62724 0.750992 3.29435 0.75 3.99023V6.61523C0.750496 7.01291 0.908691 7.39415 1.18989 7.67535C1.47109 7.95654 1.85233 8.11474 2.25 8.11523ZM9 2.11523H10.5V5.86523H9V2.11523ZM1.5 3.99023C1.5006 3.49314 1.69833 3.01657 2.04983 2.66507C2.40133 2.31356 2.8779 2.11583 3.375 2.11523H8.25V6.12661L6.76575 8.35298L6.4245 10.7402H5.625C5.52554 10.7402 5.43016 10.7007 5.35983 10.6304C5.28951 10.5601 5.25 10.4647 5.25 10.3652V7.36523H2.25C2.05118 7.36494 1.86059 7.28582 1.72 7.14524C1.57941 7.00465 1.5003 6.81406 1.5 6.61523V3.99023Z"
|
| 10 |
+
fill="currentColor"
|
| 11 |
+
/>
|
| 12 |
+
</svg>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/chatbot/shared/ThumbUpActive.svelte
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg
|
| 2 |
+
width="100%"
|
| 3 |
+
height="100%"
|
| 4 |
+
viewBox="0 0 12 12"
|
| 5 |
+
fill="none"
|
| 6 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 7 |
+
>
|
| 8 |
+
<path
|
| 9 |
+
d="M0.75 6.24023H2.625V11.4902H0.75V6.24023ZM8.625 11.4902H3.375V5.93911L4.51575 4.22798L4.83263 2.00911C4.85892 1.83065 4.94834 1.66754 5.08465 1.5494C5.22096 1.43125 5.39512 1.36591 5.5755 1.36523H5.625C5.92328 1.36553 6.20925 1.48415 6.42017 1.69507C6.63108 1.90598 6.7497 2.19196 6.75 2.49023V4.74023H9.75C10.1477 4.74073 10.5289 4.89893 10.8101 5.18012C11.0913 5.46132 11.2495 5.84256 11.25 6.24023V8.86523C11.249 9.56112 10.9721 10.2282 10.4801 10.7203C9.98799 11.2124 9.32089 11.4892 8.625 11.4902Z"
|
| 10 |
+
fill="currentColor"
|
| 11 |
+
/>
|
| 12 |
+
</svg>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/column/Index.svelte
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { StatusTracker } from "@gradio/statustracker";
|
| 3 |
+
import type { LoadingStatus } from "@gradio/statustracker";
|
| 4 |
+
import type { Gradio } from "@gradio/utils";
|
| 5 |
+
|
| 6 |
+
export let scale: number | null = null;
|
| 7 |
+
export let gap = true;
|
| 8 |
+
export let min_width = 0;
|
| 9 |
+
export let elem_id = "";
|
| 10 |
+
export let elem_classes: string[] = [];
|
| 11 |
+
export let visible = true;
|
| 12 |
+
export let variant: "default" | "panel" | "compact" = "default";
|
| 13 |
+
export let loading_status: LoadingStatus | undefined = undefined;
|
| 14 |
+
export let gradio: Gradio | undefined = undefined;
|
| 15 |
+
export let show_progress = false;
|
| 16 |
+
</script>
|
| 17 |
+
|
| 18 |
+
<div
|
| 19 |
+
id={elem_id}
|
| 20 |
+
class="column {elem_classes.join(' ')}"
|
| 21 |
+
class:gap
|
| 22 |
+
class:compact={variant === "compact"}
|
| 23 |
+
class:panel={variant === "panel"}
|
| 24 |
+
class:hide={!visible}
|
| 25 |
+
style:flex-grow={scale}
|
| 26 |
+
style:min-width="calc(min({min_width}px, 100%))"
|
| 27 |
+
>
|
| 28 |
+
{#if loading_status && show_progress && gradio}
|
| 29 |
+
<StatusTracker
|
| 30 |
+
autoscroll={gradio.autoscroll}
|
| 31 |
+
i18n={gradio.i18n}
|
| 32 |
+
{...loading_status}
|
| 33 |
+
status={loading_status
|
| 34 |
+
? loading_status.status == "pending"
|
| 35 |
+
? "generating"
|
| 36 |
+
: loading_status.status
|
| 37 |
+
: null}
|
| 38 |
+
/>
|
| 39 |
+
{/if}
|
| 40 |
+
<slot />
|
| 41 |
+
</div>
|
| 42 |
+
|
| 43 |
+
<style>
|
| 44 |
+
div {
|
| 45 |
+
display: flex;
|
| 46 |
+
position: relative;
|
| 47 |
+
flex-direction: column;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
div > :global(*),
|
| 51 |
+
div > :global(.form > *) {
|
| 52 |
+
width: var(--size-full);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.gap {
|
| 56 |
+
gap: var(--layout-gap);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.hide {
|
| 60 |
+
display: none;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.compact > :global(*),
|
| 64 |
+
.compact :global(.box) {
|
| 65 |
+
border-radius: 0;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.compact,
|
| 69 |
+
.panel {
|
| 70 |
+
border: solid var(--panel-border-width) var(--panel-border-color);
|
| 71 |
+
border-radius: var(--container-radius);
|
| 72 |
+
background: var(--panel-background-fill);
|
| 73 |
+
padding: var(--spacing-lg);
|
| 74 |
+
}
|
| 75 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/file/Example.svelte
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import type { FileData } from "@gradio/client";
|
| 3 |
+
|
| 4 |
+
export let value: FileData | null;
|
| 5 |
+
export let type: "gallery" | "table";
|
| 6 |
+
export let selected = false;
|
| 7 |
+
</script>
|
| 8 |
+
|
| 9 |
+
<div
|
| 10 |
+
class:table={type === "table"}
|
| 11 |
+
class:gallery={type === "gallery"}
|
| 12 |
+
class:selected
|
| 13 |
+
>
|
| 14 |
+
{value ? (Array.isArray(value) ? value.join(", ") : value) : ""}
|
| 15 |
+
</div>
|
| 16 |
+
|
| 17 |
+
<style>
|
| 18 |
+
div {
|
| 19 |
+
overflow: hidden;
|
| 20 |
+
text-overflow: ellipsis;
|
| 21 |
+
white-space: nowrap;
|
| 22 |
+
}
|
| 23 |
+
.gallery {
|
| 24 |
+
display: flex;
|
| 25 |
+
align-items: center;
|
| 26 |
+
cursor: pointer;
|
| 27 |
+
padding: var(--size-1) var(--size-2);
|
| 28 |
+
text-align: left;
|
| 29 |
+
}
|
| 30 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/file/Index.svelte
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svelte:options accessors={true} />
|
| 2 |
+
|
| 3 |
+
<script context="module" lang="ts">
|
| 4 |
+
export { default as FilePreview } from "./shared/FilePreview.svelte";
|
| 5 |
+
export { default as BaseFileUpload } from "./shared/FileUpload.svelte";
|
| 6 |
+
export { default as BaseFile } from "./shared/File.svelte";
|
| 7 |
+
export { default as BaseExample } from "./Example.svelte";
|
| 8 |
+
</script>
|
| 9 |
+
|
| 10 |
+
<script lang="ts">
|
| 11 |
+
import type { Gradio, SelectData } from "@gradio/utils";
|
| 12 |
+
import File from "./shared/File.svelte";
|
| 13 |
+
import FileUpload from "./shared/FileUpload.svelte";
|
| 14 |
+
import type { FileData } from "@gradio/client";
|
| 15 |
+
import { Block, UploadText } from "@gradio/atoms";
|
| 16 |
+
|
| 17 |
+
import { StatusTracker } from "@gradio/statustracker";
|
| 18 |
+
import type { LoadingStatus } from "@gradio/statustracker";
|
| 19 |
+
|
| 20 |
+
export let elem_id = "";
|
| 21 |
+
export let elem_classes: string[] = [];
|
| 22 |
+
export let visible = true;
|
| 23 |
+
export let value: null | FileData | FileData[];
|
| 24 |
+
|
| 25 |
+
export let interactive: boolean;
|
| 26 |
+
export let root: string;
|
| 27 |
+
export let label: string;
|
| 28 |
+
export let show_label: boolean;
|
| 29 |
+
export let height: number | undefined = undefined;
|
| 30 |
+
|
| 31 |
+
export let _selectable = false;
|
| 32 |
+
export let loading_status: LoadingStatus;
|
| 33 |
+
export let container = true;
|
| 34 |
+
export let scale: number | null = null;
|
| 35 |
+
export let min_width: number | undefined = undefined;
|
| 36 |
+
export let gradio: Gradio<{
|
| 37 |
+
change: never;
|
| 38 |
+
error: string;
|
| 39 |
+
upload: never;
|
| 40 |
+
clear: never;
|
| 41 |
+
select: SelectData;
|
| 42 |
+
clear_status: LoadingStatus;
|
| 43 |
+
delete: FileData;
|
| 44 |
+
}>;
|
| 45 |
+
export let file_count: "single" | "multiple" | "directory";
|
| 46 |
+
export let file_types: string[] = ["file"];
|
| 47 |
+
export let input_ready: boolean;
|
| 48 |
+
let uploading = false;
|
| 49 |
+
$: input_ready = !uploading;
|
| 50 |
+
|
| 51 |
+
let old_value = value;
|
| 52 |
+
$: if (JSON.stringify(old_value) !== JSON.stringify(value)) {
|
| 53 |
+
gradio.dispatch("change");
|
| 54 |
+
old_value = value;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
let dragging = false;
|
| 58 |
+
let pending_upload = false;
|
| 59 |
+
</script>
|
| 60 |
+
|
| 61 |
+
<Block
|
| 62 |
+
{visible}
|
| 63 |
+
variant={value ? "solid" : "dashed"}
|
| 64 |
+
border_mode={dragging ? "focus" : "base"}
|
| 65 |
+
padding={false}
|
| 66 |
+
{elem_id}
|
| 67 |
+
{elem_classes}
|
| 68 |
+
{container}
|
| 69 |
+
{scale}
|
| 70 |
+
{min_width}
|
| 71 |
+
allow_overflow={false}
|
| 72 |
+
>
|
| 73 |
+
<StatusTracker
|
| 74 |
+
autoscroll={gradio.autoscroll}
|
| 75 |
+
i18n={gradio.i18n}
|
| 76 |
+
{...loading_status}
|
| 77 |
+
status={pending_upload
|
| 78 |
+
? "generating"
|
| 79 |
+
: loading_status?.status || "complete"}
|
| 80 |
+
on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
|
| 81 |
+
/>
|
| 82 |
+
{#if !interactive}
|
| 83 |
+
<File
|
| 84 |
+
on:select={({ detail }) => gradio.dispatch("select", detail)}
|
| 85 |
+
selectable={_selectable}
|
| 86 |
+
{value}
|
| 87 |
+
{label}
|
| 88 |
+
{show_label}
|
| 89 |
+
{height}
|
| 90 |
+
i18n={gradio.i18n}
|
| 91 |
+
/>
|
| 92 |
+
{:else}
|
| 93 |
+
<FileUpload
|
| 94 |
+
upload={(...args) => gradio.client.upload(...args)}
|
| 95 |
+
stream_handler={(...args) => gradio.client.stream(...args)}
|
| 96 |
+
{label}
|
| 97 |
+
{show_label}
|
| 98 |
+
{value}
|
| 99 |
+
{file_count}
|
| 100 |
+
{file_types}
|
| 101 |
+
selectable={_selectable}
|
| 102 |
+
{root}
|
| 103 |
+
{height}
|
| 104 |
+
bind:uploading
|
| 105 |
+
max_file_size={gradio.max_file_size}
|
| 106 |
+
on:change={({ detail }) => {
|
| 107 |
+
value = detail;
|
| 108 |
+
}}
|
| 109 |
+
on:drag={({ detail }) => (dragging = detail)}
|
| 110 |
+
on:clear={() => gradio.dispatch("clear")}
|
| 111 |
+
on:select={({ detail }) => gradio.dispatch("select", detail)}
|
| 112 |
+
on:upload={() => gradio.dispatch("upload")}
|
| 113 |
+
on:error={({ detail }) => {
|
| 114 |
+
loading_status = loading_status || {};
|
| 115 |
+
loading_status.status = "error";
|
| 116 |
+
gradio.dispatch("error", detail);
|
| 117 |
+
}}
|
| 118 |
+
on:delete={({ detail }) => {
|
| 119 |
+
gradio.dispatch("delete", detail);
|
| 120 |
+
}}
|
| 121 |
+
i18n={gradio.i18n}
|
| 122 |
+
>
|
| 123 |
+
<UploadText i18n={gradio.i18n} type="file" />
|
| 124 |
+
</FileUpload>
|
| 125 |
+
{/if}
|
| 126 |
+
</Block>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/file/shared/File.svelte
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import type { FileData } from "@gradio/client";
|
| 3 |
+
import { BlockLabel, Empty } from "@gradio/atoms";
|
| 4 |
+
import { File } from "@gradio/icons";
|
| 5 |
+
import FilePreview from "./FilePreview.svelte";
|
| 6 |
+
import type { I18nFormatter } from "@gradio/utils";
|
| 7 |
+
|
| 8 |
+
export let value: FileData | FileData[] | null = null;
|
| 9 |
+
export let label: string;
|
| 10 |
+
export let show_label = true;
|
| 11 |
+
export let selectable = false;
|
| 12 |
+
export let height: number | undefined = undefined;
|
| 13 |
+
export let i18n: I18nFormatter;
|
| 14 |
+
</script>
|
| 15 |
+
|
| 16 |
+
<BlockLabel
|
| 17 |
+
{show_label}
|
| 18 |
+
float={value === null}
|
| 19 |
+
Icon={File}
|
| 20 |
+
label={label || "File"}
|
| 21 |
+
/>
|
| 22 |
+
|
| 23 |
+
{#if value && (Array.isArray(value) ? value.length > 0 : true)}
|
| 24 |
+
<FilePreview {i18n} {selectable} on:select {value} {height} />
|
| 25 |
+
{:else}
|
| 26 |
+
<Empty unpadded_box={true} size="large"><File /></Empty>
|
| 27 |
+
{/if}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/file/shared/FilePreview.svelte
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import type { FileData } from "@gradio/client";
|
| 3 |
+
import { prettyBytes } from "./utils";
|
| 4 |
+
import { createEventDispatcher } from "svelte";
|
| 5 |
+
import type { I18nFormatter, SelectData } from "@gradio/utils";
|
| 6 |
+
import { DownloadLink } from "@gradio/wasm/svelte";
|
| 7 |
+
|
| 8 |
+
const dispatch = createEventDispatcher<{
|
| 9 |
+
select: SelectData;
|
| 10 |
+
change: FileData[] | FileData;
|
| 11 |
+
delete: FileData;
|
| 12 |
+
}>();
|
| 13 |
+
export let value: FileData | FileData[];
|
| 14 |
+
export let selectable = false;
|
| 15 |
+
export let height: number | undefined = undefined;
|
| 16 |
+
export let i18n: I18nFormatter;
|
| 17 |
+
|
| 18 |
+
function split_filename(filename: string): [string, string] {
|
| 19 |
+
const last_dot = filename.lastIndexOf(".");
|
| 20 |
+
if (last_dot === -1) {
|
| 21 |
+
return [filename, ""];
|
| 22 |
+
}
|
| 23 |
+
return [filename.slice(0, last_dot), filename.slice(last_dot)];
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
$: normalized_files = (Array.isArray(value) ? value : [value]).map((file) => {
|
| 27 |
+
const [filename_stem, filename_ext] = split_filename(file.orig_name ?? "");
|
| 28 |
+
return {
|
| 29 |
+
...file,
|
| 30 |
+
filename_stem,
|
| 31 |
+
filename_ext
|
| 32 |
+
};
|
| 33 |
+
});
|
| 34 |
+
|
| 35 |
+
function handle_row_click(
|
| 36 |
+
event: MouseEvent & { currentTarget: HTMLTableRowElement },
|
| 37 |
+
index: number
|
| 38 |
+
): void {
|
| 39 |
+
const tr = event.currentTarget;
|
| 40 |
+
const should_select =
|
| 41 |
+
event.target === tr || // Only select if the click is on the row itself
|
| 42 |
+
(tr &&
|
| 43 |
+
tr.firstElementChild &&
|
| 44 |
+
event.composedPath().includes(tr.firstElementChild)); // Or if the click is on the name column
|
| 45 |
+
|
| 46 |
+
if (should_select) {
|
| 47 |
+
dispatch("select", { value: normalized_files[index].orig_name, index });
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function remove_file(index: number): void {
|
| 52 |
+
const removed = normalized_files.splice(index, 1);
|
| 53 |
+
normalized_files = [...normalized_files];
|
| 54 |
+
value = normalized_files;
|
| 55 |
+
dispatch("delete", removed[0]);
|
| 56 |
+
dispatch("change", normalized_files);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
const is_browser = typeof window !== "undefined";
|
| 60 |
+
</script>
|
| 61 |
+
|
| 62 |
+
<div
|
| 63 |
+
class="file-preview-holder"
|
| 64 |
+
style="max-height: {typeof height === undefined ? 'auto' : height + 'px'};"
|
| 65 |
+
>
|
| 66 |
+
<table class="file-preview">
|
| 67 |
+
<tbody>
|
| 68 |
+
{#each normalized_files as file, i (file)}
|
| 69 |
+
<tr
|
| 70 |
+
class="file"
|
| 71 |
+
class:selectable
|
| 72 |
+
on:click={(event) => {
|
| 73 |
+
handle_row_click(event, i);
|
| 74 |
+
}}
|
| 75 |
+
>
|
| 76 |
+
<td class="filename" aria-label={file.orig_name}>
|
| 77 |
+
<span class="stem">{file.filename_stem}</span>
|
| 78 |
+
<span class="ext">{file.filename_ext}</span>
|
| 79 |
+
</td>
|
| 80 |
+
|
| 81 |
+
<td class="download">
|
| 82 |
+
{#if file.url}
|
| 83 |
+
<DownloadLink
|
| 84 |
+
href={file.url}
|
| 85 |
+
download={is_browser && window.__is_colab__
|
| 86 |
+
? null
|
| 87 |
+
: file.orig_name}
|
| 88 |
+
>
|
| 89 |
+
{@html file.size != null
|
| 90 |
+
? prettyBytes(file.size)
|
| 91 |
+
: "(size unknown)"} ⇣
|
| 92 |
+
</DownloadLink>
|
| 93 |
+
{:else}
|
| 94 |
+
{i18n("file.uploading")}
|
| 95 |
+
{/if}
|
| 96 |
+
</td>
|
| 97 |
+
|
| 98 |
+
{#if normalized_files.length > 1}
|
| 99 |
+
<td>
|
| 100 |
+
<button
|
| 101 |
+
class="label-clear-button"
|
| 102 |
+
aria-label="Remove this file"
|
| 103 |
+
on:click={() => {
|
| 104 |
+
remove_file(i);
|
| 105 |
+
}}
|
| 106 |
+
on:keydown={(event) => {
|
| 107 |
+
if (event.key === "Enter") {
|
| 108 |
+
remove_file(i);
|
| 109 |
+
}
|
| 110 |
+
}}
|
| 111 |
+
>×
|
| 112 |
+
</button>
|
| 113 |
+
</td>
|
| 114 |
+
{/if}
|
| 115 |
+
</tr>
|
| 116 |
+
{/each}
|
| 117 |
+
</tbody>
|
| 118 |
+
</table>
|
| 119 |
+
</div>
|
| 120 |
+
|
| 121 |
+
<style>
|
| 122 |
+
.label-clear-button {
|
| 123 |
+
color: var(--body-text-color-subdued);
|
| 124 |
+
position: relative;
|
| 125 |
+
left: -3px;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
.label-clear-button:hover {
|
| 129 |
+
color: var(--body-text-color);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.file-preview {
|
| 133 |
+
table-layout: fixed;
|
| 134 |
+
width: var(--size-full);
|
| 135 |
+
max-height: var(--size-60);
|
| 136 |
+
overflow-y: auto;
|
| 137 |
+
margin-top: var(--size-1);
|
| 138 |
+
color: var(--body-text-color);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
.file-preview-holder {
|
| 142 |
+
overflow: auto;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
.file {
|
| 146 |
+
display: flex;
|
| 147 |
+
width: var(--size-full);
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
.file > * {
|
| 151 |
+
padding: var(--size-1) var(--size-2-5);
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.filename {
|
| 155 |
+
flex-grow: 1;
|
| 156 |
+
display: flex;
|
| 157 |
+
overflow: hidden;
|
| 158 |
+
}
|
| 159 |
+
.filename .stem {
|
| 160 |
+
overflow: hidden;
|
| 161 |
+
text-overflow: ellipsis;
|
| 162 |
+
white-space: nowrap;
|
| 163 |
+
}
|
| 164 |
+
.filename .ext {
|
| 165 |
+
white-space: nowrap;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.download {
|
| 169 |
+
min-width: 8rem;
|
| 170 |
+
width: 10%;
|
| 171 |
+
white-space: nowrap;
|
| 172 |
+
text-align: right;
|
| 173 |
+
}
|
| 174 |
+
.download:hover {
|
| 175 |
+
text-decoration: underline;
|
| 176 |
+
}
|
| 177 |
+
.download > :global(a) {
|
| 178 |
+
color: var(--link-text-color);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
.download > :global(a:hover) {
|
| 182 |
+
color: var(--link-text-color-hover);
|
| 183 |
+
}
|
| 184 |
+
.download > :global(a:visited) {
|
| 185 |
+
color: var(--link-text-color-visited);
|
| 186 |
+
}
|
| 187 |
+
.download > :global(a:active) {
|
| 188 |
+
color: var(--link-text-color-active);
|
| 189 |
+
}
|
| 190 |
+
.selectable {
|
| 191 |
+
cursor: pointer;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
tbody > tr:nth-child(even) {
|
| 195 |
+
background: var(--block-background-fill);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
tbody > tr:nth-child(odd) {
|
| 199 |
+
background: var(--table-odd-background-fill);
|
| 200 |
+
}
|
| 201 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/fileexplorer/icons/light-file.svg
ADDED
|
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/fileexplorer/icons/light-folder.svg
ADDED
|
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/fileexplorer/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@gradio/fileexplorer",
|
| 3 |
+
"version": "0.5.2",
|
| 4 |
+
"description": "Gradio UI packages",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"author": "",
|
| 7 |
+
"license": "ISC",
|
| 8 |
+
"dependencies": {
|
| 9 |
+
"@gradio/atoms": "workspace:^",
|
| 10 |
+
"@gradio/checkbox": "workspace:^",
|
| 11 |
+
"@gradio/client": "workspace:^",
|
| 12 |
+
"@gradio/file": "workspace:^",
|
| 13 |
+
"@gradio/icons": "workspace:^",
|
| 14 |
+
"@gradio/statustracker": "workspace:^",
|
| 15 |
+
"@gradio/upload": "workspace:^",
|
| 16 |
+
"@gradio/utils": "workspace:^",
|
| 17 |
+
"dequal": "^2.0.2"
|
| 18 |
+
},
|
| 19 |
+
"devDependencies": {
|
| 20 |
+
"@gradio/preview": "workspace:^"
|
| 21 |
+
},
|
| 22 |
+
"main_changeset": true,
|
| 23 |
+
"exports": {
|
| 24 |
+
".": {
|
| 25 |
+
"gradio": "./Index.svelte",
|
| 26 |
+
"svelte": "./dist/Index.svelte",
|
| 27 |
+
"types": "./dist/Index.svelte.d.ts"
|
| 28 |
+
},
|
| 29 |
+
"./example": {
|
| 30 |
+
"gradio": "./Example.svelte",
|
| 31 |
+
"svelte": "./dist/Example.svelte",
|
| 32 |
+
"types": "./dist/Example.svelte.d.ts"
|
| 33 |
+
},
|
| 34 |
+
"./package.json": "./package.json"
|
| 35 |
+
},
|
| 36 |
+
"peerDependencies": {
|
| 37 |
+
"svelte": "^4.0.0"
|
| 38 |
+
},
|
| 39 |
+
"repository": {
|
| 40 |
+
"type": "git",
|
| 41 |
+
"url": "git+https://github.com/gradio-app/gradio.git",
|
| 42 |
+
"directory": "js/fileexplorer"
|
| 43 |
+
}
|
| 44 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/image/shared/Image.svelte
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import type { HTMLImgAttributes } from "svelte/elements";
|
| 3 |
+
|
| 4 |
+
interface Props extends HTMLImgAttributes {
|
| 5 |
+
"data-testid"?: string;
|
| 6 |
+
}
|
| 7 |
+
type $$Props = Props;
|
| 8 |
+
|
| 9 |
+
import { resolve_wasm_src } from "@gradio/wasm/svelte";
|
| 10 |
+
|
| 11 |
+
export let src: HTMLImgAttributes["src"] = undefined;
|
| 12 |
+
|
| 13 |
+
let resolved_src: typeof src;
|
| 14 |
+
|
| 15 |
+
// The `src` prop can be updated before the Promise from `resolve_wasm_src` is resolved.
|
| 16 |
+
// In such a case, the resolved value for the old `src` has to be discarded,
|
| 17 |
+
// This variable `latest_src` is used to pick up only the value resolved for the latest `src` prop.
|
| 18 |
+
let latest_src: typeof src;
|
| 19 |
+
$: {
|
| 20 |
+
// In normal (non-Wasm) Gradio, the `<img>` element should be rendered with the passed `src` props immediately
|
| 21 |
+
// without waiting for `resolve_wasm_src()` to resolve.
|
| 22 |
+
// If it waits, a blank image is displayed until the async task finishes
|
| 23 |
+
// and it leads to undesirable flickering.
|
| 24 |
+
// So set `src` to `resolved_src` here.
|
| 25 |
+
resolved_src = src;
|
| 26 |
+
|
| 27 |
+
latest_src = src;
|
| 28 |
+
const resolving_src = src;
|
| 29 |
+
resolve_wasm_src(resolving_src).then((s) => {
|
| 30 |
+
if (latest_src === resolving_src) {
|
| 31 |
+
resolved_src = s;
|
| 32 |
+
}
|
| 33 |
+
});
|
| 34 |
+
}
|
| 35 |
+
</script>
|
| 36 |
+
|
| 37 |
+
<!-- svelte-ignore a11y-missing-attribute -->
|
| 38 |
+
<img src={resolved_src} {...$$restProps} on:load />
|
| 39 |
+
|
| 40 |
+
<style>
|
| 41 |
+
img {
|
| 42 |
+
object-fit: cover;
|
| 43 |
+
}
|
| 44 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/Example.svelte
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { BaseImage as Image } from "@gradio/image";
|
| 3 |
+
import type { EditorData } from "./shared/InteractiveImageEditor.svelte";
|
| 4 |
+
|
| 5 |
+
export let value: EditorData;
|
| 6 |
+
export let type: "gallery" | "table";
|
| 7 |
+
export let selected = false;
|
| 8 |
+
</script>
|
| 9 |
+
|
| 10 |
+
<div
|
| 11 |
+
class="container"
|
| 12 |
+
class:table={type === "table"}
|
| 13 |
+
class:gallery={type === "gallery"}
|
| 14 |
+
class:selected
|
| 15 |
+
>
|
| 16 |
+
<Image src={value.composite?.url || value.background?.url} alt="" />
|
| 17 |
+
</div>
|
| 18 |
+
|
| 19 |
+
<style>
|
| 20 |
+
.container :global(img) {
|
| 21 |
+
width: 100%;
|
| 22 |
+
height: 100%;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.container.selected {
|
| 26 |
+
border-color: var(--border-color-accent);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
.container.table {
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
border: 2px solid var(--border-color-primary);
|
| 32 |
+
border-radius: var(--radius-lg);
|
| 33 |
+
width: var(--size-20);
|
| 34 |
+
height: var(--size-20);
|
| 35 |
+
object-fit: cover;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
.container.gallery {
|
| 39 |
+
border: 2px solid var(--border-color-primary);
|
| 40 |
+
height: var(--size-20);
|
| 41 |
+
max-height: var(--size-20);
|
| 42 |
+
object-fit: cover;
|
| 43 |
+
}
|
| 44 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/Index.svelte
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svelte:options accessors={true} immutable={true} />
|
| 2 |
+
|
| 3 |
+
<script lang="ts">
|
| 4 |
+
import type { Brush, Eraser } from "./shared/tools/Brush.svelte";
|
| 5 |
+
import type {
|
| 6 |
+
EditorData,
|
| 7 |
+
ImageBlobs
|
| 8 |
+
} from "./shared/InteractiveImageEditor.svelte";
|
| 9 |
+
|
| 10 |
+
import type { Gradio, SelectData } from "@gradio/utils";
|
| 11 |
+
import { BaseStaticImage as StaticImage } from "@gradio/image";
|
| 12 |
+
import InteractiveImageEditor from "./shared/InteractiveImageEditor.svelte";
|
| 13 |
+
import { Block } from "@gradio/atoms";
|
| 14 |
+
import { StatusTracker } from "@gradio/statustracker";
|
| 15 |
+
import type { LoadingStatus } from "@gradio/statustracker";
|
| 16 |
+
import { tick } from "svelte";
|
| 17 |
+
|
| 18 |
+
export let elem_id = "";
|
| 19 |
+
export let elem_classes: string[] = [];
|
| 20 |
+
export let visible = true;
|
| 21 |
+
export let value: EditorData | null = {
|
| 22 |
+
background: null,
|
| 23 |
+
layers: [],
|
| 24 |
+
composite: null
|
| 25 |
+
};
|
| 26 |
+
export let label: string;
|
| 27 |
+
export let show_label: boolean;
|
| 28 |
+
export let show_download_button: boolean;
|
| 29 |
+
export let root: string;
|
| 30 |
+
export let value_is_output = false;
|
| 31 |
+
|
| 32 |
+
export let height: number | undefined = 450;
|
| 33 |
+
export let width: number | undefined;
|
| 34 |
+
|
| 35 |
+
export let _selectable = false;
|
| 36 |
+
export let container = true;
|
| 37 |
+
export let scale: number | null = null;
|
| 38 |
+
export let min_width: number | undefined = undefined;
|
| 39 |
+
export let loading_status: LoadingStatus;
|
| 40 |
+
export let show_share_button = false;
|
| 41 |
+
export let sources: ("clipboard" | "webcam" | "upload")[] = [
|
| 42 |
+
"upload",
|
| 43 |
+
"clipboard",
|
| 44 |
+
"webcam"
|
| 45 |
+
];
|
| 46 |
+
export let interactive: boolean;
|
| 47 |
+
export let placeholder: string | undefined;
|
| 48 |
+
|
| 49 |
+
export let brush: Brush;
|
| 50 |
+
export let eraser: Eraser;
|
| 51 |
+
export let crop_size: [number, number] | `${string}:${string}` | null = null;
|
| 52 |
+
export let transforms: "crop"[] = ["crop"];
|
| 53 |
+
export let layers = true;
|
| 54 |
+
export let attached_events: string[] = [];
|
| 55 |
+
export let server: {
|
| 56 |
+
accept_blobs: (a: any) => void;
|
| 57 |
+
};
|
| 58 |
+
export let canvas_size: [number, number] | undefined;
|
| 59 |
+
export let show_fullscreen_button = true;
|
| 60 |
+
|
| 61 |
+
export let gradio: Gradio<{
|
| 62 |
+
change: never;
|
| 63 |
+
error: string;
|
| 64 |
+
input: never;
|
| 65 |
+
edit: never;
|
| 66 |
+
drag: never;
|
| 67 |
+
apply: never;
|
| 68 |
+
upload: never;
|
| 69 |
+
clear: never;
|
| 70 |
+
select: SelectData;
|
| 71 |
+
share: ShareData;
|
| 72 |
+
clear_status: LoadingStatus;
|
| 73 |
+
}>;
|
| 74 |
+
|
| 75 |
+
let editor_instance: InteractiveImageEditor;
|
| 76 |
+
let image_id: null | string = null;
|
| 77 |
+
|
| 78 |
+
export async function get_value(): Promise<ImageBlobs | { id: string }> {
|
| 79 |
+
if (image_id) {
|
| 80 |
+
const val = { id: image_id };
|
| 81 |
+
image_id = null;
|
| 82 |
+
return val;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
const blobs = await editor_instance.get_data();
|
| 86 |
+
|
| 87 |
+
return blobs;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
let dragging: boolean;
|
| 91 |
+
|
| 92 |
+
$: value && handle_change();
|
| 93 |
+
const is_browser = typeof window !== "undefined";
|
| 94 |
+
const raf = is_browser
|
| 95 |
+
? window.requestAnimationFrame
|
| 96 |
+
: (cb: (...args: any[]) => void) => cb();
|
| 97 |
+
|
| 98 |
+
function wait_for_next_frame(): Promise<void> {
|
| 99 |
+
return new Promise((resolve) => {
|
| 100 |
+
raf(() => raf(() => resolve()));
|
| 101 |
+
});
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
async function handle_change(): Promise<void> {
|
| 105 |
+
await wait_for_next_frame();
|
| 106 |
+
|
| 107 |
+
if (
|
| 108 |
+
value &&
|
| 109 |
+
(value.background || value.layers?.length || value.composite)
|
| 110 |
+
) {
|
| 111 |
+
gradio.dispatch("change");
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
function handle_save(): void {
|
| 116 |
+
gradio.dispatch("apply");
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
function handle_history_change(): void {
|
| 120 |
+
gradio.dispatch("change");
|
| 121 |
+
if (!value_is_output) {
|
| 122 |
+
gradio.dispatch("input");
|
| 123 |
+
tick().then((_) => (value_is_output = false));
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
$: has_value = value?.background || value?.layers?.length || value?.composite;
|
| 128 |
+
</script>
|
| 129 |
+
|
| 130 |
+
{#if !interactive}
|
| 131 |
+
<Block
|
| 132 |
+
{visible}
|
| 133 |
+
variant={"solid"}
|
| 134 |
+
border_mode={dragging ? "focus" : "base"}
|
| 135 |
+
padding={false}
|
| 136 |
+
{elem_id}
|
| 137 |
+
{elem_classes}
|
| 138 |
+
height={height || undefined}
|
| 139 |
+
{width}
|
| 140 |
+
allow_overflow={false}
|
| 141 |
+
{container}
|
| 142 |
+
{scale}
|
| 143 |
+
{min_width}
|
| 144 |
+
>
|
| 145 |
+
<StatusTracker
|
| 146 |
+
autoscroll={gradio.autoscroll}
|
| 147 |
+
i18n={gradio.i18n}
|
| 148 |
+
{...loading_status}
|
| 149 |
+
on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
|
| 150 |
+
/>
|
| 151 |
+
<StaticImage
|
| 152 |
+
on:select={({ detail }) => gradio.dispatch("select", detail)}
|
| 153 |
+
on:share={({ detail }) => gradio.dispatch("share", detail)}
|
| 154 |
+
on:error={({ detail }) => gradio.dispatch("error", detail)}
|
| 155 |
+
value={value?.composite || null}
|
| 156 |
+
{label}
|
| 157 |
+
{show_label}
|
| 158 |
+
{show_download_button}
|
| 159 |
+
selectable={_selectable}
|
| 160 |
+
{show_share_button}
|
| 161 |
+
i18n={gradio.i18n}
|
| 162 |
+
{show_fullscreen_button}
|
| 163 |
+
/>
|
| 164 |
+
</Block>
|
| 165 |
+
{:else}
|
| 166 |
+
<Block
|
| 167 |
+
{visible}
|
| 168 |
+
variant={has_value ? "solid" : "dashed"}
|
| 169 |
+
border_mode={dragging ? "focus" : "base"}
|
| 170 |
+
padding={false}
|
| 171 |
+
{elem_id}
|
| 172 |
+
{elem_classes}
|
| 173 |
+
height={height || undefined}
|
| 174 |
+
{width}
|
| 175 |
+
allow_overflow={false}
|
| 176 |
+
{container}
|
| 177 |
+
{scale}
|
| 178 |
+
{min_width}
|
| 179 |
+
>
|
| 180 |
+
<StatusTracker
|
| 181 |
+
autoscroll={gradio.autoscroll}
|
| 182 |
+
i18n={gradio.i18n}
|
| 183 |
+
{...loading_status}
|
| 184 |
+
on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
|
| 185 |
+
/>
|
| 186 |
+
|
| 187 |
+
<InteractiveImageEditor
|
| 188 |
+
bind:dragging
|
| 189 |
+
{canvas_size}
|
| 190 |
+
on:change={() => handle_history_change()}
|
| 191 |
+
bind:image_id
|
| 192 |
+
{crop_size}
|
| 193 |
+
{value}
|
| 194 |
+
bind:this={editor_instance}
|
| 195 |
+
{root}
|
| 196 |
+
{sources}
|
| 197 |
+
{label}
|
| 198 |
+
{show_label}
|
| 199 |
+
{height}
|
| 200 |
+
on:save={(e) => handle_save()}
|
| 201 |
+
on:edit={() => gradio.dispatch("edit")}
|
| 202 |
+
on:clear={() => gradio.dispatch("clear")}
|
| 203 |
+
on:drag={({ detail }) => (dragging = detail)}
|
| 204 |
+
on:upload={() => gradio.dispatch("upload")}
|
| 205 |
+
on:share={({ detail }) => gradio.dispatch("share", detail)}
|
| 206 |
+
on:error={({ detail }) => {
|
| 207 |
+
loading_status = loading_status || {};
|
| 208 |
+
loading_status.status = "error";
|
| 209 |
+
gradio.dispatch("error", detail);
|
| 210 |
+
}}
|
| 211 |
+
on:error
|
| 212 |
+
{brush}
|
| 213 |
+
{eraser}
|
| 214 |
+
changeable={attached_events.includes("apply")}
|
| 215 |
+
realtime={attached_events.includes("change")}
|
| 216 |
+
i18n={gradio.i18n}
|
| 217 |
+
{transforms}
|
| 218 |
+
accept_blobs={server.accept_blobs}
|
| 219 |
+
{layers}
|
| 220 |
+
status={loading_status?.status}
|
| 221 |
+
upload={(...args) => gradio.client.upload(...args)}
|
| 222 |
+
stream_handler={(...args) => gradio.client.stream(...args)}
|
| 223 |
+
{placeholder}
|
| 224 |
+
></InteractiveImageEditor>
|
| 225 |
+
</Block>
|
| 226 |
+
{/if}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@gradio/imageeditor",
|
| 3 |
+
"version": "0.11.2",
|
| 4 |
+
"description": "Gradio UI packages",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"author": "",
|
| 7 |
+
"license": "ISC",
|
| 8 |
+
"private": false,
|
| 9 |
+
"dependencies": {
|
| 10 |
+
"@gradio/atoms": "workspace:^",
|
| 11 |
+
"@gradio/client": "workspace:^",
|
| 12 |
+
"@gradio/icons": "workspace:^",
|
| 13 |
+
"@gradio/image": "workspace:^",
|
| 14 |
+
"@gradio/statustracker": "workspace:^",
|
| 15 |
+
"@gradio/upload": "workspace:^",
|
| 16 |
+
"@gradio/utils": "workspace:^",
|
| 17 |
+
"@gradio/wasm": "workspace:^",
|
| 18 |
+
"@types/tinycolor2": "^1.4.6",
|
| 19 |
+
"pixi.js": "^7.3.2",
|
| 20 |
+
"tinycolor2": "^1.6.0"
|
| 21 |
+
},
|
| 22 |
+
"devDependencies": {
|
| 23 |
+
"@gradio/preview": "workspace:^"
|
| 24 |
+
},
|
| 25 |
+
"main_changeset": true,
|
| 26 |
+
"main": "./Index.svelte",
|
| 27 |
+
"exports": {
|
| 28 |
+
".": {
|
| 29 |
+
"gradio": "./Index.svelte",
|
| 30 |
+
"svelte": "./dist/Index.svelte",
|
| 31 |
+
"types": "./dist/Index.svelte.d.ts"
|
| 32 |
+
},
|
| 33 |
+
"./example": {
|
| 34 |
+
"gradio": "./Example.svelte",
|
| 35 |
+
"svelte": "./dist/Example.svelte",
|
| 36 |
+
"types": "./dist/Example.svelte.d.ts"
|
| 37 |
+
},
|
| 38 |
+
"./package.json": "./package.json"
|
| 39 |
+
},
|
| 40 |
+
"peerDependencies": {
|
| 41 |
+
"svelte": "^4.0.0"
|
| 42 |
+
},
|
| 43 |
+
"repository": {
|
| 44 |
+
"type": "git",
|
| 45 |
+
"url": "git+https://github.com/gradio-app/gradio.git",
|
| 46 |
+
"directory": "js/imageeditor"
|
| 47 |
+
}
|
| 48 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/Controls.svelte
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { createEventDispatcher } from "svelte";
|
| 3 |
+
import { IconButton, IconButtonWrapper } from "@gradio/atoms";
|
| 4 |
+
import { Undo, Redo, Check, Trash } from "@gradio/icons";
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Can the current image be undone?
|
| 8 |
+
*/
|
| 9 |
+
export let can_undo = false;
|
| 10 |
+
/**
|
| 11 |
+
* Can the current image be redone?
|
| 12 |
+
*/
|
| 13 |
+
export let can_redo = false;
|
| 14 |
+
|
| 15 |
+
export let can_save = false;
|
| 16 |
+
export let changeable = false;
|
| 17 |
+
|
| 18 |
+
const dispatch = createEventDispatcher<{
|
| 19 |
+
/**
|
| 20 |
+
* Remove the current image.
|
| 21 |
+
*/
|
| 22 |
+
remove_image: void;
|
| 23 |
+
/**
|
| 24 |
+
* Undo the last action.
|
| 25 |
+
*/
|
| 26 |
+
undo: void;
|
| 27 |
+
/**
|
| 28 |
+
* Redo the last action.
|
| 29 |
+
*/
|
| 30 |
+
redo: void;
|
| 31 |
+
/**
|
| 32 |
+
* Save the current image.
|
| 33 |
+
*/
|
| 34 |
+
save: void;
|
| 35 |
+
}>();
|
| 36 |
+
</script>
|
| 37 |
+
|
| 38 |
+
<IconButtonWrapper>
|
| 39 |
+
{#if changeable}
|
| 40 |
+
<IconButton
|
| 41 |
+
disabled={!can_save}
|
| 42 |
+
Icon={Check}
|
| 43 |
+
label="Save changes"
|
| 44 |
+
on:click={(event) => {
|
| 45 |
+
dispatch("save");
|
| 46 |
+
event.stopPropagation();
|
| 47 |
+
}}
|
| 48 |
+
background={"var(--color-green-500)"}
|
| 49 |
+
color={"#fff"}
|
| 50 |
+
/>
|
| 51 |
+
{/if}
|
| 52 |
+
<IconButton
|
| 53 |
+
disabled={!can_undo}
|
| 54 |
+
Icon={Undo}
|
| 55 |
+
label="Undo"
|
| 56 |
+
on:click={(event) => {
|
| 57 |
+
dispatch("undo");
|
| 58 |
+
event.stopPropagation();
|
| 59 |
+
}}
|
| 60 |
+
/>
|
| 61 |
+
<IconButton
|
| 62 |
+
disabled={!can_redo}
|
| 63 |
+
Icon={Redo}
|
| 64 |
+
label="Redo"
|
| 65 |
+
on:click={(event) => {
|
| 66 |
+
dispatch("redo");
|
| 67 |
+
event.stopPropagation();
|
| 68 |
+
}}
|
| 69 |
+
/>
|
| 70 |
+
<IconButton
|
| 71 |
+
Icon={Trash}
|
| 72 |
+
label="Clear canvas"
|
| 73 |
+
on:click={(event) => {
|
| 74 |
+
dispatch("remove_image");
|
| 75 |
+
event.stopPropagation();
|
| 76 |
+
}}
|
| 77 |
+
/>
|
| 78 |
+
</IconButtonWrapper>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/ImageEditor.svelte
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts" context="module">
|
| 2 |
+
import type { Writable, Readable } from "svelte/store";
|
| 3 |
+
import type { Spring } from "svelte/motion";
|
| 4 |
+
import { type PixiApp } from "./utils/pixi";
|
| 5 |
+
import { type CommandManager } from "./utils/commands";
|
| 6 |
+
|
| 7 |
+
export const EDITOR_KEY = Symbol("editor");
|
| 8 |
+
export type context_type = "bg" | "layers" | "crop" | "draw" | "erase";
|
| 9 |
+
type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
|
| 10 |
+
import { type tool } from "./tools";
|
| 11 |
+
|
| 12 |
+
export interface EditorContext {
|
| 13 |
+
pixi: Writable<PixiApp | null>;
|
| 14 |
+
current_layer: Writable<LayerScene | null>;
|
| 15 |
+
dimensions: Writable<[number, number]>;
|
| 16 |
+
editor_box: Writable<{
|
| 17 |
+
parent_width: number;
|
| 18 |
+
parent_height: number;
|
| 19 |
+
parent_left: number;
|
| 20 |
+
parent_top: number;
|
| 21 |
+
parent_right: number;
|
| 22 |
+
parent_bottom: number;
|
| 23 |
+
child_width: number;
|
| 24 |
+
child_height: number;
|
| 25 |
+
child_left: number;
|
| 26 |
+
child_top: number;
|
| 27 |
+
child_right: number;
|
| 28 |
+
child_bottom: number;
|
| 29 |
+
}>;
|
| 30 |
+
active_tool: Writable<tool>;
|
| 31 |
+
toolbar_box: Writable<DOMRect | Record<string, never>>;
|
| 32 |
+
crop: Writable<[number, number, number, number]>;
|
| 33 |
+
position_spring: Spring<{
|
| 34 |
+
x: number;
|
| 35 |
+
y: number;
|
| 36 |
+
}>;
|
| 37 |
+
command_manager: CommandManager;
|
| 38 |
+
current_history: CommandManager["current_history"];
|
| 39 |
+
register_context: (
|
| 40 |
+
type: context_type,
|
| 41 |
+
{
|
| 42 |
+
reset_fn,
|
| 43 |
+
init_fn
|
| 44 |
+
}: {
|
| 45 |
+
reset_fn?: () => void;
|
| 46 |
+
init_fn?: (dimensions?: [number, number]) => void;
|
| 47 |
+
}
|
| 48 |
+
) => void;
|
| 49 |
+
reset: (clear_image: boolean, dimensions: [number, number]) => void;
|
| 50 |
+
}
|
| 51 |
+
</script>
|
| 52 |
+
|
| 53 |
+
<script lang="ts">
|
| 54 |
+
import { onMount, setContext, createEventDispatcher, tick } from "svelte";
|
| 55 |
+
import { writable } from "svelte/store";
|
| 56 |
+
import { spring } from "svelte/motion";
|
| 57 |
+
import { Rectangle } from "pixi.js";
|
| 58 |
+
|
| 59 |
+
import { command_manager } from "./utils/commands";
|
| 60 |
+
|
| 61 |
+
import { type LayerScene } from "./layers/utils";
|
| 62 |
+
import { create_pixi_app, type ImageBlobs } from "./utils/pixi";
|
| 63 |
+
import Controls from "./Controls.svelte";
|
| 64 |
+
export let antialias = true;
|
| 65 |
+
export let crop_size: [number, number] | undefined;
|
| 66 |
+
export let changeable = false;
|
| 67 |
+
export let history: boolean;
|
| 68 |
+
export let bg = false;
|
| 69 |
+
export let sources: ("clipboard" | "webcam" | "upload")[];
|
| 70 |
+
const dispatch = createEventDispatcher<{
|
| 71 |
+
clear?: never;
|
| 72 |
+
save: void;
|
| 73 |
+
change: void;
|
| 74 |
+
}>();
|
| 75 |
+
export let crop_constraint = false;
|
| 76 |
+
export let canvas_size: [number, number] | undefined;
|
| 77 |
+
export let parent_height: number;
|
| 78 |
+
|
| 79 |
+
$: orig_canvas_size = canvas_size;
|
| 80 |
+
|
| 81 |
+
const BASE_DIMENSIONS: [number, number] = canvas_size || [800, 600];
|
| 82 |
+
|
| 83 |
+
let dimensions = writable(BASE_DIMENSIONS);
|
| 84 |
+
export let height = 0;
|
| 85 |
+
|
| 86 |
+
let editor_box: EditorContext["editor_box"] = writable({
|
| 87 |
+
parent_width: 0,
|
| 88 |
+
parent_height: parent_height,
|
| 89 |
+
parent_top: 0,
|
| 90 |
+
parent_left: 0,
|
| 91 |
+
parent_right: 0,
|
| 92 |
+
parent_bottom: 0,
|
| 93 |
+
child_width: 0,
|
| 94 |
+
child_height: parent_height,
|
| 95 |
+
child_top: 0,
|
| 96 |
+
child_left: 0,
|
| 97 |
+
child_right: 0,
|
| 98 |
+
child_bottom: 0
|
| 99 |
+
});
|
| 100 |
+
|
| 101 |
+
$: height = $editor_box.child_height;
|
| 102 |
+
|
| 103 |
+
const crop = writable<[number, number, number, number]>([0, 0, 1, 1]);
|
| 104 |
+
const position_spring = spring(
|
| 105 |
+
{ x: 0, y: 0 },
|
| 106 |
+
{
|
| 107 |
+
stiffness: 0.1,
|
| 108 |
+
damping: 0.5
|
| 109 |
+
}
|
| 110 |
+
);
|
| 111 |
+
const pixi = writable<PixiApp | null>(null);
|
| 112 |
+
|
| 113 |
+
const CommandManager = command_manager();
|
| 114 |
+
|
| 115 |
+
const { can_redo, can_undo, current_history } = CommandManager;
|
| 116 |
+
|
| 117 |
+
$: $current_history.previous, dispatch("change");
|
| 118 |
+
|
| 119 |
+
$: {
|
| 120 |
+
history = !!$current_history.previous || $active_tool !== "bg";
|
| 121 |
+
}
|
| 122 |
+
const is_browser = typeof window !== "undefined";
|
| 123 |
+
|
| 124 |
+
const active_tool: Writable<tool> = writable("bg");
|
| 125 |
+
const reset_context: Writable<PartialRecord<context_type, () => void>> =
|
| 126 |
+
writable({});
|
| 127 |
+
const init_context: Writable<
|
| 128 |
+
PartialRecord<context_type, (dimensions?: typeof $dimensions) => void>
|
| 129 |
+
> = writable({});
|
| 130 |
+
const contexts: Writable<context_type[]> = writable([]);
|
| 131 |
+
const toolbar_box: Writable<DOMRect | Record<string, never>> = writable(
|
| 132 |
+
is_browser ? new DOMRect() : {}
|
| 133 |
+
);
|
| 134 |
+
|
| 135 |
+
const sort_order = ["bg", "layers", "crop", "draw", "erase"] as const;
|
| 136 |
+
const editor_context = setContext<EditorContext>(EDITOR_KEY, {
|
| 137 |
+
pixi,
|
| 138 |
+
current_layer: writable(null),
|
| 139 |
+
dimensions,
|
| 140 |
+
editor_box,
|
| 141 |
+
toolbar_box,
|
| 142 |
+
active_tool,
|
| 143 |
+
crop,
|
| 144 |
+
position_spring,
|
| 145 |
+
command_manager: CommandManager,
|
| 146 |
+
current_history,
|
| 147 |
+
register_context: (
|
| 148 |
+
type: context_type,
|
| 149 |
+
{
|
| 150 |
+
reset_fn,
|
| 151 |
+
init_fn
|
| 152 |
+
}: {
|
| 153 |
+
reset_fn?: () => void;
|
| 154 |
+
init_fn?: (dimensions?: [number, number]) => void;
|
| 155 |
+
}
|
| 156 |
+
) => {
|
| 157 |
+
contexts.update((c) => [...c, type]);
|
| 158 |
+
init_context.update((c) => ({ ...c, [type]: init_fn }));
|
| 159 |
+
reset_context.update((c) => ({ ...c, [type]: reset_fn }));
|
| 160 |
+
},
|
| 161 |
+
reset: (clear_image: boolean, dimensions: [number, number]) => {
|
| 162 |
+
bg = false;
|
| 163 |
+
|
| 164 |
+
const _sorted_contexts = $contexts.sort((a, b) => {
|
| 165 |
+
return sort_order.indexOf(a) - sort_order.indexOf(b);
|
| 166 |
+
});
|
| 167 |
+
for (const k of _sorted_contexts) {
|
| 168 |
+
if (k in $reset_context && typeof $reset_context[k] === "function") {
|
| 169 |
+
$reset_context[k]?.();
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
for (const k of _sorted_contexts) {
|
| 174 |
+
if (k in $init_context && typeof $init_context[k] === "function") {
|
| 175 |
+
if (k === "bg" && !clear_image) {
|
| 176 |
+
continue;
|
| 177 |
+
} else {
|
| 178 |
+
$init_context[k]?.(dimensions);
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
CommandManager.reset();
|
| 182 |
+
$pixi?.resize?.(...dimensions);
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
});
|
| 186 |
+
|
| 187 |
+
let pixi_target: HTMLDivElement;
|
| 188 |
+
|
| 189 |
+
let canvas_wrap: HTMLDivElement;
|
| 190 |
+
|
| 191 |
+
function get_dimensions(parent: HTMLDivElement, child: HTMLDivElement): void {
|
| 192 |
+
if (!parent || !child) return;
|
| 193 |
+
const {
|
| 194 |
+
width: parent_width,
|
| 195 |
+
height: parent_height,
|
| 196 |
+
top: parent_top,
|
| 197 |
+
left: parent_left,
|
| 198 |
+
right: parent_right,
|
| 199 |
+
bottom: parent_bottom
|
| 200 |
+
} = canvas_wrap.getBoundingClientRect();
|
| 201 |
+
const {
|
| 202 |
+
width: child_width,
|
| 203 |
+
height: child_height,
|
| 204 |
+
top: child_top,
|
| 205 |
+
left: child_left,
|
| 206 |
+
right: child_right,
|
| 207 |
+
bottom: child_bottom
|
| 208 |
+
} = child.getBoundingClientRect();
|
| 209 |
+
editor_box.set({
|
| 210 |
+
child_width,
|
| 211 |
+
child_height,
|
| 212 |
+
child_left,
|
| 213 |
+
child_right,
|
| 214 |
+
child_top,
|
| 215 |
+
child_bottom,
|
| 216 |
+
|
| 217 |
+
parent_width,
|
| 218 |
+
parent_height,
|
| 219 |
+
parent_left,
|
| 220 |
+
parent_right,
|
| 221 |
+
parent_top,
|
| 222 |
+
parent_bottom
|
| 223 |
+
});
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
$: if (crop_constraint && bg && !history) {
|
| 227 |
+
set_crop();
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
function set_crop(): void {
|
| 231 |
+
requestAnimationFrame(() => {
|
| 232 |
+
tick().then((v) => ($active_tool = "crop"));
|
| 233 |
+
});
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
function reposition_canvas(): void {
|
| 237 |
+
if (!$editor_box) return;
|
| 238 |
+
const [l, t, w, h] = $crop;
|
| 239 |
+
|
| 240 |
+
const cx = l * $editor_box.child_width;
|
| 241 |
+
const cy = t * $editor_box.child_height;
|
| 242 |
+
const cw = w * $editor_box.child_width;
|
| 243 |
+
const ch = h * $editor_box.child_height;
|
| 244 |
+
|
| 245 |
+
const x = 0.5 * $editor_box.child_width - cx - cw / 2;
|
| 246 |
+
const y = 0.5 * $editor_box.child_height - cy - ch / 2;
|
| 247 |
+
|
| 248 |
+
position_spring.set({ x, y });
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
export async function get_blobs(): Promise<ImageBlobs> {
|
| 252 |
+
if (!$pixi || !$pixi.get_layers)
|
| 253 |
+
return { background: null, layers: [], composite: null };
|
| 254 |
+
const [l, t, w, h] = $crop;
|
| 255 |
+
|
| 256 |
+
return $pixi?.get_blobs(
|
| 257 |
+
$pixi.get_layers(),
|
| 258 |
+
new Rectangle(
|
| 259 |
+
Math.round(l * $dimensions[0]),
|
| 260 |
+
Math.round(t * $dimensions[1]),
|
| 261 |
+
Math.round(w * $dimensions[0]),
|
| 262 |
+
Math.round(h * $dimensions[1])
|
| 263 |
+
),
|
| 264 |
+
$dimensions
|
| 265 |
+
);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
$: $crop && reposition_canvas();
|
| 269 |
+
$: $position_spring && get_dimensions(canvas_wrap, pixi_target);
|
| 270 |
+
|
| 271 |
+
export function handle_remove(): void {
|
| 272 |
+
editor_context.reset(
|
| 273 |
+
true,
|
| 274 |
+
orig_canvas_size ? orig_canvas_size : $dimensions
|
| 275 |
+
);
|
| 276 |
+
if (!sources.length) {
|
| 277 |
+
set_tool("draw");
|
| 278 |
+
} else {
|
| 279 |
+
set_tool("bg");
|
| 280 |
+
}
|
| 281 |
+
dispatch("clear");
|
| 282 |
+
|
| 283 |
+
let _size = (canvas_size ? canvas_size : crop_size) || [800, 600];
|
| 284 |
+
editor_context.reset(true, _size);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
onMount(() => {
|
| 288 |
+
const _size = (canvas_size ? canvas_size : crop_size) || [800, 600];
|
| 289 |
+
const app = create_pixi_app({
|
| 290 |
+
target: pixi_target,
|
| 291 |
+
dimensions: _size,
|
| 292 |
+
antialias
|
| 293 |
+
});
|
| 294 |
+
|
| 295 |
+
function resize(width: number, height: number): void {
|
| 296 |
+
app.resize(width, height);
|
| 297 |
+
dimensions.set([width, height]);
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
pixi.set({ ...app, resize });
|
| 301 |
+
|
| 302 |
+
const resizer = new ResizeObserver((entries) => {
|
| 303 |
+
for (const entry of entries) {
|
| 304 |
+
get_dimensions(canvas_wrap, pixi_target);
|
| 305 |
+
}
|
| 306 |
+
});
|
| 307 |
+
|
| 308 |
+
resizer.observe(canvas_wrap);
|
| 309 |
+
resizer.observe(pixi_target);
|
| 310 |
+
|
| 311 |
+
for (const k of $contexts) {
|
| 312 |
+
if (k in $init_context && typeof $init_context[k] === "function") {
|
| 313 |
+
$init_context[k]?.($dimensions);
|
| 314 |
+
}
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
resize(...$dimensions);
|
| 318 |
+
|
| 319 |
+
return () => {
|
| 320 |
+
$pixi?.destroy();
|
| 321 |
+
resizer.disconnect();
|
| 322 |
+
for (const k of $contexts) {
|
| 323 |
+
if (k in $reset_context) {
|
| 324 |
+
$reset_context[k]?.();
|
| 325 |
+
}
|
| 326 |
+
}
|
| 327 |
+
};
|
| 328 |
+
});
|
| 329 |
+
|
| 330 |
+
let saved_history: null | typeof $current_history = $current_history;
|
| 331 |
+
|
| 332 |
+
function handle_save(): void {
|
| 333 |
+
saved_history = $current_history;
|
| 334 |
+
dispatch("save");
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
export function set_tool(tool: tool): void {
|
| 338 |
+
$active_tool = tool;
|
| 339 |
+
}
|
| 340 |
+
</script>
|
| 341 |
+
|
| 342 |
+
<svelte:window on:scroll={() => get_dimensions(canvas_wrap, pixi_target)} />
|
| 343 |
+
|
| 344 |
+
<div data-testid="image" class="image-container">
|
| 345 |
+
<Controls
|
| 346 |
+
can_undo={$can_undo}
|
| 347 |
+
can_redo={$can_redo}
|
| 348 |
+
can_save={saved_history !== $current_history}
|
| 349 |
+
{changeable}
|
| 350 |
+
on:undo={CommandManager.undo}
|
| 351 |
+
on:redo={CommandManager.redo}
|
| 352 |
+
on:remove_image={handle_remove}
|
| 353 |
+
on:save={handle_save}
|
| 354 |
+
/>
|
| 355 |
+
<div class="container">
|
| 356 |
+
<div class="wrap" bind:this={canvas_wrap}>
|
| 357 |
+
<div bind:this={pixi_target} class="stage-wrap" class:bg={!bg}></div>
|
| 358 |
+
</div>
|
| 359 |
+
<div class="tools-wrap">
|
| 360 |
+
<slot />
|
| 361 |
+
</div>
|
| 362 |
+
<div
|
| 363 |
+
class="canvas"
|
| 364 |
+
class:no-border={!bg && $active_tool === "bg" && !history}
|
| 365 |
+
style:width="{$crop[2] * $editor_box.child_width + 1}px"
|
| 366 |
+
style:height="{$crop[3] * $editor_box.child_height + 1}px"
|
| 367 |
+
style:top="{$crop[1] * $editor_box.child_height +
|
| 368 |
+
($editor_box.child_top - $editor_box.parent_top) -
|
| 369 |
+
0.5}px"
|
| 370 |
+
style:left="{$crop[0] * $editor_box.child_width +
|
| 371 |
+
($editor_box.child_left - $editor_box.parent_left) -
|
| 372 |
+
0.5}px"
|
| 373 |
+
></div>
|
| 374 |
+
</div>
|
| 375 |
+
</div>
|
| 376 |
+
|
| 377 |
+
<style>
|
| 378 |
+
.wrap {
|
| 379 |
+
display: flex;
|
| 380 |
+
width: 100%;
|
| 381 |
+
height: 100%;
|
| 382 |
+
position: relative;
|
| 383 |
+
justify-content: center;
|
| 384 |
+
}
|
| 385 |
+
.canvas {
|
| 386 |
+
position: absolute;
|
| 387 |
+
border: var(--block-border-color) 1px solid;
|
| 388 |
+
pointer-events: none;
|
| 389 |
+
border-radius: var(--radius-md);
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
.container {
|
| 393 |
+
position: relative;
|
| 394 |
+
margin: var(--spacing-md);
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
.no-border {
|
| 398 |
+
border: none;
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
.stage-wrap {
|
| 402 |
+
margin-bottom: var(--size-1);
|
| 403 |
+
border-radius: var(--radius-md);
|
| 404 |
+
overflow: hidden;
|
| 405 |
+
height: fit-content;
|
| 406 |
+
width: auto;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
.tools-wrap {
|
| 410 |
+
display: flex;
|
| 411 |
+
justify-content: center;
|
| 412 |
+
align-items: center;
|
| 413 |
+
padding: 0 var(--spacing-xl) 0 0;
|
| 414 |
+
border: 1px solid var(--block-border-color);
|
| 415 |
+
border-radius: var(--radius-sm);
|
| 416 |
+
margin: var(--spacing-xxl) 0 var(--spacing-xxl) 0;
|
| 417 |
+
width: fit-content;
|
| 418 |
+
margin: 0 auto;
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
.image-container {
|
| 422 |
+
display: flex;
|
| 423 |
+
height: 100%;
|
| 424 |
+
flex-direction: column;
|
| 425 |
+
justify-content: center;
|
| 426 |
+
align-items: center;
|
| 427 |
+
max-height: 100%;
|
| 428 |
+
}
|
| 429 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/InteractiveImageEditor.svelte
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts" context="module">
|
| 2 |
+
export interface EditorData {
|
| 3 |
+
background: FileData | null;
|
| 4 |
+
layers: FileData[] | null;
|
| 5 |
+
composite: FileData | null;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
export interface ImageBlobs {
|
| 9 |
+
background: FileData | null;
|
| 10 |
+
layers: FileData[];
|
| 11 |
+
composite: FileData | null;
|
| 12 |
+
}
|
| 13 |
+
</script>
|
| 14 |
+
|
| 15 |
+
<script lang="ts">
|
| 16 |
+
import { createEventDispatcher } from "svelte";
|
| 17 |
+
import { type I18nFormatter } from "@gradio/utils";
|
| 18 |
+
import { prepare_files, type FileData, type Client } from "@gradio/client";
|
| 19 |
+
|
| 20 |
+
import ImageEditor from "./ImageEditor.svelte";
|
| 21 |
+
import Layers from "./layers/Layers.svelte";
|
| 22 |
+
import { type Brush as IBrush } from "./tools/Brush.svelte";
|
| 23 |
+
import { type Eraser } from "./tools/Brush.svelte";
|
| 24 |
+
|
| 25 |
+
import { Tools, Crop, Brush, Sources } from "./tools";
|
| 26 |
+
import { BlockLabel } from "@gradio/atoms";
|
| 27 |
+
import { Image as ImageIcon } from "@gradio/icons";
|
| 28 |
+
import { inject } from "./utils/parse_placeholder";
|
| 29 |
+
|
| 30 |
+
export let brush: IBrush | null;
|
| 31 |
+
export let eraser: Eraser | null;
|
| 32 |
+
export let sources: ("clipboard" | "webcam" | "upload")[];
|
| 33 |
+
export let crop_size: [number, number] | `${string}:${string}` | null = null;
|
| 34 |
+
export let i18n: I18nFormatter;
|
| 35 |
+
export let root: string;
|
| 36 |
+
export let label: string | undefined = undefined;
|
| 37 |
+
export let show_label: boolean;
|
| 38 |
+
export let changeable = false;
|
| 39 |
+
export let value: EditorData | null = {
|
| 40 |
+
background: null,
|
| 41 |
+
layers: [],
|
| 42 |
+
composite: null
|
| 43 |
+
};
|
| 44 |
+
export let transforms: "crop"[] = ["crop"];
|
| 45 |
+
export let layers: boolean;
|
| 46 |
+
export let accept_blobs: (a: any) => void;
|
| 47 |
+
export let status:
|
| 48 |
+
| "pending"
|
| 49 |
+
| "complete"
|
| 50 |
+
| "error"
|
| 51 |
+
| "generating"
|
| 52 |
+
| "streaming" = "complete";
|
| 53 |
+
export let canvas_size: [number, number] | undefined;
|
| 54 |
+
export let realtime: boolean;
|
| 55 |
+
export let upload: Client["upload"];
|
| 56 |
+
export let stream_handler: Client["stream"];
|
| 57 |
+
export let dragging: boolean;
|
| 58 |
+
export let placeholder: string | undefined = undefined;
|
| 59 |
+
export let height = 450;
|
| 60 |
+
|
| 61 |
+
const dispatch = createEventDispatcher<{
|
| 62 |
+
clear?: never;
|
| 63 |
+
upload?: never;
|
| 64 |
+
change?: never;
|
| 65 |
+
}>();
|
| 66 |
+
|
| 67 |
+
let editor: ImageEditor;
|
| 68 |
+
|
| 69 |
+
function is_not_null(o: Blob | null): o is Blob {
|
| 70 |
+
return !!o;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function is_file_data(o: null | FileData): o is FileData {
|
| 74 |
+
return !!o;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
$: if (bg) dispatch("upload");
|
| 78 |
+
|
| 79 |
+
export async function get_data(): Promise<ImageBlobs> {
|
| 80 |
+
const blobs = await editor.get_blobs();
|
| 81 |
+
|
| 82 |
+
const bg = blobs.background
|
| 83 |
+
? upload(
|
| 84 |
+
await prepare_files([new File([blobs.background], "background.png")]),
|
| 85 |
+
root
|
| 86 |
+
)
|
| 87 |
+
: Promise.resolve(null);
|
| 88 |
+
|
| 89 |
+
const layers = blobs.layers
|
| 90 |
+
.filter(is_not_null)
|
| 91 |
+
.map(async (blob, i) =>
|
| 92 |
+
upload(await prepare_files([new File([blob], `layer_${i}.png`)]), root)
|
| 93 |
+
);
|
| 94 |
+
|
| 95 |
+
const composite = blobs.composite
|
| 96 |
+
? upload(
|
| 97 |
+
await prepare_files([new File([blobs.composite], "composite.png")]),
|
| 98 |
+
root
|
| 99 |
+
)
|
| 100 |
+
: Promise.resolve(null);
|
| 101 |
+
|
| 102 |
+
const [background, composite_, ...layers_] = await Promise.all([
|
| 103 |
+
bg,
|
| 104 |
+
composite,
|
| 105 |
+
...layers
|
| 106 |
+
]);
|
| 107 |
+
|
| 108 |
+
return {
|
| 109 |
+
background: Array.isArray(background) ? background[0] : background,
|
| 110 |
+
layers: layers_
|
| 111 |
+
.flatMap((layer) => (Array.isArray(layer) ? layer : [layer]))
|
| 112 |
+
.filter(is_file_data),
|
| 113 |
+
composite: Array.isArray(composite_) ? composite_[0] : composite_
|
| 114 |
+
};
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
function handle_value(value: EditorData | null): void {
|
| 118 |
+
if (!editor) return;
|
| 119 |
+
if (value == null) {
|
| 120 |
+
editor.handle_remove();
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
$: handle_value(value);
|
| 125 |
+
|
| 126 |
+
$: crop_constraint = crop_size;
|
| 127 |
+
let bg = false;
|
| 128 |
+
let history = false;
|
| 129 |
+
|
| 130 |
+
export let image_id: null | string = null;
|
| 131 |
+
|
| 132 |
+
$: editor &&
|
| 133 |
+
editor.set_tool &&
|
| 134 |
+
(sources && sources.length
|
| 135 |
+
? editor.set_tool("bg")
|
| 136 |
+
: editor.set_tool("draw"));
|
| 137 |
+
|
| 138 |
+
type BinaryImages = [string, string, File, number | null][];
|
| 139 |
+
|
| 140 |
+
function nextframe(): Promise<void> {
|
| 141 |
+
return new Promise((resolve) => setTimeout(() => resolve(), 30));
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
let uploading = false;
|
| 145 |
+
let pending = false;
|
| 146 |
+
async function handle_change(e: CustomEvent<Blob | any>): Promise<void> {
|
| 147 |
+
if (!realtime) return;
|
| 148 |
+
if (uploading) {
|
| 149 |
+
pending = true;
|
| 150 |
+
return;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
uploading = true;
|
| 154 |
+
|
| 155 |
+
await nextframe();
|
| 156 |
+
const blobs = await editor.get_blobs();
|
| 157 |
+
|
| 158 |
+
const images: BinaryImages = [];
|
| 159 |
+
|
| 160 |
+
let id = Math.random().toString(36).substring(2);
|
| 161 |
+
|
| 162 |
+
if (blobs.background)
|
| 163 |
+
images.push([
|
| 164 |
+
id,
|
| 165 |
+
"background",
|
| 166 |
+
new File([blobs.background], "background.png"),
|
| 167 |
+
null
|
| 168 |
+
]);
|
| 169 |
+
if (blobs.composite)
|
| 170 |
+
images.push([
|
| 171 |
+
id,
|
| 172 |
+
"composite",
|
| 173 |
+
new File([blobs.composite], "composite.png"),
|
| 174 |
+
null
|
| 175 |
+
]);
|
| 176 |
+
blobs.layers.forEach((layer, i) => {
|
| 177 |
+
if (layer)
|
| 178 |
+
images.push([
|
| 179 |
+
id as string,
|
| 180 |
+
`layer`,
|
| 181 |
+
new File([layer], `layer_${i}.png`),
|
| 182 |
+
i
|
| 183 |
+
]);
|
| 184 |
+
});
|
| 185 |
+
|
| 186 |
+
await Promise.all(
|
| 187 |
+
images.map(async ([image_id, type, data, index]) => {
|
| 188 |
+
return accept_blobs({
|
| 189 |
+
binary: true,
|
| 190 |
+
data: { file: data, id: image_id, type, index }
|
| 191 |
+
});
|
| 192 |
+
})
|
| 193 |
+
);
|
| 194 |
+
image_id = id;
|
| 195 |
+
dispatch("change");
|
| 196 |
+
|
| 197 |
+
await nextframe();
|
| 198 |
+
uploading = false;
|
| 199 |
+
if (pending) {
|
| 200 |
+
pending = false;
|
| 201 |
+
uploading = false;
|
| 202 |
+
handle_change(e);
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
let active_mode: "webcam" | "color" | null = null;
|
| 207 |
+
let editor_height = height - 100;
|
| 208 |
+
|
| 209 |
+
$: [heading, paragraph] = placeholder ? inject(placeholder) : [false, false];
|
| 210 |
+
</script>
|
| 211 |
+
|
| 212 |
+
<BlockLabel
|
| 213 |
+
{show_label}
|
| 214 |
+
Icon={ImageIcon}
|
| 215 |
+
label={label || i18n("image.image")}
|
| 216 |
+
/>
|
| 217 |
+
<ImageEditor
|
| 218 |
+
{canvas_size}
|
| 219 |
+
crop_size={Array.isArray(crop_size) ? crop_size : undefined}
|
| 220 |
+
bind:this={editor}
|
| 221 |
+
bind:height={editor_height}
|
| 222 |
+
parent_height={height}
|
| 223 |
+
{changeable}
|
| 224 |
+
on:save
|
| 225 |
+
on:change={handle_change}
|
| 226 |
+
on:clear={() => dispatch("clear")}
|
| 227 |
+
bind:history
|
| 228 |
+
bind:bg
|
| 229 |
+
{sources}
|
| 230 |
+
crop_constraint={!!crop_constraint}
|
| 231 |
+
>
|
| 232 |
+
<Tools {i18n}>
|
| 233 |
+
<Layers layer_files={value?.layers || null} enable_layers={layers} />
|
| 234 |
+
|
| 235 |
+
<Sources
|
| 236 |
+
bind:dragging
|
| 237 |
+
{i18n}
|
| 238 |
+
{root}
|
| 239 |
+
{sources}
|
| 240 |
+
{upload}
|
| 241 |
+
{stream_handler}
|
| 242 |
+
bind:bg
|
| 243 |
+
bind:active_mode
|
| 244 |
+
background_file={value?.background || value?.composite || null}
|
| 245 |
+
></Sources>
|
| 246 |
+
|
| 247 |
+
{#if transforms.includes("crop")}
|
| 248 |
+
<Crop {crop_constraint} />
|
| 249 |
+
{/if}
|
| 250 |
+
{#if brush}
|
| 251 |
+
<Brush
|
| 252 |
+
color_mode={brush.color_mode}
|
| 253 |
+
default_color={brush.default_color}
|
| 254 |
+
default_size={brush.default_size}
|
| 255 |
+
colors={brush.colors}
|
| 256 |
+
mode="draw"
|
| 257 |
+
/>
|
| 258 |
+
{/if}
|
| 259 |
+
|
| 260 |
+
{#if brush && eraser}
|
| 261 |
+
<Brush default_size={eraser.default_size} mode="erase" />
|
| 262 |
+
{/if}
|
| 263 |
+
</Tools>
|
| 264 |
+
|
| 265 |
+
{#if !bg && !history && active_mode !== "webcam" && status !== "error"}
|
| 266 |
+
<div class="empty wrap" style:height={`${editor_height}px`}>
|
| 267 |
+
{#if sources && sources.length}
|
| 268 |
+
{#if heading || paragraph}
|
| 269 |
+
{#if heading}
|
| 270 |
+
<h2>{heading}</h2>
|
| 271 |
+
{/if}
|
| 272 |
+
{#if paragraph}
|
| 273 |
+
<p>{paragraph}</p>
|
| 274 |
+
{/if}
|
| 275 |
+
{:else}
|
| 276 |
+
<div>Upload an image</div>
|
| 277 |
+
{/if}
|
| 278 |
+
{/if}
|
| 279 |
+
|
| 280 |
+
{#if sources && sources.length && brush && !placeholder}
|
| 281 |
+
<div class="or">or</div>
|
| 282 |
+
{/if}
|
| 283 |
+
{#if brush && !placeholder}
|
| 284 |
+
<div>select the draw tool to start</div>
|
| 285 |
+
{/if}
|
| 286 |
+
</div>
|
| 287 |
+
{/if}
|
| 288 |
+
</ImageEditor>
|
| 289 |
+
|
| 290 |
+
<style>
|
| 291 |
+
h2 {
|
| 292 |
+
font-size: var(--text-xl);
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
p,
|
| 296 |
+
h2 {
|
| 297 |
+
white-space: pre-line;
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
.empty {
|
| 301 |
+
display: flex;
|
| 302 |
+
flex-direction: column;
|
| 303 |
+
justify-content: center;
|
| 304 |
+
align-items: center;
|
| 305 |
+
position: absolute;
|
| 306 |
+
height: 100%;
|
| 307 |
+
width: 100%;
|
| 308 |
+
left: 0;
|
| 309 |
+
right: 0;
|
| 310 |
+
margin: auto;
|
| 311 |
+
z-index: var(--layer-top);
|
| 312 |
+
text-align: center;
|
| 313 |
+
color: var(--body-text-color);
|
| 314 |
+
top: var(--size-8);
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
.wrap {
|
| 318 |
+
display: flex;
|
| 319 |
+
flex-direction: column;
|
| 320 |
+
justify-content: center;
|
| 321 |
+
align-items: center;
|
| 322 |
+
color: var(--block-label-text-color);
|
| 323 |
+
line-height: var(--line-md);
|
| 324 |
+
font-size: var(--text-md);
|
| 325 |
+
pointer-events: none;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
.or {
|
| 329 |
+
color: var(--body-text-color-subdued);
|
| 330 |
+
}
|
| 331 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/layers/Layers.svelte
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { getContext, onMount, tick } from "svelte";
|
| 3 |
+
|
| 4 |
+
import { click_outside } from "../utils/events";
|
| 5 |
+
import { layer_manager, type LayerScene } from "./utils";
|
| 6 |
+
import { EDITOR_KEY, type EditorContext } from "../ImageEditor.svelte";
|
| 7 |
+
import type { FileData } from "@gradio/client";
|
| 8 |
+
import { Layers } from "@gradio/icons";
|
| 9 |
+
|
| 10 |
+
let show_layers = false;
|
| 11 |
+
|
| 12 |
+
export let layer_files: (FileData | null)[] | null = [];
|
| 13 |
+
export let enable_layers = true;
|
| 14 |
+
|
| 15 |
+
const { pixi, current_layer, dimensions, register_context } =
|
| 16 |
+
getContext<EditorContext>(EDITOR_KEY);
|
| 17 |
+
|
| 18 |
+
const LayerManager = layer_manager();
|
| 19 |
+
let layers: LayerScene[] = [];
|
| 20 |
+
|
| 21 |
+
register_context("layers", {
|
| 22 |
+
init_fn: () => {
|
| 23 |
+
new_layer();
|
| 24 |
+
},
|
| 25 |
+
reset_fn: () => {
|
| 26 |
+
LayerManager.reset();
|
| 27 |
+
}
|
| 28 |
+
});
|
| 29 |
+
|
| 30 |
+
async function validate_layers(): Promise<void> {
|
| 31 |
+
let invalid = layers.some(
|
| 32 |
+
(layer) =>
|
| 33 |
+
layer.composite.texture?.width != $dimensions[0] ||
|
| 34 |
+
layer.composite.texture?.height != $dimensions[1]
|
| 35 |
+
);
|
| 36 |
+
if (invalid) {
|
| 37 |
+
LayerManager.reset();
|
| 38 |
+
if (!layer_files || layer_files.length == 0) new_layer();
|
| 39 |
+
else render_layer_files(layer_files);
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
$: $dimensions, validate_layers();
|
| 43 |
+
|
| 44 |
+
async function new_layer(): Promise<void> {
|
| 45 |
+
if (!$pixi) return;
|
| 46 |
+
|
| 47 |
+
const [active_layer, all_layers] = LayerManager.add_layer(
|
| 48 |
+
$pixi.layer_container,
|
| 49 |
+
$pixi.renderer,
|
| 50 |
+
...$dimensions
|
| 51 |
+
);
|
| 52 |
+
|
| 53 |
+
$current_layer = active_layer;
|
| 54 |
+
layers = all_layers;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
$: render_layer_files(layer_files);
|
| 58 |
+
|
| 59 |
+
function is_not_null<T>(x: T | null): x is T {
|
| 60 |
+
return x !== null;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
async function render_layer_files(
|
| 64 |
+
_layer_files: typeof layer_files
|
| 65 |
+
): Promise<void> {
|
| 66 |
+
await tick();
|
| 67 |
+
if (!_layer_files || _layer_files.length == 0) {
|
| 68 |
+
LayerManager.reset();
|
| 69 |
+
new_layer();
|
| 70 |
+
return;
|
| 71 |
+
}
|
| 72 |
+
if (!$pixi) return;
|
| 73 |
+
|
| 74 |
+
const fetch_promises = await Promise.all(
|
| 75 |
+
_layer_files.map((f) => {
|
| 76 |
+
if (!f || !f.url) return null;
|
| 77 |
+
|
| 78 |
+
return fetch(f.url);
|
| 79 |
+
})
|
| 80 |
+
);
|
| 81 |
+
|
| 82 |
+
const blobs = await Promise.all(
|
| 83 |
+
fetch_promises.map((p) => {
|
| 84 |
+
if (!p) return null;
|
| 85 |
+
return p.blob();
|
| 86 |
+
})
|
| 87 |
+
);
|
| 88 |
+
|
| 89 |
+
LayerManager.reset();
|
| 90 |
+
|
| 91 |
+
let last_layer: [LayerScene, LayerScene[]] | null = null;
|
| 92 |
+
for (const blob of blobs.filter(is_not_null)) {
|
| 93 |
+
last_layer = await LayerManager.add_layer_from_blob(
|
| 94 |
+
$pixi.layer_container,
|
| 95 |
+
$pixi.renderer,
|
| 96 |
+
blob,
|
| 97 |
+
$pixi.view
|
| 98 |
+
);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
if (!last_layer) return;
|
| 102 |
+
|
| 103 |
+
$current_layer = last_layer[0];
|
| 104 |
+
layers = last_layer[1];
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
onMount(async () => {
|
| 108 |
+
await tick();
|
| 109 |
+
if (!$pixi) return;
|
| 110 |
+
|
| 111 |
+
$pixi = { ...$pixi!, get_layers: LayerManager.get_layers };
|
| 112 |
+
});
|
| 113 |
+
</script>
|
| 114 |
+
|
| 115 |
+
{#if enable_layers}
|
| 116 |
+
<div
|
| 117 |
+
class="layer-wrap"
|
| 118 |
+
class:closed={!show_layers}
|
| 119 |
+
use:click_outside={() => (show_layers = false)}
|
| 120 |
+
>
|
| 121 |
+
<button
|
| 122 |
+
aria-label="Show Layers"
|
| 123 |
+
on:click={() => (show_layers = !show_layers)}
|
| 124 |
+
><span class="icon"><Layers /></span> Layer {layers.findIndex(
|
| 125 |
+
(l) => l === $current_layer
|
| 126 |
+
) + 1}
|
| 127 |
+
</button>
|
| 128 |
+
{#if show_layers}
|
| 129 |
+
<ul>
|
| 130 |
+
{#each layers as layer, i (i)}
|
| 131 |
+
<li>
|
| 132 |
+
<button
|
| 133 |
+
class:selected_layer={$current_layer === layer}
|
| 134 |
+
on:click={() =>
|
| 135 |
+
($current_layer = LayerManager.change_active_layer(i))}
|
| 136 |
+
>Layer {i + 1}</button
|
| 137 |
+
>
|
| 138 |
+
</li>
|
| 139 |
+
{/each}
|
| 140 |
+
<li>
|
| 141 |
+
<button aria-label="Add Layer" on:click={new_layer}> +</button>
|
| 142 |
+
</li>
|
| 143 |
+
</ul>
|
| 144 |
+
{/if}
|
| 145 |
+
|
| 146 |
+
<span class="sep"></span>
|
| 147 |
+
</div>
|
| 148 |
+
{/if}
|
| 149 |
+
|
| 150 |
+
<style>
|
| 151 |
+
.icon {
|
| 152 |
+
width: 14px;
|
| 153 |
+
margin-right: var(--spacing-md);
|
| 154 |
+
color: var(--block-label-text-color);
|
| 155 |
+
margin-right: var(--spacing-lg);
|
| 156 |
+
margin-top: 1px;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
.layer-wrap {
|
| 160 |
+
position: relative;
|
| 161 |
+
display: flex;
|
| 162 |
+
justify-content: center;
|
| 163 |
+
align-items: center;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
.layer-wrap button {
|
| 167 |
+
justify-content: flex-start;
|
| 168 |
+
align-items: flex-start;
|
| 169 |
+
width: 100%;
|
| 170 |
+
border-bottom: 1px solid var(--block-border-color);
|
| 171 |
+
display: flex;
|
| 172 |
+
align-items: center;
|
| 173 |
+
justify-content: center;
|
| 174 |
+
font-size: var(--scale-000);
|
| 175 |
+
line-height: var(--line-sm);
|
| 176 |
+
padding-bottom: 1px;
|
| 177 |
+
margin-left: var(--spacing-xl);
|
| 178 |
+
padding: var(--spacing-sm) 0;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
.layer-wrap li:last-child button {
|
| 182 |
+
border-bottom: none;
|
| 183 |
+
text-align: center;
|
| 184 |
+
font-size: var(--scale-0);
|
| 185 |
+
line-height: 1;
|
| 186 |
+
font-weight: var(--weight-bold);
|
| 187 |
+
padding: 5px 0 1px 0;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
.closed > button {
|
| 191 |
+
border-bottom: none;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
.layer-wrap button:hover {
|
| 195 |
+
background-color: none;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
.layer-wrap button:hover .icon {
|
| 199 |
+
color: var(--color-accent);
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
.selected_layer {
|
| 203 |
+
background-color: var(--block-background-fill);
|
| 204 |
+
color: var(--color-accent);
|
| 205 |
+
font-weight: bold;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
ul {
|
| 209 |
+
position: absolute;
|
| 210 |
+
bottom: 0;
|
| 211 |
+
left: 0;
|
| 212 |
+
background: var(--block-background-fill);
|
| 213 |
+
width: calc(100% + 1px);
|
| 214 |
+
list-style: none;
|
| 215 |
+
z-index: var(--layer-top);
|
| 216 |
+
border: 1px solid var(--block-border-color);
|
| 217 |
+
padding: var(--spacing-sm) 0;
|
| 218 |
+
text-wrap: none;
|
| 219 |
+
transform: translate(-1px, 1px);
|
| 220 |
+
border-radius: var(--radius-sm);
|
| 221 |
+
border-bottom-right-radius: 0;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
.layer-wrap ul > li > button {
|
| 225 |
+
margin-left: 0;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
.sep {
|
| 229 |
+
height: 12px;
|
| 230 |
+
background-color: var(--block-border-color);
|
| 231 |
+
width: 1px;
|
| 232 |
+
display: block;
|
| 233 |
+
margin-left: var(--spacing-xl);
|
| 234 |
+
}
|
| 235 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/layers/utils.ts
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
Container,
|
| 3 |
+
type IRenderer,
|
| 4 |
+
type DisplayObject,
|
| 5 |
+
RenderTexture,
|
| 6 |
+
Texture,
|
| 7 |
+
Sprite,
|
| 8 |
+
Filter
|
| 9 |
+
} from "pixi.js";
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* GLSL Shader that takes two textures and erases the second texture from the first.
|
| 13 |
+
*/
|
| 14 |
+
export const erase_shader = `
|
| 15 |
+
precision highp float;
|
| 16 |
+
|
| 17 |
+
uniform sampler2D uDrawingTexture;
|
| 18 |
+
uniform sampler2D uEraserTexture;
|
| 19 |
+
|
| 20 |
+
varying vec2 vTextureCoord;
|
| 21 |
+
|
| 22 |
+
void main(void) {
|
| 23 |
+
vec4 drawingColor = texture2D(uDrawingTexture,vTextureCoord);
|
| 24 |
+
vec4 eraserColor = texture2D(uEraserTexture, vTextureCoord);
|
| 25 |
+
|
| 26 |
+
// Use the alpha of the eraser to determine how much to "erase" from the drawing
|
| 27 |
+
float alpha = 1.0 - eraserColor.a;
|
| 28 |
+
gl_FragColor = vec4(drawingColor.rgb * alpha, drawingColor.a * alpha);
|
| 29 |
+
}`;
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* Interface holding data for a layer
|
| 33 |
+
*/
|
| 34 |
+
export interface LayerScene {
|
| 35 |
+
/**
|
| 36 |
+
* The texture used for tracking brush strokes.
|
| 37 |
+
*/
|
| 38 |
+
draw_texture: RenderTexture;
|
| 39 |
+
/**
|
| 40 |
+
* The texture used for tracking eraser strokes.
|
| 41 |
+
*/
|
| 42 |
+
erase_texture: RenderTexture;
|
| 43 |
+
/**
|
| 44 |
+
* The sprite used for displaying the composite of the draw and erase textures.
|
| 45 |
+
*/
|
| 46 |
+
composite: Sprite;
|
| 47 |
+
/**
|
| 48 |
+
* The filter used for combining the draw and erase textures into a composite texture.
|
| 49 |
+
*/
|
| 50 |
+
filter?: Filter;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Interface for managing layers.
|
| 55 |
+
*/
|
| 56 |
+
interface LayerManager {
|
| 57 |
+
/**
|
| 58 |
+
* Adds a layer to the container.
|
| 59 |
+
* @param layer The container to add the layer to.
|
| 60 |
+
* @param renderer The renderer to use for the layer.
|
| 61 |
+
* @param width the width of the layer
|
| 62 |
+
* @param height the height of the layer
|
| 63 |
+
*/
|
| 64 |
+
add_layer(
|
| 65 |
+
container: Container,
|
| 66 |
+
renderer: IRenderer,
|
| 67 |
+
width: number,
|
| 68 |
+
height: number
|
| 69 |
+
): [LayerScene, LayerScene[]];
|
| 70 |
+
/**
|
| 71 |
+
* Swaps the layer with the layer above or below it.
|
| 72 |
+
* @param layer The index layer to swap.
|
| 73 |
+
* @param direction The direction to swap the layer.
|
| 74 |
+
*/
|
| 75 |
+
swap_layers(layer: number, direction: "up" | "down"): LayerScene;
|
| 76 |
+
/**
|
| 77 |
+
* Changes the active layer.
|
| 78 |
+
* @param layer The index of the layer to make active.
|
| 79 |
+
*/
|
| 80 |
+
change_active_layer(layer: number): LayerScene;
|
| 81 |
+
/**
|
| 82 |
+
* Resizes the layers.
|
| 83 |
+
* @param width The new width of the layers.
|
| 84 |
+
* @param height The new height of the layers.
|
| 85 |
+
*/
|
| 86 |
+
reset(): void;
|
| 87 |
+
/**
|
| 88 |
+
* Gets the layers.
|
| 89 |
+
* @returns The layers.
|
| 90 |
+
*/
|
| 91 |
+
get_layers(): LayerScene[];
|
| 92 |
+
|
| 93 |
+
add_layer_from_blob(
|
| 94 |
+
container: Container,
|
| 95 |
+
renderer: IRenderer,
|
| 96 |
+
blob: Blob,
|
| 97 |
+
view: HTMLCanvasElement
|
| 98 |
+
): Promise<[LayerScene, LayerScene[]]>;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/**
|
| 102 |
+
* Swaps two adjacent elements in an array.
|
| 103 |
+
* @param array The array to swap elements in.
|
| 104 |
+
* @param index The index of the first element to swap.
|
| 105 |
+
*/
|
| 106 |
+
function swap_adjacent(array: any[], index: number): void {
|
| 107 |
+
if (index < 0 || index >= array.length - 1) {
|
| 108 |
+
throw new Error("Index out of bounds");
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
[array[index], array[index + 1]] = [array[index + 1], array[index]];
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* Creates a layer manager.
|
| 116 |
+
* @param canvas_resize a function to resize the canvas
|
| 117 |
+
* @returns a layer manager
|
| 118 |
+
*/
|
| 119 |
+
export function layer_manager(): LayerManager {
|
| 120 |
+
let _layers: LayerScene[] = [];
|
| 121 |
+
let current_layer = 0;
|
| 122 |
+
let position = 0;
|
| 123 |
+
|
| 124 |
+
return {
|
| 125 |
+
add_layer: function (
|
| 126 |
+
container: Container,
|
| 127 |
+
renderer: IRenderer,
|
| 128 |
+
width: number,
|
| 129 |
+
height: number
|
| 130 |
+
): [LayerScene, LayerScene[]] {
|
| 131 |
+
const layer_container = new Container() as Container & DisplayObject;
|
| 132 |
+
position++;
|
| 133 |
+
layer_container.zIndex = position;
|
| 134 |
+
|
| 135 |
+
const composite_texture = RenderTexture.create({
|
| 136 |
+
width,
|
| 137 |
+
height
|
| 138 |
+
});
|
| 139 |
+
|
| 140 |
+
const composite = new Sprite(composite_texture) as Sprite & DisplayObject;
|
| 141 |
+
|
| 142 |
+
layer_container.addChild(composite);
|
| 143 |
+
|
| 144 |
+
composite.zIndex = position;
|
| 145 |
+
|
| 146 |
+
const layer_scene: LayerScene = {
|
| 147 |
+
draw_texture: RenderTexture.create({
|
| 148 |
+
width,
|
| 149 |
+
height
|
| 150 |
+
}),
|
| 151 |
+
erase_texture: RenderTexture.create({
|
| 152 |
+
width,
|
| 153 |
+
height
|
| 154 |
+
}),
|
| 155 |
+
composite
|
| 156 |
+
};
|
| 157 |
+
|
| 158 |
+
const erase_filter = new Filter(undefined, erase_shader, {
|
| 159 |
+
uEraserTexture: layer_scene.erase_texture,
|
| 160 |
+
uDrawingTexture: layer_scene.draw_texture
|
| 161 |
+
});
|
| 162 |
+
|
| 163 |
+
composite.filters = [erase_filter];
|
| 164 |
+
|
| 165 |
+
container.addChild(layer_container);
|
| 166 |
+
|
| 167 |
+
_layers.push(layer_scene);
|
| 168 |
+
|
| 169 |
+
return [layer_scene, _layers];
|
| 170 |
+
},
|
| 171 |
+
|
| 172 |
+
swap_layers: function (
|
| 173 |
+
layer: number,
|
| 174 |
+
direction: "up" | "down"
|
| 175 |
+
): LayerScene {
|
| 176 |
+
if (direction === "up") {
|
| 177 |
+
swap_adjacent(_layers, layer);
|
| 178 |
+
} else {
|
| 179 |
+
swap_adjacent(_layers, layer - 1);
|
| 180 |
+
}
|
| 181 |
+
return _layers[layer];
|
| 182 |
+
},
|
| 183 |
+
|
| 184 |
+
change_active_layer: function (layer: number): LayerScene {
|
| 185 |
+
current_layer = layer;
|
| 186 |
+
return _layers[layer];
|
| 187 |
+
},
|
| 188 |
+
reset() {
|
| 189 |
+
_layers.forEach((layer) => {
|
| 190 |
+
layer.draw_texture.destroy(true);
|
| 191 |
+
layer.erase_texture.destroy(true);
|
| 192 |
+
layer.composite.destroy(true);
|
| 193 |
+
});
|
| 194 |
+
_layers = [];
|
| 195 |
+
current_layer = 0;
|
| 196 |
+
position = 0;
|
| 197 |
+
},
|
| 198 |
+
async add_layer_from_blob(
|
| 199 |
+
container: Container,
|
| 200 |
+
renderer: IRenderer,
|
| 201 |
+
blob: Blob,
|
| 202 |
+
view: HTMLCanvasElement
|
| 203 |
+
) {
|
| 204 |
+
const img = await createImageBitmap(blob);
|
| 205 |
+
const bitmap_texture = Texture.from(img);
|
| 206 |
+
|
| 207 |
+
const [w, h] = resize_to_fit(
|
| 208 |
+
bitmap_texture.width,
|
| 209 |
+
bitmap_texture.height,
|
| 210 |
+
view.width,
|
| 211 |
+
view.height
|
| 212 |
+
);
|
| 213 |
+
|
| 214 |
+
const sprite = new Sprite(bitmap_texture) as Sprite & DisplayObject;
|
| 215 |
+
sprite.zIndex = 0;
|
| 216 |
+
|
| 217 |
+
sprite.width = w;
|
| 218 |
+
sprite.height = h;
|
| 219 |
+
|
| 220 |
+
const [layer, layers] = this.add_layer(
|
| 221 |
+
container,
|
| 222 |
+
renderer,
|
| 223 |
+
view.width,
|
| 224 |
+
view.height
|
| 225 |
+
);
|
| 226 |
+
|
| 227 |
+
renderer.render(sprite, {
|
| 228 |
+
renderTexture: layer.draw_texture
|
| 229 |
+
});
|
| 230 |
+
|
| 231 |
+
return [layer, layers];
|
| 232 |
+
},
|
| 233 |
+
get_layers() {
|
| 234 |
+
return _layers;
|
| 235 |
+
}
|
| 236 |
+
};
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
function resize_to_fit(
|
| 240 |
+
inner_width: number,
|
| 241 |
+
inner_height: number,
|
| 242 |
+
outer_width: number,
|
| 243 |
+
outer_height: number
|
| 244 |
+
): [number, number] {
|
| 245 |
+
if (inner_width <= outer_width && inner_height <= outer_height) {
|
| 246 |
+
return [inner_width, inner_height];
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
const inner_aspect = inner_width / inner_height;
|
| 250 |
+
const outer_aspect = outer_width / outer_height;
|
| 251 |
+
|
| 252 |
+
let new_width, new_height;
|
| 253 |
+
|
| 254 |
+
if (inner_aspect > outer_aspect) {
|
| 255 |
+
new_width = outer_width;
|
| 256 |
+
new_height = outer_width / inner_aspect;
|
| 257 |
+
} else {
|
| 258 |
+
new_height = outer_height;
|
| 259 |
+
new_width = outer_height * inner_aspect;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
return [new_width, new_height];
|
| 263 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/Brush.svelte
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts" context="module">
|
| 2 |
+
import { type ColorInput } from "tinycolor2";
|
| 3 |
+
|
| 4 |
+
export interface Eraser {
|
| 5 |
+
/**
|
| 6 |
+
* The default size of the eraser.
|
| 7 |
+
*/
|
| 8 |
+
default_size: number | "auto";
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
export interface Brush extends Eraser {
|
| 12 |
+
/**
|
| 13 |
+
* The default color of the brush.
|
| 14 |
+
*/
|
| 15 |
+
default_color: ColorInput;
|
| 16 |
+
/**
|
| 17 |
+
* The colors to show in the color swatch
|
| 18 |
+
*/
|
| 19 |
+
colors: ColorInput[];
|
| 20 |
+
/**
|
| 21 |
+
* Whether to show _only_ the color swatches specified in `colors`, or to show the color swatches specified in `colors` along with the colorpicker.
|
| 22 |
+
*/
|
| 23 |
+
color_mode: "fixed" | "defaults";
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
type brush_option_type = boolean;
|
| 27 |
+
</script>
|
| 28 |
+
|
| 29 |
+
<script lang="ts">
|
| 30 |
+
import tinycolor from "tinycolor2";
|
| 31 |
+
import { clamp } from "../utils/pixi";
|
| 32 |
+
|
| 33 |
+
import { getContext, onMount, tick } from "svelte";
|
| 34 |
+
import { type ToolContext, TOOL_KEY } from "./Tools.svelte";
|
| 35 |
+
import { type EditorContext, EDITOR_KEY } from "../ImageEditor.svelte";
|
| 36 |
+
import { draw_path, type DrawCommand } from "./brush";
|
| 37 |
+
import BrushOptions from "./BrushOptions.svelte";
|
| 38 |
+
import type { FederatedPointerEvent } from "pixi.js";
|
| 39 |
+
|
| 40 |
+
export let default_size: Brush["default_size"];
|
| 41 |
+
export let default_color: Brush["default_color"] | undefined = undefined;
|
| 42 |
+
export let colors: Brush["colors"] | undefined = undefined;
|
| 43 |
+
export let color_mode: Brush["color_mode"] | undefined = undefined;
|
| 44 |
+
export let mode: "erase" | "draw";
|
| 45 |
+
|
| 46 |
+
$: processed_colors = colors
|
| 47 |
+
? colors.map(process_color).filter((_, i) => i < 4)
|
| 48 |
+
: [];
|
| 49 |
+
|
| 50 |
+
$: selected_color =
|
| 51 |
+
default_color === "auto"
|
| 52 |
+
? processed_colors[0]
|
| 53 |
+
: !default_color
|
| 54 |
+
? "black"
|
| 55 |
+
: process_color(default_color);
|
| 56 |
+
|
| 57 |
+
let brush_options: brush_option_type = false;
|
| 58 |
+
|
| 59 |
+
const {
|
| 60 |
+
pixi,
|
| 61 |
+
dimensions,
|
| 62 |
+
current_layer,
|
| 63 |
+
command_manager,
|
| 64 |
+
register_context,
|
| 65 |
+
editor_box,
|
| 66 |
+
crop,
|
| 67 |
+
toolbar_box
|
| 68 |
+
} = getContext<EditorContext>(EDITOR_KEY);
|
| 69 |
+
|
| 70 |
+
const { active_tool, register_tool, current_color } =
|
| 71 |
+
getContext<ToolContext>(TOOL_KEY);
|
| 72 |
+
|
| 73 |
+
let drawing = false;
|
| 74 |
+
let draw: DrawCommand;
|
| 75 |
+
|
| 76 |
+
function generate_sizes(x: number, y: number): number {
|
| 77 |
+
const min = clamp(Math.min(x, y), 500, 1000);
|
| 78 |
+
|
| 79 |
+
return Math.round((min * 2) / 100);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
$: mode === "draw" && current_color.set(selected_color);
|
| 83 |
+
|
| 84 |
+
let selected_size =
|
| 85 |
+
default_size === "auto" ? generate_sizes(...$dimensions) : default_size;
|
| 86 |
+
|
| 87 |
+
function pointer_down_handler(event: FederatedPointerEvent): void {
|
| 88 |
+
if ($active_tool !== mode) {
|
| 89 |
+
return;
|
| 90 |
+
}
|
| 91 |
+
drawing = true;
|
| 92 |
+
|
| 93 |
+
if (!$pixi || !$current_layer) {
|
| 94 |
+
return;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
draw = draw_path(
|
| 98 |
+
$pixi.renderer!,
|
| 99 |
+
$pixi.layer_container,
|
| 100 |
+
$current_layer,
|
| 101 |
+
mode
|
| 102 |
+
);
|
| 103 |
+
|
| 104 |
+
draw.start({
|
| 105 |
+
x: event.screen.x,
|
| 106 |
+
y: event.screen.y,
|
| 107 |
+
color: selected_color || undefined,
|
| 108 |
+
size: selected_size,
|
| 109 |
+
opacity: 1
|
| 110 |
+
});
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
function pointer_up_handler(event: FederatedPointerEvent): void {
|
| 114 |
+
if (!$pixi || !$current_layer) {
|
| 115 |
+
return;
|
| 116 |
+
}
|
| 117 |
+
if ($active_tool !== mode) {
|
| 118 |
+
return;
|
| 119 |
+
}
|
| 120 |
+
draw.stop();
|
| 121 |
+
command_manager.execute(draw);
|
| 122 |
+
drawing = false;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
function pointer_move_handler(event: FederatedPointerEvent): void {
|
| 126 |
+
if ($active_tool !== mode) {
|
| 127 |
+
return;
|
| 128 |
+
}
|
| 129 |
+
if (drawing) {
|
| 130 |
+
draw.continue({
|
| 131 |
+
x: event.screen.x,
|
| 132 |
+
y: event.screen.y
|
| 133 |
+
});
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
const x_bound = $crop[0] * $dimensions[0];
|
| 137 |
+
const y_bound = $crop[1] * $dimensions[1];
|
| 138 |
+
|
| 139 |
+
if (
|
| 140 |
+
x_bound > event.screen.x ||
|
| 141 |
+
y_bound > event.screen.y ||
|
| 142 |
+
event.screen.x > x_bound + $crop[2] * $dimensions[0] ||
|
| 143 |
+
event.screen.y > y_bound + $crop[3] * $dimensions[1]
|
| 144 |
+
) {
|
| 145 |
+
brush_cursor = false;
|
| 146 |
+
document.body.style.cursor = "auto";
|
| 147 |
+
} else {
|
| 148 |
+
brush_cursor = true;
|
| 149 |
+
document.body.style.cursor = "none";
|
| 150 |
+
}
|
| 151 |
+
if (brush_cursor) {
|
| 152 |
+
pos = {
|
| 153 |
+
x: event.clientX - $editor_box.child_left,
|
| 154 |
+
y: event.clientY - $editor_box.child_top
|
| 155 |
+
};
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
let brush_cursor = false;
|
| 160 |
+
|
| 161 |
+
async function toggle_listeners(on_off: "on" | "off"): Promise<void> {
|
| 162 |
+
$pixi?.layer_container[on_off]("pointerdown", pointer_down_handler);
|
| 163 |
+
|
| 164 |
+
$pixi?.layer_container[on_off]("pointerup", pointer_up_handler);
|
| 165 |
+
|
| 166 |
+
$pixi?.layer_container[on_off]("pointermove", pointer_move_handler);
|
| 167 |
+
$pixi?.layer_container[on_off](
|
| 168 |
+
"pointerenter",
|
| 169 |
+
(event: FederatedPointerEvent) => {
|
| 170 |
+
if ($active_tool === mode) {
|
| 171 |
+
brush_cursor = true;
|
| 172 |
+
document.body.style.cursor = "none";
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
);
|
| 176 |
+
$pixi?.layer_container[on_off](
|
| 177 |
+
"pointerleave",
|
| 178 |
+
() => ((brush_cursor = false), (document.body.style.cursor = "auto"))
|
| 179 |
+
);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
register_context(mode, {
|
| 183 |
+
init_fn: () => {
|
| 184 |
+
toggle_listeners("on");
|
| 185 |
+
},
|
| 186 |
+
reset_fn: () => {
|
| 187 |
+
toggle_listeners("off");
|
| 188 |
+
}
|
| 189 |
+
});
|
| 190 |
+
const toggle_options = debounce_toggle();
|
| 191 |
+
|
| 192 |
+
const unregister = register_tool(mode, {
|
| 193 |
+
cb: toggle_options
|
| 194 |
+
});
|
| 195 |
+
onMount(() => {
|
| 196 |
+
return () => {
|
| 197 |
+
unregister();
|
| 198 |
+
toggle_listeners("off");
|
| 199 |
+
};
|
| 200 |
+
});
|
| 201 |
+
|
| 202 |
+
let recent_colors: (string | null)[] = [null, null, null];
|
| 203 |
+
|
| 204 |
+
function process_color(color: ColorInput): string {
|
| 205 |
+
return tinycolor(color).toRgbString();
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
let pos = { x: 0, y: 0 };
|
| 209 |
+
$: brush_size =
|
| 210 |
+
(selected_size / $dimensions[0]) * $editor_box.child_width * 2;
|
| 211 |
+
|
| 212 |
+
function debounce_toggle(): (should_close?: boolean) => void {
|
| 213 |
+
let timeout: NodeJS.Timeout | null = null;
|
| 214 |
+
|
| 215 |
+
return function executedFunction(should_close?: boolean) {
|
| 216 |
+
const later = (): void => {
|
| 217 |
+
if (timeout) {
|
| 218 |
+
clearTimeout(timeout);
|
| 219 |
+
}
|
| 220 |
+
if (should_close !== undefined) {
|
| 221 |
+
brush_options = should_close;
|
| 222 |
+
return;
|
| 223 |
+
}
|
| 224 |
+
brush_options = !brush_options;
|
| 225 |
+
};
|
| 226 |
+
|
| 227 |
+
if (timeout) {
|
| 228 |
+
clearTimeout(timeout);
|
| 229 |
+
}
|
| 230 |
+
timeout = setTimeout(later, 100);
|
| 231 |
+
};
|
| 232 |
+
}
|
| 233 |
+
</script>
|
| 234 |
+
|
| 235 |
+
<svelte:window
|
| 236 |
+
on:keydown={({ key }) => key === "Escape" && toggle_options(false)}
|
| 237 |
+
/>
|
| 238 |
+
|
| 239 |
+
<span
|
| 240 |
+
style:transform="translate({pos.x}px, {pos.y}px)"
|
| 241 |
+
style:top="{$editor_box.child_top -
|
| 242 |
+
$editor_box.parent_top -
|
| 243 |
+
brush_size / 2}px"
|
| 244 |
+
style:left="{$editor_box.child_left -
|
| 245 |
+
$editor_box.parent_left -
|
| 246 |
+
brush_size / 2}px"
|
| 247 |
+
style:width="{brush_size}px"
|
| 248 |
+
style:height="{brush_size}px"
|
| 249 |
+
style:opacity={brush_cursor ? 1 : 0}
|
| 250 |
+
/>
|
| 251 |
+
|
| 252 |
+
{#if brush_options}
|
| 253 |
+
<div>
|
| 254 |
+
<BrushOptions
|
| 255 |
+
show_swatch={mode === "draw"}
|
| 256 |
+
on:click_outside={() => toggle_options()}
|
| 257 |
+
colors={processed_colors}
|
| 258 |
+
bind:selected_color
|
| 259 |
+
{color_mode}
|
| 260 |
+
bind:recent_colors
|
| 261 |
+
bind:selected_size
|
| 262 |
+
dimensions={$dimensions}
|
| 263 |
+
parent_width={$editor_box.parent_width}
|
| 264 |
+
parent_height={$editor_box.parent_height}
|
| 265 |
+
parent_left={$editor_box.parent_left}
|
| 266 |
+
toolbar_box={$toolbar_box}
|
| 267 |
+
/>
|
| 268 |
+
</div>
|
| 269 |
+
{/if}
|
| 270 |
+
|
| 271 |
+
<style>
|
| 272 |
+
span {
|
| 273 |
+
position: absolute;
|
| 274 |
+
background: rgba(0, 0, 0, 0.5);
|
| 275 |
+
pointer-events: none;
|
| 276 |
+
border-radius: 50%;
|
| 277 |
+
}
|
| 278 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/BrushOptions.svelte
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { createEventDispatcher } from "svelte";
|
| 3 |
+
import { click_outside } from "../utils/events";
|
| 4 |
+
|
| 5 |
+
import { type Brush } from "./Brush.svelte";
|
| 6 |
+
import ColorPicker from "./ColorPicker.svelte";
|
| 7 |
+
import ColorSwatch from "./ColorSwatch.svelte";
|
| 8 |
+
import ColorField from "./ColorField.svelte";
|
| 9 |
+
import BrushSize from "./BrushSize.svelte";
|
| 10 |
+
|
| 11 |
+
export let colors: string[];
|
| 12 |
+
export let selected_color: string;
|
| 13 |
+
export let color_mode: Brush["color_mode"] | undefined = undefined;
|
| 14 |
+
export let recent_colors: (string | null)[] = [];
|
| 15 |
+
export let selected_size: number;
|
| 16 |
+
export let dimensions: [number, number];
|
| 17 |
+
export let parent_width: number;
|
| 18 |
+
export let parent_height: number;
|
| 19 |
+
export let parent_left: number;
|
| 20 |
+
export let toolbar_box: DOMRect | Record<string, never>;
|
| 21 |
+
export let show_swatch: boolean;
|
| 22 |
+
|
| 23 |
+
let color_picker = false;
|
| 24 |
+
let current_mode: "hex" | "rgb" | "hsl" = "hex";
|
| 25 |
+
let editing_index: number | null = null;
|
| 26 |
+
|
| 27 |
+
const dispatch = createEventDispatcher<{
|
| 28 |
+
click_outside: void;
|
| 29 |
+
}>();
|
| 30 |
+
|
| 31 |
+
function handle_color_selection(
|
| 32 |
+
{
|
| 33 |
+
index,
|
| 34 |
+
color
|
| 35 |
+
}: {
|
| 36 |
+
index: number | null;
|
| 37 |
+
color: string | null;
|
| 38 |
+
},
|
| 39 |
+
type: "core" | "user"
|
| 40 |
+
): void {
|
| 41 |
+
if (type === "user" && !color) {
|
| 42 |
+
editing_index = index;
|
| 43 |
+
color_picker = true;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
if (!color) return;
|
| 47 |
+
selected_color = color;
|
| 48 |
+
|
| 49 |
+
if (type === "core") {
|
| 50 |
+
color_picker = false;
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
function handle_color_change(color: string): void {
|
| 55 |
+
if (editing_index === null) return;
|
| 56 |
+
recent_colors[editing_index] = color;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
$: handle_color_change(selected_color);
|
| 60 |
+
let width = 0;
|
| 61 |
+
let height = 0;
|
| 62 |
+
let c_width = 0;
|
| 63 |
+
let c_height = 0;
|
| 64 |
+
let wrap_el: HTMLDivElement;
|
| 65 |
+
let full_screen = false;
|
| 66 |
+
let anchor: "default" | "center" | "top" = "default";
|
| 67 |
+
let left_anchor = 0;
|
| 68 |
+
let top_anchor = null;
|
| 69 |
+
$: {
|
| 70 |
+
if (wrap_el && (width || height || c_height || c_width)) {
|
| 71 |
+
const box = wrap_el.getBoundingClientRect();
|
| 72 |
+
color_picker;
|
| 73 |
+
|
| 74 |
+
if (box.width > parent_width) {
|
| 75 |
+
full_screen = true;
|
| 76 |
+
} else if (parent_width > box.width + 230 * 2 + 25) {
|
| 77 |
+
anchor = "default";
|
| 78 |
+
|
| 79 |
+
left_anchor = toolbar_box.right - parent_left + 24;
|
| 80 |
+
} else {
|
| 81 |
+
anchor = "center";
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
if (box.height + 50 > parent_height) {
|
| 85 |
+
anchor = "top";
|
| 86 |
+
top_anchor = true;
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
</script>
|
| 91 |
+
|
| 92 |
+
<svelte:window bind:innerHeight={height} bind:innerWidth={width} />
|
| 93 |
+
|
| 94 |
+
<div
|
| 95 |
+
class="wrap"
|
| 96 |
+
class:padded={!color_picker}
|
| 97 |
+
use:click_outside={() => dispatch("click_outside")}
|
| 98 |
+
class:anchor_default={anchor === "default"}
|
| 99 |
+
class:anchor_center={anchor === "center"}
|
| 100 |
+
class:anchor_top={anchor === "top"}
|
| 101 |
+
bind:this={wrap_el}
|
| 102 |
+
bind:clientWidth={c_width}
|
| 103 |
+
bind:clientHeight={c_height}
|
| 104 |
+
class:anchor={`${left_anchor}px`}
|
| 105 |
+
>
|
| 106 |
+
{#if color_mode === "defaults"}
|
| 107 |
+
{#if color_picker}
|
| 108 |
+
<ColorPicker bind:color={selected_color} />
|
| 109 |
+
<ColorField
|
| 110 |
+
bind:current_mode
|
| 111 |
+
color={selected_color}
|
| 112 |
+
on:close={() => (color_picker = false)}
|
| 113 |
+
on:selected={({ detail }) => (selected_color = detail)}
|
| 114 |
+
/>
|
| 115 |
+
{/if}
|
| 116 |
+
{/if}
|
| 117 |
+
{#if show_swatch}
|
| 118 |
+
<ColorSwatch
|
| 119 |
+
bind:color_picker
|
| 120 |
+
{colors}
|
| 121 |
+
on:select={({ detail }) => handle_color_selection(detail, "core")}
|
| 122 |
+
on:edit={({ detail }) => handle_color_selection(detail, "user")}
|
| 123 |
+
user_colors={color_mode === "defaults" ? recent_colors : null}
|
| 124 |
+
{selected_color}
|
| 125 |
+
{current_mode}
|
| 126 |
+
/>
|
| 127 |
+
{/if}
|
| 128 |
+
|
| 129 |
+
{#if color_picker || show_swatch}
|
| 130 |
+
<div class="sep"></div>
|
| 131 |
+
{/if}
|
| 132 |
+
|
| 133 |
+
<BrushSize max={dimensions[0] / 10} min={1} bind:selected_size />
|
| 134 |
+
</div>
|
| 135 |
+
|
| 136 |
+
<style>
|
| 137 |
+
.wrap {
|
| 138 |
+
max-width: 230px;
|
| 139 |
+
width: 90%;
|
| 140 |
+
position: absolute;
|
| 141 |
+
display: flex;
|
| 142 |
+
flex-direction: column;
|
| 143 |
+
gap: 5px;
|
| 144 |
+
background: var(--background-fill-secondary);
|
| 145 |
+
border: 1px solid var(--block-border-color);
|
| 146 |
+
border-radius: var(--radius-md);
|
| 147 |
+
box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
|
| 148 |
+
padding-bottom: var(--size-2);
|
| 149 |
+
pointer-events: all;
|
| 150 |
+
cursor: default;
|
| 151 |
+
z-index: var(--layer-top);
|
| 152 |
+
overflow: hidden;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
.anchor_default {
|
| 156 |
+
position: absolute;
|
| 157 |
+
left: var(--left-anchor);
|
| 158 |
+
bottom: 8px;
|
| 159 |
+
}
|
| 160 |
+
.anchor_center {
|
| 161 |
+
position: absolute;
|
| 162 |
+
bottom: 50px;
|
| 163 |
+
left: 50%;
|
| 164 |
+
transform: translateX(-50%);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
.anchor_top {
|
| 168 |
+
position: absolute;
|
| 169 |
+
top: 1px;
|
| 170 |
+
left: 50%;
|
| 171 |
+
transform: translateX(-50%);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
.sep {
|
| 175 |
+
height: 1px;
|
| 176 |
+
background-color: var(--block-border-color);
|
| 177 |
+
margin: 0 var(--size-3);
|
| 178 |
+
margin-top: var(--size-1);
|
| 179 |
+
}
|
| 180 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/BrushSize.svelte
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { click_outside } from "../utils/events";
|
| 3 |
+
import { createEventDispatcher } from "svelte";
|
| 4 |
+
import { BrushSize } from "@gradio/icons";
|
| 5 |
+
|
| 6 |
+
export let selected_size: number;
|
| 7 |
+
export let min: number;
|
| 8 |
+
export let max: number;
|
| 9 |
+
|
| 10 |
+
const dispatch = createEventDispatcher<{
|
| 11 |
+
click_outside: void;
|
| 12 |
+
}>();
|
| 13 |
+
|
| 14 |
+
let width = 0;
|
| 15 |
+
let height = 0;
|
| 16 |
+
let c_width = 0;
|
| 17 |
+
let c_height = 0;
|
| 18 |
+
let wrap_el: HTMLDivElement;
|
| 19 |
+
let anchor_right = false;
|
| 20 |
+
let anchor_top = false;
|
| 21 |
+
|
| 22 |
+
$: {
|
| 23 |
+
if (wrap_el && (width || height || c_height || c_width)) {
|
| 24 |
+
const box = wrap_el.getBoundingClientRect();
|
| 25 |
+
|
| 26 |
+
anchor_right = box.width + 30 > width / 2;
|
| 27 |
+
anchor_top = box.y < 80;
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
</script>
|
| 31 |
+
|
| 32 |
+
<svelte:window bind:innerHeight={height} bind:innerWidth={width} />
|
| 33 |
+
|
| 34 |
+
<div
|
| 35 |
+
class="wrap"
|
| 36 |
+
use:click_outside={() => dispatch("click_outside")}
|
| 37 |
+
bind:this={wrap_el}
|
| 38 |
+
bind:clientWidth={c_width}
|
| 39 |
+
bind:clientHeight={c_height}
|
| 40 |
+
class:right={anchor_right}
|
| 41 |
+
class:top={anchor_top}
|
| 42 |
+
class:bottom={!anchor_top}
|
| 43 |
+
>
|
| 44 |
+
<span>
|
| 45 |
+
<BrushSize />
|
| 46 |
+
</span>
|
| 47 |
+
<input type="range" bind:value={selected_size} {min} {max} step={1} />
|
| 48 |
+
</div>
|
| 49 |
+
|
| 50 |
+
<style>
|
| 51 |
+
.wrap {
|
| 52 |
+
width: 100%;
|
| 53 |
+
display: flex;
|
| 54 |
+
gap: var(--size-4);
|
| 55 |
+
background: var(--background-fill-secondary);
|
| 56 |
+
padding: 0 var(--size-4);
|
| 57 |
+
cursor: default;
|
| 58 |
+
padding-top: var(--size-2-5);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
input {
|
| 62 |
+
width: 100%;
|
| 63 |
+
}
|
| 64 |
+
span {
|
| 65 |
+
width: 26px;
|
| 66 |
+
color: var(--body-text-color);
|
| 67 |
+
}
|
| 68 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/ColorField.svelte
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Eyedropper } from "@gradio/icons";
|
| 3 |
+
import { createEventDispatcher } from "svelte";
|
| 4 |
+
|
| 5 |
+
import tinycolor from "tinycolor2";
|
| 6 |
+
export let color: string;
|
| 7 |
+
|
| 8 |
+
export let current_mode: "hex" | "rgb" | "hsl" = "hex";
|
| 9 |
+
|
| 10 |
+
const dispatch = createEventDispatcher<{
|
| 11 |
+
selected: string;
|
| 12 |
+
close: void;
|
| 13 |
+
}>();
|
| 14 |
+
const modes = [
|
| 15 |
+
["Hex", "hex"],
|
| 16 |
+
["RGB", "rgb"],
|
| 17 |
+
["HSL", "hsl"]
|
| 18 |
+
] as const;
|
| 19 |
+
|
| 20 |
+
function format_color(color: string, mode: "hex" | "rgb" | "hsl"): string {
|
| 21 |
+
if (mode === "hex") {
|
| 22 |
+
return tinycolor(color).toHexString();
|
| 23 |
+
} else if (mode === "rgb") {
|
| 24 |
+
return tinycolor(color).toRgbString();
|
| 25 |
+
}
|
| 26 |
+
return tinycolor(color).toHslString();
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
$: color_string = format_color(color, current_mode);
|
| 30 |
+
$: color_string && dispatch("selected", color_string);
|
| 31 |
+
|
| 32 |
+
function request_eyedropper(): void {
|
| 33 |
+
// @ts-ignore
|
| 34 |
+
const eyeDropper = new EyeDropper();
|
| 35 |
+
|
| 36 |
+
eyeDropper.open().then((result: { sRGBHex: string }) => {
|
| 37 |
+
color = result.sRGBHex;
|
| 38 |
+
});
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
//@ts-ignore
|
| 42 |
+
const eyedropper_supported = !!window.EyeDropper;
|
| 43 |
+
|
| 44 |
+
function handle_click(): void {
|
| 45 |
+
dispatch("selected", color_string);
|
| 46 |
+
dispatch("close");
|
| 47 |
+
}
|
| 48 |
+
</script>
|
| 49 |
+
|
| 50 |
+
<div class="input">
|
| 51 |
+
<button class="swatch" style:background={color} on:click={handle_click}
|
| 52 |
+
></button>
|
| 53 |
+
<div>
|
| 54 |
+
<div class="input-wrap">
|
| 55 |
+
<input
|
| 56 |
+
type="text"
|
| 57 |
+
value={color_string}
|
| 58 |
+
on:change={(e) => (color = e.currentTarget.value)}
|
| 59 |
+
/>
|
| 60 |
+
|
| 61 |
+
<button class="eyedropper" on:click={request_eyedropper}>
|
| 62 |
+
{#if eyedropper_supported}
|
| 63 |
+
<Eyedropper />
|
| 64 |
+
{/if}
|
| 65 |
+
</button>
|
| 66 |
+
</div>
|
| 67 |
+
<div class="buttons">
|
| 68 |
+
{#each modes as [label, value]}
|
| 69 |
+
<button
|
| 70 |
+
class="button"
|
| 71 |
+
class:active={current_mode === value}
|
| 72 |
+
on:click={() => (current_mode = value)}>{label}</button
|
| 73 |
+
>
|
| 74 |
+
{/each}
|
| 75 |
+
</div>
|
| 76 |
+
</div>
|
| 77 |
+
</div>
|
| 78 |
+
|
| 79 |
+
<style>
|
| 80 |
+
.input {
|
| 81 |
+
display: flex;
|
| 82 |
+
align-items: center;
|
| 83 |
+
padding: 0 10px 15px;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.input input {
|
| 87 |
+
height: 30px;
|
| 88 |
+
width: 100%;
|
| 89 |
+
flex-shrink: 1;
|
| 90 |
+
border-bottom-left-radius: 0;
|
| 91 |
+
border: 1px solid var(--block-border-color);
|
| 92 |
+
letter-spacing: -0.05rem;
|
| 93 |
+
border-left: none;
|
| 94 |
+
border-right: none;
|
| 95 |
+
font-family: var(--font-mono);
|
| 96 |
+
font-size: var(--scale-000);
|
| 97 |
+
padding-left: 15px;
|
| 98 |
+
padding-right: 0;
|
| 99 |
+
background-color: var(--background-fill-secondary);
|
| 100 |
+
color: var(--block-label-text-color);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.swatch {
|
| 104 |
+
width: 50px;
|
| 105 |
+
height: 50px;
|
| 106 |
+
border-top-left-radius: 15px;
|
| 107 |
+
border-bottom-left-radius: 15px;
|
| 108 |
+
flex-shrink: 0;
|
| 109 |
+
border: 1px solid var(--block-border-color);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
.buttons button {
|
| 113 |
+
display: flex;
|
| 114 |
+
align-items: center;
|
| 115 |
+
justify-content: center;
|
| 116 |
+
border: 1px solid var(--block-border-color);
|
| 117 |
+
background: var(--background-fill-secondary);
|
| 118 |
+
padding: 3px 6px;
|
| 119 |
+
font-size: var(--scale-000);
|
| 120 |
+
cursor: pointer;
|
| 121 |
+
border-right: none;
|
| 122 |
+
width: 100%;
|
| 123 |
+
border-top: none;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.buttons button:first-child {
|
| 127 |
+
border-left: none;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.buttons button:last-child {
|
| 131 |
+
border-bottom-right-radius: 15px;
|
| 132 |
+
border-right: 1px solid var(--block-border-color);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
.buttons button:hover {
|
| 136 |
+
background: var(--background-fill-secondary-hover);
|
| 137 |
+
font-weight: var(--weight-bold);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.buttons button.active {
|
| 141 |
+
background: var(--background-fill-secondary);
|
| 142 |
+
font-weight: var(--weight-bold);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
.buttons {
|
| 146 |
+
height: 20px;
|
| 147 |
+
|
| 148 |
+
display: flex;
|
| 149 |
+
justify-content: stretch;
|
| 150 |
+
gap: 0px;
|
| 151 |
+
/* padding: 0 10px; */
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.input-wrap {
|
| 155 |
+
display: flex;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.eyedropper {
|
| 159 |
+
display: flex;
|
| 160 |
+
align-items: center;
|
| 161 |
+
justify-content: center;
|
| 162 |
+
width: 25px;
|
| 163 |
+
height: 30px;
|
| 164 |
+
border-top-right-radius: 15px;
|
| 165 |
+
border: 1px solid var(--block-border-color);
|
| 166 |
+
border-left: none;
|
| 167 |
+
background: var(--background-fill-secondary);
|
| 168 |
+
height: 30px;
|
| 169 |
+
padding: 7px 7px 5px 0px;
|
| 170 |
+
cursor: pointer;
|
| 171 |
+
}
|
| 172 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/ColorPicker.svelte
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { tick } from "svelte";
|
| 3 |
+
import tinycolor from "tinycolor2";
|
| 4 |
+
import { clamp } from "../utils/pixi";
|
| 5 |
+
|
| 6 |
+
export let color = "rgb(255, 255, 255)";
|
| 7 |
+
|
| 8 |
+
let name = "world";
|
| 9 |
+
let sl_marker_pos = [0, 0];
|
| 10 |
+
let sl_rect: DOMRect | null = null;
|
| 11 |
+
let sl_moving = false;
|
| 12 |
+
let sl = [0, 0];
|
| 13 |
+
|
| 14 |
+
let hue = 0;
|
| 15 |
+
let hue_marker_pos = 0;
|
| 16 |
+
let hue_rect: DOMRect | null = null;
|
| 17 |
+
let hue_moving = false;
|
| 18 |
+
|
| 19 |
+
function handle_hue_down(
|
| 20 |
+
event: MouseEvent & { currentTarget: HTMLDivElement }
|
| 21 |
+
): void {
|
| 22 |
+
hue_rect = event.currentTarget.getBoundingClientRect();
|
| 23 |
+
|
| 24 |
+
hue_moving = true;
|
| 25 |
+
update_hue_from_mouse(event.clientX);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
function update_hue_from_mouse(x: number): void {
|
| 29 |
+
if (!hue_rect) return;
|
| 30 |
+
const _x = clamp(x - hue_rect.left, 0, hue_rect.width); // Get the x-coordinate relative to the box
|
| 31 |
+
hue_marker_pos = _x;
|
| 32 |
+
const _hue = (_x / hue_rect.width) * 360; // Scale the x position to a hue value (0-360)
|
| 33 |
+
|
| 34 |
+
hue = _hue;
|
| 35 |
+
|
| 36 |
+
color = hsva_to_rgba({ h: _hue, s: sl[0], v: sl[1], a: 1 });
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
function hsva_to_rgba(hsva: {
|
| 40 |
+
h: number;
|
| 41 |
+
s: number;
|
| 42 |
+
v: number;
|
| 43 |
+
a: number;
|
| 44 |
+
}): string {
|
| 45 |
+
const saturation = hsva.s;
|
| 46 |
+
const value = hsva.v;
|
| 47 |
+
let chroma = saturation * value;
|
| 48 |
+
const hue_by_60 = hsva.h / 60;
|
| 49 |
+
let x = chroma * (1 - Math.abs((hue_by_60 % 2) - 1));
|
| 50 |
+
const m = value - chroma;
|
| 51 |
+
|
| 52 |
+
chroma = chroma + m;
|
| 53 |
+
x = x + m;
|
| 54 |
+
|
| 55 |
+
const index = Math.floor(hue_by_60) % 6;
|
| 56 |
+
const red = [chroma, x, m, m, x, chroma][index];
|
| 57 |
+
const green = [x, chroma, chroma, x, m, m][index];
|
| 58 |
+
const blue = [m, m, x, chroma, chroma, x][index];
|
| 59 |
+
|
| 60 |
+
return `rgba(${red * 255}, ${green * 255}, ${blue * 255}, ${hsva.a})`;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
function update_color_from_mouse(x: number, y: number): void {
|
| 64 |
+
if (!sl_rect) return;
|
| 65 |
+
const _x = clamp(x - sl_rect.left, 0, sl_rect.width);
|
| 66 |
+
const _y = clamp(y - sl_rect.top, 0, sl_rect.height);
|
| 67 |
+
sl_marker_pos = [_x, _y];
|
| 68 |
+
const _hsva = {
|
| 69 |
+
h: hue * 1,
|
| 70 |
+
s: _x / sl_rect.width,
|
| 71 |
+
v: 1 - _y / sl_rect.height,
|
| 72 |
+
a: 1
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
sl = [_hsva.s, _hsva.v];
|
| 76 |
+
|
| 77 |
+
color = hsva_to_rgba(_hsva);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
function handle_sl_down(
|
| 81 |
+
event: MouseEvent & { currentTarget: HTMLDivElement }
|
| 82 |
+
): void {
|
| 83 |
+
sl_moving = true;
|
| 84 |
+
sl_rect = event.currentTarget.getBoundingClientRect();
|
| 85 |
+
update_color_from_mouse(event.clientX, event.clientY);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
function handle_move(
|
| 89 |
+
event: MouseEvent & { currentTarget: EventTarget & Window }
|
| 90 |
+
): void {
|
| 91 |
+
if (sl_moving) update_color_from_mouse(event.clientX, event.clientY);
|
| 92 |
+
if (hue_moving) update_hue_from_mouse(event.clientX);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
function handle_end(): void {
|
| 96 |
+
if (sl_moving) sl_moving = false;
|
| 97 |
+
if (hue_moving) hue_moving = false;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
async function update_mouse_from_color(color: string): Promise<void> {
|
| 101 |
+
if (sl_moving || hue_moving) return;
|
| 102 |
+
await tick();
|
| 103 |
+
if (!color) return;
|
| 104 |
+
if (!sl_rect) {
|
| 105 |
+
sl_rect = sl_wrap.getBoundingClientRect();
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
if (!hue_rect) {
|
| 109 |
+
hue_rect = hue_wrap.getBoundingClientRect();
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
const hsva = tinycolor(color).toHsv();
|
| 113 |
+
const _x = hsva.s * sl_rect!.width;
|
| 114 |
+
const _y = (1 - hsva.v) * sl_rect!.height;
|
| 115 |
+
sl_marker_pos = [_x, _y];
|
| 116 |
+
sl = [hsva.s, hsva.v];
|
| 117 |
+
hue = hsva.h;
|
| 118 |
+
hue_marker_pos = (hsva.h / 360) * hue_rect!.width;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
$: update_mouse_from_color(color);
|
| 122 |
+
|
| 123 |
+
let sl_wrap: HTMLDivElement;
|
| 124 |
+
let hue_wrap: HTMLDivElement;
|
| 125 |
+
</script>
|
| 126 |
+
|
| 127 |
+
<svelte:window on:mousemove={handle_move} on:mouseup={handle_end} />
|
| 128 |
+
|
| 129 |
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
| 130 |
+
<div
|
| 131 |
+
class="color-gradient"
|
| 132 |
+
on:mousedown={handle_sl_down}
|
| 133 |
+
style="--hue:{hue}"
|
| 134 |
+
bind:this={sl_wrap}
|
| 135 |
+
>
|
| 136 |
+
<div
|
| 137 |
+
class="marker"
|
| 138 |
+
style:transform="translate({sl_marker_pos[0]}px,{sl_marker_pos[1]}px)"
|
| 139 |
+
style:background={color}
|
| 140 |
+
/>
|
| 141 |
+
</div>
|
| 142 |
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
| 143 |
+
<div class="hue-slider" on:mousedown={handle_hue_down} bind:this={hue_wrap}>
|
| 144 |
+
<div
|
| 145 |
+
class="marker"
|
| 146 |
+
style:background={"hsl(" + hue + ", 100%, 50%)"}
|
| 147 |
+
style:transform="translateX({hue_marker_pos}px)"
|
| 148 |
+
/>
|
| 149 |
+
</div>
|
| 150 |
+
|
| 151 |
+
<style>
|
| 152 |
+
.hue-slider {
|
| 153 |
+
position: relative;
|
| 154 |
+
width: 90%;
|
| 155 |
+
margin: 10px auto;
|
| 156 |
+
height: 10px;
|
| 157 |
+
border-radius: 5px;
|
| 158 |
+
background: linear-gradient(
|
| 159 |
+
to right,
|
| 160 |
+
hsl(0, 100%, 50%) 0%,
|
| 161 |
+
#ff0 17%,
|
| 162 |
+
lime 33%,
|
| 163 |
+
cyan 50%,
|
| 164 |
+
blue 67%,
|
| 165 |
+
magenta 83%,
|
| 166 |
+
red 100%
|
| 167 |
+
);
|
| 168 |
+
border-top: none;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
.color-gradient {
|
| 172 |
+
position: relative;
|
| 173 |
+
--hue: white;
|
| 174 |
+
|
| 175 |
+
background: linear-gradient(rgba(0, 0, 0, 0), #000),
|
| 176 |
+
linear-gradient(90deg, #fff, hsl(var(--hue), 100%, 50%));
|
| 177 |
+
width: 100%;
|
| 178 |
+
height: 150px;
|
| 179 |
+
border-top-left-radius: 4px;
|
| 180 |
+
border-top-right-radius: 4px;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.marker {
|
| 184 |
+
position: absolute;
|
| 185 |
+
width: 14px;
|
| 186 |
+
height: 14px;
|
| 187 |
+
border-radius: 50%;
|
| 188 |
+
border: 2px solid white;
|
| 189 |
+
|
| 190 |
+
top: -7px;
|
| 191 |
+
left: -7px;
|
| 192 |
+
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
|
| 193 |
+
pointer-events: none;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
.hue-slider > .marker {
|
| 197 |
+
box-shadow: 0 0 1px #888;
|
| 198 |
+
top: -3px;
|
| 199 |
+
margin: auto;
|
| 200 |
+
height: 16px;
|
| 201 |
+
width: 16px;
|
| 202 |
+
left: -8px;
|
| 203 |
+
border: 2px solid white;
|
| 204 |
+
}
|
| 205 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/ColorSwatch.svelte
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import tinycolor from "tinycolor2";
|
| 3 |
+
import { createEventDispatcher } from "svelte";
|
| 4 |
+
export let selected_color: string;
|
| 5 |
+
export let colors: string[];
|
| 6 |
+
export let user_colors: (string | null)[] | null = [];
|
| 7 |
+
import { Palette } from "@gradio/icons";
|
| 8 |
+
|
| 9 |
+
export let show_empty = false;
|
| 10 |
+
export let current_mode: "hex" | "rgb" | "hsl" = "hex";
|
| 11 |
+
export let color_picker = false;
|
| 12 |
+
const dispatch = createEventDispatcher<{
|
| 13 |
+
select: { index: number | null; color: string | null };
|
| 14 |
+
edit: { index: number; color: string | null };
|
| 15 |
+
}>();
|
| 16 |
+
|
| 17 |
+
$: _colors = show_empty ? colors : colors.filter((c) => c);
|
| 18 |
+
|
| 19 |
+
function get_formatted_color(
|
| 20 |
+
color: string,
|
| 21 |
+
mode: "hex" | "rgb" | "hsl"
|
| 22 |
+
): string {
|
| 23 |
+
if (mode === "hex") {
|
| 24 |
+
return tinycolor(color).toHexString();
|
| 25 |
+
} else if (mode === "rgb") {
|
| 26 |
+
return tinycolor(color).toRgbString();
|
| 27 |
+
}
|
| 28 |
+
return tinycolor(color).toHslString();
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
let current_index = `select-${colors.findIndex(
|
| 32 |
+
(c) =>
|
| 33 |
+
get_formatted_color(c, current_mode) ===
|
| 34 |
+
get_formatted_color(selected_color, current_mode)
|
| 35 |
+
)}`;
|
| 36 |
+
|
| 37 |
+
function handle_select(
|
| 38 |
+
type: "edit" | "select",
|
| 39 |
+
detail: {
|
| 40 |
+
index: number;
|
| 41 |
+
color: string | null;
|
| 42 |
+
}
|
| 43 |
+
): void {
|
| 44 |
+
current_index = `${type}-${detail.index}`;
|
| 45 |
+
dispatch(type, detail);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
function handle_picker_click(): void {
|
| 49 |
+
dispatch("select", { index: null, color: selected_color });
|
| 50 |
+
color_picker = !color_picker;
|
| 51 |
+
}
|
| 52 |
+
</script>
|
| 53 |
+
|
| 54 |
+
{#if !color_picker}
|
| 55 |
+
<span class:lg={user_colors}></span>
|
| 56 |
+
{/if}
|
| 57 |
+
|
| 58 |
+
<div class="swatch-wrap">
|
| 59 |
+
<span class="icon-wrap">
|
| 60 |
+
<Palette />
|
| 61 |
+
</span>
|
| 62 |
+
<div>
|
| 63 |
+
{#if user_colors}
|
| 64 |
+
<div class="swatch">
|
| 65 |
+
{#each user_colors as color, i}
|
| 66 |
+
<button
|
| 67 |
+
on:click={() => handle_select("edit", { index: i, color })}
|
| 68 |
+
class="color"
|
| 69 |
+
class:empty={color === null}
|
| 70 |
+
style="background-color: {color}"
|
| 71 |
+
class:selected={`edit-${i}` === current_index}
|
| 72 |
+
></button>
|
| 73 |
+
{/each}
|
| 74 |
+
|
| 75 |
+
<button
|
| 76 |
+
on:click={handle_picker_click}
|
| 77 |
+
class="color colorpicker"
|
| 78 |
+
class:hidden={!color_picker}
|
| 79 |
+
></button>
|
| 80 |
+
</div>
|
| 81 |
+
{/if}
|
| 82 |
+
<menu class="swatch">
|
| 83 |
+
{#each _colors as color, i}
|
| 84 |
+
<button
|
| 85 |
+
on:click={() => handle_select("select", { index: i, color })}
|
| 86 |
+
class="color"
|
| 87 |
+
class:empty={color === null}
|
| 88 |
+
style="background-color: {color}"
|
| 89 |
+
class:selected={`select-${i}` === current_index}
|
| 90 |
+
></button>
|
| 91 |
+
{/each}
|
| 92 |
+
</menu>
|
| 93 |
+
</div>
|
| 94 |
+
</div>
|
| 95 |
+
|
| 96 |
+
<style>
|
| 97 |
+
.icon-wrap {
|
| 98 |
+
width: 18px;
|
| 99 |
+
margin-top: 6px;
|
| 100 |
+
|
| 101 |
+
margin-left: var(--size-4);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
.swatch-wrap {
|
| 105 |
+
display: flex;
|
| 106 |
+
justify-content: space-between;
|
| 107 |
+
align-items: flex-start;
|
| 108 |
+
}
|
| 109 |
+
span {
|
| 110 |
+
margin-top: 0px;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
span.lg {
|
| 114 |
+
margin-top: var(--spacing-xl);
|
| 115 |
+
}
|
| 116 |
+
.swatch {
|
| 117 |
+
display: flex;
|
| 118 |
+
gap: var(--size-2-5);
|
| 119 |
+
justify-content: space-around;
|
| 120 |
+
margin-bottom: var(--size-2);
|
| 121 |
+
margin-right: var(--size-6);
|
| 122 |
+
padding-left: var(--size-2);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
.empty {
|
| 126 |
+
border: 1px solid var(--block-border-color);
|
| 127 |
+
font-weight: var(--weight-bold);
|
| 128 |
+
display: flex;
|
| 129 |
+
justify-content: center;
|
| 130 |
+
align-items: center;
|
| 131 |
+
padding-top: 4px;
|
| 132 |
+
text-align: center;
|
| 133 |
+
font-size: var(--scale-0);
|
| 134 |
+
cursor: pointer;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.empty::after {
|
| 138 |
+
content: "+";
|
| 139 |
+
margin-bottom: var(--size-1);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
.color {
|
| 143 |
+
width: 30px;
|
| 144 |
+
height: 30px;
|
| 145 |
+
border-radius: 50%;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
.empty.selected,
|
| 149 |
+
.color.selected {
|
| 150 |
+
border: 2px solid var(--color-accent);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
.colorpicker {
|
| 154 |
+
border: 1px solid var(--block-border-color);
|
| 155 |
+
|
| 156 |
+
background: conic-gradient(
|
| 157 |
+
red,
|
| 158 |
+
#ff0 60deg,
|
| 159 |
+
lime 120deg,
|
| 160 |
+
cyan 180deg,
|
| 161 |
+
blue 240deg,
|
| 162 |
+
magenta 300deg,
|
| 163 |
+
red 360deg
|
| 164 |
+
);
|
| 165 |
+
overflow: hidden;
|
| 166 |
+
position: relative;
|
| 167 |
+
color: white;
|
| 168 |
+
cursor: pointer;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
.colorpicker::before {
|
| 172 |
+
content: "";
|
| 173 |
+
position: absolute;
|
| 174 |
+
width: 100%;
|
| 175 |
+
height: 100%;
|
| 176 |
+
background: rgba(0, 0, 0, 0.6);
|
| 177 |
+
opacity: 1;
|
| 178 |
+
transition: 0.1s;
|
| 179 |
+
top: 0;
|
| 180 |
+
left: 0;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.colorpicker::after {
|
| 184 |
+
display: flex;
|
| 185 |
+
justify-content: center;
|
| 186 |
+
align-content: center;
|
| 187 |
+
content: "⨯";
|
| 188 |
+
color: white;
|
| 189 |
+
font-size: var(--scale-5);
|
| 190 |
+
position: absolute;
|
| 191 |
+
width: 100%;
|
| 192 |
+
height: 100%;
|
| 193 |
+
transform: translateY(-17px);
|
| 194 |
+
opacity: 1;
|
| 195 |
+
transition: 0.1s;
|
| 196 |
+
top: 0;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
.colorpicker.hidden::after,
|
| 200 |
+
.colorpicker.hidden::before {
|
| 201 |
+
opacity: 0;
|
| 202 |
+
}
|
| 203 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/Crop.svelte
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { getContext, onDestroy, onMount, tick } from "svelte";
|
| 3 |
+
|
| 4 |
+
import { type ToolContext, TOOL_KEY } from "./Tools.svelte";
|
| 5 |
+
import { type EditorContext, EDITOR_KEY } from "../ImageEditor.svelte";
|
| 6 |
+
import { crop_canvas, resize_and_reposition, type CropCommand } from "./crop";
|
| 7 |
+
|
| 8 |
+
import Cropper from "./Cropper.svelte";
|
| 9 |
+
|
| 10 |
+
const { active_tool, register_tool } = getContext<ToolContext>(TOOL_KEY);
|
| 11 |
+
const {
|
| 12 |
+
dimensions,
|
| 13 |
+
editor_box,
|
| 14 |
+
pixi,
|
| 15 |
+
crop,
|
| 16 |
+
command_manager,
|
| 17 |
+
current_history
|
| 18 |
+
} = getContext<EditorContext>(EDITOR_KEY);
|
| 19 |
+
|
| 20 |
+
let cropper: CropCommand | null;
|
| 21 |
+
|
| 22 |
+
export let crop_constraint: [number, number] | `${string}:${string}` | null;
|
| 23 |
+
|
| 24 |
+
let _crop_constraint: number | null = null;
|
| 25 |
+
$: {
|
| 26 |
+
if (typeof crop_constraint === "string") {
|
| 27 |
+
const [w, h] = crop_constraint.split(":");
|
| 28 |
+
_crop_constraint = parseInt(w) / parseInt(h);
|
| 29 |
+
} else if (Array.isArray(crop_constraint)) {
|
| 30 |
+
_crop_constraint = crop_constraint[0] / crop_constraint[1];
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
let w_p = 1;
|
| 35 |
+
let h_p = 1;
|
| 36 |
+
let l_p = 0;
|
| 37 |
+
let t_p = 0;
|
| 38 |
+
|
| 39 |
+
let current_opacity = 0;
|
| 40 |
+
|
| 41 |
+
let manually_cropped = false;
|
| 42 |
+
|
| 43 |
+
$: {
|
| 44 |
+
if (!manually_cropped && _crop_constraint && $pixi && $active_tool) {
|
| 45 |
+
requestAnimationFrame(() => {
|
| 46 |
+
initial_crop();
|
| 47 |
+
});
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
let c: CropCommand | null = null;
|
| 52 |
+
|
| 53 |
+
async function initial_crop(): Promise<void> {
|
| 54 |
+
if (c || $current_history.previous) return;
|
| 55 |
+
const { new_height, new_width, x_offset, y_offset } = resize_and_reposition(
|
| 56 |
+
$editor_box.child_width,
|
| 57 |
+
$editor_box.child_height,
|
| 58 |
+
"c",
|
| 59 |
+
_crop_constraint!,
|
| 60 |
+
|
| 61 |
+
$editor_box.child_width,
|
| 62 |
+
$editor_box.child_height
|
| 63 |
+
);
|
| 64 |
+
|
| 65 |
+
w_p = new_width / $editor_box.child_width;
|
| 66 |
+
h_p = new_height / $editor_box.child_height;
|
| 67 |
+
l_p = x_offset / $editor_box.child_width;
|
| 68 |
+
t_p = y_offset / $editor_box.child_height;
|
| 69 |
+
|
| 70 |
+
c = crop_canvas($pixi!.renderer, $pixi!.mask_container, crop, 0.2);
|
| 71 |
+
c.start(...$dimensions, current_crop, false);
|
| 72 |
+
|
| 73 |
+
c.continue(
|
| 74 |
+
[
|
| 75 |
+
l_p * $dimensions[0],
|
| 76 |
+
t_p * $dimensions[1],
|
| 77 |
+
w_p * $dimensions[0],
|
| 78 |
+
h_p * $dimensions[1]
|
| 79 |
+
],
|
| 80 |
+
false
|
| 81 |
+
);
|
| 82 |
+
c.stop();
|
| 83 |
+
|
| 84 |
+
c.execute();
|
| 85 |
+
c = null;
|
| 86 |
+
current_opacity = 0;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
function handle_crop(
|
| 90 |
+
type: "start" | "stop" | "continue",
|
| 91 |
+
|
| 92 |
+
{
|
| 93 |
+
x,
|
| 94 |
+
y,
|
| 95 |
+
width,
|
| 96 |
+
height
|
| 97 |
+
}: {
|
| 98 |
+
x: number;
|
| 99 |
+
y: number;
|
| 100 |
+
width: number;
|
| 101 |
+
height: number;
|
| 102 |
+
}
|
| 103 |
+
): void {
|
| 104 |
+
if (!$pixi) return;
|
| 105 |
+
|
| 106 |
+
if (type === "start") {
|
| 107 |
+
if (cropper) {
|
| 108 |
+
current_opacity = cropper.stop();
|
| 109 |
+
cropper = null;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
cropper = crop_canvas(
|
| 113 |
+
$pixi?.renderer,
|
| 114 |
+
$pixi.mask_container,
|
| 115 |
+
crop,
|
| 116 |
+
current_opacity
|
| 117 |
+
);
|
| 118 |
+
cropper.start(...$dimensions, current_crop);
|
| 119 |
+
} else if (type === "continue") {
|
| 120 |
+
if (!cropper) return;
|
| 121 |
+
cropper.continue([
|
| 122 |
+
x * $dimensions[0],
|
| 123 |
+
y * $dimensions[1],
|
| 124 |
+
width * $dimensions[0],
|
| 125 |
+
height * $dimensions[1]
|
| 126 |
+
]);
|
| 127 |
+
} else if (type === "stop") {
|
| 128 |
+
if (!cropper) return;
|
| 129 |
+
command_manager.execute(cropper);
|
| 130 |
+
}
|
| 131 |
+
manually_cropped = true;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
let measured = false;
|
| 135 |
+
|
| 136 |
+
function get_measurements(): void {
|
| 137 |
+
if (measured) return;
|
| 138 |
+
if (!$editor_box.child_height) return;
|
| 139 |
+
const _height = $editor_box.child_height;
|
| 140 |
+
const _width = $editor_box.child_width;
|
| 141 |
+
const _top = $editor_box.child_top - $editor_box.parent_top;
|
| 142 |
+
const _left = $editor_box.child_left - $editor_box.parent_left;
|
| 143 |
+
|
| 144 |
+
w_p = _width / $editor_box.child_width;
|
| 145 |
+
h_p = _height / $editor_box.child_height;
|
| 146 |
+
l_p =
|
| 147 |
+
(_left - $editor_box.child_left + $editor_box.parent_left) /
|
| 148 |
+
$editor_box.child_width;
|
| 149 |
+
t_p =
|
| 150 |
+
(_top - $editor_box.child_top + $editor_box.parent_top) /
|
| 151 |
+
$editor_box.child_height;
|
| 152 |
+
|
| 153 |
+
measured = true;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
let current_crop: [number, number, number, number];
|
| 157 |
+
$: current_crop = [
|
| 158 |
+
l_p * $dimensions[0],
|
| 159 |
+
t_p * $dimensions[1],
|
| 160 |
+
w_p * $dimensions[0],
|
| 161 |
+
h_p * $dimensions[1]
|
| 162 |
+
];
|
| 163 |
+
|
| 164 |
+
$: {
|
| 165 |
+
l_p = $crop[0];
|
| 166 |
+
t_p = $crop[1];
|
| 167 |
+
w_p = $crop[2];
|
| 168 |
+
h_p = $crop[3];
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
$: $editor_box && get_measurements();
|
| 172 |
+
|
| 173 |
+
const unregister = register_tool("crop");
|
| 174 |
+
onDestroy(unregister);
|
| 175 |
+
</script>
|
| 176 |
+
|
| 177 |
+
{#if $active_tool === "crop" && measured}
|
| 178 |
+
<Cropper
|
| 179 |
+
crop_constraint={_crop_constraint}
|
| 180 |
+
{w_p}
|
| 181 |
+
{h_p}
|
| 182 |
+
{l_p}
|
| 183 |
+
{t_p}
|
| 184 |
+
{editor_box}
|
| 185 |
+
on:crop_start={({ detail }) => handle_crop("start", detail)}
|
| 186 |
+
on:crop_continue={({ detail }) => handle_crop("continue", detail)}
|
| 187 |
+
on:crop_end={({ detail }) => handle_crop("stop", detail)}
|
| 188 |
+
/>
|
| 189 |
+
{/if}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/Handle.svelte
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { tick, createEventDispatcher } from "svelte";
|
| 3 |
+
|
| 4 |
+
export let type = "corner";
|
| 5 |
+
export let location: "tl" | "tr" | "bl" | "br" | "t" | "b" | "l" | "r";
|
| 6 |
+
|
| 7 |
+
export let x1 = 0;
|
| 8 |
+
export let y1 = 0;
|
| 9 |
+
export let x2 = 0;
|
| 10 |
+
export let y2 = 0;
|
| 11 |
+
|
| 12 |
+
let box: DOMRect;
|
| 13 |
+
let y_offset = 0;
|
| 14 |
+
let x_offset = 0;
|
| 15 |
+
const min = 100;
|
| 16 |
+
|
| 17 |
+
let active = false;
|
| 18 |
+
|
| 19 |
+
const dispatch = createEventDispatcher<{
|
| 20 |
+
change: {
|
| 21 |
+
top: number | undefined;
|
| 22 |
+
bottom: number | undefined;
|
| 23 |
+
left: number | undefined;
|
| 24 |
+
right: number | undefined;
|
| 25 |
+
};
|
| 26 |
+
}>();
|
| 27 |
+
export let dragging = false;
|
| 28 |
+
|
| 29 |
+
let el: HTMLDivElement;
|
| 30 |
+
|
| 31 |
+
function handle_mousedown(e: MouseEvent): void {
|
| 32 |
+
box = el.getBoundingClientRect();
|
| 33 |
+
active = true;
|
| 34 |
+
dragging = true;
|
| 35 |
+
|
| 36 |
+
if (["tl", "bl", "l"].includes(location)) x_offset = e.clientX - box.right;
|
| 37 |
+
if (["tl", "tr", "t"].includes(location)) y_offset = e.clientY - box.bottom;
|
| 38 |
+
if (["tr", "r", "br"].includes(location)) x_offset = e.clientX - box.left;
|
| 39 |
+
if (["br", "b", "bl"].includes(location)) y_offset = e.clientY - box.top;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
function handle_mousemove(e: MouseEvent): void {
|
| 43 |
+
if (!active) return;
|
| 44 |
+
const top_pos = e.clientY - y_offset;
|
| 45 |
+
const bottom_pos = e.clientY - y_offset;
|
| 46 |
+
const left_pos = e.clientX - x_offset;
|
| 47 |
+
const right_pos = e.clientX - x_offset;
|
| 48 |
+
|
| 49 |
+
if (["tl", "bl", "l"].includes(location)) {
|
| 50 |
+
x1 = left_pos;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
if (["tl", "tr", "t"].includes(location)) {
|
| 54 |
+
y1 = top_pos;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
if (["tr", "r", "br"].includes(location)) {
|
| 58 |
+
x2 = right_pos;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
if (["br", "b", "bl"].includes(location)) {
|
| 62 |
+
y2 = bottom_pos;
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
async function handle_mouseup(e: MouseEvent): Promise<void> {
|
| 67 |
+
await tick();
|
| 68 |
+
active = false;
|
| 69 |
+
dragging = false;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
function make_transform(
|
| 73 |
+
_location: typeof location,
|
| 74 |
+
x1: number,
|
| 75 |
+
x2: number,
|
| 76 |
+
y1: number,
|
| 77 |
+
y2: number
|
| 78 |
+
): string {
|
| 79 |
+
let t = undefined;
|
| 80 |
+
let l = undefined;
|
| 81 |
+
let r = undefined;
|
| 82 |
+
let b = undefined;
|
| 83 |
+
|
| 84 |
+
if (box) {
|
| 85 |
+
if (["tl", "l", "bl"].includes(_location)) {
|
| 86 |
+
l = x1;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
if (["tl", "t", "tr"].includes(_location)) {
|
| 90 |
+
t = y1;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
if (["tr", "r", "br"].includes(_location)) {
|
| 94 |
+
r = x2;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
if (["br", "b", "bl"].includes(_location)) {
|
| 98 |
+
b = y2;
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
dispatch("change", { top: t, bottom: b, left: l, right: r });
|
| 103 |
+
return "";
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
$: transform = make_transform(location, x1, x2, y1, y2);
|
| 107 |
+
</script>
|
| 108 |
+
|
| 109 |
+
<svelte:window on:mousemove={handle_mousemove} on:mouseup={handle_mouseup} />
|
| 110 |
+
|
| 111 |
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
| 112 |
+
<div class="hitbox {location}" on:mousedown={handle_mousedown} style:transform>
|
| 113 |
+
<div class="handle {type} {location}" bind:this={el}></div>
|
| 114 |
+
</div>
|
| 115 |
+
|
| 116 |
+
<style>
|
| 117 |
+
.hitbox {
|
| 118 |
+
position: absolute;
|
| 119 |
+
width: 50px;
|
| 120 |
+
height: 50px;
|
| 121 |
+
--hitbox-mid-offset: calc(50% - 25px);
|
| 122 |
+
--hitbox-corner-offset: -25px;
|
| 123 |
+
--handle-corner-offset: calc(50% - 5px);
|
| 124 |
+
--handle-mid-offset: calc(50% - 2px);
|
| 125 |
+
z-index: var(--layer-top);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
/* hitbox positions */
|
| 129 |
+
.hitbox.tl,
|
| 130 |
+
.hitbox.bl,
|
| 131 |
+
.hitbox.l {
|
| 132 |
+
left: var(--hitbox-corner-offset);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
.hitbox.tr,
|
| 136 |
+
.hitbox.br,
|
| 137 |
+
.hitbox.r {
|
| 138 |
+
right: var(--hitbox-corner-offset);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
.hitbox.t,
|
| 142 |
+
.hitbox.tr,
|
| 143 |
+
.hitbox.tl {
|
| 144 |
+
top: var(--hitbox-corner-offset);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
.hitbox.t,
|
| 148 |
+
.hitbox.b {
|
| 149 |
+
left: var(--hitbox-mid-offset);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
.hitbox.l,
|
| 153 |
+
.hitbox.r {
|
| 154 |
+
top: var(--hitbox-mid-offset);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
.hitbox.b,
|
| 158 |
+
.hitbox.br,
|
| 159 |
+
.hitbox.bl {
|
| 160 |
+
bottom: var(--hitbox-corner-offset);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/* hitbox cursors */
|
| 164 |
+
|
| 165 |
+
.hitbox.tl,
|
| 166 |
+
.hitbox.br {
|
| 167 |
+
cursor: nwse-resize;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.hitbox.bl,
|
| 171 |
+
.hitbox.tr {
|
| 172 |
+
cursor: nesw-resize;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
.hitbox.l,
|
| 176 |
+
.hitbox.r {
|
| 177 |
+
cursor: ew-resize;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
.hitbox.t,
|
| 181 |
+
.hitbox.b {
|
| 182 |
+
cursor: ns-resize;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/* Visual handles */
|
| 186 |
+
.handle {
|
| 187 |
+
position: absolute;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
/* square to fill in corners */
|
| 191 |
+
.corner {
|
| 192 |
+
width: 4px;
|
| 193 |
+
height: 4px;
|
| 194 |
+
background: black;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
/* handle segment positions */
|
| 198 |
+
.handle.tl,
|
| 199 |
+
.handle.bl,
|
| 200 |
+
.handle.l {
|
| 201 |
+
left: var(--handle-corner-offset);
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
.handle.tr,
|
| 205 |
+
.handle.r,
|
| 206 |
+
.handle.br {
|
| 207 |
+
right: var(--handle-corner-offset);
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
.handle.tr,
|
| 211 |
+
.handle.t,
|
| 212 |
+
.handle.tl {
|
| 213 |
+
top: var(--handle-corner-offset);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
.handle.br,
|
| 217 |
+
.handle.b,
|
| 218 |
+
.handle.bl {
|
| 219 |
+
bottom: var(--handle-corner-offset);
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
.handle.l,
|
| 223 |
+
.handle.r {
|
| 224 |
+
bottom: var(--handle-mid-offset);
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
.handle.t,
|
| 228 |
+
.handle.b {
|
| 229 |
+
left: var(--handle-mid-offset);
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
.handle::before {
|
| 233 |
+
position: absolute;
|
| 234 |
+
content: "";
|
| 235 |
+
width: 20px;
|
| 236 |
+
height: 4px;
|
| 237 |
+
background: black;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
.handle::after {
|
| 241 |
+
position: absolute;
|
| 242 |
+
content: "";
|
| 243 |
+
width: 4px;
|
| 244 |
+
height: 20px;
|
| 245 |
+
background: black;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
.handle.t::before,
|
| 249 |
+
.handle.b::before {
|
| 250 |
+
width: 30px;
|
| 251 |
+
left: -14px;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
.handle.r::after,
|
| 255 |
+
.handle.l::after {
|
| 256 |
+
height: 30px;
|
| 257 |
+
top: -13px;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
.handle.l::before,
|
| 261 |
+
.handle.r::before {
|
| 262 |
+
content: none;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
.handle.t::after,
|
| 266 |
+
.handle.b::after {
|
| 267 |
+
content: none;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
.handle.tr::before,
|
| 271 |
+
.handle.br::before {
|
| 272 |
+
right: 4px;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
.handle.tl::before,
|
| 276 |
+
.handle.bl::before {
|
| 277 |
+
left: 4px;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
.handle.tl::after,
|
| 281 |
+
.handle.tr::after {
|
| 282 |
+
top: 4px;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
.handle.bl::after,
|
| 286 |
+
.handle.br::after {
|
| 287 |
+
bottom: 4px;
|
| 288 |
+
}
|
| 289 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/IconButton.svelte
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { type ComponentType } from "svelte";
|
| 3 |
+
export let Icon: ComponentType;
|
| 4 |
+
export let label = "";
|
| 5 |
+
export let show_label = false;
|
| 6 |
+
export let pending = false;
|
| 7 |
+
export let size: "small" | "large" | "medium" = "small";
|
| 8 |
+
export let padded = true;
|
| 9 |
+
export let highlight = false;
|
| 10 |
+
export let disabled = false;
|
| 11 |
+
export let hasPopup = false;
|
| 12 |
+
export let color = "var(--block-label-text-color)";
|
| 13 |
+
export let transparent = false;
|
| 14 |
+
export let background = "var(--background-fill-primary)";
|
| 15 |
+
export let offset = 0;
|
| 16 |
+
$: _color = highlight ? "var(--color-accent)" : color;
|
| 17 |
+
</script>
|
| 18 |
+
|
| 19 |
+
<button
|
| 20 |
+
{disabled}
|
| 21 |
+
on:click
|
| 22 |
+
aria-label={label}
|
| 23 |
+
aria-haspopup={hasPopup}
|
| 24 |
+
title={label}
|
| 25 |
+
class:pending
|
| 26 |
+
class:padded
|
| 27 |
+
class:highlight
|
| 28 |
+
class:transparent
|
| 29 |
+
style:color={!disabled && _color ? _color : "var(--block-label-text-color)"}
|
| 30 |
+
style:--bg-color={!disabled ? background : "auto"}
|
| 31 |
+
style:margin-left={offset + "px"}
|
| 32 |
+
>
|
| 33 |
+
{#if show_label}<span>{label}</span>{/if}
|
| 34 |
+
<div
|
| 35 |
+
class:small={size === "small"}
|
| 36 |
+
class:large={size === "large"}
|
| 37 |
+
class:medium={size === "medium"}
|
| 38 |
+
>
|
| 39 |
+
<Icon />
|
| 40 |
+
</div>
|
| 41 |
+
</button>
|
| 42 |
+
|
| 43 |
+
<style>
|
| 44 |
+
button {
|
| 45 |
+
display: flex;
|
| 46 |
+
justify-content: center;
|
| 47 |
+
align-items: center;
|
| 48 |
+
gap: 1px;
|
| 49 |
+
z-index: var(--layer-2);
|
| 50 |
+
/* background: var(--background-fill-primary); */
|
| 51 |
+
border-radius: var(--radius-sm);
|
| 52 |
+
color: var(--block-label-text-color);
|
| 53 |
+
border: 1px solid transparent;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
button[disabled] {
|
| 57 |
+
opacity: 0.5;
|
| 58 |
+
box-shadow: none;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
button[disabled]:hover {
|
| 62 |
+
cursor: not-allowed;
|
| 63 |
+
/* border: 1px solid var(--button-secondary-border-color); */
|
| 64 |
+
/* padding: 2px; */
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.padded {
|
| 68 |
+
padding: 2px;
|
| 69 |
+
background: var(--bg-color);
|
| 70 |
+
box-shadow: var(--shadow-drop);
|
| 71 |
+
border: 1px solid var(--button-secondary-border-color);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
button:hover,
|
| 75 |
+
button.highlight {
|
| 76 |
+
cursor: pointer;
|
| 77 |
+
color: var(--color-accent);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
.padded:hover {
|
| 81 |
+
border: 2px solid var(--button-secondary-border-color-hover);
|
| 82 |
+
padding: 1px;
|
| 83 |
+
color: var(--block-label-text-color);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
span {
|
| 87 |
+
padding: 0px 1px;
|
| 88 |
+
font-size: 10px;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
div {
|
| 92 |
+
padding: 2px;
|
| 93 |
+
display: flex;
|
| 94 |
+
align-items: flex-end;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
.small {
|
| 98 |
+
width: 14px;
|
| 99 |
+
height: 14px;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.medium {
|
| 103 |
+
width: 20px;
|
| 104 |
+
height: 20px;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.large {
|
| 108 |
+
width: 22px;
|
| 109 |
+
height: 22px;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
.pending {
|
| 113 |
+
animation: flash 0.5s infinite;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
@keyframes flash {
|
| 117 |
+
0% {
|
| 118 |
+
opacity: 0.5;
|
| 119 |
+
}
|
| 120 |
+
50% {
|
| 121 |
+
opacity: 1;
|
| 122 |
+
}
|
| 123 |
+
100% {
|
| 124 |
+
opacity: 0.5;
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
.transparent {
|
| 129 |
+
background: transparent;
|
| 130 |
+
border: none;
|
| 131 |
+
box-shadow: none;
|
| 132 |
+
}
|
| 133 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/Sources.svelte
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { getContext, onMount, tick, createEventDispatcher } from "svelte";
|
| 3 |
+
import { type ToolContext, TOOL_KEY } from "./Tools.svelte";
|
| 4 |
+
import { type EditorContext, EDITOR_KEY } from "../ImageEditor.svelte";
|
| 5 |
+
import {
|
| 6 |
+
Image as ImageIcon,
|
| 7 |
+
Webcam as WebcamIcon,
|
| 8 |
+
ImagePaste
|
| 9 |
+
} from "@gradio/icons";
|
| 10 |
+
import { Upload } from "@gradio/upload";
|
| 11 |
+
import { Webcam } from "@gradio/image";
|
| 12 |
+
import { type I18nFormatter } from "@gradio/utils";
|
| 13 |
+
import { default as IconButton } from "./IconButton.svelte";
|
| 14 |
+
import { type Client } from "@gradio/client";
|
| 15 |
+
|
| 16 |
+
import { add_bg_color, add_bg_image } from "./sources";
|
| 17 |
+
import type { FileData } from "@gradio/client";
|
| 18 |
+
|
| 19 |
+
export let background_file: FileData | null;
|
| 20 |
+
export let root: string;
|
| 21 |
+
export let sources: ("upload" | "webcam" | "clipboard")[] = [
|
| 22 |
+
"upload",
|
| 23 |
+
"webcam",
|
| 24 |
+
"clipboard"
|
| 25 |
+
];
|
| 26 |
+
export let mirror_webcam = true;
|
| 27 |
+
export let i18n: I18nFormatter;
|
| 28 |
+
export let upload: Client["upload"];
|
| 29 |
+
export let stream_handler: Client["stream"];
|
| 30 |
+
export let dragging: boolean;
|
| 31 |
+
|
| 32 |
+
const { active_tool } = getContext<ToolContext>(TOOL_KEY);
|
| 33 |
+
const { pixi, dimensions, register_context, reset, editor_box } =
|
| 34 |
+
getContext<EditorContext>(EDITOR_KEY);
|
| 35 |
+
|
| 36 |
+
export let active_mode: "webcam" | "color" | null = null;
|
| 37 |
+
let background: Blob | File | null;
|
| 38 |
+
|
| 39 |
+
const dispatch = createEventDispatcher<{
|
| 40 |
+
upload: never;
|
| 41 |
+
}>();
|
| 42 |
+
|
| 43 |
+
const sources_meta = {
|
| 44 |
+
upload: {
|
| 45 |
+
icon: ImageIcon,
|
| 46 |
+
label: "Upload",
|
| 47 |
+
order: 0,
|
| 48 |
+
id: "bg_upload",
|
| 49 |
+
cb() {
|
| 50 |
+
upload_component.open_file_upload();
|
| 51 |
+
|
| 52 |
+
$active_tool = "bg";
|
| 53 |
+
}
|
| 54 |
+
},
|
| 55 |
+
webcam: {
|
| 56 |
+
icon: WebcamIcon,
|
| 57 |
+
label: "Webcam",
|
| 58 |
+
order: 1,
|
| 59 |
+
id: "bg_webcam",
|
| 60 |
+
cb() {
|
| 61 |
+
active_mode = "webcam";
|
| 62 |
+
$active_tool = "bg";
|
| 63 |
+
}
|
| 64 |
+
},
|
| 65 |
+
clipboard: {
|
| 66 |
+
icon: ImagePaste,
|
| 67 |
+
label: "Paste",
|
| 68 |
+
order: 2,
|
| 69 |
+
id: "bg_clipboard",
|
| 70 |
+
cb() {
|
| 71 |
+
process_clipboard();
|
| 72 |
+
$active_tool = null;
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
} as const;
|
| 76 |
+
|
| 77 |
+
$: sources_list = sources
|
| 78 |
+
.map((src) => sources_meta[src])
|
| 79 |
+
.sort((a, b) => a.order - b.order);
|
| 80 |
+
|
| 81 |
+
let upload_component: Upload;
|
| 82 |
+
|
| 83 |
+
async function process_clipboard(): Promise<void> {
|
| 84 |
+
const items = await navigator.clipboard.read();
|
| 85 |
+
|
| 86 |
+
for (let i = 0; i < items.length; i++) {
|
| 87 |
+
const type = items[i].types.find((t) => t.startsWith("image/"));
|
| 88 |
+
if (type) {
|
| 89 |
+
const blob = await items[i].getType(type);
|
| 90 |
+
|
| 91 |
+
background = blob || null;
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
function handle_upload(e: CustomEvent<Blob | any>): void {
|
| 97 |
+
const file_data = e.detail;
|
| 98 |
+
background = file_data;
|
| 99 |
+
active_mode = null;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
let should_reset = true;
|
| 103 |
+
|
| 104 |
+
async function set_background(): Promise<void> {
|
| 105 |
+
if (!$pixi) return;
|
| 106 |
+
if (background) {
|
| 107 |
+
const add_image = add_bg_image(
|
| 108 |
+
$pixi.background_container,
|
| 109 |
+
$pixi.renderer,
|
| 110 |
+
background,
|
| 111 |
+
$pixi.resize
|
| 112 |
+
);
|
| 113 |
+
$dimensions = await add_image.start();
|
| 114 |
+
|
| 115 |
+
if (should_reset) {
|
| 116 |
+
reset(false, $dimensions);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
add_image.execute();
|
| 120 |
+
|
| 121 |
+
should_reset = true;
|
| 122 |
+
|
| 123 |
+
await tick();
|
| 124 |
+
bg = true;
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
async function process_bg_file(file: FileData | null): Promise<void> {
|
| 129 |
+
if (!file || !file.url) return;
|
| 130 |
+
should_reset = false;
|
| 131 |
+
|
| 132 |
+
const blob_res = await fetch(file.url);
|
| 133 |
+
const blob = await blob_res.blob();
|
| 134 |
+
background = blob;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
function handle_key(e: KeyboardEvent): void {
|
| 138 |
+
if (e.key === "Escape") {
|
| 139 |
+
active_mode = null;
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
$: background && set_background();
|
| 144 |
+
$: process_bg_file(background_file);
|
| 145 |
+
|
| 146 |
+
export let bg = false;
|
| 147 |
+
|
| 148 |
+
register_context("bg", {
|
| 149 |
+
init_fn: () => {
|
| 150 |
+
if (!$pixi) return;
|
| 151 |
+
|
| 152 |
+
const add_image = add_bg_color(
|
| 153 |
+
$pixi.background_container,
|
| 154 |
+
$pixi.renderer,
|
| 155 |
+
"black",
|
| 156 |
+
...$dimensions,
|
| 157 |
+
$pixi.resize
|
| 158 |
+
);
|
| 159 |
+
$dimensions = add_image.start();
|
| 160 |
+
add_image.execute();
|
| 161 |
+
},
|
| 162 |
+
reset_fn: () => {}
|
| 163 |
+
});
|
| 164 |
+
</script>
|
| 165 |
+
|
| 166 |
+
<svelte:window on:keydown={handle_key} />
|
| 167 |
+
|
| 168 |
+
{#if sources.length}
|
| 169 |
+
<div class="source-wrap">
|
| 170 |
+
{#each sources_list as { icon, label, id, cb } (id)}
|
| 171 |
+
<IconButton
|
| 172 |
+
Icon={icon}
|
| 173 |
+
size="medium"
|
| 174 |
+
padded={false}
|
| 175 |
+
label={label + " button"}
|
| 176 |
+
hasPopup={true}
|
| 177 |
+
transparent={true}
|
| 178 |
+
on:click={cb}
|
| 179 |
+
/>
|
| 180 |
+
{/each}
|
| 181 |
+
<span class="sep"></span>
|
| 182 |
+
</div>
|
| 183 |
+
<div
|
| 184 |
+
class="upload-container"
|
| 185 |
+
class:click-disabled={!!bg ||
|
| 186 |
+
active_mode === "webcam" ||
|
| 187 |
+
$active_tool !== "bg"}
|
| 188 |
+
style:height="{$editor_box.child_height +
|
| 189 |
+
($editor_box.child_top - $editor_box.parent_top)}px"
|
| 190 |
+
>
|
| 191 |
+
<Upload
|
| 192 |
+
hidden={bg || active_mode === "webcam" || $active_tool !== "bg"}
|
| 193 |
+
bind:this={upload_component}
|
| 194 |
+
filetype="image/*"
|
| 195 |
+
on:load={handle_upload}
|
| 196 |
+
on:error
|
| 197 |
+
bind:dragging
|
| 198 |
+
{root}
|
| 199 |
+
disable_click={!sources.includes("upload")}
|
| 200 |
+
format="blob"
|
| 201 |
+
{upload}
|
| 202 |
+
{stream_handler}
|
| 203 |
+
></Upload>
|
| 204 |
+
{#if active_mode === "webcam"}
|
| 205 |
+
<div
|
| 206 |
+
class="modal"
|
| 207 |
+
style:max-width="{$editor_box.child_width}px"
|
| 208 |
+
style:max-height="{$editor_box.child_height}px"
|
| 209 |
+
style:top="{$editor_box.child_top - $editor_box.parent_top}px"
|
| 210 |
+
>
|
| 211 |
+
<div class="modal-inner">
|
| 212 |
+
<Webcam
|
| 213 |
+
{upload}
|
| 214 |
+
{root}
|
| 215 |
+
on:capture={handle_upload}
|
| 216 |
+
on:error
|
| 217 |
+
on:drag
|
| 218 |
+
{mirror_webcam}
|
| 219 |
+
streaming={false}
|
| 220 |
+
mode="image"
|
| 221 |
+
include_audio={false}
|
| 222 |
+
{i18n}
|
| 223 |
+
/>
|
| 224 |
+
</div>
|
| 225 |
+
</div>
|
| 226 |
+
{/if}
|
| 227 |
+
</div>
|
| 228 |
+
{/if}
|
| 229 |
+
|
| 230 |
+
<style>
|
| 231 |
+
.modal {
|
| 232 |
+
position: absolute;
|
| 233 |
+
height: 100%;
|
| 234 |
+
width: 100%;
|
| 235 |
+
left: 0;
|
| 236 |
+
right: 0;
|
| 237 |
+
margin: auto;
|
| 238 |
+
z-index: var(--layer-top);
|
| 239 |
+
display: flex;
|
| 240 |
+
align-items: center;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
.modal-inner {
|
| 244 |
+
width: 100%;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
.sep {
|
| 248 |
+
height: 12px;
|
| 249 |
+
background-color: var(--block-border-color);
|
| 250 |
+
width: 1px;
|
| 251 |
+
display: block;
|
| 252 |
+
margin-left: var(--spacing-xl);
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
.source-wrap {
|
| 256 |
+
display: flex;
|
| 257 |
+
justify-content: center;
|
| 258 |
+
align-items: center;
|
| 259 |
+
margin-left: var(--spacing-lg);
|
| 260 |
+
height: 100%;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
.upload-container {
|
| 264 |
+
position: absolute;
|
| 265 |
+
height: 100%;
|
| 266 |
+
flex-shrink: 1;
|
| 267 |
+
max-height: 100%;
|
| 268 |
+
width: 100%;
|
| 269 |
+
left: 0;
|
| 270 |
+
top: 0;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
.upload-container.click-disabled {
|
| 274 |
+
pointer-events: none;
|
| 275 |
+
}
|
| 276 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/Tools.svelte
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts" context="module">
|
| 2 |
+
import type {
|
| 3 |
+
Subscriber,
|
| 4 |
+
Invalidator,
|
| 5 |
+
Unsubscriber,
|
| 6 |
+
Writable
|
| 7 |
+
} from "svelte/store";
|
| 8 |
+
import type { tool } from "../tools/";
|
| 9 |
+
|
| 10 |
+
export const TOOL_KEY = Symbol("tool");
|
| 11 |
+
|
| 12 |
+
type upload_tool = "bg_webcam" | "bg_upload" | "bg_clipboard" | "bg_color";
|
| 13 |
+
type transform_tool = "crop" | "rotate";
|
| 14 |
+
type brush_tool = "brush_color" | "brush_size";
|
| 15 |
+
type eraser_tool = "eraser_size";
|
| 16 |
+
|
| 17 |
+
export interface ToolOptions {
|
| 18 |
+
order: number;
|
| 19 |
+
label: string;
|
| 20 |
+
icon: typeof Image;
|
| 21 |
+
cb: (...args: any[]) => void;
|
| 22 |
+
id: upload_tool | transform_tool | brush_tool | eraser_tool;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
export interface ToolMeta {
|
| 26 |
+
default: upload_tool | transform_tool | brush_tool | eraser_tool | null;
|
| 27 |
+
options: ToolOptions[];
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
export interface ToolContext {
|
| 31 |
+
register_tool: (type: tool, opts?: { cb: () => void }) => () => void;
|
| 32 |
+
active_tool: {
|
| 33 |
+
set: (tool: tool) => void;
|
| 34 |
+
subscribe(
|
| 35 |
+
this: void,
|
| 36 |
+
run: Subscriber<tool | null>,
|
| 37 |
+
invalidate?: Invalidator<tool | null>
|
| 38 |
+
): Unsubscriber;
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
current_color: Writable<string>;
|
| 42 |
+
}
|
| 43 |
+
</script>
|
| 44 |
+
|
| 45 |
+
<script lang="ts">
|
| 46 |
+
import { Toolbar } from "@gradio/atoms";
|
| 47 |
+
import { default as IconButton } from "./IconButton.svelte";
|
| 48 |
+
import { getContext, setContext } from "svelte";
|
| 49 |
+
import { writable } from "svelte/store";
|
| 50 |
+
import { EDITOR_KEY, type EditorContext } from "../ImageEditor.svelte";
|
| 51 |
+
import { Image, Crop, Brush, Erase } from "@gradio/icons";
|
| 52 |
+
import { type I18nFormatter } from "@gradio/utils";
|
| 53 |
+
|
| 54 |
+
const { active_tool, toolbar_box, editor_box } =
|
| 55 |
+
getContext<EditorContext>(EDITOR_KEY);
|
| 56 |
+
|
| 57 |
+
export let i18n: I18nFormatter;
|
| 58 |
+
|
| 59 |
+
let tools: tool[] = [];
|
| 60 |
+
|
| 61 |
+
const cbs: Record<string, () => void> = {};
|
| 62 |
+
let current_color = writable("#000000");
|
| 63 |
+
const tool_context: ToolContext = {
|
| 64 |
+
current_color,
|
| 65 |
+
register_tool: (type: tool, opts?: { cb: () => void }) => {
|
| 66 |
+
tools = [...tools, type];
|
| 67 |
+
if (opts?.cb) {
|
| 68 |
+
cbs[type] = opts.cb;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
return () => {
|
| 72 |
+
tools = tools.filter((tool) => tool !== type);
|
| 73 |
+
};
|
| 74 |
+
},
|
| 75 |
+
|
| 76 |
+
active_tool: {
|
| 77 |
+
subscribe: active_tool.subscribe,
|
| 78 |
+
set: active_tool.set
|
| 79 |
+
}
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
setContext<ToolContext>(TOOL_KEY, tool_context);
|
| 83 |
+
|
| 84 |
+
const tools_meta: Record<
|
| 85 |
+
tool,
|
| 86 |
+
{
|
| 87 |
+
order: number;
|
| 88 |
+
label: string;
|
| 89 |
+
icon: typeof Image;
|
| 90 |
+
}
|
| 91 |
+
> = {
|
| 92 |
+
crop: {
|
| 93 |
+
order: 1,
|
| 94 |
+
label: i18n("Transform"),
|
| 95 |
+
icon: Crop
|
| 96 |
+
},
|
| 97 |
+
draw: {
|
| 98 |
+
order: 2,
|
| 99 |
+
label: i18n("Draw"),
|
| 100 |
+
icon: Brush
|
| 101 |
+
},
|
| 102 |
+
erase: {
|
| 103 |
+
order: 2,
|
| 104 |
+
label: i18n("Erase"),
|
| 105 |
+
icon: Erase
|
| 106 |
+
},
|
| 107 |
+
bg: {
|
| 108 |
+
order: 0,
|
| 109 |
+
label: i18n("Background"),
|
| 110 |
+
icon: Image
|
| 111 |
+
}
|
| 112 |
+
} as const;
|
| 113 |
+
|
| 114 |
+
let toolbar_width: number;
|
| 115 |
+
let toolbar_wrap: HTMLDivElement;
|
| 116 |
+
|
| 117 |
+
$: toolbar_width, $editor_box, get_dimensions();
|
| 118 |
+
|
| 119 |
+
function get_dimensions(): void {
|
| 120 |
+
if (!toolbar_wrap) return;
|
| 121 |
+
$toolbar_box = toolbar_wrap.getBoundingClientRect();
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
function handle_click(e: Event, tool: tool): void {
|
| 125 |
+
e.stopPropagation();
|
| 126 |
+
$active_tool = tool;
|
| 127 |
+
cbs[tool] && cbs[tool]();
|
| 128 |
+
}
|
| 129 |
+
</script>
|
| 130 |
+
|
| 131 |
+
<slot />
|
| 132 |
+
|
| 133 |
+
<div
|
| 134 |
+
class="toolbar-wrap"
|
| 135 |
+
bind:clientWidth={toolbar_width}
|
| 136 |
+
bind:this={toolbar_wrap}
|
| 137 |
+
>
|
| 138 |
+
<Toolbar show_border={false}>
|
| 139 |
+
{#each tools as tool (tool)}
|
| 140 |
+
<IconButton
|
| 141 |
+
highlight={$active_tool === tool}
|
| 142 |
+
on:click={(e) => handle_click(e, tool)}
|
| 143 |
+
Icon={tools_meta[tool].icon}
|
| 144 |
+
size="medium"
|
| 145 |
+
padded={false}
|
| 146 |
+
label={tools_meta[tool].label + " button"}
|
| 147 |
+
transparent={true}
|
| 148 |
+
offset={tool === "draw" ? -2 : tool === "erase" ? -6 : 0}
|
| 149 |
+
/>
|
| 150 |
+
{/each}
|
| 151 |
+
</Toolbar>
|
| 152 |
+
</div>
|
| 153 |
+
|
| 154 |
+
<style>
|
| 155 |
+
.toolbar-wrap {
|
| 156 |
+
display: flex;
|
| 157 |
+
justify-content: center;
|
| 158 |
+
align-items: center;
|
| 159 |
+
margin-left: var(--spacing-xl);
|
| 160 |
+
height: 100%;
|
| 161 |
+
}
|
| 162 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/brush.ts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
Container,
|
| 3 |
+
Graphics,
|
| 4 |
+
Color,
|
| 5 |
+
type ColorSource,
|
| 6 |
+
type IRenderer,
|
| 7 |
+
RenderTexture,
|
| 8 |
+
Sprite
|
| 9 |
+
} from "pixi.js";
|
| 10 |
+
|
| 11 |
+
import type { LayerScene } from "../layers/utils";
|
| 12 |
+
import { type Command } from "../utils/commands";
|
| 13 |
+
import { make_graphics } from "../utils/pixi";
|
| 14 |
+
|
| 15 |
+
export interface DrawCommand extends Command {
|
| 16 |
+
/**
|
| 17 |
+
* sets the initial state to begin drawing
|
| 18 |
+
* @param options the options for drawing
|
| 19 |
+
* @returns
|
| 20 |
+
*/
|
| 21 |
+
start: (options: DrawOptions) => void;
|
| 22 |
+
/**
|
| 23 |
+
* continues drawing, smoothly interpolating between points where necessary
|
| 24 |
+
* @param options the options for drawing
|
| 25 |
+
* @returns
|
| 26 |
+
*/
|
| 27 |
+
continue: (options: Points) => void;
|
| 28 |
+
/**
|
| 29 |
+
* stops drawing
|
| 30 |
+
* @returns
|
| 31 |
+
*/
|
| 32 |
+
stop: () => void;
|
| 33 |
+
/**
|
| 34 |
+
* Whether or not the user is currently drawing.
|
| 35 |
+
*/
|
| 36 |
+
drawing: boolean;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Coordinates for a draw or erase path.
|
| 41 |
+
*/
|
| 42 |
+
interface Points {
|
| 43 |
+
/**
|
| 44 |
+
* The x coordinate of the path.
|
| 45 |
+
*/
|
| 46 |
+
x: number;
|
| 47 |
+
/**
|
| 48 |
+
* The y coordinate of the path.
|
| 49 |
+
*/
|
| 50 |
+
y: number;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Options for drawing a path.
|
| 55 |
+
*/
|
| 56 |
+
interface DrawOptions extends Points {
|
| 57 |
+
/**
|
| 58 |
+
* The size of the brush.
|
| 59 |
+
*/
|
| 60 |
+
size: number;
|
| 61 |
+
/**
|
| 62 |
+
* The color of the brush.
|
| 63 |
+
*/
|
| 64 |
+
color?: ColorSource;
|
| 65 |
+
/**
|
| 66 |
+
* The opacity of the brush.
|
| 67 |
+
*/
|
| 68 |
+
opacity: number;
|
| 69 |
+
/**
|
| 70 |
+
* Whether or not to set the initial texture.
|
| 71 |
+
*/
|
| 72 |
+
set_initial_texture?: boolean;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* Draws a circle on the given graphics object.
|
| 77 |
+
* @param graphics the graphics object to draw on
|
| 78 |
+
* @param x the x coordinate of the circle
|
| 79 |
+
* @param y the y coordinate of the circle
|
| 80 |
+
* @param brush_color the color of the circle
|
| 81 |
+
* @param brush_size the radius of the circle
|
| 82 |
+
*/
|
| 83 |
+
function drawCircle(
|
| 84 |
+
graphics: Graphics,
|
| 85 |
+
x: number,
|
| 86 |
+
y: number,
|
| 87 |
+
brush_color: ColorSource = new Color("black"),
|
| 88 |
+
brush_size: number
|
| 89 |
+
): void {
|
| 90 |
+
const color = new Color(brush_color);
|
| 91 |
+
graphics.beginFill(color);
|
| 92 |
+
graphics.drawCircle(x, y, brush_size);
|
| 93 |
+
graphics.endFill();
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Interpolates between two points.
|
| 98 |
+
* @param point1 the first point
|
| 99 |
+
* @param point2 the second point
|
| 100 |
+
* @returns an array of points between the two points
|
| 101 |
+
*/
|
| 102 |
+
function interpolate(
|
| 103 |
+
point1: { x: number; y: number },
|
| 104 |
+
point2: { x: number; y: number }
|
| 105 |
+
): Points[] {
|
| 106 |
+
let points: Points[] = [];
|
| 107 |
+
const dx = point2.x - point1.x;
|
| 108 |
+
const dy = point2.y - point1.y;
|
| 109 |
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
| 110 |
+
const steps = Math.ceil(distance / 2);
|
| 111 |
+
const stepX = dx / steps;
|
| 112 |
+
const stepY = dy / steps;
|
| 113 |
+
|
| 114 |
+
for (let j = 0; j < steps; j++) {
|
| 115 |
+
const x = point1.x + j * stepX;
|
| 116 |
+
const y = point1.y + j * stepY;
|
| 117 |
+
points.push({ x, y });
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
return points;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
export function draw_path(
|
| 124 |
+
renderer: IRenderer,
|
| 125 |
+
stage: Container,
|
| 126 |
+
layer: LayerScene,
|
| 127 |
+
mode: "draw" | "erase"
|
| 128 |
+
): DrawCommand {
|
| 129 |
+
const paths: Points[] = [];
|
| 130 |
+
let initial_path: DrawOptions;
|
| 131 |
+
let graphics: Graphics;
|
| 132 |
+
let InitialTexture: RenderTexture;
|
| 133 |
+
|
| 134 |
+
let has_drawn = false;
|
| 135 |
+
let id = 0;
|
| 136 |
+
|
| 137 |
+
return {
|
| 138 |
+
drawing: false,
|
| 139 |
+
start: function ({
|
| 140 |
+
x,
|
| 141 |
+
y,
|
| 142 |
+
size,
|
| 143 |
+
color = new Color("black"),
|
| 144 |
+
opacity,
|
| 145 |
+
set_initial_texture = true
|
| 146 |
+
}: DrawOptions) {
|
| 147 |
+
if (set_initial_texture) {
|
| 148 |
+
InitialTexture = RenderTexture.create({
|
| 149 |
+
width: layer.draw_texture.width,
|
| 150 |
+
height: layer.draw_texture.height
|
| 151 |
+
});
|
| 152 |
+
renderer.render(layer.composite, {
|
| 153 |
+
renderTexture: InitialTexture
|
| 154 |
+
});
|
| 155 |
+
}
|
| 156 |
+
initial_path = { x, y, size, color, opacity };
|
| 157 |
+
paths.push({ x, y });
|
| 158 |
+
graphics = make_graphics(id++);
|
| 159 |
+
|
| 160 |
+
drawCircle(graphics, x, y, color, size);
|
| 161 |
+
|
| 162 |
+
renderer.render(graphics, {
|
| 163 |
+
renderTexture:
|
| 164 |
+
mode === "draw" ? layer.draw_texture : layer.erase_texture,
|
| 165 |
+
clear: false
|
| 166 |
+
});
|
| 167 |
+
|
| 168 |
+
this.drawing = true;
|
| 169 |
+
},
|
| 170 |
+
continue: function ({ x, y }: Points) {
|
| 171 |
+
const last_point = paths[paths.length - 1];
|
| 172 |
+
const new_points = interpolate(last_point, { x, y });
|
| 173 |
+
|
| 174 |
+
for (let i = 0; i < new_points.length; i++) {
|
| 175 |
+
const { x, y } = new_points[i];
|
| 176 |
+
drawCircle(graphics, x, y, initial_path.color, initial_path.size);
|
| 177 |
+
paths.push({ x, y });
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
renderer.render(graphics, {
|
| 181 |
+
renderTexture:
|
| 182 |
+
mode === "draw" ? layer.draw_texture : layer.erase_texture,
|
| 183 |
+
clear: false
|
| 184 |
+
});
|
| 185 |
+
graphics.clear();
|
| 186 |
+
},
|
| 187 |
+
stop: function () {
|
| 188 |
+
const current_sketch = RenderTexture.create({
|
| 189 |
+
width: layer.draw_texture.width,
|
| 190 |
+
height: layer.draw_texture.height
|
| 191 |
+
});
|
| 192 |
+
|
| 193 |
+
renderer.render(layer.composite, {
|
| 194 |
+
renderTexture: current_sketch
|
| 195 |
+
});
|
| 196 |
+
|
| 197 |
+
renderer.render(new Sprite(current_sketch), {
|
| 198 |
+
renderTexture: layer.draw_texture
|
| 199 |
+
});
|
| 200 |
+
|
| 201 |
+
const clear_graphics = new Graphics()
|
| 202 |
+
.beginFill(0x000000, 0) // Use a fill color with 0 alpha for transparency
|
| 203 |
+
.drawRect(0, 0, layer.erase_texture.width, layer.erase_texture.height)
|
| 204 |
+
.endFill();
|
| 205 |
+
|
| 206 |
+
renderer.render(clear_graphics, {
|
| 207 |
+
renderTexture: layer.erase_texture,
|
| 208 |
+
clear: true
|
| 209 |
+
});
|
| 210 |
+
|
| 211 |
+
has_drawn = true;
|
| 212 |
+
this.drawing = false;
|
| 213 |
+
},
|
| 214 |
+
execute: function () {
|
| 215 |
+
if (!has_drawn) {
|
| 216 |
+
for (let i = 1; i < paths.length; i++) {
|
| 217 |
+
const { x, y } = paths[i];
|
| 218 |
+
drawCircle(graphics, x, y, initial_path.color, initial_path.size);
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
renderer.render(graphics, {
|
| 222 |
+
renderTexture:
|
| 223 |
+
mode === "draw" ? layer.draw_texture : layer.erase_texture,
|
| 224 |
+
clear: false
|
| 225 |
+
});
|
| 226 |
+
|
| 227 |
+
this.stop!();
|
| 228 |
+
}
|
| 229 |
+
},
|
| 230 |
+
undo: function () {
|
| 231 |
+
const clear_graphics = new Graphics()
|
| 232 |
+
.beginFill(0x000000, 0)
|
| 233 |
+
.drawRect(0, 0, layer.erase_texture.width, layer.erase_texture.height)
|
| 234 |
+
.endFill();
|
| 235 |
+
renderer.render(new Sprite(InitialTexture), {
|
| 236 |
+
renderTexture: layer.draw_texture
|
| 237 |
+
});
|
| 238 |
+
renderer.render(clear_graphics, {
|
| 239 |
+
renderTexture: layer.erase_texture,
|
| 240 |
+
clear: true
|
| 241 |
+
});
|
| 242 |
+
|
| 243 |
+
this.stop!();
|
| 244 |
+
has_drawn = false;
|
| 245 |
+
}
|
| 246 |
+
};
|
| 247 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/crop.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
Graphics,
|
| 3 |
+
type IRenderer,
|
| 4 |
+
type Container,
|
| 5 |
+
Sprite,
|
| 6 |
+
RenderTexture
|
| 7 |
+
} from "pixi.js";
|
| 8 |
+
import { type Command } from "../utils/commands";
|
| 9 |
+
import { spring } from "svelte/motion";
|
| 10 |
+
import type { Writable } from "svelte/store";
|
| 11 |
+
|
| 12 |
+
export interface CropCommand extends Command {
|
| 13 |
+
start: (
|
| 14 |
+
width: number,
|
| 15 |
+
height: number,
|
| 16 |
+
previous_crop: [number, number, number, number],
|
| 17 |
+
preview?: boolean,
|
| 18 |
+
set_previous?: boolean
|
| 19 |
+
) => void;
|
| 20 |
+
stop: () => number;
|
| 21 |
+
continue: (
|
| 22 |
+
crop_size: [number, number, number, number],
|
| 23 |
+
preview?: boolean
|
| 24 |
+
) => void;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
export function crop_canvas(
|
| 28 |
+
renderer: IRenderer,
|
| 29 |
+
mask_container: Container,
|
| 30 |
+
crop: Writable<[number, number, number, number]>,
|
| 31 |
+
current_opacity = 0
|
| 32 |
+
): CropCommand {
|
| 33 |
+
let text: RenderTexture;
|
| 34 |
+
let sprite: Sprite;
|
| 35 |
+
const mask_graphics = new Graphics();
|
| 36 |
+
let previous_crop: [number, number, number, number];
|
| 37 |
+
let final_crop: [number, number, number, number];
|
| 38 |
+
let width: number;
|
| 39 |
+
let height: number;
|
| 40 |
+
let alpha_spring = spring(current_opacity, {
|
| 41 |
+
stiffness: 0.1,
|
| 42 |
+
damping: 0.5
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
let spring_value = current_opacity;
|
| 46 |
+
alpha_spring.subscribe((value) => {
|
| 47 |
+
if (!final_crop) return;
|
| 48 |
+
spring_value = value;
|
| 49 |
+
crop_mask(width, height, final_crop, true);
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
function crop_mask(
|
| 53 |
+
width: number,
|
| 54 |
+
height: number,
|
| 55 |
+
crop_size: [number, number, number, number],
|
| 56 |
+
preview: boolean
|
| 57 |
+
): void {
|
| 58 |
+
mask_graphics.clear();
|
| 59 |
+
if (preview) {
|
| 60 |
+
mask_graphics.beginFill(0xffffff, spring_value);
|
| 61 |
+
mask_graphics.drawRect(0, 0, width, height);
|
| 62 |
+
mask_graphics.endFill();
|
| 63 |
+
}
|
| 64 |
+
mask_graphics.beginFill(0xffffff, 1);
|
| 65 |
+
mask_graphics.drawRect(...crop_size);
|
| 66 |
+
mask_graphics.endFill();
|
| 67 |
+
|
| 68 |
+
renderer.render(mask_graphics, {
|
| 69 |
+
renderTexture: text
|
| 70 |
+
});
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
let clean = true;
|
| 74 |
+
let stopped = false;
|
| 75 |
+
|
| 76 |
+
return {
|
| 77 |
+
start: (
|
| 78 |
+
_width: number,
|
| 79 |
+
_height: number,
|
| 80 |
+
_previous_crop: [number, number, number, number],
|
| 81 |
+
_preview = true,
|
| 82 |
+
set_previous = true
|
| 83 |
+
) => {
|
| 84 |
+
clean = false;
|
| 85 |
+
text = RenderTexture.create({
|
| 86 |
+
width: _width,
|
| 87 |
+
height: _height
|
| 88 |
+
});
|
| 89 |
+
|
| 90 |
+
crop_mask(_width, _height, _previous_crop, _preview);
|
| 91 |
+
sprite = new Sprite(text);
|
| 92 |
+
mask_container.mask = sprite;
|
| 93 |
+
width = _width;
|
| 94 |
+
height = _height;
|
| 95 |
+
if (set_previous)
|
| 96 |
+
previous_crop = JSON.parse(JSON.stringify(_previous_crop));
|
| 97 |
+
},
|
| 98 |
+
continue: (crop_size: [number, number, number, number], preview = true) => {
|
| 99 |
+
final_crop = JSON.parse(JSON.stringify(crop_size));
|
| 100 |
+
if (spring_value === 0.2) {
|
| 101 |
+
crop_mask(width, height, final_crop, preview);
|
| 102 |
+
} else {
|
| 103 |
+
alpha_spring.set(0.2);
|
| 104 |
+
}
|
| 105 |
+
},
|
| 106 |
+
|
| 107 |
+
undo() {
|
| 108 |
+
this.start(width, height, previous_crop, false);
|
| 109 |
+
crop.set([
|
| 110 |
+
previous_crop[0] / width,
|
| 111 |
+
previous_crop[1] / height,
|
| 112 |
+
previous_crop[2] / width,
|
| 113 |
+
previous_crop[3] / height
|
| 114 |
+
]);
|
| 115 |
+
clean = true;
|
| 116 |
+
},
|
| 117 |
+
stop() {
|
| 118 |
+
stopped = true;
|
| 119 |
+
return spring_value;
|
| 120 |
+
},
|
| 121 |
+
execute() {
|
| 122 |
+
if (clean) {
|
| 123 |
+
this.start(width, height, final_crop, false);
|
| 124 |
+
|
| 125 |
+
crop.set([
|
| 126 |
+
final_crop[0] / width,
|
| 127 |
+
final_crop[1] / height,
|
| 128 |
+
final_crop[2] / width,
|
| 129 |
+
final_crop[3] / height
|
| 130 |
+
]);
|
| 131 |
+
clean = true;
|
| 132 |
+
} else {
|
| 133 |
+
if (!stopped) {
|
| 134 |
+
alpha_spring.set(0);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
crop.set([
|
| 138 |
+
final_crop[0] / width,
|
| 139 |
+
final_crop[1] / height,
|
| 140 |
+
final_crop[2] / width,
|
| 141 |
+
final_crop[3] / height
|
| 142 |
+
]);
|
| 143 |
+
|
| 144 |
+
clean = true;
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
};
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
export function resize_and_reposition(
|
| 151 |
+
original_width: number,
|
| 152 |
+
original_height: number,
|
| 153 |
+
anchor: "t" | "r" | "l" | "b" | "tl" | "tr" | "bl" | "br" | "c",
|
| 154 |
+
aspect_ratio: number,
|
| 155 |
+
max_width: number,
|
| 156 |
+
max_height: number
|
| 157 |
+
): {
|
| 158 |
+
new_width: number;
|
| 159 |
+
new_height: number;
|
| 160 |
+
x_offset: number;
|
| 161 |
+
y_offset: number;
|
| 162 |
+
} {
|
| 163 |
+
let new_width = original_width;
|
| 164 |
+
let new_height = original_height;
|
| 165 |
+
|
| 166 |
+
// Calculate new dimensions based on aspect ratio
|
| 167 |
+
if (anchor.includes("t") || anchor.includes("b") || anchor == "c") {
|
| 168 |
+
new_width = original_height * aspect_ratio;
|
| 169 |
+
}
|
| 170 |
+
if (anchor.includes("l") || anchor.includes("r") || anchor == "c") {
|
| 171 |
+
new_height = original_width / aspect_ratio;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
// Ensure aspect ratio is maintained
|
| 175 |
+
new_height = new_height || new_width / aspect_ratio;
|
| 176 |
+
new_width = new_width || new_height * aspect_ratio;
|
| 177 |
+
|
| 178 |
+
// Apply max width/height constraints and adjust dimensions
|
| 179 |
+
if (new_width > max_width) {
|
| 180 |
+
new_width = max_width;
|
| 181 |
+
new_height = new_width / aspect_ratio;
|
| 182 |
+
}
|
| 183 |
+
if (new_height > max_height) {
|
| 184 |
+
new_height = max_height;
|
| 185 |
+
new_width = new_height * aspect_ratio;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
// Calculate offsets to ensure anchor position is maintained
|
| 189 |
+
let x_offset = 0;
|
| 190 |
+
let y_offset = 0;
|
| 191 |
+
if (anchor.includes("r")) {
|
| 192 |
+
x_offset = original_width - new_width;
|
| 193 |
+
} else if (anchor.includes("l")) {
|
| 194 |
+
x_offset = 0;
|
| 195 |
+
} else {
|
| 196 |
+
// Center or top/bottom center
|
| 197 |
+
x_offset = (original_width - new_width) / 2;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
if (anchor.includes("b")) {
|
| 201 |
+
y_offset = original_height - new_height;
|
| 202 |
+
} else if (anchor.includes("t")) {
|
| 203 |
+
y_offset = 0;
|
| 204 |
+
} else {
|
| 205 |
+
// Center or left/right center
|
| 206 |
+
y_offset = (original_height - new_height) / 2;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
return {
|
| 210 |
+
new_width: new_width,
|
| 211 |
+
new_height: new_height,
|
| 212 |
+
x_offset: x_offset,
|
| 213 |
+
y_offset: y_offset
|
| 214 |
+
};
|
| 215 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/index.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export { default as Tools } from "./Tools.svelte";
|
| 2 |
+
export { default as Brush } from "./Brush.svelte";
|
| 3 |
+
export { default as Crop } from "./Crop.svelte";
|
| 4 |
+
export { default as Sources } from "./Sources.svelte";
|
| 5 |
+
export * from "./types";
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/sources.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
type Container,
|
| 3 |
+
type IRenderer,
|
| 4 |
+
Sprite,
|
| 5 |
+
Texture,
|
| 6 |
+
DisplayObject,
|
| 7 |
+
type ColorSource,
|
| 8 |
+
Color,
|
| 9 |
+
RenderTexture
|
| 10 |
+
} from "pixi.js";
|
| 11 |
+
|
| 12 |
+
import { type Command } from "../utils/commands";
|
| 13 |
+
import { make_graphics } from "../utils/pixi";
|
| 14 |
+
|
| 15 |
+
interface BgImageCommand extends Command {
|
| 16 |
+
/**
|
| 17 |
+
* Initial setup for the bg command
|
| 18 |
+
* @returns
|
| 19 |
+
*/
|
| 20 |
+
start: () => Promise<[number, number]>;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Adds a background image to the canvas.
|
| 25 |
+
* @param container The container to add the image to.
|
| 26 |
+
* @param renderer The renderer to use for the image.
|
| 27 |
+
* @param background The background image to add.
|
| 28 |
+
* @param resize The function to resize the canvas.
|
| 29 |
+
* @returns A command that can be used to undo the action.
|
| 30 |
+
*/
|
| 31 |
+
|
| 32 |
+
export function add_bg_image(
|
| 33 |
+
container: Container,
|
| 34 |
+
renderer: IRenderer,
|
| 35 |
+
background: Blob | File,
|
| 36 |
+
resize: (width: number, height: number) => void
|
| 37 |
+
): BgImageCommand {
|
| 38 |
+
let sprite: Sprite & DisplayObject;
|
| 39 |
+
return {
|
| 40 |
+
async start() {
|
| 41 |
+
container.removeChildren();
|
| 42 |
+
const img = await createImageBitmap(background);
|
| 43 |
+
const bitmap_texture = Texture.from(img);
|
| 44 |
+
sprite = new Sprite(bitmap_texture) as Sprite & DisplayObject;
|
| 45 |
+
return [sprite.width, sprite.height];
|
| 46 |
+
},
|
| 47 |
+
async execute() {
|
| 48 |
+
// renderer.resize(sprite.width, sprite.height);
|
| 49 |
+
resize(sprite.width, sprite.height);
|
| 50 |
+
|
| 51 |
+
sprite.zIndex = 0;
|
| 52 |
+
container.addChild(sprite);
|
| 53 |
+
},
|
| 54 |
+
undo() {
|
| 55 |
+
container.removeChildAt(0);
|
| 56 |
+
}
|
| 57 |
+
};
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* Command that sets a background
|
| 62 |
+
*/
|
| 63 |
+
interface BgColorCommand extends Command {
|
| 64 |
+
/**
|
| 65 |
+
* Initial setup for the bg command
|
| 66 |
+
* @returns
|
| 67 |
+
*/
|
| 68 |
+
start: () => [number, number];
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Adds a background color to the canvas.
|
| 73 |
+
* @param container The container to add the image to.
|
| 74 |
+
* @param renderer The renderer to use for the image.
|
| 75 |
+
* @param color The background color to add.
|
| 76 |
+
* @param width The width of the background.
|
| 77 |
+
* @param height The height of the background.
|
| 78 |
+
* @param resize The function to resize the canvas.
|
| 79 |
+
* @returns A command that can be used to undo the action.
|
| 80 |
+
*/
|
| 81 |
+
export function add_bg_color(
|
| 82 |
+
container: Container,
|
| 83 |
+
renderer: IRenderer,
|
| 84 |
+
color: ColorSource,
|
| 85 |
+
width: number,
|
| 86 |
+
height: number,
|
| 87 |
+
resize: (width: number, height: number) => void
|
| 88 |
+
): BgColorCommand {
|
| 89 |
+
let sprite: Sprite & DisplayObject;
|
| 90 |
+
return {
|
| 91 |
+
start() {
|
| 92 |
+
container.removeChildren();
|
| 93 |
+
const graphics = make_graphics(1);
|
| 94 |
+
const texture = RenderTexture.create({
|
| 95 |
+
width,
|
| 96 |
+
height
|
| 97 |
+
});
|
| 98 |
+
graphics.beginFill(new Color(color));
|
| 99 |
+
graphics.drawRect(0, 0, width, height);
|
| 100 |
+
graphics.endFill();
|
| 101 |
+
renderer.render(graphics, { renderTexture: texture });
|
| 102 |
+
sprite = new Sprite(texture) as Sprite & DisplayObject;
|
| 103 |
+
return [sprite.width, sprite.height];
|
| 104 |
+
},
|
| 105 |
+
async execute() {
|
| 106 |
+
resize(sprite.width, sprite.height);
|
| 107 |
+
sprite.zIndex = 1;
|
| 108 |
+
container.addChild(sprite);
|
| 109 |
+
},
|
| 110 |
+
undo() {
|
| 111 |
+
container.removeChildren();
|
| 112 |
+
}
|
| 113 |
+
};
|
| 114 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/tools/types.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export type tool = "draw" | "erase" | "crop" | "bg";
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/utils/commands.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { writable, type Writable } from "svelte/store";
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Base command interface that is added to the command_managers history
|
| 5 |
+
*/
|
| 6 |
+
export interface Command {
|
| 7 |
+
/**
|
| 8 |
+
* Optionally called when the command is first executed for multi-step commands
|
| 9 |
+
* @param args arguments to pass to the command
|
| 10 |
+
*/
|
| 11 |
+
start?: (...args: any) => any | Promise<any>;
|
| 12 |
+
/**
|
| 13 |
+
* Optionally called when the command is continued for multi-step commands
|
| 14 |
+
* @param args arguments to pass to the command
|
| 15 |
+
*/
|
| 16 |
+
continue?: (...args: any) => any | Promise<any>;
|
| 17 |
+
/**
|
| 18 |
+
* Optionally called when the command is stopped for multi-step commands
|
| 19 |
+
* @param args arguments to pass to the command
|
| 20 |
+
*/
|
| 21 |
+
stop?: (...args: any) => any | Promise<any>;
|
| 22 |
+
/**
|
| 23 |
+
* Called by the command manager to execute the command, can act as a no-op if the work has already been done
|
| 24 |
+
* This function must be able to recreate the command if the command is undone and redone (`stop`/`start`/`continue` will not be called again)
|
| 25 |
+
*/
|
| 26 |
+
execute(): any | Promise<any>;
|
| 27 |
+
/**
|
| 28 |
+
* Called by the command manager to undo the command
|
| 29 |
+
* This function must be able to undo the work done by the execute function
|
| 30 |
+
*/
|
| 31 |
+
undo(): any | Promise<any>;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Command manager interface that handles the undo/redo history
|
| 36 |
+
*/
|
| 37 |
+
export interface CommandManager {
|
| 38 |
+
/**
|
| 39 |
+
* Undo the last command
|
| 40 |
+
*/
|
| 41 |
+
undo(): void;
|
| 42 |
+
/**
|
| 43 |
+
* Redo the last undone command
|
| 44 |
+
*/
|
| 45 |
+
redo(): void;
|
| 46 |
+
/**
|
| 47 |
+
* Execute a command and add it to the history
|
| 48 |
+
* @param command command to execute
|
| 49 |
+
*/
|
| 50 |
+
execute(command: Command): void;
|
| 51 |
+
/**
|
| 52 |
+
* Whether or not there are commands that can be undone
|
| 53 |
+
* Observable store that you can subscribe to for updates
|
| 54 |
+
*/
|
| 55 |
+
readonly can_undo: Writable<boolean>;
|
| 56 |
+
/**
|
| 57 |
+
* Whether or not there are commands that can be redone
|
| 58 |
+
* Observable store that you can subscribe to for updates
|
| 59 |
+
*/
|
| 60 |
+
readonly can_redo: Writable<boolean>;
|
| 61 |
+
/**
|
| 62 |
+
* Resets the history
|
| 63 |
+
*/
|
| 64 |
+
reset(): void;
|
| 65 |
+
/**
|
| 66 |
+
* The current history node
|
| 67 |
+
* Observable store that you can subscribe to for updates
|
| 68 |
+
*/
|
| 69 |
+
readonly current_history: Writable<CommandNode>;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* Command node interface that is used to create the undo/redo history
|
| 74 |
+
*/
|
| 75 |
+
interface CommandNode {
|
| 76 |
+
/**
|
| 77 |
+
* Command that the node holds
|
| 78 |
+
*/
|
| 79 |
+
command: Command | null;
|
| 80 |
+
/**
|
| 81 |
+
* Next command in the history
|
| 82 |
+
*/
|
| 83 |
+
next: CommandNode | null;
|
| 84 |
+
/**
|
| 85 |
+
* Previous command in the history
|
| 86 |
+
*/
|
| 87 |
+
previous: CommandNode | null;
|
| 88 |
+
/**
|
| 89 |
+
* Push a command onto the history
|
| 90 |
+
* @param command command to push onto the history
|
| 91 |
+
*/
|
| 92 |
+
push(command: Command): void;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* Creates a command node
|
| 97 |
+
* @param command command to add to the node
|
| 98 |
+
* @returns a command node
|
| 99 |
+
*/
|
| 100 |
+
function command_node(command?: Command): CommandNode {
|
| 101 |
+
return {
|
| 102 |
+
command: command || null,
|
| 103 |
+
next: null,
|
| 104 |
+
previous: null,
|
| 105 |
+
push: function (command: Command) {
|
| 106 |
+
const node = command_node(command);
|
| 107 |
+
node.previous = this;
|
| 108 |
+
this.next = node;
|
| 109 |
+
}
|
| 110 |
+
};
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Creates a command manager
|
| 115 |
+
* @returns a command manager
|
| 116 |
+
*/
|
| 117 |
+
export function command_manager(): CommandManager {
|
| 118 |
+
let history: CommandNode = command_node();
|
| 119 |
+
const can_undo = writable(false);
|
| 120 |
+
const can_redo = writable(false);
|
| 121 |
+
const current_history = writable(history);
|
| 122 |
+
return {
|
| 123 |
+
undo: function () {
|
| 124 |
+
if (history.previous) {
|
| 125 |
+
history.command?.undo();
|
| 126 |
+
history = history.previous;
|
| 127 |
+
}
|
| 128 |
+
can_undo.set(!!history.previous);
|
| 129 |
+
can_redo.set(!!history.next);
|
| 130 |
+
current_history.set(history);
|
| 131 |
+
},
|
| 132 |
+
redo: function () {
|
| 133 |
+
if (history.next) {
|
| 134 |
+
history.next.command?.execute();
|
| 135 |
+
history = history.next;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
can_undo.set(!!history.previous);
|
| 139 |
+
can_redo.set(!!history.next);
|
| 140 |
+
current_history.set(history);
|
| 141 |
+
},
|
| 142 |
+
execute: function (command: Command) {
|
| 143 |
+
command.execute();
|
| 144 |
+
history.push(command);
|
| 145 |
+
history = history.next!;
|
| 146 |
+
can_undo.set(!!history.previous);
|
| 147 |
+
can_redo.set(!!history.next);
|
| 148 |
+
current_history.set(history);
|
| 149 |
+
},
|
| 150 |
+
|
| 151 |
+
can_undo,
|
| 152 |
+
can_redo,
|
| 153 |
+
current_history,
|
| 154 |
+
|
| 155 |
+
reset: function () {
|
| 156 |
+
history = command_node();
|
| 157 |
+
can_undo.set(false);
|
| 158 |
+
can_redo.set(false);
|
| 159 |
+
current_history.set(history);
|
| 160 |
+
}
|
| 161 |
+
};
|
| 162 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/utils/events.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { tick } from "svelte";
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Svelte action to handle clicks outside of a DOM node
|
| 5 |
+
* @param node DOM node to check the click is outside of
|
| 6 |
+
* @param callback callback function to call if click is outside
|
| 7 |
+
* @returns svelte action return object with destroy method to remove event listener
|
| 8 |
+
*/
|
| 9 |
+
export function click_outside(
|
| 10 |
+
node: Node,
|
| 11 |
+
callback: (arg: MouseEvent) => void
|
| 12 |
+
): any {
|
| 13 |
+
const handle_click = (event: MouseEvent): void => {
|
| 14 |
+
if (
|
| 15 |
+
node &&
|
| 16 |
+
!node.contains(event.target as Node) &&
|
| 17 |
+
!event.defaultPrevented
|
| 18 |
+
) {
|
| 19 |
+
callback(event);
|
| 20 |
+
}
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
document.addEventListener("mousedown", handle_click, true);
|
| 24 |
+
|
| 25 |
+
return {
|
| 26 |
+
destroy() {
|
| 27 |
+
document.removeEventListener("mousedown", handle_click, true);
|
| 28 |
+
}
|
| 29 |
+
};
|
| 30 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/utils/parse_placeholder.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const RE_HEADING = /^(#\s*)(.+)$/m;
|
| 2 |
+
|
| 3 |
+
export function inject(text: string): [string | false, string | false] {
|
| 4 |
+
const trimmed_text = text.trim();
|
| 5 |
+
|
| 6 |
+
const heading_match = trimmed_text.match(RE_HEADING);
|
| 7 |
+
if (!heading_match) {
|
| 8 |
+
return [false, trimmed_text || false];
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
const [full_match, , heading_content] = heading_match;
|
| 12 |
+
const _heading = heading_content.trim();
|
| 13 |
+
|
| 14 |
+
if (trimmed_text === full_match) {
|
| 15 |
+
return [_heading, false];
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
const heading_end_index =
|
| 19 |
+
heading_match.index !== undefined
|
| 20 |
+
? heading_match.index + full_match.length
|
| 21 |
+
: 0;
|
| 22 |
+
const remaining_text = trimmed_text.substring(heading_end_index).trim();
|
| 23 |
+
|
| 24 |
+
const _paragraph = remaining_text || false;
|
| 25 |
+
|
| 26 |
+
return [_heading, _paragraph];
|
| 27 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/imageeditor/shared/utils/pixi.ts
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
Application,
|
| 3 |
+
Container,
|
| 4 |
+
Graphics,
|
| 5 |
+
Sprite,
|
| 6 |
+
Rectangle,
|
| 7 |
+
RenderTexture,
|
| 8 |
+
type IRenderer,
|
| 9 |
+
type DisplayObject,
|
| 10 |
+
type ICanvas
|
| 11 |
+
} from "pixi.js";
|
| 12 |
+
|
| 13 |
+
import { type LayerScene } from "../layers/utils";
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* interface holding references to pixi app components
|
| 17 |
+
*/
|
| 18 |
+
export interface PixiApp {
|
| 19 |
+
/**
|
| 20 |
+
* The pixi container for layers
|
| 21 |
+
*/
|
| 22 |
+
layer_container: Container;
|
| 23 |
+
/**
|
| 24 |
+
* The pixi container for background images and colors
|
| 25 |
+
*/
|
| 26 |
+
background_container: Container;
|
| 27 |
+
/**
|
| 28 |
+
* The pixi renderer
|
| 29 |
+
*/
|
| 30 |
+
renderer: IRenderer;
|
| 31 |
+
/**
|
| 32 |
+
* The pixi canvas
|
| 33 |
+
*/
|
| 34 |
+
view: HTMLCanvasElement & ICanvas;
|
| 35 |
+
/**
|
| 36 |
+
* The pixi container for masking
|
| 37 |
+
*/
|
| 38 |
+
mask_container: Container;
|
| 39 |
+
destroy(): void;
|
| 40 |
+
/**
|
| 41 |
+
* Resizes the pixi app
|
| 42 |
+
* @param width the new width
|
| 43 |
+
* @param height the new height
|
| 44 |
+
*/
|
| 45 |
+
resize(width: number, height: number): void;
|
| 46 |
+
/**
|
| 47 |
+
* Gets the blobs for the background, layers, and composite
|
| 48 |
+
* @param bounds the bounds of the canvas
|
| 49 |
+
* @returns a promise with the blobs
|
| 50 |
+
*/
|
| 51 |
+
get_blobs(
|
| 52 |
+
layers: LayerScene[],
|
| 53 |
+
bounds: Rectangle,
|
| 54 |
+
dimensions: [number, number]
|
| 55 |
+
): Promise<ImageBlobs>;
|
| 56 |
+
// /**
|
| 57 |
+
// * Resets the mask
|
| 58 |
+
// */
|
| 59 |
+
// reset?: () => void;
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Gets the layers
|
| 63 |
+
*/
|
| 64 |
+
get_layers?: () => LayerScene[];
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/**
|
| 68 |
+
* Creates a PIXI app and attaches it to a DOM element
|
| 69 |
+
* @param target DOM element to attach PIXI app to
|
| 70 |
+
* @param width Width of the PIXI app
|
| 71 |
+
* @param height Height of the PIXI app
|
| 72 |
+
* @param antialias Whether to use antialiasing
|
| 73 |
+
* @returns object with pixi container and renderer
|
| 74 |
+
*/
|
| 75 |
+
export function create_pixi_app({
|
| 76 |
+
target,
|
| 77 |
+
dimensions: [width, height],
|
| 78 |
+
antialias
|
| 79 |
+
}: {
|
| 80 |
+
target: HTMLElement;
|
| 81 |
+
dimensions: [number, number];
|
| 82 |
+
antialias: boolean;
|
| 83 |
+
}): PixiApp {
|
| 84 |
+
const ratio = window.devicePixelRatio || 1;
|
| 85 |
+
const app = new Application({
|
| 86 |
+
width,
|
| 87 |
+
height,
|
| 88 |
+
antialias: antialias,
|
| 89 |
+
backgroundAlpha: 0,
|
| 90 |
+
eventMode: "static"
|
| 91 |
+
});
|
| 92 |
+
const view = app.view as HTMLCanvasElement;
|
| 93 |
+
// ensure that we can sort the background and layer containers
|
| 94 |
+
app.stage.sortableChildren = true;
|
| 95 |
+
view.style.maxWidth = `${width / ratio}px`;
|
| 96 |
+
view.style.maxHeight = `${height / ratio}px`;
|
| 97 |
+
view.style.width = "100%";
|
| 98 |
+
view.style.height = "100%";
|
| 99 |
+
|
| 100 |
+
target.appendChild(app.view as HTMLCanvasElement);
|
| 101 |
+
|
| 102 |
+
// we need a separate container for the background so that we can
|
| 103 |
+
// clear its content without knowing too much about its children
|
| 104 |
+
const background_container = new Container() as Container & DisplayObject;
|
| 105 |
+
background_container.zIndex = 0;
|
| 106 |
+
const layer_container = new Container() as Container & DisplayObject;
|
| 107 |
+
layer_container.zIndex = 1;
|
| 108 |
+
|
| 109 |
+
// ensure we can reorder layers via zIndex
|
| 110 |
+
layer_container.sortableChildren = true;
|
| 111 |
+
|
| 112 |
+
const mask_container = new Container() as Container & DisplayObject;
|
| 113 |
+
mask_container.zIndex = 1;
|
| 114 |
+
const composite_container = new Container() as Container & DisplayObject;
|
| 115 |
+
composite_container.zIndex = 0;
|
| 116 |
+
|
| 117 |
+
mask_container.addChild(background_container);
|
| 118 |
+
mask_container.addChild(layer_container);
|
| 119 |
+
|
| 120 |
+
app.stage.addChild(mask_container);
|
| 121 |
+
app.stage.addChild(composite_container);
|
| 122 |
+
const mask = new Graphics();
|
| 123 |
+
let text = RenderTexture.create({
|
| 124 |
+
width,
|
| 125 |
+
height
|
| 126 |
+
});
|
| 127 |
+
const sprite = new Sprite(text);
|
| 128 |
+
|
| 129 |
+
mask_container.mask = sprite;
|
| 130 |
+
|
| 131 |
+
app.render();
|
| 132 |
+
|
| 133 |
+
function reset_mask(width: number, height: number): void {
|
| 134 |
+
background_container.removeChildren();
|
| 135 |
+
mask.beginFill(0xffffff, 1);
|
| 136 |
+
mask.drawRect(0, 0, width, height);
|
| 137 |
+
mask.endFill();
|
| 138 |
+
text = RenderTexture.create({
|
| 139 |
+
width,
|
| 140 |
+
height
|
| 141 |
+
});
|
| 142 |
+
app.renderer.render(mask, {
|
| 143 |
+
renderTexture: text
|
| 144 |
+
});
|
| 145 |
+
|
| 146 |
+
const sprite = new Sprite(text);
|
| 147 |
+
|
| 148 |
+
mask_container.mask = sprite;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
function resize(width: number, height: number): void {
|
| 152 |
+
app.renderer.resize(width, height);
|
| 153 |
+
view.style.maxWidth = `${width / ratio}px`;
|
| 154 |
+
view.style.maxHeight = `${height / ratio}px`;
|
| 155 |
+
reset_mask(width, height);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
async function get_blobs(
|
| 159 |
+
_layers: LayerScene[],
|
| 160 |
+
bounds: Rectangle,
|
| 161 |
+
[w, h]: [number, number]
|
| 162 |
+
): Promise<ImageBlobs> {
|
| 163 |
+
const background = await get_canvas_blob(
|
| 164 |
+
app.renderer,
|
| 165 |
+
background_container,
|
| 166 |
+
bounds,
|
| 167 |
+
w,
|
| 168 |
+
h
|
| 169 |
+
);
|
| 170 |
+
|
| 171 |
+
const layers = await Promise.all(
|
| 172 |
+
_layers.map((layer) =>
|
| 173 |
+
get_canvas_blob(
|
| 174 |
+
app.renderer,
|
| 175 |
+
layer.composite as DisplayObject,
|
| 176 |
+
bounds,
|
| 177 |
+
w,
|
| 178 |
+
h
|
| 179 |
+
)
|
| 180 |
+
)
|
| 181 |
+
);
|
| 182 |
+
|
| 183 |
+
const composite = await get_canvas_blob(
|
| 184 |
+
app.renderer,
|
| 185 |
+
mask_container,
|
| 186 |
+
bounds,
|
| 187 |
+
w,
|
| 188 |
+
h
|
| 189 |
+
);
|
| 190 |
+
|
| 191 |
+
return {
|
| 192 |
+
background,
|
| 193 |
+
layers,
|
| 194 |
+
composite
|
| 195 |
+
};
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
return {
|
| 199 |
+
layer_container,
|
| 200 |
+
renderer: app.renderer,
|
| 201 |
+
destroy: () => app.destroy(true),
|
| 202 |
+
view: app.view as HTMLCanvasElement & ICanvas,
|
| 203 |
+
background_container,
|
| 204 |
+
mask_container,
|
| 205 |
+
resize,
|
| 206 |
+
get_blobs
|
| 207 |
+
};
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/**
|
| 211 |
+
* Creates a pixi graphics object.
|
| 212 |
+
* @param z_index the z index of the graphics object
|
| 213 |
+
* @returns a graphics object
|
| 214 |
+
*/
|
| 215 |
+
export function make_graphics(z_index: number): Graphics {
|
| 216 |
+
const graphics = new Graphics();
|
| 217 |
+
graphics.eventMode = "none";
|
| 218 |
+
graphics.zIndex = z_index;
|
| 219 |
+
|
| 220 |
+
return graphics;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
/**
|
| 224 |
+
* Clamps a number between a min and max value.
|
| 225 |
+
* @param n The number to clamp.
|
| 226 |
+
* @param min The minimum value.
|
| 227 |
+
* @param max The maximum value.
|
| 228 |
+
* @returns The clamped number.
|
| 229 |
+
*/
|
| 230 |
+
export function clamp(n: number, min: number, max: number): number {
|
| 231 |
+
return n < min ? min : n > max ? max : n;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* Generates a blob from a pixi object.
|
| 236 |
+
* @param renderer The pixi renderer.
|
| 237 |
+
* @param obj The pixi object to generate a blob from.
|
| 238 |
+
* @param bounds The bounds of the canvas that we wish to extract
|
| 239 |
+
* @param width The full width of the canvas
|
| 240 |
+
* @param height The full height of the canvas
|
| 241 |
+
* @returns A promise with the blob.
|
| 242 |
+
*/
|
| 243 |
+
function get_canvas_blob(
|
| 244 |
+
renderer: IRenderer,
|
| 245 |
+
obj: DisplayObject,
|
| 246 |
+
bounds: Rectangle,
|
| 247 |
+
width: number,
|
| 248 |
+
height: number
|
| 249 |
+
): Promise<Blob | null> {
|
| 250 |
+
return new Promise((resolve) => {
|
| 251 |
+
// for some reason pixi won't extract a cropped canvas without distorting it
|
| 252 |
+
// so we have to extract the whole canvas and crop it manually
|
| 253 |
+
const src_canvas = renderer.extract.canvas(
|
| 254 |
+
obj,
|
| 255 |
+
new Rectangle(0, 0, width, height)
|
| 256 |
+
);
|
| 257 |
+
|
| 258 |
+
// Create a new canvas for the cropped area with the appropriate size
|
| 259 |
+
let dest_canvas = document.createElement("canvas");
|
| 260 |
+
dest_canvas.width = bounds.width;
|
| 261 |
+
dest_canvas.height = bounds.height;
|
| 262 |
+
let dest_ctx = dest_canvas.getContext("2d");
|
| 263 |
+
|
| 264 |
+
if (!dest_ctx) {
|
| 265 |
+
resolve(null);
|
| 266 |
+
throw new Error("Could not create canvas context");
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
// Draw the cropped area onto the destination canvas
|
| 270 |
+
dest_ctx.drawImage(
|
| 271 |
+
src_canvas as HTMLCanvasElement,
|
| 272 |
+
// this is the area of the source that we want to copy (the crop box)
|
| 273 |
+
bounds.x,
|
| 274 |
+
bounds.y,
|
| 275 |
+
bounds.width,
|
| 276 |
+
bounds.height,
|
| 277 |
+
// this is where we want to draw the crop box on the destination canvas
|
| 278 |
+
0,
|
| 279 |
+
0,
|
| 280 |
+
bounds.width,
|
| 281 |
+
bounds.height
|
| 282 |
+
);
|
| 283 |
+
|
| 284 |
+
// we grab a blob here so we can upload it
|
| 285 |
+
dest_canvas.toBlob?.((blob) => {
|
| 286 |
+
if (!blob) {
|
| 287 |
+
resolve(null);
|
| 288 |
+
}
|
| 289 |
+
resolve(blob);
|
| 290 |
+
});
|
| 291 |
+
});
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
export interface ImageBlobs {
|
| 295 |
+
background: Blob | null;
|
| 296 |
+
layers: (Blob | null)[];
|
| 297 |
+
composite: Blob | null;
|
| 298 |
+
}
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/label/shared/Label.svelte
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import type { SelectData } from "@gradio/utils";
|
| 3 |
+
import { createEventDispatcher } from "svelte";
|
| 4 |
+
|
| 5 |
+
export let value: {
|
| 6 |
+
label?: string;
|
| 7 |
+
confidences?: { label: string; confidence: number }[];
|
| 8 |
+
};
|
| 9 |
+
|
| 10 |
+
const dispatch = createEventDispatcher<{ select: SelectData }>();
|
| 11 |
+
|
| 12 |
+
export let color: string | undefined = undefined;
|
| 13 |
+
export let selectable = false;
|
| 14 |
+
|
| 15 |
+
function get_aria_referenceable_id(elem_id: string): string {
|
| 16 |
+
// `aria-labelledby` interprets the value as a space-separated id reference list,
|
| 17 |
+
// so each single id should not contain any spaces.
|
| 18 |
+
// Ref: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby#benefits_and_drawbacks
|
| 19 |
+
return elem_id.replace(/\s/g, "-");
|
| 20 |
+
}
|
| 21 |
+
</script>
|
| 22 |
+
|
| 23 |
+
<div class="container">
|
| 24 |
+
<h2
|
| 25 |
+
class="output-class"
|
| 26 |
+
data-testid="label-output-value"
|
| 27 |
+
class:no-confidence={!("confidences" in value)}
|
| 28 |
+
style:background-color={color || "transparent"}
|
| 29 |
+
>
|
| 30 |
+
{value.label}
|
| 31 |
+
</h2>
|
| 32 |
+
|
| 33 |
+
{#if typeof value === "object" && value.confidences}
|
| 34 |
+
{#each value.confidences as confidence_set, i}
|
| 35 |
+
<button
|
| 36 |
+
class="confidence-set group"
|
| 37 |
+
data-testid={`${confidence_set.label}-confidence-set`}
|
| 38 |
+
class:selectable
|
| 39 |
+
on:click={() => {
|
| 40 |
+
dispatch("select", { index: i, value: confidence_set.label });
|
| 41 |
+
}}
|
| 42 |
+
>
|
| 43 |
+
<div class="inner-wrap">
|
| 44 |
+
<meter
|
| 45 |
+
aria-labelledby={get_aria_referenceable_id(
|
| 46 |
+
`meter-text-${confidence_set.label}`
|
| 47 |
+
)}
|
| 48 |
+
aria-label={confidence_set.label}
|
| 49 |
+
aria-valuenow={Math.round(confidence_set.confidence * 100)}
|
| 50 |
+
aria-valuemin="0"
|
| 51 |
+
aria-valuemax="100"
|
| 52 |
+
class="bar"
|
| 53 |
+
min="0"
|
| 54 |
+
max="1"
|
| 55 |
+
value={confidence_set.confidence}
|
| 56 |
+
style="width: {confidence_set.confidence *
|
| 57 |
+
100}%; background: var(--stat-background-fill);
|
| 58 |
+
"
|
| 59 |
+
/>
|
| 60 |
+
|
| 61 |
+
<dl class="label">
|
| 62 |
+
<dt
|
| 63 |
+
id={get_aria_referenceable_id(
|
| 64 |
+
`meter-text-${confidence_set.label}`
|
| 65 |
+
)}
|
| 66 |
+
class="text"
|
| 67 |
+
>
|
| 68 |
+
{confidence_set.label}
|
| 69 |
+
</dt>
|
| 70 |
+
<div class="line" />
|
| 71 |
+
<dd class="confidence">
|
| 72 |
+
{Math.round(confidence_set.confidence * 100)}%
|
| 73 |
+
</dd>
|
| 74 |
+
</dl>
|
| 75 |
+
</div>
|
| 76 |
+
</button>
|
| 77 |
+
{/each}
|
| 78 |
+
{/if}
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
<style>
|
| 82 |
+
.container {
|
| 83 |
+
padding: var(--block-padding);
|
| 84 |
+
}
|
| 85 |
+
.output-class {
|
| 86 |
+
display: flex;
|
| 87 |
+
justify-content: center;
|
| 88 |
+
align-items: center;
|
| 89 |
+
padding: var(--size-6) var(--size-4);
|
| 90 |
+
color: var(--body-text-color);
|
| 91 |
+
font-weight: var(--weight-bold);
|
| 92 |
+
font-size: var(--text-xxl);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
.confidence-set {
|
| 96 |
+
display: flex;
|
| 97 |
+
justify-content: space-between;
|
| 98 |
+
align-items: flex-start;
|
| 99 |
+
margin-bottom: var(--size-2);
|
| 100 |
+
color: var(--body-text-color);
|
| 101 |
+
line-height: var(--line-none);
|
| 102 |
+
font-family: var(--font-mono);
|
| 103 |
+
width: 100%;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.confidence-set:last-child {
|
| 107 |
+
margin-bottom: 0;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
.inner-wrap {
|
| 111 |
+
flex: 1 1 0%;
|
| 112 |
+
display: flex;
|
| 113 |
+
flex-direction: column;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
.bar {
|
| 117 |
+
appearance: none;
|
| 118 |
+
align-self: flex-start;
|
| 119 |
+
margin-bottom: var(--size-1);
|
| 120 |
+
border-radius: var(--radius-md);
|
| 121 |
+
background: var(--stat-background-fill);
|
| 122 |
+
height: var(--size-1);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
.label {
|
| 126 |
+
display: flex;
|
| 127 |
+
align-items: baseline;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.label > * + * {
|
| 131 |
+
margin-left: var(--size-2);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
.confidence-set:hover .label {
|
| 135 |
+
color: var(--color-accent);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
.confidence-set:focus .label {
|
| 139 |
+
color: var(--color-accent);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
.text {
|
| 143 |
+
line-height: var(--line-md);
|
| 144 |
+
text-align: left;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
.line {
|
| 148 |
+
flex: 1 1 0%;
|
| 149 |
+
border: 1px dashed var(--border-color-primary);
|
| 150 |
+
padding-right: var(--size-4);
|
| 151 |
+
padding-left: var(--size-4);
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.confidence {
|
| 155 |
+
margin-left: auto;
|
| 156 |
+
text-align: right;
|
| 157 |
+
}
|
| 158 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/model3D/Example.svelte
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export let value: string | null;
|
| 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 |
+
{value ? value : ""}
|
| 13 |
+
</div>
|
| 14 |
+
|
| 15 |
+
<style>
|
| 16 |
+
.gallery {
|
| 17 |
+
padding: var(--size-1) var(--size-2);
|
| 18 |
+
}
|
| 19 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/model3D/shared/Canvas3DGS.svelte
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { onMount } from "svelte";
|
| 3 |
+
import * as SPLAT from "gsplat";
|
| 4 |
+
import type { FileData } from "@gradio/client";
|
| 5 |
+
import { resolve_wasm_src } from "@gradio/wasm/svelte";
|
| 6 |
+
|
| 7 |
+
export let value: FileData;
|
| 8 |
+
export let zoom_speed: number;
|
| 9 |
+
export let pan_speed: number;
|
| 10 |
+
|
| 11 |
+
$: url = value.url;
|
| 12 |
+
|
| 13 |
+
/* URL resolution for the Wasm mode. */
|
| 14 |
+
export let resolved_url: typeof url = undefined; // Exposed to be bound to the download link in the parent component.
|
| 15 |
+
// The prop can be updated before the Promise from `resolve_wasm_src` is resolved.
|
| 16 |
+
// In such a case, the resolved url for the old `url` has to be discarded,
|
| 17 |
+
// This variable `latest_url` is used to pick up only the value resolved for the latest `url`.
|
| 18 |
+
let latest_url: typeof url;
|
| 19 |
+
$: {
|
| 20 |
+
// In normal (non-Wasm) Gradio, the original `url` should be used immediately
|
| 21 |
+
// without waiting for `resolve_wasm_src()` to resolve.
|
| 22 |
+
// If it waits, a blank element is displayed until the async task finishes
|
| 23 |
+
// and it leads to undesirable flickering.
|
| 24 |
+
// So set `resolved_url` immediately above, and update it with the resolved values below later.
|
| 25 |
+
resolved_url = url;
|
| 26 |
+
|
| 27 |
+
if (url) {
|
| 28 |
+
latest_url = url;
|
| 29 |
+
const resolving_url = url;
|
| 30 |
+
resolve_wasm_src(url).then((resolved) => {
|
| 31 |
+
if (latest_url === resolving_url) {
|
| 32 |
+
resolved_url = resolved ?? undefined;
|
| 33 |
+
} else {
|
| 34 |
+
resolved && URL.revokeObjectURL(resolved);
|
| 35 |
+
}
|
| 36 |
+
});
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
let canvas: HTMLCanvasElement;
|
| 41 |
+
let scene: SPLAT.Scene;
|
| 42 |
+
let camera: SPLAT.Camera;
|
| 43 |
+
let renderer: SPLAT.WebGLRenderer | null = null;
|
| 44 |
+
let controls: SPLAT.OrbitControls;
|
| 45 |
+
let mounted = false;
|
| 46 |
+
let frameId: number | null = null;
|
| 47 |
+
|
| 48 |
+
function reset_scene(): void {
|
| 49 |
+
if (frameId !== null) {
|
| 50 |
+
cancelAnimationFrame(frameId);
|
| 51 |
+
frameId = null;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
if (renderer !== null) {
|
| 55 |
+
renderer.dispose();
|
| 56 |
+
renderer = null;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
scene = new SPLAT.Scene();
|
| 60 |
+
camera = new SPLAT.Camera();
|
| 61 |
+
renderer = new SPLAT.WebGLRenderer(canvas);
|
| 62 |
+
controls = new SPLAT.OrbitControls(camera, canvas);
|
| 63 |
+
controls.zoomSpeed = zoom_speed;
|
| 64 |
+
controls.panSpeed = pan_speed;
|
| 65 |
+
|
| 66 |
+
if (!value) {
|
| 67 |
+
return;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
let loading = false;
|
| 71 |
+
const load = async (): Promise<void> => {
|
| 72 |
+
if (loading) {
|
| 73 |
+
console.error("Already loading");
|
| 74 |
+
return;
|
| 75 |
+
}
|
| 76 |
+
if (!resolved_url) {
|
| 77 |
+
throw new Error("No resolved URL");
|
| 78 |
+
}
|
| 79 |
+
loading = true;
|
| 80 |
+
if (resolved_url.endsWith(".ply")) {
|
| 81 |
+
await SPLAT.PLYLoader.LoadAsync(resolved_url, scene, undefined);
|
| 82 |
+
} else if (resolved_url.endsWith(".splat")) {
|
| 83 |
+
await SPLAT.Loader.LoadAsync(resolved_url, scene, undefined);
|
| 84 |
+
} else {
|
| 85 |
+
throw new Error("Unsupported file type");
|
| 86 |
+
}
|
| 87 |
+
loading = false;
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
const frame = (): void => {
|
| 91 |
+
if (!renderer) {
|
| 92 |
+
return;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
if (loading) {
|
| 96 |
+
frameId = requestAnimationFrame(frame);
|
| 97 |
+
return;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
controls.update();
|
| 101 |
+
renderer.render(scene, camera);
|
| 102 |
+
|
| 103 |
+
frameId = requestAnimationFrame(frame);
|
| 104 |
+
};
|
| 105 |
+
|
| 106 |
+
load();
|
| 107 |
+
frameId = requestAnimationFrame(frame);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
onMount(() => {
|
| 111 |
+
if (value != null) {
|
| 112 |
+
reset_scene();
|
| 113 |
+
}
|
| 114 |
+
mounted = true;
|
| 115 |
+
|
| 116 |
+
return () => {
|
| 117 |
+
if (renderer) {
|
| 118 |
+
renderer.dispose();
|
| 119 |
+
}
|
| 120 |
+
};
|
| 121 |
+
});
|
| 122 |
+
|
| 123 |
+
$: ({ path } = value || {
|
| 124 |
+
path: undefined
|
| 125 |
+
});
|
| 126 |
+
|
| 127 |
+
$: canvas && mounted && path && reset_scene();
|
| 128 |
+
</script>
|
| 129 |
+
|
| 130 |
+
<canvas bind:this={canvas}></canvas>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/model3D/shared/Model3D.svelte
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import type { FileData } from "@gradio/client";
|
| 3 |
+
import { BlockLabel, IconButton, IconButtonWrapper } from "@gradio/atoms";
|
| 4 |
+
import { File, Download, Undo } from "@gradio/icons";
|
| 5 |
+
import type { I18nFormatter } from "@gradio/utils";
|
| 6 |
+
import { dequal } from "dequal";
|
| 7 |
+
import type Canvas3DGS from "./Canvas3DGS.svelte";
|
| 8 |
+
import type Canvas3D from "./Canvas3D.svelte";
|
| 9 |
+
|
| 10 |
+
export let value: FileData | null;
|
| 11 |
+
export let display_mode: "solid" | "point_cloud" | "wireframe" = "solid";
|
| 12 |
+
export let clear_color: [number, number, number, number] = [0, 0, 0, 0];
|
| 13 |
+
export let label = "";
|
| 14 |
+
export let show_label: boolean;
|
| 15 |
+
export let i18n: I18nFormatter;
|
| 16 |
+
export let zoom_speed = 1;
|
| 17 |
+
export let pan_speed = 1;
|
| 18 |
+
// alpha, beta, radius
|
| 19 |
+
export let camera_position: [number | null, number | null, number | null] = [
|
| 20 |
+
null,
|
| 21 |
+
null,
|
| 22 |
+
null
|
| 23 |
+
];
|
| 24 |
+
export let has_change_history = false;
|
| 25 |
+
|
| 26 |
+
let current_settings = { camera_position, zoom_speed, pan_speed };
|
| 27 |
+
|
| 28 |
+
let use_3dgs = false;
|
| 29 |
+
let Canvas3DGSComponent: typeof Canvas3DGS;
|
| 30 |
+
let Canvas3DComponent: typeof Canvas3D;
|
| 31 |
+
async function loadCanvas3D(): Promise<typeof Canvas3D> {
|
| 32 |
+
const module = await import("./Canvas3D.svelte");
|
| 33 |
+
return module.default;
|
| 34 |
+
}
|
| 35 |
+
async function loadCanvas3DGS(): Promise<typeof Canvas3DGS> {
|
| 36 |
+
const module = await import("./Canvas3DGS.svelte");
|
| 37 |
+
return module.default;
|
| 38 |
+
}
|
| 39 |
+
$: if (value) {
|
| 40 |
+
use_3dgs = value.path.endsWith(".splat") || value.path.endsWith(".ply");
|
| 41 |
+
if (use_3dgs) {
|
| 42 |
+
loadCanvas3DGS().then((component) => {
|
| 43 |
+
Canvas3DGSComponent = component;
|
| 44 |
+
});
|
| 45 |
+
} else {
|
| 46 |
+
loadCanvas3D().then((component) => {
|
| 47 |
+
Canvas3DComponent = component;
|
| 48 |
+
});
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
let canvas3d: Canvas3D | undefined;
|
| 53 |
+
function handle_undo(): void {
|
| 54 |
+
canvas3d?.reset_camera_position(camera_position, zoom_speed, pan_speed);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
$: {
|
| 58 |
+
if (
|
| 59 |
+
!dequal(current_settings.camera_position, camera_position) ||
|
| 60 |
+
current_settings.zoom_speed !== zoom_speed ||
|
| 61 |
+
current_settings.pan_speed !== pan_speed
|
| 62 |
+
) {
|
| 63 |
+
canvas3d?.reset_camera_position(camera_position, zoom_speed, pan_speed);
|
| 64 |
+
current_settings = { camera_position, zoom_speed, pan_speed };
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
let resolved_url: string | undefined;
|
| 69 |
+
</script>
|
| 70 |
+
|
| 71 |
+
<BlockLabel
|
| 72 |
+
{show_label}
|
| 73 |
+
Icon={File}
|
| 74 |
+
label={label || i18n("3D_model.3d_model")}
|
| 75 |
+
/>
|
| 76 |
+
{#if value}
|
| 77 |
+
<div class="model3D">
|
| 78 |
+
<IconButtonWrapper>
|
| 79 |
+
{#if !use_3dgs}
|
| 80 |
+
<!-- Canvas3DGS doesn't implement the undo method (reset_camera_position) -->
|
| 81 |
+
<IconButton
|
| 82 |
+
Icon={Undo}
|
| 83 |
+
label="Undo"
|
| 84 |
+
on:click={() => handle_undo()}
|
| 85 |
+
disabled={!has_change_history}
|
| 86 |
+
/>
|
| 87 |
+
{/if}
|
| 88 |
+
<a
|
| 89 |
+
href={resolved_url}
|
| 90 |
+
target={window.__is_colab__ ? "_blank" : null}
|
| 91 |
+
download={window.__is_colab__ ? null : value.orig_name || value.path}
|
| 92 |
+
>
|
| 93 |
+
<IconButton Icon={Download} label={i18n("common.download")} />
|
| 94 |
+
</a>
|
| 95 |
+
</IconButtonWrapper>
|
| 96 |
+
|
| 97 |
+
{#if use_3dgs}
|
| 98 |
+
<svelte:component
|
| 99 |
+
this={Canvas3DGSComponent}
|
| 100 |
+
bind:resolved_url
|
| 101 |
+
{value}
|
| 102 |
+
{zoom_speed}
|
| 103 |
+
{pan_speed}
|
| 104 |
+
/>
|
| 105 |
+
{:else}
|
| 106 |
+
<svelte:component
|
| 107 |
+
this={Canvas3DComponent}
|
| 108 |
+
bind:this={canvas3d}
|
| 109 |
+
bind:resolved_url
|
| 110 |
+
{value}
|
| 111 |
+
{display_mode}
|
| 112 |
+
{clear_color}
|
| 113 |
+
{camera_position}
|
| 114 |
+
{zoom_speed}
|
| 115 |
+
{pan_speed}
|
| 116 |
+
/>
|
| 117 |
+
{/if}
|
| 118 |
+
</div>
|
| 119 |
+
{/if}
|
| 120 |
+
|
| 121 |
+
<style>
|
| 122 |
+
.model3D {
|
| 123 |
+
display: flex;
|
| 124 |
+
position: relative;
|
| 125 |
+
width: var(--size-full);
|
| 126 |
+
height: var(--size-full);
|
| 127 |
+
border-radius: var(--block-radius);
|
| 128 |
+
overflow: hidden;
|
| 129 |
+
}
|
| 130 |
+
.model3D :global(canvas) {
|
| 131 |
+
width: var(--size-full);
|
| 132 |
+
height: var(--size-full);
|
| 133 |
+
object-fit: contain;
|
| 134 |
+
overflow: hidden;
|
| 135 |
+
}
|
| 136 |
+
</style>
|
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/model3D/shared/Model3DUpload.svelte
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { createEventDispatcher, tick } from "svelte";
|
| 3 |
+
import { Upload, ModifyUpload } from "@gradio/upload";
|
| 4 |
+
import type { FileData, Client } from "@gradio/client";
|
| 5 |
+
import { BlockLabel } from "@gradio/atoms";
|
| 6 |
+
import { File } from "@gradio/icons";
|
| 7 |
+
import type { I18nFormatter } from "@gradio/utils";
|
| 8 |
+
import type Canvas3DGS from "./Canvas3DGS.svelte";
|
| 9 |
+
import type Canvas3D from "./Canvas3D.svelte";
|
| 10 |
+
|
| 11 |
+
export let value: null | FileData;
|
| 12 |
+
export let display_mode: "solid" | "point_cloud" | "wireframe" = "solid";
|
| 13 |
+
export let clear_color: [number, number, number, number] = [0, 0, 0, 0];
|
| 14 |
+
export let label = "";
|
| 15 |
+
export let show_label: boolean;
|
| 16 |
+
export let root: string;
|
| 17 |
+
export let i18n: I18nFormatter;
|
| 18 |
+
export let zoom_speed = 1;
|
| 19 |
+
export let pan_speed = 1;
|
| 20 |
+
export let max_file_size: number | null = null;
|
| 21 |
+
export let uploading = false;
|
| 22 |
+
|
| 23 |
+
// alpha, beta, radius
|
| 24 |
+
export let camera_position: [number | null, number | null, number | null] = [
|
| 25 |
+
null,
|
| 26 |
+
null,
|
| 27 |
+
null
|
| 28 |
+
];
|
| 29 |
+
export let upload: Client["upload"];
|
| 30 |
+
export let stream_handler: Client["stream"];
|
| 31 |
+
|
| 32 |
+
async function handle_upload({
|
| 33 |
+
detail
|
| 34 |
+
}: CustomEvent<FileData>): Promise<void> {
|
| 35 |
+
value = detail;
|
| 36 |
+
await tick();
|
| 37 |
+
dispatch("change", value);
|
| 38 |
+
dispatch("load", value);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
async function handle_clear(): Promise<void> {
|
| 42 |
+
value = null;
|
| 43 |
+
await tick();
|
| 44 |
+
dispatch("clear");
|
| 45 |
+
dispatch("change");
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
let use_3dgs = false;
|
| 49 |
+
let Canvas3DGSComponent: typeof Canvas3DGS;
|
| 50 |
+
let Canvas3DComponent: typeof Canvas3D;
|
| 51 |
+
async function loadCanvas3D(): Promise<typeof Canvas3D> {
|
| 52 |
+
const module = await import("./Canvas3D.svelte");
|
| 53 |
+
return module.default;
|
| 54 |
+
}
|
| 55 |
+
async function loadCanvas3DGS(): Promise<typeof Canvas3DGS> {
|
| 56 |
+
const module = await import("./Canvas3DGS.svelte");
|
| 57 |
+
return module.default;
|
| 58 |
+
}
|
| 59 |
+
$: if (value) {
|
| 60 |
+
use_3dgs = value.path.endsWith(".splat") || value.path.endsWith(".ply");
|
| 61 |
+
if (use_3dgs) {
|
| 62 |
+
loadCanvas3DGS().then((component) => {
|
| 63 |
+
Canvas3DGSComponent = component;
|
| 64 |
+
});
|
| 65 |
+
} else {
|
| 66 |
+
loadCanvas3D().then((component) => {
|
| 67 |
+
Canvas3DComponent = component;
|
| 68 |
+
});
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
let canvas3d: Canvas3D | undefined;
|
| 73 |
+
async function handle_undo(): Promise<void> {
|
| 74 |
+
canvas3d?.reset_camera_position(camera_position, zoom_speed, pan_speed);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
const dispatch = createEventDispatcher<{
|
| 78 |
+
change: FileData | null;
|
| 79 |
+
clear: undefined;
|
| 80 |
+
drag: boolean;
|
| 81 |
+
load: FileData;
|
| 82 |
+
}>();
|
| 83 |
+
|
| 84 |
+
let dragging = false;
|
| 85 |
+
|
| 86 |
+
$: dispatch("drag", dragging);
|
| 87 |
+
</script>
|
| 88 |
+
|
| 89 |
+
<BlockLabel {show_label} Icon={File} label={label || "3D Model"} />
|
| 90 |
+
|
| 91 |
+
{#if value === null}
|
| 92 |
+
<Upload
|
| 93 |
+
{upload}
|
| 94 |
+
{stream_handler}
|
| 95 |
+
on:load={handle_upload}
|
| 96 |
+
{root}
|
| 97 |
+
{max_file_size}
|
| 98 |
+
filetype={[".stl", ".obj", ".gltf", ".glb", "model/obj", ".splat", ".ply"]}
|
| 99 |
+
bind:dragging
|
| 100 |
+
bind:uploading
|
| 101 |
+
on:error
|
| 102 |
+
>
|
| 103 |
+
<slot />
|
| 104 |
+
</Upload>
|
| 105 |
+
{:else}
|
| 106 |
+
<div class="input-model">
|
| 107 |
+
<ModifyUpload
|
| 108 |
+
undoable={!use_3dgs}
|
| 109 |
+
on:clear={handle_clear}
|
| 110 |
+
{i18n}
|
| 111 |
+
on:undo={handle_undo}
|
| 112 |
+
/>
|
| 113 |
+
|
| 114 |
+
{#if use_3dgs}
|
| 115 |
+
<svelte:component
|
| 116 |
+
this={Canvas3DGSComponent}
|
| 117 |
+
{value}
|
| 118 |
+
{zoom_speed}
|
| 119 |
+
{pan_speed}
|
| 120 |
+
/>
|
| 121 |
+
{:else}
|
| 122 |
+
<svelte:component
|
| 123 |
+
this={Canvas3DComponent}
|
| 124 |
+
bind:this={canvas3d}
|
| 125 |
+
{value}
|
| 126 |
+
{display_mode}
|
| 127 |
+
{clear_color}
|
| 128 |
+
{camera_position}
|
| 129 |
+
{zoom_speed}
|
| 130 |
+
{pan_speed}
|
| 131 |
+
/>
|
| 132 |
+
{/if}
|
| 133 |
+
</div>
|
| 134 |
+
{/if}
|
| 135 |
+
|
| 136 |
+
<style>
|
| 137 |
+
.input-model {
|
| 138 |
+
display: flex;
|
| 139 |
+
position: relative;
|
| 140 |
+
justify-content: center;
|
| 141 |
+
align-items: center;
|
| 142 |
+
width: var(--size-full);
|
| 143 |
+
height: var(--size-full);
|
| 144 |
+
border-radius: var(--block-radius);
|
| 145 |
+
overflow: hidden;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
.input-model :global(canvas) {
|
| 149 |
+
width: var(--size-full);
|
| 150 |
+
height: var(--size-full);
|
| 151 |
+
object-fit: contain;
|
| 152 |
+
overflow: hidden;
|
| 153 |
+
}
|
| 154 |
+
</style>
|