@telperion/elements 5.3.1 → 5.4.1

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/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`) &mdash; 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,54 +3017,69 @@ class SelectChangeEvent extends Event {
2901
3017
  }
2902
3018
 
2903
3019
  var SelectElement_1;
2904
- let SelectElement = class SelectElement extends SignalWatcherLitElement {
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 = css `
2909
- :host {
2910
- position: relative;
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: #0078d4;
3028
+ --tp-select-selection-color: var(--tp-calc-element-color);
2916
3029
  --tp-select-highlight-percent: 20%;
2917
- --tp-select-selection-contrast-color: white;
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
- :host([disabled]) {
2921
- pointer-events: none;
2922
- opacity: 0.6;
2923
- }
3041
+ :host([disabled]) {
3042
+ pointer-events: none;
3043
+ opacity: 0.6;
3044
+ }
2924
3045
 
2925
- :host([open]) {
2926
- [pseudo="indicator"] {
2927
- transform: rotateX(180deg);
2928
- }
2929
- }
3046
+ :host([open]) {
3047
+ [pseudo="indicator"] {
3048
+ transform: rotateX(180deg);
3049
+ }
3050
+ }
2930
3051
 
2931
- [pseudo="button"] {
2932
- background: white;
2933
- cursor: pointer;
2934
- display: inline-flex;
2935
- align-items: center;
2936
- padding: 0.25em 0.5em;
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
- tp-selected-content {
2939
- margin-inline-end: 0.5em;
2940
- }
2941
- }
3059
+ tp-selected-content {
3060
+ margin-inline-end: 0.5em;
3061
+ }
3062
+ }
2942
3063
 
2943
- [pseudo="indicator"] {
2944
- margin-inline-start: auto;
2945
- }
3064
+ [pseudo="indicator"] {
3065
+ margin-inline-start: auto;
3066
+ }
2946
3067
 
