Model Test: color picker with confirm / close buttons
Browse files38 unmodified lines3940414243444517 unmodified lines636465666768699 unmodified lines79808182838485211 unmodified lines2972982993003013026 unmodified lines30931031131231331431531638 unmodified lines.tools button kbd { font-size: 10px; }.tools .sep { height: 6px; }.swatch { width: 20px; height: 10px; flex: none; border-radius: 3px; border: 1px solid #9ca3af; background: #ffffff; }#color { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }.foot { flex: none; display: flex; align-items: center; gap: 12px; min-height: 32px; padding: 6px 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }.foot .status { margin-left: auto; white-space: nowrap; }17 unmodified lines<div class="sep"></div><button id="colorBtn"><span class="name">์ปฌ๋ฌ์ ํ</span><span class="swatch" id="swatch"></span></button><button id="maskToggle"><span class="name">์ธํ์ธํธ ์์ญ ํ์</span><kbd>Tab</kbd></button><input type="color" id="color" value="#ffffff" tabindex="-1"></div><div class="notice">ํ์ฌ Gradio๋ฅผ ์์ฑํ ์ ์์ด ๋ฏธ๋ฆฌ ์์ ๋ ์ด๋ฏธ์ง๋ก ์ฌ์ฐํ๊ณ ์์ต๋๋ค.<br>Gradio can't be created right now, so this demo replays pre-processed images.</div></div><div class="foot">9 unmodified linesvar stage = document.getElementById("stage"), view = document.getElementById("view"), ctx = view.getContext("2d");var sizeEl = document.getElementById("size"), statusEl = document.getElementById("status"), busyEl = document.getElementById("busy");var undoBtn = document.getElementById("undo");var colorIn = document.getElementById("color");var maskToggle = document.getElementById("maskToggle");// base = current page (inpaint results baked in), mask = inpainted area, overlay = paint-over colors,211 unmodified linesvar KEYS = { w: "brush", e: "eraser", r: "paint", t: "paint_erase" };document.addEventListener("keydown", function (e) {if (e.code === "Space") { spaceDown = true; e.preventDefault(); }if ((e.ctrlKey || e.metaKey) && (e.key === "z" || e.key === "Z")) { e.preventDefault(); doUndo(); return; }if (e.ctrlKey || e.metaKey || e.altKey) return;6 unmodified linesdocument.querySelectorAll("#tools [data-tool]").forEach(function (b) {b.addEventListener("click", function () { setTool(b.getAttribute("data-tool")); });});document.getElementById("colorBtn").addEventListener("click", function () { colorIn.click(); });colorIn.addEventListener("input", function () { setColor(colorIn.value); });maskToggle.addEventListener("click", function () { setShowMask(!showMask); });undoBtn.addEventListener("click", doUndo);document.getElementById("fit").addEventListener("click", fit);38 unmodified lines39404142434445464748495051525354555657585960616263646517 unmodified lines83848586878889909192939495969 unmodified lines106107108109110111211 unmodified lines3233243253263273283293303313323336 unmodified lines34034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339438 unmodified lines.tools button kbd { font-size: 10px; }.tools .sep { height: 6px; }.swatch { width: 20px; height: 10px; flex: none; border-radius: 3px; border: 1px solid #9ca3af; background: #ffffff; }/* color picker popover: pick, then ํ์ธ applies / ๋ซ๊ธฐ (or Esc) cancels */.picker { position: absolute; top: 12px; right: 172px; width: 214px; padding: 10px; z-index: 3;border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.28); }.picker[hidden] { display: none; }.picker-head { display: flex; align-items: center; margin-bottom: 8px; font-weight: 600; font-size: 12px; }.picker-head .x { margin-left: auto; padding: 0 7px; line-height: 20px; font-size: 15px; }.sv { position: relative; height: 120px; border-radius: 5px; cursor: crosshair; touch-action: none;background: linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent); }.sv i { position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.5); pointer-events: none; }.hue { display: block; width: 100%; height: 12px; margin: 8px 0; -webkit-appearance: none; appearance: none; border-radius: 6px; outline: none; cursor: pointer;background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }.hue::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 1px solid #6b7280; }.hue::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 1px solid #6b7280; }.presets { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-bottom: 8px; }.presets button { height: 18px; padding: 0; border-radius: 3px; border: 1px solid #9ca3af; }.picker-row { display: flex; align-items: center; gap: 6px; }.picker-row .now { width: 26px; height: 22px; flex: none; border-radius: 4px; border: 1px solid #9ca3af; }.picker-row input { width: 0; flex: 1; padding: 3px 6px; border: 1px solid var(--line); border-radius: 5px; font: 12px ui-monospace, Consolas, monospace; }.picker-btns { display: flex; justify-content: flex-end; gap: 6px; margin-top: 10px; }.picker-btns .ok { border-color: var(--accent); background: var(--accent); color: #fff; }.picker-btns .ok:hover { background: var(--accent-base); color: #fff; }.foot { flex: none; display: flex; align-items: center; gap: 12px; min-height: 32px; padding: 6px 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }.foot .status { margin-left: auto; white-space: nowrap; }17 unmodified lines<div class="sep"></div><button id="colorBtn"><span class="name">์ปฌ๋ฌ์ ํ</span><span class="swatch" id="swatch"></span></button><button id="maskToggle"><span class="name">์ธํ์ธํธ ์์ญ ํ์</span><kbd>Tab</kbd></button></div><div class="picker" id="picker" hidden><div class="picker-head">๋ง์น ์ปฌ๋ฌ<button class="x" id="pickerX" aria-label="๋ซ๊ธฐ">×</button></div><div class="sv" id="sv"><i id="svDot"></i></div><input class="hue" id="hue" type="range" min="0" max="360" value="0"><div class="presets" id="presets"></div><div class="picker-row"><span class="now" id="pickNow"></span><input id="hex" maxlength="7" spellcheck="false"></div><div class="picker-btns"><button id="pickerCancel">๋ซ๊ธฐ</button><button class="ok" id="pickerOk">ํ์ธ</button></div></div><div class="notice">ํ์ฌ Gradio๋ฅผ ์์ฑํ ์ ์์ด ๋ฏธ๋ฆฌ ์์ ๋ ์ด๋ฏธ์ง๋ก ์ฌ์ฐํ๊ณ ์์ต๋๋ค.<br>Gradio can't be created right now, so this demo replays pre-processed images.</div></div><div class="foot">9 unmodified linesvar stage = document.getElementById("stage"), view = document.getElementById("view"), ctx = view.getContext("2d");var sizeEl = document.getElementById("size"), statusEl = document.getElementById("status"), busyEl = document.getElementById("busy");var undoBtn = document.getElementById("undo");var maskToggle = document.getElementById("maskToggle");// base = current page (inpaint results baked in), mask = inpainted area, overlay = paint-over colors,211 unmodified linesvar KEYS = { w: "brush", e: "eraser", r: "paint", t: "paint_erase" };document.addEventListener("keydown", function (e) {if (!picker.hidden) { // picker open: Enter = ํ์ธ, Esc = ๋ซ๊ธฐ; typing in the hex box stays thereif (e.key === "Enter") { e.preventDefault(); pickerOk(); }else if (e.key === "Escape") { e.preventDefault(); closePicker(); }if (e.target === hexIn) return;}if (e.code === "Space") { spaceDown = true; e.preventDefault(); }if ((e.ctrlKey || e.metaKey) && (e.key === "z" || e.key === "Z")) { e.preventDefault(); doUndo(); return; }if (e.ctrlKey || e.metaKey || e.altKey) return;6 unmodified linesdocument.querySelectorAll("#tools [data-tool]").forEach(function (b) {b.addEventListener("click", function () { setTool(b.getAttribute("data-tool")); });});// ---- color picker popover (HSV square + hue bar + presets + hex) ----var picker = document.getElementById("picker"), sv = document.getElementById("sv"), svDot = document.getElementById("svDot");var hueIn = document.getElementById("hue"), hexIn = document.getElementById("hex"), pickNow = document.getElementById("pickNow");var ph = 0, ps = 0, pv = 1; // picked color while the popover is openvar PRESETS = ["#ffffff", "#f2f2f2", "#d9d9d9", "#a6a6a6", "#737373", "#404040", "#1a1a1a", "#000000","#ff4d4f", "#ff9f40", "#ffd84d", "#5ad65a", "#31b9d4", "#4d7cff", "#a24dff", "#ff9fb9"];function hsvToHex(h, s, v) {var f = function (n) { var k = (n + h / 60) % 6; return v - v * s * Math.max(0, Math.min(k, 4 - k, 1)); };return "#" + [f(5), f(3), f(1)].map(function (x) { return ("0" + Math.round(x * 255).toString(16)).slice(-2); }).join("");}function hexToHsv(hex) {var r = parseInt(hex.slice(1, 3), 16) / 255, g = parseInt(hex.slice(3, 5), 16) / 255, b = parseInt(hex.slice(5, 7), 16) / 255;var max = Math.max(r, g, b), d = max - Math.min(r, g, b), h = 0;if (d) h = max === r ? ((g - b) / d) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;return [(h * 60 + 360) % 360, max ? d / max : 0, max];}function showPick(fromHex) {var hex = hsvToHex(ph, ps, pv);sv.style.backgroundColor = "hsl(" + ph + ",100%,50%)";svDot.style.left = (ps * 100) + "%"; svDot.style.top = ((1 - pv) * 100) + "%";hueIn.value = ph; pickNow.style.background = hex;if (!fromHex) hexIn.value = hex;}function pickHex(hex) { var t = hexToHsv(hex); ph = t[0]; ps = t[1]; pv = t[2]; showPick(); }function openPicker() { pickHex(paintColor); picker.hidden = false; }function closePicker() { picker.hidden = true; }function pickerOk() { setColor(hsvToHex(ph, ps, pv)); closePicker(); }PRESETS.forEach(function (c) {var b = document.createElement("button"); b.style.background = c; b.title = c;b.addEventListener("click", function () { pickHex(c); });document.getElementById("presets").appendChild(b);});function svAt(e) {var r = sv.getBoundingClientRect();ps = Math.max(0, Math.min(1, (e.clientX - r.left) / r.width));pv = 1 - Math.max(0, Math.min(1, (e.clientY - r.top) / r.height));showPick();}sv.addEventListener("pointerdown", function (e) { sv.setPointerCapture(e.pointerId); svAt(e); });sv.addEventListener("pointermove", function (e) { if (sv.hasPointerCapture(e.pointerId)) svAt(e); });hueIn.addEventListener("input", function () { ph = +hueIn.value; showPick(); });hexIn.addEventListener("input", function () {var v = hexIn.value.trim(); if (v[0] !== "#") v = "#" + v;if (/^#[0-9a-fA-F]{6}$/.test(v)) { var t = hexToHsv(v.toLowerCase()); ph = t[0]; ps = t[1]; pv = t[2]; showPick(true); }});document.getElementById("colorBtn").addEventListener("click", function () { picker.hidden ? openPicker() : closePicker(); });document.getElementById("pickerOk").addEventListener("click", pickerOk);document.getElementById("pickerCancel").addEventListener("click", closePicker);document.getElementById("pickerX").addEventListener("click", closePicker);maskToggle.addEventListener("click", function () { setShowMask(!showMask); });undoBtn.addEventListener("click", doUndo);document.getElementById("fit").addEventListener("click", fit);
model_test/index.html+83-5