@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.
Files changed (136) hide show
  1. package/CHANGELOG.md +75 -9
  2. package/dist/components/accordion/Accordion.base.js +28 -22
  3. package/dist/components/accordion/Accordion.base.js.map +1 -1
  4. package/dist/components/accordion/AccordionItem.base.d.ts +16 -6
  5. package/dist/components/accordion/AccordionItem.base.js +6 -3
  6. package/dist/components/accordion/AccordionItem.base.js.map +1 -1
  7. package/dist/components/action-group/ActionGroup.base.d.ts +108 -0
  8. package/dist/components/action-group/ActionGroup.base.js +53 -0
  9. package/dist/components/action-group/ActionGroup.base.js.map +1 -0
  10. package/dist/components/action-group/ActionGroup.types.d.ts +17 -0
  11. package/dist/components/action-group/ActionGroup.types.js +12 -0
  12. package/dist/components/action-group/ActionGroup.types.js.map +1 -0
  13. package/dist/components/action-group/index.d.ts +13 -0
  14. package/dist/components/action-group/index.js +3 -0
  15. package/dist/components/alert-banner/AlertBanner.base.js +11 -10
  16. package/dist/components/alert-banner/AlertBanner.base.js.map +1 -1
  17. package/dist/components/asset/Asset.base.d.ts +1 -1
  18. package/dist/components/asset/Asset.base.js +14 -8
  19. package/dist/components/asset/Asset.base.js.map +1 -1
  20. package/dist/components/avatar/Avatar.base.js +18 -22
  21. package/dist/components/avatar/Avatar.base.js.map +1 -1
  22. package/dist/components/badge/Badge.base.d.ts +24 -8
  23. package/dist/components/badge/Badge.base.js +22 -17
  24. package/dist/components/badge/Badge.base.js.map +1 -1
  25. package/dist/components/button/Button.base.d.ts +20 -10
  26. package/dist/components/button/Button.base.js +17 -12
  27. package/dist/components/button/Button.base.js.map +1 -1
  28. package/dist/components/button-group/ButtonGroup.base.js +19 -12
  29. package/dist/components/button-group/ButtonGroup.base.js.map +1 -1
  30. package/dist/components/card/Card.base.d.ts +95 -46
  31. package/dist/components/card/Card.base.js +71 -23
  32. package/dist/components/card/Card.base.js.map +1 -1
  33. package/dist/components/card/Card.types.d.ts +1 -0
  34. package/dist/components/card/Card.types.js +2 -2
  35. package/dist/components/card/Card.types.js.map +1 -1
  36. package/dist/components/card/index.js +3 -3
  37. package/dist/components/divider/Divider.base.js +13 -8
  38. package/dist/components/divider/Divider.base.js.map +1 -1
  39. package/dist/components/dropzone/Dropzone.base.d.ts +74 -0
  40. package/dist/components/dropzone/Dropzone.base.js +82 -0
  41. package/dist/components/dropzone/Dropzone.base.js.map +1 -0
  42. package/dist/components/dropzone/Dropzone.types.d.ts +43 -0
  43. package/dist/components/dropzone/Dropzone.types.js +15 -0
  44. package/dist/components/dropzone/Dropzone.types.js.map +1 -0
  45. package/dist/components/dropzone/index.d.ts +13 -0
  46. package/dist/components/dropzone/index.js +3 -0
  47. package/dist/components/icon/Icon.base.d.ts +11 -7
  48. package/dist/components/icon/Icon.base.js +13 -20
  49. package/dist/components/icon/Icon.base.js.map +1 -1
  50. package/dist/components/illustrated-message/IllustratedMessage.base.d.ts +22 -8
  51. package/dist/components/illustrated-message/IllustratedMessage.base.js +33 -20
  52. package/dist/components/illustrated-message/IllustratedMessage.base.js.map +1 -1
  53. package/dist/components/infield-button/InfieldButton.base.d.ts +28 -0
  54. package/dist/components/infield-button/InfieldButton.base.js +22 -0
  55. package/dist/components/infield-button/InfieldButton.base.js.map +1 -0
  56. package/dist/components/infield-button/InfieldButton.types.d.ts +13 -0
  57. package/dist/components/infield-button/InfieldButton.types.js +11 -0
  58. package/dist/components/infield-button/InfieldButton.types.js.map +1 -0
  59. package/dist/components/infield-button/index.d.ts +13 -0
  60. package/dist/components/infield-button/index.js +3 -0
  61. package/dist/components/meter/Meter.base.js +11 -9
  62. package/dist/components/meter/Meter.base.js.map +1 -1
  63. package/dist/components/popover/Popover.base.js +46 -42
  64. package/dist/components/popover/Popover.base.js.map +1 -1
  65. package/dist/components/progress-circle/ProgressCircle.base.d.ts +0 -1
  66. package/dist/components/progress-circle/ProgressCircle.base.js +26 -22
  67. package/dist/components/progress-circle/ProgressCircle.base.js.map +1 -1
  68. package/dist/components/status-light/StatusLight.base.d.ts +1 -1
  69. package/dist/components/status-light/StatusLight.base.js +12 -9
  70. package/dist/components/status-light/StatusLight.base.js.map +1 -1
  71. package/dist/components/tabs/Tabs.base.js +44 -32
  72. package/dist/components/tabs/Tabs.base.js.map +1 -1
  73. package/dist/components/tooltip/Tooltip.base.js +57 -22
  74. package/dist/components/tooltip/Tooltip.base.js.map +1 -1
  75. package/dist/controllers/color-controller/src/color-controller.js +45 -44
  76. package/dist/controllers/color-controller/src/color-controller.js.map +1 -1
  77. package/dist/controllers/drag-and-drop-controller/index.d.ts +12 -0
  78. package/dist/controllers/drag-and-drop-controller/index.js +2 -0
  79. package/dist/controllers/drag-and-drop-controller/src/drag-and-drop-controller.d.ts +68 -0
  80. package/dist/controllers/drag-and-drop-controller/src/drag-and-drop-controller.js +56 -0
  81. package/dist/controllers/drag-and-drop-controller/src/drag-and-drop-controller.js.map +1 -0
  82. package/dist/controllers/index.d.ts +4 -1
  83. package/dist/controllers/index.js +14 -11
  84. package/dist/controllers/page-scroll-lock-controller/index.d.ts +12 -0
  85. package/dist/controllers/page-scroll-lock-controller/index.js +2 -0
  86. package/dist/controllers/{page-scroll-lock.js → page-scroll-lock-controller/src/page-scroll-lock.js} +1 -1
  87. package/dist/controllers/page-scroll-lock-controller/src/page-scroll-lock.js.map +1 -0
  88. package/dist/controllers/slot-presence-controller/index.d.ts +12 -0
  89. package/dist/controllers/slot-presence-controller/index.js +2 -0
  90. package/dist/controllers/slot-presence-controller/src/slot-presence-controller.d.ts +57 -0
  91. package/dist/controllers/slot-presence-controller/src/slot-presence-controller.js +44 -0
  92. package/dist/controllers/slot-presence-controller/src/slot-presence-controller.js.map +1 -0
  93. package/dist/controllers/slot-text-controller/index.d.ts +12 -0
  94. package/dist/controllers/slot-text-controller/index.js +2 -0
  95. package/dist/controllers/slot-text-controller/src/slot-text-controller.d.ts +92 -0
  96. package/dist/controllers/slot-text-controller/src/slot-text-controller.js +53 -0
  97. package/dist/controllers/slot-text-controller/src/slot-text-controller.js.map +1 -0
  98. package/dist/element/index.d.ts +1 -1
  99. package/dist/element/index.js +2 -2
  100. package/dist/element/spectrum-element.d.ts +58 -15
  101. package/dist/element/spectrum-element.js +55 -36
  102. package/dist/element/spectrum-element.js.map +1 -1
  103. package/dist/element/version.d.ts +2 -2
  104. package/dist/element/version.js +1 -1
  105. package/dist/element/version.js.map +1 -1
  106. package/dist/mixins/index.d.ts +0 -2
  107. package/dist/mixins/index.js +4 -6
  108. package/dist/mixins/linear-progress-mixin.d.ts +1 -2
  109. package/dist/mixins/linear-progress-mixin.js +35 -34
  110. package/dist/mixins/linear-progress-mixin.js.map +1 -1
  111. package/dist/mixins/pending-mixin.js +12 -11
  112. package/dist/mixins/pending-mixin.js.map +1 -1
  113. package/dist/mixins/sized-mixin.d.ts +28 -0
  114. package/dist/mixins/sized-mixin.js +6 -6
  115. package/dist/mixins/sized-mixin.js.map +1 -1
  116. package/dist/utils/dev-validation.d.ts +88 -0
  117. package/dist/utils/dev-validation.js +33 -0
  118. package/dist/utils/dev-validation.js.map +1 -0
  119. package/dist/utils/index.d.ts +2 -0
  120. package/dist/utils/index.js +12 -10
  121. package/dist/utils/is-focus-visible-in-tree.d.ts +33 -0
  122. package/dist/utils/is-focus-visible-in-tree.js +11 -0
  123. package/dist/utils/is-focus-visible-in-tree.js.map +1 -0
  124. package/package.json +68 -15
  125. package/dist/_virtual/_@oxc-project_runtime@0.124.0/helpers/defineProperty.js +0 -12
  126. package/dist/_virtual/_@oxc-project_runtime@0.124.0/helpers/toPrimitive.js +0 -14
  127. package/dist/_virtual/_@oxc-project_runtime@0.124.0/helpers/toPropertyKey.js +0 -9
  128. package/dist/_virtual/_@oxc-project_runtime@0.124.0/helpers/typeof.js +0 -11
  129. package/dist/controllers/page-scroll-lock.js.map +0 -1
  130. package/dist/mixins/observe-slot-presence.d.ts +0 -12
  131. package/dist/mixins/observe-slot-presence.js +0 -40
  132. package/dist/mixins/observe-slot-presence.js.map +0 -1
  133. package/dist/mixins/observe-slot-text.d.ts +0 -11
  134. package/dist/mixins/observe-slot-text.js +0 -60
  135. package/dist/mixins/observe-slot-text.js.map +0 -1
  136. /package/dist/controllers/{page-scroll-lock.d.ts → page-scroll-lock-controller/src/page-scroll-lock.d.ts} +0 -0
@@ -1,6 +1,7 @@
1
- import e from "colorjs.io";
1
+ import { isDebug as e } from "@adobe/spectrum-wc-core/utils/index.js";
2
+ import t from "colorjs.io";
2
3
  //#region controllers/color-controller/src/color-controller.ts
3
- var t = [
4
+ var n = [
4
5
  /rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d*\.?\d+)\s*\)/i,
5
6
  /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/i,
6
7
  /^rgba\s+(\d{1,3})\s+(\d{1,3})\s+(\d{1,3})\s+(0|0?\.\d+|1)\s*$/i,
@@ -9,30 +10,30 @@ var t = [
9
10
  /^rgb\(\s*(\d{1,3})\s+(\d{1,3})\s+(\d{1,3})\s*\)$/i,
10
11
  /rgb\(\s*(100|[0-9]{1,2}%)\s*,\s*(100|[0-9]{1,2}%)\s*,\s*(100|[0-9]{1,2}%)\s*\)/i,
11
12
  /rgba\(\s*(100|[0-9]{1,2})%\s*,\s*(100|[0-9]{1,2})%\s*,\s*(100|[0-9]{1,2})%\s*,\s*(\d*\.?\d+)\s*\)/i
12
- ], n = [
13
+ ], r = [
13
14
  /hsla\(\s*(\d{1,3})\s*,\s*(\d{1,3}%?)\s*,\s*(\d{1,3}%?)\s*,\s*(\d*\.?\d+)\s*\)/i,
14
15
  /hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3}%?)\s*,\s*(\d{1,3}%?)\s*\)/i,
15
16
  /^hsla\s+(\d{1,3})\s+(\d{1,3}%?)\s+(\d{1,3}%?)\s+(\d*\.?\d+)\s*$/i,
16
17
  /^hsl\s+(\d{1,3})\s+(\d{1,3}%?)\s+(\d{1,3}%?)\s*$/i,
17
18
  /^hsla\(\s*(\d{1,3})\s+(\d{1,3}%?)\s+(\d{1,3}%?)\s+(\d*\.?\d+)\s*\)$/i,
18
19
  /^hsl\(\s*(\d{1,3})\s+(\d{1,3}%?)\s+(\d{1,3}%?)\s*\)$/i
