@phun-ky/speccer 4.3.1 → 6.0.0
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 +40 -0
- package/dts/browser.d.ts +4 -0
- package/dts/enums/area.d.ts +16 -0
- package/dts/helpers/dissect/index.d.ts +1 -0
- package/dts/helpers/dissect/styles.d.ts +1 -0
- package/dts/helpers/typography/index.d.ts +2 -0
- package/dts/helpers/typography/position.d.ts +4 -0
- package/dts/helpers/typography/template.d.ts +1 -0
- package/dts/index.d.ts +53 -0
- package/dts/interfaces/global.d.ts +6 -0
- package/dts/lib/attributes.d.ts +2 -0
- package/dts/lib/classnames.d.ts +4 -0
- package/dts/lib/constants.d.ts +3 -0
- package/dts/lib/css.d.ts +6 -0
- package/dts/lib/debounce.d.ts +3 -0
- package/dts/lib/node.d.ts +2 -0
- package/dts/lib/number.d.ts +1 -0
- package/dts/lib/position.d.ts +6 -0
- package/dts/lib/resize.d.ts +1 -0
- package/dts/lib/styles.d.ts +2 -0
- package/dts/tasks/dissect.d.ts +2 -0
- package/dts/tasks/index.d.ts +4 -0
- package/dts/tasks/measure.d.ts +1 -0
- package/dts/tasks/spec.d.ts +2 -0
- package/dts/tasks/typography.d.ts +2 -0
- package/dts/types/css.d.ts +19 -0
- package/dts/types/speccer.d.ts +5 -0
- package/package.json +13 -16
- package/speccer.css +16 -19
- package/speccer.js +2 -1
- package/speccer.js.map +1 -0
- package/speccer.min.css +1 -1
- package/src/{browser.js → browser.ts} +30 -21
- package/src/enums/area.ts +17 -0
- package/src/helpers/dissect/index.ts +1 -0
- package/src/helpers/dissect/styles.ts +154 -0
- package/src/helpers/typography/index.ts +3 -0
- package/src/helpers/typography/position.ts +54 -0
- package/src/helpers/typography/template.ts +27 -0
- package/src/{index.js → index.ts} +17 -14
- package/src/interfaces/global.ts +7 -0
- package/src/lib/attributes.ts +18 -0
- package/src/lib/classnames.ts +43 -0
- package/src/lib/{constants.js → constants.ts} +3 -0
- package/src/lib/css.ts +45 -0
- package/src/lib/debounce.ts +29 -0
- package/src/lib/node.ts +8 -0
- package/src/lib/number.ts +4 -0
- package/src/lib/position.ts +16 -0
- package/src/lib/{resize.js → resize.ts} +5 -4
- package/src/lib/styles.ts +31 -0
- package/src/styles/index.styl +4 -0
- package/src/styles/spacing.styl +0 -10
- package/src/styles/typography.styl +11 -12
- package/src/tasks/dissect.ts +46 -0
- package/src/tasks/index.ts +7 -0
- package/src/tasks/measure.ts +82 -0
- package/src/tasks/spec.ts +170 -0
- package/src/tasks/typography.ts +45 -0
- package/src/types/css.ts +20 -0
- package/src/types/speccer.ts +6 -0
- package/tsconfig.json +21 -0
- package/tslint.json +23 -0
- package/src/dissect.js +0 -204
- package/src/lib/attributes.js +0 -13
- package/src/lib/classnames.js +0 -37
- package/src/lib/css.js +0 -37
- package/src/lib/debounce.js +0 -22
- package/src/lib/node.js +0 -7
- package/src/lib/number.js +0 -4
- package/src/lib/styles.js +0 -27
- package/src/measure.js +0 -88
- package/src/spec.js +0 -183
- package/src/typography.js +0 -138
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* eslint no-console:0 */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
export const set = (el: HTMLElement, cls: string, avoid = 'noop') => {
|
|
5
|
+
if (!el) return;
|
|
6
|
+
|
|
7
|
+
if (!cls || (cls && cls.length === 0)) return;
|
|
8
|
+
|
|
9
|
+
cls
|
|
10
|
+
.trim()
|
|
11
|
+
.split(' ')
|
|
12
|
+
.filter((cl) => cl !== avoid)
|
|
13
|
+
.forEach((cl) => el.classList.add(cl));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const toggle = (el: HTMLElement, cls: string, avoid = 'noop') => {
|
|
17
|
+
if (!el) return;
|
|
18
|
+
|
|
19
|
+
if (!cls || (cls && cls.length === 0)) return;
|
|
20
|
+
|
|
21
|
+
cls
|
|
22
|
+
.trim()
|
|
23
|
+
.split(' ')
|
|
24
|
+
.filter((cl) => cl !== avoid)
|
|
25
|
+
.forEach((cl) => el.classList.toggle(cl));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const remove = (el: HTMLElement, cls: string, avoid = 'noop') => {
|
|
29
|
+
if (!el) return;
|
|
30
|
+
|
|
31
|
+
if (!cls || (cls && cls.length === 0)) return;
|
|
32
|
+
|
|
33
|
+
cls
|
|
34
|
+
.trim()
|
|
35
|
+
.split(' ')
|
|
36
|
+
.filter((cl) => cl !== avoid)
|
|
37
|
+
.forEach((cl) => el.classList.remove(cl));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const cx = (cls: string, cls_obj: {}): string =>
|
|
41
|
+
`${cls} ${Object.keys(cls_obj)
|
|
42
|
+
.filter((classname) => cls_obj[classname])
|
|
43
|
+
.join(' ')}`.trim();
|
package/src/lib/css.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* eslint no-console:0 */
|
|
2
|
+
'use strict';
|
|
3
|
+
import { SPECCER_DEFAULT_PIN_SPACE } from './constants';
|
|
4
|
+
import { SpacingCSSPropertiesType, TypographyCSSPropertiesType } from '../types/css';
|
|
5
|
+
|
|
6
|
+
export const getNumberValue = (value: string): number => parseInt(value, 10);
|
|
7
|
+
|
|
8
|
+
export const normalizeNumberValue = (value: string | number): number => {
|
|
9
|
+
const _value = parseFloat(value + '');
|
|
10
|
+
|
|
11
|
+
return (_value >= 0 && _value < 1) || (_value <= 0 && _value > -1) ? 0 : _value;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const getSpacing = (style: SpacingCSSPropertiesType): SpacingCSSPropertiesType => {
|
|
15
|
+
const { marginTop, marginBottom, marginLeft, marginRight, paddingTop, paddingBottom, paddingLeft, paddingRight } =
|
|
16
|
+
style;
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
marginTop,
|
|
20
|
+
marginBottom,
|
|
21
|
+
marginLeft,
|
|
22
|
+
marginRight,
|
|
23
|
+
paddingTop,
|
|
24
|
+
paddingBottom,
|
|
25
|
+
paddingLeft,
|
|
26
|
+
paddingRight
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const getTypography = (style: TypographyCSSPropertiesType): TypographyCSSPropertiesType => {
|
|
31
|
+
const { lineHeight, letterSpacing, fontFamily, fontSize, fontStyle, fontVariationSettings, fontWeight } = style;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
lineHeight,
|
|
35
|
+
letterSpacing,
|
|
36
|
+
fontFamily,
|
|
37
|
+
fontSize,
|
|
38
|
+
fontStyle,
|
|
39
|
+
fontVariationSettings,
|
|
40
|
+
fontWeight
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const pinSpace = (el: HTMLElement): number =>
|
|
45
|
+
getNumberValue(getComputedStyle(el).getPropertyValue('--ph-speccer-pin-space')) || SPECCER_DEFAULT_PIN_SPACE;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint no-console:0 */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
export const waitForFrame = () => new Promise(requestAnimationFrame);
|
|
5
|
+
|
|
6
|
+
const debounce = function (func: Function, wait: number, immediate?: boolean): Function {
|
|
7
|
+
let timeout: null | ReturnType<typeof setTimeout>;
|
|
8
|
+
|
|
9
|
+
return function (this: any) {
|
|
10
|
+
const context = this;
|
|
11
|
+
const args = arguments;
|
|
12
|
+
const later = function () {
|
|
13
|
+
timeout = null;
|
|
14
|
+
|
|
15
|
+
if (!immediate) func.apply(context, args);
|
|
16
|
+
};
|
|
17
|
+
const callNow = immediate && !timeout;
|
|
18
|
+
|
|
19
|
+
if (timeout) {
|
|
20
|
+
clearTimeout(timeout);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
timeout = setTimeout(later, wait);
|
|
24
|
+
|
|
25
|
+
if (callNow) func.apply(context, args);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default debounce;
|
package/src/lib/node.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const after = (el: HTMLElement | null, newSibling: HTMLElement) =>
|
|
2
|
+
el && el.insertAdjacentElement('afterend', newSibling);
|
|
3
|
+
|
|
4
|
+
export const removeAll = (selector: string, el: Document = document) => {
|
|
5
|
+
[].forEach.call(el.querySelectorAll(selector), function (e: HTMLElement) {
|
|
6
|
+
e.remove();
|
|
7
|
+
});
|
|
8
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const get_horizontal_center_of_els = (modifier: number, startRect: DOMRect, targetRect: DOMRect): number =>
|
|
2
|
+
modifier - startRect.width / 2 + targetRect.width / 2;
|
|
3
|
+
|
|
4
|
+
export const get_vertical_center_of_els = (modifier: number, startRect: DOMRect, targetRect: DOMRect): number =>
|
|
5
|
+
modifier - startRect.height / 2 + targetRect.height / 2;
|
|
6
|
+
|
|
7
|
+
export const get_body_correction = () => {
|
|
8
|
+
const _body_style = getComputedStyle(document.body);
|
|
9
|
+
const _body_left_correction = parseInt(_body_style.paddingLeft) + parseInt(_body_style.marginLeft);
|
|
10
|
+
const _body_top_correction = parseInt(_body_style.paddingTop) + parseInt(_body_style.marginTop);
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
top: _body_top_correction,
|
|
14
|
+
left: _body_left_correction
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import debounce from './debounce';
|
|
5
5
|
|
|
6
|
-
export const activate = speccer => {
|
|
7
|
-
const speccerEventFunc =
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export const activate = (speccer: Function) => {
|
|
7
|
+
const speccerEventFunc = () =>
|
|
8
|
+
debounce(() => {
|
|
9
|
+
speccer();
|
|
10
|
+
}, 300);
|
|
10
11
|
|
|
11
12
|
window.removeEventListener('resize', speccerEventFunc);
|
|
12
13
|
window.addEventListener('resize', speccerEventFunc);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* eslint no-console:0 */
|
|
2
|
+
'use strict';
|
|
3
|
+
import { waitForFrame } from './debounce';
|
|
4
|
+
|
|
5
|
+
export const add = async (el: HTMLElement, styles: [] | object) => {
|
|
6
|
+
if (
|
|
7
|
+
!el ||
|
|
8
|
+
!styles ||
|
|
9
|
+
typeof styles === 'string' ||
|
|
10
|
+
typeof styles === 'number' ||
|
|
11
|
+
typeof styles === 'boolean' ||
|
|
12
|
+
(Array.isArray(styles) && styles.length === 0) ||
|
|
13
|
+
(Object.keys(styles).length === 0 && styles.constructor === Object)
|
|
14
|
+
) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
await waitForFrame();
|
|
19
|
+
|
|
20
|
+
if (Array.isArray(styles)) {
|
|
21
|
+
styles.forEach((style: { key: string; value: string }) => (el.style[style.key] = style.value));
|
|
22
|
+
} else {
|
|
23
|
+
Object.keys(styles).forEach((key) => (el.style[key] = styles[key]));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const get = async (el: HTMLElement): Promise<CSSStyleDeclaration> => {
|
|
28
|
+
await waitForFrame();
|
|
29
|
+
|
|
30
|
+
return getComputedStyle(el, null);
|
|
31
|
+
};
|
package/src/styles/index.styl
CHANGED
|
@@ -48,6 +48,10 @@ $ph-speccer-measure-size = 8px
|
|
|
48
48
|
--ph-speccer-line-width-negative: $ph-speccer-line-width-negative;
|
|
49
49
|
--ph-speccer-measure-size: $ph-speccer-measure-size;
|
|
50
50
|
|
|
51
|
+
body.ph
|
|
52
|
+
margin 12px
|
|
53
|
+
padding 12px
|
|
54
|
+
box-sizing border-box
|
|
51
55
|
|
|
52
56
|
.ph.speccer,
|
|
53
57
|
.ph.speccer::after,
|
package/src/styles/spacing.styl
CHANGED
|
@@ -6,16 +6,6 @@
|
|
|
6
6
|
border var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark)
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
.is-specced
|
|
10
|
-
&:hover
|
|
11
|
-
& ~ .ph.speccer.spacing
|
|
12
|
-
&.margin
|
|
13
|
-
background-color var(--ph-speccer-color-margin-hover)
|
|
14
|
-
&.padding
|
|
15
|
-
background-color var(--ph-speccer-color-padding-hover)
|
|
16
|
-
color var(--ph-speccer-color-text-light)
|
|
17
|
-
|
|
18
|
-
|
|
19
9
|
.ph.speccer.spacing
|
|
20
10
|
&.margin
|
|
21
11
|
background-color var(--ph-speccer-color-margin)
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
.ph.speccer.typography
|
|
2
2
|
background-color var(--ph-speccer-typography-background-color)
|
|
3
3
|
color var(--ph-speccer-typography-color-text)
|
|
4
|
-
font-size
|
|
5
|
-
padding 8px
|
|
4
|
+
font-size 10px
|
|
5
|
+
padding 8px
|
|
6
6
|
max-width none
|
|
7
7
|
width auto
|
|
8
8
|
display block
|
|
9
9
|
text-align left
|
|
10
10
|
line-height 140%
|
|
11
11
|
border var(--ph-speccer-line-width) solid var(--ph-speccer-pin-color)
|
|
12
|
-
min-width 320px
|
|
13
12
|
|
|
14
13
|
&:hover
|
|
15
14
|
border var(--ph-speccer-line-width) solid var(--ph-speccer-pin-color)
|
|
@@ -23,7 +22,7 @@
|
|
|
23
22
|
top 50%
|
|
24
23
|
transform translateY(-50%)
|
|
25
24
|
height var(--ph-speccer-line-width)
|
|
26
|
-
width
|
|
25
|
+
width var(--ph-speccer-pin-space)
|
|
27
26
|
|
|
28
27
|
&.left
|
|
29
28
|
&:after
|
|
@@ -31,7 +30,7 @@
|
|
|
31
30
|
top 50%
|
|
32
31
|
transform translateY(-50%)
|
|
33
32
|
height var(--ph-speccer-line-width)
|
|
34
|
-
width
|
|
33
|
+
width var(--ph-speccer-pin-space)
|
|
35
34
|
&.right
|
|
36
35
|
&:after
|
|
37
36
|
left auto
|
|
@@ -39,14 +38,14 @@
|
|
|
39
38
|
top 50%
|
|
40
39
|
transform translateY(-50%)
|
|
41
40
|
height var(--ph-speccer-line-width)
|
|
42
|
-
width
|
|
41
|
+
width var(--ph-speccer-pin-space)
|
|
43
42
|
&.top
|
|
44
43
|
&:after
|
|
45
44
|
left 50%
|
|
46
45
|
right auto
|
|
47
46
|
top 100%
|
|
48
47
|
transform translateX(-50%)
|
|
49
|
-
height
|
|
48
|
+
height var(--ph-speccer-pin-space)
|
|
50
49
|
width var(--ph-speccer-line-width)
|
|
51
50
|
&.bottom
|
|
52
51
|
&:after
|
|
@@ -55,7 +54,7 @@
|
|
|
55
54
|
top auto
|
|
56
55
|
bottom 100%
|
|
57
56
|
transform translateX(-50%)
|
|
58
|
-
height
|
|
57
|
+
height var(--ph-speccer-pin-space)
|
|
59
58
|
width var(--ph-speccer-line-width)
|
|
60
59
|
|
|
61
60
|
& .speccer-styles
|
|
@@ -64,15 +63,15 @@
|
|
|
64
63
|
padding 0
|
|
65
64
|
margin 0
|
|
66
65
|
line-height 140%
|
|
67
|
-
padding-left
|
|
68
|
-
font-size
|
|
66
|
+
padding-left 8px
|
|
67
|
+
font-size 10px
|
|
69
68
|
|
|
70
69
|
& .property
|
|
71
70
|
font-weight normal
|
|
72
71
|
color var(--ph-speccer-typography-color-property)
|
|
73
72
|
text-align left
|
|
74
73
|
padding 0
|
|
75
|
-
font-size
|
|
74
|
+
font-size 10px
|
|
76
75
|
margin 0
|
|
77
76
|
|
|
78
77
|
& > li
|
|
@@ -80,7 +79,7 @@
|
|
|
80
79
|
color var(--ph-speccer-typography-color-value)
|
|
81
80
|
text-align left
|
|
82
81
|
padding 0
|
|
83
|
-
font-size
|
|
82
|
+
font-size 10px
|
|
84
83
|
margin 0
|
|
85
84
|
list-style none
|
|
86
85
|
border none
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
};
|