@alegendstale/holly-components 1.1.1 → 1.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"responsive-svg.d.ts","sourceRoot":"","sources":["../../../src/components/responsive-svg/responsive-svg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAQ1F,KAAK,WAAW,GAAG;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAA;CACd,CAAA;AAED,qBACa,aAAc,SAAQ,UAAU;IAC5C,MAAM,CAAC,MAAM,4BA6CX;IAGF,OAAO,EAAE,OAAO,CAAS;IAGzB,MAAM,EAAE,MAAM,CAAK;IAGnB,KAAK,EAAE,MAAM,CAAK;IAElB,gDAAgD;IAEhD,GAAG,EAAE,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,CAAM;IAGlD,OAAO,CAAC,IAAI,CAAyC;IAGrD,OAAO,CAAC,QAAQ,CAAoD;IAGpE,SAAS,CAAC,UAAU;IAIpB,SAAS,CAAC,UAAU,CAAC,kBAAkB,EAAE,cAAc,GAAG,IAAI;IAe9D,MAAM;IAiBN;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAsBhB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAaxB;;;OAGG;IACI,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI;CAM1D;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,gBAAgB,EAAE,aAAa,CAAC;KAChC;CACD"}
1
+ {"version":3,"file":"responsive-svg.d.ts","sourceRoot":"","sources":["../../../src/components/responsive-svg/responsive-svg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAQ1F,KAAK,WAAW,GAAG;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAA;CACd,CAAA;AAED,qBACa,aAAc,SAAQ,UAAU;IAC5C,MAAM,CAAC,MAAM,4BA6CX;IAGF,OAAO,EAAE,OAAO,CAAS;IAGzB,MAAM,EAAE,MAAM,CAAK;IAGnB,KAAK,EAAE,MAAM,CAAK;IAElB,gDAAgD;IAEhD,GAAG,EAAE,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,CAAM;IAGlD,OAAO,CAAC,IAAI,CAAyD;IAGrE,OAAO,CAAC,QAAQ,CAAoD;IAGpE,SAAS,CAAC,UAAU;IAIpB,SAAS,CAAC,UAAU,CAAC,kBAAkB,EAAE,cAAc,GAAG,IAAI;IAyB9D,MAAM;IAsBN;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAsBhB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAaxB;;;OAGG;IACI,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI;CAM1D;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,gBAAgB,EAAE,aAAa,CAAC;KAChC;CACD"}
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { LitElement, html, svg, css, nothing } from 'lit';
7
+ import { LitElement, html, css, nothing } from 'lit';
8
8
  import { property, state } from 'lit/decorators.js';
9
9
  import { styleMap } from 'lit/directives/style-map.js';
10
10
  import { condCustomElement } from '../../decorators/condCustomElement.js';
@@ -19,7 +19,7 @@ let ResponsiveSvg = class ResponsiveSvg extends LitElement {
19
19
  this.width = 0;
20
20
  /** Must use a property expression (.) to set */
21
21
  this.svg = '';
22
- this._svg = svg ``;
22
+ this._svg = nothing;
23
23
  this._viewBox = { x: 0, y: 0, width: 0, height: 0 };
24
24
  }
25
25
  // For classes inheriting from responsive-svg (e.g. draw-svg)
@@ -27,30 +27,48 @@ let ResponsiveSvg = class ResponsiveSvg extends LitElement {
27
27
  return {};
28
28
  }
29
29
  willUpdate(_changedProperties) {
30
- super.willUpdate(_changedProperties);
31
30
  if (_changedProperties.has('svg')) {
32
- const svgSource = this.svg instanceof SVGElement ? this.svg : isTemplateResult(this.svg) ? this.svg : parseSVG(this.svg);
33
- if (svgSource == null)
34
- throw Error('Provided SVG is not valid.');
35
- this._svg = svgSource;
36
- if (svgSource instanceof Element) {
37
- this._viewBox = this.getViewBoxSize(svgSource) || { x: 0, y: 0, width: 0, height: 0 };
31
+ try {
32
+ // Return early if SVG hasn't been set
33
+ if (this.svg === '')
34
+ return;
35
+ this._svg = this.svg instanceof SVGElement
36
+ ? this.svg : isTemplateResult(this.svg)
37
+ ? this.svg : parseSVG(this.svg);
38
+ if (this._svg instanceof SVGElement) {
39
+ const viewBox = this.getViewBoxSize(this._svg);
40
+ const width = Number(this._svg.getAttribute('width'));
41
+ const height = Number(this._svg.getAttribute('height'));
42
+ // Use viewbox values first, otherwise use height and width attributes.
43
+ this._viewBox = viewBox ?? { x: 0, y: 0, width: width || 0, height: height || 0 };
44
+ }
45
+ }
46
+ catch (e) {
47
+ console.warn(e);
38
48
  }
39
49
  }
40
50
  }
41
51
  render() {
42
52
  const width = this.width !== 0 ? this.width : this._viewBox.width;
43
53
  const height = this.height !== 0 ? this.height : this._viewBox.height;
44
- if (this._svg instanceof Element) {
45
- const clonedSVG = this._svg.cloneNode(true);
46
- this.applyPartToPaths(clonedSVG, 'path');
47
- const svgContent = Array.from(clonedSVG.children);
48
- return this.buildSVG(svgContent, width, height);
49
- }
50
- else if (isTemplateResult(this._svg))
51
- return this.buildSVG(this._svg, width, height);
52
- else
54
+ // Check if svg exits, otherwise early return
55
+ if (this._svg === nothing)
53
56
  return nothing;
57
+ else {
58
+ // SVGElement provided as input
59
+ if (this._svg instanceof Element) {
60
+ if (this._svg instanceof SVGElement) {
61
+ const clonedSVG = this._svg.cloneNode(true);
62
+ this.applyPartToPaths(clonedSVG, 'path');
63
+ return this.buildSVG(Array.from(clonedSVG.children), width, height);
64
+ }
65
+ else
66
+ return html `<p style="font-size: initial;">⚠️ SVG Error</p>`;
67
+ }
68
+ // TemplateResult<2> provided as input
69
+ else
70
+ return this.buildSVG(this._svg, width, height);
71
+ }
54
72
  }
55
73
  /**
56
74
  * Builds an SVG from an Element or TemplateResult<2> input
@@ -14,5 +14,8 @@ type Props = {
14
14
  type Story = StoryObj<Props>;
15
15
  export declare const SVG: Story;
16
16
  export declare const TemplateResult2: Story;
17
+ export declare const ServicesBottom: Story;
18
+ export declare const EmptyString: Story;
17
19
  export declare const Invalid: Story;
20
+ export declare const SVGWithoutViewBox: Story;
18
21
  //# sourceMappingURL=responsive-svg.stories.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"responsive-svg.stories.d.ts","sourceRoot":"","sources":["../../../src/components/responsive-svg/responsive-svg.stories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAa,cAAc,EAAE,MAAM,KAAK,CAAC;AAIhD,QAAA,MAAM,IAAI,EAAE,IAIX,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,CAAA;CAAE,CAAC;AAE/J,KAAK,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAuB7B,eAAO,MAAM,GAAG,EAAE,KAWjB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAW7B,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,KAWrB,CAAC"}
1
+ {"version":3,"file":"responsive-svg.stories.d.ts","sourceRoot":"","sources":["../../../src/components/responsive-svg/responsive-svg.stories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAa,cAAc,EAAE,MAAM,KAAK,CAAC;AAMhD,QAAA,MAAM,IAAI,EAAE,IAIX,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,CAAA;CAAE,CAAC;AAE/J,KAAK,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAuB7B,eAAO,MAAM,GAAG,EAAE,KAWjB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAW7B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,KAW5B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAWzB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,KAWrB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,KAW/B,CAAC"}
@@ -1,6 +1,8 @@
1
1
  import { html, svg } from 'lit';
2
2
  import { styleMap } from 'lit/directives/style-map.js';
3
3
  import ResponsiveSVGRaw from '../../assets/ResponsiveSVG.svg?raw';
4
+ import ServicesBottomRaw from '../../assets/services-bottom.svg?raw';
5
+ import GotLeakz from '../../assets/GotLeakz.svg?raw';
4
6
  const meta = {
5
7
  title: 'Responsive SVG',
6
8
  tags: ['autodocs'],
@@ -50,7 +52,19 @@ export const TemplateResult2 = {
50
52
  svg: svg `<path part="path" d="M 30 50 h 60 a 1 1 0 0 1 0 20 h -60 a 1 1 0 0 1 0 -40 h 30 v 70"/>`
51
53
  }
52
54
  };
53
- export const Invalid = {
55
+ export const ServicesBottom = {
56
+ ...Template,
57
+ args: {
58
+ fontSize: 128,
59
+ stroke: 'rebeccapurple',
60
+ fill: 'black',
61
+ autofit: false,
62
+ height: 128,
63
+ width: 128,
64
+ svg: ServicesBottomRaw
65
+ }
66
+ };
67
+ export const EmptyString = {
54
68
  ...Template,
55
69
  args: {
56
70
  fontSize: 128,
@@ -62,3 +76,27 @@ export const Invalid = {
62
76
  svg: ''
63
77
  },
64
78
  };
79
+ export const Invalid = {
80
+ ...Template,
81
+ args: {
82
+ fontSize: 128,
83
+ stroke: 'rebeccapurple',
84
+ fill: 'black',
85
+ autofit: false,
86
+ height: 0,
87
+ width: 0,
88
+ svg: 'test'
89
+ },
90
+ };
91
+ export const SVGWithoutViewBox = {
92
+ ...Template,
93
+ args: {
94
+ fontSize: 128,
95
+ stroke: 'rebeccapurple',
96
+ fill: 'black',
97
+ autofit: false,
98
+ height: 0,
99
+ width: 0,
100
+ svg: GotLeakz
101
+ },
102
+ };
@@ -49,7 +49,7 @@ export declare function isColorValid(color: string | CommonColorTuple | CommonCo
49
49
  /**
50
50
  * Parse a raw string based SVG
51
51
  * @param rawSVG SVG represented as a string
52
- * @returns SVG element if it could be parsed
52
+ * @returns SVGElement | parsererror if parse failed
53
53
  */
54
- export declare function parseSVG(rawSVG: string): SVGSVGElement | null;
54
+ export declare function parseSVG(rawSVG: string): SVGElement | Element;
55
55
  //# sourceMappingURL=basicUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"basicUtils.d.ts","sourceRoot":"","sources":["../../src/utils/basicUtils.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,gBAAgB,EAAE,iBAAiB,EAAO,MAAM,uBAAuB,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,UAAU,EAAmB,MAAM,oDAAoD,CAAC;AAExI;;GAEG;AACH,wBAAgB,mBAAmB,CAAE,QAAQ,EAAE,eAAe,wCAsB7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAE,QAAQ,EAAE,eAAe,GAAG,oBAAoB,WAUnF;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAE,QAAQ,EAAE,eAAe,sBAGrE;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,OAY9D;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,YAQnC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,oBAAoB,GAAG,eAAe,CAW7F;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAA,QAAQ,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;CAAE,GAAG,MAAM,GAAG,MAAM,CAGnH;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGxD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,UAMxC;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,UAAU,iBAU1E;AAED;;EAEE;AACF,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,UAItD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,gBAA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AAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,GAAG,iBAAiB,GAAG,OAAO,CAS1F;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAI7D"}
@@ -151,10 +151,10 @@ export function isColorValid(color) {
151
151
  /**
152
152
  * Parse a raw string based SVG
153
153
  * @param rawSVG SVG represented as a string
154
- * @returns SVG element if it could be parsed
154
+ * @returns SVGElement | parsererror if parse failed
155
155
  */
156
156
  export function parseSVG(rawSVG) {
157
157
  const parser = new DOMParser();
158
- const svgDoc = parser.parseFromString(rawSVG, 'image/svg+xml');
159
- return svgDoc.querySelector('svg');
158
+ const xmlDoc = parser.parseFromString(rawSVG, 'image/svg+xml');
159
+ return xmlDoc.querySelector('svg') ?? xmlDoc.querySelector('parsererror');
160
160
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "private": false,
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "name": "@alegendstale/holly-components",
5
5
  "description": "Reusable UI components created using lit",
6
6
  "type": "module",