@rcarls/rc-chip 0.5.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,112 @@
1
1
  # @rcarls/rc-chip
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 079e025: Standardize component styling contracts for the breaking 0.7 release.
8
+
9
+ BREAKING CHANGE: Rename the Markdown editor's `--rme-*` properties to
10
+ `--rc-markdown-editor-*`, `--rc-app-bar-background` to `--rc-app-bar-bg`,
11
+ `--rc-textarea-radius` to `--rc-textarea-border-radius`, the transfer-list
12
+ `--rc-transfer-list-panel-*` properties to `--rc-transfer-list-listbox-*`,
13
+ `--rc-chip-group-webkit-scrollbar-display` to
14
+ `--rc-chip-group-scrollbar-display`, and `--rc-text` to `--rc-field-text`.
15
+ Compatibility aliases are intentionally not provided.
16
+
17
+ BREAKING CHANGE: Replace `--rc-select-chip-padding-inline` and
18
+ `--rc-combobox-chip-padding-inline` with explicit `*-padding-inline-start` and
19
+ `*-padding-inline-end` tokens. Generated removable chips now reserve the full
20
+ remove target and its edge offset, so their indicator cannot overlap label text.
21
+
22
+ Add canonical app-bar elevation, transfer-list listbox radius, and textarea
23
+ line-action tokens. Add logical `rc-chip` inline-padding properties so themes
24
+ can implement Material's icon-aware spacing without overriding authored child
25
+ styles. Make `rc-field` consume the shared semantic token layer,
26
+ and place the `rc-chip` and `rc-search-bar` light-DOM structural styles in the
27
+ `rc-base` cascade layer so normal consumer rules override them.
28
+
29
+ Prevent decorative, `aria-hidden` trailing list content from intercepting a
30
+ whole-row action target, and keep segmented-list item geometry from leaking
31
+ into nested standard lists.
32
+
33
+ Remove unused Material navigation-rail toggle tokens and obsolete list-item
34
+ theme tokens. Register the segmented-button private theme seam and enforce
35
+ token ownership, documentation, removed-name, selector-budget, and cascade
36
+ layer contracts through the component architecture audit.
37
+
38
+ ### Patch Changes
39
+
40
+ - 3d050f1: Keep wrapped chip rows evenly spaced. Readonly chips in an `rc-chip-group`
41
+ keep the touch-target block size, so expanded rows share the disclosure
42
+ toggle's pitch. `rc-combobox` and `rc-select` return the chip touch-target
43
+ overlap tokens as row gap, so interior chip rows no longer collapse onto each
44
+ other inside a field. Material combobox and select input chips drop their
45
+ extra block padding to render at the 2rem chip height.
46
+ - 5c006de: Ship component CSS minified. Package builds now run the CSS in Lit `css` styles
47
+ and light-DOM structural styles through Lightning CSS, removing comments and
48
+ whitespace while keeping source maps that resolve to each template. Rendered
49
+ styles are unchanged.
50
+
51
+ `@rcarls/rc-common` adds `cssText`, an identity tag that marks a plain CSS
52
+ string for minification. `rc-chip`, `rc-disclosure`, and `rc-accordion` now
53
+ depend on `@rcarls/rc-common` for it.
54
+
55
+ - Updated dependencies [e3dfa59]
56
+ - Updated dependencies [50d5610]
57
+ - Updated dependencies [9ee769c]
58
+ - Updated dependencies [1179f24]
59
+ - Updated dependencies [595fe37]
60
+ - Updated dependencies [38cd00c]
61
+ - Updated dependencies [5c006de]
62
+ - Updated dependencies [a6553ff]
63
+ - Updated dependencies [2205478]
64
+ - Updated dependencies [4341311]
65
+ - Updated dependencies [899bb5e]
66
+ - Updated dependencies [25fcfe0]
67
+ - Updated dependencies [51f6403]
68
+ - Updated dependencies [9caca6b]
69
+ - Updated dependencies [b764a3c]
70
+ - Updated dependencies [54d9ead]
71
+ - Updated dependencies [b9175e9]
72
+ - Updated dependencies [c8b762b]
73
+ - Updated dependencies [55e1e7f]
74
+ - Updated dependencies [f1ca82d]
75
+ - Updated dependencies [b87f27b]
76
+ - Updated dependencies [32ebead]
77
+ - Updated dependencies [bfefedd]
78
+ - Updated dependencies [c130173]
79
+ - Updated dependencies [11680b6]
80
+ - Updated dependencies [223d36c]
81
+ - Updated dependencies [7b91a44]
82
+ - Updated dependencies [aa04ead]
83
+ - Updated dependencies [ac65b5b]
84
+ - Updated dependencies [afcfef8]
85
+ - Updated dependencies [11ef1ad]
86
+ - @rcarls/rc-common@0.7.0
87
+
88
+ ## 0.6.0
89
+
90
+ ### Minor Changes
91
+
92
+ - ffcbf11: Add adaptive chip-group layouts, native-backed filter chips, and shared
93
+ input-chip rendering. Native-backed chips preserve controlled host state,
94
+ follow form resets when uncontrolled, and accept native link actions. Groups
95
+ restore author-owned chip variants when coordination ends. Keep search input
96
+ chrome inside the search surface and align contextual icon sizes with Material 3.
97
+ - 0a462c5: Add `--rc-chip-touch-target-overlap-block-start` and `-block-end`, zero by
98
+ default. A theme or consumer sets one to let a chip's accessible
99
+ touch-target inflation on that side overlap into whatever sits just
100
+ outside the host, such as a height-constrained field's own block padding
101
+ (a multi-select value area in `rc-search-bar` or `rc-combobox`, say),
102
+ instead of also reserving layout space there. The block-axis counterpart
103
+ to `@rcarls/rc-button`'s, `@rcarls/rc-menu-button`'s, and
104
+ `@rcarls/rc-adaptive-menu`'s own inline-axis touch-target overlap tokens.
105
+
106
+ ### Patch Changes
107
+
108
+ - 7adbd76: Keep development diagnostics concise and prevent expected test fixtures from emitting noisy warnings.
109
+
3
110
  ## 0.5.0
4
111
 
5
112
  ## 0.4.2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @rcarls/rc-chip
2
2
 
3
- Chip wrapper for native button-based actions, filters, and inputs.
3
+ Chip wrapper for native actions, links, filters, and inputs.
4
4
 
