@thinkpixellab-public/px-vue 4.0.24 → 4.0.25

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,6 +1,6 @@
1
1
  <script>
2
2
  import isServer from '../utils/isServer';
3
- import { cssEmFallback } from '../utils/cssStr.js';
3
+ import { cssUnitScale, cssEmFallback } from '../utils/cssStr.js';
4
4
 
5
5
  export default {
6
6
  emits: [
@@ -106,8 +106,24 @@ export default {
106
106
  calcSrc() {
107
107
  return this.src;
108
108
  },
109
+ calcAspectRatio() {
110
+ if (this.svgViewBox) {
111
+ const viewBox = this.svgViewBox.split(' ');
112
+ const width = parseFloat(viewBox[2]);
113
+ const height = parseFloat(viewBox[3]);
114
+ if (width && height) {
115
+ return width / height;
116
+ }
117
+ }
118
+ if (this.svgWidth && this.svgHeight) {
119
+ return this.svgWidth / this.svgHeight;
120
+ }
121
+
122
+ // fallback is 1:1
123
+ return 16 / 9;
124
+ },
109
125
  calcHeight() {
110
- if (!this.size) {
126
+ if (!this.size && this.svgHeight) {
111
127
  return this.svgHeight;
112
128
  }
113
129
 
@@ -115,11 +131,15 @@ export default {
115
131
  return cssEmFallback(this.size);
116
132
  }
117
133
 
118
- // equivalent of 'auto' (but needs to be a number or else the parse shows console errors)
119
- return '100%';
134
+ if (this.size && this.calcAspectRatio) {
135
+ return cssUnitScale(cssEmFallback(this.size), 1 / this.calcAspectRatio);
136
+ }
137
+
138
+ //
139
+ return '100';
120
140
  },
121
141
  calcWidth() {
122
- if (!this.size) {
142
+ if (!this.size && this.svgWidth) {
123
143
  return this.svgWidth;
124
144
  }
125
145
 
@@ -127,8 +147,12 @@ export default {
127
147
  return cssEmFallback(this.size);
128
148
  }
129
149
 
150
+ if (this.size && this.calcAspectRatio) {
151
+ return cssUnitScale(cssEmFallback(this.size), this.calcAspectRatio);
152
+ }
153
+
130
154
  // equivalent of 'auto' (but needs to be a number or else the parse shows console errors)
131
- return '100%';
155
+ return '100';
132
156
  },
133
157
  calcStyle() {
134
158
  return null;
@@ -172,18 +196,20 @@ export default {
172
196
  let width =
173
197
  svg.width.baseVal.unitType == 1 || svg.width.baseVal.unitType == 5
174
198
  ? parseFloat(svg.width.baseVal.value)
175
- : viewBox.width;
199
+ : svg.viewBox?.width || 0;
176
200
  let height =
177
201
  svg.height.baseVal.unitType == 1 || svg.height.baseVal.unitType == 5
178
202
  ? parseFloat(svg.height.baseVal.value)
179
- : viewBox.height;
203
+ : svg.viewBox?.height || 0;
180
204
 
181
205
  // save as data values
182
- this.svgViewBox = viewBox
183
- ? `${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}`
184
- : `0 0 ${width} ${height}`;
185
- this.svgWidth = width;
186
- this.svgHeight = height;
206
+ if (viewBox?.width && viewBox?.height) {
207
+ this.svgViewBox = viewBox
208
+ ? `${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}`
209
+ : `0 0 ${width} ${height}`;
210
+ this.svgWidth = width;
211
+ this.svgHeight = height;
212
+ }
187
213
  }
188
214
 
189
215
  // string replace
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "4.0.24",
3
+ "version": "4.0.25",
4
4
  "description": "General purpose Vue components and helpers that can be used across projects.",
5
5
  "author": {
6
6
  "name": "Pixel Lab"
@@ -2,6 +2,8 @@ import PxSvg from '@/components/PxSvg.vue';
2
2
  import { extractArgTypes } from '@/storybook/sb-utils.js';
3
3
 
4
4
  import alphaSvg from './assets/alpha.svg';
5
+ import alphaSizeWidthSvg from './assets/alphaSizeWidth.svg';
6
+ import alphaNoSizingSvg from './assets/alphaNoSizing.svg';
5
7
 
6
8
  export default {
7
9
  component: PxSvg,
@@ -29,11 +31,16 @@ export const Basic = {
29
31
  setup() {
30
32
  return { args };
31
33
  },
32
- template: `<PxSvg v-bind="args" />`,
34
+ template: `<PxSvg v-bind="args" size="200px" />`,
33
35
  }),
34
36
  };
35
37
 
36
- export const Advanced = {
38
+ export const WidthAndHeightNoViewBox = {
37
39
  ...Basic,
38
- // args: { size: '2em' },
40
+ args: { src: alphaSizeWidthSvg },
41
+ };
42
+
43
+ export const NoSizing = {
44
+ ...Basic,
45
+ args: { src: alphaNoSizingSvg },
39
46
  };
@@ -0,0 +1,6 @@
1
+
2
+ <svg id='svg1' xmlns='http://www.w3.org/2000/svg'>
3
+ <circle r="32" cx="35" cy="65" fill="#F00" opacity="0.5"/>
4
+ <circle r="32" cx="65" cy="65" fill="#0F0" opacity="0.5"/>
5
+ <circle r="32" cx="50" cy="35" fill="#00F" opacity="0.5"/>
6
+ </svg>
@@ -0,0 +1,6 @@
1
+
2
+ <svg id='svg1' width="100" height="100" xmlns='http://www.w3.org/2000/svg'>
3
+ <circle r="32" cx="35" cy="65" fill="#F00" opacity="0.5"/>
4
+ <circle r="32" cx="65" cy="65" fill="#0F0" opacity="0.5"/>
5
+ <circle r="32" cx="50" cy="35" fill="#00F" opacity="0.5"/>
6
+ </svg>
package/vite.config.js CHANGED
@@ -16,14 +16,8 @@ export default defineConfig({
16
16
 
17
17
  ...(USE_PX_LOCAL
18
18
  ? {
19
- '@thinkpixellab-public/px-styles': path.resolve(
20
- __dirname,
21
- '../px-styles-vue3',
22
- ),
23
- '@thinkpixellab/px-edge-shared': path.resolve(
24
- __dirname,
25
- '../px-edge-shared-nuxt3',
26
- ),
19
+ '@thinkpixellab-public/px-styles': path.resolve(__dirname, '../px-styles'),
20
+ '@thinkpixellab/px-edge-shared': path.resolve(__dirname, '../px-edge-shared'),
27
21
  }
28
22
  : {}),
29
23
  },