@thinkpixellab-public/px-vue 4.0.24 → 4.0.26
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/bases/PxBaseSvg.vue +39 -13
- package/components/PxBalancedText.vue +14 -1
- package/components/PxCardGrid.vue +2 -7
- package/package.json +1 -1
- package/stories/PxSvg.stories.js +10 -3
- package/stories/assets/alphaNoSizing.svg +6 -0
- package/stories/assets/alphaSizeWidth.svg +6 -0
- package/utils/textWidth.js +11 -1
- package/vite.config.js +2 -8
package/bases/PxBaseSvg.vue
CHANGED
|
@@ -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
|
-
|
|
119
|
-
|
|
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
|
|
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
|
|
203
|
+
: svg.viewBox?.height || 0;
|
|
180
204
|
|
|
181
205
|
// save as data values
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
<component
|
|
12
12
|
v-if="hasHtml"
|
|
13
13
|
:class="[bem('inner', { html: true }), innerClass]"
|
|
14
|
+
:style="innerStyle"
|
|
14
15
|
:is="calcInnerTag"
|
|
15
16
|
ref="text"
|
|
16
17
|
v-html="html"
|
|
@@ -47,8 +48,16 @@ export default {
|
|
|
47
48
|
*/
|
|
48
49
|
innerTag: { type: String, default: null },
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Class applied to the inner element.
|
|
53
|
+
*/
|
|
51
54
|
innerClass: { type: String, default: null },
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Style applied to the inner element.
|
|
58
|
+
*/
|
|
59
|
+
innerStyle: { type: [String, Object], default: null },
|
|
60
|
+
|
|
52
61
|
/**
|
|
53
62
|
* Html that gets set on the inner tag element
|
|
54
63
|
*/
|
|
@@ -131,6 +140,7 @@ export default {
|
|
|
131
140
|
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
132
141
|
},
|
|
133
142
|
isHeadless() {
|
|
143
|
+
// TODO: replace with isUnderTest
|
|
134
144
|
if (isServer()) {
|
|
135
145
|
return false;
|
|
136
146
|
}
|
|
@@ -182,6 +192,9 @@ export default {
|
|
|
182
192
|
}
|
|
183
193
|
}
|
|
184
194
|
},
|
|
195
|
+
getInnerTextRef() {
|
|
196
|
+
return this.$refs.text;
|
|
197
|
+
},
|
|
185
198
|
},
|
|
186
199
|
};
|
|
187
200
|
</script>
|
|
@@ -137,6 +137,7 @@ You can define a template using space notation like this:
|
|
|
137
137
|
<script>
|
|
138
138
|
import aspect from '../plugins/filters/aspect.js';
|
|
139
139
|
import PxBaseItems from '../bases/PxBaseItems.vue';
|
|
140
|
+
import PxBaseResize from '../bases/PxBaseResize.vue';
|
|
140
141
|
|
|
141
142
|
// prettier-ignore
|
|
142
143
|
const defaultTemplates = {
|
|
@@ -193,7 +194,7 @@ const cardCountInRowTemplate = rowTemplate => {
|
|
|
193
194
|
|
|
194
195
|
export default {
|
|
195
196
|
name: 'px-card-grid',
|
|
196
|
-
mixins: [PxBaseItems],
|
|
197
|
+
mixins: [PxBaseResize, PxBaseItems],
|
|
197
198
|
props: {
|
|
198
199
|
templates: { type: Object, default: () => defaultTemplates },
|
|
199
200
|
maxColumns: { type: Number, default: 6 },
|
|
@@ -327,12 +328,6 @@ export default {
|
|
|
327
328
|
},
|
|
328
329
|
},
|
|
329
330
|
mounted() {
|
|
330
|
-
this.resizeObserver = new ResizeObserver(() => {
|
|
331
|
-
this.resize();
|
|
332
|
-
});
|
|
333
|
-
this.resizeObserver.observe(this.$el);
|
|
334
|
-
|
|
335
|
-
this.resize();
|
|
336
331
|
this.updateRowTemplates();
|
|
337
332
|
},
|
|
338
333
|
beforeDestroy() {
|
package/package.json
CHANGED
package/stories/PxSvg.stories.js
CHANGED
|
@@ -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
|
|
38
|
+
export const WidthAndHeightNoViewBox = {
|
|
37
39
|
...Basic,
|
|
38
|
-
|
|
40
|
+
args: { src: alphaSizeWidthSvg },
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const NoSizing = {
|
|
44
|
+
...Basic,
|
|
45
|
+
args: { src: alphaNoSizingSvg },
|
|
39
46
|
};
|
package/utils/textWidth.js
CHANGED
|
@@ -27,11 +27,21 @@ const getCssProp = (element, prop) => {
|
|
|
27
27
|
return window.getComputedStyle(element, null).getPropertyValue(prop);
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
const getFontFromElement = element => {
|
|
30
|
+
const getFontFromElement = (element, asObject = false) => {
|
|
31
31
|
const fontWeight = getCssProp(element, 'font-weight') || 'normal';
|
|
32
32
|
const fontSize = getCssProp(element, 'font-size') || '16px';
|
|
33
33
|
const fontFamily = getCssProp(element, 'font-family') || 'sans-serif';
|
|
34
34
|
|
|
35
|
+
if (asObject) {
|
|
36
|
+
const lineHeight = getCssProp(element, 'line-height') || 1.2;
|
|
37
|
+
return {
|
|
38
|
+
fontWeight,
|
|
39
|
+
fontSize,
|
|
40
|
+
fontFamily,
|
|
41
|
+
lineHeight,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
35
45
|
return `${fontWeight} ${fontSize} ${fontFamily}`;
|
|
36
46
|
};
|
|
37
47
|
|
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
|
-
|
|
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
|
},
|