5
5
  ```html
6
6
  <rc-chip variant="filter">
@@ -11,6 +11,20 @@ Chip wrapper for native button-based actions, filters, and inputs.
11
11
  The native button remains connected for keyboard behavior and progressive enhancement.
12
12
  Native tap highlighting is suppressed because the component's clipped state layer
13
13
  provides hover, focus, and pressed feedback within the chip shape.
14
+ Structural styles for the native child are installed in the `rc-base` cascade
15
+ layer, so normal author rules outside a layer remain the final styling authority.
16
+
17
+ Themes may use `--rc-chip-padding-inline-start` and
18
+ `--rc-chip-padding-inline-end` for icon-aware logical padding. Both fall back
19
+ to `--rc-chip-padding-inline`, so existing symmetric padding remains compatible.
20
+
21
+ Navigation chips preserve the same native-link behavior:
22
+
23
+ ```html
24
+ <rc-chip>
25
+ <a href="/recipes">Recipes</a>
26
+ </rc-chip>
27
+ ```
14
28
 
15
29
  Use `rc-toolbar` when a group of interactive chips should form one tab stop
16
30
  with arrow-key navigation. Import `@rcarls/rc-toolbar/define` separately when
@@ -62,7 +62,7 @@
62
62
  "declarations": [
63
63
  {
64
64
  "kind": "class",
65
- "description": "Chip wrapper that preserves a direct native `<button>` child for interactive\nchips and accepts a direct `[data-rc-chip-label]` child for read-only chips.",
65
+ "description": "Chip wrapper that preserves a direct native `<button>` child for action chips,\na direct `<a href>` for navigation chips, or a direct `<label>` containing a\nnative checkbox/radio for filter chips. Read-only chips accept a direct\n`[data-rc-chip-label]` child.",
66
66
  "name": "RCChip",
67
67
  "cssProperties": [
68
68
  {
@@ -74,6 +74,21 @@
74
74
  "description": "Minimum chip block size (defers to native button/anchor sizing when unset).",
75
75
  "name": "--rc-chip-block-size"
76
76
  },
77
+ {
78
+ "description": "Minimum interactive touch target size.",
79
+ "name": "--rc-chip-touch-target-block-size",
80
+ "default": "3rem"
81
+ },
82
+ {
83
+ "description": "Zero by default. A theme or consumer sets this on a chip that sits at a real block-axis leading edge (no neighbor on that side), such as inside a height-constrained field, to let its touch-target inflation overlap into whatever sits just outside the host instead of also reserving layout space there.",
84
+ "name": "--rc-chip-touch-target-overlap-block-start",
85
+ "default": "0px"
86
+ },
87
+ {
88
+ "description": "The block-axis trailing-edge counterpart to `--rc-chip-touch-target-overlap-block-start`.",
89
+ "name": "--rc-chip-touch-target-overlap-block-end",
90
+ "default": "0px"
91
+ },
77
92
  {
78
93
  "description": "Block-axis padding of the slotted button, anchor, or label (defers to native padding when unset).",
79
94
  "name": "--rc-chip-padding-block"
@@ -82,6 +97,16 @@
82
97
  "description": "Inline-axis padding of the slotted button, anchor, or label (defers to native padding when unset).",
83
98
  "name": "--rc-chip-padding-inline"
84
99
  },
100
+ {
101
+ "description": "Logical leading padding of the slotted button, anchor, or label.",
102
+ "name": "--rc-chip-padding-inline-start",
103
+ "default": "var(--rc-chip-padding-inline)"
104
+ },
105
+ {
106
+ "description": "Logical trailing padding of the slotted button, anchor, or label.",
107
+ "name": "--rc-chip-padding-inline-end",
108
+ "default": "var(--rc-chip-padding-inline)"
109
+ },
85
110
  {
86
111
  "description": "Border of the slotted button, anchor, or label (defers to native border when unset).",
87
112
  "name": "--rc-chip-border"
@@ -188,7 +213,7 @@
188
213
  {
189
214
  "description": "Override for removable chip content end padding.",
190
215
  "name": "--rc-chip-removable-padding-inline-end",
191
- "default": "calc(var(--rc-chip-remove-target-size, 1.5rem) - var(--rc-chip-gap, 0px))"
216
+ "default": "calc(var(--rc-chip-remove-target-size, 1.5rem) + var(--rc-chip-remove-offset-inline, 0.125rem))"
192
217
  }
193
218
  ],
194
219
  "cssParts": [
@@ -203,7 +228,7 @@
203
228
  ],
204
229
  "slots": [
205
230
  {
206
- "description": "A direct native `<button>` child, or `[data-rc-chip-label]` when `readonly`.",
231
+ "description": "A direct native `<button>` child, `<a href>`, native-backed filter `<label>`, or `[data-rc-chip-label]` when `readonly`.",
207
232
  "name": ""
208
233
  },
209
234
  {
@@ -212,6 +237,33 @@
212
237
  }
213
238
  ],
214
239
  "members": [
240
+ {
241
+ "kind": "field",
242
+ "name": "_styledRoots",
243
+ "privacy": "private",
244
+ "static": true,
245
+ "readonly": true,
246
+ "default": "new WeakSet<Document | ShadowRoot>()"
247
+ },
248
+ {
249
+ "kind": "method",
250
+ "name": "_ensureBaseStyles",
251
+ "privacy": "private",
252
+ "static": true,
253
+ "return": {
254
+ "type": {
255
+ "text": "void"
256
+ }
257
+ },
258
+ "parameters": [
259
+ {
260
+ "name": "root",
261
+ "type": {
262
+ "text": "Document | ShadowRoot"
263
+ }
264
+ }
265
+ ]
266
+ },
215
267
  {
216
268
  "kind": "field",
217
269
  "name": "_selected",
@@ -229,6 +281,14 @@
229
281
  "privacy": "private",
230
282
  "default": "false"
231
283
  },
284
+ {
285
+ "kind": "field",
286
+ "name": "_uncontrolledSelected",
287
+ "type": {
288
+ "text": "boolean | undefined"
289
+ },
290
+ "privacy": "private"
291
+ },
232
292
  {
233
293
  "kind": "field",
234
294
  "name": "_selectedInitialized",
@@ -249,7 +309,25 @@
249
309
  },
250
310
  {
251
311
  "kind": "field",
252
- "name": "_buttonObserver",
312
+ "name": "_$input",
313
+ "type": {
314
+ "text": "HTMLInputElement | null"
315
+ },
316
+ "privacy": "private",
317
+ "default": "null"
318
+ },
319
+ {
320
+ "kind": "field",
321
+ "name": "_$form",
322
+ "type": {
323
+ "text": "HTMLFormElement | null"
324
+ },
325
+ "privacy": "private",
326
+ "default": "null"
327
+ },
328
+ {
329
+ "kind": "field",
330
+ "name": "_controlObserver",
253
331
  "type": {
254
332
  "text": "MutationObserver | null"
255
333
  },
@@ -283,6 +361,15 @@
283
361
  "privacy": "private",
284
362
  "default": "false"
285
363
  },
364
+ {
365
+ "kind": "field",
366
+ "name": "_lastChildWarning",
367
+ "type": {
368
+ "text": "string | null"
369
+ },
370
+ "privacy": "private",
371
+ "default": "null"
372
+ },
286
373
  {
287
374
  "kind": "field",
288
375
  "name": "variant",
@@ -364,7 +451,19 @@
364
451
  "type": {
365
452
  "text": "void"
366
453
  }
367
- }
454
+ },
455
+ "parameters": [
456
+ {
457
+ "name": "deferInitialSelectionUpdate",
458
+ "default": "false"
459
+ }
460
+ ]
461
+ },
462
+ {
463
+ "kind": "field",
464
+ "name": "_handleNativeChange",
465
+ "privacy": "private",
466
+ "readonly": true
368
467
  },
369
468
  {
370
469
  "kind": "field",
@@ -392,6 +491,32 @@
392
491
  }
393
492
  }
394
493
  },
494
+ {
495
+ "kind": "method",
496
+ "name": "_syncCheckedState",
497
+ "privacy": "private",
498
+ "return": {
499
+ "type": {
500
+ "text": "void"
501
+ }
502
+ }
503
+ },
504
+ {
505
+ "kind": "method",
506
+ "name": "_syncCheckedFromNative",
507
+ "privacy": "private",
508
+ "return": {
509
+ "type": {
510
+ "text": "void"
511
+ }
512
+ }
513
+ },
514
+ {
515
+ "kind": "field",
516
+ "name": "_handleFormReset",
517
+ "privacy": "private",
518
+ "readonly": true
519
+ },
395
520
  {
396
521
  "kind": "method",
397
522
  "name": "_syncPressedState",
@@ -0,0 +1,185 @@
1
+ import { css as p, LitElement as u, html as h } from "lit";
2
+ import { property as l } from "lit/decorators.js";
3
+ import { cssText as b } from "@rcarls/rc-common";
4
+ const v = p`:host{min-block-size:var(--rc-chip-touch-target-block-size,3rem);color-scheme:inherit;vertical-align:middle;place-items:center;margin-block-start:calc(-1 * var(--rc-chip-touch-target-overlap-block-start,0px));margin-block-end:calc(-1 * var(--rc-chip-touch-target-overlap-block-end,0px));display:inline-grid;position:relative}:host([readonly]){min-block-size:var(--_rc-chip-group-readonly-min-block-size,var(--rc-chip-block-size,auto))}:host([hidden]){display:none}::slotted(button),::slotted(a),::slotted(label),::slotted([data-rc-chip-label]){justify-content:center;align-items:center;gap:var(--rc-chip-gap,0px);min-block-size:var(--rc-chip-block-size);padding-block:var(--rc-chip-padding-block,revert);border:var(--rc-chip-border,revert);border-radius:var(--rc-chip-radius,revert);background:var(--rc-chip-bg,revert);color:var(--rc-chip-color,revert);font:var(--rc-chip-font,revert);text-decoration:var(--rc-chip-text-decoration,revert);white-space:nowrap;-webkit-tap-highlight-color:transparent;padding-inline-start:var(--rc-chip-padding-inline-start,var(--rc-chip-padding-inline,revert));padding-inline-end:var(--rc-chip-padding-inline-end,var(--rc-chip-padding-inline,revert));display:inline-flex}:host([selected]) ::slotted(button),:host([selected]) ::slotted(a),:host([selected]) ::slotted(label),:host([selected]) ::slotted([data-rc-chip-label]){border-color:var(--rc-chip-selected-border-color,revert);background:var(--rc-chip-selected-bg,revert);color:var(--rc-chip-selected-color,revert)}:host([disabled]) ::slotted(button){opacity:var(--rc-chip-disabled-opacity,revert)}:host(:focus-within) ::slotted(button),:host(:focus-within) ::slotted(a),:host(:focus-within) ::slotted(label){outline:var(--rc-chip-focus-ring,revert);outline-offset:var(--rc-chip-focus-ring-offset,revert)}[part=state-layer]{pointer-events:none;z-index:2;block-size:var(--rc-chip-block-size,100%);border-radius:var(--rc-chip-radius,0);background:var(--rc-chip-state-layer-color,currentColor);opacity:0;transition:opacity var(--rc-chip-state-layer-transition-duration,var(--rc-motion-effects-duration-fast,80ms)) var(--rc-chip-state-layer-transition-easing,var(--rc-motion-effects-easing-fast,ease-out));position:absolute;inset-block-start:50%;inset-inline:0;translate:0 -50%}:host([selected]) [part=state-layer]{background:var(--rc-chip-selected-state-layer-color,var(--rc-chip-state-layer-color,currentColor))}@media (hover:hover){:host(:not([disabled],[readonly]):hover) [part=state-layer]{opacity:var(--rc-chip-hover-state-layer-opacity,.08)}}:host(:not([disabled],[readonly]):focus-within) [part=state-layer]{opacity:var(--rc-chip-focus-state-layer-opacity,.12)}:host(:not([disabled],[readonly]):active) [part=state-layer]{opacity:var(--rc-chip-pressed-state-layer-opacity,.12)}[part=remove]{z-index:3;pointer-events:none;min-inline-size:var(--rc-chip-remove-target-size,1.5rem);min-block-size:var(--rc-chip-remove-target-size,1.5rem);border-radius:var(--rc-chip-remove-radius,9999px);color:inherit;font:inherit;background:0 0;border:0;place-items:center;display:none;position:absolute;inset-block-start:50%;inset-inline-end:var(--rc-chip-remove-offset-inline,.125rem);translate:0 -50%}:host([removable]) [part=remove]{display:inline-grid}::slotted([slot=remove-icon]){font-size:var(--rc-chip-remove-icon-size,smaller)!important}:host([removable]) ::slotted(button),:host([removable]) ::slotted(a),:host([removable]) ::slotted(label),:host([removable]) ::slotted([data-rc-chip-label]){padding-inline-end:var(--rc-chip-removable-padding-inline-end,calc(var(--rc-chip-remove-target-size,1.5rem) + var(--rc-chip-remove-offset-inline,.125rem)))}@media (forced-colors:active){[part=state-layer]{display:none}::slotted(button),::slotted(a),::slotted(label),::slotted([data-rc-chip-label]){color:buttontext;background:buttonface;border-color:buttonborder}:host([selected]) ::slotted(button),:host([selected]) ::slotted(a),:host([selected]) ::slotted(label),:host([selected]) ::slotted([data-rc-chip-label]){color:highlighttext;background:highlight;border-color:highlight}}`;
5
+ var f = Object.defineProperty, _ = Object.getOwnPropertyDescriptor, n = (d, e, t, r) => {
6
+ for (var i = r > 1 ? void 0 : r ? _(e, t) : e, a = d.length - 1, o; a >= 0; a--)
7
+ (o = d[a]) && (i = (r ? o(e, t, i) : o(i)) || i);
8
+ return r && i && f(e, t, i), i;
9
+ };
10
+ const y = /* @__PURE__ */ new Set(["checkbox", "menuitemcheckbox", "menuitemradio", "radio", "switch"]), m = b`@layer rc-base{rc-chip>:is(button,a,label,[data-rc-chip-label]){box-sizing:border-box;justify-content:center;align-items:center;gap:var(--rc-chip-gap,0px);min-block-size:var(--rc-chip-block-size,revert);padding-block:var(--rc-chip-padding-block,revert);border:var(--rc-chip-border,revert);border-radius:var(--rc-chip-radius,revert);background:var(--rc-chip-bg,revert);color:var(--rc-chip-color,revert);font:var(--rc-chip-font,revert);text-decoration:var(--rc-chip-text-decoration,revert);white-space:nowrap;-webkit-tap-highlight-color:transparent;margin:0;padding-inline-start:var(--rc-chip-padding-inline-start,var(--rc-chip-padding-inline,revert));padding-inline-end:var(--rc-chip-padding-inline-end,var(--rc-chip-padding-inline,revert));display:inline-flex;position:relative}rc-chip:not([readonly])>:is(button,a,label):before{content:"";z-index:1;inset-block:calc((var(--rc-chip-touch-target-block-size,3rem) - max(100%, var(--rc-chip-block-size,0px))) / -2);border-radius:inherit;position:absolute;inset-inline:0}rc-chip[selected]>:is(button,a,label,[data-rc-chip-label]),rc-chip>label:has(>input:is([type=checkbox],[type=radio]):checked){border-color:var(--rc-chip-selected-border-color,revert);background:var(--rc-chip-selected-bg,revert);color:var(--rc-chip-selected-color,revert)}rc-chip[disabled]>:is(button,label),rc-chip>label:has(>input:is([type=checkbox],[type=radio]):disabled){opacity:var(--rc-chip-disabled-opacity,revert)}rc-chip>:is(button,a):focus-visible,rc-chip>label:has(>input:is([type=checkbox],[type=radio]):focus-visible){outline:var(--rc-chip-focus-ring,revert);outline-offset:var(--rc-chip-focus-ring-offset,revert)}rc-chip>label>input:is([type=checkbox],[type=radio]){clip-path:inset(50%);white-space:nowrap;block-size:1px;inline-size:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}rc-chip[removable]>:is(button,a,label,[data-rc-chip-label]){padding-inline-end:var(--rc-chip-removable-padding-inline-end,calc(var(--rc-chip-remove-target-size,1.5rem) + var(--rc-chip-remove-offset-inline,.125rem)))}@media (forced-colors:active){rc-chip>:is(button,a,label,[data-rc-chip-label]){color:buttontext;background:buttonface;border-color:buttonborder}rc-chip[selected]>:is(button,a,label,[data-rc-chip-label]),rc-chip>label:has(>input:is([type=checkbox],[type=radio]):checked){color:highlighttext;background:highlight;border-color:highlight}}}`;
11
+ var s;
12
+ const c = (s = class extends u {
13
+ constructor() {
14
+ super(...arguments), this._defaultSelected = !1, this._selectedInitialized = !1, this._$button = null, this._$input = null, this._$form = null, this._controlObserver = null, this._disabledOwned = !1, this._pressedOwned = !1, this._slotMicrotaskQueued = !1, this._lastChildWarning = null, this.variant = "assist", this.disabled = !1, this.readonly = !1, this.removable = !1, this._handleNativeChange = () => {
15
+ const e = this._$input;
16
+ if (!e || this.disabled || this.readonly)
17
+ return;
18
+ const t = this.selected, r = e.checked;
19
+ this._selected === void 0 ? (this._uncontrolledSelected = r, this._selectedInitialized = !0, this.requestUpdate("selected", t)) : this._syncCheckedState(), this.dispatchEvent(
20
+ new CustomEvent("rc-chip-change", {
21
+ bubbles: !0,
22
+ composed: !0,
23
+ detail: { selected: r }
24
+ })
25
+ );
26
+ }, this._handleButtonClick = () => {
27
+ if (this.disabled || this.readonly)
28
+ return;
29
+ if (this.removable) {
30
+ this._dispatchRemove();
31
+ return;
32
+ }
33
+ if (this.variant !== "filter")
34
+ return;
35
+ const e = this._$button?.getAttribute("aria-haspopup");
36
+ if (e && e !== "false")
37
+ return;
38
+ const t = this.selected, r = !t;
39
+ this._selected === void 0 && (this._uncontrolledSelected = r, this._selectedInitialized = !0, this._syncPressedState(), this.requestUpdate("selected", t)), this.dispatchEvent(
40
+ new CustomEvent("rc-chip-change", {
41
+ bubbles: !0,
42
+ composed: !0,
43
+ detail: { selected: r }
44
+ })
45
+ );
46
+ }, this._handleFormReset = () => {
47
+ queueMicrotask(() => this._syncCheckedFromNative());
48
+ };
49
+ }
50
+ static _ensureBaseStyles(e) {
51
+ if (s._styledRoots.has(e))
52
+ return;
53
+ s._styledRoots.add(e);
54
+ const t = (e instanceof Document ? e : e.ownerDocument).createElement("style");
55
+ t.setAttribute("data-rc-light-dom-base", "rc-chip"), t.textContent = m, e instanceof Document ? e.head.append(t) : e.append(t);
56
+ }
57
+ get selected() {
58
+ return this._selected ?? this._uncontrolledSelected ?? this._defaultSelected;
59
+ }
60
+ set selected(e) {
61
+ const t = this.selected;
62
+ this._selected = e, this._selectedInitialized = !0, this._syncCheckedState(), this._syncPressedState(), this.requestUpdate("selected", t);
63
+ }
64
+ get defaultSelected() {
65
+ return this._defaultSelected;
66
+ }
67
+ set defaultSelected(e) {
68
+ const t = this._defaultSelected;
69
+ this._defaultSelected = e, !this._selectedInitialized && this._selected === void 0 && this._uncontrolledSelected === void 0 && (this._syncPressedState(), this.requestUpdate("selected", t)), this.requestUpdate("defaultSelected", t);
70
+ }
71
+ connectedCallback() {
72
+ super.connectedCallback(), s._ensureBaseStyles(this.getRootNode());
73
+ }
74
+ disconnectedCallback() {
75
+ this._$button?.removeEventListener("click", this._handleButtonClick), this._$input?.removeEventListener("change", this._handleNativeChange), this._$form?.removeEventListener("reset", this._handleFormReset), this._controlObserver?.disconnect(), this._controlObserver = null, super.disconnectedCallback();
76
+ }
77
+ /** Synchronizes uncontrolled filter state from the direct native input. @internal */
78
+ syncNativeSelection() {
79
+ this._syncCheckedFromNative();
80
+ }
81
+ firstUpdated() {
82
+ this._syncSlottedButton(!0);
83
+ }
84
+ updated(e) {
85
+ (e.has("disabled") || e.has("readonly")) && this._syncDisabled(), (e.has("variant") || e.has("selected") || e.has("readonly") || e.has("removable")) && this._syncPressedState(), e.has("selected") && this._syncCheckedState();
86
+ }
87
+ render() {
88
+ return h`
89
+ <slot @slotchange=${this._handleSlotChange}></slot>
90
+ <span part="state-layer" aria-hidden="true"></span>
91
+ ${this.removable ? h`
92
+ <span part="remove" aria-hidden="true">
93
+ <slot name="remove-icon">×</slot>
94
+ </span>
95
+ ` : ""}
96
+ `;
97
+ }
98
+ _handleSlotChange() {
99
+ this._slotMicrotaskQueued || (this._slotMicrotaskQueued = !0, queueMicrotask(() => {
100
+ this._slotMicrotaskQueued = !1, this.isConnected && this._syncSlottedButton();
101
+ }));
102
+ }
103
+ _syncSlottedButton(e = !1) {
104
+ const t = this.querySelector(":scope > button");
105
+ this.querySelector(":scope > a[href]");
106
+ const i = this.querySelector(":scope > label")?.querySelector(
107
+ ':scope > input:is([type="checkbox"], [type="radio"])'
108
+ ) ?? null;
109
+ if (t === this._$button && i === this._$input) {
110
+ this._syncDisabled(), this._syncCheckedState(), this._syncPressedState();
111
+ return;
112
+ }
113
+ if (this._$button?.removeEventListener("click", this._handleButtonClick), this._$input?.removeEventListener("change", this._handleNativeChange), this._$form?.removeEventListener("reset", this._handleFormReset), this._controlObserver?.disconnect(), this._controlObserver = null, this._$button = t, this._$input = i, this._$form = i?.form ?? null, this._disabledOwned = !1, this._pressedOwned = !1, t && t.addEventListener("click", this._handleButtonClick), i) {
114
+ if (this._selected === void 0 && this._uncontrolledSelected === void 0) {
115
+ const o = this.selected;
116
+ this._uncontrolledSelected = i.checked, this._selectedInitialized = !0, e ? queueMicrotask(() => this.requestUpdate("selected", o)) : this.requestUpdate("selected", o);
117
+ } else
118
+ this._syncCheckedState();
119
+ i.addEventListener("change", this._handleNativeChange), this._$form?.addEventListener("reset", this._handleFormReset);
120
+ }
121
+ const a = i ?? t;
122
+ a && (this._controlObserver = new MutationObserver(() => {
123
+ this._syncDisabled(), this._syncCheckedFromNative(), this._syncPressedState();
124
+ }), this._controlObserver.observe(a, {
125
+ attributeFilter: ["aria-pressed", "role", "disabled", "checked"]
126
+ })), this._syncDisabled(), this._syncCheckedState(), this._syncPressedState();
127
+ }
128
+ _dispatchRemove() {
129
+ this.dispatchEvent(
130
+ new CustomEvent("rc-chip-remove", {
131
+ bubbles: !0,
132
+ composed: !0,
133
+ detail: { chip: this }
134
+ })
135
+ );
136
+ }
137
+ _syncDisabled() {
138
+ const e = this._$input ?? this._$button;
139
+ e && (this.disabled || this.readonly ? (e.disabled || (this._disabledOwned = !0), e.disabled = !0) : this._disabledOwned && (e.disabled = !1, this._disabledOwned = !1));
140
+ }
141
+ _syncCheckedState() {
142
+ const e = this._$input;
143
+ e && e.checked !== this.selected && (e.checked = this.selected);
144
+ }
145
+ _syncCheckedFromNative() {
146
+ const e = this._$input;
147
+ if (!e || e.checked === this.selected)
148
+ return;
149
+ const t = this.selected;
150
+ this._selected === void 0 ? (this._uncontrolledSelected = e.checked, this._selectedInitialized = !0, this.requestUpdate("selected", t)) : this._syncCheckedState();
151
+ }
152
+ _syncPressedState() {
153
+ const e = this._$button;
154
+ if (!e)
155
+ return;
156
+ const t = e.getAttribute("role"), r = e.hasAttribute("aria-pressed") && !this._pressedOwned || (t ? y.has(t) : !1);
157
+ if (!this.readonly && !this.removable && this.variant === "filter" && !r) {
158
+ const i = this.selected ? "true" : "false";
159
+ e.getAttribute("aria-pressed") !== i && e.setAttribute("aria-pressed", i), this._pressedOwned = !0;
160
+ } else this._pressedOwned && (e.removeAttribute("aria-pressed"), this._pressedOwned = !1);
161
+ }
162
+ }, s.styles = v, s._styledRoots = /* @__PURE__ */ new WeakSet(), s);
163
+ n([
164
+ l({ type: String, reflect: !0 })
165
+ ], c.prototype, "variant", 2);
166
+ n([
167
+ l({ type: Boolean, reflect: !0 })
168
+ ], c.prototype, "selected", 1);
169
+ n([
170
+ l({ type: Boolean, attribute: "default-selected" })
171
+ ], c.prototype, "defaultSelected", 1);
172
+ n([
173
+ l({ type: Boolean, reflect: !0 })
174
+ ], c.prototype, "disabled", 2);
175
+ n([
176
+ l({ type: Boolean, reflect: !0 })
177
+ ], c.prototype, "readonly", 2);
178
+ n([
179
+ l({ type: Boolean, reflect: !0 })
180
+ ], c.prototype, "removable", 2);
181
+ let x = c;
182
+ export {
183
+ x as R
184
+ };
185
+ //# sourceMappingURL=rc-chip-D2kF8iCM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rc-chip-D2kF8iCM.js","sources":["../src/rc-chip.styles.ts","../src/rc-chip.ts"],"sourcesContent":["import { css } from 'lit';\n\nexport const chipStyles = css`\n :host {\n display: inline-grid;\n position: relative;\n place-items: center;\n min-block-size: var(--rc-chip-touch-target-block-size, 3rem);\n color-scheme: inherit;\n vertical-align: middle;\n /*\n * Zero by default. Unlike rc-button's touch-target inflation (opt-in via\n * icon-only), a chip's accessible touch-target minimum applies\n * unconditionally, so it's a common fit inside a height-constrained\n * field -- rc-search-bar's or rc-combobox's multi-select value area, say\n * -- where 3rem per chip would force the field taller than its own\n * content needs. A theme or consumer sets one of these on a chip that\n * sits at a real block-axis edge (no neighbor on that side within the\n * field) to let the touch target overlap into the field's own block\n * padding instead of also reserving layout space there. The same\n * pattern as rc-button's, rc-menu-button's, and rc-adaptive-menu's own\n * touch-target overlap tokens, but on the block axis: a chip's own\n * touch-target inflation is vertical, not horizontal.\n */\n margin-block-start: calc(-1 * var(--rc-chip-touch-target-overlap-block-start, 0px));\n margin-block-end: calc(-1 * var(--rc-chip-touch-target-overlap-block-end, 0px));\n }\n\n :host([readonly]) {\n min-block-size: var(--_rc-chip-group-readonly-min-block-size, var(--rc-chip-block-size, auto));\n }\n\n :host([hidden]) {\n display: none;\n }\n\n ::slotted(button),\n ::slotted(a),\n ::slotted(label),\n ::slotted([data-rc-chip-label]) {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: var(--rc-chip-gap, 0px);\n min-block-size: var(--rc-chip-block-size);\n padding-block: var(--rc-chip-padding-block, revert);\n padding-inline-start: var(\n --rc-chip-padding-inline-start,\n var(--rc-chip-padding-inline, revert)\n );\n padding-inline-end: var(--rc-chip-padding-inline-end, var(--rc-chip-padding-inline, revert));\n border: var(--rc-chip-border, revert);\n border-radius: var(--rc-chip-radius, revert);\n background: var(--rc-chip-bg, revert);\n color: var(--rc-chip-color, revert);\n font: var(--rc-chip-font, revert);\n text-decoration: var(--rc-chip-text-decoration, revert);\n white-space: nowrap;\n -webkit-tap-highlight-color: transparent;\n }\n\n :host([selected]) ::slotted(button),\n :host([selected]) ::slotted(a),\n :host([selected]) ::slotted(label),\n :host([selected]) ::slotted([data-rc-chip-label]) {\n border-color: var(--rc-chip-selected-border-color, revert);\n background: var(--rc-chip-selected-bg, revert);\n color: var(--rc-chip-selected-color, revert);\n }\n\n :host([disabled]) ::slotted(button) {\n opacity: var(--rc-chip-disabled-opacity, revert);\n }\n\n :host(:focus-within) ::slotted(button),\n :host(:focus-within) ::slotted(a),\n :host(:focus-within) ::slotted(label) {\n outline: var(--rc-chip-focus-ring, revert);\n outline-offset: var(--rc-chip-focus-ring-offset, revert);\n }\n\n [part='state-layer'] {\n pointer-events: none;\n position: absolute;\n z-index: 2;\n inset-inline: 0;\n inset-block-start: 50%;\n block-size: var(--rc-chip-block-size, 100%);\n translate: 0 -50%;\n border-radius: var(--rc-chip-radius, 0);\n background: var(--rc-chip-state-layer-color, currentColor);\n opacity: 0;\n transition: opacity\n var(--rc-chip-state-layer-transition-duration, var(--rc-motion-effects-duration-fast, 80ms))\n var(--rc-chip-state-layer-transition-easing, var(--rc-motion-effects-easing-fast, ease-out));\n }\n\n :host([selected]) [part='state-layer'] {\n background: var(\n --rc-chip-selected-state-layer-color,\n var(--rc-chip-state-layer-color, currentColor)\n );\n }\n\n @media (hover: hover) {\n :host(:not([disabled], [readonly]):hover) [part='state-layer'] {\n opacity: var(--rc-chip-hover-state-layer-opacity, 0.08);\n }\n }\n\n :host(:not([disabled], [readonly]):focus-within) [part='state-layer'] {\n opacity: var(--rc-chip-focus-state-layer-opacity, 0.12);\n }\n\n :host(:not([disabled], [readonly]):active) [part='state-layer'] {\n opacity: var(--rc-chip-pressed-state-layer-opacity, 0.12);\n }\n\n [part='remove'] {\n position: absolute;\n z-index: 3;\n pointer-events: none;\n inset-block-start: 50%;\n inset-inline-end: var(--rc-chip-remove-offset-inline, 0.125rem);\n display: none;\n place-items: center;\n min-inline-size: var(--rc-chip-remove-target-size, 1.5rem);\n min-block-size: var(--rc-chip-remove-target-size, 1.5rem);\n translate: 0 -50%;\n border: 0;\n border-radius: var(--rc-chip-remove-radius, 9999px);\n background: transparent;\n color: inherit;\n font: inherit;\n }\n\n :host([removable]) [part='remove'] {\n display: inline-grid;\n }\n\n ::slotted([slot='remove-icon']) {\n /* Keep icon-font utility classes from overriding the chip's compact icon size. */\n font-size: var(--rc-chip-remove-icon-size, smaller) !important;\n }\n\n :host([removable]) ::slotted(button),\n :host([removable]) ::slotted(a),\n :host([removable]) ::slotted(label),\n :host([removable]) ::slotted([data-rc-chip-label]) {\n padding-inline-end: var(\n --rc-chip-removable-padding-inline-end,\n calc(\n var(--rc-chip-remove-target-size, 1.5rem) + var(--rc-chip-remove-offset-inline, 0.125rem)\n )\n );\n }\n\n @media (forced-colors: active) {\n [part='state-layer'] {\n display: none;\n }\n\n ::slotted(button),\n ::slotted(a),\n ::slotted(label),\n ::slotted([data-rc-chip-label]) {\n border-color: ButtonBorder;\n background: ButtonFace;\n color: ButtonText;\n }\n\n :host([selected]) ::slotted(button),\n :host([selected]) ::slotted(a),\n :host([selected]) ::slotted(label),\n :host([selected]) ::slotted([data-rc-chip-label]) {\n border-color: Highlight;\n background: Highlight;\n color: HighlightText;\n }\n }\n`;\n\nexport default chipStyles;\n","import { LitElement, html } from 'lit';\nimport type { PropertyValues } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { cssText } from '@rcarls/rc-common';\n\nimport chipStyles from './rc-chip.styles.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'rc-chip': RCChip;\n }\n\n interface HTMLElementEventMap {\n 'rc-chip-change': CustomEvent<RCChipChangeDetail>;\n 'rc-chip-remove': CustomEvent<RCChipRemoveDetail>;\n }\n}\n\nconst TOGGLE_ROLES = new Set(['checkbox', 'menuitemcheckbox', 'menuitemradio', 'radio', 'switch']);\n\nconst LIGHT_DOM_CSS = cssText`\n@layer rc-base {\n rc-chip > :is(button, a, label, [data-rc-chip-label]) {\n position: relative;\n display: inline-flex;\n box-sizing: border-box;\n align-items: center;\n justify-content: center;\n gap: var(--rc-chip-gap, 0px);\n min-block-size: var(--rc-chip-block-size, revert);\n margin: 0;\n padding-block: var(--rc-chip-padding-block, revert);\n padding-inline-start: var(\n --rc-chip-padding-inline-start,\n var(--rc-chip-padding-inline, revert)\n );\n padding-inline-end: var(--rc-chip-padding-inline-end, var(--rc-chip-padding-inline, revert));\n border: var(--rc-chip-border, revert);\n border-radius: var(--rc-chip-radius, revert);\n background: var(--rc-chip-bg, revert);\n color: var(--rc-chip-color, revert);\n font: var(--rc-chip-font, revert);\n text-decoration: var(--rc-chip-text-decoration, revert);\n white-space: nowrap;\n -webkit-tap-highlight-color: transparent;\n }\n\n rc-chip:not([readonly]) > :is(button, a, label)::before {\n content: '';\n position: absolute;\n z-index: 1;\n inset-block: calc(\n (var(--rc-chip-touch-target-block-size, 3rem) - max(100%, var(--rc-chip-block-size, 0px))) /\n -2\n );\n inset-inline: 0;\n border-radius: inherit;\n }\n\n rc-chip[selected] > :is(button, a, label, [data-rc-chip-label]),\n rc-chip > label:has(> input:is([type='checkbox'], [type='radio']):checked) {\n border-color: var(--rc-chip-selected-border-color, revert);\n background: var(--rc-chip-selected-bg, revert);\n color: var(--rc-chip-selected-color, revert);\n }\n\n rc-chip[disabled] > :is(button, label),\n rc-chip > label:has(> input:is([type='checkbox'], [type='radio']):disabled) {\n opacity: var(--rc-chip-disabled-opacity, revert);\n }\n\n rc-chip > :is(button, a):focus-visible,\n rc-chip > label:has(> input:is([type='checkbox'], [type='radio']):focus-visible) {\n outline: var(--rc-chip-focus-ring, revert);\n outline-offset: var(--rc-chip-focus-ring-offset, revert);\n }\n\n rc-chip > label > input:is([type='checkbox'], [type='radio']) {\n position: absolute;\n inline-size: 1px;\n block-size: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n }\n\n rc-chip[removable] > :is(button, a, label, [data-rc-chip-label]) {\n padding-inline-end: var(\n --rc-chip-removable-padding-inline-end,\n calc(\n var(--rc-chip-remove-target-size, 1.5rem) +\n var(--rc-chip-remove-offset-inline, 0.125rem)\n )\n );\n }\n\n @media (forced-colors: active) {\n rc-chip > :is(button, a, label, [data-rc-chip-label]) {\n border-color: ButtonBorder;\n background: ButtonFace;\n color: ButtonText;\n }\n\n rc-chip[selected] > :is(button, a, label, [data-rc-chip-label]),\n rc-chip > label:has(> input:is([type='checkbox'], [type='radio']):checked) {\n border-color: Highlight;\n background: Highlight;\n color: HighlightText;\n }\n }\n}\n`;\n\n/** Supported chip variants. */\nexport type RCChipVariant = 'assist' | 'filter' | 'input' | 'suggestion';\n\n/** Detail payload for `rc-chip-change`. */\nexport interface RCChipChangeDetail {\n /** Selected state after user interaction. */\n selected: boolean;\n}\n\n/** Detail payload for `rc-chip-remove`. */\nexport interface RCChipRemoveDetail {\n /** The host chip requesting removal. */\n chip: RCChip;\n}\n\n/**\n * Chip wrapper that preserves a direct native `<button>` child for action chips,\n * a direct `<a href>` for navigation chips, or a direct `<label>` containing a\n * native checkbox/radio for filter chips. Read-only chips accept a direct\n * `[data-rc-chip-label]` child.\n *\n * @see {@link https://richardcarls.github.io/rc-webcomponents/components/rc-chip rc-chip docs}\n * @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/button/ WAI-ARIA button pattern}\n *\n * @slot - A direct native `<button>` child, `<a href>`, native-backed filter\n * `<label>`, or `[data-rc-chip-label]` when `readonly`.\n * @slot remove-icon - Optional presentational remove icon.\n *\n * @fires rc-chip-change - Fired when a user toggles a filter chip.\n * @fires rc-chip-remove - Fired when a user activates a removable chip's native button.\n *\n * @csspart state-layer - Overlay layer for hover, focus, pressed, ripple, or design-system effects.\n * @csspart remove - Presentational trailing remove indicator.\n *\n * @cssprop [--rc-chip-gap=0px] - Gap between the slotted button/anchor/label's content.\n * @cssprop [--rc-chip-block-size] - Minimum chip block size (defers to native button/anchor\n * sizing when unset).\n * @cssprop [--rc-chip-touch-target-block-size=3rem] - Minimum interactive touch target size.\n * @cssprop [--rc-chip-touch-target-overlap-block-start=0px] - Zero by default. A theme or\n * consumer sets this on a chip that sits at a real block-axis leading edge (no neighbor on\n * that side), such as inside a height-constrained field, to let its touch-target inflation\n * overlap into whatever sits just outside the host instead of also reserving layout space\n * there.\n * @cssprop [--rc-chip-touch-target-overlap-block-end=0px] - The block-axis trailing-edge\n * counterpart to `--rc-chip-touch-target-overlap-block-start`.\n * @cssprop [--rc-chip-padding-block] - Block-axis padding of the slotted button, anchor, or\n * label (defers to native padding when unset).\n * @cssprop [--rc-chip-padding-inline] - Inline-axis padding of the slotted button, anchor, or\n * label (defers to native padding when unset).\n * @cssprop [--rc-chip-padding-inline-start=var(--rc-chip-padding-inline)] - Logical leading\n * padding of the slotted button, anchor, or label.\n * @cssprop [--rc-chip-padding-inline-end=var(--rc-chip-padding-inline)] - Logical trailing\n * padding of the slotted button, anchor, or label.\n * @cssprop [--rc-chip-border] - Border of the slotted button, anchor, or label (defers to\n * native border when unset).\n * @cssprop [--rc-chip-radius] - Border radius of the slotted button/anchor/label and the\n * state-layer overlay (defers to native border-radius when unset; the state-layer overlay\n * falls back to 0).\n * @cssprop [--rc-chip-bg] - Background of the slotted button, anchor, or label (defers to\n * native background when unset).\n * @cssprop [--rc-chip-color] - Text color of the slotted button, anchor, or label (defers to\n * native color when unset).\n * @cssprop [--rc-chip-font] - Font shorthand for the slotted button, anchor, or label (defers\n * to native font when unset).\n * @cssprop [--rc-chip-text-decoration] - Text decoration for the slotted anchor (defers to\n * native text-decoration when unset).\n * @cssprop [--rc-chip-selected-border-color] - Border color when `selected` (defers to native\n * styling when unset).\n * @cssprop [--rc-chip-selected-bg] - Background when `selected` (defers to native styling when\n * unset).\n * @cssprop [--rc-chip-selected-color] - Text color when `selected` (defers to native styling\n * when unset).\n * @cssprop [--rc-chip-disabled-opacity] - Opacity of the slotted button when `disabled` (defers\n * to native disabled styling when unset).\n * @cssprop [--rc-chip-focus-ring] - Outline shown while focus-within (defers to native focus\n * styling when unset).\n * @cssprop [--rc-chip-focus-ring-offset] - Outline offset while focus-within (defers to native\n * focus styling when unset).\n * @cssprop [--rc-chip-state-layer-color=currentColor] - Hover/focus/pressed state-layer color.\n * @cssprop [--rc-chip-selected-state-layer-color=var(--rc-chip-state-layer-color, currentColor)] - Selected chip state-layer color.\n * @cssprop [--rc-chip-hover-state-layer-opacity=0.08] - Hover state-layer opacity.\n * @cssprop [--rc-chip-focus-state-layer-opacity=0.12] - Focus state-layer opacity.\n * @cssprop [--rc-chip-pressed-state-layer-opacity=0.12] - Pressed state-layer opacity.\n * @cssprop [--rc-chip-state-layer-transition-duration=var(--rc-motion-effects-duration-fast,80ms)] - State-layer effects duration.\n * @cssprop [--rc-chip-state-layer-transition-easing=var(--rc-motion-effects-easing-fast,ease-out)] - State-layer effects easing.\n * @cssprop [--rc-chip-remove-offset-inline=0.125rem] - Inline offset of the remove indicator\n * from the chip edge.\n * @cssprop [--rc-chip-remove-target-size=1.5rem] - Minimum inline and block size of the remove\n * indicator's hit target.\n * @cssprop [--rc-chip-remove-radius=9999px] - Border radius of the remove indicator.\n * @cssprop [--rc-chip-remove-icon-size=smaller] - Font size for a slotted remove icon.\n * @cssprop [--rc-chip-removable-padding-inline-end=calc(var(--rc-chip-remove-target-size, 1.5rem) + var(--rc-chip-remove-offset-inline, 0.125rem))] - Override for removable chip content end padding.\n *\n * @attr variant - Chip variant: `assist`, `filter`, `input`, or `suggestion`.\n * @attr selected - Declarative selected state for filter/input chips.\n * @attr default-selected - Initial selected state for uncontrolled usage.\n * @attr disabled - Mirrors disabled state to the native child button.\n * @attr readonly - Marks the chip as non-interactive display content.\n * @attr removable - Shows a trailing remove affordance.\n */\nexport class RCChip extends LitElement {\n static override styles = chipStyles;\n\n private static readonly _styledRoots = new WeakSet<Document | ShadowRoot>();\n\n private static _ensureBaseStyles(root: Document | ShadowRoot): void {\n if (RCChip._styledRoots.has(root)) {\n return;\n }\n\n RCChip._styledRoots.add(root);\n\n const $style = (root instanceof Document ? root : root.ownerDocument).createElement('style');\n\n $style.setAttribute('data-rc-light-dom-base', 'rc-chip');\n $style.textContent = LIGHT_DOM_CSS;\n\n if (root instanceof Document) {\n root.head.append($style);\n } else {\n root.append($style);\n }\n }\n\n private _selected: boolean | undefined;\n private _defaultSelected = false;\n private _uncontrolledSelected: boolean | undefined;\n private _selectedInitialized = false;\n private _$button: HTMLButtonElement | null = null;\n private _$input: HTMLInputElement | null = null;\n private _$form: HTMLFormElement | null = null;\n private _controlObserver: MutationObserver | null = null;\n private _disabledOwned = false;\n private _pressedOwned = false;\n private _slotMicrotaskQueued = false;\n private _lastChildWarning: string | null = null;\n\n /** Chip variant. */\n @property({ type: String, reflect: true })\n variant: RCChipVariant = 'assist';\n\n /** Current selected state. Host writes are silent. */\n @property({ type: Boolean, reflect: true })\n get selected(): boolean {\n return this._selected ?? this._uncontrolledSelected ?? this._defaultSelected;\n }\n\n set selected(value: boolean | undefined) {\n const oldValue = this.selected;\n\n this._selected = value;\n this._selectedInitialized = true;\n this._syncCheckedState();\n this._syncPressedState();\n this.requestUpdate('selected', oldValue);\n }\n\n /** Initial selected state for uncontrolled usage. */\n @property({ type: Boolean, attribute: 'default-selected' })\n get defaultSelected(): boolean {\n return this._defaultSelected;\n }\n\n set defaultSelected(value: boolean) {\n const oldValue = this._defaultSelected;\n\n this._defaultSelected = value;\n\n if (\n !this._selectedInitialized &&\n this._selected === undefined &&\n this._uncontrolledSelected === undefined\n ) {\n this._syncPressedState();\n this.requestUpdate('selected', oldValue);\n }\n\n this.requestUpdate('defaultSelected', oldValue);\n }\n\n /** Mirror disabled state to the native child button. */\n @property({ type: Boolean, reflect: true })\n disabled = false;\n\n /** Mark this chip as non-interactive display content. */\n @property({ type: Boolean, reflect: true })\n readonly = false;\n\n /** Show a trailing remove affordance. */\n @property({ type: Boolean, reflect: true })\n removable = false;\n\n override connectedCallback(): void {\n super.connectedCallback();\n RCChip._ensureBaseStyles(this.getRootNode() as Document | ShadowRoot);\n }\n\n override disconnectedCallback(): void {\n this._$button?.removeEventListener('click', this._handleButtonClick);\n this._$input?.removeEventListener('change', this._handleNativeChange);\n this._$form?.removeEventListener('reset', this._handleFormReset);\n this._controlObserver?.disconnect();\n this._controlObserver = null;\n super.disconnectedCallback();\n }\n\n /** Synchronizes uncontrolled filter state from the direct native input. @internal */\n syncNativeSelection(): void {\n this._syncCheckedFromNative();\n }\n\n protected override firstUpdated(): void {\n this._syncSlottedButton(true);\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n if (changed.has('disabled') || changed.has('readonly')) {\n this._syncDisabled();\n }\n\n if (\n changed.has('variant') ||\n changed.has('selected') ||\n changed.has('readonly') ||\n changed.has('removable')\n ) {\n this._syncPressedState();\n }\n\n if (changed.has('selected')) {\n this._syncCheckedState();\n }\n }\n\n protected override render() {\n return html`\n <slot @slotchange=${this._handleSlotChange}></slot>\n <span part=\"state-layer\" aria-hidden=\"true\"></span>\n ${this.removable\n ? html`\n <span part=\"remove\" aria-hidden=\"true\">\n <slot name=\"remove-icon\">×</slot>\n </span>\n `\n : ''}\n `;\n }\n\n private _handleSlotChange(): void {\n if (this._slotMicrotaskQueued) {\n return;\n }\n\n this._slotMicrotaskQueued = true;\n\n queueMicrotask(() => {\n this._slotMicrotaskQueued = false;\n\n if (this.isConnected) {\n this._syncSlottedButton();\n }\n });\n }\n\n private _syncSlottedButton(deferInitialSelectionUpdate = false): void {\n const $nextButton = this.querySelector<HTMLButtonElement>(':scope > button');\n const $anchor = this.querySelector<HTMLAnchorElement>(':scope > a[href]');\n const $label = this.querySelector<HTMLLabelElement>(':scope > label');\n const $nextInput =\n $label?.querySelector<HTMLInputElement>(\n ':scope > input:is([type=\"checkbox\"], [type=\"radio\"])',\n ) ?? null;\n\n if (import.meta.env.DEV) {\n let childWarning: string | null = null;\n\n if (!$nextButton && !$anchor && !$label && !this.readonly) {\n childWarning =\n '[rc-chip] No supported direct child found. Place a native <button>, <a href>, or a <label> containing a direct checkbox/radio inside <rc-chip>, or use readonly with a [data-rc-chip-label] child.';\n } else if ($label && !$nextInput && !this.readonly) {\n childWarning =\n '[rc-chip] A direct child <label> must contain a direct <input type=\"checkbox\"> or <input type=\"radio\">.';\n }\n\n if (childWarning && childWarning !== this._lastChildWarning) {\n console.warn(childWarning);\n }\n\n this._lastChildWarning = childWarning;\n }\n\n if ($nextButton === this._$button && $nextInput === this._$input) {\n this._syncDisabled();\n this._syncCheckedState();\n this._syncPressedState();\n\n return;\n }\n\n this._$button?.removeEventListener('click', this._handleButtonClick);\n this._$input?.removeEventListener('change', this._handleNativeChange);\n this._$form?.removeEventListener('reset', this._handleFormReset);\n this._controlObserver?.disconnect();\n this._controlObserver = null;\n this._$button = $nextButton;\n this._$input = $nextInput;\n this._$form = $nextInput?.form ?? null;\n this._disabledOwned = false;\n this._pressedOwned = false;\n\n if ($nextButton) {\n $nextButton.addEventListener('click', this._handleButtonClick);\n }\n\n if ($nextInput) {\n if (this._selected === undefined && this._uncontrolledSelected === undefined) {\n const oldValue = this.selected;\n\n this._uncontrolledSelected = $nextInput.checked;\n this._selectedInitialized = true;\n\n if (deferInitialSelectionUpdate) {\n queueMicrotask(() => this.requestUpdate('selected', oldValue));\n } else {\n this.requestUpdate('selected', oldValue);\n }\n } else {\n this._syncCheckedState();\n }\n\n $nextInput.addEventListener('change', this._handleNativeChange);\n this._$form?.addEventListener('reset', this._handleFormReset);\n }\n\n const $observedControl = $nextInput ?? $nextButton;\n\n if ($observedControl) {\n this._controlObserver = new MutationObserver(() => {\n this._syncDisabled();\n this._syncCheckedFromNative();\n this._syncPressedState();\n });\n\n this._controlObserver.observe($observedControl, {\n attributeFilter: ['aria-pressed', 'role', 'disabled', 'checked'],\n });\n }\n\n this._syncDisabled();\n this._syncCheckedState();\n this._syncPressedState();\n }\n\n private readonly _handleNativeChange = (): void => {\n const $input = this._$input;\n\n if (!$input || this.disabled || this.readonly) {\n return;\n }\n\n const oldValue = this.selected;\n const requestedSelected = $input.checked;\n\n if (this._selected === undefined) {\n this._uncontrolledSelected = requestedSelected;\n this._selectedInitialized = true;\n this.requestUpdate('selected', oldValue);\n } else {\n this._syncCheckedState();\n }\n\n this.dispatchEvent(\n new CustomEvent<RCChipChangeDetail>('rc-chip-change', {\n bubbles: true,\n composed: true,\n detail: { selected: requestedSelected },\n }),\n );\n };\n\n private readonly _handleButtonClick = (): void => {\n if (this.disabled || this.readonly) {\n return;\n }\n\n if (this.removable) {\n this._dispatchRemove();\n\n return;\n }\n\n if (this.variant !== 'filter') {\n return;\n }\n\n // Menu-backed filter chips expose filter affordance, but their menu owns\n // the eventual selected state. Preserve that author-controlled behavior.\n const hasPopup = this._$button?.getAttribute('aria-haspopup');\n\n if (hasPopup && hasPopup !== 'false') {\n return;\n }\n\n const oldValue = this.selected;\n const requestedSelected = !oldValue;\n\n if (this._selected === undefined) {\n this._uncontrolledSelected = requestedSelected;\n this._selectedInitialized = true;\n this._syncPressedState();\n this.requestUpdate('selected', oldValue);\n }\n\n this.dispatchEvent(\n new CustomEvent<RCChipChangeDetail>('rc-chip-change', {\n bubbles: true,\n composed: true,\n detail: { selected: requestedSelected },\n }),\n );\n };\n\n private _dispatchRemove(): void {\n this.dispatchEvent(\n new CustomEvent<RCChipRemoveDetail>('rc-chip-remove', {\n bubbles: true,\n composed: true,\n detail: { chip: this },\n }),\n );\n }\n\n private _syncDisabled(): void {\n const $control = this._$input ?? this._$button;\n\n if (!$control) {\n return;\n }\n\n if (this.disabled || this.readonly) {\n if (!$control.disabled) {\n this._disabledOwned = true;\n }\n\n $control.disabled = true;\n } else if (this._disabledOwned) {\n $control.disabled = false;\n this._disabledOwned = false;\n }\n }\n\n private _syncCheckedState(): void {\n const $input = this._$input;\n\n if ($input && $input.checked !== this.selected) {\n $input.checked = this.selected;\n }\n }\n\n private _syncCheckedFromNative(): void {\n const $input = this._$input;\n\n if (!$input || $input.checked === this.selected) {\n return;\n }\n\n const oldValue = this.selected;\n\n if (this._selected === undefined) {\n this._uncontrolledSelected = $input.checked;\n this._selectedInitialized = true;\n this.requestUpdate('selected', oldValue);\n } else {\n this._syncCheckedState();\n }\n }\n\n private readonly _handleFormReset = (): void => {\n queueMicrotask(() => this._syncCheckedFromNative());\n };\n\n private _syncPressedState(): void {\n const $button = this._$button;\n\n if (!$button) {\n return;\n }\n\n const role = $button.getAttribute('role');\n const authorOwnsState =\n ($button.hasAttribute('aria-pressed') && !this._pressedOwned) ||\n (role ? TOGGLE_ROLES.has(role) : false);\n\n if (!this.readonly && !this.removable && this.variant === 'filter' && !authorOwnsState) {\n const pressed = this.selected ? 'true' : 'false';\n\n if ($button.getAttribute('aria-pressed') !== pressed) {\n $button.setAttribute('aria-pressed', pressed);\n }\n\n this._pressedOwned = true;\n } else if (this._pressedOwned) {\n $button.removeAttribute('aria-pressed');\n this._pressedOwned = false;\n }\n }\n}\n\nexport default RCChip;\n"],"names":["chipStyles","css","TOGGLE_ROLES","LIGHT_DOM_CSS","cssText","_RCChip","_a","LitElement","$input","oldValue","requestedSelected","hasPopup","root","$style","value","changed","html","deferInitialSelectionUpdate","$nextButton","$nextInput","$observedControl","$control","$button","role","authorOwnsState","pressed","__decorateClass","property","RCChip"],"mappings":";;;AAEO,MAAMA,IAAaC;;;;;;ACiB1B,MAAMC,wBAAmB,IAAI,CAAC,YAAY,oBAAoB,iBAAiB,SAAS,QAAQ,CAAC,GAE3FC,IAAgBC;;AAmMf,MAAMC,KAANC,IAAA,cAAqBC,EAAW;AAAA,EAAhC,cAAA;AAAA,UAAA,GAAA,SAAA,GAyBL,KAAQ,mBAAmB,IAE3B,KAAQ,uBAAuB,IAC/B,KAAQ,WAAqC,MAC7C,KAAQ,UAAmC,MAC3C,KAAQ,SAAiC,MACzC,KAAQ,m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AM,SAAS,WAAW,oBAAoB;AAAA,GA1D/CtB,EA2DP,WAAA,mBAAA,CAAA;AAuBJqB,EAAA;AAAA,EADCC,EAAS,EAAE,MAAM,SAAS,SAAS,IAAM;AAAA,GAjF/BtB,EAkFX,WAAA,YAAA,CAAA;AAIAqB,EAAA;AAAA,EADCC,EAAS,EAAE,MAAM,SAAS,SAAS,IAAM;AAAA,GArF/BtB,EAsFX,WAAA,YAAA,CAAA;AAIAqB,EAAA;AAAA,EADCC,EAAS,EAAE,MAAM,SAAS,SAAS,IAAM;AAAA,GAzF/BtB,EA0FX,WAAA,aAAA,CAAA;AA1FK,IAAMuB,IAANvB;"}
@@ -1,3 +1,3 @@
1
- import { R as e } from "./rc-chip-Do50B5yx.js";
1
+ import { R as e } from "./rc-chip-D2kF8iCM.js";
2
2
  customElements.get("rc-chip") || customElements.define("rc-chip", e);
