@instructure/ui-utils 11.7.8 → 11.7.9-pr-snapshot-1792147648392
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/CHANGELOG.md +13 -0
- package/es/camelize.js +2 -44
- package/es/capitalizeFirstLetter.js +2 -34
- package/es/cloneArray.js +9 -42
- package/es/combineDataCid.js +4 -34
- package/es/convertCase.js +1 -25
- package/es/createChainedFunction.js +26 -75
- package/es/deepEqual.js +1 -25
- package/es/generateId.js +8 -50
- package/es/getBrowser.js +40 -71
- package/es/hash.js +40 -65
- package/es/index.js +1 -24
- package/es/isBaseTheme.js +22 -42
- package/es/isEmpty.js +6 -29
- package/es/mergeDeep.js +48 -74
- package/es/ms.js +12 -53
- package/es/parseUnit.js +7 -48
- package/es/pascalize.js +2 -44
- package/es/px.js +14 -56
- package/es/safeHref.js +64 -96
- package/es/safeLinkProps.js +9 -50
- package/es/shallowEqual.js +22 -72
- package/es/within.js +2 -39
- package/package.json +8 -11
- package/tsconfig.build.json +0 -3
- package/lib/camelize.js +0 -53
- package/lib/capitalizeFirstLetter.js +0 -43
- package/lib/cloneArray.js +0 -52
- package/lib/combineDataCid.js +0 -41
- package/lib/convertCase.js +0 -19
- package/lib/createChainedFunction.js +0 -86
- package/lib/deepEqual.js +0 -38
- package/lib/generateId.js +0 -58
- package/lib/getBrowser.js +0 -85
- package/lib/hash.js +0 -82
- package/lib/index.js +0 -187
- package/lib/isBaseTheme.js +0 -50
- package/lib/isEmpty.js +0 -39
- package/lib/mergeDeep.js +0 -89
- package/lib/ms.js +0 -62
- package/lib/package.json +0 -1
- package/lib/parseUnit.js +0 -57
- package/lib/pascalize.js +0 -55
- package/lib/px.js +0 -68
- package/lib/safeHref.js +0 -115
- package/lib/safeLinkProps.js +0 -59
- package/lib/shallowEqual.js +0 -85
- package/lib/within.js +0 -48
package/es/index.js
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
1
|
export { capitalizeFirstLetter } from './capitalizeFirstLetter.js';
|
|
25
2
|
export { cloneArray } from './cloneArray.js';
|
|
26
3
|
export { createChainedFunction } from './createChainedFunction.js';
|
|
@@ -40,4 +17,4 @@ export { camelize } from './camelize.js';
|
|
|
40
17
|
export { pascalize } from './pascalize.js';
|
|
41
18
|
export { isBaseTheme } from './isBaseTheme.js';
|
|
42
19
|
export { getBrowser, isSafari, isEdge, isIE, isFirefox, isChromium, isAndroidOrIOS, isMac } from './getBrowser.js';
|
|
43
|
-
export { combineDataCid } from './combineDataCid.js';
|
|
20
|
+
export { combineDataCid } from './combineDataCid.js';
|
package/es/isBaseTheme.js
CHANGED
|
@@ -1,44 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const baseThemeProps = ['borders', 'breakpoints', 'colors', 'forms', 'media', 'shadows', 'spacing', 'stacking', 'transitions', 'typography'];
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Checks if the given param is an object with all the keys needed for an
|
|
29
|
-
* Instructure theme.
|
|
30
|
-
* @param theme Anything. This function will throw an error if it's not a theme
|
|
31
|
-
* object.
|
|
32
|
-
*/
|
|
33
|
-
const isBaseTheme = theme => {
|
|
34
|
-
if (Array.isArray(theme) || typeof theme === 'function') {
|
|
35
|
-
throw new Error();
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
return 'key' in theme && baseThemeProps.every(prop => prop in theme);
|
|
39
|
-
} catch {
|
|
40
|
-
throw new Error();
|
|
41
|
-
}
|
|
1
|
+
const baseThemeProps = [
|
|
2
|
+
'borders',
|
|
3
|
+
'breakpoints',
|
|
4
|
+
'colors',
|
|
5
|
+
'forms',
|
|
6
|
+
'media',
|
|
7
|
+
'shadows',
|
|
8
|
+
'spacing',
|
|
9
|
+
'stacking',
|
|
10
|
+
'transitions',
|
|
11
|
+
'typography'
|
|
12
|
+
];
|
|
13
|
+
const isBaseTheme = (theme)=>{
|
|
14
|
+
if (Array.isArray(theme) || typeof theme === 'function') {
|
|
15
|
+
throw new Error();
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
return 'key' in theme && baseThemeProps.every((prop)=>prop in theme);
|
|
19
|
+
} catch {
|
|
20
|
+
throw new Error();
|
|
21
|
+
}
|
|
42
22
|
};
|
|
43
23
|
export default isBaseTheme;
|
|
44
|
-
export { isBaseTheme };
|
|
24
|
+
export { isBaseTheme };
|
package/es/isEmpty.js
CHANGED
|
@@ -1,33 +1,10 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
1
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
25
2
|
function isEmpty(obj) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
3
|
+
if (typeof obj !== 'object') return true;
|
|
4
|
+
for(const key in obj){
|
|
5
|
+
if (hasOwnProperty.call(obj, key)) return false;
|
|
6
|
+
}
|
|
7
|
+
return true;
|
|
31
8
|
}
|
|
32
9
|
export default isEmpty;
|
|
33
|
-
export { isEmpty };
|
|
10
|
+
export { isEmpty };
|
package/es/mergeDeep.js
CHANGED
|
@@ -1,83 +1,57 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* ---
|
|
27
|
-
* category: utilities/Misc
|
|
28
|
-
* ---
|
|
29
|
-
* Deep merge N objects into a single result object.
|
|
30
|
-
* Merging creates a new object, so that none of the arguments are modified.
|
|
31
|
-
*
|
|
32
|
-
* @module mergeDeep
|
|
33
|
-
*
|
|
34
|
-
* @param {Object} args objects to merge
|
|
35
|
-
* @returns {Object} a new object with items from all arguments
|
|
36
|
-
*/
|
|
37
1
|
function mergeDeep(...args) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
return target;
|
|
2
|
+
let target = {};
|
|
3
|
+
args.forEach((arg)=>{
|
|
4
|
+
target = mergeSourceIntoTarget(target, arg);
|
|
5
|
+
});
|
|
6
|
+
return target;
|
|
45
7
|
}
|
|
46
8
|
function mergeSourceIntoTarget(target, source) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
9
|
+
if (isObject(source)) {
|
|
10
|
+
const keys = [
|
|
11
|
+
...Object.keys(source),
|
|
12
|
+
...Object.getOwnPropertySymbols(source)
|
|
13
|
+
];
|
|
14
|
+
const merged = {
|
|
15
|
+
...target
|
|
16
|
+
};
|
|
17
|
+
keys.forEach((key)=>{
|
|
18
|
+
if (key === '__proto__' || key === 'prototype' || key === 'constructor') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (isObject(target[key]) && isObject(source[key])) {
|
|
22
|
+
merged[key] = mergeSourceIntoTarget(target[key], source[key]);
|
|
23
|
+
} else if (isArray(source[key]) && isArray(target[key])) {
|
|
24
|
+
merged[key] = [
|
|
25
|
+
...new Set([
|
|
26
|
+
...target[key],
|
|
27
|
+
...source[key]
|
|
28
|
+
])
|
|
29
|
+
];
|
|
30
|
+
} else if (isArray(target[key])) {
|
|
31
|
+
merged[key] = [
|
|
32
|
+
...new Set([
|
|
33
|
+
...target[key],
|
|
34
|
+
...[
|
|
35
|
+
source[key]
|
|
36
|
+
]
|
|
37
|
+
])
|
|
38
|
+
];
|
|
39
|
+
} else {
|
|
40
|
+
merged[key] = source[key];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return merged;
|
|
44
|
+
} else {
|
|
45
|
+
return {
|
|
46
|
+
...target
|
|
47
|
+
};
|
|
48
|
+
}
|
|
75
49
|
}
|
|
76
50
|
function isObject(item) {
|
|
77
|
-
|
|
51
|
+
return item && (typeof item === 'object' || typeof item === 'function') && !Array.isArray(item);
|
|
78
52
|
}
|
|
79
53
|
function isArray(item) {
|
|
80
|
-
|
|
54
|
+
return Array.isArray(item);
|
|
81
55
|
}
|
|
82
56
|
export default mergeDeep;
|
|
83
|
-
export { mergeDeep };
|
|
57
|
+
export { mergeDeep };
|
package/es/ms.js
CHANGED
|
@@ -1,57 +1,16 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
1
|
import { parseUnit } from './parseUnit.js';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* ---
|
|
29
|
-
* category: utilities/Misc
|
|
30
|
-
* ---
|
|
31
|
-
* Converts a unit value time combination (s, ms) to a number representing ms
|
|
32
|
-
*
|
|
33
|
-
* @module ms
|
|
34
|
-
*
|
|
35
|
-
* Example inputs:
|
|
36
|
-
* - '100s'
|
|
37
|
-
* - '20ms'
|
|
38
|
-
*
|
|
39
|
-
* @param {String|Number} val
|
|
40
|
-
* @returns {Number} Returns numerical representation of milliseconds
|
|
41
|
-
*/
|
|
42
2
|
function ms(val) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
3
|
+
if (!val || typeof val === 'number') {
|
|
4
|
+
return val;
|
|
5
|
+
}
|
|
6
|
+
const [num, unit] = parseUnit(val);
|
|
7
|
+
if (unit === 'ms') {
|
|
8
|
+
return num;
|
|
9
|
+
} else if (unit === 's') {
|
|
10
|
+
return num * 1000;
|
|
11
|
+
} else {
|
|
12
|
+
return num;
|
|
13
|
+
}
|
|
55
14
|
}
|
|
56
15
|
export default ms;
|
|
57
|
-
export { ms };
|
|
16
|
+
export { ms };
|
package/es/parseUnit.js
CHANGED
|
@@ -1,51 +1,10 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* ---
|
|
27
|
-
* category: utilities/Misc
|
|
28
|
-
* ---
|
|
29
|
-
* Converts a CSS unit value combination into an array of type [ value, unit ]
|
|
30
|
-
*
|
|
31
|
-
* @module parseUnit
|
|
32
|
-
*
|
|
33
|
-
* Example inputs:
|
|
34
|
-
* - '100px'
|
|
35
|
-
* - '20rem'
|
|
36
|
-
* - '10vh'
|
|
37
|
-
* - '400vmin'
|
|
38
|
-
*
|
|
39
|
-
* @param {string|number} str
|
|
40
|
-
* @returns {Array} Returns array of shape [ value, unit ] Unit is '' if it could
|
|
41
|
-
* not be parsed
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
1
|
function parseUnit(str) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
2
|
+
const value = `${str}`;
|
|
3
|
+
const match = value.match(/[\d.\-\+]*\s*(.*)/);
|
|
4
|
+
return [
|
|
5
|
+
parseFloat(value),
|
|
6
|
+
match && match.length > 0 ? match[1] : ''
|
|
7
|
+
];
|
|
49
8
|
}
|
|
50
9
|
export default parseUnit;
|
|
51
|
-
export { parseUnit };
|
|
10
|
+
export { parseUnit };
|
package/es/pascalize.js
CHANGED
|
@@ -1,49 +1,7 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
1
|
import { capitalizeFirstLetter } from './capitalizeFirstLetter.js';
|
|
25
2
|
import { camelize } from './camelize.js';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* ---
|
|
29
|
-
* category: utilities/Misc
|
|
30
|
-
* ---
|
|
31
|
-
* Converts a hyphenated or camel cased string to pascal case
|
|
32
|
-
*
|
|
33
|
-
* Example inputs:
|
|
34
|
-
* - 'foo-bar'
|
|
35
|
-
* - 'baz-qux'
|
|
36
|
-
*
|
|
37
|
-
* Example outputs:
|
|
38
|
-
* - 'FooBar'
|
|
39
|
-
* - 'BazQux'
|
|
40
|
-
*
|
|
41
|
-
* @module pascalize
|
|
42
|
-
* @param {String} str
|
|
43
|
-
* @returns {String} Returns pascal cased string
|
|
44
|
-
*/
|
|
45
3
|
function pascalize(str) {
|
|
46
|
-
|
|
4
|
+
return capitalizeFirstLetter(camelize(str));
|
|
47
5
|
}
|
|
48
6
|
export default pascalize;
|
|
49
|
-
export { pascalize };
|
|
7
|
+
export { pascalize };
|
package/es/px.js
CHANGED
|
@@ -1,61 +1,19 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
1
|
import { canUseDOM, getFontSize } from '@instructure/ui-dom-utils';
|
|
26
2
|
import { parseUnit } from './parseUnit.js';
|
|
27
|
-
/**
|
|
28
|
-
* ---
|
|
29
|
-
* category: utilities/Misc
|
|
30
|
-
* ---
|
|
31
|
-
* Converts a unit value size combination (em, rem, px) to a number representing px
|
|
32
|
-
*
|
|
33
|
-
* Example inputs:
|
|
34
|
-
* - '100rem'
|
|
35
|
-
* - '20em'
|
|
36
|
-
* - '40px'
|
|
37
|
-
*
|
|
38
|
-
* @module px
|
|
39
|
-
*
|
|
40
|
-
* @param {String|number} val The value to look up. If it's a number its just returned as is.
|
|
41
|
-
* @param {Document|Window|Node|React.ReactElement |React.Component|null} el - containing element, for context measure is em (defaults to `document.body`)
|
|
42
|
-
* @returns {Number} Returns numerical representation of pixels
|
|
43
|
-
*/
|
|
44
3
|
function px(val, el) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
4
|
+
if (!val || typeof val === 'number') {
|
|
5
|
+
return val;
|
|
6
|
+
}
|
|
7
|
+
const [num, unit] = parseUnit(val);
|
|
8
|
+
if (unit === 'rem') {
|
|
9
|
+
return num * getFontSize();
|
|
10
|
+
} else if (unit === 'em') {
|
|
11
|
+
const doc = canUseDOM ? document.body : null;
|
|
12
|
+
const container = el || doc;
|
|
13
|
+
return num * getFontSize(container);
|
|
14
|
+
} else {
|
|
15
|
+
return num;
|
|
16
|
+
}
|
|
59
17
|
}
|
|
60
18
|
export default px;
|
|
61
|
-
export { px };
|
|
19
|
+
export { px };
|