2947
- tp-popover {
2948
- border: none;
2949
- padding: 0;
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;
2953
3084
  get #popover() {
2954
3085
  return this.shadowRoot?.querySelector("tp-popover");
@@ -2959,7 +3090,7 @@ let SelectElement = class SelectElement extends SignalWatcherLitElement {
2959
3090
  }
2960
3091
  set value(next) {
2961
3092
  defer(() => {
2962
- const values = next.split(",").map((s) => s.trim());
3093
+ const values = next?.split(",").map((s) => s.trim()) ?? [];
2963
3094
  const options = Array.from(this.#options);
2964
3095
  this.selectedOptions.set(values
2965
3096
  .map((value) => options.find((option) => option.value === value))
@@ -3013,6 +3144,17 @@ let SelectElement = class SelectElement extends SignalWatcherLitElement {
3013
3144
  * down to size from the end.
3014
3145
  */
3015
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;
3016
3158
  /** Form field name. Submitted with the owning `<form>`. */
3017
3159
  this.name = null;
3018
3160
  /** When true, the element is non-interactive and excluded from form submission. */
@@ -3192,10 +3334,13 @@ let SelectElement = class SelectElement extends SignalWatcherLitElement {
3192
3334
  this.selectedOptions.set(trimmed);
3193
3335
  }
3194
3336
  deselectOption(option) {
3195
- const optionRef = this.selectedOptions.get().find(ref => ref.deref() === option);
3337
+ const current = this.selectedOptions.get();
3338
+ const optionRef = current.find(ref => ref.deref() === option);
3196
3339
  if (!optionRef)
3197
3340
  return;
3198
- this.selectedOptions.set(this.selectedOptions.get().filter(ref => ref !== optionRef));
3341
+ if (current.length <= this.min)
3342
+ return;
3343
+ this.selectedOptions.set(current.filter(ref => ref !== optionRef));
3199
3344
  }
3200
3345
  toggleOption(option) {
3201
3346
  const ref = this.selectedOptions.get().find(ref => ref.deref() === option);
@@ -3315,8 +3460,8 @@ __decorate([
3315
3460
  ], SelectElement.prototype, "self", void 0);
3316
3461
  __decorate([
3317
3462
  property({ type: String, reflect: true, noAccessor: true }),
3318
- __metadata("design:type", String),
3319
- __metadata("design:paramtypes", [String])
3463
+ __metadata("design:type", Object),
3464
+ __metadata("design:paramtypes", [Object])
3320
3465
  ], SelectElement.prototype, "value", null);
3321
3466
  __decorate([
3322
3467
  property({ type: String, reflect: true, noAccessor: true }),
@@ -3345,6 +3490,22 @@ __decorate([
3345
3490
  }),
3346
3491
  __metadata("design:type", Number)
3347
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);
3348
3509
  __decorate([
3349
3510
  property({ type: String, reflect: true }),
3350
3511
  __metadata("design:type", Object)
@@ -3366,121 +3527,6 @@ SelectElement = SelectElement_1 = __decorate([
3366
3527
  __metadata("design:paramtypes", [])
3367
3528
  ], SelectElement);
3368
3529
 
3369
- /**
3370
- * Base class that powers Telperion's shared color/design system.
3371
- *
3372
- * Elements that extend `ShadeMixerLitElement` participate in a fully themable
3373
- * palette driven entirely by CSS custom properties. The class:
3374
- *
3375
- * 1. Auto-injects a default palette onto `:root` &mdash; `--tp-color-white`,
3376
- * `--tp-color-black`, `--tp-color-contrast`, `--tp-color-primary`,
3377
- * `--tp-color-secondary`, `--tp-color-tertiary`, `--tp-color-quaternary`,
3378
- * `--tp-color-success`, `--tp-color-danger`, `--tp-color-warning`, and
3379
- * `--tp-color-neutral`. Override any of them at `:root` or any ancestor to
3380
- * re-theme every shade-mixer-aware element underneath.
3381
- * 2. Exposes `shadedElementStyles` &mdash; a `css` block that resolves the
3382
- * selected `color` to `--tp-element-color`, applies the `shade`/`mixer`
3383
- * math, and exposes the result as `--tp-calc-element-color` and
3384
- * `--tp-calc-contrast-color` for consumers (variants, hover, focus, …).
3385
- * Subclasses include it once in their own host rule.
3386
- * 3. Provides three reflected attributes that drive the math:
3387
- * - `color` &mdash; palette token name (predefined or custom).
3388
- * - `shade` (`0`&ndash;`1000`, default `500`) &mdash; lighten/darken the
3389
- * resolved color (`<500` mixes white, `>500` mixes black).
3390
- * - `mixer` (`none` / `black` / `white`) &mdash; read-only output, auto-set
3391
- * whenever `shade` changes.
3392
- *
3393
- * **Adding custom color tokens.** If the predefined names are not enough,
3394
- * declare a new selector that supplies `--tp-element-color`:
3395
- *
3396
- * ```css
3397
- * tp-button[color="brand"] {
3398
- * --tp-element-color: hsl(265 75% 45%);
3399
- * }
3400
- * ```
3401
- *
3402
- * The shade math, hover/focus styles, and contrast color all derive from this
3403
- * one variable, so the new token "just works" with `shade`, `variant`, etc.
3404
- */
3405
- class ShadeMixerLitElement extends LitElement {
3406
- constructor() {
3407
- super(...arguments);
3408
- this.color = "contrast";
3409
- this.shade = 500;
3410
- this.mixer = "none";
3411
- }
3412
- static { this.rootStyles = (() => {
3413
- const style = css `
3414
- @layer properties {
3415
- :root {
3416
- --tp-color-white: hsl(0 0% 100%);
3417
- --tp-color-black: hsl(0 0% 0%);
3418
- --tp-color-contrast: var(--tp-color-black);
3419
- --tp-color-primary: hsl(220 90% 56%);
3420
- --tp-color-secondary: hsl(340 82% 52%);
3421
- --tp-color-tertiary: hsl(50 100% 50%);
3422
- --tp-color-quaternary: hsl(120 100% 40%);
3423
- --tp-color-success: hsl(140 70% 40%);
3424
- --tp-color-danger: hsl(0 70% 50%);
3425
- --tp-color-warning: hsl(45 100% 50%);
3426
- --tp-color-neutral: color-mix(in xyz, var(--tp-color-white) 50%, var(--tp-color-black) 50%);
3427
- }
3428
- }
3429
- `;
3430
- document.adoptedStyleSheets = uniquify([...document.adoptedStyleSheets, style.styleSheet]);
3431
- return style;
3432
- })(); }
3433
- static { this.shadedElementStyles = css `
3434
- --tp-element-color: var(--tp-color-primary);
3435
- --tp-shade-attr: attr(shade type(<number>));
3436
- --tp-shade-mixer-type: attr(mixer type(*));
3437
- --tp-shade-mixer-color: if(
3438
- style(--tp-shade-mixer-type: black): var(--tp-color-black);
3439
- else: var(--tp-color-white)
3440
- );
3441
- --tp-shade-mixer-percent: if(
3442
- style(--tp-shade-mixer-type: black): calc(100% - ((var(--tp-shade-attr) - 500) / 500 * 100%));
3443
- else: calc(100% - ((500 - var(--tp-shade-attr)) / 500 * 100%))
3444
- );
3445
- --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)));
3446
- --tp-calc-contrast-color: contrast-color(var(--tp-calc-element-color));
3447
- --tp-contrast-color: if(
3448
- style(--tp-calc-contrast-color: white): var(--tp-color-white);
3449
- else: var(--tp-color-black);
3450
- );
3451
-
3452
- &[color="contrast"] { --tp-element-color: var(--tp-color-contrast); }
3453
- &[color="primary"] { --tp-element-color: var(--tp-color-primary); }
3454
- &[color="secondary"] { --tp-element-color: var(--tp-color-secondary); }
3455
- &[color="tertiary"] { --tp-element-color: var(--tp-color-tertiary); }
3456
- &[color="quaternary"] { --tp-element-color: var(--tp-color-quaternary); }
3457
- &[color="success"] { --tp-element-color: var(--tp-color-success); }
3458
- &[color="danger"] { --tp-element-color: var(--tp-color-danger); }
3459
- &[color="warning"] { --tp-element-color: var(--tp-color-warning); }
3460
- &[color="neutral"] { --tp-element-color: var(--tp-color-neutral); }
3461
- `; }
3462
- willUpdate(changed) {
3463
- if (changed.has("shade")) {
3464
- this.mixer = this.shade === 500 ? "none" : this.shade > 500 ? "black" : "white";
3465
- }
3466
- }
3467
- }
3468
- __decorate([
3469
- property({ type: String, reflect: true }),
3470
- __metadata("design:type", String)
3471
- ], ShadeMixerLitElement.prototype, "color", void 0);
3472
- __decorate([
3473
- property({ type: Number, reflect: true, converter(value, type) {
3474
- const num = Number(value);
3475
- return isNaN(num) ? 500 : minMax(0, 1000, num);
3476
- } }),
3477
- __metadata("design:type", Number)
3478
- ], ShadeMixerLitElement.prototype, "shade", void 0);
3479
- __decorate([
3480
- property({ type: String, reflect: true }),
3481
- __metadata("design:type", String)
3482
- ], ShadeMixerLitElement.prototype, "mixer", void 0);
3483
-
3484
3530
  /**
3485
3531
  * `<tp-button>` &mdash; framework-agnostic, form-associated button.
3486
3532
  *