@phcdevworks/spectre-components 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/base-DQtCQ-dP.d.cts +22 -0
  2. package/dist/base-DQtCQ-dP.d.ts +22 -0
  3. package/dist/button.cjs +149 -124
  4. package/dist/button.cjs.map +1 -1
  5. package/dist/button.d.cts +15 -40
  6. package/dist/button.d.ts +15 -40
  7. package/dist/button.js +150 -125
  8. package/dist/button.js.map +1 -1
  9. package/dist/checkbox.cjs +140 -25
  10. package/dist/checkbox.cjs.map +1 -1
  11. package/dist/checkbox.d.cts +32 -32
  12. package/dist/checkbox.d.ts +32 -32
  13. package/dist/checkbox.js +141 -26
  14. package/dist/checkbox.js.map +1 -1
  15. package/dist/fieldset.cjs +96 -50
  16. package/dist/fieldset.cjs.map +1 -1
  17. package/dist/fieldset.d.cts +24 -36
  18. package/dist/fieldset.d.ts +24 -36
  19. package/dist/fieldset.js +96 -50
  20. package/dist/fieldset.js.map +1 -1
  21. package/dist/form-iI7vV-3W.d.cts +6 -0
  22. package/dist/form-iI7vV-3W.d.ts +6 -0
  23. package/dist/index.cjs +298 -826
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +5 -2
  26. package/dist/index.d.ts +5 -2
  27. package/dist/index.js +300 -827
  28. package/dist/index.js.map +1 -1
  29. package/dist/input.cjs +70 -59
  30. package/dist/input.cjs.map +1 -1
  31. package/dist/input.d.cts +25 -36
  32. package/dist/input.d.ts +25 -36
  33. package/dist/input.js +70 -59
  34. package/dist/input.js.map +1 -1
  35. package/dist/label.cjs +101 -38
  36. package/dist/label.cjs.map +1 -1
  37. package/dist/label.d.cts +16 -20
  38. package/dist/label.d.ts +16 -20
  39. package/dist/label.js +101 -38
  40. package/dist/label.js.map +1 -1
  41. package/dist/projectable-DcnBRiko.d.cts +17 -0
  42. package/dist/projectable-SzbPvXfM.d.ts +17 -0
  43. package/dist/radio.cjs +140 -25
  44. package/dist/radio.cjs.map +1 -1
  45. package/dist/radio.d.cts +32 -32
  46. package/dist/radio.d.ts +32 -32
  47. package/dist/radio.js +141 -26
  48. package/dist/radio.js.map +1 -1
  49. package/dist/select.cjs +142 -113
  50. package/dist/select.cjs.map +1 -1
  51. package/dist/select.d.cts +23 -41
  52. package/dist/select.d.ts +23 -41
  53. package/dist/select.js +143 -113
  54. package/dist/select.js.map +1 -1
  55. package/dist/textarea.cjs +24 -223
  56. package/dist/textarea.cjs.map +1 -1
  57. package/dist/textarea.d.cts +20 -32
  58. package/dist/textarea.d.ts +20 -32
  59. package/dist/textarea.js +24 -223
  60. package/dist/textarea.js.map +1 -1
  61. package/package.json +11 -11
package/dist/label.js CHANGED
@@ -2,10 +2,12 @@ import { LitElement, nothing, html } from 'lit';
2
2
  import { ifDefined } from 'lit/directives/if-defined.js';
3
3
 
4
4
  // src/components/label/sp-label.ts
