@alegendstale/holly-components 1.1.2 → 1.2.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 +6 -0
- package/dist/components/responsive-svg/responsive-svg.d.ts.map +1 -1
- package/dist/components/responsive-svg/responsive-svg.js +16 -2
- package/dist/components/responsive-svg/responsive-svg.stories.d.ts +4 -0
- package/dist/components/responsive-svg/responsive-svg.stories.d.ts.map +1 -1
- package/dist/components/responsive-svg/responsive-svg.stories.js +68 -1
- package/package.json +1 -1
|
@@ -5,6 +5,10 @@ type ViewBoxType = {
|
|
|
5
5
|
width: number;
|
|
6
6
|
height: number;
|
|
7
7
|
};
|
|
8
|
+
export type PreserveAspectRatioAlign = "none" | "xMinYMin" | "xMidYMin" | "xMaxYMin" | "xMinYMid" | "xMidYMid" | "xMaxYMid" | "xMinYMax" | "xMidYMax" | "xMaxYMax";
|
|
9
|
+
export type PreserveAspectRatioSpacing = "meet" | "slice";
|
|
10
|
+
export type CombinedAlignSpacing = `${PreserveAspectRatioAlign} ${PreserveAspectRatioSpacing}`;
|
|
11
|
+
export type PreserveAspectRatio = PreserveAspectRatioAlign | CombinedAlignSpacing;
|
|
8
12
|
export declare class ResponsiveSvg extends LitElement {
|
|
9
13
|
static styles: import("lit").CSSResult[];
|
|
10
14
|
autofit: boolean;
|
|
@@ -12,8 +16,10 @@ export declare class ResponsiveSvg extends LitElement {
|
|
|
12
16
|
width: number;
|
|
13
17
|
/** Must use a property expression (.) to set */
|
|
14
18
|
svg: SVGElement | TemplateResult<2> | string;
|
|
19
|
+
preserveAspectRatio: PreserveAspectRatio;
|
|
15
20
|
private _svg;
|
|
16
21
|
private _viewBox;
|
|
22
|
+
private _preserveAspectRatio?;
|
|
17
23
|
protected svgClasses(): {};
|
|
18
24
|
protected willUpdate(_changedProperties: PropertyValues): void;
|
|
19
25
|
render(): TemplateResult<1> | typeof nothing | undefined;
|
|
@@ -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,CAAyD;IAGrE,OAAO,CAAC,QAAQ,CAAoD;IAGpE,SAAS,CAAC,UAAU;IAIpB,SAAS,CAAC,UAAU,CAAC,kBAAkB,EAAE,cAAc,GAAG,IAAI;
|
|
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,MAAM,MAAM,wBAAwB,GAClC,MAAM,GACN,UAAU,GAAG,UAAU,GAAG,UAAU,GACpC,UAAU,GAAG,UAAU,GAAG,UAAU,GACpC,UAAU,GAAG,UAAU,GAAG,UAAU,CAAA;AAEtC,MAAM,MAAM,0BAA0B,GAAG,MAAM,GAAG,OAAO,CAAC;AAE1D,MAAM,MAAM,oBAAoB,GAAG,GAAG,wBAAwB,IAAI,0BAA0B,EAAE,CAAC;AAE/F,MAAM,MAAM,mBAAmB,GAAG,wBAAwB,GAAG,oBAAoB,CAAC;AAElF,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,mBAAmB,EAAE,mBAAmB,CAAmB;IAG3D,OAAO,CAAC,IAAI,CAAyD;IAGrE,OAAO,CAAC,QAAQ,CAAoD;IAGpE,OAAO,CAAC,oBAAoB,CAAC,CAAS;IAGtC,SAAS,CAAC,UAAU;IAIpB,SAAS,CAAC,UAAU,CAAC,kBAAkB,EAAE,cAAc,GAAG,IAAI;IA0B9D,MAAM;IAsBN;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAuBhB;;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"}
|
|
@@ -19,6 +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.preserveAspectRatio = 'xMidYMid meet';
|
|
22
23
|
this._svg = nothing;
|
|
23
24
|
this._viewBox = { x: 0, y: 0, width: 0, height: 0 };
|
|
24
25
|
}
|
|
@@ -35,8 +36,14 @@ let ResponsiveSvg = class ResponsiveSvg extends LitElement {
|
|
|
35
36
|
this._svg = this.svg instanceof SVGElement
|
|
36
37
|
? this.svg : isTemplateResult(this.svg)
|
|
37
38
|
? this.svg : parseSVG(this.svg);
|
|
38
|
-
if (this._svg instanceof SVGElement)
|
|
39
|
-
|
|
39
|
+
if (this._svg instanceof SVGElement) {
|
|
40
|
+
const viewBox = this.getViewBoxSize(this._svg);
|
|
41
|
+
const width = Number(this._svg.getAttribute('width'));
|
|
42
|
+
const height = Number(this._svg.getAttribute('height'));
|
|
43
|
+
// Use viewbox values first, otherwise use height and width attributes.
|
|
44
|
+
this._viewBox = viewBox ?? { x: 0, y: 0, width: width || 0, height: height || 0 };
|
|
45
|
+
this._preserveAspectRatio = this._svg.getAttribute('preserveAspectRatio') || undefined;
|
|
46
|
+
}
|
|
40
47
|
}
|
|
41
48
|
catch (e) {
|
|
42
49
|
console.warn(e);
|
|
@@ -85,6 +92,7 @@ let ResponsiveSvg = class ResponsiveSvg extends LitElement {
|
|
|
85
92
|
style=${styleMap(styles)}
|
|
86
93
|
viewBox="0 0 ${width} ${height}"
|
|
87
94
|
fill="none"
|
|
95
|
+
preserveAspectRatio=${this.preserveAspectRatio || this._preserveAspectRatio}
|
|
88
96
|
xmlns="http://www.w3.org/2000/svg"
|
|
89
97
|
>
|
|
90
98
|
${svg}
|
|
@@ -175,12 +183,18 @@ __decorate([
|
|
|
175
183
|
__decorate([
|
|
176
184
|
property({ type: Object })
|
|
177
185
|
], ResponsiveSvg.prototype, "svg", void 0);
|
|
186
|
+
__decorate([
|
|
187
|
+
property({ type: String, reflect: true })
|
|
188
|
+
], ResponsiveSvg.prototype, "preserveAspectRatio", void 0);
|
|
178
189
|
__decorate([
|
|
179
190
|
state()
|
|
180
191
|
], ResponsiveSvg.prototype, "_svg", void 0);
|
|
181
192
|
__decorate([
|
|
182
193
|
state()
|
|
183
194
|
], ResponsiveSvg.prototype, "_viewBox", void 0);
|
|
195
|
+
__decorate([
|
|
196
|
+
state()
|
|
197
|
+
], ResponsiveSvg.prototype, "_preserveAspectRatio", void 0);
|
|
184
198
|
ResponsiveSvg = __decorate([
|
|
185
199
|
condCustomElement('responsive-svg')
|
|
186
200
|
], ResponsiveSvg);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/web-components';
|
|
2
2
|
import { TemplateResult } from 'lit';
|
|
3
|
+
import { PreserveAspectRatio } from './responsive-svg.js';
|
|
3
4
|
declare const meta: Meta;
|
|
4
5
|
export default meta;
|
|
5
6
|
type Props = {
|
|
@@ -10,6 +11,7 @@ type Props = {
|
|
|
10
11
|
height: number;
|
|
11
12
|
width: number;
|
|
12
13
|
svg: SVGElement | TemplateResult<2> | string;
|
|
14
|
+
preserveAspectRatio: PreserveAspectRatio;
|
|
13
15
|
};
|
|
14
16
|
type Story = StoryObj<Props>;
|
|
15
17
|
export declare const SVG: Story;
|
|
@@ -17,4 +19,6 @@ export declare const TemplateResult2: Story;
|
|
|
17
19
|
export declare const ServicesBottom: Story;
|
|
18
20
|
export declare const EmptyString: Story;
|
|
19
21
|
export declare const Invalid: Story;
|
|
22
|
+
export declare const SVGWithoutViewBox: Story;
|
|
23
|
+
export declare const SVGWithoutWidthHeight: Story;
|
|
20
24
|
//# 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;
|
|
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,OAAO,EAAwD,mBAAmB,EAAwB,MAAM,qBAAqB,CAAC;AAiBtI,QAAA,MAAM,IAAI,EAAE,IAgCX,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,CAAC;IAAC,mBAAmB,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAEzM,KAAK,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAwB7B,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;AAEF,eAAO,MAAM,qBAAqB,EAAE,KAYnC,CAAC"}
|
|
@@ -2,14 +2,55 @@ 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
|
import ServicesBottomRaw from '../../assets/services-bottom.svg?raw';
|
|
5
|
+
import GotLeakz from '../../assets/GotLeakz.svg?raw';
|
|
6
|
+
import ComicBackground from '../../assets/comic-background.svg?raw';
|
|
7
|
+
const alignOptions = [
|
|
8
|
+
"none",
|
|
9
|
+
"xMinYMin", "xMidYMin", "xMaxYMin",
|
|
10
|
+
"xMinYMid", "xMidYMid", "xMaxYMid",
|
|
11
|
+
"xMinYMax", "xMidYMax", "xMaxYMax",
|
|
12
|
+
];
|
|
13
|
+
const spacingOptions = ["meet", "slice"];
|
|
14
|
+
const allAspectRatios = [
|
|
15
|
+
...alignOptions,
|
|
16
|
+
...alignOptions.flatMap(align => spacingOptions.map(spacing => `${align} ${spacing}`))
|
|
17
|
+
];
|
|
5
18
|
const meta = {
|
|
6
19
|
title: 'Responsive SVG',
|
|
7
20
|
tags: ['autodocs'],
|
|
8
21
|
component: 'responsive-svg',
|
|
22
|
+
argTypes: {
|
|
23
|
+
fontSize: {
|
|
24
|
+
control: {
|
|
25
|
+
type: 'number',
|
|
26
|
+
step: 8
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
stroke: {
|
|
30
|
+
control: {
|
|
31
|
+
type: 'color',
|
|
32
|
+
presetColors: [
|
|
33
|
+
'rebeccapurple', 'black'
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
fill: {
|
|
38
|
+
control: {
|
|
39
|
+
type: 'color',
|
|
40
|
+
presetColors: [
|
|
41
|
+
'rebeccapurple', 'black'
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
preserveAspectRatio: {
|
|
46
|
+
control: 'select',
|
|
47
|
+
options: allAspectRatios
|
|
48
|
+
},
|
|
49
|
+
}
|
|
9
50
|
};
|
|
10
51
|
export default meta;
|
|
11
52
|
const Template = {
|
|
12
|
-
render: ({ fontSize, stroke, fill, autofit, height, width, svg }) => {
|
|
53
|
+
render: ({ fontSize, stroke, fill, autofit, height, width, svg, preserveAspectRatio = 'xMidYMid meet' }) => {
|
|
13
54
|
const styles = {
|
|
14
55
|
'font-size': `${fontSize}px`,
|
|
15
56
|
stroke,
|
|
@@ -20,6 +61,7 @@ const Template = {
|
|
|
20
61
|
?autofit=${autofit}
|
|
21
62
|
height=${height}
|
|
22
63
|
width=${width}
|
|
64
|
+
.preserveAspectRatio=${preserveAspectRatio}
|
|
23
65
|
.svg=${svg}
|
|
24
66
|
style=${styleMap(styles)}
|
|
25
67
|
>
|
|
@@ -87,3 +129,28 @@ export const Invalid = {
|
|
|
87
129
|
svg: 'test'
|
|
88
130
|
},
|
|
89
131
|
};
|
|
132
|
+
export const SVGWithoutViewBox = {
|
|
133
|
+
...Template,
|
|
134
|
+
args: {
|
|
135
|
+
fontSize: 128,
|
|
136
|
+
stroke: 'rebeccapurple',
|
|
137
|
+
fill: 'black',
|
|
138
|
+
autofit: false,
|
|
139
|
+
height: 0,
|
|
140
|
+
width: 0,
|
|
141
|
+
svg: GotLeakz
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
export const SVGWithoutWidthHeight = {
|
|
145
|
+
...Template,
|
|
146
|
+
args: {
|
|
147
|
+
fontSize: 128,
|
|
148
|
+
stroke: 'rebeccapurple',
|
|
149
|
+
fill: 'black',
|
|
150
|
+
autofit: false,
|
|
151
|
+
height: 0,
|
|
152
|
+
width: 0,
|
|
153
|
+
svg: ComicBackground,
|
|
154
|
+
preserveAspectRatio: 'none'
|
|
155
|
+
},
|
|
156
|
+
};
|