@adobe/spectrum-wc-core 2.0.0-beta.2 → 2.0.0-beta.3
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 +75 -9
- package/dist/components/accordion/Accordion.base.js +28 -22
- package/dist/components/accordion/Accordion.base.js.map +1 -1
- package/dist/components/accordion/AccordionItem.base.d.ts +16 -6
- package/dist/components/accordion/AccordionItem.base.js +6 -3
- package/dist/components/accordion/AccordionItem.base.js.map +1 -1
- package/dist/components/action-group/ActionGroup.base.d.ts +108 -0
- package/dist/components/action-group/ActionGroup.base.js +53 -0
- package/dist/components/action-group/ActionGroup.base.js.map +1 -0
- package/dist/components/action-group/ActionGroup.types.d.ts +17 -0
- package/dist/components/action-group/ActionGroup.types.js +12 -0
- package/dist/components/action-group/ActionGroup.types.js.map +1 -0
- package/dist/components/action-group/index.d.ts +13 -0
- package/dist/components/action-group/index.js +3 -0
- package/dist/components/alert-banner/AlertBanner.base.js +11 -10
- package/dist/components/alert-banner/AlertBanner.base.js.map +1 -1
- package/dist/components/asset/Asset.base.d.ts +1 -1
- package/dist/components/asset/Asset.base.js +14 -8
- package/dist/components/asset/Asset.base.js.map +1 -1
- package/dist/components/avatar/Avatar.base.js +18 -22
- package/dist/components/avatar/Avatar.base.js.map +1 -1
- package/dist/components/badge/Badge.base.d.ts +24 -8
- package/dist/components/badge/Badge.base.js +22 -17
- package/dist/components/badge/Badge.base.js.map +1 -1
- package/dist/components/button/Button.base.d.ts +20 -10
- package/dist/components/button/Button.base.js +17 -12
- package/dist/components/button/Button.base.js.map +1 -1
- package/dist/components/button-group/ButtonGroup.base.js +19 -12
- package/dist/components/button-group/ButtonGroup.base.js.map +1 -1
- package/dist/components/card/Card.base.d.ts +95 -46
- package/dist/components/card/Card.base.js +71 -23
- package/dist/components/card/Card.base.js.map +1 -1
- package/dist/components/card/Card.types.d.ts +1 -0
- package/dist/components/card/Card.types.js +2 -2
- package/dist/components/card/Card.types.js.map +1 -1
- package/dist/components/card/index.js +3 -3
- package/dist/components/divider/Divider.base.js +13 -8
- package/dist/components/divider/Divider.base.js.map +1 -1
- package/dist/components/dropzone/Dropzone.base.d.ts +74 -0
- package/dist/components/dropzone/Dropzone.base.js +82 -0
- package/dist/components/dropzone/Dropzone.base.js.map +1 -0
- package/dist/components/dropzone/Dropzone.types.d.ts +43 -0
- package/dist/components/dropzone/Dropzone.types.js +15 -0
- package/dist/components/dropzone/Dropzone.types.js.map +1 -0
- package/dist/components/dropzone/index.d.ts +13 -0
- package/dist/components/dropzone/index.js +3 -0
- package/dist/components/icon/Icon.base.d.ts +11 -7
- package/dist/components/icon/Icon.base.js +13 -20
- package/dist/components/icon/Icon.base.js.map +1 -1
- package/dist/components/illustrated-message/IllustratedMessage.base.d.ts +22 -8
- package/dist/components/illustrated-message/IllustratedMessage.base.js +33 -20
- package/dist/components/illustrated-message/IllustratedMessage.base.js.map +1 -1
- package/dist/components/infield-button/InfieldButton.base.d.ts +28 -0
- package/dist/components/infield-button/InfieldButton.base.js +22 -0
- package/dist/components/infield-button/InfieldButton.base.js.map +1 -0
- package/dist/components/infield-button/InfieldButton.types.d.ts +13 -0
- package/dist/components/infield-button/InfieldButton.types.js +11 -0
- package/dist/components/infield-button/InfieldButton.types.js.map +1 -0
- package/dist/components/infield-button/index.d.ts +13 -0
- package/dist/components/infield-button/index.js +3 -0
- package/dist/components/meter/Meter.base.js +11 -9
- package/dist/components/meter/Meter.base.js.map +1 -1
- package/dist/components/popover/Popover.base.js +46 -42
- package/dist/components/popover/Popover.base.js.map +1 -1
- package/dist/components/progress-circle/ProgressCircle.base.d.ts +0 -1
- package/dist/components/progress-circle/ProgressCircle.base.js +26 -22
- package/dist/components/progress-circle/ProgressCircle.base.js.map +1 -1
- package/dist/components/status-light/StatusLight.base.d.ts +1 -1
- package/dist/components/status-light/StatusLight.base.js +12 -9
- package/dist/components/status-light/StatusLight.base.js.map +1 -1
- package/dist/components/tabs/Tabs.base.js +44 -32
- package/dist/components/tabs/Tabs.base.js.map +1 -1
- package/dist/components/tooltip/Tooltip.base.js +57 -22
- package/dist/components/tooltip/Tooltip.base.js.map +1 -1
- package/dist/controllers/color-controller/src/color-controller.js +45 -44
- package/dist/controllers/color-controller/src/color-controller.js.map +1 -1
- package/dist/controllers/drag-and-drop-controller/index.d.ts +12 -0
- package/dist/controllers/drag-and-drop-controller/index.js +2 -0
- package/dist/controllers/drag-and-drop-controller/src/drag-and-drop-controller.d.ts +68 -0
- package/dist/controllers/drag-and-drop-controller/src/drag-and-drop-controller.js +56 -0
- package/dist/controllers/drag-and-drop-controller/src/drag-and-drop-controller.js.map +1 -0
- package/dist/controllers/index.d.ts +4 -1
- package/dist/controllers/index.js +14 -11
- package/dist/controllers/page-scroll-lock-controller/index.d.ts +12 -0
- package/dist/controllers/page-scroll-lock-controller/index.js +2 -0
- package/dist/controllers/{page-scroll-lock.js → page-scroll-lock-controller/src/page-scroll-lock.js} +1 -1
- package/dist/controllers/page-scroll-lock-controller/src/page-scroll-lock.js.map +1 -0
- package/dist/controllers/slot-presence-controller/index.d.ts +12 -0
- package/dist/controllers/slot-presence-controller/index.js +2 -0
- package/dist/controllers/slot-presence-controller/src/slot-presence-controller.d.ts +57 -0
- package/dist/controllers/slot-presence-controller/src/slot-presence-controller.js +44 -0
- package/dist/controllers/slot-presence-controller/src/slot-presence-controller.js.map +1 -0
- package/dist/controllers/slot-text-controller/index.d.ts +12 -0
- package/dist/controllers/slot-text-controller/index.js +2 -0
- package/dist/controllers/slot-text-controller/src/slot-text-controller.d.ts +92 -0
- package/dist/controllers/slot-text-controller/src/slot-text-controller.js +53 -0
- package/dist/controllers/slot-text-controller/src/slot-text-controller.js.map +1 -0
- package/dist/element/index.d.ts +1 -1
- package/dist/element/index.js +2 -2
- package/dist/element/spectrum-element.d.ts +58 -15
- package/dist/element/spectrum-element.js +55 -36
- package/dist/element/spectrum-element.js.map +1 -1
- package/dist/element/version.d.ts +2 -2
- package/dist/element/version.js +1 -1
- package/dist/element/version.js.map +1 -1
- package/dist/mixins/index.d.ts +0 -2
- package/dist/mixins/index.js +4 -6
- package/dist/mixins/linear-progress-mixin.d.ts +1 -2
- package/dist/mixins/linear-progress-mixin.js +35 -34
- package/dist/mixins/linear-progress-mixin.js.map +1 -1
- package/dist/mixins/pending-mixin.js +12 -11
- package/dist/mixins/pending-mixin.js.map +1 -1
- package/dist/mixins/sized-mixin.d.ts +28 -0
- package/dist/mixins/sized-mixin.js +6 -6
- package/dist/mixins/sized-mixin.js.map +1 -1
- package/dist/utils/dev-validation.d.ts +88 -0
- package/dist/utils/dev-validation.js +33 -0
- package/dist/utils/dev-validation.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +12 -10
- package/dist/utils/is-focus-visible-in-tree.d.ts +33 -0
- package/dist/utils/is-focus-visible-in-tree.js +11 -0
- package/dist/utils/is-focus-visible-in-tree.js.map +1 -0
- package/package.json +68 -15
- package/dist/_virtual/_@oxc-project_runtime@0.124.0/helpers/defineProperty.js +0 -12
- package/dist/_virtual/_@oxc-project_runtime@0.124.0/helpers/toPrimitive.js +0 -14
- package/dist/_virtual/_@oxc-project_runtime@0.124.0/helpers/toPropertyKey.js +0 -9
- package/dist/_virtual/_@oxc-project_runtime@0.124.0/helpers/typeof.js +0 -11
- package/dist/controllers/page-scroll-lock.js.map +0 -1
- package/dist/mixins/observe-slot-presence.d.ts +0 -12
- package/dist/mixins/observe-slot-presence.js +0 -40
- package/dist/mixins/observe-slot-presence.js.map +0 -1
- package/dist/mixins/observe-slot-text.d.ts +0 -11
- package/dist/mixins/observe-slot-text.js +0 -60
- package/dist/mixins/observe-slot-text.js.map +0 -1
- /package/dist/controllers/{page-scroll-lock.d.ts → page-scroll-lock-controller/src/page-scroll-lock.d.ts} +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ReactiveElement } from 'lit';
|
|
2
|
-
import { SlotPresenceObservingInterface } from './observe-slot-presence.js';
|
|
3
2
|
type Constructor<T = Record<string, unknown>> = {
|
|
4
3
|
new (...args: any[]): T;
|
|
5
4
|
prototype: T;
|
|
@@ -10,7 +9,7 @@ export declare const LINEAR_PROGRESS_STATIC_COLORS: readonly ["white", "black"];
|
|
|
10
9
|
export type LinearProgressStaticColor = (typeof LINEAR_PROGRESS_STATIC_COLORS)[number];
|
|
11
10
|
export declare const LINEAR_PROGRESS_LABEL_POSITIONS: readonly ["top", "side"];
|
|
12
11
|
export type LinearProgressLabelPosition = (typeof LINEAR_PROGRESS_LABEL_POSITIONS)[number];
|
|
13
|
-
export interface LinearProgressInterface
|
|
12
|
+
export interface LinearProgressInterface {
|
|
14
13
|
value: number;
|
|
15
14
|
minValue: number;
|
|
16
15
|
maxValue: number;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { __decorate as e } from "../_virtual/_@oxc-project_runtime@0.124.0/helpers/decorate.js";
|
|
2
2
|
import { LanguageResolutionController as t } from "../controllers/language-resolution.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { SlotPresenceController as n } from "../controllers/slot-presence-controller/src/slot-presence-controller.js";
|
|
4
|
+
import { isDebug as r, validateEnum as i, warnIf as a } from "../utils/dev-validation.js";
|
|
5
|
+
import "../utils/index.js";
|
|
6
|
+
import { property as o } from "lit/decorators.js";
|
|
5
7
|
//#region mixins/linear-progress-mixin.ts
|
|
6
|
-
var
|
|
8
|
+
var s = [
|
|
7
9
|
"s",
|
|
8
10
|
"m",
|
|
9
11
|
"l",
|
|
10
12
|
"xl"
|
|
11
|
-
],
|
|
12
|
-
function
|
|
13
|
-
class
|
|
13
|
+
], c = ["white", "black"], l = ["top", "side"], u = { style: "percent" }, d = "[slot=\"label\"]", f = "[slot=\"description\"]", p = 0;
|
|
14
|
+
function m(s) {
|
|
15
|
+
class m extends s {
|
|
14
16
|
constructor(...e) {
|
|
15
|
-
super(...e), this.value = 0, this.minValue = 0, this.maxValue = 100, this.accessibleLabel = "", this.labelPosition = "top", this.languageResolver = new t(this), this._instanceId = ++
|
|
17
|
+
super(...e), this.slotPresence = new n(this, [d, f]), this.value = 0, this.minValue = 0, this.maxValue = 100, this.accessibleLabel = "", this.labelPosition = "top", this.languageResolver = new t(this), this._instanceId = ++p;
|
|
16
18
|
}
|
|
17
19
|
get docsHref() {
|
|
18
20
|
return `https://spectrum-web-components.adobe.com/?path=/docs/components-${this.localName.replace(/^swc-/, "")}--docs`;
|
|
@@ -24,10 +26,10 @@ function d(i) {
|
|
|
24
26
|
return `swc-linear-progress-description-${this._instanceId}`;
|
|
25
27
|
}
|
|
26
28
|
get hasLabelSlotContent() {
|
|
27
|
-
return this.
|
|
29
|
+
return this.slotPresence.getPresence(d);
|
|
28
30
|
}
|
|
29
31
|
get hasDescriptionSlotContent() {
|
|
30
|
-
return this.
|
|
32
|
+
return this.slotPresence.getPresence(f);
|
|
31
33
|
}
|
|
32
34
|
get sanitizedMin() {
|
|
33
35
|
let e = Number.isFinite(this.minValue) ? this.minValue : 0, t = Number.isFinite(this.maxValue) ? this.maxValue : 100;
|
|
@@ -49,7 +51,7 @@ function d(i) {
|
|
|
49
51
|
}
|
|
50
52
|
get formattedValue() {
|
|
51
53
|
if (this.valueLabel) return this.valueLabel;
|
|
52
|
-
let e = this.sanitizedMin, t = this.sanitizedMax, n = this.formatOptions && typeof this.formatOptions == "object" && Object.keys(this.formatOptions).length > 0 ? this.formatOptions :
|
|
54
|
+
let e = this.sanitizedMin, t = this.sanitizedMax, n = this.formatOptions && typeof this.formatOptions == "object" && Object.keys(this.formatOptions).length > 0 ? this.formatOptions : u, r = new Intl.NumberFormat(this.languageResolver.language, n);
|
|
53
55
|
if (n.style === "percent") {
|
|
54
56
|
let n = t === e ? 0 : (this.clampedValue - e) / (t - e);
|
|
55
57
|
return r.format(n);
|
|
@@ -57,58 +59,57 @@ function d(i) {
|
|
|
57
59
|
return r.format(this.clampedValue);
|
|
58
60
|
}
|
|
59
61
|
updated(e) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
super.updated(e), r() && this.warnMissingAccessibleName(), r() && (e.has("value") || e.has("minValue") || e.has("maxValue")) && this.warnValueOutOfRange(), e.has("labelPosition") && i(this, {
|
|
63
|
+
prop: "label-position",
|
|
64
|
+
value: this.labelPosition,
|
|
65
|
+
valid: l,
|
|
66
|
+
url: "https://spectrum-web-components.adobe.com/?path=/docs/components-meter--docs"
|
|
67
|
+
}), e.has("staticColor") && this.staticColor !== void 0 && i(this, {
|
|
68
|
+
prop: "static-color",
|
|
69
|
+
value: this.staticColor,
|
|
70
|
+
valid: c,
|
|
71
|
+
url: "https://spectrum-web-components.adobe.com/?path=/docs/components-meter--docs"
|
|
72
|
+
});
|
|
62
73
|
}
|
|
63
74
|
warnValueOutOfRange() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (!Number.isFinite(t) || t >= n && t <= r) {
|
|
67
|
-
this._hasWarnedValueOutOfRange = !1;
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
this._hasWarnedValueOutOfRange || (this._hasWarnedValueOutOfRange = !0, (e = window.__swc) == null || e.warn(this, `<${this.localName}> "value" (${t}) is outside the [${n}, ${r}] range and was clamped to ${this.clampedValue}.`, this.docsHref, { issues: ["set \"value\" within the \"min-value\" and \"max-value\" range, or", "adjust \"min-value\"/\"max-value\" so the range includes the value."] }));
|
|
75
|
+
let e = this.value, t = this.sanitizedMin, n = this.sanitizedMax;
|
|
76
|
+
!Number.isFinite(e) || e >= t && e <= n || a(this, !0, `<${this.localName}> "value" (${e}) is outside the [${t}, ${n}] range and was clamped to ${this.clampedValue}.`, this.docsHref, { issues: ["set \"value\" within the \"min-value\" and \"max-value\" range, or", "adjust \"min-value\"/\"max-value\" so the range includes the value."] });
|
|
71
77
|
}
|
|
72
78
|
warnMissingAccessibleName() {
|
|
73
|
-
|
|
74
|
-
if (this.hasLabelSlotContent || this.accessibleLabel) {
|
|
75
|
-
this._hasWarnedNoAccessibleName = !1;
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
this._hasWarnedNoAccessibleName = !0, (e = window.__swc) == null || e.warn(this, `<${this.localName}> requires an accessible name.`, this.docsHref, {
|
|
79
|
+
this.hasLabelSlotContent || this.accessibleLabel || a(this, !0, `<${this.localName}> requires an accessible name.`, this.docsHref, {
|
|
79
80
|
type: "accessibility",
|
|
80
81
|
issues: ["add visible label content via the \"label\" named slot, or", "set the \"accessible-label\" attribute (or \"accessibleLabel\" property) when there is no visible label."]
|
|
81
82
|
});
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
|
-
return e([
|
|
85
|
+
return e([o({
|
|
85
86
|
type: Number,
|
|
86
87
|
reflect: !0
|
|
87
|
-
})],
|
|
88
|
+
})], m.prototype, "value", void 0), e([o({
|
|
88
89
|
type: Number,
|
|
89
90
|
reflect: !0,
|
|
90
91
|
attribute: "min-value"
|
|
91
|
-
})],
|
|
92
|
+
})], m.prototype, "minValue", void 0), e([o({
|
|
92
93
|
type: Number,
|
|
93
94
|
reflect: !0,
|
|
94
95
|
attribute: "max-value"
|
|
95
|
-
})],
|
|
96
|
+
})], m.prototype, "maxValue", void 0), e([o({
|
|
96
97
|
type: String,
|
|
97
98
|
attribute: "accessible-label"
|
|
98
|
-
})],
|
|
99
|
+
})], m.prototype, "accessibleLabel", void 0), e([o({
|
|
99
100
|
type: String,
|
|
100
101
|
attribute: "value-label"
|
|
101
|
-
})],
|
|
102
|
+
})], m.prototype, "valueLabel", void 0), e([o({ attribute: !1 })], m.prototype, "formatOptions", void 0), e([o({
|
|
102
103
|
type: String,
|
|
103
104
|
reflect: !0,
|
|
104
105
|
attribute: "label-position"
|
|
105
|
-
})],
|
|
106
|
+
})], m.prototype, "labelPosition", void 0), e([o({
|
|
106
107
|
type: String,
|
|
107
108
|
reflect: !0,
|
|
108
109
|
attribute: "static-color"
|
|
109
|
-
})],
|
|
110
|
+
})], m.prototype, "staticColor", void 0), m;
|
|
110
111
|
}
|
|
111
112
|
//#endregion
|
|
112
|
-
export {
|
|
113
|
+
export { l as LINEAR_PROGRESS_LABEL_POSITIONS, c as LINEAR_PROGRESS_STATIC_COLORS, s as LINEAR_PROGRESS_VALID_SIZES, m as LinearProgressMixin };
|
|
113
114
|
|
|
114
115
|
//# sourceMappingURL=linear-progress-mixin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linear-progress-mixin.js","names":[],"sources":["../../mixins/linear-progress-mixin.ts"],"sourcesContent":["/**\n * Copyright 2026 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nimport { PropertyValues, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { LanguageResolutionController } from '../controllers/language-resolution.js';\nimport {\n ObserveSlotPresence,\n type SlotPresenceObservingInterface,\n} from './observe-slot-presence.js';\nimport type { ElementSize } from './sized-mixin.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport const LINEAR_PROGRESS_VALID_SIZES = [\n 's',\n 'm',\n 'l',\n 'xl',\n] as const satisfies readonly ElementSize[];\nexport type LinearProgressSize = (typeof LINEAR_PROGRESS_VALID_SIZES)[number];\n\nexport const LINEAR_PROGRESS_STATIC_COLORS = ['white', 'black'] as const;\nexport type LinearProgressStaticColor =\n (typeof LINEAR_PROGRESS_STATIC_COLORS)[number];\n\nexport const LINEAR_PROGRESS_LABEL_POSITIONS = ['top', 'side'] as const;\nexport type LinearProgressLabelPosition =\n (typeof LINEAR_PROGRESS_LABEL_POSITIONS)[number];\n\nconst DEFAULT_FORMAT_OPTIONS: Intl.NumberFormatOptions = { style: 'percent' };\n\nconst LABEL_SLOT_SELECTOR = '[slot=\"label\"]';\nconst DESCRIPTION_SLOT_SELECTOR = '[slot=\"description\"]';\n\nexport interface LinearProgressInterface extends SlotPresenceObservingInterface {\n value: number;\n minValue: number;\n maxValue: number;\n accessibleLabel: string;\n valueLabel?: string;\n formatOptions?: Intl.NumberFormatOptions;\n labelPosition: LinearProgressLabelPosition;\n staticColor?: LinearProgressStaticColor;\n readonly sanitizedMin: number;\n readonly sanitizedMax: number;\n readonly clampedValue: number;\n readonly fillPercent: number;\n readonly formattedValue: string;\n readonly hasLabelSlotContent: boolean;\n readonly hasDescriptionSlotContent: boolean;\n readonly labelContainerId: string;\n readonly descriptionContainerId: string;\n}\n\nlet nextLinearProgressId = 0;\n\n/**\n * Mixin for linear progress components. Owns the typed property\n * declarations, sanitized range + value, locale formatting, light-DOM\n * slot presence tracking (so the shadow-DOM containers and slots can\n * be fully conditional), and the DEBUG accessible-name warning.\n *\n * Intentionally silent on `role` and animation — those stay in each\n * component's own base class.\n */\nexport function LinearProgressMixin<T extends Constructor<ReactiveElement>>(\n constructor: T\n): T & Constructor<LinearProgressInterface> {\n class LinearProgressElement\n extends ObserveSlotPresence(constructor, [\n LABEL_SLOT_SELECTOR,\n DESCRIPTION_SLOT_SELECTOR,\n ])\n implements LinearProgressInterface\n {\n /**\n * Current value. Sanitized via `clampedValue` for rendering and\n * `aria-valuenow`.\n */\n @property({ type: Number, reflect: true })\n public value = 0;\n\n /**\n * Bottom of the value range.\n */\n @property({ type: Number, reflect: true, attribute: 'min-value' })\n public minValue = 0;\n\n /**\n * Top of the value range.\n */\n @property({ type: Number, reflect: true, attribute: 'max-value' })\n public maxValue = 100;\n\n /**\n * Rare-case accessible-name fallback used when there is no visible\n * `label` slot content (for example, a data grid of meters).\n * Renders into `aria-label` on the role element when set.\n */\n @property({ type: String, attribute: 'accessible-label' })\n public accessibleLabel = '';\n\n /**\n * Custom value text (e.g. `\"1 of 4\"`). Overrides the auto-formatted\n * value in both rendered text and `aria-valuetext`.\n */\n @property({ type: String, attribute: 'value-label' })\n public valueLabel?: string;\n\n /**\n * `Intl.NumberFormatOptions` used to format the visible value and\n * `aria-valuetext` when `valueLabel` is unset. JS property only —\n * no attribute (full `Intl.NumberFormat` pass-through).\n */\n @property({ attribute: false })\n public formatOptions?: Intl.NumberFormatOptions;\n\n /**\n * Position of the label relative to the bar.\n */\n @property({ type: String, reflect: true, attribute: 'label-position' })\n public labelPosition: LinearProgressLabelPosition = 'top';\n\n /**\n * Static color override for use on images or colored backgrounds.\n */\n @property({ type: String, reflect: true, attribute: 'static-color' })\n public staticColor?: LinearProgressStaticColor;\n\n private readonly languageResolver = new LanguageResolutionController(this);\n\n private readonly _instanceId = ++nextLinearProgressId;\n\n /**\n * @internal\n *\n * Documentation URL used in DEBUG warnings. Derived from the custom\n * element tag name so each concrete component gets an accurate link\n * with no per-subclass override needed (e.g. `swc-meter` →\n * `components-meter--docs`, `swc-progress-bar` →\n * `components-progress-bar--docs`).\n */\n protected get docsHref(): string {\n const name = this.localName.replace(/^swc-/, '');\n return `https://spectrum-web-components.adobe.com/?path=/docs/components-${name}--docs`;\n }\n\n /**\n * @internal\n */\n public get labelContainerId(): string {\n return `swc-linear-progress-label-${this._instanceId}`;\n }\n\n /**\n * @internal\n */\n public get descriptionContainerId(): string {\n return `swc-linear-progress-description-${this._instanceId}`;\n }\n\n /**\n * @internal\n */\n public get hasLabelSlotContent(): boolean {\n return this.getSlotContentPresence(LABEL_SLOT_SELECTOR);\n }\n\n /**\n * @internal\n */\n public get hasDescriptionSlotContent(): boolean {\n return this.getSlotContentPresence(DESCRIPTION_SLOT_SELECTOR);\n }\n\n /**\n * @internal\n *\n * Sanitized lower bound: falls back to 0 when `minValue` is non-finite,\n * and to the smaller of (min, max) when the two are reversed. ARIA\n * `aria-valuemin`, `aria-valuenow`, `aria-valuetext`, and the rendered\n * fill all read from the same sanitized range so screen-reader output\n * stays internally consistent.\n */\n public get sanitizedMin(): number {\n const min = Number.isFinite(this.minValue) ? this.minValue : 0;\n const max = Number.isFinite(this.maxValue) ? this.maxValue : 100;\n return Math.min(min, max);\n }\n\n /**\n * @internal\n *\n * Sanitized upper bound. See `sanitizedMin`.\n */\n public get sanitizedMax(): number {\n const min = Number.isFinite(this.minValue) ? this.minValue : 0;\n const max = Number.isFinite(this.maxValue) ? this.maxValue : 100;\n return Math.max(min, max);\n }\n\n /**\n * @internal\n */\n public get clampedValue(): number {\n const value = Number.isFinite(this.value) ? this.value : 0;\n return Math.min(this.sanitizedMax, Math.max(this.sanitizedMin, value));\n }\n\n /**\n * @internal\n */\n public get fillPercent(): number {\n const min = this.sanitizedMin;\n const max = this.sanitizedMax;\n if (max === min) {\n return 0;\n }\n const fraction = (this.clampedValue - min) / (max - min);\n return Math.min(100, Math.max(0, fraction * 100));\n }\n\n /**\n * @internal\n */\n public get formattedValue(): string {\n if (this.valueLabel) {\n return this.valueLabel;\n }\n const min = this.sanitizedMin;\n const max = this.sanitizedMax;\n // Treat anything that is not a plain options object (null, undefined,\n // empty string from Storybook helpers, etc.) as \"no override\" and\n // fall back to the percent default.\n const providedOptions =\n this.formatOptions &&\n typeof this.formatOptions === 'object' &&\n Object.keys(this.formatOptions).length > 0\n ? this.formatOptions\n : DEFAULT_FORMAT_OPTIONS;\n const formatter = new Intl.NumberFormat(\n this.languageResolver.language,\n providedOptions\n );\n // Percent style consumes a fraction; every other style consumes the\n // raw value.\n if (providedOptions.style === 'percent') {\n const fraction =\n max === min ? 0 : (this.clampedValue - min) / (max - min);\n return formatter.format(fraction);\n }\n return formatter.format(this.clampedValue);\n }\n\n protected override updated(changes: PropertyValues): void {\n super.updated(changes);\n\n // Locale changes are picked up automatically: the\n // `LanguageResolutionController` requests an update with\n // `languageResolverUpdatedSymbol`, which re-runs `render()`. The\n // render template reads `formattedValue` (which reads\n // `languageResolver.language` lazily), so the new locale is already\n // reflected in this render cycle. No second `requestUpdate()`\n // needed here.\n\n // Only re-evaluate the accessible-name fallback when the inputs\n // that determine it actually change, so the warning does not fire\n // on every property update during development.\n if (\n window.__swc?.DEBUG &&\n (changes.has('accessibleLabel') || !this._hasWarnedNoAccessibleName)\n ) {\n this.warnMissingAccessibleName();\n }\n\n // Surface a dev warning when `value` falls outside the resolved\n // range. The value is still clamped for rendering and ARIA, but the\n // clamp is otherwise silent, so flag it as a likely authoring error.\n if (\n window.__swc?.DEBUG &&\n (changes.has('value') ||\n changes.has('minValue') ||\n changes.has('maxValue'))\n ) {\n this.warnValueOutOfRange();\n }\n }\n\n private _hasWarnedNoAccessibleName = false;\n\n private _hasWarnedValueOutOfRange = false;\n\n private warnValueOutOfRange(): void {\n const value = this.value;\n const min = this.sanitizedMin;\n const max = this.sanitizedMax;\n if (!Number.isFinite(value) || (value >= min && value <= max)) {\n this._hasWarnedValueOutOfRange = false;\n return;\n }\n if (this._hasWarnedValueOutOfRange) {\n return;\n }\n this._hasWarnedValueOutOfRange = true;\n window.__swc?.warn(\n this,\n `<${this.localName}> \"value\" (${value}) is outside the [${min}, ${max}] range and was clamped to ${this.clampedValue}.`,\n this.docsHref,\n {\n issues: [\n 'set \"value\" within the \"min-value\" and \"max-value\" range, or',\n 'adjust \"min-value\"/\"max-value\" so the range includes the value.',\n ],\n }\n );\n }\n\n private warnMissingAccessibleName(): void {\n if (this.hasLabelSlotContent || this.accessibleLabel) {\n this._hasWarnedNoAccessibleName = false;\n return;\n }\n this._hasWarnedNoAccessibleName = true;\n window.__swc?.warn(\n this,\n `<${this.localName}> requires an accessible name.`,\n this.docsHref,\n {\n type: 'accessibility',\n issues: [\n 'add visible label content via the \"label\" named slot, or',\n 'set the \"accessible-label\" attribute (or \"accessibleLabel\" property) when there is no visible label.',\n ],\n }\n );\n }\n }\n return LinearProgressElement as unknown as T &\n Constructor<LinearProgressInterface>;\n}\n"],"mappings":";;;;;AA2BA,IAAa,IAA8B;CACzC;CACA;CACA;CACA;CACD,EAGY,IAAgC,CAAC,SAAS,QAAQ,EAIlD,IAAk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AClC;;AAGF,GADA,KAAK,6BAA6B,KAClC,IAAA,OAAO,UAAA,QAAA,EAAO,KACZ,MACA,IAAI,KAAK,UAAU,iCACnB,KAAK,UACL;IACE,MAAM;IACN,QAAQ,CACN,8DACA,2GACD;IACF,CACF;;;AAGL,WAlQG,EAAS;EAAE,MAAM;EAAQ,SAAS;EAAM,CAAC,CAAA,EAAA,EAAA,WAAA,SAAA,KAAA,EAAA,KAMzC,EAAS;EAAE,MAAM;EAAQ,SAAS;EAAM,WAAW;EAAa,CAAC,CAAA,EAAA,EAAA,WAAA,YAAA,KAAA,EAAA,KAMjE,EAAS;EAAE,MAAM;EAAQ,SAAS;EAAM,WAAW;EAAa,CAAC,CAAA,EAAA,EAAA,WAAA,YAAA,KAAA,EAAA,KAQjE,EAAS;EAAE,MAAM;EAAQ,WAAW;EAAoB,CAAC,CAAA,EAAA,EAAA,WAAA,mBAAA,KAAA,EAAA,KAOzD,EAAS;EAAE,MAAM;EAAQ,WAAW;EAAe,CAAC,CAAA,EAAA,EAAA,WAAA,cAAA,KAAA,EAAA,KAQpD,EAAS,EAAE,WAAW,IAAO,CAAC,CAAA,EAAA,EAAA,WAAA,iBAAA,KAAA,EAAA,KAM9B,EAAS;EAAE,MAAM;EAAQ,SAAS;EAAM,WAAW;EAAkB,CAAC,CAAA,EAAA,EAAA,WAAA,iBAAA,KAAA,EAAA,KAMtE,EAAS;EAAE,MAAM;EAAQ,SAAS;EAAM,WAAW;EAAgB,CAAC,CAAA,EAAA,EAAA,WAAA,eAAA,KAAA,EAAA,EAmNhE"}
|
|
1
|
+
{"version":3,"file":"linear-progress-mixin.js","names":[],"sources":["../../mixins/linear-progress-mixin.ts"],"sourcesContent":["/**\n * Copyright 2026 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nimport { PropertyValues, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { LanguageResolutionController } from '../controllers/language-resolution.js';\nimport { SlotPresenceController } from '../controllers/slot-presence-controller/index.js';\nimport { isDebug, validateEnum, warnIf } from '../utils/index.js';\nimport type { ElementSize } from './sized-mixin.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport const LINEAR_PROGRESS_VALID_SIZES = [\n 's',\n 'm',\n 'l',\n 'xl',\n] as const satisfies readonly ElementSize[];\nexport type LinearProgressSize = (typeof LINEAR_PROGRESS_VALID_SIZES)[number];\n\nexport const LINEAR_PROGRESS_STATIC_COLORS = ['white', 'black'] as const;\nexport type LinearProgressStaticColor =\n (typeof LINEAR_PROGRESS_STATIC_COLORS)[number];\n\nexport const LINEAR_PROGRESS_LABEL_POSITIONS = ['top', 'side'] as const;\nexport type LinearProgressLabelPosition =\n (typeof LINEAR_PROGRESS_LABEL_POSITIONS)[number];\n\nconst DEFAULT_FORMAT_OPTIONS: Intl.NumberFormatOptions = { style: 'percent' };\n\nconst LABEL_SLOT_SELECTOR = '[slot=\"label\"]';\nconst DESCRIPTION_SLOT_SELECTOR = '[slot=\"description\"]';\n\nexport interface LinearProgressInterface {\n value: number;\n minValue: number;\n maxValue: number;\n accessibleLabel: string;\n valueLabel?: string;\n formatOptions?: Intl.NumberFormatOptions;\n labelPosition: LinearProgressLabelPosition;\n staticColor?: LinearProgressStaticColor;\n readonly sanitizedMin: number;\n readonly sanitizedMax: number;\n readonly clampedValue: number;\n readonly fillPercent: number;\n readonly formattedValue: string;\n readonly hasLabelSlotContent: boolean;\n readonly hasDescriptionSlotContent: boolean;\n readonly labelContainerId: string;\n readonly descriptionContainerId: string;\n}\n\nlet nextLinearProgressId = 0;\n\n/**\n * Mixin for linear progress components. Owns the typed property\n * declarations, sanitized range + value, locale formatting, light-DOM\n * slot presence tracking (so the shadow-DOM containers and slots can\n * be fully conditional), and the DEBUG accessible-name warning.\n *\n * Intentionally silent on `role` and animation — those stay in each\n * component's own base class.\n */\nexport function LinearProgressMixin<T extends Constructor<ReactiveElement>>(\n constructor: T\n): T & Constructor<LinearProgressInterface> {\n class LinearProgressElement\n extends constructor\n implements LinearProgressInterface\n {\n /**\n * Observes the light-DOM `label` and `description` slots so the shadow-DOM\n * containers and slots can be fully conditional.\n */\n private readonly slotPresence = new SlotPresenceController(this, [\n LABEL_SLOT_SELECTOR,\n DESCRIPTION_SLOT_SELECTOR,\n ]);\n\n /**\n * Current value. Sanitized via `clampedValue` for rendering and\n * `aria-valuenow`.\n */\n @property({ type: Number, reflect: true })\n public value = 0;\n\n /**\n * Bottom of the value range.\n */\n @property({ type: Number, reflect: true, attribute: 'min-value' })\n public minValue = 0;\n\n /**\n * Top of the value range.\n */\n @property({ type: Number, reflect: true, attribute: 'max-value' })\n public maxValue = 100;\n\n /**\n * Rare-case accessible-name fallback used when there is no visible\n * `label` slot content (for example, a data grid of meters).\n * Renders into `aria-label` on the role element when set.\n */\n @property({ type: String, attribute: 'accessible-label' })\n public accessibleLabel = '';\n\n /**\n * Custom value text (e.g. `\"1 of 4\"`). Overrides the auto-formatted\n * value in both rendered text and `aria-valuetext`.\n */\n @property({ type: String, attribute: 'value-label' })\n public valueLabel?: string;\n\n /**\n * `Intl.NumberFormatOptions` used to format the visible value and\n * `aria-valuetext` when `valueLabel` is unset. JS property only —\n * no attribute (full `Intl.NumberFormat` pass-through).\n */\n @property({ attribute: false })\n public formatOptions?: Intl.NumberFormatOptions;\n\n /**\n * Position of the label relative to the bar.\n */\n @property({ type: String, reflect: true, attribute: 'label-position' })\n public labelPosition: LinearProgressLabelPosition = 'top';\n\n /**\n * Static color override for use on images or colored backgrounds.\n */\n @property({ type: String, reflect: true, attribute: 'static-color' })\n public staticColor?: LinearProgressStaticColor;\n\n private readonly languageResolver = new LanguageResolutionController(this);\n\n private readonly _instanceId = ++nextLinearProgressId;\n\n /**\n * @internal\n *\n * Documentation URL used in DEBUG warnings. Derived from the custom\n * element tag name so each concrete component gets an accurate link\n * with no per-subclass override needed (e.g. `swc-meter` →\n * `components-meter--docs`, `swc-progress-bar` →\n * `components-progress-bar--docs`).\n */\n protected get docsHref(): string {\n const name = this.localName.replace(/^swc-/, '');\n return `https://spectrum-web-components.adobe.com/?path=/docs/components-${name}--docs`;\n }\n\n /**\n * @internal\n */\n public get labelContainerId(): string {\n return `swc-linear-progress-label-${this._instanceId}`;\n }\n\n /**\n * @internal\n */\n public get descriptionContainerId(): string {\n return `swc-linear-progress-description-${this._instanceId}`;\n }\n\n /**\n * @internal\n */\n public get hasLabelSlotContent(): boolean {\n return this.slotPresence.getPresence(LABEL_SLOT_SELECTOR);\n }\n\n /**\n * @internal\n */\n public get hasDescriptionSlotContent(): boolean {\n return this.slotPresence.getPresence(DESCRIPTION_SLOT_SELECTOR);\n }\n\n /**\n * @internal\n *\n * Sanitized lower bound: falls back to 0 when `minValue` is non-finite,\n * and to the smaller of (min, max) when the two are reversed. ARIA\n * `aria-valuemin`, `aria-valuenow`, `aria-valuetext`, and the rendered\n * fill all read from the same sanitized range so screen-reader output\n * stays internally consistent.\n */\n public get sanitizedMin(): number {\n const min = Number.isFinite(this.minValue) ? this.minValue : 0;\n const max = Number.isFinite(this.maxValue) ? this.maxValue : 100;\n return Math.min(min, max);\n }\n\n /**\n * @internal\n *\n * Sanitized upper bound. See `sanitizedMin`.\n */\n public get sanitizedMax(): number {\n const min = Number.isFinite(this.minValue) ? this.minValue : 0;\n const max = Number.isFinite(this.maxValue) ? this.maxValue : 100;\n return Math.max(min, max);\n }\n\n /**\n * @internal\n */\n public get clampedValue(): number {\n const value = Number.isFinite(this.value) ? this.value : 0;\n return Math.min(this.sanitizedMax, Math.max(this.sanitizedMin, value));\n }\n\n /**\n * @internal\n */\n public get fillPercent(): number {\n const min = this.sanitizedMin;\n const max = this.sanitizedMax;\n if (max === min) {\n return 0;\n }\n const fraction = (this.clampedValue - min) / (max - min);\n return Math.min(100, Math.max(0, fraction * 100));\n }\n\n /**\n * @internal\n */\n public get formattedValue(): string {\n if (this.valueLabel) {\n return this.valueLabel;\n }\n const min = this.sanitizedMin;\n const max = this.sanitizedMax;\n // Treat anything that is not a plain options object (null, undefined,\n // empty string from Storybook helpers, etc.) as \"no override\" and\n // fall back to the percent default.\n const providedOptions =\n this.formatOptions &&\n typeof this.formatOptions === 'object' &&\n Object.keys(this.formatOptions).length > 0\n ? this.formatOptions\n : DEFAULT_FORMAT_OPTIONS;\n const formatter = new Intl.NumberFormat(\n this.languageResolver.language,\n providedOptions\n );\n // Percent style consumes a fraction; every other style consumes the\n // raw value.\n if (providedOptions.style === 'percent') {\n const fraction =\n max === min ? 0 : (this.clampedValue - min) / (max - min);\n return formatter.format(fraction);\n }\n return formatter.format(this.clampedValue);\n }\n\n protected override updated(changes: PropertyValues): void {\n super.updated(changes);\n\n // Locale changes are picked up automatically: the\n // `LanguageResolutionController` requests an update with\n // `languageResolverUpdatedSymbol`, which re-runs `render()`. The\n // render template reads `formattedValue` (which reads\n // `languageResolver.language` lazily), so the new locale is already\n // reflected in this render cycle. No second `requestUpdate()`\n // needed here.\n\n // The accessible name can come from the `accessibleLabel` property or the\n // label slot (tracked by a slot controller that requests an update without\n // surfacing a changed property), so re-check on every dev render and let\n // the warning dedup handle repeats rather than gating on one property.\n if (isDebug()) {\n this.warnMissingAccessibleName();\n }\n\n // Surface a dev warning when `value` falls outside the resolved\n // range. The value is still clamped for rendering and ARIA, but the\n // clamp is otherwise silent, so flag it as a likely authoring error.\n if (\n isDebug() &&\n (changes.has('value') ||\n changes.has('minValue') ||\n changes.has('maxValue'))\n ) {\n this.warnValueOutOfRange();\n }\n\n if (changes.has('labelPosition')) {\n validateEnum(this, {\n prop: 'label-position',\n value: this.labelPosition,\n valid: LINEAR_PROGRESS_LABEL_POSITIONS,\n url: 'https://spectrum-web-components.adobe.com/?path=/docs/components-meter--docs',\n });\n }\n\n if (changes.has('staticColor') && this.staticColor !== undefined) {\n validateEnum(this, {\n prop: 'static-color',\n value: this.staticColor,\n valid: LINEAR_PROGRESS_STATIC_COLORS,\n url: 'https://spectrum-web-components.adobe.com/?path=/docs/components-meter--docs',\n });\n }\n }\n\n private warnValueOutOfRange(): void {\n const value = this.value;\n const min = this.sanitizedMin;\n const max = this.sanitizedMax;\n // Early return when the value is valid so the message is not built on\n // every in-range render.\n if (!Number.isFinite(value) || (value >= min && value <= max)) {\n return;\n }\n warnIf(\n this,\n true,\n `<${this.localName}> \"value\" (${value}) is outside the [${min}, ${max}] range and was clamped to ${this.clampedValue}.`,\n this.docsHref,\n {\n issues: [\n 'set \"value\" within the \"min-value\" and \"max-value\" range, or',\n 'adjust \"min-value\"/\"max-value\" so the range includes the value.',\n ],\n }\n );\n }\n\n private warnMissingAccessibleName(): void {\n // Early return when a name is present so the message is not built on\n // every render (this runs unconditionally in dev).\n if (this.hasLabelSlotContent || this.accessibleLabel) {\n return;\n }\n warnIf(\n this,\n true,\n `<${this.localName}> requires an accessible name.`,\n this.docsHref,\n {\n type: 'accessibility',\n issues: [\n 'add visible label content via the \"label\" named slot, or',\n 'set the \"accessible-label\" attribute (or \"accessibleLabel\" property) when there is no visible label.',\n ],\n }\n );\n }\n }\n return LinearProgressElement as unknown as T &\n Constructor<LinearProgressInterface>;\n}\n"],"mappings":";;;;;;;AAyBA,IAAa,IAA8B;CACzC;CACA;CACA;CACA;CACD,EAGY,IAAgC,CAAC,SAAS,QAAQ,EAIlD,IAAkC,CAAC,OAAO,OAAO,EAIxD,IAAmD,EAAE,OAAO,WAAW,EAEvE,IAAsB,oBACtB,IAA4B,0BAsB9B,IAAuB;AAW3B,SAAgB,EACd,GAC0C;CAC1C,MAAM,UACI,EAEV;;oCAKkC,IAAI,EAAuB,MAAM,CAC/D,GACA,EAC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EAAA,WAAA,SAAA,KAAA,EAAA,KAMzC,EAAS;EAAE,MAAM;EAAQ,SAAS;EAAM,WAAW;EAAa,CAAC,CAAA,EAAA,EAAA,WAAA,YAAA,KAAA,EAAA,KAMjE,EAAS;EAAE,MAAM;EAAQ,SAAS;EAAM,WAAW;EAAa,CAAC,CAAA,EAAA,EAAA,WAAA,YAAA,KAAA,EAAA,KAQjE,EAAS;EAAE,MAAM;EAAQ,WAAW;EAAoB,CAAC,CAAA,EAAA,EAAA,WAAA,mBAAA,KAAA,EAAA,KAOzD,EAAS;EAAE,MAAM;EAAQ,WAAW;EAAe,CAAC,CAAA,EAAA,EAAA,WAAA,cAAA,KAAA,EAAA,KAQpD,EAAS,EAAE,WAAW,IAAO,CAAC,CAAA,EAAA,EAAA,WAAA,iBAAA,KAAA,EAAA,KAM9B,EAAS;EAAE,MAAM;EAAQ,SAAS;EAAM,WAAW;EAAkB,CAAC,CAAA,EAAA,EAAA,WAAA,iBAAA,KAAA,EAAA,KAMtE,EAAS;EAAE,MAAM;EAAQ,SAAS;EAAM,WAAW;EAAgB,CAAC,CAAA,EAAA,EAAA,WAAA,eAAA,KAAA,EAAA,EA8NhE"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { __decorate as e } from "../_virtual/_@oxc-project_runtime@0.124.0/helpers/decorate.js";
|
|
2
|
-
import {
|
|
2
|
+
import { warnIf as t } from "../utils/dev-validation.js";
|
|
3
|
+
import "../utils/index.js";
|
|
4
|
+
import { PendingController as n } from "../controllers/pending-controller/src/pending-controller.js";
|
|
3
5
|
import "../controllers/pending-controller/index.js";
|
|
4
|
-
import { property as
|
|
6
|
+
import { property as r } from "lit/decorators.js";
|
|
5
7
|
//#region mixins/pending-mixin.ts
|
|
6
|
-
function
|
|
7
|
-
class
|
|
8
|
+
function i(i) {
|
|
9
|
+
class a extends i {
|
|
8
10
|
constructor(...e) {
|
|
9
|
-
super(...e), this.pending = !1, this._pendingController = new
|
|
11
|
+
super(...e), this.pending = !1, this._pendingController = new n(this, { resolveAccessibleName: () => {
|
|
10
12
|
var e, t;
|
|
11
13
|
return (e = this.accessibleLabel) == null ? ((t = this.textContent) == null ? void 0 : t.trim()) || null : e;
|
|
12
14
|
} }), this._suppressPendingActivation = (e) => {
|
|
@@ -29,21 +31,20 @@ function r(r) {
|
|
|
29
31
|
this.removeEventListener("click", this._suppressPendingActivation, !0), super.disconnectedCallback();
|
|
30
32
|
}
|
|
31
33
|
update(e) {
|
|
32
|
-
var t;
|
|
33
34
|
super.update(e);
|
|
34
35
|
let n = "disabled" in this && this.disabled === !0;
|
|
35
|
-
(
|
|
36
|
+
t(this, this.pending && n, `<${this.localName}> should not set both "pending" and "disabled" simultaneously. Use "pending" to keep the element focusable while unavailable, or "disabled" to fully remove it from the tab order.`, "https://spectrum-web-components.adobe.com/?path=/docs/components-button--docs", { issues: ["pending + disabled"] });
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
return e([
|
|
39
|
+
return e([r({
|
|
39
40
|
type: Boolean,
|
|
40
41
|
reflect: !0
|
|
41
|
-
})],
|
|
42
|
+
})], a.prototype, "pending", void 0), e([r({
|
|
42
43
|
type: String,
|
|
43
44
|
attribute: "pending-label"
|
|
44
|
-
})],
|
|
45
|
+
})], a.prototype, "pendingLabel", void 0), a;
|
|
45
46
|
}
|
|
46
47
|
//#endregion
|
|
47
|
-
export {
|
|
48
|
+
export { i as PendingMixin };
|
|
48
49
|
|
|
49
50
|
//# sourceMappingURL=pending-mixin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pending-mixin.js","names":[],"sources":["../../mixins/pending-mixin.ts"],"sourcesContent":["/**\n * Copyright 2026 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type { PropertyValues, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { PendingController } from '../controllers/pending-controller/index.js';\nimport type { PendingSpinnerResult } from '../directives/pending-spinner/index.js';\n\n// Abstract-capable so the mixin can be applied over abstract base classes such\n// as `ButtonBase`; `new` alone cannot construct an abstract class.\ntype Constructor<T = Record<string, unknown>> =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n abstract new (...args: any[]) => T;\n\n/** The API {@link PendingMixin} adds to its host. */\nexport interface PendingInterface {\n pending: boolean;\n pendingLabel?: string;\n readonly pendingActive: boolean;\n getPendingAccessibleName(): string;\n renderPendingState(): PendingSpinnerResult;\n}\n\n/**\n * A mixin that adds the pending (busy) state to a host: the reactive `pending`\n * and `pending-label` properties, a {@link PendingController} for the delayed\n * visual / inline-size freeze / accessible-name derivation, and capture-phase\n * click suppression so activation is blocked while pending.\n *\n * The host stays focusable while pending; the mixin never sets the native\n * `disabled` attribute. The host's template is responsible for applying\n * `aria-disabled` and the pending `aria-label` (read from\n * {@link PendingInterface.getPendingAccessibleName}), and for rendering the\n * spinner with the `renderPendingSpinner` directive.\n *\n * The busy accessible name is derived from the host's optional\n * `accessibleLabel` when present, otherwise from trimmed `textContent`.\n *\n * @example\n * ```typescript\n * class MyButton extends PendingMixin(SpectrumElement) {\n * render() {\n * return html`<button\n * aria-disabled=${ifDefined(this.pending ? 'true' : undefined)}\n * aria-label=${ifDefined(this.pending ? this.getPendingAccessibleName() : this.accessibleLabel)}\n * >\n * <slot></slot>\n * ${this.renderPendingState()}\n * </button>`;\n * }\n * }\n * ```\n */\nexport function PendingMixin<\n T extends Constructor<ReactiveElement & { accessibleLabel?: string }>,\n>(constructor: T): T & Constructor<PendingInterface> {\n abstract class PendingElement\n extends constructor\n implements PendingInterface\n {\n /**\n * Whether the element is in a pending (busy) state. The element remains\n * focusable but activation is suppressed.\n */\n @property({ type: Boolean, reflect: true })\n public pending = false;\n\n /**\n * Custom accessible label used during the pending state. When omitted, the\n * pending label is derived from the resolved non-busy accessible name plus\n * a busy suffix (e.g. \"Save, busy\").\n */\n @property({ type: String, attribute: 'pending-label' })\n public pendingLabel?: string;\n\n private _pendingController = new PendingController(this, {\n resolveAccessibleName: () =>\n this.accessibleLabel ?? (this.textContent?.trim() || null),\n });\n\n /**\n * Whether the delayed busy visual is active. Read this in `render()` to\n * apply the busy styling.\n */\n public get pendingActive(): boolean {\n return this._pendingController.pendingActive;\n }\n\n /** Derives the pending-state accessible label. */\n public getPendingAccessibleName(): string {\n return this._pendingController.getPendingAccessibleName();\n }\n\n /**\n * Renders the pending spinner for the current state, via the controller.\n * Lets hosts render the indicator with `${this.renderPendingState()}` and no\n * separate directive import.\n */\n public renderPendingState(): PendingSpinnerResult {\n return this._pendingController.renderPendingState();\n }\n\n /**\n * Suppresses click activation while pending. Capture phase so slotted\n * light-DOM clicks are suppressed before host listeners run.\n */\n private readonly _suppressPendingActivation = (event: Event): void => {\n if (this.pending) {\n event.preventDefault();\n event.stopImmediatePropagation();\n }\n };\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener('click', this._suppressPendingActivation, true);\n }\n\n public override disconnectedCallback(): void {\n this.removeEventListener('click', this._suppressPendingActivation, true);\n super.disconnectedCallback();\n }\n\n protected override update(changedProperties: PropertyValues): void {\n super.update(changedProperties);\n // Guard the `disabled` read with an `in` check rather than a cast: not\n // every host that applies this mixin necessarily has a `disabled`\n // property.\n const hasDisabled = 'disabled' in this && this.disabled === true;\n
|
|
1
|
+
{"version":3,"file":"pending-mixin.js","names":[],"sources":["../../mixins/pending-mixin.ts"],"sourcesContent":["/**\n * Copyright 2026 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type { PropertyValues, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { PendingController } from '../controllers/pending-controller/index.js';\nimport type { PendingSpinnerResult } from '../directives/pending-spinner/index.js';\nimport { warnIf } from '../utils/index.js';\n\n// Abstract-capable so the mixin can be applied over abstract base classes such\n// as `ButtonBase`; `new` alone cannot construct an abstract class.\ntype Constructor<T = Record<string, unknown>> =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n abstract new (...args: any[]) => T;\n\n/** The API {@link PendingMixin} adds to its host. */\nexport interface PendingInterface {\n pending: boolean;\n pendingLabel?: string;\n readonly pendingActive: boolean;\n getPendingAccessibleName(): string;\n renderPendingState(): PendingSpinnerResult;\n}\n\n/**\n * A mixin that adds the pending (busy) state to a host: the reactive `pending`\n * and `pending-label` properties, a {@link PendingController} for the delayed\n * visual / inline-size freeze / accessible-name derivation, and capture-phase\n * click suppression so activation is blocked while pending.\n *\n * The host stays focusable while pending; the mixin never sets the native\n * `disabled` attribute. The host's template is responsible for applying\n * `aria-disabled` and the pending `aria-label` (read from\n * {@link PendingInterface.getPendingAccessibleName}), and for rendering the\n * spinner with the `renderPendingSpinner` directive.\n *\n * The busy accessible name is derived from the host's optional\n * `accessibleLabel` when present, otherwise from trimmed `textContent`.\n *\n * @example\n * ```typescript\n * class MyButton extends PendingMixin(SpectrumElement) {\n * render() {\n * return html`<button\n * aria-disabled=${ifDefined(this.pending ? 'true' : undefined)}\n * aria-label=${ifDefined(this.pending ? this.getPendingAccessibleName() : this.accessibleLabel)}\n * >\n * <slot></slot>\n * ${this.renderPendingState()}\n * </button>`;\n * }\n * }\n * ```\n */\nexport function PendingMixin<\n T extends Constructor<ReactiveElement & { accessibleLabel?: string }>,\n>(constructor: T): T & Constructor<PendingInterface> {\n abstract class PendingElement\n extends constructor\n implements PendingInterface\n {\n /**\n * Whether the element is in a pending (busy) state. The element remains\n * focusable but activation is suppressed.\n */\n @property({ type: Boolean, reflect: true })\n public pending = false;\n\n /**\n * Custom accessible label used during the pending state. When omitted, the\n * pending label is derived from the resolved non-busy accessible name plus\n * a busy suffix (e.g. \"Save, busy\").\n */\n @property({ type: String, attribute: 'pending-label' })\n public pendingLabel?: string;\n\n private _pendingController = new PendingController(this, {\n resolveAccessibleName: () =>\n this.accessibleLabel ?? (this.textContent?.trim() || null),\n });\n\n /**\n * Whether the delayed busy visual is active. Read this in `render()` to\n * apply the busy styling.\n */\n public get pendingActive(): boolean {\n return this._pendingController.pendingActive;\n }\n\n /** Derives the pending-state accessible label. */\n public getPendingAccessibleName(): string {\n return this._pendingController.getPendingAccessibleName();\n }\n\n /**\n * Renders the pending spinner for the current state, via the controller.\n * Lets hosts render the indicator with `${this.renderPendingState()}` and no\n * separate directive import.\n */\n public renderPendingState(): PendingSpinnerResult {\n return this._pendingController.renderPendingState();\n }\n\n /**\n * Suppresses click activation while pending. Capture phase so slotted\n * light-DOM clicks are suppressed before host listeners run.\n */\n private readonly _suppressPendingActivation = (event: Event): void => {\n if (this.pending) {\n event.preventDefault();\n event.stopImmediatePropagation();\n }\n };\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener('click', this._suppressPendingActivation, true);\n }\n\n public override disconnectedCallback(): void {\n this.removeEventListener('click', this._suppressPendingActivation, true);\n super.disconnectedCallback();\n }\n\n protected override update(changedProperties: PropertyValues): void {\n super.update(changedProperties);\n // Guard the `disabled` read with an `in` check rather than a cast: not\n // every host that applies this mixin necessarily has a `disabled`\n // property.\n const hasDisabled = 'disabled' in this && this.disabled === true;\n warnIf(\n this,\n this.pending && hasDisabled,\n `<${this.localName}> should not set both \"pending\" and \"disabled\" simultaneously. Use \"pending\" to keep the element focusable while unavailable, or \"disabled\" to fully remove it from the tab order.`,\n 'https://spectrum-web-components.adobe.com/?path=/docs/components-button--docs',\n { issues: ['pending + disabled'] }\n );\n }\n }\n return PendingElement as unknown as T & Constructor<PendingInterface>;\n}\n"],"mappings":";;;;;;;AAgEA,SAAgB,EAEd,GAAmD;CACnD,MAAe,UACL,EAEV;;+BAMmB,8BAUY,IAAI,EAAkB,MAAM,EACvD,6BACE;;qBAAK,oBAAA,SAAA,IAAoB,KAAK,gBAAA,OAAA,KAAA,IAAA,EAAa,MAAM,KAAI,OAAhD;MACR,CAAC,qCA4B6C,MAAuB;AACpE,IAAI,KAAK,YACP,EAAM,gBAAgB,EACtB,EAAM,0BAA0B;;;EAzBpC,IAAW,gBAAyB;AAClC,UAAO,KAAK,mBAAmB;;EAIjC,2BAA0C;AACxC,UAAO,KAAK,mBAAmB,0BAA0B;;EAQ3D,qBAAkD;AAChD,UAAO,KAAK,mBAAmB,oBAAoB;;EAcrD,oBAA0C;AAExC,GADA,MAAM,mBAAmB,EACzB,KAAK,iBAAiB,SAAS,KAAK,4BAA4B,GAAK;;EAGvE,uBAA6C;AAE3C,GADA,KAAK,oBAAoB,SAAS,KAAK,4BAA4B,GAAK,EACxE,MAAM,sBAAsB;;EAG9B,OAA0B,GAAyC;AACjE,SAAM,OAAO,EAAkB;GAI/B,IAAM,IAAc,cAAc,QAAQ,KAAK,aAAa;AAC5D,KACE,MACA,KAAK,WAAW,GAChB,IAAI,KAAK,UAAU,qLACnB,iFACA,EAAE,QAAQ,CAAC,qBAAqB,EAAE,CACnC;;;AAGL,WA1EG,EAAS;EAAE,MAAM;EAAS,SAAS;EAAM,CAAC,CAAA,EAAA,EAAA,WAAA,WAAA,KAAA,EAAA,KAQ1C,EAAS;EAAE,MAAM;EAAQ,WAAW;EAAiB,CAAC,CAAA,EAAA,EAAA,WAAA,gBAAA,KAAA,EAAA,EAkElD"}
|
|
@@ -12,7 +12,35 @@ export interface SizedElementInterface {
|
|
|
12
12
|
}
|
|
13
13
|
export interface SizedElementConstructor {
|
|
14
14
|
readonly VALID_SIZES: readonly ElementSize[];
|
|
15
|
+
readonly NO_DEFAULT_SIZE: boolean;
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Mixes size-awareness into a Lit `ReactiveElement` subclass.
|
|
19
|
+
*
|
|
20
|
+
* ## Why NO_DEFAULT_SIZE is a static rather than a closure variable
|
|
21
|
+
*
|
|
22
|
+
* The original implementation captured `noDefaultSize` in a closure at call
|
|
23
|
+
* time. That works when a component applies SizedMixin directly to a plain
|
|
24
|
+
* base (e.g. `SizedMixin(SpectrumElement, { noDefaultSize: true })`), but
|
|
25
|
+
* breaks silently when a component extends a base that is already SizedMixin'd.
|
|
26
|
+
*
|
|
27
|
+
* Consider InfieldButton extending ButtonBase:
|
|
28
|
+
* - ButtonBase = SizedMixin(SpectrumElement, {}) — closure captures noDefaultSize=false
|
|
29
|
+
* - InfieldButtonBase extends ButtonBase
|
|
30
|
+
*
|
|
31
|
+
* Even if a second SizedMixin wrapper is applied with noDefaultSize=true, calling
|
|
32
|
+
* super.update() reaches the inner ButtonBase SizedMixin, whose update() still
|
|
33
|
+
* reads noDefaultSize=false from its closure and writes size="m" to the DOM.
|
|
34
|
+
* Likewise, when a parent calls removeAttribute('size'), the inherited setter
|
|
35
|
+
* reads the inner closure's fallbackSize='m' and immediately re-sets the attribute.
|
|
36
|
+
*
|
|
37
|
+
* Making NO_DEFAULT_SIZE a static property solves both problems: the setter and
|
|
38
|
+
* update() read this.constructor.NO_DEFAULT_SIZE, which follows the prototype
|
|
39
|
+
* chain to the leaf class. A subclass like InfieldButtonBase only needs to
|
|
40
|
+
* declare `static override readonly NO_DEFAULT_SIZE = true` — no mixin
|
|
41
|
+
* re-wrapping, no lifecycle interception, and the correct value is read by every
|
|
42
|
+
* SizedMixin layer in the chain.
|
|
43
|
+
*/
|
|
16
44
|
export declare function SizedMixin<T extends Constructor<ReactiveElement>>(constructor: T, { validSizes, noDefaultSize, defaultSize, }?: {
|
|
17
45
|
validSizes?: readonly ElementSize[];
|
|
18
46
|
noDefaultSize?: boolean;
|
|
@@ -25,16 +25,16 @@ function i(n, { validSizes: i = [...r], noDefaultSize: a, defaultSize: o = "m" }
|
|
|
25
25
|
return this._size || o;
|
|
26
26
|
}
|
|
27
27
|
set size(e) {
|
|
28
|
-
let t =
|
|
29
|
-
if (
|
|
30
|
-
let
|
|
31
|
-
this._size =
|
|
28
|
+
let t = this.constructor, n = t.NO_DEFAULT_SIZE ? null : o, r = e && e.toLocaleLowerCase(), i = t.VALID_SIZES.includes(r) ? r : n;
|
|
29
|
+
if (i && this.setAttribute("size", i), this._size === i) return;
|
|
30
|
+
let a = this._size;
|
|
31
|
+
this._size = i, this.requestUpdate("size", a);
|
|
32
32
|
}
|
|
33
33
|
update(e) {
|
|
34
|
-
!this.hasAttribute("size") && !
|
|
34
|
+
!this.hasAttribute("size") && !this.constructor.NO_DEFAULT_SIZE && this.setAttribute("size", this.size), super.update(e);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
return s = c, s.VALID_SIZES = i, e([t({ type: String })], c.prototype, "size", null), c;
|
|
37
|
+
return s = c, s.VALID_SIZES = i, s.NO_DEFAULT_SIZE = a == null ? !1 : a, e([t({ type: String })], c.prototype, "size", null), c;
|
|
38
38
|
}
|
|
39
39
|
//#endregion
|
|
40
40
|
export { r as DEFAULT_ELEMENT_SIZES, n as ELEMENT_SIZES, i as SizedMixin };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sized-mixin.js","names":[],"sources":["../../mixins/sized-mixin.ts"],"sourcesContent":["/**\n * Copyright 2026 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nimport { PropertyValues, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport const ELEMENT_SIZES = ['xxs', 'xs', 's', 'm', 'l', 'xl', 'xxl'] as const;\nexport type ElementSize = (typeof ELEMENT_SIZES)[number];\n\nexport const DEFAULT_ELEMENT_SIZES = [\n 's',\n 'm',\n 'l',\n 'xl',\n] as const satisfies readonly ElementSize[];\nexport type DefaultElementSize = (typeof DEFAULT_ELEMENT_SIZES)[number];\n\nexport interface SizedElementInterface {\n size: ElementSize;\n}\n\nexport interface SizedElementConstructor {\n readonly VALID_SIZES: readonly ElementSize[];\n}\n\nexport function SizedMixin<T extends Constructor<ReactiveElement>>(\n constructor: T,\n {\n validSizes = [...DEFAULT_ELEMENT_SIZES],\n noDefaultSize,\n defaultSize = 'm',\n }: {\n validSizes?: readonly ElementSize[];\n noDefaultSize?: boolean;\n defaultSize?: ElementSize;\n } = {}\n): T & Constructor<SizedElementInterface> & SizedElementConstructor {\n class SizedElement extends constructor {\n /**\n * @internal\n */\n static readonly VALID_SIZES: readonly ElementSize[] = validSizes;\n\n @property({ type: String })\n public get size(): ElementSize {\n return this._size || defaultSize;\n }\n\n public set size(value: ElementSize) {\n const fallbackSize =
|
|
1
|
+
{"version":3,"file":"sized-mixin.js","names":[],"sources":["../../mixins/sized-mixin.ts"],"sourcesContent":["/**\n * Copyright 2026 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nimport { PropertyValues, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport const ELEMENT_SIZES = ['xxs', 'xs', 's', 'm', 'l', 'xl', 'xxl'] as const;\nexport type ElementSize = (typeof ELEMENT_SIZES)[number];\n\nexport const DEFAULT_ELEMENT_SIZES = [\n 's',\n 'm',\n 'l',\n 'xl',\n] as const satisfies readonly ElementSize[];\nexport type DefaultElementSize = (typeof DEFAULT_ELEMENT_SIZES)[number];\n\nexport interface SizedElementInterface {\n size: ElementSize;\n}\n\nexport interface SizedElementConstructor {\n readonly VALID_SIZES: readonly ElementSize[];\n readonly NO_DEFAULT_SIZE: boolean;\n}\n\n/**\n * Mixes size-awareness into a Lit `ReactiveElement` subclass.\n *\n * ## Why NO_DEFAULT_SIZE is a static rather than a closure variable\n *\n * The original implementation captured `noDefaultSize` in a closure at call\n * time. That works when a component applies SizedMixin directly to a plain\n * base (e.g. `SizedMixin(SpectrumElement, { noDefaultSize: true })`), but\n * breaks silently when a component extends a base that is already SizedMixin'd.\n *\n * Consider InfieldButton extending ButtonBase:\n * - ButtonBase = SizedMixin(SpectrumElement, {}) — closure captures noDefaultSize=false\n * - InfieldButtonBase extends ButtonBase\n *\n * Even if a second SizedMixin wrapper is applied with noDefaultSize=true, calling\n * super.update() reaches the inner ButtonBase SizedMixin, whose update() still\n * reads noDefaultSize=false from its closure and writes size=\"m\" to the DOM.\n * Likewise, when a parent calls removeAttribute('size'), the inherited setter\n * reads the inner closure's fallbackSize='m' and immediately re-sets the attribute.\n *\n * Making NO_DEFAULT_SIZE a static property solves both problems: the setter and\n * update() read this.constructor.NO_DEFAULT_SIZE, which follows the prototype\n * chain to the leaf class. A subclass like InfieldButtonBase only needs to\n * declare `static override readonly NO_DEFAULT_SIZE = true` — no mixin\n * re-wrapping, no lifecycle interception, and the correct value is read by every\n * SizedMixin layer in the chain.\n */\nexport function SizedMixin<T extends Constructor<ReactiveElement>>(\n constructor: T,\n {\n validSizes = [...DEFAULT_ELEMENT_SIZES],\n noDefaultSize,\n defaultSize = 'm',\n }: {\n validSizes?: readonly ElementSize[];\n noDefaultSize?: boolean;\n defaultSize?: ElementSize;\n } = {}\n): T & Constructor<SizedElementInterface> & SizedElementConstructor {\n class SizedElement extends constructor {\n /**\n * @internal\n */\n static readonly VALID_SIZES: readonly ElementSize[] = validSizes;\n\n /**\n * When true, the component does not auto-reflect a default size attribute.\n * The parent is expected to supply the size. Subclasses of an already-sized\n * base (e.g. InfieldButtonBase extends ButtonBase) can override this static\n * to opt out of the inherited base's auto-set behavior without re-wrapping\n * the mixin.\n *\n * @internal\n */\n static readonly NO_DEFAULT_SIZE: boolean = noDefaultSize ?? false;\n\n @property({ type: String })\n public get size(): ElementSize {\n return this._size || defaultSize;\n }\n\n public set size(value: ElementSize) {\n const sizedConstructor = this\n .constructor as unknown as SizedElementConstructor;\n const fallbackSize = sizedConstructor.NO_DEFAULT_SIZE\n ? null\n : defaultSize;\n const size = (value ? value.toLocaleLowerCase() : value) as ElementSize;\n const classValidSizes = sizedConstructor.VALID_SIZES;\n const validSize = (\n classValidSizes.includes(size) ? size : fallbackSize\n ) as ElementSize;\n if (validSize) {\n this.setAttribute('size', validSize);\n }\n if (this._size === validSize) {\n return;\n }\n const oldSize = this._size;\n this._size = validSize;\n this.requestUpdate('size', oldSize);\n }\n\n /** @internal */\n private _size: ElementSize | null = defaultSize;\n\n protected override update(changes: PropertyValues): void {\n if (\n !this.hasAttribute('size') &&\n !(this.constructor as unknown as SizedElementConstructor)\n .NO_DEFAULT_SIZE\n ) {\n this.setAttribute('size', this.size);\n }\n super.update(changes);\n }\n }\n return SizedElement;\n}\n"],"mappings":";;;AAoBA,IAAa,IAAgB;CAAC;CAAO;CAAM;CAAK;CAAK;CAAK;CAAM;CAAM,EAGzD,IAAwB;CACnC;CACA;CACA;CACA;CACD;AAuCD,SAAgB,EACd,GACA,EACE,gBAAa,CAAC,GAAG,EAAsB,EACvC,kBACA,iBAAc,QAKZ,EAAE,EAC4D;;CAClE,MAAM,UAAqB,EAAY;;6BA6CD;;EA5BpC,IACW,OAAoB;AAC7B,UAAO,KAAK,SAAS;;EAGvB,IAAW,KAAK,GAAoB;GAClC,IAAM,IAAmB,KACtB,aACG,IAAe,EAAiB,kBAClC,OACA,GACE,IAAQ,KAAQ,EAAM,mBAAmB,EAEzC,IADkB,EAAiB,YAEvB,SAAS,EAAK,GAAG,IAAO;AAK1C,OAHI,KACF,KAAK,aAAa,QAAQ,EAAU,EAElC,KAAK,UAAU,EACjB;GAEF,IAAM,IAAU,KAAK;AAErB,GADA,KAAK,QAAQ,GACb,KAAK,cAAc,QAAQ,EAAQ;;EAMrC,OAA0B,GAA+B;AAQvD,GANE,CAAC,KAAK,aAAa,OAAO,IAC1B,CAAE,KAAK,YACJ,mBAEH,KAAK,aAAa,QAAQ,KAAK,KAAK,EAEtC,MAAM,OAAO,EAAQ;;;AAGzB,+BAtDwD,uBAWX,KAAA,OAAiB,KAAjB,MAE1C,EAAS,EAAE,MAAM,QAAQ,CAAC,CAAA,EAAA,EAAA,WAAA,QAAA,KAAA,EAyCtB"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Whether dev-mode validation is active: `false` in production builds and in
|
|
14
|
+
* non-browser (SSR) environments, otherwise mirrors `window.__swc.DEBUG`.
|
|
15
|
+
*
|
|
16
|
+
* Use this to guard the *call site* of a warning whose condition or message is
|
|
17
|
+
* expensive to compute (for example a DOM traversal), so that work is skipped
|
|
18
|
+
* entirely when validation is off:
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* if (isDebug()) {
|
|
22
|
+
* this.warnAboutExpensiveThing(); // only traverses the DOM when validation runs
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* For cheap conditions, call `warnIf`/`validateEnum` directly; they already
|
|
27
|
+
* gate internally. This helper exists only to avoid paying call-site argument
|
|
28
|
+
* cost in the expensive cases. It checks `process.env.NODE_ENV` first so a
|
|
29
|
+
* bundler can dead-code-eliminate the guarded block in production, matching the
|
|
30
|
+
* other helpers in this file, and short-circuits when `window` is undefined so
|
|
31
|
+
* it is safe to call during server-side rendering.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isDebug(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Warns when `value` is not one of `valid`. Covers union-type/enum property
|
|
36
|
+
* validation (e.g. `variant`, `size`).
|
|
37
|
+
*
|
|
38
|
+
* @param element - The component instance the warning is attributed to.
|
|
39
|
+
* @param check - The enum check to perform.
|
|
40
|
+
* @param check.prop - The property name, for the warning message.
|
|
41
|
+
* @param check.value - The value received.
|
|
42
|
+
* @param check.valid - The allowed values.
|
|
43
|
+
* @param check.url - Documentation URL for the component.
|
|
44
|
+
* @param check.options - Passed through to `window.__swc.warn`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function validateEnum<T extends string>(element: HTMLElement, { prop, value, valid, url, options, }: {
|
|
47
|
+
prop: string;
|
|
48
|
+
value: string;
|
|
49
|
+
valid: readonly T[];
|
|
50
|
+
url: string;
|
|
51
|
+
options?: SWCWarningOptions;
|
|
52
|
+
}): void;
|
|
53
|
+
/**
|
|
54
|
+
* Warns when `condition` is true. The general-purpose validation primitive:
|
|
55
|
+
* covers required properties, conditionally required properties, mutually
|
|
56
|
+
* exclusive/no-effect property combinations, and any component-specific
|
|
57
|
+
* quirk that doesn't fit the other helpers here.
|
|
58
|
+
*
|
|
59
|
+
* @param element - The component instance the warning is attributed to.
|
|
60
|
+
* @param condition - Warn when this is true.
|
|
61
|
+
* @param message - The warning message.
|
|
62
|
+
* @param url - Documentation URL for the component.
|
|
63
|
+
* @param options - Passed through to `window.__swc.warn`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function warnIf(element: HTMLElement, condition: boolean, message: string, url: string, options?: SWCWarningOptions): void;
|
|
66
|
+
/**
|
|
67
|
+
* Warns when a slot has no assigned nodes. Covers required-slot validation.
|
|
68
|
+
*
|
|
69
|
+
* @param element - The component instance the warning is attributed to.
|
|
70
|
+
* @param slot - The slot element to check (`null`/`undefined` counts as empty).
|
|
71
|
+
* @param slotName - The slot's `name` attribute (or `"default"`), for the message.
|
|
72
|
+
* @param url - Documentation URL for the component.
|
|
73
|
+
* @param options - Passed through to `window.__swc.warn`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function validateRequiredSlot(element: HTMLElement, slot: HTMLSlotElement | null | undefined, slotName: string, url: string, options?: SWCWarningOptions): void;
|
|
76
|
+
/**
|
|
77
|
+
* Warns for each assigned element in `slot` whose tag name is not in
|
|
78
|
+
* `allowedTagNames`. Covers allowed-children slot validation (e.g. a heading
|
|
79
|
+
* slot that only accepts `<h2>`-`<h6>`).
|
|
80
|
+
*
|
|
81
|
+
* @param element - The component instance the warning is attributed to.
|
|
82
|
+
* @param slot - The slot element to check.
|
|
83
|
+
* @param allowedTagNames - Allowed tag names (case-insensitive, e.g. `['h2', 'h3']`).
|
|
84
|
+
* @param slotName - The slot's `name` attribute (or `"default"`), for the message.
|
|
85
|
+
* @param url - Documentation URL for the component.
|
|
86
|
+
* @param options - Passed through to `window.__swc.warn`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function validateAllowedChildren(element: HTMLElement, slot: HTMLSlotElement | null | undefined, allowedTagNames: readonly string[], slotName: string, url: string, options?: SWCWarningOptions): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region utils/dev-validation.ts
|
|
2
|
+
function e(e, t, n, r) {
|
|
3
|
+
var i;
|
|
4
|
+
(i = window.__swc) != null && i.DEBUG && window.__swc.warn(e, t, n, r);
|
|
5
|
+
}
|
|
6
|
+
function t() {
|
|
7
|
+
var e;
|
|
8
|
+
return process.env.NODE_ENV === "production" || typeof window > "u" ? !1 : !!((e = window.__swc) != null && e.DEBUG);
|
|
9
|
+
}
|
|
10
|
+
function n(t, { prop: n, value: r, valid: i, url: a, options: o }) {
|
|
11
|
+
process.env.NODE_ENV !== "production" && (i.includes(r) || e(t, `<${t.localName}> expects "${n}" to be one of: ${i.join(", ")}. Received "${r}".`, a, {
|
|
12
|
+
issues: [`${n}="${r}"`],
|
|
13
|
+
...o
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
function r(t, n, r, i, a) {
|
|
17
|
+
process.env.NODE_ENV !== "production" && n && e(t, r, i, a);
|
|
18
|
+
}
|
|
19
|
+
function i(t, n, r, i, a) {
|
|
20
|
+
process.env.NODE_ENV !== "production" && (!n || n.assignedNodes({ flatten: !0 }).length === 0) && e(t, `<${t.localName}> requires content in the "${r}" slot.`, i, a);
|
|
21
|
+
}
|
|
22
|
+
function a(t, n, r, i, a, o) {
|
|
23
|
+
if (process.env.NODE_ENV === "production" || !n) return;
|
|
24
|
+
let s = r.map((e) => e.toUpperCase()), c = r.map((e) => `<${e}>`).join(", ");
|
|
25
|
+
for (let r of n.assignedElements()) s.includes(r.tagName) || e(t, `<${t.localName}> "${i}" slot received a <${r.tagName.toLowerCase()}> element. Only ${c} elements are allowed.`, a, {
|
|
26
|
+
issues: [`${i} slot: <${r.tagName.toLowerCase()}>`],
|
|
27
|
+
...o
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { t as isDebug, a as validateAllowedChildren, n as validateEnum, i as validateRequiredSlot, r as warnIf };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=dev-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-validation.js","names":[],"sources":["../../utils/dev-validation.ts"],"sourcesContent":["/**\n * Copyright 2026 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/**\n * The single place \"warn in development\" lives: the `DEBUG` gate plus the\n * `window.__swc.warn` call. Every public helper below computes its own\n * predicate and message, then defers the actual emit to this primitive, so\n * there is one source of truth for how a warning is gated and dispatched.\n *\n * Note: this deliberately does **not** include the\n * `process.env.NODE_ENV === 'production'` guard. That guard must stay in each\n * public helper so a bundler can dead-code-eliminate the message construction\n * inside that function for production builds; centralizing it here would leave\n * each caller's message-building in the production bundle.\n *\n * @param element - The component instance the warning is attributed to.\n * @param message - The warning message.\n * @param url - Documentation URL for the component.\n * @param options - Passed through to `window.__swc.warn`.\n */\nfunction emitWarning(\n element: HTMLElement,\n message: string,\n url: string,\n options?: SWCWarningOptions\n): void {\n if (!window.__swc?.DEBUG) {\n return;\n }\n window.__swc.warn(element, message, url, options);\n}\n\n/**\n * Whether dev-mode validation is active: `false` in production builds and in\n * non-browser (SSR) environments, otherwise mirrors `window.__swc.DEBUG`.\n *\n * Use this to guard the *call site* of a warning whose condition or message is\n * expensive to compute (for example a DOM traversal), so that work is skipped\n * entirely when validation is off:\n *\n * ```ts\n * if (isDebug()) {\n * this.warnAboutExpensiveThing(); // only traverses the DOM when validation runs\n * }\n * ```\n *\n * For cheap conditions, call `warnIf`/`validateEnum` directly; they already\n * gate internally. This helper exists only to avoid paying call-site argument\n * cost in the expensive cases. It checks `process.env.NODE_ENV` first so a\n * bundler can dead-code-eliminate the guarded block in production, matching the\n * other helpers in this file, and short-circuits when `window` is undefined so\n * it is safe to call during server-side rendering.\n */\nexport function isDebug(): boolean {\n if (process.env.NODE_ENV === 'production') {\n return false;\n }\n if (typeof window === 'undefined') {\n return false;\n }\n return Boolean(window.__swc?.DEBUG);\n}\n\n/**\n * Warns when `value` is not one of `valid`. Covers union-type/enum property\n * validation (e.g. `variant`, `size`).\n *\n * @param element - The component instance the warning is attributed to.\n * @param check - The enum check to perform.\n * @param check.prop - The property name, for the warning message.\n * @param check.value - The value received.\n * @param check.valid - The allowed values.\n * @param check.url - Documentation URL for the component.\n * @param check.options - Passed through to `window.__swc.warn`.\n */\nexport function validateEnum<T extends string>(\n element: HTMLElement,\n {\n prop,\n value,\n valid,\n url,\n options,\n }: {\n prop: string;\n value: string;\n valid: readonly T[];\n url: string;\n options?: SWCWarningOptions;\n }\n): void {\n if (process.env.NODE_ENV === 'production') {\n return;\n }\n if ((valid as readonly string[]).includes(value)) {\n return;\n }\n emitWarning(\n element,\n `<${element.localName}> expects \"${prop}\" to be one of: ${valid.join(', ')}. Received \"${value}\".`,\n url,\n { issues: [`${prop}=\"${value}\"`], ...options }\n );\n}\n\n/**\n * Warns when `condition` is true. The general-purpose validation primitive:\n * covers required properties, conditionally required properties, mutually\n * exclusive/no-effect property combinations, and any component-specific\n * quirk that doesn't fit the other helpers here.\n *\n * @param element - The component instance the warning is attributed to.\n * @param condition - Warn when this is true.\n * @param message - The warning message.\n * @param url - Documentation URL for the component.\n * @param options - Passed through to `window.__swc.warn`.\n */\nexport function warnIf(\n element: HTMLElement,\n condition: boolean,\n message: string,\n url: string,\n options?: SWCWarningOptions\n): void {\n if (process.env.NODE_ENV === 'production') {\n return;\n }\n if (!condition) {\n return;\n }\n emitWarning(element, message, url, options);\n}\n\n/**\n * Warns when a slot has no assigned nodes. Covers required-slot validation.\n *\n * @param element - The component instance the warning is attributed to.\n * @param slot - The slot element to check (`null`/`undefined` counts as empty).\n * @param slotName - The slot's `name` attribute (or `\"default\"`), for the message.\n * @param url - Documentation URL for the component.\n * @param options - Passed through to `window.__swc.warn`.\n */\nexport function validateRequiredSlot(\n element: HTMLElement,\n slot: HTMLSlotElement | null | undefined,\n slotName: string,\n url: string,\n options?: SWCWarningOptions\n): void {\n if (process.env.NODE_ENV === 'production') {\n return;\n }\n const isEmpty = !slot || slot.assignedNodes({ flatten: true }).length === 0;\n if (!isEmpty) {\n return;\n }\n emitWarning(\n element,\n `<${element.localName}> requires content in the \"${slotName}\" slot.`,\n url,\n options\n );\n}\n\n/**\n * Warns for each assigned element in `slot` whose tag name is not in\n * `allowedTagNames`. Covers allowed-children slot validation (e.g. a heading\n * slot that only accepts `<h2>`-`<h6>`).\n *\n * @param element - The component instance the warning is attributed to.\n * @param slot - The slot element to check.\n * @param allowedTagNames - Allowed tag names (case-insensitive, e.g. `['h2', 'h3']`).\n * @param slotName - The slot's `name` attribute (or `\"default\"`), for the message.\n * @param url - Documentation URL for the component.\n * @param options - Passed through to `window.__swc.warn`.\n */\nexport function validateAllowedChildren(\n element: HTMLElement,\n slot: HTMLSlotElement | null | undefined,\n allowedTagNames: readonly string[],\n slotName: string,\n url: string,\n options?: SWCWarningOptions\n): void {\n if (process.env.NODE_ENV === 'production') {\n return;\n }\n if (!slot) {\n return;\n }\n const allowed = allowedTagNames.map((tag) => tag.toUpperCase());\n const allowedList = allowedTagNames.map((tag) => `<${tag}>`).join(', ');\n for (const el of slot.assignedElements()) {\n if (!allowed.includes(el.tagName)) {\n emitWarning(\n element,\n `<${element.localName}> \"${slotName}\" slot received a <${el.tagName.toLowerCase()}> element. Only ${allowedList} elements are allowed.`,\n url,\n {\n issues: [`${slotName} slot: <${el.tagName.toLowerCase()}>`],\n ...options,\n }\n );\n }\n }\n}\n"],"mappings":";AA6BA,SAAS,EACP,GACA,GACA,GACA,GACM;;AACF,EAAA,IAAC,OAAO,UAAA,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AAU,EAAG,QAAQ,aAAa,CAAC,GAAG;EAC3D,GAAG;EACJ,CACF"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -12,9 +12,11 @@
|
|
|
12
12
|
export { physicalSide } from './actual-placement.js';
|
|
13
13
|
export { capitalize } from './capitalize.js';
|
|
14
14
|
export { deepContains } from './deep-contains.js';
|
|
15
|
+
export { isDebug, validateAllowedChildren, validateEnum, validateRequiredSlot, warnIf, } from './dev-validation.js';
|
|
15
16
|
export { isTopDismissible, registerDismissible, unregisterDismissible, } from './dismissible-stack.js';
|
|
16
17
|
export { getActiveElement } from './get-active-element.js';
|
|
17
18
|
export { focusableSelector, tabbableSelector } from './focusable-selectors.js';
|
|
18
19
|
export { getLabelFromSlot } from './get-label-from-slot.js';
|
|
20
|
+
export { isFocusVisibleInTree } from './is-focus-visible-in-tree.js';
|
|
19
21
|
export { resolveTrigger, type ResolvedTrigger, type ResolveTriggerOptions, } from './resolve-trigger.js';
|
|
20
22
|
export { hasActiveTransition, maxTransitionDurationMs, runAfterTransition, } from './transition.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { isTopDismissible as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
1
|
+
import { physicalSide as e } from "./actual-placement.js";
|
|
2
|
+
import { capitalize as t } from "./capitalize.js";
|
|
3
|
+
import { deepContains as n } from "./deep-contains.js";
|
|
4
|
+
import { isDebug as r, validateAllowedChildren as i, validateEnum as a, validateRequiredSlot as o, warnIf as s } from "./dev-validation.js";
|
|
5
|
+
import { isTopDismissible as c, registerDismissible as l, unregisterDismissible as u } from "./dismissible-stack.js";
|
|
6
|
+
import { getActiveElement as d } from "./get-active-element.js";
|
|
7
|
+
import { focusableSelector as f, tabbableSelector as p } from "./focusable-selectors.js";
|
|
8
|
+
import { getLabelFromSlot as m } from "./get-label-from-slot.js";
|
|
9
|
+
import { isFocusVisibleInTree as h } from "./is-focus-visible-in-tree.js";
|
|
10
|
+
import { resolveTrigger as g } from "./resolve-trigger.js";
|
|
11
|
+
import { hasActiveTransition as _, maxTransitionDurationMs as v, runAfterTransition as y } from "./transition.js";
|
|
12
|
+
export { t as capitalize, n as deepContains, f as focusableSelector, d as getActiveElement, m as getLabelFromSlot, _ as hasActiveTransition, r as isDebug, h as isFocusVisibleInTree, c as isTopDismissible, v as maxTransitionDurationMs, e as physicalSide, l as registerDismissible, g as resolveTrigger, y as runAfterTransition, p as tabbableSelector, u as unregisterDismissible, i as validateAllowedChildren, a as validateEnum, o as validateRequiredSlot, s as warnIf };
|