@rettangoli/ui 1.0.1 → 1.0.2

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.
@@ -940,7 +940,7 @@ var rettangoli=(()=>{var fa=Object.defineProperty;var N=(e,t)=>{for(var r in t)f
940
940
  }
941
941
  ${z}
942
942
  ${j}
943
- `))}constructor(){super(),e.initializeStyleSheet(),this.shadow=this.attachShadow({mode:"open"}),this.shadow.adoptedStyleSheets=[e.styleSheet],this._styles={default:{},sm:{},md:{},lg:{},xl:{}},this._lastStyleString="",this._inputElement=document.createElement("input"),this._inputElement.type="checkbox",this._wrapperElement=document.createElement("label"),this._wrapperElement.className="checkbox-wrapper",this._labelElement=document.createElement("span"),this._labelElement.className="checkbox-label",this._labelSlotElement=document.createElement("slot"),this._labelSlotElement.addEventListener("slotchange",()=>{this._updateLabelState()}),this._labelElement.appendChild(this._labelSlotElement),this._styleElement=document.createElement("style"),this.shadow.appendChild(this._styleElement),this._wrapperElement.appendChild(this._inputElement),this._wrapperElement.appendChild(this._labelElement),this.shadow.appendChild(this._wrapperElement),this._inputElement.addEventListener("change",this._onChange)}static get observedAttributes(){return["key","checked","disabled","label",...J([...ue,"wh","w","h","hide","show","op","z"])]}get checked(){return this._inputElement.checked}set checked(t){this._inputElement.checked=!!t}get value(){return this._inputElement.checked}set value(t){this._inputElement.checked=!!t}_onChange=()=>{this.dispatchEvent(new CustomEvent("value-change",{detail:{value:this._inputElement.checked},bubbles:!0}))};attributeChangedCallback(t,r,s){if(t==="key"&&r!==s){requestAnimationFrame(()=>{let n=this.hasAttribute("checked");this._inputElement.checked=n});return}if(t==="checked"){this._inputElement.checked=s!==null;return}if(t==="disabled"){s!==null?this._inputElement.setAttribute("disabled",""):this._inputElement.removeAttribute("disabled");return}if(t==="label"){this._updateLabelState();return}this._styles={default:{},sm:{},md:{},lg:{},xl:{}},["default","sm","md","lg","xl"].forEach(n=>{let a=d=>`${n==="default"?"":`${n}-`}${d}`,l=this.getAttribute(a("wh")),p=V(l===null?this.getAttribute(a("w")):l),o=V(l===null?this.getAttribute(a("h")):l),u=this.getAttribute(a("op")),c=this.getAttribute(a("z"));c!==null&&(this._styles[n]["z-index"]=c),u!==null&&(this._styles[n].opacity=u),p==="f"?this._styles[n].width="var(--width-stretch)":p!==void 0&&(this._styles[n].width=p,this._styles[n]["min-width"]=p,this._styles[n]["max-width"]=p),o==="f"?this._styles[n].height="100%":o!==void 0&&(this._styles[n].height=o,this._styles[n]["min-height"]=o,this._styles[n]["max-height"]=o),this.hasAttribute(a("hide"))&&(this._styles[n].display="none"),this.hasAttribute(a("show"))&&(this._styles[n].display="block")});let i=X(this._styles,'input[type="checkbox"]');i!==this._lastStyleString&&(this._styleElement.textContent=i,this._lastStyleString=i)}connectedCallback(){let t=this.hasAttribute("checked");this._inputElement.checked=t,this.hasAttribute("disabled")&&this._inputElement.setAttribute("disabled",""),this._updateLabelState()}_updateLabelState(){let t=this.getAttribute("label");this._labelSlotElement.textContent=t??"";let s=this._labelSlotElement.assignedNodes({flatten:!0}).some(n=>n.nodeType===Node.TEXT_NODE?n.textContent.trim().length>0:n.nodeType===Node.ELEMENT_NODE),i=typeof t=="string"&&t.trim().length>0;s||i?this.setAttribute("has-label",""):this.removeAttribute("has-label")}},Os=({render:e,html:t})=>qt;var Jt=40,Ba=6,Yt=class e extends HTMLElement{static styleSheet=null;static initializeStyleSheet(){e.styleSheet||(e.styleSheet=new CSSStyleSheet,e.styleSheet.replaceSync(T`
943
+ `))}constructor(){super(),this._isSyncingLabelState=!1,e.initializeStyleSheet(),this.shadow=this.attachShadow({mode:"open"}),this.shadow.adoptedStyleSheets=[e.styleSheet],this._styles={default:{},sm:{},md:{},lg:{},xl:{}},this._lastStyleString="",this._inputElement=document.createElement("input"),this._inputElement.type="checkbox",this._wrapperElement=document.createElement("label"),this._wrapperElement.className="checkbox-wrapper",this._labelElement=document.createElement("span"),this._labelElement.className="checkbox-label",this._labelSlotElement=document.createElement("slot"),this._labelSlotElement.addEventListener("slotchange",()=>{this._updateLabelState()}),this._labelElement.appendChild(this._labelSlotElement),this._styleElement=document.createElement("style"),this.shadow.appendChild(this._styleElement),this._wrapperElement.appendChild(this._inputElement),this._wrapperElement.appendChild(this._labelElement),this.shadow.appendChild(this._wrapperElement),this._inputElement.addEventListener("change",this._onChange)}static get observedAttributes(){return["key","checked","disabled","label",...J([...ue,"wh","w","h","hide","show","op","z"])]}get checked(){return this._inputElement.checked}set checked(t){this._inputElement.checked=!!t}get value(){return this._inputElement.checked}set value(t){this._inputElement.checked=!!t}_onChange=()=>{this.dispatchEvent(new CustomEvent("value-change",{detail:{value:this._inputElement.checked},bubbles:!0}))};attributeChangedCallback(t,r,s){if(t==="key"&&r!==s){requestAnimationFrame(()=>{let n=this.hasAttribute("checked");this._inputElement.checked=n});return}if(t==="checked"){this._inputElement.checked=s!==null;return}if(t==="disabled"){s!==null?this._inputElement.setAttribute("disabled",""):this._inputElement.removeAttribute("disabled");return}if(t==="label"){this._updateLabelState();return}this._styles={default:{},sm:{},md:{},lg:{},xl:{}},["default","sm","md","lg","xl"].forEach(n=>{let a=d=>`${n==="default"?"":`${n}-`}${d}`,l=this.getAttribute(a("wh")),p=V(l===null?this.getAttribute(a("w")):l),o=V(l===null?this.getAttribute(a("h")):l),u=this.getAttribute(a("op")),c=this.getAttribute(a("z"));c!==null&&(this._styles[n]["z-index"]=c),u!==null&&(this._styles[n].opacity=u),p==="f"?this._styles[n].width="var(--width-stretch)":p!==void 0&&(this._styles[n].width=p,this._styles[n]["min-width"]=p,this._styles[n]["max-width"]=p),o==="f"?this._styles[n].height="100%":o!==void 0&&(this._styles[n].height=o,this._styles[n]["min-height"]=o,this._styles[n]["max-height"]=o),this.hasAttribute(a("hide"))&&(this._styles[n].display="none"),this.hasAttribute(a("show"))&&(this._styles[n].display="block")});let i=X(this._styles,'input[type="checkbox"]');i!==this._lastStyleString&&(this._styleElement.textContent=i,this._lastStyleString=i)}connectedCallback(){let t=this.hasAttribute("checked");this._inputElement.checked=t,this.hasAttribute("disabled")&&this._inputElement.setAttribute("disabled",""),this._updateLabelState()}_updateLabelState(){if(!this._isSyncingLabelState){this._isSyncingLabelState=!0;try{let t=this.getAttribute("label"),r=t??"";this._labelSlotElement.textContent!==r&&(this._labelSlotElement.textContent=r);let i=this._labelSlotElement.assignedNodes({flatten:!0}).some(l=>l.nodeType===Node.TEXT_NODE?l.textContent.trim().length>0:l.nodeType===Node.ELEMENT_NODE),n=typeof t=="string"&&t.trim().length>0,a=i||n;a&&!this.hasAttribute("has-label")?this.setAttribute("has-label",""):!a&&this.hasAttribute("has-label")&&this.removeAttribute("has-label")}finally{this._isSyncingLabelState=!1}}}},Os=({render:e,html:t})=>qt;var Jt=40,Ba=6,Yt=class e extends HTMLElement{static styleSheet=null;static initializeStyleSheet(){e.styleSheet||(e.styleSheet=new CSSStyleSheet,e.styleSheet.replaceSync(T`
944
944
  :host {
945
945
  display: contents;
946
946
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rettangoli/ui",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A UI component library for building web interfaces.",
5
5
  "main": "dist/rettangoli-esm.min.js",
6
6
  "type": "module",
@@ -89,6 +89,7 @@ class RettangoliCheckboxElement extends HTMLElement {
89
89
 
90
90
  constructor() {
91
91
  super();
92
+ this._isSyncingLabelState = false;
92
93
  RettangoliCheckboxElement.initializeStyleSheet();
93
94
  this.shadow = this.attachShadow({ mode: "open" });
94
95
  this.shadow.adoptedStyleSheets = [RettangoliCheckboxElement.styleSheet];
@@ -270,22 +271,33 @@ class RettangoliCheckboxElement extends HTMLElement {
270
271
  }
271
272
 
272
273
  _updateLabelState() {
273
- const fallbackLabel = this.getAttribute("label");
274
- this._labelSlotElement.textContent = fallbackLabel ?? "";
275
-
276
- const assignedNodes = this._labelSlotElement.assignedNodes({ flatten: true });
277
- const hasAssignedLabel = assignedNodes.some((node) => {
278
- if (node.nodeType === Node.TEXT_NODE) {
279
- return node.textContent.trim().length > 0;
274
+ if (this._isSyncingLabelState) return;
275
+ this._isSyncingLabelState = true;
276
+ try {
277
+ const fallbackLabel = this.getAttribute("label");
278
+ const fallbackText = fallbackLabel ?? "";
279
+ if (this._labelSlotElement.textContent !== fallbackText) {
280
+ this._labelSlotElement.textContent = fallbackText;
280
281
  }
281
- return node.nodeType === Node.ELEMENT_NODE;
282
- });
283
- const hasFallbackLabel = typeof fallbackLabel === "string" && fallbackLabel.trim().length > 0;
284
282
 
285
- if (hasAssignedLabel || hasFallbackLabel) {
286
- this.setAttribute("has-label", "");
287
- } else {
288
- this.removeAttribute("has-label");
283
+ const assignedNodes = this._labelSlotElement.assignedNodes({ flatten: true });
284
+ const hasAssignedLabel = assignedNodes.some((node) => {
285
+ if (node.nodeType === Node.TEXT_NODE) {
286
+ return node.textContent.trim().length > 0;
287
+ }
288
+ return node.nodeType === Node.ELEMENT_NODE;
289
+ });
290
+ const hasFallbackLabel =
291
+ typeof fallbackLabel === "string" && fallbackLabel.trim().length > 0;
292
+
293
+ const shouldHaveLabel = hasAssignedLabel || hasFallbackLabel;
294
+ if (shouldHaveLabel && !this.hasAttribute("has-label")) {
295
+ this.setAttribute("has-label", "");
296
+ } else if (!shouldHaveLabel && this.hasAttribute("has-label")) {
297
+ this.removeAttribute("has-label");
298
+ }
299
+ } finally {
300
+ this._isSyncingLabelState = false;
289
301
  }
290
302
  }
291
303
  }