@phun-ky/speccer 6.0.0 → 6.0.1
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/package.json +7 -1
- package/CHANGELOG.md +0 -78
- package/dts/browser.d.ts +0 -4
- package/dts/enums/area.d.ts +0 -16
- package/dts/helpers/dissect/index.d.ts +0 -1
- package/dts/helpers/dissect/styles.d.ts +0 -1
- package/dts/helpers/typography/index.d.ts +0 -2
- package/dts/helpers/typography/position.d.ts +0 -4
- package/dts/helpers/typography/template.d.ts +0 -1
- package/dts/index.d.ts +0 -53
- package/dts/interfaces/global.d.ts +0 -6
- package/dts/lib/attributes.d.ts +0 -2
- package/dts/lib/classnames.d.ts +0 -4
- package/dts/lib/constants.d.ts +0 -3
- package/dts/lib/css.d.ts +0 -6
- package/dts/lib/debounce.d.ts +0 -3
- package/dts/lib/node.d.ts +0 -2
- package/dts/lib/number.d.ts +0 -1
- package/dts/lib/position.d.ts +0 -6
- package/dts/lib/resize.d.ts +0 -1
- package/dts/lib/styles.d.ts +0 -2
- package/dts/tasks/dissect.d.ts +0 -2
- package/dts/tasks/index.d.ts +0 -4
- package/dts/tasks/measure.d.ts +0 -1
- package/dts/tasks/spec.d.ts +0 -2
- package/dts/tasks/typography.d.ts +0 -2
- package/dts/types/css.d.ts +0 -19
- package/dts/types/speccer.d.ts +0 -5
- package/src/browser.ts +0 -96
- package/src/enums/area.ts +0 -17
- package/src/helpers/dissect/index.ts +0 -1
- package/src/helpers/dissect/styles.ts +0 -154
- package/src/helpers/typography/index.ts +0 -3
- package/src/helpers/typography/position.ts +0 -54
- package/src/helpers/typography/template.ts +0 -27
- package/src/index.ts +0 -36
- package/src/interfaces/global.ts +0 -7
- package/src/lib/attributes.ts +0 -18
- package/src/lib/classnames.ts +0 -43
- package/src/lib/constants.ts +0 -8
- package/src/lib/css.ts +0 -45
- package/src/lib/debounce.ts +0 -29
- package/src/lib/node.ts +0 -8
- package/src/lib/number.ts +0 -4
- package/src/lib/position.ts +0 -16
- package/src/lib/resize.ts +0 -14
- package/src/lib/styles.ts +0 -31
- package/src/styles/anatomy.styl +0 -274
- package/src/styles/index.styl +0 -72
- package/src/styles/measure.styl +0 -88
- package/src/styles/spacing.styl +0 -142
- package/src/styles/typography.styl +0 -85
- package/src/tasks/dissect.ts +0 -46
- package/src/tasks/index.ts +0 -7
- package/src/tasks/measure.ts +0 -82
- package/src/tasks/spec.ts +0 -170
- package/src/tasks/typography.ts +0 -45
- package/src/types/css.ts +0 -20
- package/src/types/speccer.ts +0 -6
- package/tsconfig.json +0 -21
- package/tslint.json +0 -23
package/src/styles/measure.styl
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
.ph.speccer.measure
|
|
2
|
-
&.width
|
|
3
|
-
color var(--ph-speccer-measure-color)
|
|
4
|
-
border var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color)
|
|
5
|
-
border-bottom none
|
|
6
|
-
height var(--ph-speccer-measure-size)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.ph.speccer.measure
|
|
10
|
-
&.width
|
|
11
|
-
&::after
|
|
12
|
-
content attr(data-measure)
|
|
13
|
-
position absolute
|
|
14
|
-
top calc(-100% - 10px)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.ph.speccer.measure
|
|
18
|
-
&.width
|
|
19
|
-
&.bottom
|
|
20
|
-
color var(--ph-speccer-measure-color)
|
|
21
|
-
border var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color)
|
|
22
|
-
border-top none
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.ph.speccer.measure
|
|
26
|
-
&.width
|
|
27
|
-
&.bottom
|
|
28
|
-
&::after
|
|
29
|
-
content attr(data-measure)
|
|
30
|
-
position absolute
|
|
31
|
-
top calc(100% + 5px)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.ph.speccer.measure
|
|
35
|
-
&.width
|
|
36
|
-
&.top
|
|
37
|
-
color var(--ph-speccer-measure-color)
|
|
38
|
-
border var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color)
|
|
39
|
-
border-bottom none
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.ph.speccer.measure
|
|
43
|
-
&.width
|
|
44
|
-
&.top
|
|
45
|
-
&::after
|
|
46
|
-
content attr(data-measure)
|
|
47
|
-
position absolute
|
|
48
|
-
bottom calc(100% + 5px)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.ph.speccer.measure
|
|
52
|
-
&.height
|
|
53
|
-
&.left
|
|
54
|
-
color var(--ph-speccer-measure-color)
|
|
55
|
-
border var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color)
|
|
56
|
-
border-right none
|
|
57
|
-
width var(--ph-speccer-measure-size)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.ph.speccer.measure
|
|
61
|
-
&.height
|
|
62
|
-
&.left
|
|
63
|
-
&::after
|
|
64
|
-
content attr(data-measure)
|
|
65
|
-
position absolute
|
|
66
|
-
top 50%
|
|
67
|
-
left calc(-100% - 20px - var(--ph-speccer-line-width))
|
|
68
|
-
transform translateY(-50%) rotate(-90deg)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.ph.speccer.measure
|
|
72
|
-
&.height
|
|
73
|
-
&.right
|
|
74
|
-
color var(--ph-speccer-measure-color)
|
|
75
|
-
border var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color)
|
|
76
|
-
border-left none
|
|
77
|
-
width var(--ph-speccer-measure-size)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.ph.speccer.measure
|
|
81
|
-
&.height
|
|
82
|
-
&.right
|
|
83
|
-
&::after
|
|
84
|
-
content attr(data-measure)
|
|
85
|
-
position absolute
|
|
86
|
-
top 50%
|
|
87
|
-
left calc(100% - var(--ph-speccer-measure-size))
|
|
88
|
-
transform translateY(-50%) rotate(90deg)
|
package/src/styles/spacing.styl
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
.ph.speccer.spacing
|
|
2
|
-
pointer-events auto
|
|
3
|
-
transition none
|
|
4
|
-
border var(--ph-speccer-line-width) solid transparent
|
|
5
|
-
&:hover
|
|
6
|
-
border var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.ph.speccer.spacing
|
|
10
|
-
&.margin
|
|
11
|
-
background-color var(--ph-speccer-color-margin)
|
|
12
|
-
color var(--ph-speccer-color-text-dark)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
.ph.speccer.spacing
|
|
16
|
-
&.padding
|
|
17
|
-
background-color var(--ph-speccer-color-padding)
|
|
18
|
-
color var(--ph-speccer-spacing-color)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
.ph.speccer.spacing
|
|
22
|
-
&.margin
|
|
23
|
-
&.bottom,
|
|
24
|
-
&.top
|
|
25
|
-
&::after
|
|
26
|
-
transition none
|
|
27
|
-
content ""
|
|
28
|
-
position absolute
|
|
29
|
-
height 100%
|
|
30
|
-
border-top var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark)
|
|
31
|
-
border-bottom var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark)
|
|
32
|
-
width 9px
|
|
33
|
-
left 40%
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.ph.speccer.spacing
|
|
37
|
-
&.margin
|
|
38
|
-
&.bottom,
|
|
39
|
-
&.top
|
|
40
|
-
&::before
|
|
41
|
-
transition none
|
|
42
|
-
content ""
|
|
43
|
-
position absolute
|
|
44
|
-
height 100%
|
|
45
|
-
border-left var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark)
|
|
46
|
-
margin-left 4px
|
|
47
|
-
width 0
|
|
48
|
-
left 40%
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.ph.speccer.spacing
|
|
52
|
-
&.margin
|
|
53
|
-
&.left,
|
|
54
|
-
&.right
|
|
55
|
-
&::after
|
|
56
|
-
transition none
|
|
57
|
-
content ""
|
|
58
|
-
position absolute
|
|
59
|
-
height 9px
|
|
60
|
-
border-right var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark)
|
|
61
|
-
border-left var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark)
|
|
62
|
-
width 100%
|
|
63
|
-
top 10%
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.ph.speccer.spacing
|
|
67
|
-
&.margin
|
|
68
|
-
&.left,
|
|
69
|
-
&.right
|
|
70
|
-
&::before
|
|
71
|
-
transition none
|
|
72
|
-
content ""
|
|
73
|
-
position absolute
|
|
74
|
-
height 0
|
|
75
|
-
border-top var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark)
|
|
76
|
-
margin-top 4px
|
|
77
|
-
width 100%
|
|
78
|
-
top 10%
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
.ph.speccer.spacing
|
|
82
|
-
&.padding
|
|
83
|
-
&.bottom,
|
|
84
|
-
&.top
|
|
85
|
-
&::after
|
|
86
|
-
transition none
|
|
87
|
-
content ""
|
|
88
|
-
position absolute
|
|
89
|
-
height 100%
|
|
90
|
-
border-top var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color)
|
|
91
|
-
border-bottom var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color)
|
|
92
|
-
width 9px
|
|
93
|
-
left 40%
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
.ph.speccer.spacing
|
|
97
|
-
&.padding
|
|
98
|
-
&.bottom,
|
|
99
|
-
&.top
|
|
100
|
-
&::before
|
|
101
|
-
transition none
|
|
102
|
-
content ""
|
|
103
|
-
position absolute
|
|
104
|
-
height 100%
|
|
105
|
-
border-left var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color)
|
|
106
|
-
margin-left 4px
|
|
107
|
-
width 0
|
|
108
|
-
left 40%
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
.ph.speccer.spacing
|
|
112
|
-
&.padding
|
|
113
|
-
&.left,
|
|
114
|
-
&.right
|
|
115
|
-
&::after
|
|
116
|
-
transition none
|
|
117
|
-
content ""
|
|
118
|
-
position absolute
|
|
119
|
-
height 9px
|
|
120
|
-
border-right var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color)
|
|
121
|
-
border-left var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color)
|
|
122
|
-
width 100%
|
|
123
|
-
top 10%
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
.ph.speccer.spacing
|
|
127
|
-
&.padding
|
|
128
|
-
&.left,
|
|
129
|
-
&.right
|
|
130
|
-
&::before
|
|
131
|
-
transition none
|
|
132
|
-
content ""
|
|
133
|
-
position absolute
|
|
134
|
-
height 0
|
|
135
|
-
border-top var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color)
|
|
136
|
-
margin-top 4px
|
|
137
|
-
width 100%
|
|
138
|
-
top 10%
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
@require './typography.styl'
|
|
142
|
-
@require './measure.styl'
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
.ph.speccer.typography
|
|
2
|
-
background-color var(--ph-speccer-typography-background-color)
|
|
3
|
-
color var(--ph-speccer-typography-color-text)
|
|
4
|
-
font-size 10px
|
|
5
|
-
padding 8px
|
|
6
|
-
max-width none
|
|
7
|
-
width auto
|
|
8
|
-
display block
|
|
9
|
-
text-align left
|
|
10
|
-
line-height 140%
|
|
11
|
-
border var(--ph-speccer-line-width) solid var(--ph-speccer-pin-color)
|
|
12
|
-
|
|
13
|
-
&:hover
|
|
14
|
-
border var(--ph-speccer-line-width) solid var(--ph-speccer-pin-color)
|
|
15
|
-
|
|
16
|
-
&:after
|
|
17
|
-
content ""
|
|
18
|
-
position absolute
|
|
19
|
-
display block
|
|
20
|
-
background-color var(--ph-speccer-pin-color)
|
|
21
|
-
left 100%
|
|
22
|
-
top 50%
|
|
23
|
-
transform translateY(-50%)
|
|
24
|
-
height var(--ph-speccer-line-width)
|
|
25
|
-
width var(--ph-speccer-pin-space)
|
|
26
|
-
|
|
27
|
-
&.left
|
|
28
|
-
&:after
|
|
29
|
-
left 100%
|
|
30
|
-
top 50%
|
|
31
|
-
transform translateY(-50%)
|
|
32
|
-
height var(--ph-speccer-line-width)
|
|
33
|
-
width var(--ph-speccer-pin-space)
|
|
34
|
-
&.right
|
|
35
|
-
&:after
|
|
36
|
-
left auto
|
|
37
|
-
right 100%
|
|
38
|
-
top 50%
|
|
39
|
-
transform translateY(-50%)
|
|
40
|
-
height var(--ph-speccer-line-width)
|
|
41
|
-
width var(--ph-speccer-pin-space)
|
|
42
|
-
&.top
|
|
43
|
-
&:after
|
|
44
|
-
left 50%
|
|
45
|
-
right auto
|
|
46
|
-
top 100%
|
|
47
|
-
transform translateX(-50%)
|
|
48
|
-
height var(--ph-speccer-pin-space)
|
|
49
|
-
width var(--ph-speccer-line-width)
|
|
50
|
-
&.bottom
|
|
51
|
-
&:after
|
|
52
|
-
left 50%
|
|
53
|
-
right auto
|
|
54
|
-
top auto
|
|
55
|
-
bottom 100%
|
|
56
|
-
transform translateX(-50%)
|
|
57
|
-
height var(--ph-speccer-pin-space)
|
|
58
|
-
width var(--ph-speccer-line-width)
|
|
59
|
-
|
|
60
|
-
& .speccer-styles
|
|
61
|
-
list-style none
|
|
62
|
-
width 100%
|
|
63
|
-
padding 0
|
|
64
|
-
margin 0
|
|
65
|
-
line-height 140%
|
|
66
|
-
padding-left 8px
|
|
67
|
-
font-size 10px
|
|
68
|
-
|
|
69
|
-
& .property
|
|
70
|
-
font-weight normal
|
|
71
|
-
color var(--ph-speccer-typography-color-property)
|
|
72
|
-
text-align left
|
|
73
|
-
padding 0
|
|
74
|
-
font-size 10px
|
|
75
|
-
margin 0
|
|
76
|
-
|
|
77
|
-
& > li
|
|
78
|
-
font-weight normal
|
|
79
|
-
color var(--ph-speccer-typography-color-value)
|
|
80
|
-
text-align left
|
|
81
|
-
padding 0
|
|
82
|
-
font-size 10px
|
|
83
|
-
margin 0
|
|
84
|
-
list-style none
|
|
85
|
-
border none
|
package/src/tasks/dissect.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/* eslint no-console:0 */
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
import * as styles from '../lib/styles';
|
|
5
|
-
import * as classnames from '../lib/classnames';
|
|
6
|
-
import { DissectAreaEnum } from '../enums/area';
|
|
7
|
-
import * as helpers from '../helpers/dissect';
|
|
8
|
-
import { SPECCER_LITERALS } from '../lib/constants';
|
|
9
|
-
|
|
10
|
-
export const create = (textContent = '', area: string, n = 'span') => {
|
|
11
|
-
const _el = document.createElement(n);
|
|
12
|
-
const _text_node = document.createTextNode(textContent);
|
|
13
|
-
const _extra_class_names = {};
|
|
14
|
-
|
|
15
|
-
if (area !== null && area !== '') {
|
|
16
|
-
_extra_class_names[area] = true;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (area.indexOf(DissectAreaEnum.Full) === -1 && area.indexOf(DissectAreaEnum.Enclose) === -1) {
|
|
20
|
-
_el.appendChild(_text_node);
|
|
21
|
-
} else if (area.indexOf(DissectAreaEnum.Full) !== -1 || area.indexOf(DissectAreaEnum.Enclose) !== -1) {
|
|
22
|
-
_el.setAttribute('data-dissection-counter', textContent);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const _class_names = classnames.cx('ph speccer dissection', _extra_class_names);
|
|
26
|
-
|
|
27
|
-
classnames.set(_el, _class_names);
|
|
28
|
-
|
|
29
|
-
return _el;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const element = async (el: HTMLElement, dissectIndex: number) => {
|
|
33
|
-
if (!el) return;
|
|
34
|
-
|
|
35
|
-
const _area: string | null = el.getAttribute('data-anatomy') || '';
|
|
36
|
-
|
|
37
|
-
if (!_area || _area === '') return;
|
|
38
|
-
|
|
39
|
-
const _dissection_el = create(SPECCER_LITERALS[dissectIndex], _area);
|
|
40
|
-
|
|
41
|
-
document.body.appendChild(_dissection_el);
|
|
42
|
-
|
|
43
|
-
const _dissection_styles = helpers.styles(_area, el, _dissection_el);
|
|
44
|
-
|
|
45
|
-
styles.add(_dissection_el, _dissection_styles);
|
|
46
|
-
};
|
package/src/tasks/index.ts
DELETED
package/src/tasks/measure.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/* eslint no-console:0 */
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
import * as classnames from '../lib/classnames';
|
|
5
|
-
import * as styles from '../lib/styles';
|
|
6
|
-
import { get_body_correction } from '../lib/position';
|
|
7
|
-
|
|
8
|
-
const create = (text: string | number = '', area: string | null = '', tag = 'span') => {
|
|
9
|
-
const _el = document.createElement(tag);
|
|
10
|
-
|
|
11
|
-
_el.setAttribute('title', text + 'px');
|
|
12
|
-
_el.setAttribute('data-measure', parseInt(text + '', 10) + 'px');
|
|
13
|
-
|
|
14
|
-
classnames.set(_el, `ph speccer measure ${area}`);
|
|
15
|
-
|
|
16
|
-
return _el;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const element = (el: HTMLElement) => {
|
|
20
|
-
if (!el) return;
|
|
21
|
-
|
|
22
|
-
const _el_rect = el.getBoundingClientRect();
|
|
23
|
-
const _area: string | null = el.getAttribute('data-speccer-measure');
|
|
24
|
-
|
|
25
|
-
if (_area === '' || !_area) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const _body_correction = get_body_correction();
|
|
30
|
-
const _el_offset_top = el.offsetTop + _body_correction.top;
|
|
31
|
-
const _el_offset_left = el.offsetLeft + _body_correction.left;
|
|
32
|
-
|
|
33
|
-
if (_area.indexOf('width') !== -1) {
|
|
34
|
-
if (_area.indexOf('bottom') !== -1) {
|
|
35
|
-
const _measure_el = create(_el_rect.width, 'width bottom');
|
|
36
|
-
|
|
37
|
-
document.body.appendChild(_measure_el);
|
|
38
|
-
|
|
39
|
-
styles.add(_measure_el, {
|
|
40
|
-
left: _el_offset_left + 'px',
|
|
41
|
-
top: _el_offset_top + _el_rect.height + 1 + 'px',
|
|
42
|
-
width: _el_rect.width + 'px'
|
|
43
|
-
});
|
|
44
|
-
} else {
|
|
45
|
-
const _measure_el = create(_el_rect.width, 'width top');
|
|
46
|
-
|
|
47
|
-
document.body.appendChild(_measure_el);
|
|
48
|
-
|
|
49
|
-
const _measure_rect = _measure_el.getBoundingClientRect();
|
|
50
|
-
|
|
51
|
-
styles.add(_measure_el, {
|
|
52
|
-
left: _el_offset_left + 'px',
|
|
53
|
-
top: _el_offset_top - _measure_rect.height + 1 + 'px',
|
|
54
|
-
width: _el_rect.width + 'px'
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
} else if (_area.indexOf('height') !== -1) {
|
|
58
|
-
if (_area.indexOf('right') !== -1) {
|
|
59
|
-
const _measure_el = create(_el_rect.height, 'height right');
|
|
60
|
-
|
|
61
|
-
document.body.appendChild(_measure_el);
|
|
62
|
-
|
|
63
|
-
styles.add(_measure_el, {
|
|
64
|
-
left: _el_offset_left + _el_rect.width + 'px',
|
|
65
|
-
top: _el_offset_top + 'px',
|
|
66
|
-
height: _el_rect.height + 'px'
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
const _measure_el = create(_el_rect.height, 'height left');
|
|
70
|
-
|
|
71
|
-
document.body.appendChild(_measure_el);
|
|
72
|
-
|
|
73
|
-
const _measure_rect = _measure_el.getBoundingClientRect();
|
|
74
|
-
|
|
75
|
-
styles.add(_measure_el, {
|
|
76
|
-
left: _el_offset_left - _measure_rect.width + 'px',
|
|
77
|
-
top: _el_offset_top + 'px',
|
|
78
|
-
height: _el_rect.height + 'px'
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
package/src/tasks/spec.ts
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/* eslint no-console:0 */
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
import * as classnames from '../lib/classnames';
|
|
5
|
-
import * as css from '../lib/css';
|
|
6
|
-
import * as styles from '../lib/styles';
|
|
7
|
-
import { get_body_correction } from '../lib/position';
|
|
8
|
-
import { SpeccerElType } from '../types/speccer';
|
|
9
|
-
|
|
10
|
-
export const create = (text: string | number = '', tag = 'span') => {
|
|
11
|
-
const _el = document.createElement(tag);
|
|
12
|
-
const _text_content = document.createTextNode(text + '');
|
|
13
|
-
|
|
14
|
-
_el.appendChild(_text_content);
|
|
15
|
-
_el.setAttribute('title', text + 'px');
|
|
16
|
-
classnames.set(_el, 'ph speccer spacing');
|
|
17
|
-
|
|
18
|
-
return _el;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const element = async (el: HTMLElement) => {
|
|
22
|
-
const _speccer_el: SpeccerElType = {};
|
|
23
|
-
const _el_style = await styles.get(el);
|
|
24
|
-
|
|
25
|
-
if (_el_style.display === 'none' || _el_style.visibility === 'hidden' || !el.parentElement) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
el.classList.add('is-specced');
|
|
30
|
-
|
|
31
|
-
_speccer_el.styles = css.getSpacing(_el_style);
|
|
32
|
-
|
|
33
|
-
const _target_rect = el.getBoundingClientRect();
|
|
34
|
-
const _body_correction = get_body_correction();
|
|
35
|
-
const _el_offset_top = el.offsetTop + _body_correction.top;
|
|
36
|
-
const _el_offset_left = el.offsetLeft + _body_correction.left;
|
|
37
|
-
|
|
38
|
-
if (_speccer_el.styles['marginTop'] !== '0px') {
|
|
39
|
-
const _speccer_margin_top_el = create(css.getNumberValue(_speccer_el.styles.marginTop));
|
|
40
|
-
|
|
41
|
-
document.body.appendChild(_speccer_margin_top_el);
|
|
42
|
-
|
|
43
|
-
classnames.set(_speccer_margin_top_el, 'margin top');
|
|
44
|
-
styles.add(_speccer_margin_top_el, {
|
|
45
|
-
height: _speccer_el.styles.marginTop,
|
|
46
|
-
width: _target_rect.width + 'px',
|
|
47
|
-
transform: el.style.transform,
|
|
48
|
-
left: _el_offset_left + 'px',
|
|
49
|
-
top: _el_offset_top - parseInt(_speccer_el.styles.marginTop, 10) + 'px'
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (_speccer_el.styles['marginRight'] !== '0px') {
|
|
54
|
-
const _speccer_margin_right_el = create(css.getNumberValue(_speccer_el.styles.marginRight));
|
|
55
|
-
|
|
56
|
-
classnames.set(_speccer_margin_right_el, 'margin right');
|
|
57
|
-
|
|
58
|
-
styles.add(_speccer_margin_right_el, {
|
|
59
|
-
height: _target_rect.height + 'px',
|
|
60
|
-
width: _speccer_el.styles.marginRight,
|
|
61
|
-
transform: el.style.transform,
|
|
62
|
-
left: _el_offset_left + parseInt(_target_rect.width + '', 10) + 'px',
|
|
63
|
-
top: _el_offset_top + 'px'
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
document.body.appendChild(_speccer_margin_right_el);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (_speccer_el.styles['marginBottom'] !== '0px') {
|
|
70
|
-
const _speccer_margin_bottom_el = create(css.getNumberValue(_speccer_el.styles.marginBottom));
|
|
71
|
-
|
|
72
|
-
classnames.set(_speccer_margin_bottom_el, 'margin bottom');
|
|
73
|
-
|
|
74
|
-
styles.add(_speccer_margin_bottom_el, {
|
|
75
|
-
height: _speccer_el.styles.marginBottom,
|
|
76
|
-
width: _target_rect.width + 'px',
|
|
77
|
-
transform: el.style.transform,
|
|
78
|
-
left: _el_offset_left + 'px',
|
|
79
|
-
top: _el_offset_top + parseInt(_target_rect.height + '', 10) + 'px'
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
document.body.appendChild(_speccer_margin_bottom_el);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (_speccer_el.styles['marginLeft'] !== '0px') {
|
|
86
|
-
const _speccer_margin_left_el = create(css.getNumberValue(_speccer_el.styles.marginLeft));
|
|
87
|
-
|
|
88
|
-
classnames.set(_speccer_margin_left_el, 'margin left');
|
|
89
|
-
|
|
90
|
-
styles.add(_speccer_margin_left_el, {
|
|
91
|
-
height: _target_rect.height + 'px',
|
|
92
|
-
width: _speccer_el.styles.marginLeft,
|
|
93
|
-
transform: el.style.transform,
|
|
94
|
-
left: _el_offset_left - parseInt(_speccer_el.styles.marginLeft, 10) + 'px',
|
|
95
|
-
top: _el_offset_top + 'px'
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
document.body.appendChild(_speccer_margin_left_el);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (_speccer_el.styles['paddingTop'] !== '0px') {
|
|
102
|
-
const _speccer_padding_top_el = create(css.getNumberValue(_speccer_el.styles.paddingTop));
|
|
103
|
-
|
|
104
|
-
classnames.set(_speccer_padding_top_el, 'padding top');
|
|
105
|
-
|
|
106
|
-
styles.add(_speccer_padding_top_el, {
|
|
107
|
-
height: _speccer_el.styles.paddingTop,
|
|
108
|
-
width: _target_rect.width + 'px',
|
|
109
|
-
transform: el.style.transform,
|
|
110
|
-
left: _el_offset_left + 'px',
|
|
111
|
-
top: _el_offset_top + 'px'
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
document.body.appendChild(_speccer_padding_top_el);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (_speccer_el.styles['paddingBottom'] !== '0px') {
|
|
118
|
-
const _speccer_padding_bottom_el = create(css.getNumberValue(_speccer_el.styles.paddingBottom));
|
|
119
|
-
|
|
120
|
-
classnames.set(_speccer_padding_bottom_el, 'padding bottom');
|
|
121
|
-
|
|
122
|
-
styles.add(_speccer_padding_bottom_el, {
|
|
123
|
-
height: _speccer_el.styles.paddingBottom,
|
|
124
|
-
width: _target_rect.width + 'px',
|
|
125
|
-
transform: el.style.transform,
|
|
126
|
-
left: _el_offset_left + 'px',
|
|
127
|
-
top:
|
|
128
|
-
_el_offset_top +
|
|
129
|
-
(parseInt(_target_rect.height + '', 10) - parseInt(_speccer_el.styles.paddingBottom, 10)) +
|
|
130
|
-
'px'
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
document.body.appendChild(_speccer_padding_bottom_el);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (_speccer_el.styles['paddingRight'] !== '0px') {
|
|
137
|
-
const _speccer_padding_right_el = create(css.getNumberValue(_speccer_el.styles.paddingRight));
|
|
138
|
-
|
|
139
|
-
classnames.set(_speccer_padding_right_el, 'padding right');
|
|
140
|
-
|
|
141
|
-
styles.add(_speccer_padding_right_el, {
|
|
142
|
-
height: _target_rect.height + 'px',
|
|
143
|
-
width: _speccer_el.styles.paddingRight,
|
|
144
|
-
transform: el.style.transform,
|
|
145
|
-
left:
|
|
146
|
-
_el_offset_left +
|
|
147
|
-
(parseInt(_target_rect.width + '', 10) - parseInt(_speccer_el.styles.paddingRight, 10)) +
|
|
148
|
-
'px',
|
|
149
|
-
top: _el_offset_top + 'px'
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
document.body.appendChild(_speccer_padding_right_el);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (_speccer_el.styles['paddingLeft'] !== '0px') {
|
|
156
|
-
const _speccer_padding_left_el = create(css.getNumberValue(_speccer_el.styles.paddingLeft));
|
|
157
|
-
|
|
158
|
-
classnames.set(_speccer_padding_left_el, 'padding left');
|
|
159
|
-
|
|
160
|
-
styles.add(_speccer_padding_left_el, {
|
|
161
|
-
height: _target_rect.height + 'px',
|
|
162
|
-
width: _speccer_el.styles.paddingLeft,
|
|
163
|
-
transform: el.style.transform,
|
|
164
|
-
left: _el_offset_left + 'px',
|
|
165
|
-
top: _el_offset_top + 'px'
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
document.body.appendChild(_speccer_padding_left_el);
|
|
169
|
-
}
|
|
170
|
-
};
|
package/src/tasks/typography.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/* eslint no-console:0 */
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
import * as classnames from '../lib/classnames';
|
|
5
|
-
import * as styles from '../lib/styles';
|
|
6
|
-
import * as helpers from '../helpers/typography';
|
|
7
|
-
|
|
8
|
-
export const create = (html: string, area: string | null) => {
|
|
9
|
-
const _el = document.createElement('div');
|
|
10
|
-
const _extra_class_names = {};
|
|
11
|
-
|
|
12
|
-
if (area !== null && area !== '') {
|
|
13
|
-
_extra_class_names[area] = true;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const _class_names = classnames.cx('ph speccer typography', _extra_class_names);
|
|
17
|
-
|
|
18
|
-
_el.innerHTML = html;
|
|
19
|
-
|
|
20
|
-
classnames.set(_el, _class_names);
|
|
21
|
-
|
|
22
|
-
return _el;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const element = async (el: HTMLElement) => {
|
|
26
|
-
if (!el) return;
|
|
27
|
-
|
|
28
|
-
const _area: string | null = el.getAttribute('data-speccer-typography');
|
|
29
|
-
const _el_style = await styles.get(el);
|
|
30
|
-
|
|
31
|
-
if (_el_style.display === 'none' || _el_style.visibility === 'hidden' || !el.parentElement) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
el.classList.add('is-specced');
|
|
36
|
-
|
|
37
|
-
const _html = await helpers.template(el);
|
|
38
|
-
const _speccer_el = create(_html, _area);
|
|
39
|
-
|
|
40
|
-
document.body.appendChild(_speccer_el);
|
|
41
|
-
|
|
42
|
-
const _position = helpers.position(_area, el, _speccer_el);
|
|
43
|
-
|
|
44
|
-
styles.add(_speccer_el, _position);
|
|
45
|
-
};
|
package/src/types/css.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type SpacingCSSPropertiesType = {
|
|
2
|
-
marginTop: string;
|
|
3
|
-
marginBottom: string;
|
|
4
|
-
marginLeft: string;
|
|
5
|
-
marginRight: string;
|
|
6
|
-
paddingTop: string;
|
|
7
|
-
paddingBottom: string;
|
|
8
|
-
paddingLeft: string;
|
|
9
|
-
paddingRight: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type TypographyCSSPropertiesType = {
|
|
13
|
-
lineHeight: string;
|
|
14
|
-
letterSpacing: string;
|
|
15
|
-
fontFamily: string;
|
|
16
|
-
fontSize: string;
|
|
17
|
-
fontStyle: string;
|
|
18
|
-
fontVariationSettings: string;
|
|
19
|
-
fontWeight: string;
|
|
20
|
-
};
|