@phun-ky/speccer 5.0.0 → 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 +19 -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 +10 -3
- 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} +16 -13
- 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 -17
- 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 -211
- 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 -99
- package/src/spec.js +0 -214
- package/src/typography.js +0 -141
package/src/typography.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/* eslint no-console:0 */
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
import * as classnames from './lib/classnames';
|
|
5
|
-
import * as number from './lib/number';
|
|
6
|
-
import * as styles from './lib/styles';
|
|
7
|
-
import * as node from './lib/node';
|
|
8
|
-
import * as css from './lib/css';
|
|
9
|
-
import { SPECCER_TAGS_TO_AVOID } from './lib/constants';
|
|
10
|
-
|
|
11
|
-
export const create = (html, area) => {
|
|
12
|
-
const _el = document.createElement('div');
|
|
13
|
-
|
|
14
|
-
_el.innerHTML = html;
|
|
15
|
-
|
|
16
|
-
classnames.set(_el, `ph speccer typography ${area}`);
|
|
17
|
-
|
|
18
|
-
return _el;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const element = async (el) => {
|
|
22
|
-
const _area = el.getAttribute('data-speccer-typography');
|
|
23
|
-
const _el_style = await styles.get(el);
|
|
24
|
-
|
|
25
|
-
if (_el_style.display === 'none' || _el_style.visibility === 'hidden') {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
el.classList.add('is-specced');
|
|
30
|
-
|
|
31
|
-
const _parent_style = styles.get(el.parentElement);
|
|
32
|
-
|
|
33
|
-
if (_parent_style.position === 'static') {
|
|
34
|
-
window.requestAnimationFrame(() => {
|
|
35
|
-
el.parentElement.style.position = 'relative';
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const _styles = css.getTypography(_el_style);
|
|
40
|
-
const _el_rect = el.getBoundingClientRect();
|
|
41
|
-
const html =
|
|
42
|
-
`
|
|
43
|
-
` +
|
|
44
|
-
'font-styles: {' +
|
|
45
|
-
'<ul class="speccer-styles">' +
|
|
46
|
-
` <li><span class="property">font-family:</span> ${_styles['fontFamily']};</li>` +
|
|
47
|
-
` <li><span class="property">font-size:</span> ${_styles['fontSize']} / ${
|
|
48
|
-
parseInt(_styles['fontSize'], 10) / 16
|
|
49
|
-
}rem;</li>` +
|
|
50
|
-
` <li><span class="property">font-weight:</span> ${_styles['fontWeight']};</li>` +
|
|
51
|
-
` <li><span class="property">font-variation-settings:</span> ${_styles['fontVariationSettings']};</li>` +
|
|
52
|
-
` <li><span class="property">line-height:</span> ${_styles['lineHeight']} / ${
|
|
53
|
-
parseInt(_styles['lineHeight'], 10) / 16
|
|
54
|
-
}rem;</li>` +
|
|
55
|
-
` <li><span class="property">letter-spacing:</span> ${_styles['letterSpacing']};</li>` +
|
|
56
|
-
` <li><span class="property">font-style:</span> ${_styles['fontStyle']};</li>` +
|
|
57
|
-
'</ul>' +
|
|
58
|
-
'}';
|
|
59
|
-
const speccerNode = create(html, _area);
|
|
60
|
-
|
|
61
|
-
let tableCorrectionTop = 0;
|
|
62
|
-
let tableCorrectionLeft = 0;
|
|
63
|
-
|
|
64
|
-
const tableCorrection = SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0;
|
|
65
|
-
|
|
66
|
-
if (tableCorrection) {
|
|
67
|
-
const table = el.parentElement;
|
|
68
|
-
const tableStyle = window.getComputedStyle(table.parentElement);
|
|
69
|
-
|
|
70
|
-
node.after(table, speccerNode);
|
|
71
|
-
tableCorrectionTop = table.getBoundingClientRect().top - parseInt(tableStyle.getPropertyValue('padding-top'), 10);
|
|
72
|
-
tableCorrectionLeft =
|
|
73
|
-
table.getBoundingClientRect().left - parseInt(tableStyle.getPropertyValue('padding-left'), 10);
|
|
74
|
-
} else {
|
|
75
|
-
node.after(el, speccerNode);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const rectOfSpeccerNode = speccerNode.getBoundingClientRect();
|
|
79
|
-
const outlineLeftLeft =
|
|
80
|
-
(tableCorrection ? rectOfSpeccerNode.left - tableCorrectionLeft : el.offsetLeft) -
|
|
81
|
-
rectOfSpeccerNode.width -
|
|
82
|
-
48 +
|
|
83
|
-
'px';
|
|
84
|
-
const outlineLeftTop =
|
|
85
|
-
number.to3Decimals(
|
|
86
|
-
(tableCorrection ? rectOfSpeccerNode.top - tableCorrectionTop : el.offsetTop) -
|
|
87
|
-
rectOfSpeccerNode.height / 2 +
|
|
88
|
-
_el_rect.height / 2
|
|
89
|
-
) + 'px';
|
|
90
|
-
const outlineRightLeft =
|
|
91
|
-
(tableCorrection ? rectOfSpeccerNode.left - tableCorrectionLeft : el.offsetLeft) + _el_rect.width + 48 + 'px';
|
|
92
|
-
const outlineRightTop =
|
|
93
|
-
number.to3Decimals(
|
|
94
|
-
(tableCorrection ? rectOfSpeccerNode.top - tableCorrectionTop : el.offsetTop) -
|
|
95
|
-
rectOfSpeccerNode.height / 2 +
|
|
96
|
-
_el_rect.height / 2
|
|
97
|
-
) + 'px';
|
|
98
|
-
const outlineTopLeft =
|
|
99
|
-
number.to3Decimals(
|
|
100
|
-
(tableCorrection ? rectOfSpeccerNode.left - tableCorrectionLeft : el.offsetLeft) -
|
|
101
|
-
rectOfSpeccerNode.width / 2 +
|
|
102
|
-
_el_rect.width / 2
|
|
103
|
-
) + 'px';
|
|
104
|
-
const outlineTopTop =
|
|
105
|
-
(tableCorrection ? rectOfSpeccerNode.top - tableCorrectionTop : el.offsetTop) -
|
|
106
|
-
rectOfSpeccerNode.height -
|
|
107
|
-
48 +
|
|
108
|
-
'px';
|
|
109
|
-
const outlineBottomleft =
|
|
110
|
-
number.to3Decimals(
|
|
111
|
-
(tableCorrection ? rectOfSpeccerNode.left - tableCorrectionLeft : el.offsetLeft) -
|
|
112
|
-
rectOfSpeccerNode.width / 2 +
|
|
113
|
-
_el_rect.width / 2
|
|
114
|
-
) + 'px';
|
|
115
|
-
const outlineBottomTop =
|
|
116
|
-
(tableCorrection ? rectOfSpeccerNode.top - tableCorrectionTop : el.offsetTop) + _el_rect.height + 48 + 'px';
|
|
117
|
-
|
|
118
|
-
let position = {
|
|
119
|
-
left: outlineLeftLeft,
|
|
120
|
-
top: outlineLeftTop
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
if (_area.indexOf('right') !== -1) {
|
|
124
|
-
position = {
|
|
125
|
-
left: outlineRightLeft,
|
|
126
|
-
top: outlineRightTop
|
|
127
|
-
};
|
|
128
|
-
} else if (_area.indexOf('top') !== -1) {
|
|
129
|
-
position = {
|
|
130
|
-
left: outlineTopLeft,
|
|
131
|
-
top: outlineTopTop
|
|
132
|
-
};
|
|
133
|
-
} else if (_area.indexOf('bottom') !== -1) {
|
|
134
|
-
position = {
|
|
135
|
-
left: outlineBottomleft,
|
|
136
|
-
top: outlineBottomTop
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
styles.add(speccerNode, position);
|
|
141
|
-
};
|