matchheight 0.1.2 → 0.2.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/dist/MatchHeight.d.ts +5 -0
- package/dist/MatchHeight.js +74 -101
- package/dist/MatchHeight.min.js +1 -1
- package/dist/MatchHeight.module.js +70 -97
- package/dist/main.d.ts +2 -0
- package/dist/throttle.d.ts +2 -0
- package/package.json +9 -9
- package/rollup.config.mjs +32 -0
- package/src/{MatchHeight.js → MatchHeight.ts} +19 -9
- package/src/{main.js → main.ts} +0 -0
- package/src/{throttle.js → throttle.ts} +4 -4
- package/tsconfig.json +21 -0
- package/rollup.config.js +0 -44
package/dist/MatchHeight.js
CHANGED
|
@@ -7,118 +7,91 @@
|
|
|
7
7
|
(function (global, factory) {
|
|
8
8
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
9
9
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
10
|
-
(global.MatchHeight = factory());
|
|
11
|
-
}(this, (function () { 'use strict';
|
|
12
|
-
|
|
13
|
-
function throttle(fn,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}, threshhold);
|
|
30
|
-
} else {
|
|
31
|
-
|
|
32
|
-
last = now;
|
|
33
|
-
fn();
|
|
34
|
-
}
|
|
35
|
-
};
|
|
10
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MatchHeight = factory());
|
|
11
|
+
})(this, (function () { 'use strict';
|
|
12
|
+
|
|
13
|
+
function throttle(fn, threshold) {
|
|
14
|
+
var last, deferTimer;
|
|
15
|
+
return function () {
|
|
16
|
+
var now = Date.now();
|
|
17
|
+
if (last && now < last + threshold) {
|
|
18
|
+
clearTimeout(deferTimer);
|
|
19
|
+
deferTimer = setTimeout(function () {
|
|
20
|
+
last = now;
|
|
21
|
+
fn();
|
|
22
|
+
}, threshold);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
last = now;
|
|
26
|
+
fn();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
36
29
|
}
|
|
37
30
|
|
|
38
|
-
var errorThreshold = 1;
|
|
31
|
+
var errorThreshold = 1;
|
|
39
32
|
var initialized = false;
|
|
40
|
-
var elements
|
|
41
|
-
var remains
|
|
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
|
-
item.el.style.minHeight = '';
|
|
68
|
-
});
|
|
69
|
-
process();
|
|
70
|
-
}
|
|
33
|
+
var elements;
|
|
34
|
+
var remains;
|
|
35
|
+
var MatchHeight = {
|
|
36
|
+
init: function () {
|
|
37
|
+
initialized = true;
|
|
38
|
+
elements = document.querySelectorAll('[data-mh]');
|
|
39
|
+
MatchHeight.update();
|
|
40
|
+
},
|
|
41
|
+
update: function () {
|
|
42
|
+
if (!initialized) {
|
|
43
|
+
MatchHeight.init();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (elements.length === 0)
|
|
47
|
+
return;
|
|
48
|
+
remains = Array.prototype.map.call(elements, function (el) {
|
|
49
|
+
return {
|
|
50
|
+
el: el,
|
|
51
|
+
top: 0,
|
|
52
|
+
height: 0,
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
remains.forEach(function (item) {
|
|
56
|
+
item.el.style.minHeight = '';
|
|
57
|
+
});
|
|
58
|
+
process();
|
|
59
|
+
}
|
|
71
60
|
};
|
|
72
|
-
|
|
73
61
|
function process() {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
processingTargets.forEach(function (item) {
|
|
96
|
-
|
|
97
|
-
var error = processingTop - item.top + errorThreshold;
|
|
98
|
-
var paddingAndBorder = parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-top'), 10) + parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-bottom'), 10) + parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-top-width'), 10) + parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-bottom-width'), 10);
|
|
99
|
-
item.el.style.minHeight = maxHeightInRow - paddingAndBorder + error + 'px';
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
remains.splice(0, processingTargets.length);
|
|
103
|
-
|
|
104
|
-
if (0 < remains.length) process();
|
|
62
|
+
remains.forEach(function (item) {
|
|
63
|
+
var bb = item.el.getBoundingClientRect();
|
|
64
|
+
item.top = bb.top;
|
|
65
|
+
item.height = bb.height;
|
|
66
|
+
});
|
|
67
|
+
remains.sort(function (a, b) { return a.top - b.top; });
|
|
68
|
+
var processingTop = remains[0].top;
|
|
69
|
+
var processingTargets = remains.filter(function (item) { return Math.abs(item.top - processingTop) <= errorThreshold; });
|
|
70
|
+
var maxHeightInRow = Math.max.apply(Math, processingTargets.map(function (item) { return item.height; }));
|
|
71
|
+
processingTargets.forEach(function (item) {
|
|
72
|
+
var error = processingTop - item.top + errorThreshold;
|
|
73
|
+
var paddingAndBorder = parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-top')) +
|
|
74
|
+
parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-bottom')) +
|
|
75
|
+
parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-top-width')) +
|
|
76
|
+
parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-bottom-width'));
|
|
77
|
+
item.el.style.minHeight = "".concat(maxHeightInRow - paddingAndBorder + error, "px");
|
|
78
|
+
});
|
|
79
|
+
remains.splice(0, processingTargets.length);
|
|
80
|
+
if (0 < remains.length)
|
|
81
|
+
process();
|
|
105
82
|
}
|
|
106
83
|
|
|
107
|
-
var throttledUpdate = throttle(MatchHeight
|
|
108
|
-
|
|
84
|
+
var throttledUpdate = throttle(MatchHeight.update, 200);
|
|
109
85
|
window.addEventListener('DOMContentLoaded', function onDomReady() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
window.removeEventListener('DOMContentLoaded', onDomReady);
|
|
86
|
+
MatchHeight.init();
|
|
87
|
+
window.removeEventListener('DOMContentLoaded', onDomReady);
|
|
113
88
|
});
|
|
114
89
|
window.addEventListener('load', function onLoad() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
window.removeEventListener('load', onLoad);
|
|
90
|
+
MatchHeight.update();
|
|
91
|
+
window.removeEventListener('load', onLoad);
|
|
118
92
|
});
|
|
119
|
-
|
|
120
93
|
window.addEventListener('resize', throttledUpdate);
|
|
121
94
|
|
|
122
|
-
return MatchHeight
|
|
95
|
+
return MatchHeight;
|
|
123
96
|
|
|
124
|
-
}))
|
|
97
|
+
}));
|
package/dist/MatchHeight.min.js
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* https://github.com/yomotsu/MatchHeight
|
|
5
5
|
* Released under the MIT License.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,global.MatchHeight=factory())})(this,(function(){"use strict";function throttle(fn,threshold){var last,deferTimer;return function(){var now=Date.now();if(last&&now<last+threshold){clearTimeout(deferTimer);deferTimer=setTimeout((function(){last=now;fn()}),threshold)}else{last=now;fn()}}}var errorThreshold=1;var initialized=false;var elements;var remains;var MatchHeight={init:function(){initialized=true;elements=document.querySelectorAll("[data-mh]");MatchHeight.update()},update:function(){if(!initialized){MatchHeight.init();return}if(elements.length===0)return;remains=Array.prototype.map.call(elements,(function(el){return{el:el,top:0,height:0}}));remains.forEach((function(item){item.el.style.minHeight=""}));process()}};function process(){remains.forEach((function(item){var bb=item.el.getBoundingClientRect();item.top=bb.top;item.height=bb.height}));remains.sort((function(a,b){return a.top-b.top}));var processingTop=remains[0].top;var processingTargets=remains.filter((function(item){return Math.abs(item.top-processingTop)<=errorThreshold}));var maxHeightInRow=Math.max.apply(Math,processingTargets.map((function(item){return item.height})));processingTargets.forEach((function(item){var error=processingTop-item.top+errorThreshold;var paddingAndBorder=parseFloat(window.getComputedStyle(item.el).getPropertyValue("padding-top"))+parseFloat(window.getComputedStyle(item.el).getPropertyValue("padding-bottom"))+parseFloat(window.getComputedStyle(item.el).getPropertyValue("border-top-width"))+parseFloat(window.getComputedStyle(item.el).getPropertyValue("border-bottom-width"));item.el.style.minHeight="".concat(maxHeightInRow-paddingAndBorder+error,"px")}));remains.splice(0,processingTargets.length);if(0<remains.length)process()}var throttledUpdate=throttle(MatchHeight.update,200);window.addEventListener("DOMContentLoaded",(function onDomReady(){MatchHeight.init();window.removeEventListener("DOMContentLoaded",onDomReady)}));window.addEventListener("load",(function onLoad(){MatchHeight.update();window.removeEventListener("load",onLoad)}));window.addEventListener("resize",throttledUpdate);return MatchHeight}));
|
|
@@ -4,113 +4,86 @@
|
|
|
4
4
|
* https://github.com/yomotsu/MatchHeight
|
|
5
5
|
* Released under the MIT License.
|
|
6
6
|
*/
|
|
7
|
-
function throttle(fn,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}, threshhold);
|
|
24
|
-
} else {
|
|
25
|
-
|
|
26
|
-
last = now;
|
|
27
|
-
fn();
|
|
28
|
-
}
|
|
29
|
-
};
|
|
7
|
+
function throttle(fn, threshold) {
|
|
8
|
+
var last, deferTimer;
|
|
9
|
+
return function () {
|
|
10
|
+
var now = Date.now();
|
|
11
|
+
if (last && now < last + threshold) {
|
|
12
|
+
clearTimeout(deferTimer);
|
|
13
|
+
deferTimer = setTimeout(function () {
|
|
14
|
+
last = now;
|
|
15
|
+
fn();
|
|
16
|
+
}, threshold);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
last = now;
|
|
20
|
+
fn();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
30
23
|
}
|
|
31
24
|
|
|
32
|
-
var errorThreshold = 1;
|
|
25
|
+
var errorThreshold = 1;
|
|
33
26
|
var initialized = false;
|
|
34
|
-
var elements
|
|
35
|
-
var remains
|
|
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
|
-
item.el.style.minHeight = '';
|
|
62
|
-
});
|
|
63
|
-
process();
|
|
64
|
-
}
|
|
27
|
+
var elements;
|
|
28
|
+
var remains;
|
|
29
|
+
var MatchHeight = {
|
|
30
|
+
init: function () {
|
|
31
|
+
initialized = true;
|
|
32
|
+
elements = document.querySelectorAll('[data-mh]');
|
|
33
|
+
MatchHeight.update();
|
|
34
|
+
},
|
|
35
|
+
update: function () {
|
|
36
|
+
if (!initialized) {
|
|
37
|
+
MatchHeight.init();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (elements.length === 0)
|
|
41
|
+
return;
|
|
42
|
+
remains = Array.prototype.map.call(elements, function (el) {
|
|
43
|
+
return {
|
|
44
|
+
el: el,
|
|
45
|
+
top: 0,
|
|
46
|
+
height: 0,
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
remains.forEach(function (item) {
|
|
50
|
+
item.el.style.minHeight = '';
|
|
51
|
+
});
|
|
52
|
+
process();
|
|
53
|
+
}
|
|
65
54
|
};
|
|
66
|
-
|
|
67
55
|
function process() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
processingTargets.forEach(function (item) {
|
|
90
|
-
|
|
91
|
-
var error = processingTop - item.top + errorThreshold;
|
|
92
|
-
var paddingAndBorder = parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-top'), 10) + parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-bottom'), 10) + parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-top-width'), 10) + parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-bottom-width'), 10);
|
|
93
|
-
item.el.style.minHeight = maxHeightInRow - paddingAndBorder + error + 'px';
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
remains.splice(0, processingTargets.length);
|
|
97
|
-
|
|
98
|
-
if (0 < remains.length) process();
|
|
56
|
+
remains.forEach(function (item) {
|
|
57
|
+
var bb = item.el.getBoundingClientRect();
|
|
58
|
+
item.top = bb.top;
|
|
59
|
+
item.height = bb.height;
|
|
60
|
+
});
|
|
61
|
+
remains.sort(function (a, b) { return a.top - b.top; });
|
|
62
|
+
var processingTop = remains[0].top;
|
|
63
|
+
var processingTargets = remains.filter(function (item) { return Math.abs(item.top - processingTop) <= errorThreshold; });
|
|
64
|
+
var maxHeightInRow = Math.max.apply(Math, processingTargets.map(function (item) { return item.height; }));
|
|
65
|
+
processingTargets.forEach(function (item) {
|
|
66
|
+
var error = processingTop - item.top + errorThreshold;
|
|
67
|
+
var paddingAndBorder = parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-top')) +
|
|
68
|
+
parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-bottom')) +
|
|
69
|
+
parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-top-width')) +
|
|
70
|
+
parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-bottom-width'));
|
|
71
|
+
item.el.style.minHeight = "".concat(maxHeightInRow - paddingAndBorder + error, "px");
|
|
72
|
+
});
|
|
73
|
+
remains.splice(0, processingTargets.length);
|
|
74
|
+
if (0 < remains.length)
|
|
75
|
+
process();
|
|
99
76
|
}
|
|
100
77
|
|
|
101
|
-
var throttledUpdate = throttle(MatchHeight
|
|
102
|
-
|
|
78
|
+
var throttledUpdate = throttle(MatchHeight.update, 200);
|
|
103
79
|
window.addEventListener('DOMContentLoaded', function onDomReady() {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
window.removeEventListener('DOMContentLoaded', onDomReady);
|
|
80
|
+
MatchHeight.init();
|
|
81
|
+
window.removeEventListener('DOMContentLoaded', onDomReady);
|
|
107
82
|
});
|
|
108
83
|
window.addEventListener('load', function onLoad() {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
window.removeEventListener('load', onLoad);
|
|
84
|
+
MatchHeight.update();
|
|
85
|
+
window.removeEventListener('load', onLoad);
|
|
112
86
|
});
|
|
113
|
-
|
|
114
87
|
window.addEventListener('resize', throttledUpdate);
|
|
115
88
|
|
|
116
|
-
export default
|
|
89
|
+
export { MatchHeight as default };
|
package/dist/main.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matchheight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"author": "Yomotsu",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"main": "dist/MatchHeight.js",
|
|
7
6
|
"repository": "yomotsu/MatchHeight",
|
|
7
|
+
"main": "dist/MatchHeight.js",
|
|
8
8
|
"jsnext:main": "dist/MatchHeight.module.js",
|
|
9
9
|
"module": "dist/MatchHeight.module.js",
|
|
10
|
+
"types": "dist/MatchHeight.d.ts",
|
|
10
11
|
"devDependencies": {
|
|
11
|
-
"
|
|
12
|
-
"rollup": "^
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
12
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
13
|
+
"rollup": "^3.16.0",
|
|
14
|
+
"terser": "^5.16.4",
|
|
15
|
+
"tslib": "^2.5.0",
|
|
16
|
+
"typescript": "^4.9.5"
|
|
16
17
|
},
|
|
17
18
|
"scripts": {
|
|
18
19
|
"dev": "rollup --config --watch",
|
|
19
|
-
"build": "rollup --config"
|
|
20
|
-
"release": "rollup --config && uglifyjs dist/MatchHeight.js -cm --preamble \"/*!\n * @author yomotsu\n * MatchHeight\n * https://github.com/yomotsu/MatchHeight\n * Released under the MIT License.\n */\" > dist/MatchHeight.min.js"
|
|
20
|
+
"build": "rollup --config && terser dist/MatchHeight.js -o dist/MatchHeight.min.js --comments '/^!/'"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"matchHeight",
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import pkg from './package.json' assert { type: "json" };
|
|
2
|
+
import typescript from 'typescript';
|
|
3
|
+
import rollupTypescript from '@rollup/plugin-typescript';
|
|
4
|
+
|
|
5
|
+
const license = `/*!
|
|
6
|
+
* @author yomotsu
|
|
7
|
+
* MatchHeight
|
|
8
|
+
* https://github.com/yomotsu/MatchHeight
|
|
9
|
+
* Released under the MIT License.
|
|
10
|
+
*/`;
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
input: './src/main.ts',
|
|
14
|
+
output: [
|
|
15
|
+
{
|
|
16
|
+
format: 'umd',
|
|
17
|
+
name: 'MatchHeight',
|
|
18
|
+
file: pkg.main,
|
|
19
|
+
banner: license,
|
|
20
|
+
indent: '\t',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
format: 'es',
|
|
24
|
+
file: pkg.module,
|
|
25
|
+
banner: license,
|
|
26
|
+
indent: '\t',
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
plugins: [
|
|
30
|
+
rollupTypescript( { typescript } ),
|
|
31
|
+
],
|
|
32
|
+
};
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
type Item = {
|
|
2
|
+
el: HTMLElement;
|
|
3
|
+
top: number;
|
|
4
|
+
height: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
1
7
|
const errorThreshold = 1; // in px
|
|
2
8
|
let initialized = false;
|
|
3
|
-
let elements
|
|
4
|
-
let remains;
|
|
9
|
+
let elements: NodeListOf<HTMLElement>;
|
|
10
|
+
let remains: Item[];
|
|
5
11
|
|
|
6
12
|
const MatchHeight = {
|
|
7
13
|
|
|
@@ -24,11 +30,15 @@ const MatchHeight = {
|
|
|
24
30
|
|
|
25
31
|
if ( elements.length === 0 ) return;
|
|
26
32
|
|
|
27
|
-
remains = Array.prototype.map.call( elements, ( el ) => {
|
|
33
|
+
remains = Array.prototype.map.call( elements, ( el: HTMLElement ): Item => {
|
|
28
34
|
|
|
29
|
-
return {
|
|
35
|
+
return {
|
|
36
|
+
el,
|
|
37
|
+
top: 0,
|
|
38
|
+
height: 0,
|
|
39
|
+
};
|
|
30
40
|
|
|
31
|
-
} );
|
|
41
|
+
} ) as Item[];
|
|
32
42
|
// remove all height before
|
|
33
43
|
remains.forEach( ( item ) => {
|
|
34
44
|
|
|
@@ -62,10 +72,10 @@ function process() {
|
|
|
62
72
|
|
|
63
73
|
const error = processingTop - item.top + errorThreshold;
|
|
64
74
|
const paddingAndBorder =
|
|
65
|
-
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'padding-top' )
|
|
66
|
-
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'padding-bottom' )
|
|
67
|
-
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'border-top-width' )
|
|
68
|
-
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'border-bottom-width' )
|
|
75
|
+
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'padding-top' ) ) +
|
|
76
|
+
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'padding-bottom' ) ) +
|
|
77
|
+
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'border-top-width' ) ) +
|
|
78
|
+
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'border-bottom-width' ) );
|
|
69
79
|
item.el.style.minHeight = `${ maxHeightInRow - paddingAndBorder + error }px`;
|
|
70
80
|
|
|
71
81
|
} );
|
package/src/{main.js → main.ts}
RENAMED
|
File without changes
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
function throttle( fn,
|
|
1
|
+
function throttle( fn: () => void, threshold: number ) {
|
|
2
2
|
|
|
3
|
-
let last, deferTimer;
|
|
3
|
+
let last: number, deferTimer: number;
|
|
4
4
|
|
|
5
5
|
return function () {
|
|
6
6
|
|
|
7
7
|
const now = Date.now();
|
|
8
8
|
|
|
9
|
-
if ( last && now < last +
|
|
9
|
+
if ( last && now < last + threshold ) {
|
|
10
10
|
|
|
11
11
|
clearTimeout( deferTimer );
|
|
12
12
|
deferTimer = setTimeout( function () {
|
|
@@ -14,7 +14,7 @@ function throttle( fn, threshhold ) {
|
|
|
14
14
|
last = now;
|
|
15
15
|
fn();
|
|
16
16
|
|
|
17
|
-
},
|
|
17
|
+
}, threshold );
|
|
18
18
|
|
|
19
19
|
} else {
|
|
20
20
|
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": "src",
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"target": "es5",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"removeComments": true,
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"noImplicitAny": true,
|
|
11
|
+
"noImplicitThis": true,
|
|
12
|
+
"noImplicitReturns": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"noUnusedParameters": true,
|
|
15
|
+
"strictNullChecks": true,
|
|
16
|
+
"strictFunctionTypes": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["src/**/*"],
|
|
20
|
+
"exclude": ["node_modules"]
|
|
21
|
+
}
|
package/rollup.config.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import babel from 'rollup-plugin-babel'
|
|
2
|
-
|
|
3
|
-
const license = `/*!
|
|
4
|
-
* @author yomotsu
|
|
5
|
-
* MatchHeight
|
|
6
|
-
* https://github.com/yomotsu/MatchHeight
|
|
7
|
-
* Released under the MIT License.
|
|
8
|
-
*/`
|
|
9
|
-
|
|
10
|
-
export default {
|
|
11
|
-
entry: './src/main.js',
|
|
12
|
-
indent: '\t',
|
|
13
|
-
sourceMap: false,
|
|
14
|
-
plugins: [
|
|
15
|
-
babel( {
|
|
16
|
-
exclude: 'node_modules/**',
|
|
17
|
-
presets: [
|
|
18
|
-
[ 'env', {
|
|
19
|
-
targets: {
|
|
20
|
-
browsers: [
|
|
21
|
-
'last 2 versions',
|
|
22
|
-
'ie >= 9'
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
|
-
loose: true,
|
|
26
|
-
modules: false
|
|
27
|
-
} ]
|
|
28
|
-
]
|
|
29
|
-
} )
|
|
30
|
-
],
|
|
31
|
-
targets: [
|
|
32
|
-
{
|
|
33
|
-
format: 'umd',
|
|
34
|
-
moduleName: 'MatchHeight',
|
|
35
|
-
dest: 'dist/MatchHeight.js',
|
|
36
|
-
banner: license
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
format: 'es',
|
|
40
|
-
dest: 'dist/MatchHeight.module.js',
|
|
41
|
-
banner: license
|
|
42
|
-
}
|
|
43
|
-
]
|
|
44
|
-
};
|