19
- ], r = [
20
+ ], i = [
20
21
  /hsva\(\s*(\d{1,3})\s*,\s*(\d{1,3}%?)\s*,\s*(\d{1,3}%?)\s*,\s*(\d*\.?\d+)\s*\)/i,
21
22
  /hsv\(\s*(\d{1,3})\s*,\s*(\d{1,3}%?)\s*,\s*(\d{1,3}%?)\s*\)/i,
22
23
  /^hsva\s+(\d{1,3})\s+(\d{1,3}%?)\s+(\d{1,3}%?)\s+(\d*\.?\d+)\s*$/i,
23
24
  /^hsv\s+(\d{1,3})\s+(\d{1,3}%?)\s+(\d{1,3}%?)\s*$/i,
24
25
  /^hsva\(\s*(\d{1,3})\s+(\d{1,3}%?)\s+(\d{1,3}%?)\s+(\d*\.?\d+)\s*\)$/i,
25
26
  /^hsv\(\s*(\d{1,3})\s+(\d{1,3}%?)\s+(\d{1,3}%?)\s*\)$/i
26
- ], i = [/^#([A-Fa-f0-9]{6})([A-Fa-f0-9]{2})?$/, /^#([A-Fa-f0-9]{3})([A-Fa-f0-9]{1})?$/], a = [
27
+ ], a = [/^#([A-Fa-f0-9]{6})([A-Fa-f0-9]{2})?$/, /^#([A-Fa-f0-9]{3})([A-Fa-f0-9]{1})?$/], o = [
27
28
  "srgb",
28
29
  "hsv",
29
30
  "hsl"
30
- ], o = "https://github.com/WICG/color-api/issues/196";
31
- function s(e, t, n) {
32
- var r;
33
- typeof window > "u" || !((r = window.__swc) != null && r.DEBUG) || window.__swc.warn(e, t, o, { issues: [n instanceof Error ? n.message : "Unknown error"] });
31
+ ], s = "https://github.com/WICG/color-api/issues/196";
32
+ function c(t, n, r) {
33
+ var i;
34
+ e() && ((i = window.__swc) == null || i.warn(t, n, s, { issues: [r instanceof Error ? r.message : "Unknown error"] }));
34
35
  }