3
3
  //# sourceMappingURL=rc-chip-define.js.map
package/dist/rc-chip.js CHANGED
@@ -1,4 +1,4 @@
1
- import { R as r } from "./rc-chip-Do50B5yx.js";
1
+ import { R as r } from "./rc-chip-D2kF8iCM.js";
2
2
  export {
3
3
  r as RCChip
4
4
  };
@@ -21,13 +21,16 @@ export interface RCChipRemoveDetail {
21
21
  chip: RCChip;
22
22
  }
23
23
  /**
24
- * Chip wrapper that preserves a direct native `<button>` child for interactive
25
- * chips and accepts a direct `[data-rc-chip-label]` child for read-only chips.
24
+ * Chip wrapper that preserves a direct native `<button>` child for action chips,
25
+ * a direct `<a href>` for navigation chips, or a direct `<label>` containing a
26
+ * native checkbox/radio for filter chips. Read-only chips accept a direct
27
+ * `[data-rc-chip-label]` child.
26
28
  *
27
29
  * @see {@link https://richardcarls.github.io/rc-webcomponents/components/rc-chip rc-chip docs}
28
30
  * @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/button/ WAI-ARIA button pattern}
29
31
  *
30
- * @slot - A direct native `<button>` child, or `[data-rc-chip-label]` when `readonly`.
32
+ * @slot - A direct native `<button>` child, `<a href>`, native-backed filter
33
+ * `<label>`, or `[data-rc-chip-label]` when `readonly`.
31
34
  * @slot remove-icon - Optional presentational remove icon.
32
35
  *
33
36
  * @fires rc-chip-change - Fired when a user toggles a filter chip.
@@ -39,10 +42,22 @@ export interface RCChipRemoveDetail {
39
42
  * @cssprop [--rc-chip-gap=0px] - Gap between the slotted button/anchor/label's content.
40
43
  * @cssprop [--rc-chip-block-size] - Minimum chip block size (defers to native button/anchor
41
44
  * sizing when unset).
45
+ * @cssprop [--rc-chip-touch-target-block-size=3rem] - Minimum interactive touch target size.
46
+ * @cssprop [--rc-chip-touch-target-overlap-block-start=0px] - Zero by default. A theme or
47
+ * consumer sets this on a chip that sits at a real block-axis leading edge (no neighbor on
48
+ * that side), such as inside a height-constrained field, to let its touch-target inflation
49
+ * overlap into whatever sits just outside the host instead of also reserving layout space
50
+ * there.
51
+ * @cssprop [--rc-chip-touch-target-overlap-block-end=0px] - The block-axis trailing-edge
52
+ * counterpart to `--rc-chip-touch-target-overlap-block-start`.
42
53
  * @cssprop [--rc-chip-padding-block] - Block-axis padding of the slotted button, anchor, or
43
54
  * label (defers to native padding when unset).
44
55
  * @cssprop [--rc-chip-padding-inline] - Inline-axis padding of the slotted button, anchor, or
45
56
  * label (defers to native padding when unset).
57
+ * @cssprop [--rc-chip-padding-inline-start=var(--rc-chip-padding-inline)] - Logical leading
58
+ * padding of the slotted button, anchor, or label.
59
+ * @cssprop [--rc-chip-padding-inline-end=var(--rc-chip-padding-inline)] - Logical trailing
60
+ * padding of the slotted button, anchor, or label.
46
61
  * @cssprop [--rc-chip-border] - Border of the slotted button, anchor, or label (defers to
47
62
  * native border when unset).
48
63
  * @cssprop [--rc-chip-radius] - Border radius of the slotted button/anchor/label and the
@@ -81,7 +96,7 @@ export interface RCChipRemoveDetail {
81
96
  * indicator's hit target.
82
97
  * @cssprop [--rc-chip-remove-radius=9999px] - Border radius of the remove indicator.
83
98
  * @cssprop [--rc-chip-remove-icon-size=smaller] - Font size for a slotted remove icon.
84
- * @cssprop [--rc-chip-removable-padding-inline-end=calc(var(--rc-chip-remove-target-size, 1.5rem) - var(--rc-chip-gap, 0px))] - Override for removable chip content end padding.
99
+ * @cssprop [--rc-chip-removable-padding-inline-end=calc(var(--rc-chip-remove-target-size, 1.5rem) + var(--rc-chip-remove-offset-inline, 0.125rem))] - Override for removable chip content end padding.
85
100
  *
86
101
  * @attr variant - Chip variant: `assist`, `filter`, `input`, or `suggestion`.
87
102
  * @attr selected - Declarative selected state for filter/input chips.
@@ -92,14 +107,20 @@ export interface RCChipRemoveDetail {
92
107
  */
