@itcase/ui-core 1.10.47 → 1.10.48
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/cjs/context/Notifications.interface.js +2 -1
- package/dist/cjs/context/Notifications.js +207 -1
- package/dist/cjs/context/UIContext.js +76 -1
- package/dist/cjs/context/UrlAssetPrefix.js +17 -1
- package/dist/cjs/context/index.js +24 -1
- package/dist/cjs/hoc/index.js +11 -1
- package/dist/cjs/hoc/urlWithAssetPrefix.js +78 -1
- package/dist/cjs/hooks/index.js +37 -1
- package/dist/cjs/hooks/useActiveClasses/index.js +9 -1
- package/dist/cjs/hooks/useActiveClasses/useActiveClasses.helpers.js +93 -1
- package/dist/cjs/hooks/useActiveClasses/useActiveClasses.interface.js +65 -1
- package/dist/cjs/hooks/useActiveClasses/useActiveClasses.js +60 -1
- package/dist/cjs/hooks/useAppearanceConfig/index.js +8 -1
- package/dist/cjs/hooks/useAppearanceConfig/useAppearanceConfig.js +30 -1
- package/dist/cjs/hooks/useDevicePropsGenerator/index.js +23 -1
- package/dist/cjs/hooks/useDevicePropsGenerator/useDevicePropsGenerator.interface.js +2 -1
- package/dist/cjs/hooks/useDevicePropsGenerator/useDevicePropsGenerator.js +236 -1
- package/dist/cjs/hooks/useDeviceTargetClass.js +64 -1
- package/dist/cjs/hooks/useMediaQueries/index.js +9 -1
- package/dist/cjs/hooks/useMediaQueries/useMediaQueries.js +124 -1
- package/dist/cjs/hooks/useStyles/index.js +23 -1
- package/dist/cjs/hooks/useStyles/styleAttributes.helpers.js +9 -1
- package/dist/cjs/hooks/useStyles/styleAttributes.interface.js +2 -1
- package/dist/cjs/hooks/useStyles/styleAttributes.js +177 -1
- package/dist/cjs/hooks/useStyles/useStyles.js +224 -1
- package/dist/cjs/hooks/useViewportFix.js +43 -1
- package/dist/cjs/utils/index.js +9 -1
- package/dist/cjs/utils/mergeAppearanceKeys.js +18 -1
- package/dist/cjs/utils/setViewportProperty.js +8 -1
- package/dist/context/Notifications.js +202 -1
- package/dist/context/UIContext.js +73 -1
- package/dist/context/UrlAssetPrefix.js +14 -1
- package/dist/context/index.js +11 -1
- package/dist/hoc/index.js +5 -1
- package/dist/hoc/urlWithAssetPrefix.js +76 -1
- package/dist/hooks/index.js +24 -1
- package/dist/hooks/useActiveClasses/index.js +3 -1
- package/dist/hooks/useActiveClasses/useActiveClasses.helpers.js +89 -1
- package/dist/hooks/useActiveClasses/useActiveClasses.interface.js +63 -1
- package/dist/hooks/useActiveClasses/useActiveClasses.js +58 -1
- package/dist/hooks/useAppearanceConfig/index.js +2 -1
- package/dist/hooks/useAppearanceConfig/useAppearanceConfig.js +28 -1
- package/dist/hooks/useDevicePropsGenerator/index.js +17 -1
- package/dist/hooks/useDevicePropsGenerator/useDevicePropsGenerator.js +234 -1
- package/dist/hooks/useDeviceTargetClass.js +62 -1
- package/dist/hooks/useMediaQueries/index.js +3 -1
- package/dist/hooks/useMediaQueries/useMediaQueries.js +122 -1
- package/dist/hooks/useStyles/index.js +16 -1
- package/dist/hooks/useStyles/styleAttributes.helpers.js +7 -1
- package/dist/hooks/useStyles/styleAttributes.js +173 -1
- package/dist/hooks/useStyles/useStyles.js +222 -1
- package/dist/hooks/useViewportFix.js +41 -1
- package/dist/types/context/Notifications.d.ts +8 -8
- package/dist/types/hoc/urlWithAssetPrefix.d.ts +2 -3
- package/dist/types/hooks/useActiveClasses/useActiveClasses.interface.d.ts +4 -4
- package/dist/types/hooks/useAppearanceConfig/useAppearanceConfig.d.ts +1 -1
- package/dist/types/hooks/useDevicePropsGenerator/useDevicePropsGenerator.d.ts +1 -1
- package/dist/types/hooks/useDeviceTargetClass.d.ts +2 -1
- package/dist/types/hooks/useMediaQueries/useMediaQueries.d.ts +2 -1
- package/dist/types/hooks/useStyles/styleAttributes.helpers.d.ts +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/mergeAppearanceKeys.js +16 -1
- package/dist/utils/setViewportProperty.js +6 -1
- package/package.json +2 -2
|
@@ -1 +1,177 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var styleAttributes = [
|
|
6
|
+
/**
|
|
7
|
+
* Layout
|
|
8
|
+
*/
|
|
9
|
+
'alignContent',
|
|
10
|
+
'alignItems',
|
|
11
|
+
'alignSelf',
|
|
12
|
+
'aspectRatio',
|
|
13
|
+
'border',
|
|
14
|
+
'borderBottomWidth',
|
|
15
|
+
'borderLeftWidth',
|
|
16
|
+
'borderRightWidth',
|
|
17
|
+
'borderTopWidth',
|
|
18
|
+
'borderWidth',
|
|
19
|
+
'bottom',
|
|
20
|
+
'display',
|
|
21
|
+
'flex',
|
|
22
|
+
'flexBasis',
|
|
23
|
+
'flexDirection',
|
|
24
|
+
'flexGrow',
|
|
25
|
+
'flexShrink',
|
|
26
|
+
'flexWrap',
|
|
27
|
+
'gap',
|
|
28
|
+
'rowGap',
|
|
29
|
+
'columnGap',
|
|
30
|
+
'columnWidth',
|
|
31
|
+
'height',
|
|
32
|
+
'justifyContent',
|
|
33
|
+
'left',
|
|
34
|
+
'margin',
|
|
35
|
+
'marginBottom',
|
|
36
|
+
'marginHorizontal',
|
|
37
|
+
'marginLeft',
|
|
38
|
+
'marginRight',
|
|
39
|
+
'marginTop',
|
|
40
|
+
'marginVertical',
|
|
41
|
+
'maxHeight',
|
|
42
|
+
'maxWidth',
|
|
43
|
+
'minHeight',
|
|
44
|
+
'minWidth',
|
|
45
|
+
'overflow',
|
|
46
|
+
'overflowY',
|
|
47
|
+
'overflowX',
|
|
48
|
+
'padding',
|
|
49
|
+
'paddingBottom',
|
|
50
|
+
'paddingEnd',
|
|
51
|
+
'paddingHorizontal',
|
|
52
|
+
'paddingLeft',
|
|
53
|
+
'paddingRight',
|
|
54
|
+
'paddingStart',
|
|
55
|
+
'paddingTop',
|
|
56
|
+
'paddingVertical',
|
|
57
|
+
'position',
|
|
58
|
+
'right',
|
|
59
|
+
'top',
|
|
60
|
+
[
|
|
61
|
+
'width',
|
|
62
|
+
{
|
|
63
|
+
validate: (value) => {
|
|
64
|
+
// Pass only number value for "width" style.
|
|
65
|
+
// If width have custom value, like "fill", we must set class by this value.
|
|
66
|
+
// "\d" - digit; "+" - 1 or more
|
|
67
|
+
return /\d+/.test(value);
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
'zIndex',
|
|
72
|
+
'order',
|
|
73
|
+
/**
|
|
74
|
+
* Shadow
|
|
75
|
+
*/
|
|
76
|
+
'shadowColor',
|
|
77
|
+
'shadowOffset',
|
|
78
|
+
'shadowOpacity',
|
|
79
|
+
'shadowRadius',
|
|
80
|
+
/**
|
|
81
|
+
* Transform
|
|
82
|
+
*/
|
|
83
|
+
'transform',
|
|
84
|
+
/**
|
|
85
|
+
* View
|
|
86
|
+
*/
|
|
87
|
+
'background',
|
|
88
|
+
'backgroundColor',
|
|
89
|
+
'borderBottomColor',
|
|
90
|
+
'borderBottomEndRadius',
|
|
91
|
+
'borderBottomLeftRadius',
|
|
92
|
+
'borderBottomRightRadius',
|
|
93
|
+
'borderBottomStartRadius',
|
|
94
|
+
'borderColor',
|
|
95
|
+
'borderCurve',
|
|
96
|
+
'borderEndColor',
|
|
97
|
+
'borderLeftColor',
|
|
98
|
+
'borderRadius',
|
|
99
|
+
'borderRightColor',
|
|
100
|
+
'borderStartColor',
|
|
101
|
+
'borderStyle',
|
|
102
|
+
'borderTopColor',
|
|
103
|
+
'borderTopEndRadius',
|
|
104
|
+
'borderTopLeftRadius',
|
|
105
|
+
'borderTopRightRadius',
|
|
106
|
+
'borderTopStartRadius',
|
|
107
|
+
'opacity',
|
|
108
|
+
'cursor',
|
|
109
|
+
/**
|
|
110
|
+
* Text
|
|
111
|
+
*/
|
|
112
|
+
'color',
|
|
113
|
+
'fontFamily',
|
|
114
|
+
'fontSize',
|
|
115
|
+
'fontStyle',
|
|
116
|
+
'fontVariant',
|
|
117
|
+
'fontWeight',
|
|
118
|
+
'letterSpacing',
|
|
119
|
+
'lineHeight',
|
|
120
|
+
'textAlign',
|
|
121
|
+
'textDecorationColor',
|
|
122
|
+
'textDecorationLine',
|
|
123
|
+
'textDecorationStyle',
|
|
124
|
+
'textShadowColor',
|
|
125
|
+
'textShadowOffset',
|
|
126
|
+
'textShadowRadius',
|
|
127
|
+
'textTransform',
|
|
128
|
+
'verticalAlign',
|
|
129
|
+
'writingMode',
|
|
130
|
+
'whiteSpace',
|
|
131
|
+
/**
|
|
132
|
+
* Image
|
|
133
|
+
*/
|
|
134
|
+
'overlayColor',
|
|
135
|
+
'resizeMode',
|
|
136
|
+
'tintColor',
|
|
137
|
+
'objectFit',
|
|
138
|
+
'objectPosition',
|
|
139
|
+
/**
|
|
140
|
+
* Grid
|
|
141
|
+
*/
|
|
142
|
+
'gridTemplateColumns',
|
|
143
|
+
'gridArea',
|
|
144
|
+
'gridAutoColumns',
|
|
145
|
+
'gridAutoFlow',
|
|
146
|
+
'gridAutoRows',
|
|
147
|
+
'gridTemplate',
|
|
148
|
+
'gridTemplateAreas',
|
|
149
|
+
'gridTemplateRows',
|
|
150
|
+
'gridColumn',
|
|
151
|
+
'gridColumnStart',
|
|
152
|
+
'gridColumnEnd',
|
|
153
|
+
'gridColumnGap',
|
|
154
|
+
'gridRow',
|
|
155
|
+
'gridRowStart',
|
|
156
|
+
'gridRowEnd',
|
|
157
|
+
'gridRowGap',
|
|
158
|
+
/**
|
|
159
|
+
* Filter
|
|
160
|
+
*/
|
|
161
|
+
'backdropFilter',
|
|
162
|
+
/**
|
|
163
|
+
* Transition
|
|
164
|
+
*/
|
|
165
|
+
'transition',
|
|
166
|
+
'transitionBehavior',
|
|
167
|
+
'transitionDelay',
|
|
168
|
+
'transitionDuration',
|
|
169
|
+
'transitionProperty',
|
|
170
|
+
'transitionTimingFunction',
|
|
171
|
+
/**
|
|
172
|
+
* Control
|
|
173
|
+
*/
|
|
174
|
+
'pointerEvents',
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
exports.default = styleAttributes;
|
|
@@ -1 +1,224 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var camelCase = require('lodash/camelCase');
|
|
5
|
+
var maxBy = require('lodash/maxBy');
|
|
6
|
+
var upperFirst = require('lodash/upperFirst');
|
|
7
|
+
require('../../context/Notifications.js');
|
|
8
|
+
var UIContext = require('../../context/UIContext.js');
|
|
9
|
+
require('../../context/UrlAssetPrefix.js');
|
|
10
|
+
var styleAttributes = require('./styleAttributes.js');
|
|
11
|
+
var styleAttributes_helpers = require('./styleAttributes.helpers.js');
|
|
12
|
+
require('react/jsx-runtime');
|
|
13
|
+
require('uuid');
|
|
14
|
+
require('@itcase/common');
|
|
15
|
+
require('../useMediaQueries/useMediaQueries.js');
|
|
16
|
+
require('react-responsive');
|
|
17
|
+
require('../../utils/setViewportProperty.js');
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* rule of prop key:
|
|
21
|
+
*
|
|
22
|
+
* first is style second is div target third is device
|
|
23
|
+
* paddingHorizontal GridInnerWrapper MobileNormal
|
|
24
|
+
*
|
|
25
|
+
* paddingHorizontalGridInnerWrapperMobileNormal: "10px"
|
|
26
|
+
*/
|
|
27
|
+
function useStyles(props) {
|
|
28
|
+
const { deviceCurrentMainType, deviceCurrentType, deviceTypesList } = UIContext.useUserDeviceContext();
|
|
29
|
+
const propsStyleAttributes = React.useMemo(() => {
|
|
30
|
+
const styles = Object.entries(props).reduce((result, [propKey, propValue]) => {
|
|
31
|
+
const styleAttributeKey = getTargetStyleAttributeKey(propKey, propValue);
|
|
32
|
+
if (styleAttributeKey) {
|
|
33
|
+
result[propKey] = propValue;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}, {});
|
|
37
|
+
return styles;
|
|
38
|
+
// "props" object maybe big and frequently changing
|
|
39
|
+
}, [props]);
|
|
40
|
+
const collectedStyles = React.useMemo(() => {
|
|
41
|
+
const resultStylesGroups = {};
|
|
42
|
+
for (const [propKey, propValue] of Object.entries(propsStyleAttributes)) {
|
|
43
|
+
let value = null;
|
|
44
|
+
const styleAttributeKey = getTargetStyleAttributeKey(propKey, propValue);
|
|
45
|
+
const isStyleForCurrentDevice = propKey
|
|
46
|
+
.toLowerCase()
|
|
47
|
+
.endsWith(deviceCurrentType.toLowerCase());
|
|
48
|
+
// e.g. "GridWrapperInner"
|
|
49
|
+
const targetElementKey = removeDeviceType(propKey.replace(styleAttributeKey, ''), deviceTypesList);
|
|
50
|
+
const targetElementGroupKey = camelCase(targetElementKey) || 'styles';
|
|
51
|
+
if (!resultStylesGroups[targetElementGroupKey]) {
|
|
52
|
+
resultStylesGroups[targetElementGroupKey] = {};
|
|
53
|
+
}
|
|
54
|
+
if (isStyleForCurrentDevice) {
|
|
55
|
+
value = propValue;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const propKeyWithOutDeviceType = `${styleAttributeKey}${targetElementKey}`;
|
|
59
|
+
const propKeyWithBaseDeviceType = `${propKeyWithOutDeviceType}${upperFirst(deviceCurrentMainType)}`;
|
|
60
|
+
const defaultValue = props[propKeyWithBaseDeviceType] || props[propKeyWithOutDeviceType];
|
|
61
|
+
let currentValue = resultStylesGroups[targetElementGroupKey][styleAttributeKey];
|
|
62
|
+
if (propKeyWithOutDeviceType.includes('Horizontal')) {
|
|
63
|
+
const keyLeft = styleAttributeKey.replace('Horizontal', 'Left');
|
|
64
|
+
currentValue =
|
|
65
|
+
resultStylesGroups[targetElementGroupKey][keyLeft];
|
|
66
|
+
}
|
|
67
|
+
else if (propKeyWithOutDeviceType.includes('Vertical')) {
|
|
68
|
+
const keyTop = styleAttributeKey.replace('Vertical', 'Top');
|
|
69
|
+
currentValue =
|
|
70
|
+
resultStylesGroups[targetElementGroupKey][keyTop];
|
|
71
|
+
}
|
|
72
|
+
if (!currentValue) {
|
|
73
|
+
value = defaultValue;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (value) {
|
|
77
|
+
// Check not digit symbols. Chars means some unit ("px", "em", "rem" or custom "m")
|
|
78
|
+
const isValueHasUnit = /\D/.test(value);
|
|
79
|
+
// If value has some unit
|
|
80
|
+
if (isValueHasUnit) {
|
|
81
|
+
// Check value on our custom "m"(module) unit
|
|
82
|
+
/** Pattern for:
|
|
83
|
+
* 1m
|
|
84
|
+
* 1.5m
|
|
85
|
+
* 1m 1m 1.5m
|
|
86
|
+
* 0 0 1m 1m
|
|
87
|
+
*/
|
|
88
|
+
const isValueHasModuleUnit = /\d+\.?\d*m\s?(?![a-zA-Z]+)/.test(value);
|
|
89
|
+
// If value has module unit
|
|
90
|
+
if (isValueHasModuleUnit) {
|
|
91
|
+
/** Order for shorthand properties:
|
|
92
|
+
* top
|
|
93
|
+
* right
|
|
94
|
+
* bottom
|
|
95
|
+
* left
|
|
96
|
+
* or:
|
|
97
|
+
* top
|
|
98
|
+
* right and left
|
|
99
|
+
* bottom
|
|
100
|
+
* or:
|
|
101
|
+
* top and bottom
|
|
102
|
+
* right and left
|
|
103
|
+
*/
|
|
104
|
+
const valuePxPartsList = value
|
|
105
|
+
.split(' ')
|
|
106
|
+
.map((valuePart) => {
|
|
107
|
+
const valueModule = valuePart.replace(/[a-z]/gi, '');
|
|
108
|
+
const valuePx = parseFloat(valueModule) * 8;
|
|
109
|
+
return `${valuePx}px`;
|
|
110
|
+
}, []);
|
|
111
|
+
value = valuePxPartsList.join(' ');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// Some properties doesn't have any units
|
|
116
|
+
const ignorePX = [
|
|
117
|
+
'flexGrow',
|
|
118
|
+
'gridColumn',
|
|
119
|
+
'gridColumnEnd',
|
|
120
|
+
'gridColumnStart',
|
|
121
|
+
'gridRow',
|
|
122
|
+
'gridRowEnd',
|
|
123
|
+
'gridRowStart',
|
|
124
|
+
'opacity',
|
|
125
|
+
'order',
|
|
126
|
+
'zIndex',
|
|
127
|
+
].includes(styleAttributeKey);
|
|
128
|
+
if (!ignorePX) {
|
|
129
|
+
// Add px to non-unit value
|
|
130
|
+
value = `${value}px`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (styleAttributeKey.includes('Horizontal')) {
|
|
134
|
+
const keyRight = styleAttributeKey.replace('Horizontal', 'Right');
|
|
135
|
+
const keyLeft = styleAttributeKey.replace('Horizontal', 'Left');
|
|
136
|
+
const valuePartsList = value.split(' ');
|
|
137
|
+
const valueRight = valuePartsList[0];
|
|
138
|
+
const valueLeft = valuePartsList[1] || valuePartsList[0];
|
|
139
|
+
resultStylesGroups[targetElementGroupKey][keyRight] = valueRight;
|
|
140
|
+
resultStylesGroups[targetElementGroupKey][keyLeft] = valueLeft;
|
|
141
|
+
}
|
|
142
|
+
else if (styleAttributeKey.includes('Vertical')) {
|
|
143
|
+
const keyTop = styleAttributeKey.replace('Vertical', 'Top');
|
|
144
|
+
const keyBottom = styleAttributeKey.replace('Vertical', 'Bottom');
|
|
145
|
+
const valuePartsList = value.split(' ');
|
|
146
|
+
const valueTop = valuePartsList[0];
|
|
147
|
+
const valueBottom = valuePartsList[1] || valuePartsList[0];
|
|
148
|
+
resultStylesGroups[targetElementGroupKey][keyTop] = valueTop;
|
|
149
|
+
resultStylesGroups[targetElementGroupKey][keyBottom] = valueBottom;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
resultStylesGroups[targetElementGroupKey][styleAttributeKey] = value;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return resultStylesGroups;
|
|
157
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
158
|
+
}, [
|
|
159
|
+
deviceCurrentMainType,
|
|
160
|
+
deviceCurrentType,
|
|
161
|
+
...Object.values(propsStyleAttributes),
|
|
162
|
+
]);
|
|
163
|
+
return collectedStyles;
|
|
164
|
+
}
|
|
165
|
+
const removeDeviceType = (originalKey, deviceTypesList) => {
|
|
166
|
+
// Remove "mobile"/"tablet"/"desktop"
|
|
167
|
+
const withOutDeviceType = deviceTypesList.reduce((cleanKey, deviceType) => {
|
|
168
|
+
if (cleanKey.endsWith(upperFirst(deviceType))) {
|
|
169
|
+
return cleanKey.replace(upperFirst(deviceType), '');
|
|
170
|
+
}
|
|
171
|
+
return cleanKey;
|
|
172
|
+
}, originalKey);
|
|
173
|
+
return withOutDeviceType;
|
|
174
|
+
};
|
|
175
|
+
const targetStyleAttributeKeyCache = new Map();
|
|
176
|
+
// This function is pure and it does a lot of useless work.
|
|
177
|
+
// We can achieve huge cache hit rate by memoizing it.
|
|
178
|
+
const getTargetStyleAttributeKey = (styleKey, styleValue = '') => {
|
|
179
|
+
const cacheKey = `${styleKey}_${styleValue}`;
|
|
180
|
+
if (targetStyleAttributeKeyCache.has(cacheKey)) {
|
|
181
|
+
return targetStyleAttributeKeyCache.get(cacheKey);
|
|
182
|
+
}
|
|
183
|
+
// Collect list of possible styles for propKey. e.g:
|
|
184
|
+
// "borderLeftWidthWrapperInnerMobileNormal" to ["border", "borderLeftWidth"]
|
|
185
|
+
const possibleStyleAttributesList = styleAttributes.default.filter((styleAttribute) => {
|
|
186
|
+
// Attribute can be array with key on first position and params on second
|
|
187
|
+
if (Array.isArray(styleAttribute)) {
|
|
188
|
+
// First item always attribute key (e.g. border, width, etc)
|
|
189
|
+
const styleAttributeKey = styleAttribute[0];
|
|
190
|
+
// Second item always params with some settings or methods
|
|
191
|
+
const styleAttributeParams = styleAttribute[1] || {};
|
|
192
|
+
// If is target attribute key
|
|
193
|
+
if (styleKey.startsWith(styleAttributeKey)) {
|
|
194
|
+
// If target attribute params has validate method
|
|
195
|
+
if (styleAttributeParams.validate) {
|
|
196
|
+
// Return validation result for target attribute
|
|
197
|
+
return styleAttributeParams.validate(styleValue);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
// Or always add to list
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
// Else ignore
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
// If is target attribute
|
|
211
|
+
return styleKey.startsWith(String(styleAttribute));
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
// Get longest style key (e.g. "borderLeftWidth")
|
|
215
|
+
const targetStyleAttribute = maxBy(possibleStyleAttributesList, (styleAttribute) => {
|
|
216
|
+
const key = styleAttributes_helpers.getStyleAttributeKey(styleAttribute);
|
|
217
|
+
return key.length;
|
|
218
|
+
});
|
|
219
|
+
const styleAttributeKey = styleAttributes_helpers.getStyleAttributeKey(targetStyleAttribute);
|
|
220
|
+
targetStyleAttributeKeyCache.set(cacheKey, styleAttributeKey);
|
|
221
|
+
return styleAttributeKey;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
exports.useStyles = useStyles;
|
|
@@ -1 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
function useViewportFix() {
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
// https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
|
|
8
|
+
const setViewportProperty = () => {
|
|
9
|
+
// "vh" unit is equal to 1% of the height of the initial containing block
|
|
10
|
+
// https://www.w3.org/R/css-values-3/#viewport-relative-lengths
|
|
11
|
+
const vh = window.innerHeight * 0.01;
|
|
12
|
+
/** NOTE:
|
|
13
|
+
* In JavaScript, you can always get the value of the current viewport
|
|
14
|
+
* by using the global variable window.innerHeight. This value takes
|
|
15
|
+
* the browser’s interface into account and is updated when its
|
|
16
|
+
* visibility changes. The trick is to store the viewport value
|
|
17
|
+
* in a CSS variable and apply that to the element instead of the vh unit.
|
|
18
|
+
* Let’s say our CSS custom variable is --vh for this example.
|
|
19
|
+
* That means we will want to apply it in our CSS like this:
|
|
20
|
+
* ```
|
|
21
|
+
* .my-element {
|
|
22
|
+
* height: 100vh; (Fallback for browsers that do not support Custom Properties)
|
|
23
|
+
* height: calc(var(--vh, 1vh) * 100);
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
* We told JavaScript to grab the height of the viewport and then
|
|
27
|
+
* drilled it down into 1/100th of that total so we have a value
|
|
28
|
+
* to assign as our viewport height unit value.
|
|
29
|
+
* Then we politely asked JS to create the CSS variable "--vh" at the ":root":
|
|
30
|
+
*/
|
|
31
|
+
document.documentElement.style.setProperty('--vh', `${vh}px`);
|
|
32
|
+
};
|
|
33
|
+
// Update the value of "--vh" after render
|
|
34
|
+
setViewportProperty();
|
|
35
|
+
// Update the value of "--vh" by listening to the window resize event
|
|
36
|
+
window.addEventListener('resize', setViewportProperty);
|
|
37
|
+
return () => {
|
|
38
|
+
window.removeEventListener('resize', setViewportProperty);
|
|
39
|
+
};
|
|
40
|
+
}, []);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.useViewportFix = useViewportFix;
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var mergeAppearanceKeys = require('./mergeAppearanceKeys.js');
|
|
4
|
+
var setViewportProperty = require('./setViewportProperty.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.mergeAppearanceKeys = mergeAppearanceKeys.mergeAppearanceKeys;
|
|
9
|
+
exports.setViewportProperty = setViewportProperty.setViewportProperty;
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @example
|
|
5
|
+
* mergeAppearanceKeys(' ', '1', undefined, '2', '1') === '1 2'
|
|
6
|
+
*/
|
|
7
|
+
const mergeAppearanceKeys = (...appearances) => {
|
|
8
|
+
const trimmedAppearances = appearances
|
|
9
|
+
.map((appearance) => appearance?.trim())
|
|
10
|
+
.filter(Boolean);
|
|
11
|
+
if (trimmedAppearances.length < 2) {
|
|
12
|
+
return trimmedAppearances[0] ?? '';
|
|
13
|
+
}
|
|
14
|
+
const uniqueAppearances = Array.from(new Set(trimmedAppearances));
|
|
15
|
+
return uniqueAppearances.join(' ');
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.mergeAppearanceKeys = mergeAppearanceKeys;
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const setViewportProperty = () => {
|
|
4
|
+
const vh = window.innerHeight * 0.01;
|
|
5
|
+
document.documentElement.style.setProperty('--vh', `${vh}px`);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
exports.setViewportProperty = setViewportProperty;
|