5
- var SpectreLabelElement = class extends LitElement {
5
+ var SpectreBaseElement = class extends LitElement {
6
6
  constructor() {
7
7
  super(...arguments);
8
- this.projectedContent = [];
8
+ this.ariaLabel = null;
9
+ this.ariaLabelledBy = null;
10
+ this.ariaDescribedBy = null;
9
11
  }
10
12
  get id() {
11
13
  return this._id ?? "";
@@ -21,6 +23,8 @@ var SpectreLabelElement = class extends LitElement {
21
23
  }
22
24
  this.requestUpdate();
23
25
  }
26
+ // Spectre components intentionally render in light DOM so the global
27
+ // `@phcdevworks/spectre-ui` styling contract can apply directly.
24
28
  createRenderRoot() {
25
29
  return this;
26
30
  }
@@ -30,12 +34,6 @@ var SpectreLabelElement = class extends LitElement {
30
34
  if (hostId !== null) {
31
35
  this.id = hostId;
32
36
  }
33
- this.syncProjectedContent();
34
- this.startContentObserver();
35
- }
36
- disconnectedCallback() {
37
- this.stopContentObserver();
38
- super.disconnectedCallback();
39
37
  }
40
38
  getAttribute(qualifiedName) {
41
39
  if (qualifiedName === "id") {
@@ -63,24 +61,88 @@ var SpectreLabelElement = class extends LitElement {
63
61
  }
64
62
  super.removeAttribute(qualifiedName);
65
63
  }
64
+ get forwardedAriaLabel() {
65
+ const value = this.ariaLabel?.trim();
66
+ return value ? value : void 0;
67
+ }
68
+ get forwardedAriaLabelledBy() {
69
+ const value = this.ariaLabelledBy?.trim();
70
+ return value ? value : void 0;
71
+ }
72
+ get forwardedAriaDescribedBy() {
73
+ const value = this.ariaDescribedBy?.trim();
74
+ return value ? value : void 0;
75
+ }
76
+ };
77
+ SpectreBaseElement.properties = {
78
+ ariaLabel: { attribute: "aria-label", type: String },
79
+ ariaLabelledBy: { attribute: "aria-labelledby", type: String },
80
+ ariaDescribedBy: { attribute: "aria-describedby", type: String }
81
+ };
82
+
83
+ // src/utils/dom.ts
84
+ function hasMeaningfulContent(nodes) {
85
+ return nodes.some((node) => {
86
+ if (node.nodeType === Node.ELEMENT_NODE) {
87
+ return true;
88
+ }
89
+ if (node.nodeType === Node.TEXT_NODE) {
90
+ return (node.textContent?.trim().length ?? 0) > 0;
91
+ }
92
+ return false;
93
+ });
94
+ }
95
+
96
+ // src/utils/projectable.ts
97
+ var SpectreProjectableElement = class extends SpectreBaseElement {
98
+ constructor() {
99
+ super(...arguments);
100
+ this.projectedContent = [];
101
+ }
102
+ get hasProjectedContent() {
103
+ return hasMeaningfulContent(this.projectedContent);
104
+ }
105
+ connectedCallback() {
106
+ super.connectedCallback();
107
+ this.syncProjectedContent();
108
+ this.startContentObserver();
109
+ }
110
+ disconnectedCallback() {
111
+ this.stopContentObserver();
112
+ super.disconnectedCallback();
113
+ }
66
114
  update(changedProperties) {
67
115
  this.stopContentObserver();
68
116
  super.update(changedProperties);
69
117
  this.startContentObserver();
70
118
  }
71
- get nativeLabel() {
72
- return this.querySelector("[data-sp-label-native]");
119
+ syncProjectedContent() {
120
+ const nextProjectedContent = [];
121
+ const sourceNodes = [
122
+ ...this.childNodes,
123
+ ...this.getContentContainer()?.childNodes ?? []
124
+ ];
125
+ sourceNodes.forEach((node) => {
126
+ if (!this.isInternalNode(node) && !nextProjectedContent.includes(node)) {
127
+ nextProjectedContent.push(node);
128
+ }
129
+ });
130
+ const hasChanged = nextProjectedContent.length !== this.projectedContent.length || nextProjectedContent.some((node, index) => node !== this.projectedContent[index]);
131
+ if (hasChanged) {
132
+ this.projectedContent = nextProjectedContent;
133
+ }
134
+ return hasChanged;
73
135
  }
74
136
  startContentObserver() {
75
137
  if (this.contentObserver) {
76
138
  return;
77
139
  }
78
140
  this.contentObserver = new MutationObserver((mutations) => {
79
- const isInternalMovement = mutations.every((mutation) => {
80
- return Array.from(mutation.removedNodes).every(
81
- (node) => this.isInternalLabelNode(node) || this.contains(node)
82
- ) && Array.from(mutation.addedNodes).every((node) => this.isInternalLabelNode(node));
83
- });
141
+ const isInternalMovement = mutations.every(
142
+ (mutation) => Array.from(mutation.removedNodes).every(
143
+ (node) => this.isInternalNode(node) || this.contains(node)
144
+ ) && Array.from(mutation.addedNodes).every((node) => this.isInternalNode(node))
145
+ );
84
146
  if (isInternalMovement) {
85
147
  return;
86
148
  }
@@ -94,50 +156,51 @@ var SpectreLabelElement = class extends LitElement {
94
156
  this.contentObserver?.disconnect();
95
157
  this.contentObserver = void 0;
96
158
  }
97
- syncProjectedContent() {
98
- const nextProjectedContent = [];
99
- Array.from(this.childNodes).forEach((node) => {
100
- if (this.isInternalLabelNode(node)) {
101
- this.projectedContent.forEach((projectedNode) => {
102
- if (projectedNode.parentNode !== this && this.contains(projectedNode)) {
103
- nextProjectedContent.push(projectedNode);
104
- }
105
- });
106
- return;
107
- }
108
- nextProjectedContent.push(node);
109
- });
110
- if (nextProjectedContent.length === this.projectedContent.length && nextProjectedContent.every((node, index) => node === this.projectedContent[index])) {
159
+ };
160
+
161
+ // src/components/label/sp-label.ts
162
+ var SpectreLabelElement = class extends SpectreProjectableElement {
163
+ constructor() {
164
+ super(...arguments);
165
+ this.title = "";
166
+ }
167
+ getContentContainer() {
168
+ return this.querySelector("[data-sp-label-native]");
169
+ }
170
+ isInternalNode(node) {
171
+ if (node.nodeType !== Node.ELEMENT_NODE) {
111
172
  return false;
112
173
  }
113
- this.projectedContent = nextProjectedContent;
114
- return true;
115
- }
116
- isInternalLabelNode(node) {
117
- return node === this.nativeLabel;
174
+ const el = node;
175
+ return el.hasAttribute("data-sp-label-native");
118
176
  }
119
177
  focus(options) {
120
- this.nativeLabel?.focus(options);
178
+ this.getContentContainer()?.focus(options);
121
179
  }
122
180
  blur() {
123
- this.nativeLabel?.blur();
181
+ this.getContentContainer()?.blur();
124
182
  }
125
183
  render() {
126
184
  return html`
127
185
  <label
186
+ aria-describedby=${ifDefined(this.forwardedAriaDescribedBy)}
187
+ aria-label=${ifDefined(this.forwardedAriaLabel)}
188
+ aria-labelledby=${ifDefined(this.forwardedAriaLabelledBy)}
128
189
  class='sp-label'
129
190
  data-sp-label-native
130
191
  for=${ifDefined(this.htmlFor)}
131
192
  id=${ifDefined(this.id || void 0)}
132
193
  tabindex='-1'
194
+ title=${ifDefined(this.title || void 0)}
133
195
  >
134
- ${this.projectedContent.length > 0 ? this.projectedContent : nothing}
196
+ ${this.hasProjectedContent ? this.projectedContent : nothing}
135
197
  </label>
136
198
  `;
137
199
  }
138
200
  };
139
201
  SpectreLabelElement.properties = {
140
- htmlFor: { attribute: "for", type: String }
202
+ htmlFor: { attribute: "for", type: String, reflect: true },
203
+ title: { type: String, reflect: true }
141
204
  };
142
205
  function defineSpectreLabel(tagName = "sp-label") {
143
206
  const existingElement = customElements.get(tagName);
package/dist/label.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/label/sp-label.ts"],"names":[],"mappings":";;;;AAOO,IAAM,mBAAA,GAAN,cAAkC,UAAA,CAAwC;AAAA,EAA1E,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAOL,IAAA,IAAA,CAAQ,mBAA2B,EAAC;AAAA,EAAA;AAAA,EAGpC,IAAa,EAAA,GAAa;AACxB,IAAA,OAAO,KAAK,GAAA,IAAO,E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AA,EACjF;AACA,MAAA,OAAO,KAAA;AAAA,IACT;AAEA,IAAA,IAAA,CAAK,gBAAA,GAAmB,oBAAA;AACxB,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EAEQ,oBAAoB,IAAA,EAAqB;AAC/C,IAAA,OAAO,SAAS,IAAA,CAAK,WAAA;AAAA,EACvB;AAAA,EAES,MAAM,OAAA,EAA8B;AAC3C,IAAA,IAAA,CAAK,WAAA,EAAa,MAAM,OAAO,CAAA;AAAA,EACjC;AAAA,EAES,IAAA,GAAa;AACpB,IAAA,IAAA,CAAK,aAAa,IAAA,EAAK;AAAA,EACzB;AAAA,EAES,MAAA,GAAS;AAChB,IAAA,OAAO,IAAA;AAAA;AAAA;AAAA;AAAA,YAAA,EAIG,SAAA,CAAU,IAAA,CAAK,OAAO,CAAC;AAAA,WAAA,EACxB,SAAA,CAAU,IAAA,CAAK,EAAA,IAAM,MAAS,CAAC;AAAA;AAAA;AAAA,QAAA,EAGlC,KAAK,gBAAA,CAAiB,MAAA,GAAS,CAAA,GAAI,IAAA,CAAK,mBAAmB,OAAO;AAAA;AAAA,IAAA,CAAA;AAAA,EAG1E;AACF;AAlLa,mBAAA,CACJ,UAAA,GAAa;AAAA,EAClB,OAAA,EAAS,EAAE,SAAA,EAAW,KAAA,EAAO,MAAM,MAAA;AACrC,CAAA;AAiLK,SAAS,kBAAA,CAAmB,UAAU,UAAA,EAAwC;AACnF,EAAA,MAAM,eAAA,GAAkB,cAAA,CAAe,GAAA,CAAI,OAAO,CAAA;AAElD,EAAA,IAAI,eAAA,EAAiB;AACnB,IAAA,OAAO,eAAA;AAAA,EACT;AAEA,EAAA,cAAA,CAAe,MAAA,CAAO,SAAS,mBAAmB,CAAA;AAClD,EAAA,OAAO,mBAAA;AACT","file":"label.js","sourcesContent":["import { LitElement, html, nothing } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nexport interface SpectreLabelProps {\n htmlFor?: string;\n}\n\nexport class SpectreLabelElement extends LitElement implements SpectreLabelProps {\n static properties = {\n htmlFor: { attribute: 'for', type: String },\n };\n\n htmlFor?: string;\n private _id?: string;\n private projectedContent: Node[] = [];\n private contentObserver?: MutationObserver | undefined;\n\n override get id(): string {\n return this._id ?? '';\n }\n\n override set id(value: string) {\n if ((this._id ?? '') === value) {\n return;\n }\n\n this._id = value;\n\n const host = this as unknown as HTMLElement;\n if (HTMLElement.prototype.hasAttribute.call(host, 'id')) {\n HTMLElement.prototype.removeAttribute.call(host, 'id');\n }\n\n this.requestUpdate();\n }\n\n createRenderRoot(): this {\n return this;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n const hostId = super.getAttribute('id');\n\n if (hostId !== null) {\n this.id = hostId;\n }\n\n this.syncProjectedContent();\n this.startContentObserver();\n }\n\n override disconnectedCallback(): void {\n this.stopContentObserver();\n super.disconnectedCallback();\n }\n\n override getAttribute(qualifiedName: string): string | null {\n if (qualifiedName === 'id') {\n return this.id || null;\n }\n\n return super.getAttribute(qualifiedName);\n }\n\n override hasAttribute(qualifiedName: string): boolean {\n if (qualifiedName === 'id') {\n return this.id !== '';\n }\n\n return super.hasAttribute(qualifiedName);\n }\n\n override setAttribute(qualifiedName: string, value: string): void {\n if (qualifiedName === 'id') {\n this.id = value;\n return;\n }\n\n super.setAttribute(qualifiedName, value);\n }\n\n override removeAttribute(qualifiedName: string): void {\n if (qualifiedName === 'id') {\n this.id = '';\n return;\n }\n\n super.removeAttribute(qualifiedName);\n }\n\n protected override update(changedProperties: Map<PropertyKey, unknown>): void {\n this.stopContentObserver();\n super.update(changedProperties);\n this.startContentObserver();\n }\n\n private get nativeLabel(): HTMLLabelElement | null {\n return this.querySelector('[data-sp-label-native]');\n }\n\n private startContentObserver(): void {\n if (this.contentObserver) {\n return;\n }\n\n this.contentObserver = new MutationObserver((mutations) => {\n const isInternalMovement = mutations.every((mutation) => {\n return (\n Array.from(mutation.removedNodes).every(\n (node) => this.isInternalLabelNode(node) || this.contains(node),\n ) &&\n Array.from(mutation.addedNodes).every((node) => this.isInternalLabelNode(node))\n );\n });\n\n if (isInternalMovement) {\n return;\n }\n\n if (this.syncProjectedContent()) {\n this.requestUpdate();\n }\n });\n\n this.contentObserver.observe(this, { childList: true });\n }\n\n private stopContentObserver(): void {\n this.contentObserver?.disconnect();\n this.contentObserver = undefined;\n }\n\n private syncProjectedContent(): boolean {\n const nextProjectedContent: Node[] = [];\n\n Array.from(this.childNodes).forEach((node) => {\n if (this.isInternalLabelNode(node)) {\n this.projectedContent.forEach((projectedNode) => {\n if (projectedNode.parentNode !== this && this.contains(projectedNode)) {\n nextProjectedContent.push(projectedNode);\n }\n });\n return;\n }\n\n nextProjectedContent.push(node);\n });\n\n if (\n nextProjectedContent.length === this.projectedContent.length &&\n nextProjectedContent.every((node, index) => node === this.projectedContent[index])\n ) {\n return false;\n }\n\n this.projectedContent = nextProjectedContent;\n return true;\n }\n\n private isInternalLabelNode(node: Node): boolean {\n return node === this.nativeLabel;\n }\n\n override focus(options?: FocusOptions): void {\n this.nativeLabel?.focus(options);\n }\n\n override blur(): void {\n this.nativeLabel?.blur();\n }\n\n override render() {\n return html`\n <label\n class='sp-label'\n data-sp-label-native\n for=${ifDefined(this.htmlFor)}\n id=${ifDefined(this.id || undefined)}\n tabindex='-1'\n >\n ${this.projectedContent.length > 0 ? this.projectedContent : nothing}\n </label>\n `;\n }\n}\n\nexport function defineSpectreLabel(tagName = 'sp-label'): typeof SpectreLabelElement {\n const existingElement = customElements.get(tagName);\n\n if (existingElement) {\n return existingElement as unknown as typeof SpectreLabelElement;\n }\n\n customElements.define(tagName, SpectreLabelElement);\n return SpectreLabelElement;\n}\n"]}
1
+ {"version":3,"sources":["../src/utils/base.ts","../src/utils/dom.ts","../src/utils/projectable.ts","../src/components/label/sp-label.ts"],"names":[],"mappings":";;;;AAEO,IAAM,kBAAA,GAAN,cAAiC,UAAA,CAAW;AAAA,EAA5C,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAOL,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,SAAA,CAAU,IAAA,CAAK,kBAAkB,CAAC;AAAA,wBAAA,EAC7B,SAAA,CAAU,IAAA,CAAK,uBAAuB,CAAC;AAAA;AAAA;AAAA,YAAA,EAGnD,SAAA,CAAU,IAAA,CAAK,OAAO,CAAC;AAAA,WAAA,EACxB,SAAA,CAAU,IAAA,CAAK,EAAA,IAAM,MAAS,CAAC;AAAA;AAAA,cAAA,EAE5B,SAAA,CAAU,IAAA,CAAK,KAAA,IAAS,MAAS,CAAC;AAAA;AAAA,QAAA,EAExC,IAAA,CAAK,mBAAA,GAAsB,IAAA,CAAK,gBAAA,GAAmB,OAAO;AAAA;AAAA,IAAA,CAAA;AAAA,EAGlE;AACF;AA/Ca,mBAAA,CACJ,UAAA,GAAa;AAAA,EAClB,SAAS,EAAE,SAAA,EAAW,OAAO,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACzD,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA;AAClC,CAAA;AA6CK,SAAS,kBAAA,CAAmB,UAAU,UAAA,EAAwC;AACnF,EAAA,MAAM,eAAA,GAAkB,cAAA,CAAe,GAAA,CAAI,OAAO,CAAA;AAElD,EAAA,IAAI,eAAA,EAAiB;AACnB,IAAA,OAAO,eAAA;AAAA,EACT;AAEA,EAAA,cAAA,CAAe,MAAA,CAAO,SAAS,mBAAmB,CAAA;AAClD,EAAA,OAAO,mBAAA;AACT","file":"label.js","sourcesContent":["import { LitElement, type PropertyDeclarations } from 'lit';\n\nexport class SpectreBaseElement extends LitElement {\n static properties: PropertyDeclarations = {\n ariaLabel: { attribute: 'aria-label', type: String },\n ariaLabelledBy: { attribute: 'aria-labelledby', type: String },\n ariaDescribedBy: { attribute: 'aria-describedby', type: String },\n };\n\n ariaLabel: string | null = null;\n ariaLabelledBy: string | null = null;\n ariaDescribedBy: string | null = null;\n\n private _id?: string;\n\n override get id(): string {\n return this._id ?? '';\n }\n\n override set id(value: string) {\n if ((this._id ?? '') === value) {\n return;\n }\n\n this._id = value;\n\n const host = this as unknown as HTMLElement;\n if (HTMLElement.prototype.hasAttribute.call(host, 'id')) {\n HTMLElement.prototype.removeAttribute.call(host, 'id');\n }\n\n this.requestUpdate();\n }\n\n // Spectre components intentionally render in light DOM so the global\n // `@phcdevworks/spectre-ui` styling contract can apply directly.\n createRenderRoot(): this {\n return this;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n\n const hostId = super.getAttribute('id');\n if (hostId !== null) {\n this.id = hostId;\n }\n }\n\n override getAttribute(qualifiedName: string): string | null {\n if (qualifiedName === 'id') {\n return this.id || null;\n }\n\n return super.getAttribute(qualifiedName);\n }\n\n override hasAttribute(qualifiedName: string): boolean {\n if (qualifiedName === 'id') {\n return this.id !== '';\n }\n\n return super.hasAttribute(qualifiedName);\n }\n\n override setAttribute(qualifiedName: string, value: string): void {\n if (qualifiedName === 'id') {\n this.id = value;\n return;\n }\n\n super.setAttribute(qualifiedName, value);\n }\n\n override removeAttribute(qualifiedName: string): void {\n if (qualifiedName === 'id') {\n this.id = '';\n return;\n }\n\n super.removeAttribute(qualifiedName);\n }\n\n protected get forwardedAriaLabel(): string | undefined {\n const value = this.ariaLabel?.trim();\n return value ? value : undefined;\n }\n\n protected get forwardedAriaLabelledBy(): string | undefined {\n const value = this.ariaLabelledBy?.trim();\n return value ? value : undefined;\n }\n\n protected get forwardedAriaDescribedBy(): string | undefined {\n const value = this.ariaDescribedBy?.trim();\n return value ? value : undefined;\n }\n}\n","export function hasMeaningfulContent(nodes: readonly Node[]): boolean {\n return nodes.some((node) => {\n if (node.nodeType === Node.ELEMENT_NODE) {\n return true;\n }\n\n if (node.nodeType === Node.TEXT_NODE) {\n return (node.textContent?.trim().length ?? 0) > 0;\n }\n\n return false;\n });\n}\n","import { SpectreBaseElement } from './base';\nimport { hasMeaningfulContent } from './dom';\n\nexport abstract class SpectreProjectableElement extends SpectreBaseElement {\n protected projectedContent: Node[] = [];\n private contentObserver?: MutationObserver | undefined;\n\n // Return the native container whose existing children are also treated as\n // projected content sources (e.g. the rendered <button>, <select>, <label>).\n protected abstract getContentContainer(): Element | null;\n\n // Return true if the node was rendered by this component and should not be\n // treated as external projected content.\n protected abstract isInternalNode(node: Node): boolean;\n\n protected get hasProjectedContent(): boolean {\n return hasMeaningfulContent(this.projectedContent);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.syncProjectedContent();\n this.startContentObserver();\n }\n\n override disconnectedCallback(): void {\n this.stopContentObserver();\n super.disconnectedCallback();\n }\n\n protected override update(changedProperties: Map<PropertyKey, unknown>): void {\n this.stopContentObserver();\n super.update(changedProperties);\n this.startContentObserver();\n }\n\n protected syncProjectedContent(): boolean {\n const nextProjectedContent: Node[] = [];\n const sourceNodes = [\n ...this.childNodes,\n ...(this.getContentContainer()?.childNodes ?? []),\n ];\n\n sourceNodes.forEach((node) => {\n if (!this.isInternalNode(node) && !nextProjectedContent.includes(node)) {\n nextProjectedContent.push(node);\n }\n });\n\n const hasChanged =\n nextProjectedContent.length !== this.projectedContent.length ||\n nextProjectedContent.some((node, index) => node !== this.projectedContent[index]);\n\n if (hasChanged) {\n this.projectedContent = nextProjectedContent;\n }\n\n return hasChanged;\n }\n\n private startContentObserver(): void {\n if (this.contentObserver) {\n return;\n }\n\n this.contentObserver = new MutationObserver((mutations) => {\n const isInternalMovement = mutations.every((mutation) =>\n Array.from(mutation.removedNodes).every(\n (node) => this.isInternalNode(node) || this.contains(node),\n ) &&\n Array.from(mutation.addedNodes).every((node) => this.isInternalNode(node)),\n );\n\n if (isInternalMovement) {\n return;\n }\n\n if (this.syncProjectedContent()) {\n this.requestUpdate();\n }\n });\n\n this.contentObserver.observe(this, { childList: true });\n }\n\n private stopContentObserver(): void {\n this.contentObserver?.disconnect();\n this.contentObserver = undefined;\n }\n}\n","import { html, nothing } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport { SpectreProjectableElement } from '../../utils/projectable';\n\nexport interface SpectreLabelProps {\n ariaLabel?: string | null;\n ariaLabelledBy?: string | null;\n ariaDescribedBy?: string | null;\n htmlFor?: string;\n title?: string;\n}\n\nexport class SpectreLabelElement extends SpectreProjectableElement implements SpectreLabelProps {\n static properties = {\n htmlFor: { attribute: 'for', type: String, reflect: true },\n title: { type: String, reflect: true },\n };\n\n htmlFor?: string;\n override title = '';\n\n protected override getContentContainer(): Element | null {\n return this.querySelector('[data-sp-label-native]');\n }\n\n protected override isInternalNode(node: Node): boolean {\n if (node.nodeType !== Node.ELEMENT_NODE) {\n return false;\n }\n\n const el = node as Element;\n return el.hasAttribute('data-sp-label-native');\n }\n\n override focus(options?: FocusOptions): void {\n (this.getContentContainer() as HTMLLabelElement | null)?.focus(options);\n }\n\n override blur(): void {\n (this.getContentContainer() as HTMLLabelElement | null)?.blur();\n }\n\n override render() {\n return html`\n <label\n aria-describedby=${ifDefined(this.forwardedAriaDescribedBy)}\n aria-label=${ifDefined(this.forwardedAriaLabel)}\n aria-labelledby=${ifDefined(this.forwardedAriaLabelledBy)}\n class='sp-label'\n data-sp-label-native\n for=${ifDefined(this.htmlFor)}\n id=${ifDefined(this.id || undefined)}\n tabindex='-1'\n title=${ifDefined(this.title || undefined)}\n >\n ${this.hasProjectedContent ? this.projectedContent : nothing}\n </label>\n `;\n }\n}\n\nexport function defineSpectreLabel(tagName = 'sp-label'): typeof SpectreLabelElement {\n const existingElement = customElements.get(tagName);\n\n if (existingElement) {\n return existingElement as unknown as typeof SpectreLabelElement;\n }\n\n customElements.define(tagName, SpectreLabelElement);\n return SpectreLabelElement;\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { S as SpectreBaseElement } from './base-DQtCQ-dP.cjs';
2
+
3
+ declare abstract class SpectreProjectableElement extends SpectreBaseElement {
4
+ protected projectedContent: Node[];
5
+ private contentObserver?;
6
+ protected abstract getContentContainer(): Element | null;
7
+ protected abstract isInternalNode(node: Node): boolean;
8
+ protected get hasProjectedContent(): boolean;
9
+ connectedCallback(): void;
10
+ disconnectedCallback(): void;
11
+ protected update(changedProperties: Map<PropertyKey, unknown>): void;
12
+ protected syncProjectedContent(): boolean;
13
+ private startContentObserver;
14
+ private stopContentObserver;
15
+ }
16
+
17
+ export { SpectreProjectableElement as S };
@@ -0,0 +1,17 @@
1
+ import { S as SpectreBaseElement } from './base-DQtCQ-dP.js';
2
+
3
+ declare abstract class SpectreProjectableElement extends SpectreBaseElement {
4
+ protected projectedContent: Node[];
5
+ private contentObserver?;
6
+ protected abstract getContentContainer(): Element | null;
7
+ protected abstract isInternalNode(node: Node): boolean;
8
+ protected get hasProjectedContent(): boolean;
9
+ connectedCallback(): void;
10
+ disconnectedCallback(): void;
11
+ protected update(changedProperties: Map<PropertyKey, unknown>): void;
12
+ protected syncProjectedContent(): boolean;
13
+ private startContentObserver;
14
+ private stopContentObserver;
15
+ }
16
+
17
+ export { SpectreProjectableElement as S };
package/dist/radio.cjs CHANGED
@@ -1,23 +1,16 @@
1
1
  'use strict';
2
2
 
3
3
  var lit = require('lit');
4
+ var live_js = require('lit/directives/live.js');
4
5
  var ifDefined_js = require('lit/directives/if-defined.js');
5
6
 
6
7
  // src/components/radio/sp-radio.ts
7
- var SpectreRadioElement = class extends lit.LitElement {
8
+ var SpectreBaseElement = class extends lit.LitElement {
8
9
  constructor() {
9
10
  super(...arguments);
10
11
  this.ariaLabel = null;
11
12
  this.ariaLabelledBy = null;
12
13
  this.ariaDescribedBy = null;
13
- this.autofocus = false;
14
- this.checked = false;
15
- this.disabled = false;
16
- this.invalid = false;
17
- this.label = "";
18
- this.required = false;
19
- this.title = "";
20
- this.value = "on";
21
14
  }
22
15
  get id() {
23
16
  return this._id ?? "";
@@ -33,6 +26,8 @@ var SpectreRadioElement = class extends lit.LitElement {
33
26
  }
34
27
  this.requestUpdate();
35
28
  }
29
+ // Spectre components intentionally render in light DOM so the global
30
+ // `@phcdevworks/spectre-ui` styling contract can apply directly.
36
31
  createRenderRoot() {
37
32
  return this;
38
33
  }
@@ -69,14 +64,6 @@ var SpectreRadioElement = class extends lit.LitElement {
69
64
  }
70
65
  super.removeAttribute(qualifiedName);
71
66
  }
72
- willUpdate(changedProperties) {
73
- if (changedProperties.has("value") && this.value == null) {
74
- this.value = "on";
75
- }
76
- }
77
- get nativeInput() {
78
- return this.querySelector("[data-sp-radio-native]");
79
- }
80
67
  get forwardedAriaLabel() {
81
68
  const value = this.ariaLabel?.trim();
82
69
  return value ? value : void 0;
@@ -89,6 +76,130 @@ var SpectreRadioElement = class extends lit.LitElement {
89
76
  const value = this.ariaDescribedBy?.trim();
90
77
  return value ? value : void 0;
91
78
  }
79
+ };
80
+ SpectreBaseElement.properties = {
81
+ ariaLabel: { attribute: "aria-label", type: String },
82
+ ariaLabelledBy: { attribute: "aria-labelledby", type: String },
83
+ ariaDescribedBy: { attribute: "aria-describedby", type: String }
84
+ };
85
+
86
+ // src/utils/dom.ts
87
+ function hasMeaningfulContent(nodes) {
88
+ return nodes.some((node) => {
89
+ if (node.nodeType === Node.ELEMENT_NODE) {
90
+ return true;
91
+ }
92
+ if (node.nodeType === Node.TEXT_NODE) {
93
+ return (node.textContent?.trim().length ?? 0) > 0;
94
+ }
95
+ return false;
96
+ });
97
+ }
98
+
99
+ // src/utils/projectable.ts
100
+ var SpectreProjectableElement = class extends SpectreBaseElement {
101
+ constructor() {
102
+ super(...arguments);
103
+ this.projectedContent = [];
104
+ }
105
+ get hasProjectedContent() {
106
+ return hasMeaningfulContent(this.projectedContent);
107
+ }
108
+ connectedCallback() {
109
+ super.connectedCallback();
110
+ this.syncProjectedContent();
111
+ this.startContentObserver();
112
+ }
113
+ disconnectedCallback() {
114
+ this.stopContentObserver();
115
+ super.disconnectedCallback();
116
+ }
117
+ update(changedProperties) {
118
+ this.stopContentObserver();
119
+ super.update(changedProperties);
120
+ this.startContentObserver();
121
+ }
122
+ syncProjectedContent() {
123
+ const nextProjectedContent = [];
124
+ const sourceNodes = [
125
+ ...this.childNodes,
126
+ ...this.getContentContainer()?.childNodes ?? []
127
+ ];
128
+ sourceNodes.forEach((node) => {
129
+ if (!this.isInternalNode(node) && !nextProjectedContent.includes(node)) {
130
+ nextProjectedContent.push(node);
131
+ }
132
+ });
133
+ const hasChanged = nextProjectedContent.length !== this.projectedContent.length || nextProjectedContent.some((node, index) => node !== this.projectedContent[index]);
134
+ if (hasChanged) {
135
+ this.projectedContent = nextProjectedContent;
136
+ }
137
+ return hasChanged;
138
+ }
139
+ startContentObserver() {
140
+ if (this.contentObserver) {
141
+ return;
142
+ }
143
+ this.contentObserver = new MutationObserver((mutations) => {
144
+ const isInternalMovement = mutations.every(
145
+ (mutation) => Array.from(mutation.removedNodes).every(
146
+ (node) => this.isInternalNode(node) || this.contains(node)
147
+ ) && Array.from(mutation.addedNodes).every((node) => this.isInternalNode(node))
148
+ );
149
+ if (isInternalMovement) {
150
+ return;
151
+ }
152
+ if (this.syncProjectedContent()) {
153
+ this.requestUpdate();
154
+ }
155
+ });
156
+ this.contentObserver.observe(this, { childList: true });
157
+ }
158
+ stopContentObserver() {
159
+ this.contentObserver?.disconnect();
160
+ this.contentObserver = void 0;
161
+ }
162
+ };
163
+
164
+ // src/components/radio/sp-radio.ts
165
+ var SpectreRadioElement = class extends SpectreProjectableElement {
166
+ constructor() {
167
+ super(...arguments);
168
+ this.autofocus = false;
169
+ this.checked = false;
170
+ this.disabled = false;
171
+ this.invalid = false;
172
+ this.loading = false;
173
+ this.required = false;
174
+ this.success = false;
175
+ this.title = "";
176
+ this.value = "on";
177
+ }
178
+ getContentContainer() {
179
+ return this.querySelector("[data-sp-radio-label]");
180
+ }
181
+ isInternalNode(node) {
182
+ if (node.nodeType !== Node.ELEMENT_NODE) {
183
+ return false;
184
+ }
185
+ const el = node;
186
+ return el.hasAttribute("data-sp-radio-label") || el.hasAttribute("data-sp-radio-native") || el.hasAttribute("data-sp-radio-label-fallback") || el.hasAttribute("data-sp-radio-indicator");
187
+ }
188
+ willUpdate(changedProperties) {
189
+ if (changedProperties.has("value") && this.value == null) {
190
+ this.value = "on";
191
+ }
192
+ }
193
+ get nativeInput() {
194
+ return this.querySelector("[data-sp-radio-native]");
195
+ }
196
+ get isDisabled() {
197
+ return this.disabled || this.loading;
198
+ }
199
+ get visibleLabelFallback() {
200
+ const trimmedLabel = this.label?.trim();
201
+ return trimmedLabel ? trimmedLabel : void 0;
202
+ }
92
203
  handleInput(event) {
93
204
  const input = event.currentTarget;
94
205
  this.checked = input.checked;
@@ -104,17 +215,20 @@ var SpectreRadioElement = class extends lit.LitElement {
104
215
  this.nativeInput?.blur();
105
216
  }
106
217
  render() {
218
+ const labelContent = this.hasProjectedContent ? this.projectedContent : this.visibleLabelFallback ? lit.html`<span class='sp-label' data-sp-radio-label-fallback>${this.visibleLabelFallback}</span>` : lit.nothing;
107
219
  return lit.html`
108
- <label>
220
+ <label data-sp-radio-label>
109
221
  <input
222
+ aria-busy=${this.loading ? "true" : "false"}
110
223
  aria-describedby=${ifDefined_js.ifDefined(this.forwardedAriaDescribedBy)}
111
224
  aria-invalid=${ifDefined_js.ifDefined(this.invalid ? "true" : void 0)}
112
225
  aria-label=${ifDefined_js.ifDefined(this.forwardedAriaLabel)}
113
226
  aria-labelledby=${ifDefined_js.ifDefined(this.forwardedAriaLabelledBy)}
114
227
  ?autofocus=${this.autofocus}
115
228
  data-sp-radio-native
116
- ?checked=${this.checked}
117
- ?disabled=${this.disabled}
229
+ .checked=${live_js.live(this.checked)}
230
+ ?disabled=${this.isDisabled}
231
+ form=${ifDefined_js.ifDefined(this.form)}
118
232
  id=${ifDefined_js.ifDefined(this.id || void 0)}
119
233
  name=${ifDefined_js.ifDefined(this.name)}
120
234
  ?required=${this.required}
@@ -124,22 +238,23 @@ var SpectreRadioElement = class extends lit.LitElement {
124
238
  @change=${this.handleChange}
125
239
  @input=${this.handleInput}
126
240
  />
127
- <span class='sp-label'>${this.label}</span>
241
+ <span class="sp-radio-indicator" data-sp-radio-indicator></span>
242
+ ${labelContent}
128
243
  </label>
129
244
  `;
130
245
  }
131
246
  };
132
247
  SpectreRadioElement.properties = {
133
- ariaLabel: { attribute: "aria-label", type: String },
134
- ariaLabelledBy: { attribute: "aria-labelledby", type: String },
135
- ariaDescribedBy: { attribute: "aria-describedby", type: String },
136
248
  autofocus: { type: Boolean, reflect: true },
137
249
  checked: { type: Boolean, reflect: true },
138
250
  disabled: { type: Boolean, reflect: true },
251
+ form: { type: String },
139
252
  invalid: { type: Boolean, reflect: true },
253
+ loading: { type: Boolean, reflect: true },
140
254
  label: { type: String, reflect: true },
141
- name: { type: String },
255
+ name: { type: String, reflect: true },
142
256
  required: { type: Boolean, reflect: true },
257
+ success: { type: Boolean, reflect: true },
143
258
  title: { type: String, reflect: true },
144
259
  value: { type: String }
145
260
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/radio/sp-radio.ts"],"names":["LitElement","html","ifDefined"],"mappings":";;;;;;AAeO,IAAM,mBAAA,GAAN,cAAkCA,cAAA,CAAwC;AAAA,EAA1E,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAgBL,IAAA,IAAA,CAAA,SAAA,GAA2B,IAAA;AAC3B,IAAA,IAAA,CAAA,cAAA,GAAgC,IAAA;AAChC,IAAA,IAAA,CAAA,eAAA,GAAiC,IAAA;AACjC,IAAA,IAAA,CAAA,SAAA,GAAY,KAAA;AACZ,IAAA,IAAA,CAAA,OAAA,GAAU,KAAA;AACV,IAAA,IAAA,CAAA,QAAA,GAAW,KAAA;AACX,IAAA,IAAA,CAAA,OAAA,GAAU,KAAA;AACV,IAAA,IAAA,CAAA,KAAA,GAAQ,EAAA;AAER,IAAA,IAAA,CAAA,QAAA,GAAW,KAAA;AACX,IAAA,IAAA,CAAS,KAAA,GAAQ,EAAA;AACjB,IAAA,IAAA,CAAA,KAAA,GAAQ,IAAA;AAAA,EAAA;AAAA,EAGR,IAAa,EAAA,GAAa;AACxB,IAAA,OAAO,KAAK,GAAA,IAAO,EAAA;AAAA,EACrB;AAAA,EAEA,IAAa,GAAG,KAAA,EAAe;AA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EAAW,iBAAA,EAAmB,MAAM,MAAA,EAAO;AAAA,EAC7D,eAAA,EAAiB,EAAE,SAAA,EAAW,kBAAA,EAAoB,MAAM,MAAA,EAAO;AAAA,EAC/D,SAAA,EAAW,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EAC1C,OAAA,EAAS,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACxC,QAAA,EAAU,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACzC,OAAA,EAAS,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACxC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACrC,IAAA,EAAM,EAAE,IAAA,EAAM,MAAA,EAAO;AAAA,EACrB,QAAA,EAAU,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACzC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACrC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA;AACjB,CAAA;AAwJK,SAAS,kBAAA,CAAmB,UAAU,UAAA,EAAwC;AACnF,EAAA,MAAM,eAAA,GAAkB,cAAA,CAAe,GAAA,CAAI,OAAO,CAAA;AAElD,EAAA,IAAI,eAAA,EAAiB;AACnB,IAAA,OAAO,eAAA;AAAA,EACT;AAEA,EAAA,cAAA,CAAe,MAAA,CAAO,SAAS,mBAAmB,CAAA;AAClD,EAAA,OAAO,mBAAA;AACT","file":"radio.cjs","sourcesContent":["import { LitElement, html } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nexport interface SpectreRadioProps {\n autofocus?: boolean;\n checked?: boolean;\n disabled?: boolean;\n invalid?: boolean;\n label?: string;\n name?: string;\n required?: boolean;\n title?: string;\n value?: string;\n}\n\nexport class SpectreRadioElement extends LitElement implements SpectreRadioProps {\n static properties = {\n ariaLabel: { attribute: 'aria-label', type: String },\n ariaLabelledBy: { attribute: 'aria-labelledby', type: String },\n ariaDescribedBy: { attribute: 'aria-describedby', type: String },\n autofocus: { type: Boolean, reflect: true },\n checked: { type: Boolean, reflect: true },\n disabled: { type: Boolean, reflect: true },\n invalid: { type: Boolean, reflect: true },\n label: { type: String, reflect: true },\n name: { type: String },\n required: { type: Boolean, reflect: true },\n title: { type: String, reflect: true },\n value: { type: String },\n };\n\n ariaLabel: string | null = null;\n ariaLabelledBy: string | null = null;\n ariaDescribedBy: string | null = null;\n autofocus = false;\n checked = false;\n disabled = false;\n invalid = false;\n label = '';\n name?: string;\n required = false;\n override title = '';\n value = 'on';\n private _id?: string;\n\n override get id(): string {\n return this._id ?? '';\n }\n\n override set id(value: string) {\n if ((this._id ?? '') === value) {\n return;\n }\n\n this._id = value;\n\n const host = this as unknown as HTMLElement;\n if (HTMLElement.prototype.hasAttribute.call(host, 'id')) {\n HTMLElement.prototype.removeAttribute.call(host, 'id');\n }\n\n this.requestUpdate();\n }\n\n createRenderRoot(): this {\n return this;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n const hostId = super.getAttribute('id');\n\n if (hostId !== null) {\n this.id = hostId;\n }\n }\n\n override getAttribute(qualifiedName: string): string | null {\n if (qualifiedName === 'id') {\n return this.id || null;\n }\n\n return super.getAttribute(qualifiedName);\n }\n\n override hasAttribute(qualifiedName: string): boolean {\n if (qualifiedName === 'id') {\n return this.id !== '';\n }\n\n return super.hasAttribute(qualifiedName);\n }\n\n override setAttribute(qualifiedName: string, value: string): void {\n if (qualifiedName === 'id') {\n this.id = value;\n return;\n }\n\n super.setAttribute(qualifiedName, value);\n }\n\n override removeAttribute(qualifiedName: string): void {\n if (qualifiedName === 'id') {\n this.id = '';\n return;\n }\n\n super.removeAttribute(qualifiedName);\n }\n\n protected override willUpdate(changedProperties: Map<PropertyKey, unknown>): void {\n if (changedProperties.has('value') && this.value == null) {\n this.value = 'on';\n }\n }\n\n private get nativeInput(): HTMLInputElement | null {\n return this.querySelector('[data-sp-radio-native]');\n }\n\n private get forwardedAriaLabel(): string | undefined {\n const value = this.ariaLabel?.trim();\n return value ? value : undefined;\n }\n\n private get forwardedAriaLabelledBy(): string | undefined {\n const value = this.ariaLabelledBy?.trim();\n return value ? value : undefined;\n }\n\n private get forwardedAriaDescribedBy(): string | undefined {\n const value = this.ariaDescribedBy?.trim();\n return value ? value : undefined;\n }\n\n private handleInput(event: Event): void {\n const input = event.currentTarget as HTMLInputElement;\n this.checked = input.checked;\n }\n\n private handleChange(event: Event): void {\n const input = event.currentTarget as HTMLInputElement;\n this.checked = input.checked;\n }\n\n override focus(options?: FocusOptions): void {\n this.nativeInput?.focus(options);\n }\n\n override blur(): void {\n this.nativeInput?.blur();\n }\n\n override render() {\n return html`\n <label>\n <input\n aria-describedby=${ifDefined(this.forwardedAriaDescribedBy)}\n aria-invalid=${ifDefined(this.invalid ? 'true' : undefined)}\n aria-label=${ifDefined(this.forwardedAriaLabel)}\n aria-labelledby=${ifDefined(this.forwardedAriaLabelledBy)}\n ?autofocus=${this.autofocus}\n data-sp-radio-native\n ?checked=${this.checked}\n ?disabled=${this.disabled}\n id=${ifDefined(this.id || undefined)}\n name=${ifDefined(this.name)}\n ?required=${this.required}\n title=${ifDefined(this.title || undefined)}\n type='radio'\n value=${ifDefined(this.value || undefined)}\n @change=${this.handleChange}\n @input=${this.handleInput}\n />\n <span class='sp-label'>${this.label}</span>\n </label>\n `;\n }\n}\n\nexport function defineSpectreRadio(tagName = 'sp-radio'): typeof SpectreRadioElement {\n const existingElement = customElements.get(tagName);\n\n if (existingElement) {\n return existingElement as unknown as typeof SpectreRadioElement;\n }\n\n customElements.define(tagName, SpectreRadioElement);\n return SpectreRadioElement;\n}\n"]}
1
+ {"version":3,"sources":["../src/utils/base.ts","../src/utils/dom.ts","../src/utils/projectable.ts","../src/components/radio/sp-radio.ts"],"names":["LitElement","html","nothing","ifDefined","live"],"mappings":";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B,SAAA,EAAW,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EAC1C,OAAA,EAAS,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACxC,QAAA,EAAU,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACzC,IAAA,EAAM,EAAE,IAAA,EAAM,MAAA,EAAO;AAAA,EACrB,OAAA,EAAS,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACxC,OAAA,EAAS,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACxC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACrC,IAAA,EAAM,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACpC,QAAA,EAAU,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACzC,OAAA,EAAS,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACxC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACrC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA;AACjB,CAAA;AA0GK,SAAS,kBAAA,CAAmB,UAAU,UAAA,EAAwC;AACnF,EAAA,MAAM,eAAA,GAAkB,cAAA,CAAe,GAAA,CAAI,OAAO,CAAA;AAElD,EAAA,IAAI,eAAA,EAAiB;AACnB,IAAA,OAAO,eAAA;AAAA,EACT;AAEA,EAAA,cAAA,CAAe,MAAA,CAAO,SAAS,mBAAmB,CAAA;AAClD,EAAA,OAAO,mBAAA;AACT","file":"radio.cjs","sourcesContent":["import { LitElement, type PropertyDeclarations } from 'lit';\n\nexport class SpectreBaseElement extends LitElement {\n static properties: PropertyDeclarations = {\n ariaLabel: { attribute: 'aria-label', type: String },\n ariaLabelledBy: { attribute: 'aria-labelledby', type: String },\n ariaDescribedBy: { attribute: 'aria-describedby', type: String },\n };\n\n ariaLabel: string | null = null;\n ariaLabelledBy: string | null = null;\n ariaDescribedBy: string | null = null;\n\n private _id?: string;\n\n override get id(): string {\n return this._id ?? '';\n }\n\n override set id(value: string) {\n if ((this._id ?? '') === value) {\n return;\n }\n\n this._id = value;\n\n const host = this as unknown as HTMLElement;\n if (HTMLElement.prototype.hasAttribute.call(host, 'id')) {\n HTMLElement.prototype.removeAttribute.call(host, 'id');\n }\n\n this.requestUpdate();\n }\n\n // Spectre components intentionally render in light DOM so the global\n // `@phcdevworks/spectre-ui` styling contract can apply directly.\n createRenderRoot(): this {\n return this;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n\n const hostId = super.getAttribute('id');\n if (hostId !== null) {\n this.id = hostId;\n }\n }\n\n override getAttribute(qualifiedName: string): string | null {\n if (qualifiedName === 'id') {\n return this.id || null;\n }\n\n return super.getAttribute(qualifiedName);\n }\n\n override hasAttribute(qualifiedName: string): boolean {\n if (qualifiedName === 'id') {\n return this.id !== '';\n }\n\n return super.hasAttribute(qualifiedName);\n }\n\n override setAttribute(qualifiedName: string, value: string): void {\n if (qualifiedName === 'id') {\n this.id = value;\n return;\n }\n\n super.setAttribute(qualifiedName, value);\n }\n\n override removeAttribute(qualifiedName: string): void {\n if (qualifiedName === 'id') {\n this.id = '';\n return;\n }\n\n super.removeAttribute(qualifiedName);\n }\n\n protected get forwardedAriaLabel(): string | undefined {\n const value = this.ariaLabel?.trim();\n return value ? value : undefined;\n }\n\n protected get forwardedAriaLabelledBy(): string | undefined {\n const value = this.ariaLabelledBy?.trim();\n return value ? value : undefined;\n }\n\n protected get forwardedAriaDescribedBy(): string | undefined {\n const value = this.ariaDescribedBy?.trim();\n return value ? value : undefined;\n }\n}\n","export function hasMeaningfulContent(nodes: readonly Node[]): boolean {\n return nodes.some((node) => {\n if (node.nodeType === Node.ELEMENT_NODE) {\n return true;\n }\n\n if (node.nodeType === Node.TEXT_NODE) {\n return (node.textContent?.trim().length ?? 0) > 0;\n }\n\n return false;\n });\n}\n","import { SpectreBaseElement } from './base';\nimport { hasMeaningfulContent } from './dom';\n\nexport abstract class SpectreProjectableElement extends SpectreBaseElement {\n protected projectedContent: Node[] = [];\n private contentObserver?: MutationObserver | undefined;\n\n // Return the native container whose existing children are also treated as\n // projected content sources (e.g. the rendered <button>, <select>, <label>).\n protected abstract getContentContainer(): Element | null;\n\n // Return true if the node was rendered by this component and should not be\n // treated as external projected content.\n protected abstract isInternalNode(node: Node): boolean;\n\n protected get hasProjectedContent(): boolean {\n return hasMeaningfulContent(this.projectedContent);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.syncProjectedContent();\n this.startContentObserver();\n }\n\n override disconnectedCallback(): void {\n this.stopContentObserver();\n super.disconnectedCallback();\n }\n\n protected override update(changedProperties: Map<PropertyKey, unknown>): void {\n this.stopContentObserver();\n super.update(changedProperties);\n this.startContentObserver();\n }\n\n protected syncProjectedContent(): boolean {\n const nextProjectedContent: Node[] = [];\n const sourceNodes = [\n ...this.childNodes,\n ...(this.getContentContainer()?.childNodes ?? []),\n ];\n\n sourceNodes.forEach((node) => {\n if (!this.isInternalNode(node) && !nextProjectedContent.includes(node)) {\n nextProjectedContent.push(node);\n }\n });\n\n const hasChanged =\n nextProjectedContent.length !== this.projectedContent.length ||\n nextProjectedContent.some((node, index) => node !== this.projectedContent[index]);\n\n if (hasChanged) {\n this.projectedContent = nextProjectedContent;\n }\n\n return hasChanged;\n }\n\n private startContentObserver(): void {\n if (this.contentObserver) {\n return;\n }\n\n this.contentObserver = new MutationObserver((mutations) => {\n const isInternalMovement = mutations.every((mutation) =>\n Array.from(mutation.removedNodes).every(\n (node) => this.isInternalNode(node) || this.contains(node),\n ) &&\n Array.from(mutation.addedNodes).every((node) => this.isInternalNode(node)),\n );\n\n if (isInternalMovement) {\n return;\n }\n\n if (this.syncProjectedContent()) {\n this.requestUpdate();\n }\n });\n\n this.contentObserver.observe(this, { childList: true });\n }\n\n private stopContentObserver(): void {\n this.contentObserver?.disconnect();\n this.contentObserver = undefined;\n }\n}\n","import { html, nothing } from 'lit';\nimport { live } from 'lit/directives/live.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport { SpectreProjectableElement } from '../../utils/projectable';\n\nexport interface SpectreRadioProps {\n ariaLabel?: string | null;\n ariaLabelledBy?: string | null;\n ariaDescribedBy?: string | null;\n autofocus?: boolean;\n checked?: boolean;\n disabled?: boolean;\n form?: string;\n invalid?: boolean;\n loading?: boolean;\n label?: string | undefined;\n name?: string | undefined;\n required?: boolean;\n success?: boolean;\n title?: string;\n value?: string;\n}\n\nexport class SpectreRadioElement extends SpectreProjectableElement implements SpectreRadioProps {\n static properties = {\n autofocus: { type: Boolean, reflect: true },\n checked: { type: Boolean, reflect: true },\n disabled: { type: Boolean, reflect: true },\n form: { type: String },\n invalid: { type: Boolean, reflect: true },\n loading: { type: Boolean, reflect: true },\n label: { type: String, reflect: true },\n name: { type: String, reflect: true },\n required: { type: Boolean, reflect: true },\n success: { type: Boolean, reflect: true },\n title: { type: String, reflect: true },\n value: { type: String },\n };\n\n autofocus = false;\n checked = false;\n disabled = false;\n form?: string;\n invalid = false;\n loading = false;\n label?: string;\n name?: string;\n required = false;\n success = false;\n override title = '';\n value = 'on';\n\n protected override getContentContainer(): Element | null {\n return this.querySelector('[data-sp-radio-label]');\n }\n\n protected override isInternalNode(node: Node): boolean {\n if (node.nodeType !== Node.ELEMENT_NODE) {\n return false;\n }\n\n const el = node as Element;\n return (\n el.hasAttribute('data-sp-radio-label') ||\n el.hasAttribute('data-sp-radio-native') ||\n el.hasAttribute('data-sp-radio-label-fallback') ||\n el.hasAttribute('data-sp-radio-indicator')\n );\n }\n\n protected override willUpdate(changedProperties: Map<PropertyKey, unknown>): void {\n if (changedProperties.has('value') && this.value == null) {\n this.value = 'on';\n }\n }\n\n private get nativeInput(): HTMLInputElement | null {\n return this.querySelector('[data-sp-radio-native]');\n }\n\n private get isDisabled(): boolean {\n return this.disabled || this.loading;\n }\n\n private get visibleLabelFallback(): string | undefined {\n const trimmedLabel = this.label?.trim();\n return trimmedLabel ? trimmedLabel : undefined;\n }\n\n private handleInput(event: Event): void {\n const input = event.currentTarget as HTMLInputElement;\n this.checked = input.checked;\n }\n\n private handleChange(event: Event): void {\n const input = event.currentTarget as HTMLInputElement;\n this.checked = input.checked;\n }\n\n override focus(options?: FocusOptions): void {\n this.nativeInput?.focus(options);\n }\n\n override blur(): void {\n this.nativeInput?.blur();\n }\n\n override render() {\n const labelContent = this.hasProjectedContent\n ? this.projectedContent\n : this.visibleLabelFallback\n ? html`<span class='sp-label' data-sp-radio-label-fallback>${this.visibleLabelFallback}</span>`\n : nothing;\n\n return html`\n <label data-sp-radio-label>\n <input\n aria-busy=${this.loading ? 'true' : 'false'}\n aria-describedby=${ifDefined(this.forwardedAriaDescribedBy)}\n aria-invalid=${ifDefined(this.invalid ? 'true' : undefined)}\n aria-label=${ifDefined(this.forwardedAriaLabel)}\n aria-labelledby=${ifDefined(this.forwardedAriaLabelledBy)}\n ?autofocus=${this.autofocus}\n data-sp-radio-native\n .checked=${live(this.checked)}\n ?disabled=${this.isDisabled}\n form=${ifDefined(this.form)}\n id=${ifDefined(this.id || undefined)}\n name=${ifDefined(this.name)}\n ?required=${this.required}\n title=${ifDefined(this.title || undefined)}\n type='radio'\n value=${ifDefined(this.value || undefined)}\n @change=${this.handleChange}\n @input=${this.handleInput}\n />\n <span class=\"sp-radio-indicator\" data-sp-radio-indicator></span>\n ${labelContent}\n </label>\n `;\n }\n}\n\nexport function defineSpectreRadio(tagName = 'sp-radio'): typeof SpectreRadioElement {\n const existingElement = customElements.get(tagName);\n\n if (existingElement) {\n return existingElement as unknown as typeof SpectreRadioElement;\n }\n\n customElements.define(tagName, SpectreRadioElement);\n return SpectreRadioElement;\n}\n"]}