93
108
  export declare class RCChip extends LitElement {
94
109
  static styles: import('lit').CSSResult;
110
+ private static readonly _styledRoots;
111
+ private static _ensureBaseStyles;
95
112
  private _selected;
96
113
  private _defaultSelected;
114
+ private _uncontrolledSelected;
97
115
  private _selectedInitialized;
98
116
  private _$button;
99
- private _buttonObserver;
117
+ private _$input;
118
+ private _$form;
119
+ private _controlObserver;
100
120
  private _disabledOwned;
101
121
  private _pressedOwned;
102
122
  private _slotMicrotaskQueued;
123
+ private _lastChildWarning;
103
124
  /** Chip variant. */
104
125
  variant: RCChipVariant;
105
126
  /** Current selected state. Host writes are silent. */
@@ -114,15 +135,22 @@ export declare class RCChip extends LitElement {
114
135
  readonly: boolean;
115
136
  /** Show a trailing remove affordance. */
116
137
  removable: boolean;
138
+ connectedCallback(): void;
117
139
  disconnectedCallback(): void;
140
+ /** Synchronizes uncontrolled filter state from the direct native input. @internal */
141
+ syncNativeSelection(): void;
118
142
  protected firstUpdated(): void;
119
143
  protected updated(changed: PropertyValues<this>): void;
120
- protected render(): import('lit').TemplateResult<1>;
144
+ protected render(): import('lit-html').TemplateResult<1>;
121
145
  private _handleSlotChange;
122
146
  private _syncSlottedButton;
147
+ private readonly _handleNativeChange;
123
148
  private readonly _handleButtonClick;
124
149
  private _dispatchRemove;
125
150
  private _syncDisabled;
151
+ private _syncCheckedState;
152
+ private _syncCheckedFromNative;
153
+ private readonly _handleFormReset;
126
154
  private _syncPressedState;
127
155
  }
128
156
  export default RCChip;
package/package.json CHANGED
@@ -3,8 +3,8 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.5.0",
7
- "description": "Chip wrapper for native button-based actions, filters, and inputs.",
6
+ "version": "0.7.0",
7
+ "description": "Chip wrapper for native actions, links, filters, and inputs.",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/richardcarls/rc-webcomponents.git",
@@ -44,6 +44,9 @@
44
44
  "test:browser:chrome": "vitest --run --project=chromium",
45
45
  "test:browser:firefox": "vitest --run --project=firefox"
46
46
  },
