@telperion/elements 5.2.0 → 5.4.0
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.
- package/.build-manifest.json +1 -1
- package/README.md +2 -0
- package/_chunks/shade-mixer-lit-element-sw8t_VC5.d.cts +50 -0
- package/_chunks/shade-mixer-lit-element-sw8t_VC5.d.ts +50 -0
- package/_chunks/{signal-watcher-lit-element-B9xodkLt.d.cts → signal-watcher-lit-element-B-vV0yNG.d.ts} +7 -1
- package/_chunks/{signal-watcher-lit-element-B9xodkLt.d.ts → signal-watcher-lit-element-B5xCaa26.d.cts} +7 -1
- package/button/index.d.cts +2 -48
- package/button/index.d.ts +2 -48
- package/fesm/elements.mjs +271 -156
- package/fesm/elements.mjs.map +1 -1
- package/iife/elements.js +119 -111
- package/iife/elements.js.map +1 -1
- package/iife/router/index.js +64 -21
- package/iife/router/index.js.map +1 -1
- package/iife/select/index.js +181 -129
- package/iife/select/index.js.map +1 -1
- package/index.d.cts +2 -1
- package/index.d.ts +2 -1
- package/package.json +1 -1
- package/router/index.d.cts +2 -1
- package/router/index.d.ts +2 -1
- package/select/index.d.cts +107 -2
- package/select/index.d.ts +107 -2
- package/select/select.element.cjs +156 -41
- package/select/select.element.cjs.map +1 -1
- package/select/select.element.js +157 -42
- package/select/select.element.js.map +1 -1
- package/utils/signal-watcher-lit-element.cjs +3 -0
- package/utils/signal-watcher-lit-element.cjs.map +1 -1
- package/utils/signal-watcher-lit-element.js +3 -1
- package/utils/signal-watcher-lit-element.js.map +1 -1
package/fesm/elements.mjs
CHANGED
|
@@ -3,6 +3,8 @@ import { LitElement, css, html as html$1 } from 'lit';
|
|
|
3
3
|
import { property, customElement, state } from 'lit/decorators.js';
|
|
4
4
|
import { signal, SignalWatcher, computed, html } from '@lit-labs/signals';
|
|
5
5
|
import { noop } from '@telperion/js-utils/function/noop';
|
|
6
|
+
import { uniquify } from '@telperion/js-utils/array/uniquify';
|
|
7
|
+
import { minMax } from '@telperion/js-utils/math/min-max';
|
|
6
8
|
import { createMemoryHistory, createHashHistory, createBrowserHistory } from 'history';
|
|
7
9
|
import { defer } from '@telperion/js-utils/function/defer';
|
|
8
10
|
import { compact } from '@telperion/js-utils/array/compact';
|
|
@@ -11,8 +13,6 @@ import { uniqueId } from '@telperion/js-utils/unique-id';
|
|
|
11
13
|
import { createContext, consume, provide } from '@lit/context';
|
|
12
14
|
import { sliceBefore } from '@telperion/js-utils/array/slice-before';
|
|
13
15
|
import { DomClone } from '@telperion/dom-utils';
|
|
14
|
-
import { uniquify } from '@telperion/js-utils/array/uniquify';
|
|
15
|
-
import { minMax } from '@telperion/js-utils/math/min-max';
|
|
16
16
|
|
|
17
17
|
var _a$3, _b;
|
|
18
18
|
/**
|
|
@@ -132,12 +132,128 @@ ThaRoute = __decorate([
|
|
|
132
132
|
customElement('tha-route')
|
|
133
133
|
], ThaRoute);
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Base class that powers Telperion's shared color/design system.
|
|
137
|
+
*
|
|
138
|
+
* Elements that extend `ShadeMixerLitElement` participate in a fully themable
|
|
139
|
+
* palette driven entirely by CSS custom properties. The class:
|
|
140
|
+
*
|
|
141
|
+
* 1. Auto-injects a default palette onto `:root` — `--tp-color-white`,
|
|
142
|
+
* `--tp-color-black`, `--tp-color-contrast`, `--tp-color-primary`,
|
|
143
|
+
* `--tp-color-secondary`, `--tp-color-tertiary`, `--tp-color-quaternary`,
|
|
144
|
+
* `--tp-color-success`, `--tp-color-danger`, `--tp-color-warning`, and
|
|
145
|
+
* `--tp-color-neutral`. Override any of them at `:root` or any ancestor to
|
|
146
|
+
* re-theme every shade-mixer-aware element underneath.
|
|
147
|
+
* 2. Exposes `shadedElementStyles` — a `css` block that resolves the
|
|
148
|
+
* selected `color` to `--tp-element-color`, applies the `shade`/`mixer`
|
|
149
|
+
* math, and exposes the result as `--tp-calc-element-color` and
|
|
150
|
+
* `--tp-calc-contrast-color` for consumers (variants, hover, focus, …).
|
|
151
|
+
* Subclasses include it once in their own host rule.
|
|
152
|
+
* 3. Provides three reflected attributes that drive the math:
|
|
153
|
+
* - `color` — palette token name (predefined or custom).
|
|
154
|
+
* - `shade` (`0`–`1000`, default `500`) — lighten/darken the
|
|
155
|
+
* resolved color (`<500` mixes white, `>500` mixes black).
|
|
156
|
+
* - `mixer` (`none` / `black` / `white`) — read-only output, auto-set
|
|
157
|
+
* whenever `shade` changes.
|
|
158
|
+
*
|
|
159
|
+
* **Adding custom color tokens.** If the predefined names are not enough,
|
|
160
|
+
* declare a new selector that supplies `--tp-element-color`:
|
|
161
|
+
*
|
|
162
|
+
* ```css
|
|
163
|
+
* tp-button[color="brand"] {
|
|
164
|
+
* --tp-element-color: hsl(265 75% 45%);
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* The shade math, hover/focus styles, and contrast color all derive from this
|
|
169
|
+
* one variable, so the new token "just works" with `shade`, `variant`, etc.
|
|
170
|
+
*/
|
|
171
|
+
class ShadeMixerLitElement extends LitElement {
|
|
172
|
+
constructor() {
|
|
173
|
+
super(...arguments);
|
|
174
|
+
this.color = "contrast";
|
|
175
|
+
this.shade = 500;
|
|
176
|
+
this.mixer = "none";
|
|
177
|
+
}
|
|
178
|
+
static { this.rootStyles = (() => {
|
|
179
|
+
const style = css `
|
|
180
|
+
@layer properties {
|
|
181
|
+
:root {
|
|
182
|
+
--tp-color-white: hsl(0 0% 100%);
|
|
183
|
+
--tp-color-black: hsl(0 0% 0%);
|
|
184
|
+
--tp-color-contrast: var(--tp-color-black);
|
|
185
|
+
--tp-color-primary: hsl(220 90% 56%);
|
|
186
|
+
--tp-color-secondary: hsl(340 82% 52%);
|
|
187
|
+
--tp-color-tertiary: hsl(50 100% 50%);
|
|
188
|
+
--tp-color-quaternary: hsl(120 100% 40%);
|
|
189
|
+
--tp-color-success: hsl(140 70% 40%);
|
|
190
|
+
--tp-color-danger: hsl(0 70% 50%);
|
|
191
|
+
--tp-color-warning: hsl(45 100% 50%);
|
|
192
|
+
--tp-color-neutral: color-mix(in xyz, var(--tp-color-white) 50%, var(--tp-color-black) 50%);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
196
|
+
document.adoptedStyleSheets = uniquify([...document.adoptedStyleSheets, style.styleSheet]);
|
|
197
|
+
return style;
|
|
198
|
+
})(); }
|
|
199
|
+
static { this.shadedElementStyles = css `
|
|
200
|
+
--tp-element-color: var(--tp-color-primary);
|
|
201
|
+
--tp-shade-attr: attr(shade type(<number>));
|
|
202
|
+
--tp-shade-mixer-type: attr(mixer type(*));
|
|
203
|
+
--tp-shade-mixer-color: if(
|
|
204
|
+
style(--tp-shade-mixer-type: black): var(--tp-color-black);
|
|
205
|
+
else: var(--tp-color-white)
|
|
206
|
+
);
|
|
207
|
+
--tp-shade-mixer-percent: if(
|
|
208
|
+
style(--tp-shade-mixer-type: black): calc(100% - ((var(--tp-shade-attr) - 500) / 500 * 100%));
|
|
209
|
+
else: calc(100% - ((500 - var(--tp-shade-attr)) / 500 * 100%))
|
|
210
|
+
);
|
|
211
|
+
--tp-calc-element-color: color-mix(in xyz, var(--tp-element-color) var(--tp-shade-mixer-percent), var(--tp-shade-mixer-color) calc(100% - var(--tp-shade-mixer-percent)));
|
|
212
|
+
--tp-calc-contrast-color: contrast-color(var(--tp-calc-element-color));
|
|
213
|
+
--tp-contrast-color: if(
|
|
214
|
+
style(--tp-calc-contrast-color: white): var(--tp-color-white);
|
|
215
|
+
else: var(--tp-color-black);
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
&[color="contrast"] { --tp-element-color: var(--tp-color-contrast); }
|
|
219
|
+
&[color="primary"] { --tp-element-color: var(--tp-color-primary); }
|
|
220
|
+
&[color="secondary"] { --tp-element-color: var(--tp-color-secondary); }
|
|
221
|
+
&[color="tertiary"] { --tp-element-color: var(--tp-color-tertiary); }
|
|
222
|
+
&[color="quaternary"] { --tp-element-color: var(--tp-color-quaternary); }
|
|
223
|
+
&[color="success"] { --tp-element-color: var(--tp-color-success); }
|
|
224
|
+
&[color="danger"] { --tp-element-color: var(--tp-color-danger); }
|
|
225
|
+
&[color="warning"] { --tp-element-color: var(--tp-color-warning); }
|
|
226
|
+
&[color="neutral"] { --tp-element-color: var(--tp-color-neutral); }
|
|
227
|
+
`; }
|
|
228
|
+
willUpdate(changed) {
|
|
229
|
+
if (changed.has("shade")) {
|
|
230
|
+
this.mixer = this.shade === 500 ? "none" : this.shade > 500 ? "black" : "white";
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
__decorate([
|
|
235
|
+
property({ type: String, reflect: true }),
|
|
236
|
+
__metadata("design:type", String)
|
|
237
|
+
], ShadeMixerLitElement.prototype, "color", void 0);
|
|
238
|
+
__decorate([
|
|
239
|
+
property({ type: Number, reflect: true, converter(value, type) {
|
|
240
|
+
const num = Number(value);
|
|
241
|
+
return isNaN(num) ? 500 : minMax(0, 1000, num);
|
|
242
|
+
} }),
|
|
243
|
+
__metadata("design:type", Number)
|
|
244
|
+
], ShadeMixerLitElement.prototype, "shade", void 0);
|
|
245
|
+
__decorate([
|
|
246
|
+
property({ type: String, reflect: true }),
|
|
247
|
+
__metadata("design:type", String)
|
|
248
|
+
], ShadeMixerLitElement.prototype, "mixer", void 0);
|
|
249
|
+
|
|
135
250
|
/**
|
|
136
251
|
* A LitElement base class extended with SignalWatcher capabilities.
|
|
137
252
|
*
|
|
138
253
|
* This class allows LitElement components to reactively watch for changes
|
|
139
254
|
*/
|
|
140
255
|
const SignalWatcherLitElement = SignalWatcher(LitElement);
|
|
256
|
+
const ShadeMixerSignalWatcherLitElement = SignalWatcher(ShadeMixerLitElement);
|
|
141
257
|
|
|
142
258
|
/**
|
|
143
259
|
* Global registry mapping history types to their singleton instances.
|
|
@@ -2901,55 +3017,73 @@ class SelectChangeEvent extends Event {
|
|
|
2901
3017
|
}
|
|
2902
3018
|
|
|
2903
3019
|
var SelectElement_1;
|
|
2904
|
-
let SelectElement = class SelectElement extends
|
|
3020
|
+
let SelectElement = class SelectElement extends ShadeMixerSignalWatcherLitElement {
|
|
2905
3021
|
static { SelectElement_1 = this; }
|
|
2906
3022
|
static { this.formAssociated = true; }
|
|
2907
3023
|
static { this.ALLOWED_OPTION_ELEMENTS = [OptionElement]; }
|
|
2908
|
-
static { this.styles =
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
display: inline-flex;
|
|
2912
|
-
height: fit-content;
|
|
2913
|
-
|
|
3024
|
+
static { this.styles = (() => {
|
|
3025
|
+
const variables = css `
|
|
3026
|
+
${ShadeMixerLitElement.shadedElementStyles}
|
|
2914
3027
|
--tp-select-option-color: white;
|
|
2915
|
-
--tp-select-selection-color:
|
|
3028
|
+
--tp-select-selection-color: var(--tp-calc-element-color);
|
|
2916
3029
|
--tp-select-highlight-percent: 20%;
|
|
2917
|
-
--tp-select-selection-contrast-color:
|
|
2918
|
-
|
|
3030
|
+
--tp-select-selection-contrast-color: var(--tp-calc-contrast-color);
|
|
3031
|
+
`;
|
|
3032
|
+
const shadowStyles = css `
|
|
3033
|
+
@layer base {
|
|
3034
|
+
:host {
|
|
3035
|
+
${variables}
|
|
3036
|
+
position: relative;
|
|
3037
|
+
display: inline-flex;
|
|
3038
|
+
height: fit-content;
|
|
3039
|
+
}
|
|
2919
3040
|
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
3041
|
+
:host([disabled]) {
|
|
3042
|
+
pointer-events: none;
|
|
3043
|
+
opacity: 0.6;
|
|
3044
|
+
}
|
|
2924
3045
|
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
3046
|
+
:host([open]) {
|
|
3047
|
+
[pseudo="indicator"] {
|
|
3048
|
+
transform: rotateX(180deg);
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
2930
3051
|
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
3052
|
+
[pseudo="button"] {
|
|
3053
|
+
background: white;
|
|
3054
|
+
cursor: pointer;
|
|
3055
|
+
display: inline-flex;
|
|
3056
|
+
align-items: center;
|
|
3057
|
+
padding: 0.25em 0.5em;
|
|
2937
3058
|
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
3059
|
+
tp-selected-content {
|
|
3060
|
+
margin-inline-end: 0.5em;
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
2942
3063
|
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
3064
|
+
[pseudo="indicator"] {
|
|
3065
|
+
margin-inline-start: auto;
|
|
3066
|
+
}
|
|
2946
3067
|
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
3068
|
+
tp-popover {
|
|
3069
|
+
border: none;
|
|
3070
|
+
padding: 0;
|
|
3071
|
+
}
|
|
3072
|
+
}`;
|
|
3073
|
+
const documentStyles = css `
|
|
3074
|
+
@layer base {
|
|
3075
|
+
tp-select {
|
|
3076
|
+
${variables}
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
`;
|
|
3080
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, documentStyles.styleSheet];
|
|
3081
|
+
return shadowStyles;
|
|
3082
|
+
})(); }
|
|
2952
3083
|
#options;
|
|
3084
|
+
get #popover() {
|
|
3085
|
+
return this.shadowRoot?.querySelector("tp-popover");
|
|
3086
|
+
}
|
|
2953
3087
|
#value;
|
|
2954
3088
|
get value() {
|
|
2955
3089
|
return this.#value.get();
|
|
@@ -3010,6 +3144,17 @@ let SelectElement = class SelectElement extends SignalWatcherLitElement {
|
|
|
3010
3144
|
* down to size from the end.
|
|
3011
3145
|
*/
|
|
3012
3146
|
this.max = 1;
|
|
3147
|
+
/**
|
|
3148
|
+
* Minimum number of options that must remain selected.
|
|
3149
|
+
*
|
|
3150
|
+
* Defaults to `0` (no lower bound). When the current selection size is at
|
|
3151
|
+
* or below `min`, calls to {@link deselectOption} (and the click-driven
|
|
3152
|
+
* toggle inside the popover) become no-ops, so the user can't drop below
|
|
3153
|
+
* the floor by interacting with the control. Programmatic writes to
|
|
3154
|
+
* `value` and `selectedOptions` are not policed — `min` is purely an
|
|
3155
|
+
* interaction guard.
|
|
3156
|
+
*/
|
|
3157
|
+
this.min = 0;
|
|
3013
3158
|
/** Form field name. Submitted with the owning `<form>`. */
|
|
3014
3159
|
this.name = null;
|
|
3015
3160
|
/** When true, the element is non-interactive and excluded from form submission. */
|
|
@@ -3189,10 +3334,13 @@ let SelectElement = class SelectElement extends SignalWatcherLitElement {
|
|
|
3189
3334
|
this.selectedOptions.set(trimmed);
|
|
3190
3335
|
}
|
|
3191
3336
|
deselectOption(option) {
|
|
3192
|
-
const
|
|
3337
|
+
const current = this.selectedOptions.get();
|
|
3338
|
+
const optionRef = current.find(ref => ref.deref() === option);
|
|
3193
3339
|
if (!optionRef)
|
|
3194
3340
|
return;
|
|
3195
|
-
|
|
3341
|
+
if (current.length <= this.min)
|
|
3342
|
+
return;
|
|
3343
|
+
this.selectedOptions.set(current.filter(ref => ref !== optionRef));
|
|
3196
3344
|
}
|
|
3197
3345
|
toggleOption(option) {
|
|
3198
3346
|
const ref = this.selectedOptions.get().find(ref => ref.deref() === option);
|
|
@@ -3203,6 +3351,72 @@ let SelectElement = class SelectElement extends SignalWatcherLitElement {
|
|
|
3203
3351
|
this.selectOption(option);
|
|
3204
3352
|
}
|
|
3205
3353
|
}
|
|
3354
|
+
/**
|
|
3355
|
+
* Open, close, or toggle the dropdown popover.
|
|
3356
|
+
*
|
|
3357
|
+
* Overrides the native {@link HTMLElement.togglePopover} so callers can
|
|
3358
|
+
* drive the select from outside without reaching into the shadow DOM.
|
|
3359
|
+
* `<tp-select>` itself is not the popover element — the actual popover
|
|
3360
|
+
* lives inside its shadow root — so the call is delegated to the inner
|
|
3361
|
+
* `<tp-popover>`.
|
|
3362
|
+
*
|
|
3363
|
+
* @param options Same shape as the native API: pass `true` to force open,
|
|
3364
|
+
* `false` to force close, or a `{ force }` options bag. Omit to toggle
|
|
3365
|
+
* between the two states.
|
|
3366
|
+
* @returns `true` if the popover ends up open, `false` otherwise (matching
|
|
3367
|
+
* the native return value). Returns `false` early if the inner popover
|
|
3368
|
+
* isn't reachable yet (for example, before the first render).
|
|
3369
|
+
*
|
|
3370
|
+
* @example
|
|
3371
|
+
* ```ts
|
|
3372
|
+
* const select = document.querySelector('tp-select');
|
|
3373
|
+
* select.togglePopover(); // toggle
|
|
3374
|
+
* select.togglePopover(true); // force open
|
|
3375
|
+
* select.togglePopover(false); // force close
|
|
3376
|
+
* ```
|
|
3377
|
+
*/
|
|
3378
|
+
togglePopover() {
|
|
3379
|
+
return this.#popover.togglePopover();
|
|
3380
|
+
}
|
|
3381
|
+
/**
|
|
3382
|
+
* Close the dropdown popover.
|
|
3383
|
+
*
|
|
3384
|
+
* Overrides the native {@link HTMLElement.hidePopover} so callers can
|
|
3385
|
+
* close the select from outside without reaching into the shadow DOM.
|
|
3386
|
+
* `<tp-select>` itself is not the popover element — the actual popover
|
|
3387
|
+
* lives inside its shadow root — so the call is delegated to the inner
|
|
3388
|
+
* `<tp-popover>`.
|
|
3389
|
+
*
|
|
3390
|
+
* No-op if the popover is already closed.
|
|
3391
|
+
*
|
|
3392
|
+
* @example
|
|
3393
|
+
* ```ts
|
|
3394
|
+
* document.querySelector('tp-select').hidePopover();
|
|
3395
|
+
* ```
|
|
3396
|
+
*/
|
|
3397
|
+
hidePopover() {
|
|
3398
|
+
this.#popover.hidePopover();
|
|
3399
|
+
}
|
|
3400
|
+
/**
|
|
3401
|
+
* Open the dropdown popover.
|
|
3402
|
+
*
|
|
3403
|
+
* Overrides the native {@link HTMLElement.showPopover} so callers can
|
|
3404
|
+
* open the select from outside without reaching into the shadow DOM.
|
|
3405
|
+
* `<tp-select>` itself is not the popover element — the actual popover
|
|
3406
|
+
* lives inside its shadow root — so the call is delegated to the inner
|
|
3407
|
+
* `<tp-popover>`.
|
|
3408
|
+
*
|
|
3409
|
+
* @param options Same shape as the native API (e.g. `{ source }` to set
|
|
3410
|
+
* the invoker for the popover invoker relationship).
|
|
3411
|
+
*
|
|
3412
|
+
* @example
|
|
3413
|
+
* ```ts
|
|
3414
|
+
* document.querySelector('tp-select').showPopover();
|
|
3415
|
+
* ```
|
|
3416
|
+
*/
|
|
3417
|
+
showPopover() {
|
|
3418
|
+
this.#popover.showPopover();
|
|
3419
|
+
}
|
|
3206
3420
|
[REGISTER_OPTION](option) {
|
|
3207
3421
|
this.#options.add(option);
|
|
3208
3422
|
}
|
|
@@ -3276,6 +3490,22 @@ __decorate([
|
|
|
3276
3490
|
}),
|
|
3277
3491
|
__metadata("design:type", Number)
|
|
3278
3492
|
], SelectElement.prototype, "max", void 0);
|
|
3493
|
+
__decorate([
|
|
3494
|
+
property({
|
|
3495
|
+
type: Number,
|
|
3496
|
+
reflect: true,
|
|
3497
|
+
converter: {
|
|
3498
|
+
fromAttribute: (value) => {
|
|
3499
|
+
if (value === null || value === undefined || value === "")
|
|
3500
|
+
return 0;
|
|
3501
|
+
const parsed = Number(String(value).trim());
|
|
3502
|
+
return Number.isFinite(parsed) && parsed >= 0 ? Math.floor(parsed) : 0;
|
|
3503
|
+
},
|
|
3504
|
+
toAttribute: (value) => String(value),
|
|
3505
|
+
},
|
|
3506
|
+
}),
|
|
3507
|
+
__metadata("design:type", Number)
|
|
3508
|
+
], SelectElement.prototype, "min", void 0);
|
|
3279
3509
|
__decorate([
|
|
3280
3510
|
property({ type: String, reflect: true }),
|
|
3281
3511
|
__metadata("design:type", Object)
|
|
@@ -3297,121 +3527,6 @@ SelectElement = SelectElement_1 = __decorate([
|
|
|
3297
3527
|
__metadata("design:paramtypes", [])
|
|
3298
3528
|
], SelectElement);
|
|
3299
3529
|
|
|
3300
|
-
/**
|
|
3301
|
-
* Base class that powers Telperion's shared color/design system.
|
|
3302
|
-
*
|
|
3303
|
-
* Elements that extend `ShadeMixerLitElement` participate in a fully themable
|
|
3304
|
-
* palette driven entirely by CSS custom properties. The class:
|
|
3305
|
-
*
|
|
3306
|
-
* 1. Auto-injects a default palette onto `:root` — `--tp-color-white`,
|
|
3307
|
-
* `--tp-color-black`, `--tp-color-contrast`, `--tp-color-primary`,
|
|
3308
|
-
* `--tp-color-secondary`, `--tp-color-tertiary`, `--tp-color-quaternary`,
|
|
3309
|
-
* `--tp-color-success`, `--tp-color-danger`, `--tp-color-warning`, and
|
|
3310
|
-
* `--tp-color-neutral`. Override any of them at `:root` or any ancestor to
|
|
3311
|
-
* re-theme every shade-mixer-aware element underneath.
|
|
3312
|
-
* 2. Exposes `shadedElementStyles` — a `css` block that resolves the
|
|
3313
|
-
* selected `color` to `--tp-element-color`, applies the `shade`/`mixer`
|
|
3314
|
-
* math, and exposes the result as `--tp-calc-element-color` and
|
|
3315
|
-
* `--tp-calc-contrast-color` for consumers (variants, hover, focus, …).
|
|
3316
|
-
* Subclasses include it once in their own host rule.
|
|
3317
|
-
* 3. Provides three reflected attributes that drive the math:
|
|
3318
|
-
* - `color` — palette token name (predefined or custom).
|
|
3319
|
-
* - `shade` (`0`–`1000`, default `500`) — lighten/darken the
|
|
3320
|
-
* resolved color (`<500` mixes white, `>500` mixes black).
|
|
3321
|
-
* - `mixer` (`none` / `black` / `white`) — read-only output, auto-set
|
|
3322
|
-
* whenever `shade` changes.
|
|
3323
|
-
*
|
|
3324
|
-
* **Adding custom color tokens.** If the predefined names are not enough,
|
|
3325
|
-
* declare a new selector that supplies `--tp-element-color`:
|
|
3326
|
-
*
|
|
3327
|
-
* ```css
|
|
3328
|
-
* tp-button[color="brand"] {
|
|
3329
|
-
* --tp-element-color: hsl(265 75% 45%);
|
|
3330
|
-
* }
|
|
3331
|
-
* ```
|
|
3332
|
-
*
|
|
3333
|
-
* The shade math, hover/focus styles, and contrast color all derive from this
|
|
3334
|
-
* one variable, so the new token "just works" with `shade`, `variant`, etc.
|
|
3335
|
-
*/
|
|
3336
|
-
class ShadeMixerLitElement extends LitElement {
|
|
3337
|
-
constructor() {
|
|
3338
|
-
super(...arguments);
|
|
3339
|
-
this.color = "contrast";
|
|
3340
|
-
this.shade = 500;
|
|
3341
|
-
this.mixer = "none";
|
|
3342
|
-
}
|
|
3343
|
-
static { this.rootStyles = (() => {
|
|
3344
|
-
const style = css `
|
|
3345
|
-
@layer properties {
|
|
3346
|
-
:root {
|
|
3347
|
-
--tp-color-white: hsl(0 0% 100%);
|
|
3348
|
-
--tp-color-black: hsl(0 0% 0%);
|
|
3349
|
-
--tp-color-contrast: var(--tp-color-black);
|
|
3350
|
-
--tp-color-primary: hsl(220 90% 56%);
|
|
3351
|
-
--tp-color-secondary: hsl(340 82% 52%);
|
|
3352
|
-
--tp-color-tertiary: hsl(50 100% 50%);
|
|
3353
|
-
--tp-color-quaternary: hsl(120 100% 40%);
|
|
3354
|
-
--tp-color-success: hsl(140 70% 40%);
|
|
3355
|
-
--tp-color-danger: hsl(0 70% 50%);
|
|
3356
|
-
--tp-color-warning: hsl(45 100% 50%);
|
|
3357
|
-
--tp-color-neutral: color-mix(in xyz, var(--tp-color-white) 50%, var(--tp-color-black) 50%);
|
|
3358
|
-
}
|
|
3359
|
-
}
|
|
3360
|
-
`;
|
|
3361
|
-
document.adoptedStyleSheets = uniquify([...document.adoptedStyleSheets, style.styleSheet]);
|
|
3362
|
-
return style;
|
|
3363
|
-
})(); }
|
|
3364
|
-
static { this.shadedElementStyles = css `
|
|
3365
|
-
--tp-element-color: var(--tp-color-primary);
|
|
3366
|
-
--tp-shade-attr: attr(shade type(<number>));
|
|
3367
|
-
--tp-shade-mixer-type: attr(mixer type(*));
|
|
3368
|
-
--tp-shade-mixer-color: if(
|
|
3369
|
-
style(--tp-shade-mixer-type: black): var(--tp-color-black);
|
|
3370
|
-
else: var(--tp-color-white)
|
|
3371
|
-
);
|
|
3372
|
-
--tp-shade-mixer-percent: if(
|
|
3373
|
-
style(--tp-shade-mixer-type: black): calc(100% - ((var(--tp-shade-attr) - 500) / 500 * 100%));
|
|
3374
|
-
else: calc(100% - ((500 - var(--tp-shade-attr)) / 500 * 100%))
|
|
3375
|
-
);
|
|
3376
|
-
--tp-calc-element-color: color-mix(in xyz, var(--tp-element-color) var(--tp-shade-mixer-percent), var(--tp-shade-mixer-color) calc(100% - var(--tp-shade-mixer-percent)));
|
|
3377
|
-
--tp-calc-contrast-color: contrast-color(var(--tp-calc-element-color));
|
|
3378
|
-
--tp-contrast-color: if(
|
|
3379
|
-
style(--tp-calc-contrast-color: white): var(--tp-color-white);
|
|
3380
|
-
else: var(--tp-color-black);
|
|
3381
|
-
);
|
|
3382
|
-
|
|
3383
|
-
&[color="contrast"] { --tp-element-color: var(--tp-color-contrast); }
|
|
3384
|
-
&[color="primary"] { --tp-element-color: var(--tp-color-primary); }
|
|
3385
|
-
&[color="secondary"] { --tp-element-color: var(--tp-color-secondary); }
|
|
3386
|
-
&[color="tertiary"] { --tp-element-color: var(--tp-color-tertiary); }
|
|
3387
|
-
&[color="quaternary"] { --tp-element-color: var(--tp-color-quaternary); }
|
|
3388
|
-
&[color="success"] { --tp-element-color: var(--tp-color-success); }
|
|
3389
|
-
&[color="danger"] { --tp-element-color: var(--tp-color-danger); }
|
|
3390
|
-
&[color="warning"] { --tp-element-color: var(--tp-color-warning); }
|
|
3391
|
-
&[color="neutral"] { --tp-element-color: var(--tp-color-neutral); }
|
|
3392
|
-
`; }
|
|
3393
|
-
willUpdate(changed) {
|
|
3394
|
-
if (changed.has("shade")) {
|
|
3395
|
-
this.mixer = this.shade === 500 ? "none" : this.shade > 500 ? "black" : "white";
|
|
3396
|
-
}
|
|
3397
|
-
}
|
|
3398
|
-
}
|
|
3399
|
-
__decorate([
|
|
3400
|
-
property({ type: String, reflect: true }),
|
|
3401
|
-
__metadata("design:type", String)
|
|
3402
|
-
], ShadeMixerLitElement.prototype, "color", void 0);
|
|
3403
|
-
__decorate([
|
|
3404
|
-
property({ type: Number, reflect: true, converter(value, type) {
|
|
3405
|
-
const num = Number(value);
|
|
3406
|
-
return isNaN(num) ? 500 : minMax(0, 1000, num);
|
|
3407
|
-
} }),
|
|
3408
|
-
__metadata("design:type", Number)
|
|
3409
|
-
], ShadeMixerLitElement.prototype, "shade", void 0);
|
|
3410
|
-
__decorate([
|
|
3411
|
-
property({ type: String, reflect: true }),
|
|
3412
|
-
__metadata("design:type", String)
|
|
3413
|
-
], ShadeMixerLitElement.prototype, "mixer", void 0);
|
|
3414
|
-
|
|
3415
3530
|
/**
|
|
3416
3531
|
* `<tp-button>` — framework-agnostic, form-associated button.
|
|
3417
3532
|
*
|