-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathcss-units.ts
79 lines (62 loc) · 2.22 KB
/
css-units.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
75
76
77
78
79
/// <reference path="../requirements.ts" />
interface ModuleHub { (file: 'core:css-units'): CSSUnits.CSSUnitsModule; }
module CSSUnits {
/**
* Provides a basic css unit converter.
*/
export interface CSSUnitsModule extends Object {
/**
* Converts "cssLength" from its inherent unit to pixels, and returns the result as a float
*
* @param cssLength A string representing the value to convert
* @param element The element from which the relative values will be computed (default: the root element)
* @param opts Additionnal options such as "boxType" and "isHeightRelated" (default: border-box & isWidthRelated).
*/
convertToPixels(
cssLength : string,
element? : HTMLElement,
opts? : PixelConvertOptions
)
: number
/**
* Converts "pixelLength" from pixels to "destinUnit", and returns the result as a float
*
* @param pixelLength A string representing the value to convert
* @param destinUnit A string value representing the unit name
* @param element The element from which the relative values will be computed (default: the root element)
* @param opts Additionnal options such as "boxType" and "isHeightRelated" (default: border-box & isWidthRelated).
*/
convertFromPixels(
pixelLength : number,
destinUnit : string,
element? : HTMLElement,
opts? : PixelConvertOptions
)
: number
}
export interface PixelConvertOptions {
boxType?: string
isWidthRelated?: boolean
isHeightRelated?: boolean
isRadiusRelated?: boolean
}
}
/////////////////////////////////////////////////////////////////////////
//// EXAMPLES ///////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
/** How do you convert a value to pixels ? */
function convert_value_to_pixels() {
var cssUnits = require('core:css-units');
return cssUnits.convertToPixels("33%", document.body, {
boxType: "content-box",
isHeightRelated: true
});
}
/** How do you convert a value from pixels ? */
function convert_value_from_pixels() {
var cssUnits = require('core:css-units');
return cssUnits.convertFromPixels(550/*px*/, /*to*/"em", document.body, {
boxType: "content-box",
isHeightRelated: true
});
}