47
+ "dependencies": {
48
+ "@rcarls/rc-common": "0.7.0"
49
+ },
47
50
  "devDependencies": {
48
51
  "@custom-elements-manifest/analyzer": "0.11.0",
49
52
  "@vitest/browser-playwright": "4.1.5",
@@ -1,267 +0,0 @@
1
- import { css as p, LitElement as u, html as h } from "lit";
2
- import { property as a } from "lit/decorators.js";
3
- const b = p`
4
- :host {
5
- display: inline-grid;
6
- position: relative;
7
- color-scheme: inherit;
8
- vertical-align: middle;
9
- }
10
-
11
- :host([hidden]) {
12
- display: none;
13
- }
14
-
15
- ::slotted(button),
16
- ::slotted(a),
17
- ::slotted([data-rc-chip-label]) {
18
- display: inline-flex;
19
- align-items: center;
20
- justify-content: center;
21
- gap: var(--rc-chip-gap, 0px);
22
- min-block-size: var(--rc-chip-block-size);
23
- padding-block: var(--rc-chip-padding-block, revert);
24
- padding-inline: var(--rc-chip-padding-inline, revert);
25
- border: var(--rc-chip-border, revert);
26
- border-radius: var(--rc-chip-radius, revert);
27
- background: var(--rc-chip-bg, revert);
28
- color: var(--rc-chip-color, revert);
29
- font: var(--rc-chip-font, revert);
30
- text-decoration: var(--rc-chip-text-decoration, revert);
31
- white-space: nowrap;
32
- -webkit-tap-highlight-color: transparent;
33
- }
34
-
35
- :host([selected]) ::slotted(button),
36
- :host([selected]) ::slotted(a),
37
- :host([selected]) ::slotted([data-rc-chip-label]) {
38
- border-color: var(--rc-chip-selected-border-color, revert);
39
- background: var(--rc-chip-selected-bg, revert);
40
- color: var(--rc-chip-selected-color, revert);
41
- }
42
-
43
- :host([disabled]) ::slotted(button) {
44
- opacity: var(--rc-chip-disabled-opacity, revert);
45
- }
46
-
47
- :host(:focus-within) ::slotted(button),
48
- :host(:focus-within) ::slotted(a) {
49
- outline: var(--rc-chip-focus-ring, revert);
50
- outline-offset: var(--rc-chip-focus-ring-offset, revert);
51
- }
52
-
53
- [part='state-layer'] {
54
- pointer-events: none;
55
- position: absolute;
56
- inset: 0;
57
- border-radius: var(--rc-chip-radius, 0);
58
- background: var(--rc-chip-state-layer-color, currentColor);
59
- opacity: 0;
60
- transition: opacity
61
- var(--rc-chip-state-layer-transition-duration, var(--rc-motion-effects-duration-fast, 80ms))
62
- var(--rc-chip-state-layer-transition-easing, var(--rc-motion-effects-easing-fast, ease-out));
63
- }
64
-
65
- :host([selected]) [part='state-layer'] {
66
- background: var(
67
- --rc-chip-selected-state-layer-color,
68
- var(--rc-chip-state-layer-color, currentColor)
69
- );
70
- }
71
-
72
- @media (hover: hover) {
73
- :host(:not([disabled], [readonly]):hover) [part='state-layer'] {
74
- opacity: var(--rc-chip-hover-state-layer-opacity, 0.08);
75
- }
76
- }
77
-
78
- :host(:not([disabled], [readonly]):focus-within) [part='state-layer'] {
79
- opacity: var(--rc-chip-focus-state-layer-opacity, 0.12);
80
- }
81
-
82
- :host(:not([disabled], [readonly]):active) [part='state-layer'] {
83
- opacity: var(--rc-chip-pressed-state-layer-opacity, 0.12);
84
- }
85
-
86
- [part='remove'] {
87
- position: absolute;
88
- pointer-events: none;
89
- inset-block: 0;
90
- inset-inline-end: var(--rc-chip-remove-offset-inline, 0.125rem);
91
- display: none;
92
- place-items: center;
93
- min-inline-size: var(--rc-chip-remove-target-size, 1.5rem);
94
- min-block-size: var(--rc-chip-remove-target-size, 1.5rem);
95
- margin: auto 0;
96
- border: 0;
97
- border-radius: var(--rc-chip-remove-radius, 9999px);
98
- background: transparent;
99
- color: inherit;
100
- font: inherit;
101
- }
102
-
103
- :host([removable]) [part='remove'] {
104
- display: inline-grid;
105
- }
106
-
107
- ::slotted([slot='remove-icon']) {
108
- /* Keep icon-font utility classes from overriding the chip's compact icon size. */
109
- font-size: var(--rc-chip-remove-icon-size, smaller) !important;
110
- }
111
-
112
- :host([removable]) ::slotted(button),
113
- :host([removable]) ::slotted(a),
114
- :host([removable]) ::slotted([data-rc-chip-label]) {
115
- padding-inline-end: var(
116
- --rc-chip-removable-padding-inline-end,
117
- calc(var(--rc-chip-remove-target-size, 1.5rem) - var(--rc-chip-gap, 0px))
118
- );
119
- }
120
-
121
- @media (forced-colors: active) {
122
- [part='state-layer'] {
123
- display: none;
124
- }
125
-
126
- ::slotted(button),
127
- ::slotted(a),
128
- ::slotted([data-rc-chip-label]) {
129
- border-color: ButtonBorder;
130
- background: ButtonFace;
131
- color: ButtonText;
132
- }
133
-
134
- :host([selected]) ::slotted(button),
135
- :host([selected]) ::slotted(a),
136
- :host([selected]) ::slotted([data-rc-chip-label]) {
137
- border-color: Highlight;
138
- background: Highlight;
139
- color: HighlightText;
140
- }
141
- }
142
- `;
143
- var v = Object.defineProperty, f = Object.getOwnPropertyDescriptor, o = (d, e, t, i) => {
144
- for (var s = i > 1 ? void 0 : i ? f(e, t) : e, l = d.length - 1, c; l >= 0; l--)
145
- (c = d[l]) && (s = (i ? c(e, t, s) : c(s)) || s);
146
- return i && s && v(e, t, s), s;
147
- };
148
- const y = /* @__PURE__ */ new Set(["checkbox", "menuitemcheckbox", "menuitemradio", "radio", "switch"]), n = class n extends u {
149
- constructor() {
150
- super(...arguments), this._defaultSelected = !1, this._selectedInitialized = !1, this._$button = null, this._buttonObserver = null, this._disabledOwned = !1, this._pressedOwned = !1, this._slotMicrotaskQueued = !1, this.variant = "assist", this.disabled = !1, this.readonly = !1, this.removable = !1, this._handleButtonClick = () => {
151
- if (this.disabled || this.readonly)
152
- return;
153
- if (this.removable) {
154
- this._dispatchRemove();
155
- return;
156
- }
157
- if (this.variant !== "filter")
158
- return;
159
- const e = this.selected;
160
- this._selected = !this.selected, this._selectedInitialized = !0, this._syncPressedState(), this.requestUpdate("selected", e), this.dispatchEvent(
161
- new CustomEvent("rc-chip-change", {
162
- bubbles: !0,
163
- composed: !0,
164
- detail: { selected: this.selected }
165
- })
166
- );
167
- };
168
- }
169
- get selected() {
170
- return this._selected ?? this._defaultSelected;
171
- }
172
- set selected(e) {
173
- const t = this.selected;
174
- this._selected = e, this._selectedInitialized = !0, this._syncPressedState(), this.requestUpdate("selected", t);
175
- }
176
- get defaultSelected() {
177
- return this._defaultSelected;
178
- }
179
- set defaultSelected(e) {
180
- const t = this._defaultSelected;
181
- this._defaultSelected = e, !this._selectedInitialized && this._selected === void 0 && (this._syncPressedState(), this.requestUpdate("selected", t)), this.requestUpdate("defaultSelected", t);
182
- }
183
- disconnectedCallback() {
184
- this._$button?.removeEventListener("click", this._handleButtonClick), this._buttonObserver?.disconnect(), this._buttonObserver = null, super.disconnectedCallback();
185
- }
186
- firstUpdated() {
187
- this._syncSlottedButton();
188
- }
189
- updated(e) {
190
- (e.has("disabled") || e.has("readonly")) && this._syncDisabled(), (e.has("variant") || e.has("selected") || e.has("readonly") || e.has("removable")) && this._syncPressedState();
191
- }
192
- render() {
193
- return h`
194
- <slot @slotchange=${this._handleSlotChange}></slot>
195
- <span part="state-layer" aria-hidden="true"></span>
196
- ${this.removable ? h`
197
- <span part="remove" aria-hidden="true">
198
- <slot name="remove-icon">×</slot>
199
- </span>
200
- ` : ""}
201
- `;
202
- }
203
- _handleSlotChange() {
204
- this._slotMicrotaskQueued || (this._slotMicrotaskQueued = !0, queueMicrotask(() => {
205
- this._slotMicrotaskQueued = !1, this.isConnected && this._syncSlottedButton();
206
- }));
207
- }
208
- _syncSlottedButton() {
209
- const e = this.querySelector(":scope > button");
210
- if (!e && this.readonly, e === this._$button) {
211
- this._syncDisabled(), this._syncPressedState();
212
- return;
213
- }
214
- this._$button?.removeEventListener("click", this._handleButtonClick), this._buttonObserver?.disconnect(), this._buttonObserver = null, this._$button = e, this._disabledOwned = !1, this._pressedOwned = !1, e && (e.addEventListener("click", this._handleButtonClick), this._buttonObserver = new MutationObserver(() => {
215
- this._syncDisabled(), this._syncPressedState();
216
- }), this._buttonObserver.observe(e, {
217
- attributeFilter: ["aria-pressed", "role", "disabled"]
218
- })), this._syncDisabled(), this._syncPressedState();
219
- }
220
- _dispatchRemove() {
221
- this.dispatchEvent(
222
- new CustomEvent("rc-chip-remove", {
223
- bubbles: !0,
224
- composed: !0,
225
- detail: { chip: this }
226
- })
227
- );
228
- }
229
- _syncDisabled() {
230
- const e = this._$button;
231
- e && (this.disabled || this.readonly ? (e.disabled || (this._disabledOwned = !0), e.disabled = !0) : this._disabledOwned && (e.disabled = !1, this._disabledOwned = !1));
232
- }
233
- _syncPressedState() {
234
- const e = this._$button;
235
- if (!e)
236
- return;
237
- const t = e.getAttribute("role"), i = e.hasAttribute("aria-pressed") && !this._pressedOwned || (t ? y.has(t) : !1);
238
- if (!this.readonly && !this.removable && this.variant === "filter" && !i) {
239
- const s = this.selected ? "true" : "false";
240
- e.getAttribute("aria-pressed") !== s && e.setAttribute("aria-pressed", s), this._pressedOwned = !0;
241
- } else this._pressedOwned && (e.removeAttribute("aria-pressed"), this._pressedOwned = !1);
242
- }
243
- };
244
- n.styles = b;
245
- let r = n;
246
- o([
247
- a({ type: String, reflect: !0 })
248
- ], r.prototype, "variant", 2);
249
- o([
250
- a({ type: Boolean, reflect: !0 })
251
- ], r.prototype, "selected", 1);
252
- o([
253
- a({ type: Boolean, attribute: "default-selected" })
254
- ], r.prototype, "defaultSelected", 1);
255
- o([
256
- a({ type: Boolean, reflect: !0 })
257
- ], r.prototype, "disabled", 2);
258
- o([
259
- a({ type: Boolean, reflect: !0 })
260
- ], r.prototype, "readonly", 2);
261
- o([
262
- a({ type: Boolean, reflect: !0 })
263
- ], r.prototype, "removable", 2);
264
- export {
265
- r as R
266
- };
267
- //# sourceMappingURL=rc-chip-Do50B5yx.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rc-chip-Do50B5yx.js","sources":["../src/rc-chip.styles.ts","../src/rc-chip.ts"],"sourcesContent":["import { css } from 'lit';\n\nexport const chipStyles = css`\n :host {\n display: inline-grid;\n position: relative;\n color-scheme: inherit;\n vertical-align: middle;\n }\n\n :host([hidden]) {\n display: none;\n }\n\n ::slotted(button),\n ::slotted(a),\n ::slotted([data-rc-chip-label]) {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: var(--rc-chip-gap, 0px);\n min-block-size: var(--rc-chip-block-size);\n padding-block: var(--rc-chip-padding-block, revert);\n padding-inline: var(--rc-chip-padding-inline, revert);\n border: var(--rc-chip-border, revert);\n border-radius: var(--rc-chip-radius, revert);\n background: var(--rc-chip-bg, revert);\n color: var(--rc-chip-color, revert);\n font: var(--rc-chip-font, revert);\n text-decoration: var(--rc-chip-text-decoration, revert);\n white-space: nowrap;\n -webkit-tap-highlight-color: transparent;\n }\n\n :host([selected]) ::slotted(button),\n :host([selected]) ::slotted(a),\n :host([selected]) ::slotted([data-rc-chip-label]) {\n border-color: var(--rc-chip-selected-border-color, revert);\n background: var(--rc-chip-selected-bg, revert);\n color: var(--rc-chip-selected-color, revert);\n }\n\n :host([disabled]) ::slotted(button) {\n opacity: var(--rc-chip-disabled-opacity, revert);\n }\n\n :host(:focus-within) ::slotted(button),\n :host(:focus-within) ::slotted(a) {\n outline: var(--rc-chip-focus-ring, revert);\n outline-offset: var(--rc-chip-focus-ring-offset, revert);\n }\n\n [part='state-layer'] {\n pointer-events: none;\n position: absolute;\n inset: 0;\n border-radius: var(--rc-chip-radius, 0);\n background: var(--rc-chip-state-layer-color, currentColor);\n opacity: 0;\n transition: opacity\n var(--rc-chip-state-layer-transition-duration, var(--rc-motion-effects-duration-fast, 80ms))\n var(--rc-chip-state-layer-transition-easing, var(--rc-motion-effects-easing-fast, ease-out));\n }\n\n :host([selected]) [part='state-layer'] {\n background: var(\n --rc-chip-selected-state-layer-color,\n var(--rc-chip-state-layer-color, currentColor)\n );\n }\n\n @media (hover: hover) {\n :host(:not([disabled], [readonly]):hover) [part='state-layer'] {\n opacity: var(--rc-chip-hover-state-layer-opacity, 0.08);\n }\n }\n\n :host(:not([disabled], [readonly]):focus-within) [part='state-layer'] {\n opacity: var(--rc-chip-focus-state-layer-opacity, 0.12);\n }\n\n :host(:not([disabled], [readonly]):active) [part='state-layer'] {\n opacity: var(--rc-chip-pressed-state-layer-opacity, 0.12);\n }\n\n [part='remove'] {\n position: absolute;\n pointer-events: none;\n inset-block: 0;\n inset-inline-end: var(--rc-chip-remove-offset-inline, 0.125rem);\n display: none;\n place-items: center;\n min-inline-size: var(--rc-chip-remove-target-size, 1.5rem);\n min-block-size: var(--rc-chip-remove-target-size, 1.5rem);\n margin: auto 0;\n border: 0;\n border-radius: var(--rc-chip-remove-radius, 9999px);\n background: transparent;\n color: inherit;\n font: inherit;\n }\n\n :host([removable]) [part='remove'] {\n display: inline-grid;\n }\n\n ::slotted([slot='remove-icon']) {\n /* Keep icon-font utility classes from overriding the chip's compact icon size. */\n font-size: var(--rc-chip-remove-icon-size, smaller) !important;\n }\n\n :host([removable]) ::slotted(button),\n :host([removable]) ::slotted(a),\n :host([removable]) ::slotted([data-rc-chip-label]) {\n padding-inline-end: var(\n --rc-chip-removable-padding-inline-end,\n calc(var(--rc-chip-remove-target-size, 1.5rem) - var(--rc-chip-gap, 0px))\n );\n }\n\n @media (forced-colors: active) {\n [part='state-layer'] {\n display: none;\n }\n\n ::slotted(button),\n ::slotted(a),\n ::slotted([data-rc-chip-label]) {\n border-color: ButtonBorder;\n background: ButtonFace;\n color: ButtonText;\n }\n\n :host([selected]) ::slotted(button),\n :host([selected]) ::slotted(a),\n :host([selected]) ::slotted([data-rc-chip-label]) {\n border-color: Highlight;\n background: Highlight;\n color: HighlightText;\n }\n }\n`;\n\nexport default chipStyles;\n","import { LitElement, html } from 'lit';\nimport type { PropertyValues } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport chipStyles from './rc-chip.styles.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'rc-chip': RCChip;\n }\n\n interface HTMLElementEventMap {\n 'rc-chip-change': CustomEvent<RCChipChangeDetail>;\n 'rc-chip-remove': CustomEvent<RCChipRemoveDetail>;\n }\n}\n\nconst TOGGLE_ROLES = new Set(['checkbox', 'menuitemcheckbox', 'menuitemradio', 'radio', 'switch']);\n\n/** Supported chip variants. */\nexport type RCChipVariant = 'assist' | 'filter' | 'input' | 'suggestion';\n\n/** Detail payload for `rc-chip-change`. */\nexport interface RCChipChangeDetail {\n /** Selected state after user interaction. */\n selected: boolean;\n}\n\n/** Detail payload for `rc-chip-remove`. */\nexport interface RCChipRemoveDetail {\n /** The host chip requesting removal. */\n chip: RCChip;\n}\n\n/**\n * Chip wrapper that preserves a direct native `<button>` child for interactive\n * chips and accepts a direct `[data-rc-chip-label]` child for read-only chips.\n *\n * @see {@link https://richardcarls.github.io/rc-webcomponents/components/rc-chip rc-chip docs}\n * @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/button/ WAI-ARIA button pattern}\n *\n * @slot - A direct native `<button>` child, or `[data-rc-chip-label]` when `readonly`.\n * @slot remove-icon - Optional presentational remove icon.\n *\n * @fires rc-chip-change - Fired when a user toggles a filter chip.\n * @fires rc-chip-remove - Fired when a user activates a removable chip's native button.\n *\n * @csspart state-layer - Overlay layer for hover, focus, pressed, ripple, or design-system effects.\n * @csspart remove - Presentational trailing remove indicator.\n *\n * @cssprop [--rc-chip-gap=0px] - Gap between the slotted button/anchor/label's content.\n * @cssprop [--rc-chip-block-size] - Minimum chip block size (defers to native button/anchor\n * sizing when unset).\n * @cssprop [--rc-chip-padding-block] - Block-axis padding of the slotted button, anchor, or\n * label (defers to native padding when unset).\n * @cssprop [--rc-chip-padding-inline] - Inline-axis padding of the slotted button, anchor, or\n * label (defers to native padding when unset).\n * @cssprop [--rc-chip-border] - Border of the slotted button, anchor, or label (defers to\n * native border when unset).\n * @cssprop [--rc-chip-radius] - Border radius of the slotted button/anchor/label and the\n * state-layer overlay (defers to native border-radius when unset; the state-layer overlay\n * falls back to 0).\n * @cssprop [--rc-chip-bg] - Background of the slotted button, anchor, or label (defers to\n * native background when unset).\n * @cssprop [--rc-chip-color] - Text color of the slotted button, anchor, or label (defers to\n * native color when unset).\n * @cssprop [--rc-chip-font] - Font shorthand for the slotted button, anchor, or label (defers\n * to native font when unset).\n * @cssprop [--rc-chip-text-decoration] - Text decoration for the slotted anchor (defers to\n * native text-decoration when unset).\n * @cssprop [--rc-chip-selected-border-color] - Border color when `selected` (defers to native\n * styling when unset).\n * @cssprop [--rc-chip-selected-bg] - Background when `selected` (defers to native styling when\n * unset).\n * @cssprop [--rc-chip-selected-color] - Text color when `selected` (defers to native styling\n * when unset).\n * @cssprop [--rc-chip-disabled-opacity] - Opacity of the slotted button when `disabled` (defers\n * to native disabled styling when unset).\n * @cssprop [--rc-chip-focus-ring] - Outline shown while focus-within (defers to native focus\n * styling when unset).\n * @cssprop [--rc-chip-focus-ring-offset] - Outline offset while focus-within (defers to native\n * focus styling when unset).\n * @cssprop [--rc-chip-state-layer-color=currentColor] - Hover/focus/pressed state-layer color.\n * @cssprop [--rc-chip-selected-state-layer-color=var(--rc-chip-state-layer-color, currentColor)] - Selected chip state-layer color.\n * @cssprop [--rc-chip-hover-state-layer-opacity=0.08] - Hover state-layer opacity.\n * @cssprop [--rc-chip-focus-state-layer-opacity=0.12] - Focus state-layer opacity.\n * @cssprop [--rc-chip-pressed-state-layer-opacity=0.12] - Pressed state-layer opacity.\n * @cssprop [--rc-chip-state-layer-transition-duration=var(--rc-motion-effects-duration-fast,80ms)] - State-layer effects duration.\n * @cssprop [--rc-chip-state-layer-transition-easing=var(--rc-motion-effects-easing-fast,ease-out)] - State-layer effects easing.\n * @cssprop [--rc-chip-remove-offset-inline=0.125rem] - Inline offset of the remove indicator\n * from the chip edge.\n * @cssprop [--rc-chip-remove-target-size=1.5rem] - Minimum inline and block size of the remove\n * indicator's hit target.\n * @cssprop [--rc-chip-remove-radius=9999px] - Border radius of the remove indicator.\n * @cssprop [--rc-chip-remove-icon-size=smaller] - Font size for a slotted remove icon.\n * @cssprop [--rc-chip-removable-padding-inline-end=calc(var(--rc-chip-remove-target-size, 1.5rem) - var(--rc-chip-gap, 0px))] - Override for removable chip content end padding.\n *\n * @attr variant - Chip variant: `assist`, `filter`, `input`, or `suggestion`.\n * @attr selected - Declarative selected state for filter/input chips.\n * @attr default-selected - Initial selected state for uncontrolled usage.\n * @attr disabled - Mirrors disabled state to the native child button.\n * @attr readonly - Marks the chip as non-interactive display content.\n * @attr removable - Shows a trailing remove affordance.\n */\nexport class RCChip extends LitElement {\n static override styles = chipStyles;\n\n private _selected: boolean | undefined;\n private _defaultSelected = false;\n private _selectedInitialized = false;\n private _$button: HTMLButtonElement | null = null;\n private _buttonObserver: MutationObserver | null = null;\n private _disabledOwned = false;\n private _pressedOwned = false;\n private _slotMicrotaskQueued = false;\n\n /** Chip variant. */\n @property({ type: String, reflect: true })\n variant: RCChipVariant = 'assist';\n\n /** Current selected state. Host writes are silent. */\n @property({ type: Boolean, reflect: true })\n get selected(): boolean {\n return this._selected ?? this._defaultSelected;\n }\n\n set selected(value: boolean | undefined) {\n const oldValue = this.selected;\n\n this._selected = value;\n this._selectedInitialized = true;\n this._syncPressedState();\n this.requestUpdate('selected', oldValue);\n }\n\n /** Initial selected state for uncontrolled usage. */\n @property({ type: Boolean, attribute: 'default-selected' })\n get defaultSelected(): boolean {\n return this._defaultSelected;\n }\n\n set defaultSelected(value: boolean) {\n const oldValue = this._defaultSelected;\n\n this._defaultSelected = value;\n\n if (!this._selectedInitialized && this._selected === undefined) {\n this._syncPressedState();\n this.requestUpdate('selected', oldValue);\n }\n\n this.requestUpdate('defaultSelected', oldValue);\n }\n\n /** Mirror disabled state to the native child button. */\n @property({ type: Boolean, reflect: true })\n disabled = false;\n\n /** Mark this chip as non-interactive display content. */\n @property({ type: Boolean, reflect: true })\n readonly = false;\n\n /** Show a trailing remove affordance. */\n @property({ type: Boolean, reflect: true })\n removable = false;\n\n override disconnectedCallback(): void {\n this._$button?.removeEventListener('click', this._handleButtonClick);\n this._buttonObserver?.disconnect();\n this._buttonObserver = null;\n super.disconnectedCallback();\n }\n\n protected override firstUpdated(): void {\n this._syncSlottedButton();\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n if (changed.has('disabled') || changed.has('readonly')) {\n this._syncDisabled();\n }\n\n if (\n changed.has('variant') ||\n changed.has('selected') ||\n changed.has('readonly') ||\n changed.has('removable')\n ) {\n this._syncPressedState();\n }\n }\n\n protected override render() {\n return html`\n <slot @slotchange=${this._handleSlotChange}></slot>\n <span part=\"state-layer\" aria-hidden=\"true\"></span>\n ${this.removable\n ? html`\n <span part=\"remove\" aria-hidden=\"true\">\n <slot name=\"remove-icon\">×</slot>\n </span>\n `\n : ''}\n `;\n }\n\n private _handleSlotChange(): void {\n if (this._slotMicrotaskQueued) {\n return;\n }\n\n this._slotMicrotaskQueued = true;\n\n queueMicrotask(() => {\n this._slotMicrotaskQueued = false;\n\n if (this.isConnected) {\n this._syncSlottedButton();\n }\n });\n }\n\n private _syncSlottedButton(): void {\n const $nextButton = this.querySelector<HTMLButtonElement>(':scope > button');\n\n if (!$nextButton && !this.readonly && import.meta.env.DEV) {\n console.warn(\n '[rc-chip] No direct child <button> found. Place a native <button> inside <rc-chip>, or use readonly with a [data-rc-chip-label] child.',\n this,\n );\n }\n\n if ($nextButton === this._$button) {\n this._syncDisabled();\n this._syncPressedState();\n\n return;\n }\n\n this._$button?.removeEventListener('click', this._handleButtonClick);\n this._buttonObserver?.disconnect();\n this._buttonObserver = null;\n this._$button = $nextButton;\n this._disabledOwned = false;\n this._pressedOwned = false;\n\n if ($nextButton) {\n $nextButton.addEventListener('click', this._handleButtonClick);\n\n this._buttonObserver = new MutationObserver(() => {\n this._syncDisabled();\n this._syncPressedState();\n });\n\n this._buttonObserver.observe($nextButton, {\n attributeFilter: ['aria-pressed', 'role', 'disabled'],\n });\n }\n\n this._syncDisabled();\n this._syncPressedState();\n }\n\n private readonly _handleButtonClick = (): void => {\n if (this.disabled || this.readonly) {\n return;\n }\n\n if (this.removable) {\n this._dispatchRemove();\n\n return;\n }\n\n if (this.variant !== 'filter') {\n return;\n }\n\n const oldValue = this.selected;\n\n this._selected = !this.selected;\n this._selectedInitialized = true;\n this._syncPressedState();\n this.requestUpdate('selected', oldValue);\n\n this.dispatchEvent(\n new CustomEvent<RCChipChangeDetail>('rc-chip-change', {\n bubbles: true,\n composed: true,\n detail: { selected: this.selected },\n }),\n );\n };\n\n private _dispatchRemove(): void {\n this.dispatchEvent(\n new CustomEvent<RCChipRemoveDetail>('rc-chip-remove', {\n bubbles: true,\n composed: true,\n detail: { chip: this },\n }),\n );\n }\n\n private _syncDisabled(): void {\n const $button = this._$button;\n\n if (!$button) {\n return;\n }\n\n if (this.disabled || this.readonly) {\n if (!$button.disabled) {\n this._disabledOwned = true;\n }\n\n $button.disabled = true;\n } else if (this._disabledOwned) {\n $button.disabled = false;\n this._disabledOwned = false;\n }\n }\n\n private _syncPressedState(): void {\n const $button = this._$button;\n\n if (!$button) {\n return;\n }\n\n const role = $button.getAttribute('role');\n const authorOwnsState =\n ($button.hasAttribute('aria-pressed') && !this._pressedOwned) ||\n (role ? TOGGLE_ROLES.has(role) : false);\n\n if (!this.readonly && !this.removable && this.variant === 'filter' && !authorOwnsState) {\n const pressed = this.selected ? 'true' : 'false';\n\n if ($button.getAttribute('aria-pressed') !== pressed) {\n $button.setAttribute('aria-pressed', pressed);\n }\n\n this._pressedOwned = true;\n } else if (this._pressedOwned) {\n $button.removeAttribute('aria-pressed');\n this._pressedOwned = false;\n }\n }\n}\n\nexport default RCChip;\n"],"names":["chipStyles","css","TOGGLE_ROLES","_RCChip","LitElement","oldValue","value","changed","html","$nextButton","$button","role","authorOwnsState","pressed","RCChip","__decorateClass","property"],"mappings":";;AAEO,MAAMA,IAAaC;AA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