matchheight 0.1.1 → 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 -99
- package/dist/MatchHeight.min.js +1 -1
- package/dist/MatchHeight.module.js +70 -95
- 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} +25 -13
- 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,116 +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
|
|
|
31
|
+
var errorThreshold = 1;
|
|
38
32
|
var initialized = false;
|
|
39
|
-
var elements
|
|
40
|
-
var remains
|
|
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
|
-
item.el.style.minHeight = '';
|
|
67
|
-
});
|
|
68
|
-
process();
|
|
69
|
-
}
|
|
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
|
+
}
|
|
70
60
|
};
|
|
71
|
-
|
|
72
61
|
function process() {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
processingTargets.forEach(function (item) {
|
|
95
|
-
|
|
96
|
-
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);
|
|
97
|
-
item.el.style.minHeight = maxHeightInRow - paddingAndBorder + 'px';
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
remains.splice(0, processingTargets.length);
|
|
101
|
-
|
|
102
|
-
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();
|
|
103
82
|
}
|
|
104
83
|
|
|
105
|
-
var throttledUpdate = throttle(MatchHeight
|
|
106
|
-
|
|
84
|
+
var throttledUpdate = throttle(MatchHeight.update, 200);
|
|
107
85
|
window.addEventListener('DOMContentLoaded', function onDomReady() {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
window.removeEventListener('DOMContentLoaded', onDomReady);
|
|
86
|
+
MatchHeight.init();
|
|
87
|
+
window.removeEventListener('DOMContentLoaded', onDomReady);
|
|
111
88
|
});
|
|
112
89
|
window.addEventListener('load', function onLoad() {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
window.removeEventListener('load', onLoad);
|
|
90
|
+
MatchHeight.update();
|
|
91
|
+
window.removeEventListener('load', onLoad);
|
|
116
92
|
});
|
|
117
|
-
|
|
118
93
|
window.addEventListener('resize', throttledUpdate);
|
|
119
94
|
|
|
120
|
-
return MatchHeight
|
|
95
|
+
return MatchHeight;
|
|
121
96
|
|
|
122
|
-
}))
|
|
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,111 +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
|
|
|
25
|
+
var errorThreshold = 1;
|
|
32
26
|
var initialized = false;
|
|
33
|
-
var elements
|
|
34
|
-
var remains
|
|
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
|
-
item.el.style.minHeight = '';
|
|
61
|
-
});
|
|
62
|
-
process();
|
|
63
|
-
}
|
|
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
|
+
}
|
|
64
54
|
};
|
|
65
|
-
|
|
66
55
|
function process() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
processingTargets.forEach(function (item) {
|
|
89
|
-
|
|
90
|
-
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);
|
|
91
|
-
item.el.style.minHeight = maxHeightInRow - paddingAndBorder + 'px';
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
remains.splice(0, processingTargets.length);
|
|
95
|
-
|
|
96
|
-
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();
|
|
97
76
|
}
|
|
98
77
|
|
|
99
|
-
var throttledUpdate = throttle(MatchHeight
|
|
100
|
-
|
|
78
|
+
var throttledUpdate = throttle(MatchHeight.update, 200);
|
|
101
79
|
window.addEventListener('DOMContentLoaded', function onDomReady() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
window.removeEventListener('DOMContentLoaded', onDomReady);
|
|
80
|
+
MatchHeight.init();
|
|
81
|
+
window.removeEventListener('DOMContentLoaded', onDomReady);
|
|
105
82
|
});
|
|
106
83
|
window.addEventListener('load', function onLoad() {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
window.removeEventListener('load', onLoad);
|
|
84
|
+
MatchHeight.update();
|
|
85
|
+
window.removeEventListener('load', onLoad);
|
|
110
86
|
});
|
|
111
|
-
|
|
112
87
|
window.addEventListener('resize', throttledUpdate);
|
|
113
88
|
|
|
114
|
-
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,6 +1,13 @@
|
|
|
1
|
+
type Item = {
|
|
2
|
+
el: HTMLElement;
|
|
3
|
+
top: number;
|
|
4
|
+
height: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const errorThreshold = 1; // in px
|
|
1
8
|
let initialized = false;
|
|
2
|
-
let elements
|
|
3
|
-
let remains;
|
|
9
|
+
let elements: NodeListOf<HTMLElement>;
|
|
10
|
+
let remains: Item[];
|
|
4
11
|
|
|
5
12
|
const MatchHeight = {
|
|
6
13
|
|
|
@@ -8,7 +15,7 @@ const MatchHeight = {
|
|
|
8
15
|
|
|
9
16
|
initialized = true;
|
|
10
17
|
elements = document.querySelectorAll( '[data-mh]' );
|
|
11
|
-
|
|
18
|
+
MatchHeight.update();
|
|
12
19
|
|
|
13
20
|
},
|
|
14
21
|
|
|
@@ -16,18 +23,22 @@ const MatchHeight = {
|
|
|
16
23
|
|
|
17
24
|
if ( ! initialized ) {
|
|
18
25
|
|
|
19
|
-
|
|
26
|
+
MatchHeight.init();
|
|
20
27
|
return;
|
|
21
28
|
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
if ( elements.length === 0 ) return;
|
|
25
32
|
|
|
26
|
-
remains = Array.prototype.map.call( elements, ( el ) => {
|
|
33
|
+
remains = Array.prototype.map.call( elements, ( el: HTMLElement ): Item => {
|
|
27
34
|
|
|
28
|
-
return {
|
|
35
|
+
return {
|
|
36
|
+
el,
|
|
37
|
+
top: 0,
|
|
38
|
+
height: 0,
|
|
39
|
+
};
|
|
29
40
|
|
|
30
|
-
} );
|
|
41
|
+
} ) as Item[];
|
|
31
42
|
// remove all height before
|
|
32
43
|
remains.forEach( ( item ) => {
|
|
33
44
|
|
|
@@ -54,17 +65,18 @@ function process() {
|
|
|
54
65
|
remains.sort( ( a, b ) => a.top - b.top );
|
|
55
66
|
|
|
56
67
|
const processingTop = remains[ 0 ].top;
|
|
57
|
-
const processingTargets = remains.filter( item => item.top
|
|
68
|
+
const processingTargets = remains.filter( item => Math.abs( item.top - processingTop ) <= errorThreshold );
|
|
58
69
|
const maxHeightInRow = Math.max( ...processingTargets.map( ( item ) => item.height ) );
|
|
59
70
|
|
|
60
71
|
processingTargets.forEach( ( item ) => {
|
|
61
72
|
|
|
73
|
+
const error = processingTop - item.top + errorThreshold;
|
|
62
74
|
const paddingAndBorder =
|
|
63
|
-
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'padding-top' )
|
|
64
|
-
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'padding-bottom' )
|
|
65
|
-
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'border-top-width' )
|
|
66
|
-
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'border-bottom-width' )
|
|
67
|
-
item.el.style.minHeight = `${ maxHeightInRow - paddingAndBorder }px`;
|
|
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' ) );
|
|
79
|
+
item.el.style.minHeight = `${ maxHeightInRow - paddingAndBorder + error }px`;
|
|
68
80
|
|
|
69
81
|
} );
|
|
70
82
|
|
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
|
-
};
|