semantic-forms 5.3.17 → 5.3.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+ // the variables are set at zero specificity, so that an app overriding one with any selector of its own, such as form.semanticForms, wins without needing a heavier selector or !important. that holds in dark mode too, whose blocks further down are written the same way
2
+ :where(form.semanticForms, table.semanticForms, .semanticFormsButton) {
3
+ --semanticFormsFontFamily: sans-serif;
4
+ --semanticFormsCursor: pointer; // what the pointer looks like over a button, a checkbox, a select and the like. a desktop app may want default, as native controls have
5
+ --semanticFormsFontSize: 16px;
6
+ --semanticFormsFormBgColor: #fff;
7
+ --semanticFormsFormSubBgColor: #f5f5f5;
8
+ --semanticFormsTextColor: #000;
9
+ --semanticFormsBorderColor: #c0c0c0;
10
+ // the focus ring is drawn inside the field, so what it has to stand out against is the field's own background. this is the lightest grey that still clears the 3:1 WCAG asks of a focus indicator against white; the old #c0c0c0 managed 1.8:1
11
+ --semanticFormsFocusColor: #8c8c8c;
12
+ --semanticFormsSubBorderColor: #c0c0c0;
13
+ --semanticFormsPlaceholderColor: rgba(0, 0, 0, 0.75);
14
+ --semanticFormsScrollbarColor: #c0c0c0;
15
+ --semanticFormsClearButtonColor: #000;
16
+ --semanticFormsButtonGradientLight: #fff;
17
+ --semanticFormsButtonGradientDark: #c0c0c0;
18
+ --semanticFormsInvalid: #f00;
19
+ --semanticFormsInvalidBorder: 1px solid var(--semanticFormsInvalid);
20
+ --semanticFormsWarn: #ffdd00;
21
+ --semanticFormsWarnBorder: 1px solid var(--semanticFormsWarn);
22
+ --semanticFormsInputHeight: 38px;
23
+ --semanticFormsInputFontSize: 16px;
24
+ --semanticFormsInputTopMargin: 15px;
25
+ --semanticFormsInputMinWidth: 250px;
26
+ --semanticFormsInputMaxWidth: 365px;
27
+ --semanticFormsInputColumnMaxWidth: 1fr;
28
+ --semanticFormsBorderRadius: 10px;
29
+ // the operating system's own highlight colour, so a switch matches the other controls the visitor sees, with the blue kept for anything that does not know the keyword. overriding this variable still wins over both
30
+ --semanticFormsSwitchOnColor: #2196f3;
31
+
32
+ @supports (color: AccentColor) {
33
+ --semanticFormsSwitchOnColor: AccentColor;
34
+ }
35
+
36
+ --semanticFormsSwitchOffColor: #c0c0c0;
37
+ --semanticFormsSwitchThumbColor: #fff;
38
+ // the browser's own autofill highlight cannot be painted over, so the form hides it and marks an autofilled field itself: see inputs.scss. it follows the system accent, so it reads as something the browser did rather than part of the form
39
+ --semanticFormsAutofillColor: #2196f3;
40
+
41
+ @supports (color: AccentColor) {
42
+ --semanticFormsAutofillColor: AccentColor;
43
+ }
44
+
45
+ --semanticFormsNestedFieldsetBgColor: oklch(from var(--semanticFormsFormSubBgColor) 0.3 c h / 0.05);
46
+ --semanticFormsNestedFieldsetBorder: 1px rgba(0, 0, 0, .2) solid;
47
+ --semanticFormsNestedInputBgColor: #fff;
48
+ --semanticFormsBorder: 1px var(--semanticFormsBorderColor) solid;
49
+ --semanticFormsTableTitleColor: #fcfcfc;
50
+ --semanticFormsTableHeaderColor: #eeeeee;
51
+ --semanticFormsTableOddColor: #dddddd;
52
+ --semanticFormsTableEvenColor: #cccccc;
53
+ --semanticFormsTableBorder: 1px #c0c0c0 solid;
54
+ --semanticFormsSelectIcon: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='%23000'%3E%3Cpolygon points='0,0 100,0 50,50'/%3E%3C/svg%3E");
55
+ --semanticFormsCustomResizer: url("data:image/svg+xml;utf8,%3Csvg width='20' height='20' viewBox='0 0 5.2916665 5.2916666' version='1.1' id='svg5' xmlns='http://www.w3.org/2000/svg' xmlns:svg='http://www.w3.org/2000/svg'%3E%3Cdefs id='defs2' /%3E%3Cg id='layer1'%3E%3Cpath style='fill:%23aaa;stroke:%23aaa;stroke-width:0.264583;stroke-dasharray:none;stroke-opacity:1' d='M 2.8245112,5.0994569 C 4.9396993,2.9842685 4.9396993,2.9842685 4.9396993,2.9842685' id='path1034' /%3E%3Cpath style='fill:%23aaa;stroke:%23aaa;stroke-width:0.264583;stroke-dasharray:none;stroke-opacity:1' d='M 1.515747,5.0406977 C 4.8873304,1.6691138 4.8873304,1.6691138 4.8873304,1.6691138' id='path1034-1' /%3E%3Cpath style='fill:%23aaa;stroke:%23aaa;stroke-width:0.264583;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1' d='M 0.20657789,5.0909782 C 4.9312207,0.3663348 4.9312207,0.3663348 4.9312207,0.3663348' id='path1034-9' /%3E%3C/g%3E%3C/svg%3E");
56
+ // drawn on an 18 unit grid, the size it's shown at, so each unit is a pixel: its 2px lines are placed on whole pixels, which keeps them crisp. a grid of another size, or lines of a fractional width, put its edges between pixels, which looks jagged
57
+ --semanticFormsSearchIcon: url("data:image/svg+xml,%3Csvg%20width%3D%2218px%22%20height%3D%2218px%22%20viewBox%3D%220%200%2018%2018%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Ccircle%20cx%3D%228%22%20cy%3D%228%22%20r%3D%225%22%20stroke%3D%22%23000000%22%20stroke-width%3D%222%22%2F%3E%3Cpath%20d%3D%22M12%2012L16%2016%22%20stroke%3D%22%23000000%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%2F%3E%3C%2Fsvg%3E");
58
+ // the colour of the page the theme was designed against. the library paints nothing with it, since the page is outside the form, but an app can give the form this background so that, for example, a form in dark mode stays readable on a light page. see the theming docs
59
+ --semanticFormsPageBgColor: #fff;
60
+ }
61
+
62
+ form.semanticForms,
63
+ table.semanticForms {
64
+ font-family: var(--semanticFormsFontFamily);
65
+ font-size: var(--semanticFormsFontSize);
66
+ width: 100%;
67
+ overflow-x: hidden;
68
+
69
+ &:not(table) {
70
+ display: flex;
71
+ flex-direction: column;
72
+ gap: 10px;
73
+ }
74
+
75
+ // https://caniuse.com/wf-interpolate-size
76
+ @supports (interpolate-size: allow-keywords) {
77
+ interpolate-size: allow-keywords;
78
+ }
79
+
80
+ // due to the specificity of some of these rules, [hidden] won't actually hide things, so we're forcing the issue
81
+ [hidden] {
82
+ display: none !important;
83
+ }
84
+
85
+ // hides semantic forms divs if the field itself is hidden
86
+ div:has(dd[hidden]) {
87
+ display: none !important;
88
+ }
89
+
90
+ // input + container style reset
91
+ //
92
+ // wrapped in :where so that this weighs no more than the form's own class and element, which an app's ordinary rule for its own markup can match
93
+ :where(fieldset, label, input, select, textarea, button, menu:has(li > input, li > label, li > button, li > select, li > textarea), dl:has(dt > label, dd > input, dd > select, dd > textarea), dt:has(> input, > select, > textarea), dd:has(> input, > select, > textarea, > ul, > menu), div:has(dt, dd), dd > p) {
94
+ color: var(--semanticFormsTextColor);
95
+ font-family: var(--semanticFormsFontFamily);
96
+ box-sizing: border-box;
97
+ }
98
+ }
99
+
100
+ // margin/padding reset for various elements commonly used in semantic-forms
101
+ //
102
+ // this only undoes the browser's own margins and padding, so it weighs no more than a single class: it still wins over a page's rules for bare elements, such as `p` or `div`, while any rule an app writes for its own markup inside the form, such as a row of its own design, wins over it
103
+ :where(form, table).semanticForms :where(menu, dl, dt, dd, div, dd > p) {
104
+ margin: 0;
105
+ padding: 0;
106
+ }
107
+
108
+ @mixin dark-mode {
109
+ --semanticFormsFormBgColor: #555;
110
+ --inputBackgroudColor: rgba(85,85,85,0.1);
111
+ --semanticFormsFormSubBgColor: #2f2f2f;
112
+ --semanticFormsTextColor: #fff;
113
+ --semanticFormsBorderColor: #656565;
114
+ // as in light mode, measured against the field's own background: #656565 on #555 was 1.3:1, which is all but invisible
115
+ --semanticFormsFocusColor: #b0b0b0;
116
+ --semanticFormsSubBorderColor: #3f3f3f;
117
+ --semanticFormsPlaceholderColor: rgba(255, 255, 255, 0.85);
118
+ --semanticFormsScrollbarColor: #373737;
119
+ --semanticFormsClearButtonColor: #fff;
120
+ --semanticFormsButtonGradientLight: #6f6f6f;
121
+ --semanticFormsButtonGradientDark: #373737;
122
+ // the operating system's own highlight colour, so a switch matches the other controls the visitor sees, with the blue kept for anything that does not know the keyword. overriding this variable still wins over both
123
+ --semanticFormsSwitchOnColor: #2196f3;
124
+
125
+ @supports (color: AccentColor) {
126
+ --semanticFormsSwitchOnColor: AccentColor;
127
+ }
128
+
129
+ --semanticFormsSwitchOffColor: #656565;
130
+ --semanticFormsSwitchThumbColor: #fff;
131
+ // as above
132
+ --semanticFormsAutofillColor: #2196f3;
133
+
134
+ @supports (color: AccentColor) {
135
+ --semanticFormsAutofillColor: AccentColor;
136
+ }
137
+
138
+ --semanticFormsNestedFieldsetBgColor: oklch(from var(--semanticFormsFormSubBgColor) 0.9 c h / 0.05);
139
+ --semanticFormsNestedFieldsetBorder: 1px rgba(255, 255, 255, .1) solid;
140
+ --semanticFormsNestedInputBgColor: rgba(255, 255, 255, .15);
141
+ --semanticFormsBorder: none;
142
+ --semanticFormsTableTitleColor: #3f3f3f;
143
+ --semanticFormsTableHeaderColor: #4f4f4f;
144
+ --semanticFormsTableOddColor: #3f3f3f;
145
+ --semanticFormsTableEvenColor: #4f4f4f;
146
+ --semanticFormsTableBorder: 1px #656565 solid;
147
+ --semanticFormsSelectIcon: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='%23fff'%3E%3Cpolygon stroke='%23fff' points='0,0 100,0 50,50'/%3E%3C/svg%3E");
148
+ --semanticFormsCustomResizer: url("data:image/svg+xml;utf8,%3Csvg width='20' height='20' viewBox='0 0 5.2916665 5.2916666' version='1.1' id='svg5' xmlns='http://www.w3.org/2000/svg' xmlns:svg='http://www.w3.org/2000/svg'%3E%3Cdefs id='defs2' /%3E%3Cg id='layer1'%3E%3Cpath style='fill:%23c9c9c9;stroke:%23c9c9c9;stroke-width:0.264583;stroke-dasharray:none;stroke-opacity:1' d='M 2.8245112,5.0994569 C 4.9396993,2.9842685 4.9396993,2.9842685 4.9396993,2.9842685' id='path1034' /%3E%3Cpath style='fill:%23c9c9c9;stroke:%23c9c9c9;stroke-width:0.264583;stroke-dasharray:none;stroke-opacity:1' d='M 1.515747,5.0406977 C 4.8873304,1.6691138 4.8873304,1.6691138 4.8873304,1.6691138' id='path1034-1' /%3E%3Cpath style='fill:%23c9c9c9;stroke:%23c9c9c9;stroke-width:0.264583;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1' d='M 0.20657789,5.0909782 C 4.9312207,0.3663348 4.9312207,0.3663348 4.9312207,0.3663348' id='path1034-9' /%3E%3C/g%3E%3C/svg%3E");
149
+ --semanticFormsSearchIcon: url("data:image/svg+xml,%3Csvg%20width%3D%2218px%22%20height%3D%2218px%22%20viewBox%3D%220%200%2018%2018%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Ccircle%20cx%3D%228%22%20cy%3D%228%22%20r%3D%225%22%20stroke%3D%22%23FFFFFF%22%20stroke-width%3D%222%22%2F%3E%3Cpath%20d%3D%22M12%2012L16%2016%22%20stroke%3D%22%23FFFFFF%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%2F%3E%3C%2Fsvg%3E");
150
+ --semanticFormsPageBgColor: #000;
151
+
152
+ // the browser's own parts of the controls, such as scrollbars and date pickers, are drawn dark too
153
+ color-scheme: dark;
154
+
155
+ input::-webkit-calendar-picker-indicator {
156
+ filter: invert(100%);
157
+ }
158
+ }
159
+
160
+ // like the light values above, these are wrapped in :where so they weigh nothing, and an app's own override of a variable wins in dark mode just as it does in light mode. they still take over from the light values because they come later
161
+ @media (prefers-color-scheme: dark) {
162
+ :where(html:not(.light) body:not(.light) form.semanticForms:not(.light), html:not(.light) body:not(.light) table.semanticForms:not(.light), html:not(.light) body:not(.light) .semanticFormsButton:not(.light)) {
163
+ @include dark-mode;
164
+ }
165
+ }
166
+
167
+ :where(html:not(.light) body:not(.light) form.semanticForms.dark, html:not(.light) body:not(.light) table.semanticForms.dark, html:not(.light) body:not(.light) .semanticFormsButton.dark) {
168
+ @include dark-mode;
169
+ }
170
+
171
+ :where(form.semanticForms.dark, table.semanticForms.dark, .semanticFormsButton.dark) {
172
+ @include dark-mode;
173
+ }
174
+
175
+ // the colour of the page the theme was designed against, which the forms define for themselves, is defined for the whole page too, so a page can paint its own background with it: see the theming docs
176
+ :where(:root) {
177
+ --semanticFormsPageBgColor: #fff;
178
+ }
179
+
180
+ @media (prefers-color-scheme: dark) {
181
+ :where(:root:not(.light)) {
182
+ --semanticFormsPageBgColor: #000;
183
+ }
184
+ }
185
+
186
+ :where(:root.dark) {
187
+ --semanticFormsPageBgColor: #000;
188
+ }
189
+ // help text that a screen reader reads but the page does not draw, which the enhancement adds beside a field carrying a help icon
190
+ //
191
+ // it is moved out of sight rather than hidden with display: none or the hidden attribute, either of which would take it out of the accessibility tree along with the screen, leaving the field with nothing to describe it. it is taken out of flow too, so a grid or flex row it lands in does not lay it out as an item
192
+ .semanticFormsVisuallyHidden {
193
+ position: absolute;
194
+ width: 1px;
195
+ height: 1px;
196
+ margin: -1px;
197
+ padding: 0;
198
+ border: 0;
199
+ overflow: hidden;
200
+ clip-path: inset(50%);
201
+ white-space: nowrap;
202
+ }
@@ -0,0 +1,473 @@
1
+ @use 'layoutScope.scss' as *;
2
+
3
+ // the clear button is square, and its size is what centers it on the field
4
+ $clearButtonSize: 25px;
5
+
6
+ // how a button looks, in a form or as a .semanticFormsButton outside one
7
+ @mixin button {
8
+ appearance: none;
9
+ -moz-appearance: none;
10
+ -webkit-appearance: none;
11
+ cursor: var(--semanticFormsCursor, pointer);
12
+ max-width: max-content;
13
+ background-image: linear-gradient(to bottom, var(--semanticFormsButtonGradientLight) 0%, var(--semanticFormsButtonGradientDark) 100%);
14
+ background-origin: border-box; // prevents graphical errors in Firefox
15
+ border: 1px var(--semanticFormsButtonGradientDark) solid;
16
+ corner-shape: squircle;
17
+ border-radius: 20px;
18
+ // the browser centers a control's text on the middle of the box holding it, which is not quite where the letters sit. the enhancement measures that difference for the page's font, and taking it off the top padding and adding it to the bottom moves the letters rather than the box
19
+ padding: calc(5px - var(--semanticFormsFieldTextInkOffset, 0px)) 25px calc(5px + var(--semanticFormsFieldTextInkOffset, 0px));
20
+ font-size: 100%;
21
+ line-height: 1;
22
+ user-select: none;
23
+ transform: scale(1);
24
+ transition: transform 180ms;
25
+ text-decoration: none;
26
+ color: var(--semanticFormsTextColor);
27
+
28
+ &:active {
29
+ transform: scale(0.97);
30
+ }
31
+
32
+ // the press is motion, so a visitor who asked for less of it gets the button without it. only the movement goes: the hover brightness below is a colour change, not motion, and stays
33
+ @media (prefers-reduced-motion: reduce) {
34
+ transition: none;
35
+
36
+ &:active {
37
+ transform: none;
38
+ }
39
+ }
40
+ }
41
+
42
+ @mixin button-hover {
43
+ transition: filter 0.1s;
44
+
45
+ &:hover {
46
+ filter: brightness(1.05);
47
+ }
48
+ }
49
+
50
+ // the control selectors below wrap everything past the element name in :where, so each weighs no more than the form's class and the element itself. that is the weight of an app's ordinary rule, such as `form.myForm input[type=number]`, which then wins without needing an id or !important. rules that have to win over these, such as focus and invalid states, add their own state on top, and the grid layout's rules in the other files are deliberately heavier
51
+ .semanticForms {
52
+ input:where(:not([type=submit], [type=reset], [type=button], [type=image], [type=checkbox], [type=radio])),
53
+ select {
54
+ height: var(--semanticFormsInputHeight);
55
+ }
56
+
57
+ input:where([type=checkbox], [type=radio]) {
58
+ width: 18px;
59
+ height: 18px;
60
+ margin: 3px 0;
61
+ cursor: var(--semanticFormsCursor, pointer);
62
+ }
63
+
64
+ // this styles the label rather than the control, so it keeps the weight it has always had. rules elsewhere are written to lose to it, such as the subtext colour in the lowFlow layout
65
+ input[type=checkbox],
66
+ input[type=radio] {
67
+ & ~ label:first-of-type {
68
+ color: var(--semanticFormsTextColor);
69
+ }
70
+ }
71
+
72
+ input:where(:not([type=submit], [type=reset], [type=button], [type=image], [type=checkbox], [type=radio])),
73
+ select,
74
+ textarea {
75
+ font-size: var(--semanticFormsInputFontSize);
76
+ background: var(--semanticFormsFormBgColor);
77
+ border: var(--semanticFormsBorder);
78
+ border-radius: var(--semanticFormsBorderRadius);
79
+ width: 100%;
80
+ touch-action: manipulation;
81
+ outline: none;
82
+
83
+ // custom focus highlight
84
+ //
85
+ // drawn inside the element rather than around it: forms clip their horizontal overflow, so a ring painted outside the box loses its outer edge on any field sitting flush against the form's edge, which made the highlight look thinner there than everywhere else
86
+ &:focus {
87
+ outline: none;
88
+ box-shadow: inset 0 0 0 2px var(--semanticFormsFocusColor);
89
+
90
+ // forced colors mode drops box shadows, which would leave the field with no focus ring at all, so it is drawn as a real outline there. the negative offset puts it inside the box, where the shadow is, so a field sitting flush against the form's edge does not have it clipped
91
+ @media (forced-colors: active) {
92
+ outline: 2px solid Highlight;
93
+ outline-offset: -2px;
94
+ }
95
+ }
96
+
97
+ // the browser centers a control's text on the middle of the box holding it, which is not quite where the letters sit. the enhancement measures that difference for the page's font, and taking it off the top padding and adding it to the bottom moves the letters rather than the box
98
+ //
99
+ // textareas are left out: their text starts at the top and runs down, so there is no single line to center, and shifting it up only crops the last one against the bottom edge. selects are left out too and padded further down, because the browser places the text of a select differently from the text a field draws inside itself
100
+ //
101
+ // the right padding matches the left here. the extra room kept for the clear and show password buttons is added below, only where the enhancement puts those buttons
102
+ &:where(:not([type=range], textarea, select)) {
103
+ padding: calc(6px - var(--semanticFormsFieldTextInkOffset, 0px)) 20px calc(6px + var(--semanticFormsFieldTextInkOffset, 0px)) 20px;
104
+ }
105
+
106
+ // the clear button and the show password button are only ever added to fields in the grid layout, inside a <dd>, so only there does the field keep room for them on the right. a field anywhere else would have its text cut short for a button it does not have
107
+ //
108
+ // the <dd> is wrapped in :where along with everything else, so that this weighs the same as the rule above and wins by coming after it rather than by being heavier
109
+ //
110
+ // a <dl> in a customLayout element gets no buttons either, so it keeps no room for them: see layoutScope.scss
111
+ @at-root .semanticForms :where(dl#{$notCustomLayout} dd) input:where(:not([type=submit], [type=reset], [type=button], [type=image], [type=checkbox], [type=radio], [type=range])) {
112
+ padding-right: 30px;
113
+ }
114
+
115
+ // input type styling
116
+ @at-root .semanticForms :where(dl#{$notCustomLayout} dd) input:where([type=password], [type=text]:has(~ button.show)) {
117
+ padding-right: 55px;
118
+ }
119
+
120
+ &:where([type=search]) {
121
+ padding: calc(6px - var(--semanticFormsFieldTextInkOffset, 0px)) 20px calc(6px + var(--semanticFormsFieldTextInkOffset, 0px)) 32px;
122
+ background: var(--semanticFormsSearchIcon) no-repeat 10px;
123
+ background-color: var(--semanticFormsFormBgColor);
124
+ background-size: 18px;
125
+
126
+ &:focus,
127
+ &:not(:placeholder-shown) {
128
+ & + label.floatLabelFormAnimatedLabel {
129
+ left: 20px;
130
+ }
131
+ }
132
+
133
+ // hide native cancel button
134
+ &::-webkit-search-cancel-button {
135
+ display: none;
136
+ }
137
+ }
138
+
139
+ &:where([type=range], [type=color]) {
140
+ cursor: var(--semanticFormsCursor, pointer);
141
+ }
142
+
143
+ &:where([type=color]) {
144
+ height: var(--semanticFormsInputHeight);
145
+ padding: 4px 10px;
146
+ }
147
+
148
+ // in the grid a color field fills its column, and keeps room for its clear button. elsewhere it is as wide as the other controls, and has no clear button to make room for
149
+ @at-root .semanticForms :where(dl#{$notCustomLayout} dd) input:where([type=color]) {
150
+ min-width: 100%;
151
+ padding-right: 30px;
152
+ }
153
+
154
+ &:where([type=file]) {
155
+ cursor: var(--semanticFormsCursor, pointer);
156
+ font-size: var(--semanticFormsInputFontSize);
157
+ }
158
+
159
+ &[disabled] {
160
+ cursor: not-allowed;
161
+ opacity: 0.5;
162
+ }
163
+ }
164
+
165
+ // these style the labels and buttons beside a field rather than the field itself, so they keep the weight they have always had, which rules elsewhere are written around
166
+ input:not([type=submit], [type=reset], [type=button], [type=image], [type=checkbox], [type=radio]),
167
+ select,
168
+ textarea {
169
+ &[disabled] {
170
+ ~ label:first-of-type {
171
+ opacity: 0.5;
172
+ }
173
+
174
+ ~ label + button {
175
+ display: none;
176
+ }
177
+ }
178
+ }
179
+
180
+ select {
181
+ cursor: var(--semanticFormsCursor, pointer);
182
+ // the browser centers a control's text on the middle of the box holding it, which is not quite where the letters sit. the enhancement measures that difference for the page's font, and taking it off the top padding and adding it to the bottom moves the letters rather than the box
183
+ padding: calc(6px - var(--semanticFormsTextInkOffset, 0px)) 30px calc(6px + var(--semanticFormsTextInkOffset, 0px)) 20px;
184
+
185
+ // single selects
186
+ &:where(:not([multiple])) {
187
+ // custom dropdown graphic on select element
188
+ background-image: var(--semanticFormsSelectIcon);
189
+ background-size: 14px;
190
+ // the icon is a 14px square with its arrow drawn in the top half, so it is centered on the field and then moved down to bring the arrow rather than the square to the middle. a fixed 16px from the top only did that at the default 38px height, and left the arrow off center whenever --semanticFormsInputHeight or the height of the select was overridden. a percentage is taken from the room left over once the icon is placed, so at 38px this is still exactly 16px
191
+ background-position: calc(100% - 8px) calc(50% + 5px);
192
+ background-repeat: no-repeat;
193
+ -webkit-appearance: none;
194
+ -moz-appearance: none;
195
+ appearance: none;
196
+ }
197
+
198
+ // multi-selects
199
+ &:where([multiple]) {
200
+ min-height: 38px;
201
+ height: 100px;
202
+ padding: 0;
203
+
204
+ option {
205
+ padding: 6px 20px;
206
+
207
+ &:first-of-type {
208
+ border-top-left-radius: var(--semanticFormsBorderRadius);
209
+ }
210
+
211
+ &:last-of-type {
212
+ border-bottom-left-radius: var(--semanticFormsBorderRadius);
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ textarea {
219
+ padding: 6px 20px;
220
+ resize: vertical;
221
+ line-height: 1.5;
222
+ width: 100%;
223
+ min-height: 38px;
224
+
225
+ &:where([data-auto-grow]) {
226
+ field-sizing: content;
227
+ }
228
+ }
229
+
230
+ // as with the other fields, the room on the right for the clear button is only kept where the enhancement adds one
231
+ :where(dl#{$notCustomLayout} dd) textarea {
232
+ padding-right: 30px;
233
+ }
234
+
235
+ // buttons
236
+ button.clear, button.show {
237
+ cursor: var(--semanticFormsCursor, pointer);
238
+ appearance: none;
239
+ -webkit-appearance: none;
240
+ position: absolute;
241
+ // centered on the field from its own size rather than by a fixed offset, so that it stays centered when the field height is overridden
242
+ top: calc(var(--semanticFormsInputTopMargin) + (var(--semanticFormsInputHeight) - #{$clearButtonSize}) / 2);
243
+ right: 0;
244
+ width: $clearButtonSize;
245
+ height: $clearButtonSize;
246
+ margin: auto 6px;
247
+ padding: 5px;
248
+ background: none;
249
+ border: none;
250
+ color: var(--semanticFormsClearButtonColor);
251
+ display: flex;
252
+ align-items: center;
253
+ justify-content: center;
254
+ }
255
+
256
+ button.show {
257
+ right: 25px;
258
+
259
+ svg {
260
+ height: 100%;
261
+ }
262
+ }
263
+
264
+ // custom styling of clear button on textarea
265
+ textarea ~ .clear {
266
+ bottom: auto;
267
+ }
268
+
269
+ // hide clear/show button while placeholder text is visible
270
+ input:placeholder-shown ~ .clear,
271
+ input:placeholder-shown ~ .show,
272
+ textarea:placeholder-shown ~ .clear,
273
+ input[type=file] ~ .clear {
274
+ display: none;
275
+ }
276
+
277
+ // a field the user cannot edit has no clear button to begin with, but one that is made readonly or disabled after the enhancement ran still has the button it was given
278
+ input:read-only ~ .clear,
279
+ textarea:read-only ~ .clear {
280
+ display: none;
281
+ }
282
+
283
+ // button styling
284
+ input:where([type=submit], [type=reset], [type=button]),
285
+ button:where(:not(.clear, .show)),
286
+ .button-link {
287
+ @include button;
288
+ }
289
+
290
+ input:where([type=submit], [type=reset], [type=button], [type=image]),
291
+ button:where(:not(.clear, .show)),
292
+ .button-link {
293
+ @include button-hover;
294
+ }
295
+
296
+ .button-link {
297
+ display: block;
298
+
299
+ &:visited,
300
+ &:link {
301
+ color: var(--semanticFormsTextColor);
302
+ }
303
+ }
304
+
305
+ // invalid styling
306
+ [data-invalid-text] {
307
+ display: none;
308
+ color: var(--semanticFormsInvalid);
309
+ }
310
+
311
+ // the message semanticForms.setInvalid puts beside a field, which is shown wherever it was put, since it's only there while the field is invalid
312
+ .semanticFormsInvalidText {
313
+ display: block;
314
+ margin: 0;
315
+ font-size: small;
316
+ color: var(--semanticFormsInvalid);
317
+ }
318
+
319
+ input:where(:not([type=submit], [type=reset], [type=button], [type=image])),
320
+ select,
321
+ textarea {
322
+ &.invalid,
323
+ &:user-invalid {
324
+ border: var(--semanticFormsInvalidBorder);
325
+ }
326
+
327
+ &.warn {
328
+ border: var(--semanticFormsWarnBorder);
329
+ }
330
+ }
331
+
332
+ // the subtext and the message beside an invalid field keep the weight they have always had, since they are not the field itself, and the layouts' own subtext rules are written to lose to them
333
+ input:not([type=submit], [type=reset], [type=button], [type=image]),
334
+ select,
335
+ textarea {
336
+ &.invalid,
337
+ &:user-invalid {
338
+ ~ label:nth-of-type(2) {
339
+ color: var(--semanticFormsInvalid);
340
+ }
341
+
342
+ ~ [data-invalid-text] {
343
+ font-size: small;
344
+ display: flex;
345
+ }
346
+ }
347
+
348
+ &.warn {
349
+ ~ label:nth-of-type(2) {
350
+ color: var(--semanticFormsWarn);
351
+ }
352
+
353
+ ~ [data-invalid-text] {
354
+ font-size: small;
355
+ display: flex;
356
+ }
357
+ }
358
+ }
359
+
360
+ // a checkbox carrying the switch attribute is a switch
361
+ // https://html.spec.whatwg.org/multipage/input.html#the-switch-attribute
362
+ //
363
+ // browsers without native support render an ordinary checkbox, so it is drawn here instead: the element's background is the track and the thumb is a circle painted on top of it, which slides across when it is checked
364
+ //
365
+ // the thumb used to be the background showing through a gap in an inset shadow, which left it flat on the side facing the track and stepped where that flat side met the rounded ends. a circle has a round edge all the way around, and the browser draws its curve smoothly
366
+ //
367
+ // this comes after the invalid styling on purpose: the invalid border outweighs the switch's own, as it always has, while a checked switch still colours that border in its on colour, which needs it to come later now that both weigh the same
368
+ input:where([type=checkbox][switch]) {
369
+ appearance: none;
370
+ box-sizing: border-box;
371
+ width: 34px;
372
+ height: 18px;
373
+ border-radius: 999px;
374
+ background-color: var(--semanticFormsSwitchOffColor);
375
+ border: 1px solid var(--semanticFormsSwitchOffColor);
376
+ // the colour stops a pixel short of the edge so the browser has a band to shade across. a stop at the very edge gives it nothing to work with and it draws the circle as a polygon
377
+ //
378
+ // the box the circle is drawn in is exactly as tall as the space inside the border, so centering it lands on a whole pixel. a box any smaller leaves an odd number of pixels to share between top and bottom, and each browser rounds that half pixel its own way
379
+ background-image: radial-gradient(circle 7px at center, var(--semanticFormsSwitchThumbColor) 6px, transparent 7px);
380
+ background-size: 16px 16px;
381
+ background-position: 0 center;
382
+ background-repeat: no-repeat;
383
+ transition: background-color 200ms ease-in-out, background-position 200ms ease-in-out, border-color 200ms ease-in-out;
384
+ touch-action: none; // the thumb can be dragged, which must not scroll the page
385
+
386
+ &:checked {
387
+ background-color: var(--semanticFormsSwitchOnColor);
388
+ border-color: var(--semanticFormsSwitchOnColor);
389
+ background-position: 16px center; // the far end of the 32px of space inside the border, less the 16px the thumb occupies
390
+ }
391
+
392
+ &:focus-visible {
393
+ outline: none;
394
+ box-shadow: 0 0 0 2px var(--semanticFormsFocusColor);
395
+
396
+ @media (forced-colors: active) {
397
+ outline: 2px solid Highlight;
398
+ outline-offset: 2px;
399
+ }
400
+ }
401
+
402
+ &:disabled {
403
+ cursor: default;
404
+ opacity: 0.5;
405
+ }
406
+
407
+ // the track and the thumb must stay distinguishable when colors are overridden
408
+ @media (forced-colors: active) {
409
+ forced-color-adjust: none;
410
+ background-color: Canvas;
411
+ border-color: ButtonText;
412
+ background-image: radial-gradient(circle 7px at center, ButtonText 6px, transparent 7px);
413
+ }
414
+
415
+ @media (prefers-reduced-motion: reduce) {
416
+ transition: none;
417
+ }
418
+ }
419
+
420
+ // the browser paints an autofilled field in its own colour, which no background of ours can override, so a shadow the size of the field covers it and the form keeps its theme
421
+ //
422
+ // that colour is also the only sign the browser gives that it filled the field, and a visitor who cannot tell those colours apart never had it. so the field is marked here too, by a bar down its inline start edge: a second shadow, which takes up no space and shifts nothing, rather than a border, which would move the text. the two are listed with the bar first, since the earlier shadow in the list is drawn on top
423
+ //
424
+ // the :autofill and :-webkit-autofill rules are written separately on purpose. a browser that does not know one of the two selectors throws the whole rule away, which with both in one list would leave the field looking autofilled in the browser's colours
425
+ $semanticFormsAutofillShadow: inset 3px 0 0 var(--semanticFormsAutofillColor), inset 0 0 0 1000px var(--semanticFormsFormBgColor);
426
+
427
+ input:autofill,
428
+ textarea:autofill,
429
+ select:autofill {
430
+ box-shadow: #{$semanticFormsAutofillShadow};
431
+
432
+ &:focus {
433
+ box-shadow: inset 0 0 0 2px var(--semanticFormsFocusColor), #{$semanticFormsAutofillShadow};
434
+ }
435
+ }
436
+
437
+ input:-webkit-autofill,
438
+ textarea:-webkit-autofill,
439
+ select:-webkit-autofill {
440
+ box-shadow: #{$semanticFormsAutofillShadow};
441
+
442
+ &:focus {
443
+ box-shadow: inset 0 0 0 2px var(--semanticFormsFocusColor), #{$semanticFormsAutofillShadow};
444
+ }
445
+ }
446
+
447
+ // update for scrollbars
448
+ @supports (scrollbar-color: auto) {
449
+ textarea {
450
+ scrollbar-color: var(--semanticFormsScrollbarColor) transparent;
451
+
452
+ &::-webkit-resizer {
453
+ border: none;
454
+ background-image: var(--semanticFormsCustomResizer);
455
+ background-size: 14px;
456
+ background-repeat: no-repeat;
457
+ background-position: 100%;
458
+ margin: 0 2px 2px 0;
459
+ }
460
+ }
461
+
462
+ select[multiple] {
463
+ scrollbar-color: var(--semanticFormsScrollbarColor) transparent;
464
+ }
465
+ }
466
+ }
467
+
468
+ // a button outside a semanticForms form, which looks like one inside one, so that a page doesn't have to wrap a button in a form to have it match the form's buttons
469
+ .semanticFormsButton:where(button, input, a) {
470
+ @include button;
471
+ @include button-hover;
472
+ font-family: var(--semanticFormsFontFamily);
473
+ }