From d4aef4920cf5e773919cb82937b7a880890a0a77 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Thu, 22 Aug 2024 13:35:36 +0200 Subject: [PATCH] Slider-input web component (#1109) * feat: slider-input web component * feat: slider-input web component - Brush size * feat: slider-input - statesGrowthRate * feat: slider-input - units editor * feat: slider-input - dissalow invalid numbers * chore: pump version to v1.99.05 * chore: pump version to v1.99.05 --------- Co-authored-by: Azgaar --- components/slider-input.js | 78 ++++ index.css | 134 ++---- index.html | 467 ++++++-------------- modules/burgs-and-states.js | 19 +- modules/cultures-generator.js | 2 +- modules/dynamic/editors/cultures-editor.js | 25 +- modules/dynamic/editors/religions-editor.js | 32 +- modules/dynamic/editors/states-editor.js | 86 +--- modules/io/load.js | 10 +- modules/relief-icons.js | 4 +- modules/religions-generator.js | 5 +- modules/river-generator.js | 1 - modules/ui/biomes-editor.js | 6 +- modules/ui/burgs-overview.js | 4 +- modules/ui/editors.js | 21 +- modules/ui/heightmap-editor.js | 10 +- modules/ui/hotkeys.js | 29 +- modules/ui/layers.js | 28 +- modules/ui/options.js | 54 +-- modules/ui/provinces-editor.js | 8 +- modules/ui/style.js | 249 +++++------ modules/ui/submap.js | 11 +- modules/ui/tools.js | 8 +- modules/ui/units-editor.js | 42 +- utils/probabilityUtils.js | 9 +- versioning.js | 2 +- 26 files changed, 546 insertions(+), 798 deletions(-) create mode 100644 components/slider-input.js diff --git a/components/slider-input.js b/components/slider-input.js new file mode 100644 index 00000000..f1732027 --- /dev/null +++ b/components/slider-input.js @@ -0,0 +1,78 @@ +{ + const style = /* css */ ` + slider-input { + display: flex; + align-items: center; + gap: .4em; + } + `; + + const styleElement = document.createElement("style"); + styleElement.setAttribute("type", "text/css"); + styleElement.innerHTML = style; + document.head.appendChild(styleElement); +} + +{ + const template = document.createElement("template"); + template.innerHTML = /* html */ ` + + + `; + + class SliderInput extends HTMLElement { + constructor() { + super(); + this.appendChild(template.content.cloneNode(true)); + + const range = this.querySelector("input[type=range]"); + const number = this.querySelector("input[type=number]"); + + range.value = number.value = this.value || this.getAttribute("value") || 50; + range.min = number.min = this.getAttribute("min") || 0; + range.max = number.max = this.getAttribute("max") || 100; + range.step = number.step = this.getAttribute("step") || 1; + + range.addEventListener("input", this.handleEvent.bind(this)); + number.addEventListener("input", this.handleEvent.bind(this)); + range.addEventListener("change", this.handleEvent.bind(this)); + number.addEventListener("change", this.handleEvent.bind(this)); + } + + handleEvent(e) { + const value = e.target.value; + const isNaN = Number.isNaN(Number(value)); + if (isNaN || value === "") return e.stopPropagation(); + + const range = this.querySelector("input[type=range]"); + const number = this.querySelector("input[type=number]"); + this.value = range.value = number.value = value; + + this.dispatchEvent( + new CustomEvent(e.type, { + detail: {value}, + bubbles: true, + composed: true + }) + ); + } + + set value(value) { + const range = this.querySelector("input[type=range]"); + const number = this.querySelector("input[type=number]"); + range.value = number.value = value; + } + + get value() { + const number = this.querySelector("input[type=number]"); + return number.value; + } + + get valueAsNumber() { + const number = this.querySelector("input[type=number]"); + return number.valueAsNumber; + } + } + + customElements.define("slider-input", SliderInput); +} diff --git a/index.css b/index.css index 555b650c..da6acf9e 100644 --- a/index.css +++ b/index.css @@ -525,7 +525,48 @@ input[type="color"]::-webkit-color-swatch-wrapper { font-size: smaller; } +#options input[type="text"] { + border: 0px; + width: 62%; + font-size: smaller; +} + +#options output { + text-align: right; + font-size: smaller; +} + +#options input[type="number"] { + font-size: 0.8em; + border: 0; + text-align: right; + background-color: transparent; + width: 3.3em; +} + +#options input[type="number"]::-webkit-inner-spin-button, +#options input[type="number"]::-webkit-outer-spin-button { + -webkit-appearance: none; + margin: 0; +} + +#options input[type="number"]:hover { + outline: 1px solid var(--dark-solid); +} + +#options input.paired { + text-align: center; + background-color: white; +} + +#options input.long { + width: 100%; + background-color: white; + text-align: left; +} + #options input[type="range"] { + width: 100%; height: 8px; background: 0; appearance: none; @@ -568,55 +609,7 @@ input[type="color"]::-webkit-color-swatch-wrapper { height: 2px; } -#options input[type="number"] { - font-size: 0.8em; -} - -#options input[type="text"] { - border: 0px; - width: 62%; - font-size: smaller; -} - -#optionsContent output { - text-align: right; - font-size: smaller; -} - -#optionsContent input[type="number"] { - border: 0; - text-align: right; - background-color: transparent; - width: 3.3em; - -moz-appearance: textfield; -} - -#optionsContent input[type="number"]::-webkit-inner-spin-button, -#optionsContent input[type="number"]::-webkit-outer-spin-button { - -webkit-appearance: none; - margin: 0; -} - -#optionsContent input[type="number"]:hover { - outline: 1px solid var(--dark-solid); -} - -#optionsContent input.paired { - text-align: center; - background-color: white; -} - -#optionsContent input.long { - width: 100%; - background-color: white; - text-align: left; -} - -#optionsContent input[type="range"] { - width: 100%; -} - -#optionsContent select { +#options select { width: 100%; } @@ -641,19 +634,6 @@ input[type="color"]::-webkit-color-swatch-wrapper { transform: translate(0px, 1px); } -#styleElements input[type="range"] { - width: 64%; -} - -#styleElements select { - width: 64%; -} - -#styleElements input[type="number"] { - width: 6em; - border: 0; -} - #styleSelectFont > option { font-size: 2em; } @@ -724,9 +704,6 @@ input[type="color"]::-webkit-color-swatch-wrapper { padding: 0.45em 0.75em; margin: 0.35em 0; transition: 0.1s; - font-size: 1em; - text-transform: capitalize; - overflow: hidden; white-space: nowrap; text-overflow: ellipsis; @@ -1268,7 +1245,6 @@ i.resetButton:active { padding: 0; height: 2px; background: #d4d4d4; - top: -0.35em; position: relative; appearance: none; -webkit-appearance: none; @@ -1844,11 +1820,6 @@ div.editorLine { padding: 0px 3px !important; } -#unitsBody > div > * { - display: inline-block; - margin-bottom: 0.2em; -} - .unitsHeader { margin: 0.8em 0 0 -1.1em; font-weight: bold; @@ -1860,28 +1831,21 @@ div.editorLine { margin: 6px 0 0 6px; } -#unitsBody > div > div { +#unitsBody label { + display: inline-block; width: 9em; } -#unitsBody > div > input[type="range"] { - width: 7em; -} - #unitsBody > div > select, #unitsBody > div > input[type="text"] { - width: 12em; -} - -#unitsBody > div > input[type="number"] { - width: 4.35em; -} - -#unitsBody > div > input, -#unitsBody > div > select { + width: 14.4em; border: 1px solid #e9e9e9; } +#unitsBody input[type="range"] { + width: 9em; +} + #unitsEditor i.icon-lock-open, #unitsEditor i.icon-lock { color: #626573; diff --git a/index.html b/index.html index 20ac57af..da02b625 100644 --- a/index.html +++ b/index.html @@ -138,7 +138,7 @@ } - + @@ -836,27 +836,24 @@ - + Terracing - - 0 + Reduce layers - - 5 + Simplify line - - 0 + @@ -874,7 +871,7 @@ Color scheme - + @@ -1241,7 +1221,7 @@ - + @@ -1281,16 +1261,14 @@ Fill opacity - - 0.3 + Labels size - - 8 + @@ -1307,8 +1285,7 @@ Body opacity - - + @@ -1326,24 +1303,21 @@ Halo width - - 10 + Halo opacity - - 1 + Halo blur - - 4 + @@ -1352,22 +1326,20 @@ Fill opacity - - 1 + Box Size - - 3 + - State Size + State size - Province Size + Province size - Burg Size + Burg size Back opacity - - + Back fill - + @@ -1511,7 +1482,7 @@ Back stroke - + Width @@ -1712,53 +1683,41 @@ - + States number - - - - - + + - + Provinces ratio - - - - - + + - + Size variety - - - - - + + - + Growth rate - - - - - + + @@ -1779,14 +1738,17 @@ data-tip="Define how many organized religions and cults should be generated. Cultures will have their own folk religions in any case" > - + Religions number - - - - - + + @@ -1815,22 +1777,16 @@ > Interface size - - - - - + + Tooltip size - - - - - + + @@ -1850,11 +1806,8 @@ Transparency - - - - - + + @@ -4123,72 +4076,24 @@