35
- function c(e) {
36
+ function l(e) {
36
37
  let { h: t, s: n, l: r, v: i, r: a, g: o, b: s } = e;
37
38
  if (t !== void 0 && n !== void 0) {
38
39
  if (r !== void 0) return "hsl";
@@ -40,12 +41,12 @@ function c(e) {
40
41
  }
41
42
  if (a !== void 0 && o !== void 0 && s !== void 0) return "srgb";
42
43
  }
43
- var l = class {
44
+ var u = class {
44
45
  get color() {
45
46
  return this._color;
46
47
  }
47
48
  validateColorString(e) {
48
- var a, o, s, c;
49
+ var t, o, s, c;
49
50
  let l = {
50
51
  spaceId: null,
51
52
  coords: [
@@ -55,7 +56,7 @@ var l = class {
55
56
  ],
56
57
  isValid: !1,
57
58
  alpha: 1
58
- }, u = (a = t.find((t) => t.test(e))) == null ? void 0 : a.exec(e), d = (o = n.find((t) => t.test(e))) == null ? void 0 : o.exec(e), f = (s = r.find((t) => t.test(e))) == null ? void 0 : s.exec(e), p = (c = i.find((t) => t.test(e))) == null ? void 0 : c.exec(e);
59
+ }, u = (t = n.find((t) => t.test(e))) == null ? void 0 : t.exec(e), d = (o = r.find((t) => t.test(e))) == null ? void 0 : o.exec(e), f = (s = i.find((t) => t.test(e))) == null ? void 0 : s.exec(e), p = (c = a.find((t) => t.test(e))) == null ? void 0 : c.exec(e);
59
60
  if (u) {
60
61
  let [, e, t, n, r] = u.filter((e) => typeof e == "string"), i = r === void 0 ? 1 : Number(r), a = (e) => e.includes("%") ? Number(e.replace("%", "")) / 100 : Number(e) / 255, o = a(e), s = a(t), c = a(n);
61
62
  l.spaceId = "srgb", l.coords = [
@@ -109,46 +110,46 @@ var l = class {
109
110
  let { r: n, g: r, b: i } = this._color.to("srgb").srgb, a = this._color.alpha, o = (e) => Math.round(e * 255).toString(16).padStart(2, "0"), s = o(n), c = o(r), l = o(i), u = o(a);
110
111
  return `${e ? "#" : ""}${s}${c}${l}${t ? u : ""}`;
111
112
  }
112
- set color(t) {
113
- this._colorOrigin = t;
113
+ set color(e) {
114
+ this._colorOrigin = e;
114
115
  let n;
115
- if (typeof t == "string") {
116
- let r = this.validateColorString(t);
116
+ if (typeof e == "string") {
117
+ let r = this.validateColorString(e);
117
118
  if (r.isValid) {
118
- let [t, i, a] = r.coords;
119
- n = new e(`${r.spaceId}`, [
120
- t,
119
+ let [e, i, a] = r.coords;
120
+ n = new t(`${r.spaceId}`, [
121
+ e,
121
122
  i,
122
123
  a
123
124
  ], r.alpha);
124
125
  } else try {
125
- e.parse(t);
126
+ t.parse(e);
126
127
  } catch (r) {
127
- s(this.host, `Failed to parse color: ${t}`, r);
128
+ c(this.host, `Failed to parse color: ${e}`, r);
128
129
  try {
129
- n = new e(`#${t}`);
130
- } catch (e) {
131
- s(this.host, `Failed to parse color as hex: ${t}`, e);
130
+ n = new t(`#${e}`);
131
+ } catch (t) {
132
+ c(this.host, `Failed to parse color as hex: ${e}`, t);
132
133
  return;
133
134
  }
134
135
  }
135
- } else if (t instanceof e) n = t;
136
- else if (!Array.isArray(t)) {
137
- let { h: r, s: i, l: a, v: o, r: s, g: c, b: l, a: u } = t;
136
+ } else if (e instanceof t) n = e;
137
+ else if (!Array.isArray(e)) {
138
+ let { h: r, s: i, l: a, v: o, r: s, g: c, b: l, a: u } = e;
138
139
  if (r !== void 0 && i !== void 0) {
139
- let t = a == null ? o : a;
140
- n = new e(a === void 0 ? "hsv" : "hsl", [
140
+ let e = a == null ? o : a;
141
+ n = new t(a === void 0 ? "hsv" : "hsl", [
141
142
  parseFloat(`${r}`),
142
143
  typeof i == "string" ? parseFloat(i) : i * 100,
143
- typeof t == "string" ? parseFloat(t) : t * 100
144
+ typeof e == "string" ? parseFloat(e) : e * 100
144
145
  ], parseFloat(`${u == null ? "1" : u}`));
145
- } else s !== void 0 && c !== void 0 && l !== void 0 && (n = new e("srgb", [
146
+ } else s !== void 0 && c !== void 0 && l !== void 0 && (n = new t("srgb", [
146
147
  parseFloat(`${s}`) / 255,
147
148
  parseFloat(`${c}`) / 255,
148
149
  parseFloat(`${l}`) / 255
149
150
  ], parseFloat(`${u == null ? "1" : u}`)));
150
151
  }
151
- n || (n = new e(t)), this.manageAs ? this._color = n.to(this.manageAs) : this._color = n, this.host.requestUpdate();
152
+ n || (n = new t(e)), this.manageAs ? this._color = n.to(this.manageAs) : this._color = n, this.host.requestUpdate();
152
153
  }
153
154
  get colorValue() {
154
155
  if (typeof this._colorOrigin == "string") {
@@ -176,14 +177,14 @@ var l = class {
176
177
  }
177
178
  }
178
179
  }
179
- let t;
180
+ let e;
180
181
  if (this._colorOrigin) try {
181
- ({spaceId: t} = new e(this._colorOrigin));
182
- } catch (e) {
183
- s(this.host, `Failed to parse color as default color types: ${JSON.stringify(this._colorOrigin)}`, e), t = c(this._colorOrigin);
182
+ ({spaceId: e} = new t(this._colorOrigin));
183
+ } catch (t) {
184
+ c(this.host, `Failed to parse color as default color types: ${JSON.stringify(this._colorOrigin)}`, t), e = l(this._colorOrigin);
184
185
  }
185
- else ({spaceId: t} = this.color);
186
- switch (t) {
186
+ else ({spaceId: e} = this.color);
187
+ switch (e) {
187
188
  case "hsv": {
188
189
  let { h: e, s: t, v: n } = this._color.to("hsv").hsv;
189
190
  return {
@@ -225,15 +226,15 @@ var l = class {
225
226
  set hue(e) {
226
227
  this._color.set("h", e), this.host.requestUpdate();
227
228
  }
228
- constructor(t, { manageAs: n } = {}) {
229
- this._color = new e("hsv", [
229
+ constructor(e, { manageAs: n } = {}) {
230
+ this._color = new t("hsv", [
230
231
  0,
231
232
  100,
232
233
  100
233
- ], 1), this.host = t, this.manageAs = n;
234
+ ], 1), this.host = e, this.manageAs = n;
234
235
  }
235
236
  getColor(e) {
236
- if (typeof e == "string" && !a.includes(e)) throw Error("not a valid format");
237
+ if (typeof e == "string" && !o.includes(e)) throw Error("not a valid format");
237
238
  return this._color.to(e);
238
239
  }
239
240
  getHslString() {
@@ -247,6 +248,6 @@ var l = class {
247
248
  }
248
249
  };
249
250
  //#endregion
250
- export { l as ColorController };
251
+ export { u as ColorController };
251
252
 
252
253
  //# sourceMappingURL=color-controller.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"color-controller.js","names":[],"sources":["../../../../controllers/color-controller/src/color-controller.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 { ReactiveElement } from 'lit';\nimport type ColorSpace from 'colorjs.io';\nimport type { ColorObject, ColorTypes as DefaultColorTypes } from 'colorjs.io';\nimport Color from 'colorjs.io';\n\n// ─────────────────────────\n// TYPES\n// ─────────────────────────\n\n/**\n * Represents various color types that can be used in the application.\n *\n * This type can be one of the following:\n * - `DefaultColorTypes`: A predefined set of color types.\n * - An object representing an RGBA color with properties:\n * - `r`: Red component, can be a number or string.\n * - `g`: Green component, can be a number or string.\n * - `b`: Blue component, can be a number or string.\n * - `a` (optional): Alpha component, can be a number or string.\n * - An object representing an HSLA color with properties:\n * - `h`: Hue component, can be a number or string.\n * - `s`: Saturation component, can be a number or string.\n * - `l`: Lightness component, can be a number or string.\n * - `a` (optional): Alpha component, can be a number or string.\n * - An object representing an HSVA color with properties:\n * - `h`: Hue component, can be a number or string.\n * - `s`: Saturation component, can be a number or string.\n * - `v`: Value component, can be a number or string.\n * - `a` (optional): Alpha component, can be a number or string.\n */\ntype ColorTypes =\n | DefaultColorTypes\n | {\n r: number | string;\n g: number | string;\n b: number | string;\n a?: number | string;\n }\n | {\n h: number | string;\n s: number | string;\n l: number | string;\n a?: number | string;\n }\n | {\n h: number | string;\n s: number | string;\n v: number | string;\n a?: number | string;\n };\n\nexport type { Color, ColorTypes };\n\ntype ColorValidationResult = {\n spaceId: string | null;\n coords: number[];\n isValid: boolean;\n alpha: number;\n};\n\n/** Loose shape of a color object whose channel values may arrive as strings. */\ntype LooseColorObject = {\n h?: number | string;\n s?: number | string;\n l?: number | string;\n v?: number | string;\n r?: number | string;\n g?: number | string;\n b?: number | string;\n a?: number | string;\n};\n\n// ─────────────────────────\n// CONSTANTS\n// ─────────────────────────\n\n// These pattern arrays are static, so they live at module scope and are shared\n// across every controller instance and `validateColorString` call rather than\n// being rebuilt on each invocation.\n\n// RGB color formats\nconst RGB_REG_EXP_ARRAY = [\n // With commas\n /rgba\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d*\\.?\\d+)\\s*\\)/i, // rgba(r, g, b, a)\n /rgb\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*\\)/i, // rgb(r, g, b)\n\n // With spaces\n /^rgba\\s+(\\d{1,3})\\s+(\\d{1,3})\\s+(\\d{1,3})\\s+(0|0?\\.\\d+|1)\\s*$/i, // rgba r g b a\n /^rgb\\s+(\\d{1,3})\\s+(\\d{1,3})\\s+(\\d{1,3})\\s*$/i, // rgb r g b\n\n // Spaces inside parentheses\n /^rgba\\(\\s*(\\d{1,3})\\s+(\\d{1,3})\\s+(\\d{1,3})\\s+(\\d*\\.?\\d+)\\s*\\)$/i, // rgba(r g b a)\n /^rgb\\(\\s*(\\d{1,3})\\s+(\\d{1,3})\\s+(\\d{1,3})\\s*\\)$/i, // rgb(r g b)\n\n // Percentage values\n /rgb\\(\\s*(100|[0-9]{1,2}%)\\s*,\\s*(100|[0-9]{1,2}%)\\s*,\\s*(100|[0-9]{1,2}%)\\s*\\)/i, // rgb(r%, g%, b%)\n /rgba\\(\\s*(100|[0-9]{1,2})%\\s*,\\s*(100|[0-9]{1,2})%\\s*,\\s*(100|[0-9]{1,2})%\\s*,\\s*(\\d*\\.?\\d+)\\s*\\)/i, // rgba(r%, g%, b%, a)\n] as const;\n\n// HSL color formats\nconst HSL_REG_EXP_ARRAY = [\n // With commas\n /hsla\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d*\\.?\\d+)\\s*\\)/i, // hsla(h, s, l, a)\n /hsl\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d{1,3}%?)\\s*\\)/i, // hsl(h, s, l)\n\n // With spaces\n /^hsla\\s+(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s+(\\d*\\.?\\d+)\\s*$/i, // hsla h s l a\n /^hsl\\s+(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s*$/i, // hsl h s l\n\n // Spaces inside parentheses\n /^hsla\\(\\s*(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s+(\\d*\\.?\\d+)\\s*\\)$/i, // hsla(h s l a)\n /^hsl\\(\\s*(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s*\\)$/i, // hsl(h s l)\n] as const;\n\n// HSV color formats\nconst HSV_REG_EXP_ARRAY = [\n // With commas\n /hsva\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d*\\.?\\d+)\\s*\\)/i, // hsva(h, s, v, a)\n /hsv\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d{1,3}%?)\\s*\\)/i, // hsv(h, s, v)\n\n // With spaces\n /^hsva\\s+(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s+(\\d*\\.?\\d+)\\s*$/i, // hsva h s v a\n /^hsv\\s+(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s*$/i, // hsv h s v\n\n // Spaces inside parentheses\n /^hsva\\(\\s*(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s+(\\d*\\.?\\d+)\\s*\\)$/i, // hsva(h s v a)\n /^hsv\\(\\s*(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s*\\)$/i, // hsv(h s v)\n] as const;\n\n// HEX color formats\nconst HEX_REG_EXP_ARRAY = [\n /^#([A-Fa-f0-9]{6})([A-Fa-f0-9]{2})?$/, // 6-digit hex with optional hex alpha\n /^#([A-Fa-f0-9]{3})([A-Fa-f0-9]{1})?$/, // 3-digit hex with optional hex alpha\n] as const;\n\n// The colorjs.io space ids `getColor` can convert to. `hsva`/`hsla` are not real\n// colorjs.io spaces (converting to them throws), so they are intentionally absent.\nconst VALID_GET_COLOR_FORMATS = ['srgb', 'hsv', 'hsl'] as const;\n\n/** Documentation URL surfaced alongside Dev Mode parse warnings. */\nconst COLOR_PARSE_HELP_URL = 'https://github.com/WICG/color-api/issues/196';\n\n/**\n * Emits a Dev Mode parse warning when `window.__swc.DEBUG` is enabled. Guarded by\n * a `typeof window` check so the controller is safe to evaluate in non-browser\n * (SSR / Node unit test) environments where `window` is undefined. Centralizes\n * the otherwise-repeated warn blocks.\n */\nfunction debugWarn(\n host: ReactiveElement | undefined,\n message: string,\n error: unknown\n): void {\n if (typeof window === 'undefined' || !window.__swc?.DEBUG) {\n return;\n }\n window.__swc.warn(host, message, COLOR_PARSE_HELP_URL, {\n issues: [error instanceof Error ? error.message : 'Unknown error'],\n });\n}\n\n/**\n * Derives a colorjs.io space id from a loose color object based on which channel\n * keys are present. Shared by the `color` setter and the `colorValue` getter so\n * the detection logic lives in one place.\n */\nfunction spaceIdFromColorObject(color: LooseColorObject): string | undefined {\n const { h, s, l, v, r, g, b } = color;\n if (typeof h !== 'undefined' && typeof s !== 'undefined') {\n if (typeof l !== 'undefined') {\n return 'hsl';\n }\n if (typeof v !== 'undefined') {\n return 'hsv';\n }\n }\n if (\n typeof r !== 'undefined' &&\n typeof g !== 'undefined' &&\n typeof b !== 'undefined'\n ) {\n return 'srgb';\n }\n return undefined;\n}\n\n/**\n * The `ColorController` class is responsible for managing and validating color values\n * in various color spaces (RGB, HSL, HSV, Hex). It provides methods to set, get, and\n * validate colors, as well as convert between different color formats.\n *\n * @class\n * @property {Color} color - Gets or sets the current color value.\n * @property {ColorTypes} colorValue - Gets the color value in various formats based on the original color input.\n * @property {number} hue - Gets or sets the hue value of the current color.\n *\n * @function validateColorString(color: string): ColorValidationResult - Validates a color string and returns the validation result.\n * @function getColor(format: string | ColorSpace): ColorObject - Converts the current color to the specified format.\n * @function getHslString(): string - Returns the current color in HSL string format.\n * @function savePreviousColor(): void - Saves the current color as the previous color.\n * @function restorePreviousColor(): void - Restores the previous color.\n *\n * @class\n * @param {ReactiveElement} host - The host element that uses this controller.\n * @param {object} [options] - Optional configuration options.\n * @param {string} [options.manageAs] - Specifies the color space to manage the color as.\n */\nexport class ColorController {\n get color(): Color {\n return this._color;\n }\n\n /**\n * Validates a color string and returns a result indicating the color space,\n * coordinates, alpha value, and whether the color is valid.\n *\n * @param color - The color string to validate. Supported formats include:\n * - RGB: `rgb(r, g, b)`, `rgba(r, g, b, a)`, `rgb r g b`, `rgba r g b a`\n * - HSL: `hsl(h, s, l)`, `hsla(h, s, l, a)`, `hsl h s l`, `hsla h s l a`\n * - HSV: `hsv(h, s, v)`, `hsva(h, s, v, a)`, `hsv h s v`, `hsva h s v a`\n * - HEX: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`\n *\n * @returns An object containing the following properties:\n * - `spaceId`: The color space identifier (`'srgb'`, `'hsl'`, or `'hsv'`).\n * - `coords`: An array of numeric values representing the color coordinates.\n * - `alpha`: The alpha value of the color (0 to 1).\n * - `isValid`: A boolean indicating whether the color string is valid.\n */\n public validateColorString(color: string): ColorValidationResult {\n const result: ColorValidationResult = {\n spaceId: null,\n coords: [0, 0, 0],\n isValid: false,\n alpha: 1,\n };\n\n const rgbaMatch = RGB_REG_EXP_ARRAY.find((regex) =>\n regex.test(color)\n )?.exec(color);\n const hslaMatch = HSL_REG_EXP_ARRAY.find((regex) =>\n regex.test(color)\n )?.exec(color);\n const hsvaMatch = HSV_REG_EXP_ARRAY.find((regex) =>\n regex.test(color)\n )?.exec(color);\n const hexMatch = HEX_REG_EXP_ARRAY.find((regex) => regex.test(color))?.exec(\n color\n );\n\n if (rgbaMatch) {\n const [, r, g, b, a] = rgbaMatch.filter(\n (element) => typeof element === 'string'\n );\n const alpha = a === undefined ? 1 : Number(a);\n const processValue = (value: string): number => {\n if (value.includes('%')) {\n return Number(value.replace('%', '')) / 100;\n } else {\n return Number(value) / 255;\n }\n };\n const numericR = processValue(r);\n const numericG = processValue(g);\n const numericB = processValue(b);\n\n result.spaceId = 'srgb';\n result.coords = [numericR, numericG, numericB];\n result.alpha = alpha;\n result.isValid =\n numericR >= 0 &&\n numericR <= 1 &&\n numericG >= 0 &&\n numericG <= 1 &&\n numericB >= 0 &&\n numericB <= 1 &&\n alpha >= 0 &&\n alpha <= 1;\n } else if (hslaMatch) {\n const [, h, s, l, a] = hslaMatch;\n const values = [h, s, l, a === undefined ? '1' : a].map((value) =>\n Number(value.replace(/[^\\d.]/g, ''))\n );\n const [numericH, numericS, numericL, numericA] = values;\n\n result.spaceId = 'hsl';\n result.coords = [numericH, numericS, numericL];\n result.alpha = numericA;\n result.isValid =\n numericH >= 0 &&\n numericH <= 360 &&\n numericS >= 0 &&\n numericS <= 100 &&\n numericL >= 0 &&\n numericL <= 100 &&\n numericA >= 0 &&\n numericA <= 1;\n } else if (hsvaMatch) {\n const [, h, s, v, a] = hsvaMatch;\n const values = [h, s, v, a === undefined ? '1' : a].map((value) =>\n Number(value.replace(/[^\\d.]/g, ''))\n );\n const [numericH, numericS, numericV, numericA] = values;\n\n result.spaceId = 'hsv';\n result.coords = [numericH, numericS, numericV];\n result.alpha = numericA;\n result.isValid =\n numericH >= 0 &&\n numericH <= 360 &&\n numericS >= 0 &&\n numericS <= 100 &&\n numericV >= 0 &&\n numericV <= 100 &&\n numericA >= 0 &&\n numericA <= 1;\n } else if (hexMatch) {\n const [, hex, alphaHex] = hexMatch;\n\n // Function to process 2-digit or repeated 1-digit hex\n const processHex = (hex: string): number => {\n // For 3-digit hex values, repeat each digit\n if (hex.length === 1) {\n hex = hex + hex;\n }\n return parseInt(hex, 16) / 255;\n };\n\n // Handle both 3-digit and 6-digit hex\n let numericR, numericG, numericB;\n if (hex.length === 3) {\n // 3-digit hex (e.g., #3a7 -> #33aa77)\n numericR = processHex(hex.substring(0, 1));\n numericG = processHex(hex.substring(1, 2));\n numericB = processHex(hex.substring(2, 3));\n } else {\n // 6-digit hex (e.g., #33aa77)\n numericR = processHex(hex.substring(0, 2));\n numericG = processHex(hex.substring(2, 4));\n numericB = processHex(hex.substring(4, 6));\n }\n\n // Process hex alpha if provided (convert from 0-255 to 0-1)\n const numericA = alphaHex ? processHex(alphaHex) : 1;\n\n // Validate the color values\n result.spaceId = 'srgb';\n result.coords = [numericR, numericG, numericB];\n result.alpha = numericA;\n result.isValid =\n numericR >= 0 &&\n numericR <= 1 &&\n numericG >= 0 &&\n numericG <= 1 &&\n numericB >= 0 &&\n numericB <= 1 &&\n numericA >= 0 &&\n numericA <= 1;\n }\n\n return result;\n }\n\n /**\n * Represents the color state of the component.\n * Initialized with an HSV color model with hue 0, saturation 100, and value 100, and an alpha value of 1.\n *\n * @private\n * @type {Color}\n */\n private _color: Color = new Color('hsv', [0, 100, 100], 1);\n\n /**\n * Represents the original color value provided by the user.\n *\n * @private\n * @type {ColorTypes}\n */\n private _colorOrigin!: ColorTypes;\n\n /**\n * Gets the original color value provided by the user.\n *\n * @returns {ColorTypes} The original color value.\n */\n get colorOrigin(): ColorTypes {\n return this._colorOrigin;\n }\n\n /**\n * Sets the original color value provided by the user.\n *\n * @param {ColorTypes} colorOrigin - The original color value to set.\n */\n set colorOrigin(colorOrigin: ColorTypes) {\n this._colorOrigin = colorOrigin;\n }\n\n /**\n * An optional string property that specifies how the color should be managed(its value is the name of color space in which color object will be managed).\n * This property can be used to define a specific management strategy or identifier.\n */\n private manageAs?: string;\n\n /**\n * Stores the previous color value.\n * This is used to keep track of the color before any changes are made.\n *\n * @private\n */\n private _previousColor!: Color;\n\n /**\n * Private helper method to convert RGB color to hex format with optional alpha\n *\n * @private\n * @param {boolean} includeHash - Whether to include the # prefix in the returned string\n * @param {boolean} includeAlpha - Whether to include the alpha channel in the returned string\n * @returns {string} The color in hex format\n */\n private _getHexString(includeHash: boolean, includeAlpha: boolean): string {\n const { r, g, b } = (this._color.to('srgb') as Color).srgb;\n const a = this._color.alpha;\n\n const toHex = (channel: number): string =>\n Math.round(channel * 255)\n .toString(16)\n .padStart(2, '0');\n\n const rHex = toHex(r);\n const gHex = toHex(g);\n const bHex = toHex(b);\n const aHex = toHex(a);\n\n return `${includeHash ? '#' : ''}${rHex}${gHex}${bHex}${includeAlpha ? aHex : ''}`;\n }\n\n /**\n * Sets the color value for the controller. The color can be provided in various formats:\n * - A string representing a color name, hex code, or other color format.\n * - An instance of the `Color` class.\n * - An object containing color properties such as `h`, `s`, `l`, `v`, `r`, `g`, `b`, and optionally `a`.\n *\n * The method validates and parses the input color, converting it to a `Color` instance.\n * If the color is invalid, it attempts to parse it as a hex code or returns without setting a new color.\n *\n * @param {ColorTypes} color - The color value to set. It can be a string, an instance of `Color`, or an object with color properties.\n */\n set color(color: ColorTypes) {\n this._colorOrigin = color;\n let newColor!: Color;\n if (typeof color === 'string') {\n const colorValidationResult = this.validateColorString(color as string);\n if (colorValidationResult.isValid) {\n const [coord1, coord2, coord3] = colorValidationResult.coords;\n newColor = new Color(\n `${colorValidationResult.spaceId}`,\n [coord1, coord2, coord3],\n colorValidationResult.alpha\n );\n } else {\n try {\n Color.parse(color);\n } catch (error) {\n debugWarn(this.host, `Failed to parse color: ${color}`, error);\n try {\n newColor = new Color(`#${color}`);\n } catch (error) {\n debugWarn(\n this.host,\n `Failed to parse color as hex: ${color}`,\n error\n );\n return;\n }\n }\n }\n } else if (color instanceof Color) {\n newColor = color;\n } else if (!Array.isArray(color)) {\n const { h, s, l, v, r, g, b, a } = color as LooseColorObject;\n if (typeof h !== 'undefined' && typeof s !== 'undefined') {\n const lv = l ?? v;\n newColor = new Color(\n typeof l !== 'undefined' ? 'hsl' : 'hsv',\n [\n parseFloat(`${h}`),\n typeof s !== 'string' ? (s as number) * 100 : parseFloat(s),\n typeof lv !== 'string' ? (lv as number) * 100 : parseFloat(lv),\n ],\n parseFloat(`${a ?? '1'}`)\n );\n } else if (\n typeof r !== 'undefined' &&\n typeof g !== 'undefined' &&\n typeof b !== 'undefined'\n ) {\n newColor = new Color(\n 'srgb',\n [\n parseFloat(`${r}`) / 255,\n parseFloat(`${g}`) / 255,\n parseFloat(`${b}`) / 255,\n ],\n parseFloat(`${a ?? '1'}`)\n );\n }\n }\n\n if (!newColor) {\n newColor = new Color(color as DefaultColorTypes);\n }\n\n if (this.manageAs) {\n this._color = newColor.to(this.manageAs) as Color;\n } else {\n this._color = newColor;\n }\n this.host.requestUpdate();\n }\n\n /**\n * Gets the color value in various formats based on the original color input.\n *\n * The method determines the color space of the original color input and converts\n * the color to the appropriate format. The supported color spaces are:\n * - HSV (Hue, Saturation, Value)\n * - HSL (Hue, Saturation, Lightness)\n * - Hexadecimal (with or without alpha)\n * - RGB (Red, Green, Blue) with optional alpha\n *\n * @returns {ColorTypes} The color value in the appropriate format.\n *\n * The method handles the following cases:\n * - If the original color input is a string, it checks the prefix to determine the color space.\n * - If the original color input is an object, it checks the properties to determine the color space.\n * - If the original color input is not provided, it defaults to the current color space of the color object.\n *\n * The returned color value can be in one of the following formats:\n * - `hsv(h, s%, v%)` or `hsva(h, s%, v%, a)`\n * - `hsl(h, s%, l%)` or `hsla(h, s%, l%, a)`\n * - `#rrggbb` or `#rrggbbaa`\n * - `rgb(r, g, b)` or `rgba(r, g, b, a)`\n * - `{ h, s, v, a }` for HSV object\n * - `{ h, s, l, a }` for HSL object\n * - `{ r, g, b, a }` for RGB object\n */\n get colorValue(): ColorTypes {\n if (typeof this._colorOrigin === 'string') {\n let spaceId = '';\n if (this._colorOrigin.startsWith('#')) {\n spaceId = 'hex string';\n } else if (this._colorOrigin.startsWith('rgb')) {\n spaceId = 'rgb';\n } else if (this._colorOrigin.startsWith('hsl')) {\n spaceId = 'hsl';\n } else if (this._colorOrigin.startsWith('hsv')) {\n spaceId = 'hsv';\n } else {\n spaceId = 'hex';\n }\n switch (spaceId) {\n case 'hsv': {\n const hadAlpha = this._colorOrigin[3] === 'a';\n const { h, s, v } = (this._color.to('hsv') as Color).hsv;\n const a = this._color.alpha;\n return `hsv${hadAlpha ? `a` : ''}(${Math.round(\n h\n )}, ${Math.round(s)}%, ${Math.round(v)}%${hadAlpha ? `, ${a}` : ''})`;\n }\n case 'hsl': {\n const hadAlpha = this._colorOrigin[3] === 'a';\n const { h, s, l } = (this._color.to('hsl') as Color).hsl;\n const a = this._color.alpha;\n return `hsl${hadAlpha ? `a` : ''}(${Math.round(\n h\n )}, ${Math.round(s)}%, ${Math.round(l)}%${hadAlpha ? `, ${a}` : ''})`;\n }\n case 'hex string': {\n // Check if the original input included alpha\n const hadAlpha =\n this._colorOrigin.length === 9 || // #RRGGBBAA format\n this._colorOrigin.length === 5; // #RGBA format\n return this._getHexString(true, hadAlpha);\n }\n case 'hex': {\n // Check if the original input included alpha\n const hadAlpha =\n this._colorOrigin.length === 8 || // RRGGBBAA format (no #)\n this._colorOrigin.length === 4; // RGBA format (no #)\n return this._getHexString(false, hadAlpha);\n }\n //rgb\n default: {\n const { r, g, b } = (this._color.to('srgb') as Color).srgb;\n const hadAlpha = this._colorOrigin[3] === 'a';\n const a = this._color.alpha;\n if (this._colorOrigin.search('%') > -1) {\n return `rgb${hadAlpha ? `a` : ''}(${Math.round(r * 100)}%, ${Math.round(\n g * 100\n )}%, ${Math.round(b * 100)}%${hadAlpha ? `,${Math.round(a * 100)}%` : ''})`;\n }\n return `rgb${hadAlpha ? `a` : ''}(${Math.round(r * 255)}, ${Math.round(\n g * 255\n )}, ${Math.round(b * 255)}${hadAlpha ? `, ${a}` : ''})`;\n }\n }\n }\n let spaceId;\n if (this._colorOrigin) {\n try {\n ({ spaceId } = new Color(this._colorOrigin as DefaultColorTypes));\n } catch (error) {\n debugWarn(\n this.host,\n `Failed to parse color as default color types: ${JSON.stringify(\n this._colorOrigin\n )}`,\n error\n );\n spaceId = spaceIdFromColorObject(this._colorOrigin as LooseColorObject);\n }\n } else {\n ({ spaceId } = this.color);\n }\n switch (spaceId) {\n case 'hsv': {\n const { h, s, v } = (this._color.to('hsv') as Color).hsv;\n return {\n h,\n s: s / 100,\n v: v / 100,\n a: this._color.alpha,\n };\n }\n case 'hsl': {\n const { h, s, l } = (this._color.to('hsl') as Color).hsl;\n return {\n h,\n s: s / 100,\n l: l / 100,\n a: this._color.alpha,\n };\n }\n case 'srgb': {\n const { r, g, b } = (this._color.to('srgb') as Color).srgb;\n if (\n this._colorOrigin &&\n typeof (this._colorOrigin as { r: string }).r === 'string' &&\n (this._colorOrigin as { r: string }).r.includes('%')\n ) {\n return {\n r: `${Math.round(r * 100)}%`,\n g: `${Math.round(g * 100)}%`,\n b: `${Math.round(b * 100)}%`,\n a: this._color.alpha,\n };\n }\n return {\n r: Math.round(r * 255),\n g: Math.round(g * 255),\n b: Math.round(b * 255),\n a: this._color.alpha,\n };\n }\n }\n return this._color;\n }\n\n protected host: ReactiveElement;\n\n /**\n * Gets the hue value of the current color in HSL format.\n *\n * @returns {number} The hue value as a number.\n */\n get hue(): number {\n return Number((this._color.to('hsl') as Color).hsl.h);\n }\n\n /**\n * Sets the hue value of the color and requests an update from the host.\n *\n * @param hue - The hue value to set, represented as a number.\n */\n set hue(hue: number) {\n this._color.set('h', hue);\n this.host.requestUpdate();\n }\n\n /**\n * Creates an instance of ColorController.\n *\n * @param host - The ReactiveElement that this controller is associated with.\n * @param options - An object containing optional parameters.\n * @param options.manageAs - A string to manage the controller as a specific type.\n */\n constructor(\n host: ReactiveElement,\n {\n manageAs,\n }: {\n manageAs?: string;\n } = {}\n ) {\n this.host = host;\n this.manageAs = manageAs;\n }\n\n /**\n * Converts the current color to the specified format.\n *\n * @param format - The desired color format. It can be a string representing one of the valid formats\n * ('srgb', 'hsv', 'hsl') or a ColorSpace.Space object.\n * @returns The color object in the specified format.\n * @throws Will throw an error if the provided format is not a valid string format.\n */\n getColor(format: string | ColorSpace.Space): ColorObject {\n if (\n typeof format === 'string' &&\n !VALID_GET_COLOR_FORMATS.includes(\n format as (typeof VALID_GET_COLOR_FORMATS)[number]\n )\n ) {\n throw new Error('not a valid format');\n }\n\n return this._color.to(format);\n }\n\n /**\n * Converts the current color to an HSL string representation.\n *\n * @returns {string} The HSL string representation of the current color.\n */\n getHslString(): string {\n return this._color.to('hsl').toString();\n }\n\n /**\n * Saves the current color state by cloning the current color and storing it\n * as the previous color. This allows for the ability to revert to the previous\n * color state if needed.\n *\n * @returns {void}\n */\n savePreviousColor(): void {\n this._previousColor = this._color.clone();\n }\n\n /**\n * Restores the color to the previously saved color value.\n *\n * This method sets the current color (`_color`) to the previously stored color (`_previousColor`).\n */\n restorePreviousColor(): void {\n this._color = this._previousColor;\n }\n}\n"],"mappings":";;AA6FA,IAAM,IAAoB;CAExB;CACA;CAGA;CACA;CAGA;CACA;CAGA;CACA;CACD,EAGK,IAAoB;CAExB;CACA;CAGA;CACA;CAGA;CACA;CACD,EAGK,IAAoB;CAExB;CACA;CAGA;CACA;CAGA;CACA;CACD,EAGK,IAAoB,CACxB,wCACA,uCACD,EAIK,IAA0B;CAAC;CAAQ;CAAO;CAAM,EAGhD,IAAuB;AAQ7B,SAAS,EACP,GACA,GACA,GACM;;AACF,QAAO,SAAW,OAAe,GAAA,IAAC,OAAO,UAAA,QAAA,EAAO,UAGpD,OAAO,MAAM,KAAK,GAAM,GAAS,GAAsB,EACrD,QAAQ,CAAC,aAAiB,QAAQ,EAAM,UAAU,gBAAgB,EACnE,CAAC;;AAQJ,SAAS,EAAuB,GAA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AAK,EAAI,EACzB,KAAK,KAAK,eAAe;;CAU3B,YACE,GACA,EACE,gBAGE,EAAE,EACN;AAEA,gBAhVsB,IAAI,EAAM,OAAO;GAAC;GAAG;GAAK;GAAI,EAAE,EAAE,EA+UxD,KAAK,OAAO,GACZ,KAAK,WAAW;;CAWlB,SAAS,GAAgD;AACvD,MACE,OAAO,KAAW,YAClB,CAAC,EAAwB,SACvB,EACD,CAED,OAAU,MAAM,qBAAqB;AAGvC,SAAO,KAAK,OAAO,GAAG,EAAO;;CAQ/B,eAAuB;AACrB,SAAO,KAAK,OAAO,GAAG,MAAM,CAAC,UAAU;;CAUzC,oBAA0B;AACxB,OAAK,iBAAiB,KAAK,OAAO,OAAO;;CAQ3C,uBAA6B;AAC3B,OAAK,SAAS,KAAK"}
1
+ {"version":3,"file":"color-controller.js","names":[],"sources":["../../../../controllers/color-controller/src/color-controller.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 { ReactiveElement } from 'lit';\nimport type ColorSpace from 'colorjs.io';\nimport type { ColorObject, ColorTypes as DefaultColorTypes } from 'colorjs.io';\nimport Color from 'colorjs.io';\n\nimport { isDebug } from '@adobe/spectrum-wc-core/utils/index.js';\n\n// ─────────────────────────\n// TYPES\n// ─────────────────────────\n\n/**\n * Represents various color types that can be used in the application.\n *\n * This type can be one of the following:\n * - `DefaultColorTypes`: A predefined set of color types.\n * - An object representing an RGBA color with properties:\n * - `r`: Red component, can be a number or string.\n * - `g`: Green component, can be a number or string.\n * - `b`: Blue component, can be a number or string.\n * - `a` (optional): Alpha component, can be a number or string.\n * - An object representing an HSLA color with properties:\n * - `h`: Hue component, can be a number or string.\n * - `s`: Saturation component, can be a number or string.\n * - `l`: Lightness component, can be a number or string.\n * - `a` (optional): Alpha component, can be a number or string.\n * - An object representing an HSVA color with properties:\n * - `h`: Hue component, can be a number or string.\n * - `s`: Saturation component, can be a number or string.\n * - `v`: Value component, can be a number or string.\n * - `a` (optional): Alpha component, can be a number or string.\n */\ntype ColorTypes =\n | DefaultColorTypes\n | {\n r: number | string;\n g: number | string;\n b: number | string;\n a?: number | string;\n }\n | {\n h: number | string;\n s: number | string;\n l: number | string;\n a?: number | string;\n }\n | {\n h: number | string;\n s: number | string;\n v: number | string;\n a?: number | string;\n };\n\nexport type { Color, ColorTypes };\n\ntype ColorValidationResult = {\n spaceId: string | null;\n coords: number[];\n isValid: boolean;\n alpha: number;\n};\n\n/** Loose shape of a color object whose channel values may arrive as strings. */\ntype LooseColorObject = {\n h?: number | string;\n s?: number | string;\n l?: number | string;\n v?: number | string;\n r?: number | string;\n g?: number | string;\n b?: number | string;\n a?: number | string;\n};\n\n// ─────────────────────────\n// CONSTANTS\n// ─────────────────────────\n\n// These pattern arrays are static, so they live at module scope and are shared\n// across every controller instance and `validateColorString` call rather than\n// being rebuilt on each invocation.\n\n// RGB color formats\nconst RGB_REG_EXP_ARRAY = [\n // With commas\n /rgba\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d*\\.?\\d+)\\s*\\)/i, // rgba(r, g, b, a)\n /rgb\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*\\)/i, // rgb(r, g, b)\n\n // With spaces\n /^rgba\\s+(\\d{1,3})\\s+(\\d{1,3})\\s+(\\d{1,3})\\s+(0|0?\\.\\d+|1)\\s*$/i, // rgba r g b a\n /^rgb\\s+(\\d{1,3})\\s+(\\d{1,3})\\s+(\\d{1,3})\\s*$/i, // rgb r g b\n\n // Spaces inside parentheses\n /^rgba\\(\\s*(\\d{1,3})\\s+(\\d{1,3})\\s+(\\d{1,3})\\s+(\\d*\\.?\\d+)\\s*\\)$/i, // rgba(r g b a)\n /^rgb\\(\\s*(\\d{1,3})\\s+(\\d{1,3})\\s+(\\d{1,3})\\s*\\)$/i, // rgb(r g b)\n\n // Percentage values\n /rgb\\(\\s*(100|[0-9]{1,2}%)\\s*,\\s*(100|[0-9]{1,2}%)\\s*,\\s*(100|[0-9]{1,2}%)\\s*\\)/i, // rgb(r%, g%, b%)\n /rgba\\(\\s*(100|[0-9]{1,2})%\\s*,\\s*(100|[0-9]{1,2})%\\s*,\\s*(100|[0-9]{1,2})%\\s*,\\s*(\\d*\\.?\\d+)\\s*\\)/i, // rgba(r%, g%, b%, a)\n] as const;\n\n// HSL color formats\nconst HSL_REG_EXP_ARRAY = [\n // With commas\n /hsla\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d*\\.?\\d+)\\s*\\)/i, // hsla(h, s, l, a)\n /hsl\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d{1,3}%?)\\s*\\)/i, // hsl(h, s, l)\n\n // With spaces\n /^hsla\\s+(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s+(\\d*\\.?\\d+)\\s*$/i, // hsla h s l a\n /^hsl\\s+(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s*$/i, // hsl h s l\n\n // Spaces inside parentheses\n /^hsla\\(\\s*(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s+(\\d*\\.?\\d+)\\s*\\)$/i, // hsla(h s l a)\n /^hsl\\(\\s*(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s*\\)$/i, // hsl(h s l)\n] as const;\n\n// HSV color formats\nconst HSV_REG_EXP_ARRAY = [\n // With commas\n /hsva\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d*\\.?\\d+)\\s*\\)/i, // hsva(h, s, v, a)\n /hsv\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3}%?)\\s*,\\s*(\\d{1,3}%?)\\s*\\)/i, // hsv(h, s, v)\n\n // With spaces\n /^hsva\\s+(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s+(\\d*\\.?\\d+)\\s*$/i, // hsva h s v a\n /^hsv\\s+(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s*$/i, // hsv h s v\n\n // Spaces inside parentheses\n /^hsva\\(\\s*(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s+(\\d*\\.?\\d+)\\s*\\)$/i, // hsva(h s v a)\n /^hsv\\(\\s*(\\d{1,3})\\s+(\\d{1,3}%?)\\s+(\\d{1,3}%?)\\s*\\)$/i, // hsv(h s v)\n] as const;\n\n// HEX color formats\nconst HEX_REG_EXP_ARRAY = [\n /^#([A-Fa-f0-9]{6})([A-Fa-f0-9]{2})?$/, // 6-digit hex with optional hex alpha\n /^#([A-Fa-f0-9]{3})([A-Fa-f0-9]{1})?$/, // 3-digit hex with optional hex alpha\n] as const;\n\n// The colorjs.io space ids `getColor` can convert to. `hsva`/`hsla` are not real\n// colorjs.io spaces (converting to them throws), so they are intentionally absent.\nconst VALID_GET_COLOR_FORMATS = ['srgb', 'hsv', 'hsl'] as const;\n\n/** Documentation URL surfaced alongside Dev Mode parse warnings. */\nconst COLOR_PARSE_HELP_URL = 'https://github.com/WICG/color-api/issues/196';\n\n/**\n * Emits a Dev Mode parse warning when dev validation is active. Gated by\n * `isDebug()`, which is `false` in production and in non-browser (SSR / Node\n * unit test) environments where `window` is undefined, so the controller stays\n * safe to evaluate server-side. Centralizes the otherwise-repeated warn blocks.\n */\nfunction debugWarn(\n host: ReactiveElement | undefined,\n message: string,\n error: unknown\n): void {\n if (!isDebug()) {\n return;\n }\n window.__swc?.warn(host, message, COLOR_PARSE_HELP_URL, {\n issues: [error instanceof Error ? error.message : 'Unknown error'],\n });\n}\n\n/**\n * Derives a colorjs.io space id from a loose color object based on which channel\n * keys are present. Shared by the `color` setter and the `colorValue` getter so\n * the detection logic lives in one place.\n */\nfunction spaceIdFromColorObject(color: LooseColorObject): string | undefined {\n const { h, s, l, v, r, g, b } = color;\n if (typeof h !== 'undefined' && typeof s !== 'undefined') {\n if (typeof l !== 'undefined') {\n return 'hsl';\n }\n if (typeof v !== 'undefined') {\n return 'hsv';\n }\n }\n if (\n typeof r !== 'undefined' &&\n typeof g !== 'undefined' &&\n typeof b !== 'undefined'\n ) {\n return 'srgb';\n }\n return undefined;\n}\n\n/**\n * The `ColorController` class is responsible for managing and validating color values\n * in various color spaces (RGB, HSL, HSV, Hex). It provides methods to set, get, and\n * validate colors, as well as convert between different color formats.\n *\n * @class\n * @property {Color} color - Gets or sets the current color value.\n * @property {ColorTypes} colorValue - Gets the color value in various formats based on the original color input.\n * @property {number} hue - Gets or sets the hue value of the current color.\n *\n * @function validateColorString(color: string): ColorValidationResult - Validates a color string and returns the validation result.\n * @function getColor(format: string | ColorSpace): ColorObject - Converts the current color to the specified format.\n * @function getHslString(): string - Returns the current color in HSL string format.\n * @function savePreviousColor(): void - Saves the current color as the previous color.\n * @function restorePreviousColor(): void - Restores the previous color.\n *\n * @class\n * @param {ReactiveElement} host - The host element that uses this controller.\n * @param {object} [options] - Optional configuration options.\n * @param {string} [options.manageAs] - Specifies the color space to manage the color as.\n */\nexport class ColorController {\n get color(): Color {\n return this._color;\n }\n\n /**\n * Validates a color string and returns a result indicating the color space,\n * coordinates, alpha value, and whether the color is valid.\n *\n * @param color - The color string to validate. Supported formats include:\n * - RGB: `rgb(r, g, b)`, `rgba(r, g, b, a)`, `rgb r g b`, `rgba r g b a`\n * - HSL: `hsl(h, s, l)`, `hsla(h, s, l, a)`, `hsl h s l`, `hsla h s l a`\n * - HSV: `hsv(h, s, v)`, `hsva(h, s, v, a)`, `hsv h s v`, `hsva h s v a`\n * - HEX: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`\n *\n * @returns An object containing the following properties:\n * - `spaceId`: The color space identifier (`'srgb'`, `'hsl'`, or `'hsv'`).\n * - `coords`: An array of numeric values representing the color coordinates.\n * - `alpha`: The alpha value of the color (0 to 1).\n * - `isValid`: A boolean indicating whether the color string is valid.\n */\n public validateColorString(color: string): ColorValidationResult {\n const result: ColorValidationResult = {\n spaceId: null,\n coords: [0, 0, 0],\n isValid: false,\n alpha: 1,\n };\n\n const rgbaMatch = RGB_REG_EXP_ARRAY.find((regex) =>\n regex.test(color)\n )?.exec(color);\n const hslaMatch = HSL_REG_EXP_ARRAY.find((regex) =>\n regex.test(color)\n )?.exec(color);\n const hsvaMatch = HSV_REG_EXP_ARRAY.find((regex) =>\n regex.test(color)\n )?.exec(color);\n const hexMatch = HEX_REG_EXP_ARRAY.find((regex) => regex.test(color))?.exec(\n color\n );\n\n if (rgbaMatch) {\n const [, r, g, b, a] = rgbaMatch.filter(\n (element) => typeof element === 'string'\n );\n const alpha = a === undefined ? 1 : Number(a);\n const processValue = (value: string): number => {\n if (value.includes('%')) {\n return Number(value.replace('%', '')) / 100;\n } else {\n return Number(value) / 255;\n }\n };\n const numericR = processValue(r);\n const numericG = processValue(g);\n const numericB = processValue(b);\n\n result.spaceId = 'srgb';\n result.coords = [numericR, numericG, numericB];\n result.alpha = alpha;\n result.isValid =\n numericR >= 0 &&\n numericR <= 1 &&\n numericG >= 0 &&\n numericG <= 1 &&\n numericB >= 0 &&\n numericB <= 1 &&\n alpha >= 0 &&\n alpha <= 1;\n } else if (hslaMatch) {\n const [, h, s, l, a] = hslaMatch;\n const values = [h, s, l, a === undefined ? '1' : a].map((value) =>\n Number(value.replace(/[^\\d.]/g, ''))\n );\n const [numericH, numericS, numericL, numericA] = values;\n\n result.spaceId = 'hsl';\n result.coords = [numericH, numericS, numericL];\n result.alpha = numericA;\n result.isValid =\n numericH >= 0 &&\n numericH <= 360 &&\n numericS >= 0 &&\n numericS <= 100 &&\n numericL >= 0 &&\n numericL <= 100 &&\n numericA >= 0 &&\n numericA <= 1;\n } else if (hsvaMatch) {\n const [, h, s, v, a] = hsvaMatch;\n const values = [h, s, v, a === undefined ? '1' : a].map((value) =>\n Number(value.replace(/[^\\d.]/g, ''))\n );\n const [numericH, numericS, numericV, numericA] = values;\n\n result.spaceId = 'hsv';\n result.coords = [numericH, numericS, numericV];\n result.alpha = numericA;\n result.isValid =\n numericH >= 0 &&\n numericH <= 360 &&\n numericS >= 0 &&\n numericS <= 100 &&\n numericV >= 0 &&\n numericV <= 100 &&\n numericA >= 0 &&\n numericA <= 1;\n } else if (hexMatch) {\n const [, hex, alphaHex] = hexMatch;\n\n // Function to process 2-digit or repeated 1-digit hex\n const processHex = (hex: string): number => {\n // For 3-digit hex values, repeat each digit\n if (hex.length === 1) {\n hex = hex + hex;\n }\n return parseInt(hex, 16) / 255;\n };\n\n // Handle both 3-digit and 6-digit hex\n let numericR, numericG, numericB;\n if (hex.length === 3) {\n // 3-digit hex (e.g., #3a7 -> #33aa77)\n numericR = processHex(hex.substring(0, 1));\n numericG = processHex(hex.substring(1, 2));\n numericB = processHex(hex.substring(2, 3));\n } else {\n // 6-digit hex (e.g., #33aa77)\n numericR = processHex(hex.substring(0, 2));\n numericG = processHex(hex.substring(2, 4));\n numericB = processHex(hex.substring(4, 6));\n }\n\n // Process hex alpha if provided (convert from 0-255 to 0-1)\n const numericA = alphaHex ? processHex(alphaHex) : 1;\n\n // Validate the color values\n result.spaceId = 'srgb';\n result.coords = [numericR, numericG, numericB];\n result.alpha = numericA;\n result.isValid =\n numericR >= 0 &&\n numericR <= 1 &&\n numericG >= 0 &&\n numericG <= 1 &&\n numericB >= 0 &&\n numericB <= 1 &&\n numericA >= 0 &&\n numericA <= 1;\n }\n\n return result;\n }\n\n /**\n * Represents the color state of the component.\n * Initialized with an HSV color model with hue 0, saturation 100, and value 100, and an alpha value of 1.\n *\n * @private\n * @type {Color}\n */\n private _color: Color = new Color('hsv', [0, 100, 100], 1);\n\n /**\n * Represents the original color value provided by the user.\n *\n * @private\n * @type {ColorTypes}\n */\n private _colorOrigin!: ColorTypes;\n\n /**\n * Gets the original color value provided by the user.\n *\n * @returns {ColorTypes} The original color value.\n */\n get colorOrigin(): ColorTypes {\n return this._colorOrigin;\n }\n\n /**\n * Sets the original color value provided by the user.\n *\n * @param {ColorTypes} colorOrigin - The original color value to set.\n */\n set colorOrigin(colorOrigin: ColorTypes) {\n this._colorOrigin = colorOrigin;\n }\n\n /**\n * An optional string property that specifies how the color should be managed(its value is the name of color space in which color object will be managed).\n * This property can be used to define a specific management strategy or identifier.\n */\n private manageAs?: string;\n\n /**\n * Stores the previous color value.\n * This is used to keep track of the color before any changes are made.\n *\n * @private\n */\n private _previousColor!: Color;\n\n /**\n * Private helper method to convert RGB color to hex format with optional alpha\n *\n * @private\n * @param {boolean} includeHash - Whether to include the # prefix in the returned string\n * @param {boolean} includeAlpha - Whether to include the alpha channel in the returned string\n * @returns {string} The color in hex format\n */\n private _getHexString(includeHash: boolean, includeAlpha: boolean): string {\n const { r, g, b } = (this._color.to('srgb') as Color).srgb;\n const a = this._color.alpha;\n\n const toHex = (channel: number): string =>\n Math.round(channel * 255)\n .toString(16)\n .padStart(2, '0');\n\n const rHex = toHex(r);\n const gHex = toHex(g);\n const bHex = toHex(b);\n const aHex = toHex(a);\n\n return `${includeHash ? '#' : ''}${rHex}${gHex}${bHex}${includeAlpha ? aHex : ''}`;\n }\n\n /**\n * Sets the color value for the controller. The color can be provided in various formats:\n * - A string representing a color name, hex code, or other color format.\n * - An instance of the `Color` class.\n * - An object containing color properties such as `h`, `s`, `l`, `v`, `r`, `g`, `b`, and optionally `a`.\n *\n * The method validates and parses the input color, converting it to a `Color` instance.\n * If the color is invalid, it attempts to parse it as a hex code or returns without setting a new color.\n *\n * @param {ColorTypes} color - The color value to set. It can be a string, an instance of `Color`, or an object with color properties.\n */\n set color(color: ColorTypes) {\n this._colorOrigin = color;\n let newColor!: Color;\n if (typeof color === 'string') {\n const colorValidationResult = this.validateColorString(color as string);\n if (colorValidationResult.isValid) {\n const [coord1, coord2, coord3] = colorValidationResult.coords;\n newColor = new Color(\n `${colorValidationResult.spaceId}`,\n [coord1, coord2, coord3],\n colorValidationResult.alpha\n );\n } else {\n try {\n Color.parse(color);\n } catch (error) {\n debugWarn(this.host, `Failed to parse color: ${color}`, error);\n try {\n newColor = new Color(`#${color}`);\n } catch (error) {\n debugWarn(\n this.host,\n `Failed to parse color as hex: ${color}`,\n error\n );\n return;\n }\n }\n }\n } else if (color instanceof Color) {\n newColor = color;\n } else if (!Array.isArray(color)) {\n const { h, s, l, v, r, g, b, a } = color as LooseColorObject;\n if (typeof h !== 'undefined' && typeof s !== 'undefined') {\n const lv = l ?? v;\n newColor = new Color(\n typeof l !== 'undefined' ? 'hsl' : 'hsv',\n [\n parseFloat(`${h}`),\n typeof s !== 'string' ? (s as number) * 100 : parseFloat(s),\n typeof lv !== 'string' ? (lv as number) * 100 : parseFloat(lv),\n ],\n parseFloat(`${a ?? '1'}`)\n );\n } else if (\n typeof r !== 'undefined' &&\n typeof g !== 'undefined' &&\n typeof b !== 'undefined'\n ) {\n newColor = new Color(\n 'srgb',\n [\n parseFloat(`${r}`) / 255,\n parseFloat(`${g}`) / 255,\n parseFloat(`${b}`) / 255,\n ],\n parseFloat(`${a ?? '1'}`)\n );\n }\n }\n\n if (!newColor) {\n newColor = new Color(color as DefaultColorTypes);\n }\n\n if (this.manageAs) {\n this._color = newColor.to(this.manageAs) as Color;\n } else {\n this._color = newColor;\n }\n this.host.requestUpdate();\n }\n\n /**\n * Gets the color value in various formats based on the original color input.\n *\n * The method determines the color space of the original color input and converts\n * the color to the appropriate format. The supported color spaces are:\n * - HSV (Hue, Saturation, Value)\n * - HSL (Hue, Saturation, Lightness)\n * - Hexadecimal (with or without alpha)\n * - RGB (Red, Green, Blue) with optional alpha\n *\n * @returns {ColorTypes} The color value in the appropriate format.\n *\n * The method handles the following cases:\n * - If the original color input is a string, it checks the prefix to determine the color space.\n * - If the original color input is an object, it checks the properties to determine the color space.\n * - If the original color input is not provided, it defaults to the current color space of the color object.\n *\n * The returned color value can be in one of the following formats:\n * - `hsv(h, s%, v%)` or `hsva(h, s%, v%, a)`\n * - `hsl(h, s%, l%)` or `hsla(h, s%, l%, a)`\n * - `#rrggbb` or `#rrggbbaa`\n * - `rgb(r, g, b)` or `rgba(r, g, b, a)`\n * - `{ h, s, v, a }` for HSV object\n * - `{ h, s, l, a }` for HSL object\n * - `{ r, g, b, a }` for RGB object\n */\n get colorValue(): ColorTypes {\n if (typeof this._colorOrigin === 'string') {\n let spaceId = '';\n if (this._colorOrigin.startsWith('#')) {\n spaceId = 'hex string';\n } else if (this._colorOrigin.startsWith('rgb')) {\n spaceId = 'rgb';\n } else if (this._colorOrigin.startsWith('hsl')) {\n spaceId = 'hsl';\n } else if (this._colorOrigin.startsWith('hsv')) {\n spaceId = 'hsv';\n } else {\n spaceId = 'hex';\n }\n switch (spaceId) {\n case 'hsv': {\n const hadAlpha = this._colorOrigin[3] === 'a';\n const { h, s, v } = (this._color.to('hsv') as Color).hsv;\n const a = this._color.alpha;\n return `hsv${hadAlpha ? `a` : ''}(${Math.round(\n h\n )}, ${Math.round(s)}%, ${Math.round(v)}%${hadAlpha ? `, ${a}` : ''})`;\n }\n case 'hsl': {\n const hadAlpha = this._colorOrigin[3] === 'a';\n const { h, s, l } = (this._color.to('hsl') as Color).hsl;\n const a = this._color.alpha;\n return `hsl${hadAlpha ? `a` : ''}(${Math.round(\n h\n )}, ${Math.round(s)}%, ${Math.round(l)}%${hadAlpha ? `, ${a}` : ''})`;\n }\n case 'hex string': {\n // Check if the original input included alpha\n const hadAlpha =\n this._colorOrigin.length === 9 || // #RRGGBBAA format\n this._colorOrigin.length === 5; // #RGBA format\n return this._getHexString(true, hadAlpha);\n }\n case 'hex': {\n // Check if the original input included alpha\n const hadAlpha =\n this._colorOrigin.length === 8 || // RRGGBBAA format (no #)\n this._colorOrigin.length === 4; // RGBA format (no #)\n return this._getHexString(false, hadAlpha);\n }\n //rgb\n default: {\n const { r, g, b } = (this._color.to('srgb') as Color).srgb;\n const hadAlpha = this._colorOrigin[3] === 'a';\n const a = this._color.alpha;\n if (this._colorOrigin.search('%') > -1) {\n return `rgb${hadAlpha ? `a` : ''}(${Math.round(r * 100)}%, ${Math.round(\n g * 100\n )}%, ${Math.round(b * 100)}%${hadAlpha ? `,${Math.round(a * 100)}%` : ''})`;\n }\n return `rgb${hadAlpha ? `a` : ''}(${Math.round(r * 255)}, ${Math.round(\n g * 255\n )}, ${Math.round(b * 255)}${hadAlpha ? `, ${a}` : ''})`;\n }\n }\n }\n let spaceId;\n if (this._colorOrigin) {\n try {\n ({ spaceId } = new Color(this._colorOrigin as DefaultColorTypes));\n } catch (error) {\n debugWarn(\n this.host,\n `Failed to parse color as default color types: ${JSON.stringify(\n this._colorOrigin\n )}`,\n error\n );\n spaceId = spaceIdFromColorObject(this._colorOrigin as LooseColorObject);\n }\n } else {\n ({ spaceId } = this.color);\n }\n switch (spaceId) {\n case 'hsv': {\n const { h, s, v } = (this._color.to('hsv') as Color).hsv;\n return {\n h,\n s: s / 100,\n v: v / 100,\n a: this._color.alpha,\n };\n }\n case 'hsl': {\n const { h, s, l } = (this._color.to('hsl') as Color).hsl;\n return {\n h,\n s: s / 100,\n l: l / 100,\n a: this._color.alpha,\n };\n }\n case 'srgb': {\n const { r, g, b } = (this._color.to('srgb') as Color).srgb;\n if (\n this._colorOrigin &&\n typeof (this._colorOrigin as { r: string }).r === 'string' &&\n (this._colorOrigin as { r: string }).r.includes('%')\n ) {\n return {\n r: `${Math.round(r * 100)}%`,\n g: `${Math.round(g * 100)}%`,\n b: `${Math.round(b * 100)}%`,\n a: this._color.alpha,\n };\n }\n return {\n r: Math.round(r * 255),\n g: Math.round(g * 255),\n b: Math.round(b * 255),\n a: this._color.alpha,\n };\n }\n }\n return this._color;\n }\n\n protected host: ReactiveElement;\n\n /**\n * Gets the hue value of the current color in HSL format.\n *\n * @returns {number} The hue value as a number.\n */\n get hue(): number {\n return Number((this._color.to('hsl') as Color).hsl.h);\n }\n\n /**\n * Sets the hue value of the color and requests an update from the host.\n *\n * @param hue - The hue value to set, represented as a number.\n */\n set hue(hue: number) {\n this._color.set('h', hue);\n this.host.requestUpdate();\n }\n\n /**\n * Creates an instance of ColorController.\n *\n * @param host - The ReactiveElement that this controller is associated with.\n * @param options - An object containing optional parameters.\n * @param options.manageAs - A string to manage the controller as a specific type.\n */\n constructor(\n host: ReactiveElement,\n {\n manageAs,\n }: {\n manageAs?: string;\n } = {}\n ) {\n this.host = host;\n this.manageAs = manageAs;\n }\n\n /**\n * Converts the current color to the specified format.\n *\n * @param format - The desired color format. It can be a string representing one of the valid formats\n * ('srgb', 'hsv', 'hsl') or a ColorSpace.Space object.\n * @returns The color object in the specified format.\n * @throws Will throw an error if the provided format is not a valid string format.\n */\n getColor(format: string | ColorSpace.Space): ColorObject {\n if (\n typeof format === 'string' &&\n !VALID_GET_COLOR_FORMATS.includes(\n format as (typeof VALID_GET_COLOR_FORMATS)[number]\n )\n ) {\n throw new Error('not a valid format');\n }\n\n return this._color.to(format);\n }\n\n /**\n * Converts the current color to an HSL string representation.\n *\n * @returns {string} The HSL string representation of the current color.\n */\n getHslString(): string {\n return this._color.to('hsl').toString();\n }\n\n /**\n * Saves the current color state by cloning the current color and storing it\n * as the previous color. This allows for the ability to revert to the previous\n * color state if needed.\n *\n * @returns {void}\n */\n savePreviousColor(): void {\n this._previousColor = this._color.clone();\n }\n\n /**\n * Restores the color to the previously saved color value.\n *\n * This method sets the current color (`_color`) to the previously stored color (`_previousColor`).\n */\n restorePreviousColor(): void {\n this._color = this._previousColor;\n }\n}\n"],"mappings":";;;AA+FA,IAAM,IAAoB;CAExB;CACA;CAGA;CACA;CAGA;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AM,IAAI,IAAI,CAAC;KAC1B,GAAG,GAAG,KAAK,MAAM,IAAI,IAAI,CAAC;KAC1B,GAAG,KAAK,OAAO;KAChB,GAEI;KACL,GAAG,KAAK,MAAM,IAAI,IAAI;KACtB,GAAG,KAAK,MAAM,IAAI,IAAI;KACtB,GAAG,KAAK,MAAM,IAAI,IAAI;KACtB,GAAG,KAAK,OAAO;KAChB;;;AAGL,SAAO,KAAK;;CAUd,IAAI,MAAc;AAChB,SAAO,OAAQ,KAAK,OAAO,GAAG,MAAM,CAAW,IAAI,EAAE;;CAQvD,IAAI,IAAI,GAAa;AAEnB,EADA,KAAK,OAAO,IAAI,KAAK,EAAI,EACzB,KAAK,KAAK,eAAe;;CAU3B,YACE,GACA,EACE,gBAGE,EAAE,EACN;AAEA,gBAhVsB,IAAI,EAAM,OAAO;GAAC;GAAG;GAAK;GAAI,EAAE,EAAE,EA+UxD,KAAK,OAAO,GACZ,KAAK,WAAW;;CAWlB,SAAS,GAAgD;AACvD,MACE,OAAO,KAAW,YAClB,CAAC,EAAwB,SACvB,EACD,CAED,OAAU,MAAM,qBAAqB;AAGvC,SAAO,KAAK,OAAO,GAAG,EAAO;;CAQ/B,eAAuB;AACrB,SAAO,KAAK,OAAO,GAAG,MAAM,CAAC,UAAU;;CAUzC,oBAA0B;AACxB,OAAK,iBAAiB,KAAK,OAAO,OAAO;;CAQ3C,uBAA6B;AAC3B,OAAK,SAAS,KAAK"}
@@ -0,0 +1,12 @@
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
+ export { DragAndDropController, type DragAndDropControllerOptions, type DragLeaveSnapshot, } from './src/drag-and-drop-controller.js';
@@ -0,0 +1,2 @@
1
+ import { DragAndDropController as e } from "./src/drag-and-drop-controller.js";
2
+ export { e as DragAndDropController };
@@ -0,0 +1,68 @@
1
+ import { ReactiveController, ReactiveElement } from 'lit';
2
+ /**
3
+ * Snapshot of the fields read from a native `DragEvent` before it's recycled
4
+ * by the browser, safe to read after the debounce in {@link DragAndDropControllerOptions.onDragLeave}.
5
+ */
6
+ export interface DragLeaveSnapshot {
7
+ clientX: number;
8
+ clientY: number;
9
+ relatedTarget: EventTarget | null;
10
+ }
11
+ /** Configuration options for {@link DragAndDropController}. */
12
+ export interface DragAndDropControllerOptions {
13
+ /**
14
+ * The host's own current "is a drag over me" flag. The controller never
15
+ * keeps a copy of this state; it re-reads it on every native event so a
16
+ * host that also exposes this flag as a public, externally-settable
17
+ * property (as `swc-dropzone` does) can never drift out of sync with it.
18
+ */
19
+ isDragged: () => boolean;
20
+ /**
21
+ * Return `false` to reject the current drag payload; sets the OS cursor to
22
+ * "not-allowed". Called on every native `dragover` tick. Defaults to
23
+ * always-accept.
24
+ */
25
+ shouldAccept?: (event: DragEvent) => boolean;
26
+ /** Called once when an accepted drag enters — not on every `dragover` tick. Set `isDragged`'s backing flag to `true` here. */
27
+ onDragEnter?: (event: DragEvent) => void;
28
+ /** Called once the accepted drag leaves or becomes rejected. Set `isDragged`'s backing flag to `false` here. */
29
+ onDragLeave?: (snapshot: DragLeaveSnapshot) => void;
30
+ /** Called on drop, only when `isDragged()` is currently `true`. */
31
+ onDrop?: (event: DragEvent) => void;
32
+ /** OS cursor feedback while an accepted drag hovers. Defaults to `'copy'`. */
33
+ dropEffect?: () => DataTransfer['dropEffect'];
34
+ }
35
+ /**
36
+ * A Lit {@link ReactiveController} that manages native drag-and-drop event
37
+ * wiring (`dragover` / `dragleave` / `drop`) for a host element: debounces
38
+ * `dragleave` so passing over a child element doesn't flicker the state,
39
+ * de-duplicates entry so `onDragEnter` fires once per hover session rather
40
+ * than on every `dragover` tick, and lets the host veto payloads it doesn't
41
+ * want via `shouldAccept`.
42
+ *
43
+ * The host owns its own "dragged" state (via `isDragged`/`onDragEnter`/
44
+ * `onDragLeave`); this controller only drives the timing.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const dragAndDrop = new DragAndDropController(this, {
49
+ * isDragged: () => this._dragged,
50
+ * onDragEnter: () => { this._dragged = true; },
51
+ * onDragLeave: () => { this._dragged = false; },
52
+ * onDrop: (event) => this._handleFilesDropped(event.dataTransfer?.files),
53
+ * });
54
+ * ```
55
+ */
56
+ export declare class DragAndDropController implements ReactiveController {
57
+ private readonly _host;
58
+ private readonly _options;
59
+ private _dragLeaveTimer;
60
+ private _abortController;
61
+ constructor(host: ReactiveElement, options: DragAndDropControllerOptions);
62
+ hostConnected(): void;
63
+ hostDisconnected(): void;
64
+ private readonly _onDragOver;
65
+ private readonly _onDragLeave;
66
+ private readonly _onDrop;
67
+ private _clearDragLeaveTimer;
68
+ }
@@ -0,0 +1,56 @@
1
+ //#region controllers/drag-and-drop-controller/src/drag-and-drop-controller.ts
2
+ var e = 100, t = class {
3
+ constructor(t, n) {
4
+ this._dragLeaveTimer = null, this._abortController = null, this._onDragOver = (e) => {
5
+ var t, n, r, i, a;
6
+ if (e.preventDefault(), e.dataTransfer) {
7
+ if (this._clearDragLeaveTimer(), ((t = (n = this._options).shouldAccept) == null ? void 0 : t.call(n, e)) === !1) {
8
+ if (e.dataTransfer.dropEffect = "none", this._options.isDragged()) {
9
+ var o, s;
10
+ (o = (s = this._options).onDragLeave) == null || o.call(s, {
11
+ clientX: e.clientX,
12
+ clientY: e.clientY,
13
+ relatedTarget: e.relatedTarget
14
+ });
15
+ }
16
+ return;
17
+ }
18
+ if (e.dataTransfer.dropEffect = (r = (i = (a = this._options).dropEffect) == null ? void 0 : i.call(a)) == null ? "copy" : r, !this._options.isDragged()) {
19
+ var c, l;
20
+ (c = (l = this._options).onDragEnter) == null || c.call(l, e);
21
+ }
22
+ }
23
+ }, this._onDragLeave = (t) => {
24
+ if (t.relatedTarget && this._host.contains(t.relatedTarget)) return;
25
+ this._clearDragLeaveTimer();
26
+ let { clientX: n, clientY: r, relatedTarget: i } = t;
27
+ this._dragLeaveTimer = setTimeout(() => {
28
+ var e, t;
29
+ this._dragLeaveTimer = null, (e = (t = this._options).onDragLeave) == null || e.call(t, {
30
+ clientX: n,
31
+ clientY: r,
32
+ relatedTarget: i
33
+ });
34
+ }, e);
35
+ }, this._onDrop = (e) => {
36
+ var t, n;
37
+ e.preventDefault(), this._options.isDragged() && (this._clearDragLeaveTimer(), (t = (n = this._options).onDrop) == null || t.call(n, e));
38
+ }, this._host = t, this._options = n, t.addController(this);
39
+ }
40
+ hostConnected() {
41
+ this._abortController = new AbortController();
42
+ let { signal: e } = this._abortController;
43
+ this._host.addEventListener("dragover", this._onDragOver, { signal: e }), this._host.addEventListener("dragleave", this._onDragLeave, { signal: e }), this._host.addEventListener("drop", this._onDrop, { signal: e });
44
+ }
45
+ hostDisconnected() {
46
+ var e;
47
+ (e = this._abortController) == null || e.abort(), this._abortController = null, this._clearDragLeaveTimer();
48
+ }
49
+ _clearDragLeaveTimer() {
50
+ this._dragLeaveTimer !== null && (clearTimeout(this._dragLeaveTimer), this._dragLeaveTimer = null);
51
+ }
52
+ };
53
+ //#endregion
54
+ export { t as DragAndDropController };
55
+
56
+ //# sourceMappingURL=drag-and-drop-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag-and-drop-controller.js","names":[],"sources":["../../../../controllers/drag-and-drop-controller/src/drag-and-drop-controller.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 { ReactiveController, ReactiveElement } from 'lit';\n\n// ─────────────────────────\n// TYPES\n// ─────────────────────────\n\n/**\n * Snapshot of the fields read from a native `DragEvent` before it's recycled\n * by the browser, safe to read after the debounce in {@link DragAndDropControllerOptions.onDragLeave}.\n */\nexport interface DragLeaveSnapshot {\n clientX: number;\n clientY: number;\n relatedTarget: EventTarget | null;\n}\n\n/** Configuration options for {@link DragAndDropController}. */\nexport interface DragAndDropControllerOptions {\n /**\n * The host's own current \"is a drag over me\" flag. The controller never\n * keeps a copy of this state; it re-reads it on every native event so a\n * host that also exposes this flag as a public, externally-settable\n * property (as `swc-dropzone` does) can never drift out of sync with it.\n */\n isDragged: () => boolean;\n\n /**\n * Return `false` to reject the current drag payload; sets the OS cursor to\n * \"not-allowed\". Called on every native `dragover` tick. Defaults to\n * always-accept.\n */\n shouldAccept?: (event: DragEvent) => boolean;\n\n /** Called once when an accepted drag enters — not on every `dragover` tick. Set `isDragged`'s backing flag to `true` here. */\n onDragEnter?: (event: DragEvent) => void;\n\n /** Called once the accepted drag leaves or becomes rejected. Set `isDragged`'s backing flag to `false` here. */\n onDragLeave?: (snapshot: DragLeaveSnapshot) => void;\n\n /** Called on drop, only when `isDragged()` is currently `true`. */\n onDrop?: (event: DragEvent) => void;\n\n /** OS cursor feedback while an accepted drag hovers. Defaults to `'copy'`. */\n dropEffect?: () => DataTransfer['dropEffect'];\n}\n\n// Long enough that passing over a child element's own dragleave/dragover pair\n// doesn't flicker the state; short enough that leaving the host still reads\n// as immediate.\nconst DRAG_LEAVE_DEBOUNCE_MS = 100;\n\n// ─────────────────────────\n// CONTROLLER\n// ─────────────────────────\n\n/**\n * A Lit {@link ReactiveController} that manages native drag-and-drop event\n * wiring (`dragover` / `dragleave` / `drop`) for a host element: debounces\n * `dragleave` so passing over a child element doesn't flicker the state,\n * de-duplicates entry so `onDragEnter` fires once per hover session rather\n * than on every `dragover` tick, and lets the host veto payloads it doesn't\n * want via `shouldAccept`.\n *\n * The host owns its own \"dragged\" state (via `isDragged`/`onDragEnter`/\n * `onDragLeave`); this controller only drives the timing.\n *\n * @example\n * ```ts\n * const dragAndDrop = new DragAndDropController(this, {\n * isDragged: () => this._dragged,\n * onDragEnter: () => { this._dragged = true; },\n * onDragLeave: () => { this._dragged = false; },\n * onDrop: (event) => this._handleFilesDropped(event.dataTransfer?.files),\n * });\n * ```\n */\nexport class DragAndDropController implements ReactiveController {\n private readonly _host: ReactiveElement;\n private readonly _options: DragAndDropControllerOptions;\n private _dragLeaveTimer: ReturnType<typeof setTimeout> | null = null;\n private _abortController: AbortController | null = null;\n\n constructor(host: ReactiveElement, options: DragAndDropControllerOptions) {\n this._host = host;\n this._options = options;\n host.addController(this);\n }\n\n public hostConnected(): void {\n this._abortController = new AbortController();\n const { signal } = this._abortController;\n this._host.addEventListener('dragover', this._onDragOver as EventListener, {\n signal,\n });\n this._host.addEventListener(\n 'dragleave',\n this._onDragLeave as EventListener,\n { signal }\n );\n this._host.addEventListener('drop', this._onDrop as EventListener, {\n signal,\n });\n }\n\n public hostDisconnected(): void {\n this._abortController?.abort();\n this._abortController = null;\n this._clearDragLeaveTimer();\n }\n\n private readonly _onDragOver = (event: DragEvent): void => {\n event.preventDefault();\n if (!event.dataTransfer) {\n return;\n }\n\n this._clearDragLeaveTimer();\n if (this._options.shouldAccept?.(event) === false) {\n event.dataTransfer.dropEffect = 'none';\n if (this._options.isDragged()) {\n this._options.onDragLeave?.({\n clientX: event.clientX,\n clientY: event.clientY,\n relatedTarget: event.relatedTarget,\n });\n }\n return;\n }\n\n event.dataTransfer.dropEffect = this._options.dropEffect?.() ?? 'copy';\n\n if (!this._options.isDragged()) {\n this._options.onDragEnter?.(event);\n }\n };\n\n private readonly _onDragLeave = (event: DragEvent): void => {\n if (\n event.relatedTarget &&\n this._host.contains(event.relatedTarget as Node)\n ) {\n return;\n }\n\n this._clearDragLeaveTimer();\n // Capture synchronously; browsers recycle DragEvent objects after the\n // synchronous handler returns, so reading them inside setTimeout is unsafe.\n const { clientX, clientY, relatedTarget } = event;\n this._dragLeaveTimer = setTimeout(() => {\n this._dragLeaveTimer = null;\n this._options.onDragLeave?.({ clientX, clientY, relatedTarget });\n }, DRAG_LEAVE_DEBOUNCE_MS);\n };\n\n private readonly _onDrop = (event: DragEvent): void => {\n event.preventDefault();\n if (!this._options.isDragged()) {\n return;\n }\n\n this._clearDragLeaveTimer();\n this._options.onDrop?.(event);\n };\n\n private _clearDragLeaveTimer(): void {\n if (this._dragLeaveTimer !== null) {\n clearTimeout(this._dragLeaveTimer);\n this._dragLeaveTimer = null;\n }\n }\n}\n"],"mappings":";AA6DA,IAAM,IAAyB,KA2BlB,IAAb,MAAiE;CAM/D,YAAY,GAAuB,GAAuC;AAGxE,yBAN8D,8BACb,0BA8BnB,MAA2B;;AACzD,SAAM,gBAAgB,EACjB,EAAM,cAKX;QADA,KAAK,sBAAsB,IAC3B,KAAA,IAAI,KAAK,UAAS,iBAAA,OAAA,KAAA,IAAA,EAAA,KAAA,GAAe,EAAM,MAAK,IAAO;AAEjD,SADA,EAAM,aAAa,aAAa,QAC5B,KAAK,SAAS,WAAW,EAAE;;AAC7B,OAAA,KAAA,IAAA,KAAK,UAAS,gBAAA,QAAA,EAAA,KAAA,GAAc;OAC1B,SAAS,EAAM;OACf,SAAS,EAAM;OACf,eAAe,EAAM;OACtB,CAAC;;AAEJ;;AAKF,QAFA,EAAM,aAAa,cAAA,KAAA,KAAA,IAAa,KAAK,UAAS,eAAA,OAAA,KAAA,IAAA,EAAA,KAAA,EAAc,KAAA,OAAI,SAAJ,GAExD,CAAC,KAAK,SAAS,WAAW,EAAE;;AAC9B,MAAA,KAAA,IAAA,KAAK,UAAS,gBAAA,QAAA,EAAA,KAAA,GAAc,EAAM;;;0BAIL,MAA2B;AAC1D,OACE,EAAM,iBACN,KAAK,MAAM,SAAS,EAAM,cAAsB,CAEhD;AAGF,QAAK,sBAAsB;GAG3B,IAAM,EAAE,YAAS,YAAS,qBAAkB;AAC5C,QAAK,kBAAkB,iBAAiB;;AAEtC,IADA,KAAK,kBAAkB,OACvB,KAAA,IAAA,KAAK,UAAS,gBAAA,QAAA,EAAA,KAAA,GAAc;KAAE;KAAS;KAAS;KAAe,CAAC;MAC/D,EAAuB;qBAGA,MAA2B;;AACrD,KAAM,gBAAgB,EACjB,KAAK,SAAS,WAAW,KAI9B,KAAK,sBAAsB,GAC3B,KAAA,IAAA,KAAK,UAAS,WAAA,QAAA,EAAA,KAAA,GAAS,EAAM;KA9E7B,KAAK,QAAQ,GACb,KAAK,WAAW,GAChB,EAAK,cAAc,KAAK;;CAG1B,gBAA6B;AAC3B,OAAK,mBAAmB,IAAI,iBAAiB;EAC7C,IAAM,EAAE,cAAW,KAAK;AASxB,EARA,KAAK,MAAM,iBAAiB,YAAY,KAAK,aAA8B,EACzE,WACD,CAAC,EACF,KAAK,MAAM,iBACT,aACA,KAAK,cACL,EAAE,WAAQ,CACX,EACD,KAAK,MAAM,iBAAiB,QAAQ,KAAK,SAA0B,EACjE,WACD,CAAC;;CAGJ,mBAAgC;;AAG9B,GAFA,IAAA,KAAK,qBAAA,QAAA,EAAkB,OAAO,EAC9B,KAAK,mBAAmB,MACxB,KAAK,sBAAsB;;CAyD7B,uBAAqC;AACnC,EAAI,KAAK,oBAAoB,SAC3B,aAAa,KAAK,gBAAgB,EAClC,KAAK,kBAAkB"}
@@ -13,11 +13,14 @@
13
13
  * Public exports for Lit reactive controllers shared across 2nd-gen packages.
14
14
  */
15
15
  export { ColorController, type Color, type ColorTypes, } from './color-controller/index.js';
16
+ export { DragAndDropController, type DragAndDropControllerOptions, type DragLeaveSnapshot, } from './drag-and-drop-controller/index.js';
16
17
  export { focusgroupNavigationActiveChange, FocusgroupNavigationController, type FocusgroupActiveChangeSource, type FocusgroupDirection, type FocusgroupNavigationActiveChangeDetail, type FocusgroupNavigationOptions, } from './focusgroup-navigation-controller/index.js';
17
18
  export { LiveSelectionController, type LiveSelectionMode, type LiveSelectionOptions, } from './live-selection-controller/index.js';
18
19
  export { HoverController, type HoverControllerHost, type HoverControllerOptions, } from './hover-controller/index.js';
19
20
  export { LanguageResolutionController, languageResolverUpdatedSymbol, } from './language-resolution.js';
20
- export { PageScrollLockController } from './page-scroll-lock.js';
21
+ export { PageScrollLockController } from './page-scroll-lock-controller/index.js';
21
22
  export { PendingController, type PendingControllerHost, type PendingControllerOptions, } from './pending-controller/index.js';
22
23
  export { ALL_PLACEMENTS, fromFloatingPlacement, PlacementController, toFloatingPlacement, type Placement, type PlacementOptions, type VirtualTrigger, } from './placement-controller/index.js';
23
24
  export { SlotAttributePropagationController, type SlotAttributePropagationControllerOptions, } from './slot-attribute-propagation-controller/index.js';
25
+ export { SlotPresenceController } from './slot-presence-controller/index.js';
26
+ export { SlotTextController, type SlotTextConfig, } from './slot-text-controller/index.js';
@@ -1,15 +1,18 @@
1
1
  import { SlotAttributePropagationController as e } from "./slot-attribute-propagation-controller/src/slot-attribute-propagation-controller.js";
2
- import { HoverController as t } from "./hover-controller/src/hover-controller.js";
3
- import { fromFloatingPlacement as n, toFloatingPlacement as r } from "./placement-controller/src/placement-conversion.js";
4
- import { ALL_PLACEMENTS as i } from "./placement-controller/src/types.js";
5
- import { PlacementController as a } from "./placement-controller/src/placement-controller.js";
2
+ import { SlotTextController as t } from "./slot-text-controller/src/slot-text-controller.js";
3
+ import { DragAndDropController as n } from "./drag-and-drop-controller/src/drag-and-drop-controller.js";
4
+ import { HoverController as r } from "./hover-controller/src/hover-controller.js";
5
+ import { fromFloatingPlacement as i, toFloatingPlacement as a } from "./placement-controller/src/placement-conversion.js";
6
+ import { ALL_PLACEMENTS as o } from "./placement-controller/src/types.js";
7
+ import { PlacementController as s } from "./placement-controller/src/placement-controller.js";
6
8
  import "./placement-controller/index.js";
7
- import { LanguageResolutionController as o, languageResolverUpdatedSymbol as s } from "./language-resolution.js";
8
- import { PendingController as c } from "./pending-controller/src/pending-controller.js";
9
+ import { LanguageResolutionController as c, languageResolverUpdatedSymbol as l } from "./language-resolution.js";
10
+ import { SlotPresenceController as u } from "./slot-presence-controller/src/slot-presence-controller.js";
11
+ import { PendingController as d } from "./pending-controller/src/pending-controller.js";
9
12
  import "./pending-controller/index.js";
10
- import { ColorController as l } from "./color-controller/src/color-controller.js";
13
+ import { ColorController as f } from "./color-controller/src/color-controller.js";
11
14
  import "./color-controller/index.js";
12
- import { FocusgroupNavigationController as u, focusgroupNavigationActiveChange as d } from "./focusgroup-navigation-controller/src/focusgroup-navigation-controller.js";
13
- import { LiveSelectionController as f } from "./live-selection-controller/src/live-selection-controller.js";
14
- import { PageScrollLockController as p } from "./page-scroll-lock.js";
15
- export { i as ALL_PLACEMENTS, l as ColorController, u as FocusgroupNavigationController, t as HoverController, o as LanguageResolutionController, f as LiveSelectionController, p as PageScrollLockController, c as PendingController, a as PlacementController, e as SlotAttributePropagationController, d as focusgroupNavigationActiveChange, n as fromFloatingPlacement, s as languageResolverUpdatedSymbol, r as toFloatingPlacement };
15
+ import { FocusgroupNavigationController as p, focusgroupNavigationActiveChange as m } from "./focusgroup-navigation-controller/src/focusgroup-navigation-controller.js";
16
+ import { LiveSelectionController as h } from "./live-selection-controller/src/live-selection-controller.js";
17
+ import { PageScrollLockController as g } from "./page-scroll-lock-controller/src/page-scroll-lock.js";
18
+ export { o as ALL_PLACEMENTS, f as ColorController, n as DragAndDropController, p as FocusgroupNavigationController, r as HoverController, c as LanguageResolutionController, h as LiveSelectionController, g as PageScrollLockController, d as PendingController, s as PlacementController, e as SlotAttributePropagationController, u as SlotPresenceController, t as SlotTextController, m as focusgroupNavigationActiveChange, i as fromFloatingPlacement, l as languageResolverUpdatedSymbol, a as toFloatingPlacement };
@@ -0,0 +1,12 @@
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
+ export { PageScrollLockController } from './src/page-scroll-lock.js';
@@ -0,0 +1,2 @@
1
+ import { PageScrollLockController as e } from "./src/page-scroll-lock.js";
2
+ export { e as PageScrollLockController };
@@ -1,4 +1,4 @@
1
- //#region controllers/page-scroll-lock.ts
1
+ //#region controllers/page-scroll-lock-controller/src/page-scroll-lock.ts
2
2
  var e = 0, t = "";
3
3
  function n() {
4
4
  if (e === 0) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-scroll-lock.js","names":[],"sources":["../../../../controllers/page-scroll-lock-controller/src/page-scroll-lock.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 { ReactiveController, ReactiveElement } from 'lit';\n\n// ────────────────────────────────────────────\n// Module-scoped reference-counted lock\n// ────────────────────────────────────────────\n//\n// Stacked blocking surfaces (e.g. nested modal dialogs, a modal popover opened\n// over another) must coordinate a single page-scroll lock. The document's\n// original `overflow` is captured once on the 0 -> 1 transition and restored\n// once on the 1 -> 0 transition. Saving per instance would let a later locker\n// capture an already-locked value (`hidden`) and then restore it permanently\n// when it releases, leaving the page unscrollable.\n\nlet lockCount = 0;\nlet savedOverflow = '';\n\nfunction acquirePageScrollLock(): void {\n if (lockCount === 0) {\n const html = document.documentElement;\n savedOverflow = html.style.overflow;\n html.style.overflow = 'hidden';\n }\n lockCount += 1;\n}\n\nfunction releasePageScrollLock(): void {\n if (lockCount === 0) {\n return;\n }\n lockCount -= 1;\n if (lockCount === 0) {\n document.documentElement.style.overflow = savedOverflow;\n savedOverflow = '';\n }\n}\n\n/**\n * Locks page scroll behind a blocking surface (a modal popover, dialog, or tray)\n * by setting `overflow: hidden` on the document element. A component's shadow\n * stylesheet cannot reach `<html>`, so this is done in JS.\n *\n * The lock is reference-counted at module scope so concurrent locks from stacked\n * surfaces do not clobber one another's saved state. Each host holds at most one\n * count (the per-instance `lock()` / `unlock()` are idempotent), and the\n * controller releases the host's count automatically on disconnect.\n */\nexport class PageScrollLockController implements ReactiveController {\n private _locked = false;\n\n constructor(host: ReactiveElement) {\n host.addController(this);\n }\n\n /** Lock page scroll on behalf of the host. Idempotent per host. */\n public lock(): void {\n if (this._locked) {\n return;\n }\n this._locked = true;\n acquirePageScrollLock();\n }\n\n /** Release the host's lock if it holds one. Idempotent per host. */\n public unlock(): void {\n if (!this._locked) {\n return;\n }\n this._locked = false;\n releasePageScrollLock();\n }\n\n public hostDisconnected(): void {\n this.unlock();\n }\n}\n"],"mappings":";AAyBA,IAAI,IAAY,GACZ,IAAgB;AAEpB,SAAS,IAA8B;AACrC,KAAI,MAAc,GAAG;EACnB,IAAM,IAAO,SAAS;AAEtB,EADA,IAAgB,EAAK,MAAM,UAC3B,EAAK,MAAM,WAAW;;AAExB,MAAa;;AAGf,SAAS,IAA8B;AACjC,OAAc,MAGlB,KACI,MAAc,MAChB,SAAS,gBAAgB,MAAM,WAAW,GAC1C,IAAgB;;AAcpB,IAAa,IAAb,MAAoE;CAGlE,YAAY,GAAuB;AACjC,iBAHgB,IAGhB,EAAK,cAAc,KAAK;;CAI1B,OAAoB;AACd,OAAK,YAGT,KAAK,UAAU,IACf,GAAuB;;CAIzB,SAAsB;AACf,OAAK,YAGV,KAAK,UAAU,IACf,GAAuB;;CAGzB,mBAAgC;AAC9B,OAAK,QAAQ"}