inputs: add hue, lightness and font-weight controls
This commit is contained in:
1 parent
232c543990
commit
dfd2166284
3 files changed
+242
-3
No files matched your search
@@ -5,8 +5,10 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Studio Vitali</title>
|
<title>Studio Vitali</title>
|
||||||
<link rel="stylesheet" href="styles.css">
|
<link rel="stylesheet" href="styles.css">
|
||||||
|
<script src="script.js" defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<canvas id="canvas" aria-hidden="true"></canvas>
|
||||||
<header class="frame frame-block-start">
|
<header class="frame frame-block-start">
|
||||||
<h1>Studio Vitali GmbH</h1>
|
<h1>Studio Vitali GmbH</h1>
|
||||||
<a href="https://informatik.studiovitali.ch">Informatik</a>
|
<a href="https://informatik.studiovitali.ch">Informatik</a>
|
||||||
@@ -17,9 +19,16 @@
|
|||||||
<a href="tel:+41445201596" title="Telefon">+41 44 520 15 96</a>
|
<a href="tel:+41445201596" title="Telefon">+41 44 520 15 96</a>
|
||||||
</address>
|
</address>
|
||||||
<footer class="frame frame-block-end">
|
<footer class="frame frame-block-end">
|
||||||
|
<div class="legal">
|
||||||
<!-- <a href="https://zefix.ch/de/search/entity/list/firm/1651152" title="Zefix">CHE-215.230.900</a> -->
|
<!-- <a href="https://zefix.ch/de/search/entity/list/firm/1651152" title="Zefix">CHE-215.230.900</a> -->
|
||||||
<a href="#impressum" title="Impressum">Impressum</a>
|
<a href="#impressum" title="Impressum">Impressum</a>
|
||||||
<a href="#datenschutz" title="Datenschutz">Datenschutz</a>
|
<a href="#datenschutz" title="Datenschutz">Datenschutz</a>
|
||||||
|
</div>
|
||||||
|
<div class="controls">
|
||||||
|
<input id="hue" type="range" min="0" max="360" value="220" aria-label="Hue">
|
||||||
|
<input id="lightness" type="range" min="0" max="100" value="50" aria-label="Lightness">
|
||||||
|
<input id="weight" type="range" min="100" max="900" step="1" value="500" aria-label="Font weight">
|
||||||
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<address class="frame frame-inline-start">
|
<address class="frame frame-inline-start">
|
||||||
<a href="https://maps.app.goo.gl/sgo7hm1Xa4DBFRAYA" title="Google Maps">
|
<a href="https://maps.app.goo.gl/sgo7hm1Xa4DBFRAYA" title="Google Maps">
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
const root = document.documentElement;
|
||||||
|
const canvas = document.querySelector("#canvas");
|
||||||
|
const context = canvas.getContext("2d");
|
||||||
|
const hue = document.querySelector("#hue");
|
||||||
|
const lightness = document.querySelector("#lightness");
|
||||||
|
const weight = document.querySelector("#weight");
|
||||||
|
|
||||||
|
const updateTokens = () => {
|
||||||
|
root.style.setProperty("--color-hue", hue.value);
|
||||||
|
root.style.setProperty("--color-lightness", `${lightness.value}%`);
|
||||||
|
root.style.setProperty("--font-weight", weight.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
hue.addEventListener("input", updateTokens);
|
||||||
|
lightness.addEventListener("input", updateTokens);
|
||||||
|
weight.addEventListener("input", updateTokens);
|
||||||
|
updateTokens();
|
||||||
|
|
||||||
|
let scale = window.devicePixelRatio || 1;
|
||||||
|
|
||||||
|
function resizeCanvas() {
|
||||||
|
const previousScale = scale;
|
||||||
|
const previous = document.createElement("canvas");
|
||||||
|
const hadSize = canvas.dataset.sized === "true";
|
||||||
|
|
||||||
|
if (hadSize) {
|
||||||
|
previous.width = canvas.width;
|
||||||
|
previous.height = canvas.height;
|
||||||
|
previous.getContext("2d").drawImage(canvas, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
scale = window.devicePixelRatio || 1;
|
||||||
|
canvas.width = Math.round(window.innerWidth * scale);
|
||||||
|
canvas.height = Math.round(window.innerHeight * scale);
|
||||||
|
canvas.style.width = `${window.innerWidth}px`;
|
||||||
|
canvas.style.height = `${window.innerHeight}px`;
|
||||||
|
canvas.dataset.sized = "true";
|
||||||
|
|
||||||
|
context.setTransform(scale, 0, 0, scale, 0, 0);
|
||||||
|
context.lineCap = "round";
|
||||||
|
context.lineJoin = "round";
|
||||||
|
|
||||||
|
if (hadSize) {
|
||||||
|
context.drawImage(
|
||||||
|
previous,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
previous.width / previousScale,
|
||||||
|
previous.height / previousScale,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ink = () => getComputedStyle(document.body).color;
|
||||||
|
const brushSize = () => Number(weight.value) / 100;
|
||||||
|
|
||||||
|
let drawing = false;
|
||||||
|
let lastPoint = null;
|
||||||
|
|
||||||
|
canvas.addEventListener("pointerdown", (event) => {
|
||||||
|
if (event.button !== 0) return;
|
||||||
|
|
||||||
|
drawing = true;
|
||||||
|
lastPoint = { x: event.clientX, y: event.clientY };
|
||||||
|
canvas.setPointerCapture(event.pointerId);
|
||||||
|
|
||||||
|
context.fillStyle = ink();
|
||||||
|
context.beginPath();
|
||||||
|
context.arc(
|
||||||
|
lastPoint.x,
|
||||||
|
lastPoint.y,
|
||||||
|
brushSize() / 2,
|
||||||
|
0,
|
||||||
|
Math.PI * 2,
|
||||||
|
);
|
||||||
|
context.fill();
|
||||||
|
});
|
||||||
|
|
||||||
|
canvas.addEventListener("pointermove", (event) => {
|
||||||
|
if (!drawing || !lastPoint) return;
|
||||||
|
|
||||||
|
const nextPoint = { x: event.clientX, y: event.clientY };
|
||||||
|
|
||||||
|
context.strokeStyle = ink();
|
||||||
|
context.lineWidth = brushSize();
|
||||||
|
context.beginPath();
|
||||||
|
context.moveTo(lastPoint.x, lastPoint.y);
|
||||||
|
context.lineTo(nextPoint.x, nextPoint.y);
|
||||||
|
context.stroke();
|
||||||
|
|
||||||
|
lastPoint = nextPoint;
|
||||||
|
});
|
||||||
|
|
||||||
|
const stopDrawing = (event) => {
|
||||||
|
if (!drawing) return;
|
||||||
|
|
||||||
|
drawing = false;
|
||||||
|
lastPoint = null;
|
||||||
|
|
||||||
|
if (canvas.hasPointerCapture(event.pointerId)) {
|
||||||
|
canvas.releasePointerCapture(event.pointerId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
canvas.addEventListener("pointerup", stopDrawing);
|
||||||
|
canvas.addEventListener("pointercancel", stopDrawing);
|
||||||
|
window.addEventListener("resize", resizeCanvas);
|
||||||
|
|
||||||
|
resizeCanvas();
|
||||||
+124
-3
@@ -17,8 +17,15 @@
|
|||||||
:root {
|
:root {
|
||||||
--font-sans: "Geist", system-ui, sans-serif;
|
--font-sans: "Geist", system-ui, sans-serif;
|
||||||
--color-paper: #ffffff;
|
--color-paper: #ffffff;
|
||||||
--color-ink: #000000;
|
--color-hue: 220;
|
||||||
|
--color-saturation: 85%;
|
||||||
|
--color-lightness: 50%;
|
||||||
|
--color-ink: hsl(var(--color-hue) var(--color-saturation) var(--color-lightness));
|
||||||
|
--font-weight: 500;
|
||||||
--gutter: clamp(0.4rem, 1vw, 0.8rem);
|
--gutter: clamp(0.4rem, 1vw, 0.8rem);
|
||||||
|
|
||||||
|
--control-size: 1rem;
|
||||||
|
--control-border: solid 0.2rem var(--color-ink);
|
||||||
}
|
}
|
||||||
|
|
||||||
*,
|
*,
|
||||||
@@ -38,7 +45,7 @@ body {
|
|||||||
color: var(--color-ink);
|
color: var(--color-ink);
|
||||||
font-family: var(--font-sans);
|
font-family: var(--font-sans);
|
||||||
font-size: clamp(1rem, 2vw, 2rem);
|
font-size: clamp(1rem, 2vw, 2rem);
|
||||||
font-weight: 500;
|
font-weight: var(--font-weight);
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,10 +68,121 @@ address {
|
|||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#canvas {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
cursor: crosshair;
|
||||||
|
touch-action: none;
|
||||||
|
}
|
||||||
|
|
||||||
.frame {
|
.frame {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 1.2rem;
|
gap: 1.2rem;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legal {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
display: flex;
|
||||||
|
align-self: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
rotate: 180deg;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls input[type="range"] {
|
||||||
|
appearance: none;
|
||||||
|
width: clamp(5rem, 12vw, 8rem);
|
||||||
|
height: var(--control-size);
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#hue {
|
||||||
|
--hue-preview: 50%;
|
||||||
|
--range-track: linear-gradient(
|
||||||
|
to right,
|
||||||
|
hsl(0 var(--color-saturation) var(--hue-preview)),
|
||||||
|
hsl(60 var(--color-saturation) var(--hue-preview)),
|
||||||
|
hsl(120 var(--color-saturation) var(--hue-preview)),
|
||||||
|
hsl(180 var(--color-saturation) var(--hue-preview)),
|
||||||
|
hsl(240 var(--color-saturation) var(--hue-preview)),
|
||||||
|
hsl(300 var(--color-saturation) var(--hue-preview)),
|
||||||
|
hsl(360 var(--color-saturation) var(--hue-preview))
|
||||||
|
);
|
||||||
|
--range-thumb: hsl(
|
||||||
|
var(--color-hue) var(--color-saturation) var(--hue-preview)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#lightness {
|
||||||
|
--lightness-preview: calc(10% + var(--color-lightness) * 0.8);
|
||||||
|
--range-track: linear-gradient(
|
||||||
|
to right,
|
||||||
|
hsl(var(--color-hue) var(--color-saturation) 10%) 0%,
|
||||||
|
hsl(var(--color-hue) var(--color-saturation) var(--lightness-preview))
|
||||||
|
var(--color-lightness),
|
||||||
|
hsl(var(--color-hue) var(--color-saturation) 90%) 100%
|
||||||
|
);
|
||||||
|
--range-thumb: hsl(
|
||||||
|
var(--color-hue) var(--color-saturation) var(--lightness-preview)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#weight {
|
||||||
|
--range-track: linear-gradient(to right in oklab, #d9d9d9, #111111);
|
||||||
|
--range-thumb: color-mix(
|
||||||
|
in oklab,
|
||||||
|
#d9d9d9 calc((900 - var(--font-weight)) / 8 * 1%),
|
||||||
|
#111111
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls input[type="range"]::-webkit-slider-runnable-track {
|
||||||
|
height: 0.6rem;
|
||||||
|
border-radius: 0.2rem;
|
||||||
|
background: var(--range-track, #888888);
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls input[type="range"]::-webkit-slider-thumb {
|
||||||
|
appearance: none;
|
||||||
|
width: var(--control-size);
|
||||||
|
height: var(--control-size);
|
||||||
|
margin-top: -0.2rem;
|
||||||
|
border: var(--control-border);
|
||||||
|
border-color: var(--range-thumb, var(--color-ink));
|
||||||
|
border-radius: 0.2rem;
|
||||||
|
background: var(--color-paper);
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls input[type="range"]::-moz-range-track {
|
||||||
|
height: 0.6rem;
|
||||||
|
border-radius: 0.2rem;
|
||||||
|
background: var(--range-track, #888888);
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls input[type="range"]::-moz-range-thumb {
|
||||||
|
width: var(--control-size);
|
||||||
|
height: var(--control-size);
|
||||||
|
border: var(--control-border);
|
||||||
|
border-color: var(--range-thumb, var(--color-ink));
|
||||||
|
border-radius: 0.2rem;
|
||||||
|
background: var(--color-paper);
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls input[type="range"]:focus-visible {
|
||||||
|
outline: 0.1rem solid var(--color-ink);
|
||||||
|
outline-offset: 0.1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.frame-block-start {
|
.frame-block-start {
|
||||||
@@ -77,7 +195,10 @@ address {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.frame-block-end {
|
.frame-block-end {
|
||||||
inset: auto var(--gutter) var(--gutter) auto;
|
inset: auto var(--gutter) var(--gutter) var(--gutter);
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding-inline-end: 2.5rem;
|
||||||
rotate: 180deg;
|
rotate: 180deg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user