@crowdfarming/oliva-ds 1.11.0 → 1.12.0-rc.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.
@@ -2063,58 +2063,48 @@ class IconComponent {
2063
2063
  }
2064
2064
  /**
2065
2065
  * Updates the SVG content dynamically based on the current icon name and color.
2066
- * This method performs the following operations:
2067
- * 1. Creates a temporary DOM element to manipulate the SVG
2068
- * 2. Sets responsive width and height attributes (100%)
2066
+ * This method performs the following operations using string manipulation (SSR-compatible):
2067
+ * 1. Gets the raw SVG string from our icons object
2068
+ * 2. Uses regex to set responsive width and height attributes (100%)
2069
2069
  * 3. Applies dynamic color styling using CSS variables
2070
2070
  * 4. Sanitizes the HTML for safe rendering
2071
- * 5. Cleans up the temporary DOM element to prevent memory leaks
2072
2071
  */
2073
2072
  updateIconSvg() {
2074
- // Create a temporary div element to manipulate the SVG DOM
2075
- // This allows us to modify SVG attributes programmatically
2076
- const iconElement = document.createElement('div');
2077
- // Insert the raw SVG content from our icons object into the temporary element
2078
- // The iconName is cast to IconName type for type safety
2079
- iconElement.innerHTML = this.icons[this.iconName];
2080
- // Find the SVG element within our temporary container
2081
- const svgElement = iconElement.querySelector('svg');
2082
- if (svgElement) {
2083
- // Set responsive dimensions - width and height to 100% for flexible scaling
2084
- // This ensures the icon scales properly within its container
2085
- svgElement.setAttribute('width', '100%');
2086
- svgElement.setAttribute('height', '100%');
2087
- // Find all path elements within the SVG
2088
- // Path elements are the main components that define the icon's shape
2089
- const pathElements = svgElement.querySelectorAll('path');
2090
- // Apply dynamic color styling if both path elements exist and a color is specified
2091
- if (pathElements.length && this.iconColor) {
2092
- // Create a CSS variable reference for the color
2093
- // This allows the icon to use theme colors (e.g., var(--color-primary))
2094
- const fill = `var(--color-${this.iconColor})`;
2095
- // Apply the fill color to all path elements in the SVG
2096
- // This ensures consistent coloring across all parts of the icon
2097
- pathElements.forEach((pathElement) => {
2098
- pathElement.setAttribute('fill', fill);
2099
- });
2100
- }
2073
+ if (!this.iconName || !this.icons[this.iconName]) {
2074
+ this.iconSvg = '';
2075
+ return;
2101
2076
  }
2102
- // Convert the manipulated HTML back to a SafeHtml object
2077
+ let svgString = this.icons[this.iconName];
2078
+ // Set responsive dimensions - width and height to 100% for flexible scaling
2079
+ // This ensures the icon scales properly within its container
2080
+ // First, remove any existing width and height attributes
2081
+ svgString = svgString.replace(/(width|height)="[^"]*"/g, '');
2082
+ // Then add width="100%" height="100%" to the SVG element
2083
+ svgString = svgString.replace(/<svg([^>]*)>/, '<svg$1 width="100%" height="100%">');
2084
+ // Apply dynamic color styling if a color is specified
2085
+ if (this.iconColor) {
2086
+ // Create a CSS variable reference for the color
2087
+ // This allows the icon to use theme colors (e.g., var(--color-primary))
2088
+ const fill = `var(--color-${this.iconColor})`;
2089
+ // Apply the fill color to all path elements in the SVG using regex
2090
+ // This ensures consistent coloring across all parts of the icon
2091
+ svgString = svgString.replace(/<path([^>]*?)>/g, (match, attributes) => {
2092
+ // Remove any existing fill attribute
2093
+ const cleanAttributes = attributes.replace(/fill="[^"]*"/g, '');
2094
+ return `<path${cleanAttributes} fill="${fill}">`;
2095
+ });
2096
+ }
2097
+ // Convert the manipulated HTML string to a SafeHtml object
2103
2098
  // This bypasses Angular's security restrictions for trusted content
2104
2099
  // and allows the SVG to be rendered safely in the template
2105
- this.iconSvg = this.sanitizer.bypassSecurityTrustHtml(iconElement.innerHTML);
2106
- // Clean up the temporary DOM element to prevent memory leaks
2107
- // Remove the entire element from the DOM
2108
- if (iconElement.parentNode) {
2109
- iconElement.parentNode.removeChild(iconElement);
2110
- }
2100
+ this.iconSvg = this.sanitizer.bypassSecurityTrustHtml(svgString);
2111
2101
  }
2112
2102
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: IconComponent, deps: [{ token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Component });
2113
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.7", type: IconComponent, isStandalone: true, selector: "lib-icon", inputs: { size: "size", icon: "icon", name: "name", color: "color" }, ngImport: i0, template: "<div\n class=\"lib-icon\"\n [ngClass]=\"size\"\n [innerHTML]=\"iconSvg\"\n></div>\n", styles: [":host{display:contents}.lib-icon{display:inline-block}.lib-icon.lg{height:1.5rem}.lib-icon.md{height:1.25rem}.lib-icon.sm{height:1rem}.lib-icon.xs{height:.875rem}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1$1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] });
2103
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.7", type: IconComponent, isStandalone: true, selector: "lib-icon", inputs: { size: "size", icon: "icon", name: "name", color: "color" }, ngImport: i0, template: "<div\n class=\"lib-icon\"\n [ngClass]=\"size\"\n [innerHTML]=\"iconSvg\"\n></div>\n", styles: [":host{display:contents}.lib-icon{display:inline-block;pointer-events:none}.lib-icon.lg{height:1.5rem}.lib-icon.md{height:1.25rem}.lib-icon.sm{height:1rem}.lib-icon.xs{height:.875rem}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1$1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] });
2114
2104
  }
2115
2105
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: IconComponent, decorators: [{
2116
2106
  type: Component,
2117
- args: [{ selector: 'lib-icon', imports: [CommonModule], template: "<div\n class=\"lib-icon\"\n [ngClass]=\"size\"\n [innerHTML]=\"iconSvg\"\n></div>\n", styles: [":host{display:contents}.lib-icon{display:inline-block}.lib-icon.lg{height:1.5rem}.lib-icon.md{height:1.25rem}.lib-icon.sm{height:1rem}.lib-icon.xs{height:.875rem}\n"] }]
2107
+ args: [{ selector: 'lib-icon', imports: [CommonModule], template: "<div\n class=\"lib-icon\"\n [ngClass]=\"size\"\n [innerHTML]=\"iconSvg\"\n></div>\n", styles: [":host{display:contents}.lib-icon{display:inline-block;pointer-events:none}.lib-icon.lg{height:1.5rem}.lib-icon.md{height:1.25rem}.lib-icon.sm{height:1rem}.lib-icon.xs{height:.875rem}\n"] }]
2118
2108
  }], ctorParameters: () => [{ type: i1.DomSanitizer }], propDecorators: { size: [{
2119
2109
  type: Input
2120
2110
  }], icon: [{