@alegendstale/holly-components 1.1.3 → 1.2.1

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.
@@ -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,4BA6C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,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
  }
@@ -41,6 +42,7 @@ let ResponsiveSvg = class ResponsiveSvg extends LitElement {
41
42
  const height = Number(this._svg.getAttribute('height'));
42
43
  // Use viewbox values first, otherwise use height and width attributes.
43
44
  this._viewBox = viewBox ?? { x: 0, y: 0, width: width || 0, height: height || 0 };
45
+ this._preserveAspectRatio = this._svg.getAttribute('preserveAspectRatio') || undefined;
44
46
  }
45
47
  }
46
48
  catch (e) {
@@ -90,6 +92,7 @@ let ResponsiveSvg = class ResponsiveSvg extends LitElement {
90
92
  style=${styleMap(styles)}
91
93
  viewBox="0 0 ${width} ${height}"
92
94
  fill="none"
95
+ preserveAspectRatio=${this.preserveAspectRatio || this._preserveAspectRatio}
93
96
  xmlns="http://www.w3.org/2000/svg"
94
97
  >
95
98
  ${svg}
@@ -131,7 +134,7 @@ ResponsiveSvg.styles = [
131
134
  --scale: 1;
132
135
  }
133
136
 
134
- :host([autofit]) {
137
+ :host([autofit]), :host([autofit]) svg {
135
138
  width: 100%;
136
139
  height: 100%;
137
140
  }
@@ -180,12 +183,18 @@ __decorate([
180
183
  __decorate([
181
184
  property({ type: Object })
182
185
  ], ResponsiveSvg.prototype, "svg", void 0);
186
+ __decorate([
187
+ property({ type: String, reflect: true })
188
+ ], ResponsiveSvg.prototype, "preserveAspectRatio", void 0);
183
189
  __decorate([
184
190
  state()
185
191
  ], ResponsiveSvg.prototype, "_svg", void 0);
186
192
  __decorate([
187
193
  state()
188
194
  ], ResponsiveSvg.prototype, "_viewBox", void 0);
195
+ __decorate([
196
+ state()
197
+ ], ResponsiveSvg.prototype, "_preserveAspectRatio", void 0);
189
198
  ResponsiveSvg = __decorate([
190
199
  condCustomElement('responsive-svg')
191
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;
@@ -18,4 +20,5 @@ export declare const ServicesBottom: Story;
18
20
  export declare const EmptyString: Story;
19
21
  export declare const Invalid: Story;
20
22
  export declare const SVGWithoutViewBox: Story;
23
+ export declare const SVGWithoutWidthHeight: Story;
21
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;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
+ {"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"}
@@ -3,14 +3,54 @@ 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
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
+ ];
6
18
  const meta = {
7
19
  title: 'Responsive SVG',
8
20
  tags: ['autodocs'],
9
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
+ }
10
50
  };
11
51
  export default meta;
12
52
  const Template = {
13
- render: ({ fontSize, stroke, fill, autofit, height, width, svg }) => {
53
+ render: ({ fontSize, stroke, fill, autofit, height, width, svg, preserveAspectRatio = 'xMidYMid meet' }) => {
14
54
  const styles = {
15
55
  'font-size': `${fontSize}px`,
16
56
  stroke,
@@ -21,6 +61,7 @@ const Template = {
21
61
  ?autofit=${autofit}
22
62
  height=${height}
23
63
  width=${width}
64
+ .preserveAspectRatio=${preserveAspectRatio}
24
65
  .svg=${svg}
25
66
  style=${styleMap(styles)}
26
67
  >
@@ -100,3 +141,16 @@ export const SVGWithoutViewBox = {
100
141
  svg: GotLeakz
101
142
  },
102
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "private": false,
3
- "version": "1.1.3",
3
+ "version": "1.2.1",
4
4
  "name": "@alegendstale/holly-components",
5
5
  "description": "Reusable UI components created using lit",
6
6
  "type": "module",