@alegendstale/holly-components 1.0.2 → 1.1.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.
- package/dist/components/responsive-svg/responsive-svg.d.ts +11 -3
- package/dist/components/responsive-svg/responsive-svg.d.ts.map +1 -1
- package/dist/components/responsive-svg/responsive-svg.js +29 -13
- package/dist/components/responsive-svg/responsive-svg.stories.d.ts +3 -1
- package/dist/components/responsive-svg/responsive-svg.stories.d.ts.map +1 -1
- package/dist/components/responsive-svg/responsive-svg.stories.js +13 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LitElement, nothing, PropertyValues } from 'lit';
|
|
1
|
+
import { LitElement, nothing, PropertyValues, TemplateResult } from 'lit';
|
|
2
2
|
type ViewBoxType = {
|
|
3
3
|
x: number;
|
|
4
4
|
y: number;
|
|
@@ -11,12 +11,20 @@ export declare class ResponsiveSvg extends LitElement {
|
|
|
11
11
|
height: number;
|
|
12
12
|
width: number;
|
|
13
13
|
/** Must use a property expression (.) to set */
|
|
14
|
-
svg: SVGElement | string;
|
|
14
|
+
svg: SVGElement | TemplateResult<2> | string;
|
|
15
15
|
private _svg;
|
|
16
16
|
private _viewBox;
|
|
17
17
|
protected svgClasses(): {};
|
|
18
18
|
protected willUpdate(_changedProperties: PropertyValues): void;
|
|
19
|
-
render():
|
|
19
|
+
render(): TemplateResult<1> | typeof nothing | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Builds an SVG from an Element or TemplateResult<2> input
|
|
22
|
+
* @param svg
|
|
23
|
+
* @param width
|
|
24
|
+
* @param height
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
private buildSVG;
|
|
20
28
|
/**
|
|
21
29
|
* Applies a part name to all paths in the given element
|
|
22
30
|
*/
|
|
@@ -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,
|
|
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;IAa9D,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"}
|
|
@@ -4,12 +4,13 @@ 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, css, nothing } from 'lit';
|
|
7
|
+
import { LitElement, html, svg, 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';
|
|
11
11
|
import { parseSVG } from '../../utils/basicUtils.js';
|
|
12
12
|
import { classMap } from 'lit/directives/class-map.js';
|
|
13
|
+
import { isTemplateResult } from 'lit/directive-helpers.js';
|
|
13
14
|
let ResponsiveSvg = class ResponsiveSvg extends LitElement {
|
|
14
15
|
constructor() {
|
|
15
16
|
super(...arguments);
|
|
@@ -18,7 +19,7 @@ let ResponsiveSvg = class ResponsiveSvg extends LitElement {
|
|
|
18
19
|
this.width = 0;
|
|
19
20
|
/** Must use a property expression (.) to set */
|
|
20
21
|
this.svg = '';
|
|
21
|
-
this._svg =
|
|
22
|
+
this._svg = svg ``;
|
|
22
23
|
this._viewBox = { x: 0, y: 0, width: 0, height: 0 };
|
|
23
24
|
}
|
|
24
25
|
// For classes inheriting from responsive-svg (e.g. draw-svg)
|
|
@@ -28,9 +29,9 @@ let ResponsiveSvg = class ResponsiveSvg extends LitElement {
|
|
|
28
29
|
willUpdate(_changedProperties) {
|
|
29
30
|
super.willUpdate(_changedProperties);
|
|
30
31
|
if (_changedProperties.has('svg')) {
|
|
31
|
-
const svgSource = this.svg instanceof SVGElement ? this.svg : parseSVG(this.svg);
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const svgSource = this.svg instanceof SVGElement ? this.svg : isTemplateResult(this.svg) ? this.svg : parseSVG(this.svg);
|
|
33
|
+
this._svg = svgSource || svg ``;
|
|
34
|
+
if (svgSource instanceof Element) {
|
|
34
35
|
this._viewBox = this.getViewBoxSize(svgSource) || { x: 0, y: 0, width: 0, height: 0 };
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -38,28 +39,43 @@ let ResponsiveSvg = class ResponsiveSvg extends LitElement {
|
|
|
38
39
|
render() {
|
|
39
40
|
const width = this.width !== 0 ? this.width : this._viewBox.width;
|
|
40
41
|
const height = this.height !== 0 ? this.height : this._viewBox.height;
|
|
41
|
-
const styles = {
|
|
42
|
-
'--svg-width': `${width}em`,
|
|
43
|
-
'--svg-height': `${height}em`,
|
|
44
|
-
};
|
|
45
42
|
if (this._svg instanceof Element) {
|
|
46
43
|
const clonedSVG = this._svg.cloneNode(true);
|
|
47
44
|
this.applyPartToPaths(clonedSVG, 'path');
|
|
48
45
|
const svgContent = Array.from(clonedSVG.children);
|
|
46
|
+
return this.buildSVG(svgContent, width, height);
|
|
47
|
+
}
|
|
48
|
+
else if (isTemplateResult(this._svg))
|
|
49
|
+
return this.buildSVG(this._svg, width, height);
|
|
50
|
+
else
|
|
51
|
+
return nothing;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Builds an SVG from an Element or TemplateResult<2> input
|
|
55
|
+
* @param svg
|
|
56
|
+
* @param width
|
|
57
|
+
* @param height
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
buildSVG(svg, width, height) {
|
|
61
|
+
const styles = {
|
|
62
|
+
'--svg-width': `${width}em`,
|
|
63
|
+
'--svg-height': `${height}em`,
|
|
64
|
+
};
|
|
65
|
+
if (svg) {
|
|
49
66
|
return html `
|
|
50
67
|
<svg
|
|
51
68
|
part="svg"
|
|
52
69
|
class=${classMap(this.svgClasses())}
|
|
53
70
|
style=${styleMap(styles)}
|
|
54
|
-
viewBox="0 0 ${width} ${height}"
|
|
55
|
-
fill="none"
|
|
71
|
+
viewBox="0 0 ${width} ${height}"
|
|
72
|
+
fill="none"
|
|
56
73
|
xmlns="http://www.w3.org/2000/svg"
|
|
57
74
|
>
|
|
58
|
-
${
|
|
75
|
+
${svg}
|
|
59
76
|
</svg>
|
|
60
77
|
`;
|
|
61
78
|
}
|
|
62
|
-
return nothing;
|
|
63
79
|
}
|
|
64
80
|
/**
|
|
65
81
|
* Applies a part name to all paths in the given element
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/web-components';
|
|
2
|
+
import { TemplateResult } from 'lit';
|
|
2
3
|
declare const meta: Meta;
|
|
3
4
|
export default meta;
|
|
4
5
|
type Props = {
|
|
@@ -8,8 +9,9 @@ type Props = {
|
|
|
8
9
|
autofit: boolean;
|
|
9
10
|
height: number;
|
|
10
11
|
width: number;
|
|
11
|
-
svg: SVGElement | string;
|
|
12
|
+
svg: SVGElement | TemplateResult<2> | string;
|
|
12
13
|
};
|
|
13
14
|
type Story = StoryObj<Props>;
|
|
14
15
|
export declare const SVG: Story;
|
|
16
|
+
export declare const TemplateResult2: Story;
|
|
15
17
|
//# 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;
|
|
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,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { html } from 'lit';
|
|
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
4
|
const meta = {
|
|
@@ -38,3 +38,15 @@ export const SVG = {
|
|
|
38
38
|
svg: ResponsiveSVGRaw
|
|
39
39
|
},
|
|
40
40
|
};
|
|
41
|
+
export const TemplateResult2 = {
|
|
42
|
+
...Template,
|
|
43
|
+
args: {
|
|
44
|
+
fontSize: 128,
|
|
45
|
+
stroke: 'rebeccapurple',
|
|
46
|
+
fill: 'black',
|
|
47
|
+
autofit: false,
|
|
48
|
+
height: 128,
|
|
49
|
+
width: 128,
|
|
50
|
+
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
|
+
}
|
|
52
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"name": "@alegendstale/holly-components",
|
|
5
5
|
"description": "Reusable UI components created using lit",
|
|
6
6
|
"type": "module",
|
|
@@ -97,4 +97,4 @@
|
|
|
97
97
|
"typescript": "latest",
|
|
98
98
|
"vite": "^7.2.6"
|
|
99
99
|
}
|
|
100
|
-
}
|
|
100
|
+
}
|