matchheight 0.2.0 → 1.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.
@@ -0,0 +1,9 @@
1
+ declare class MatchHeight {
2
+ private _selector;
3
+ private _remains;
4
+ disconnect: () => void;
5
+ constructor(selector?: string);
6
+ update(): void;
7
+ private _process;
8
+ }
9
+ export default MatchHeight;
@@ -0,0 +1,94 @@
1
+ /*!
2
+ * @author yomotsu
3
+ * MatchHeight
4
+ * https://github.com/yomotsu/MatchHeight
5
+ * Released under the MIT License.
6
+ */
7
+ (function (global, factory) {
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
9
+ typeof define === 'function' && define.amd ? define(factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MatchHeight = factory());
11
+ })(this, (function () { 'use strict';
12
+
13
+ function throttle(fn, threshold) {
14
+ let last, deferTimer;
15
+ return function () {
16
+ const 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
+ };
29
+ }
30
+
31
+ const errorThreshold = 1;
32
+ class MatchHeight {
33
+ constructor(selector = '[data-mh]') {
34
+ this._remains = [];
35
+ this._selector = selector;
36
+ const update = this.update.bind(this);
37
+ const throttledUpdate = throttle(update, 200);
38
+ if (document.readyState === 'loading') {
39
+ document.addEventListener('DOMContentLoaded', update, { once: true });
40
+ }
41
+ if (document.readyState === 'interactive') {
42
+ document.addEventListener('load', update, { once: true });
43
+ }
44
+ else {
45
+ update();
46
+ }
47
+ window.addEventListener('resize', throttledUpdate);
48
+ this.disconnect = () => {
49
+ window.removeEventListener('resize', throttledUpdate);
50
+ };
51
+ }
52
+ update() {
53
+ const elements = document.querySelectorAll(this._selector);
54
+ if (elements.length === 0)
55
+ return;
56
+ this._remains = Array.prototype.map.call(elements, (el) => {
57
+ return {
58
+ el,
59
+ top: 0,
60
+ height: 0,
61
+ };
62
+ });
63
+ this._remains.forEach((item) => {
64
+ item.el.style.minHeight = '';
65
+ });
66
+ this._process();
67
+ }
68
+ _process() {
69
+ this._remains.forEach((item) => {
70
+ const bb = item.el.getBoundingClientRect();
71
+ item.top = bb.top;
72
+ item.height = bb.height;
73
+ });
74
+ this._remains.sort((a, b) => a.top - b.top);
75
+ const processingTop = this._remains[0].top;
76
+ const processingTargets = this._remains.filter(item => Math.abs(item.top - processingTop) <= errorThreshold);
77
+ const maxHeightInRow = Math.max(...processingTargets.map((item) => item.height));
78
+ processingTargets.forEach((item) => {
79
+ const error = processingTop - item.top + errorThreshold;
80
+ const paddingAndBorder = parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-top')) +
81
+ parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-bottom')) +
82
+ parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-top-width')) +
83
+ parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-bottom-width'));
84
+ item.el.style.minHeight = `${maxHeightInRow - paddingAndBorder + error}px`;
85
+ });
86
+ this._remains.splice(0, processingTargets.length);
87
+ if (0 < this._remains.length)
88
+ this._process();
89
+ }
90
+ }
91
+
92
+ return MatchHeight;
93
+
94
+ }));
@@ -0,0 +1,86 @@
1
+ /*!
2
+ * @author yomotsu
3
+ * MatchHeight
4
+ * https://github.com/yomotsu/MatchHeight
5
+ * Released under the MIT License.
6
+ */
7
+ function throttle(fn, threshold) {
8
+ let last, deferTimer;
9
+ return function () {
10
+ const 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
+ };
23
+ }
24
+
25
+ const errorThreshold = 1;
26
+ class MatchHeight {
27
+ constructor(selector = '[data-mh]') {
28
+ this._remains = [];
29
+ this._selector = selector;
30
+ const update = this.update.bind(this);
31
+ const throttledUpdate = throttle(update, 200);
32
+ if (document.readyState === 'loading') {
33
+ document.addEventListener('DOMContentLoaded', update, { once: true });
34
+ }
35
+ if (document.readyState === 'interactive') {
36
+ document.addEventListener('load', update, { once: true });
37
+ }
38
+ else {
39
+ update();
40
+ }
41
+ window.addEventListener('resize', throttledUpdate);
42
+ this.disconnect = () => {
43
+ window.removeEventListener('resize', throttledUpdate);
44
+ };
45
+ }
46
+ update() {
47
+ const elements = document.querySelectorAll(this._selector);
48
+ if (elements.length === 0)
49
+ return;
50
+ this._remains = Array.prototype.map.call(elements, (el) => {
51
+ return {
52
+ el,
53
+ top: 0,
54
+ height: 0,
55
+ };
56
+ });
57
+ this._remains.forEach((item) => {
58
+ item.el.style.minHeight = '';
59
+ });
60
+ this._process();
61
+ }
62
+ _process() {
63
+ this._remains.forEach((item) => {
64
+ const bb = item.el.getBoundingClientRect();
65
+ item.top = bb.top;
66
+ item.height = bb.height;
67
+ });
68
+ this._remains.sort((a, b) => a.top - b.top);
69
+ const processingTop = this._remains[0].top;
70
+ const processingTargets = this._remains.filter(item => Math.abs(item.top - processingTop) <= errorThreshold);
71
+ const maxHeightInRow = Math.max(...processingTargets.map((item) => item.height));
72
+ processingTargets.forEach((item) => {
73
+ const error = processingTop - item.top + errorThreshold;
74
+ const paddingAndBorder = parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-top')) +
75
+ parseFloat(window.getComputedStyle(item.el).getPropertyValue('padding-bottom')) +
76
+ parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-top-width')) +
77
+ parseFloat(window.getComputedStyle(item.el).getPropertyValue('border-bottom-width'));
78
+ item.el.style.minHeight = `${maxHeightInRow - paddingAndBorder + error}px`;
79
+ });
80
+ this._remains.splice(0, processingTargets.length);
81
+ if (0 < this._remains.length)
82
+ this._process();
83
+ }
84
+ }
85
+
86
+ export { MatchHeight as default };
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "matchheight",
3
- "version": "0.2.0",
3
+ "version": "1.0.0",
4
4
  "author": "Yomotsu",
5
5
  "license": "MIT",
6
- "repository": "yomotsu/MatchHeight",
7
- "main": "dist/MatchHeight.js",
8
- "jsnext:main": "dist/MatchHeight.module.js",
9
- "module": "dist/MatchHeight.module.js",
10
- "types": "dist/MatchHeight.d.ts",
6
+ "repository": "yomotsu/matchheight",
7
+ "main": "dist/match-height.js",
8
+ "jsnext:main": "dist/match-height.module.js",
9
+ "module": "dist/match-height.module.js",
10
+ "types": "dist/match-height.d.ts",
11
11
  "devDependencies": {
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"
12
+ "@rollup/plugin-typescript": "^11.1.2",
13
+ "rollup": "^3.28.0",
14
+ "terser": "^5.19.2",
15
+ "tslib": "^2.6.1",
16
+ "typescript": "^5.1.6"
17
17
  },
18
18
  "scripts": {
19
19
  "dev": "rollup --config --watch",
package/readme.md CHANGED
@@ -13,9 +13,10 @@ No dependencies, Light weight, Makes elements equal height.
13
13
 
14
14
  ### Standalone
15
15
 
16
- Copy MatchHeight.js from `/dist/MatchHeight.js` and place it in your project.
16
+ Copy MatchHeight.js from `/dist/MatchHeight.js` and place it in your project, then call `new MatchHeight()`.
17
17
  ```html
18
- <script src="./js/MatchHeight.js"></script>
18
+ <script src="./js/match-height.js"></script>
19
+ <script>new MatchHeight();</script>
19
20
  ```
20
21
 
21
22
  ### NPM
@@ -26,6 +27,7 @@ $ npm install --save matchheight
26
27
  then
27
28
  ```javascript
28
29
  import MatchHeight from 'matchheight';
30
+ MatchHeight();
29
31
  ```
30
32
 
31
33
  for more info, see [the demo](https://yomotsu.github.io/MatchHeight/examples/).
package/rollup.config.mjs CHANGED
@@ -10,7 +10,7 @@ const license = `/*!
10
10
  */`;
11
11
 
12
12
  export default {
13
- input: './src/main.ts',
13
+ input: './src/match-height.ts',
14
14
  output: [
15
15
  {
16
16
  format: 'umd',
@@ -0,0 +1,111 @@
1
+ import throttle from './throttle';
2
+
3
+ type Item = {
4
+ el: HTMLElement;
5
+ top: number;
6
+ height: number;
7
+ }
8
+
9
+ const errorThreshold = 1; // in px
10
+
11
+ class MatchHeight {
12
+
13
+ private _selector: string;
14
+ private _remains: Item[] = [];
15
+ disconnect: () => void;
16
+
17
+ constructor( selector: string = '[data-mh]' ) {
18
+
19
+ this._selector = selector;
20
+
21
+ const update = this.update.bind( this );
22
+ const throttledUpdate = throttle( update, 200 );
23
+
24
+ if ( document.readyState === 'loading' ) {
25
+
26
+ document.addEventListener( 'DOMContentLoaded', update, { once: true } );
27
+
28
+ } if ( document.readyState === 'interactive' ) {
29
+
30
+ document.addEventListener( 'load', update, { once: true } );
31
+
32
+ } else {
33
+
34
+ update();
35
+
36
+ }
37
+
38
+ window.addEventListener( 'resize', throttledUpdate );
39
+
40
+ this.disconnect = () => {
41
+
42
+ window.removeEventListener( 'resize', throttledUpdate );
43
+
44
+ }
45
+
46
+ }
47
+
48
+ update() {
49
+
50
+ const elements = document.querySelectorAll( this._selector );
51
+
52
+ if ( elements.length === 0 ) return;
53
+
54
+ this._remains = Array.prototype.map.call( elements, ( el: HTMLElement ): Item => {
55
+
56
+ return {
57
+ el,
58
+ top: 0,
59
+ height: 0,
60
+ };
61
+
62
+ } ) as Item[];
63
+ // remove all height before
64
+ this._remains.forEach( ( item ) => {
65
+
66
+ item.el.style.minHeight = '';
67
+
68
+ } );
69
+
70
+ this._process();
71
+
72
+ }
73
+
74
+ private _process() {
75
+
76
+ this._remains.forEach( ( item ) => {
77
+
78
+ const bb = item.el.getBoundingClientRect();
79
+
80
+ item.top = bb.top;
81
+ item.height = bb.height;
82
+
83
+ } );
84
+
85
+ this._remains.sort( ( a, b ) => a.top - b.top );
86
+
87
+ const processingTop = this._remains[ 0 ].top;
88
+ const processingTargets = this._remains.filter( item => Math.abs( item.top - processingTop ) <= errorThreshold );
89
+ const maxHeightInRow = Math.max( ...processingTargets.map( ( item ) => item.height ) );
90
+
91
+ processingTargets.forEach( ( item ) => {
92
+
93
+ const error = processingTop - item.top + errorThreshold;
94
+ const paddingAndBorder =
95
+ parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'padding-top' ) ) +
96
+ parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'padding-bottom' ) ) +
97
+ parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'border-top-width' ) ) +
98
+ parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'border-bottom-width' ) );
99
+ item.el.style.minHeight = `${ maxHeightInRow - paddingAndBorder + error }px`;
100
+
101
+ } );
102
+
103
+ this._remains.splice( 0, processingTargets.length );
104
+
105
+ if ( 0 < this._remains.length ) this._process();
106
+
107
+ }
108
+
109
+ }
110
+
111
+ export default MatchHeight;
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "baseUrl": "src",
4
4
  "outDir": "./dist",
5
5
  "declaration": true,
6
- "target": "es5",
6
+ "target": "es2017",
7
7
  "strict": true,
8
8
  "removeComments": true,
9
9
  "experimentalDecorators": true,
@@ -1,5 +0,0 @@
1
- declare const MatchHeight: {
2
- init(): void;
3
- update(): void;
4
- };
5
- export default MatchHeight;
@@ -1,97 +0,0 @@
1
- /*!
2
- * @author yomotsu
3
- * MatchHeight
4
- * https://github.com/yomotsu/MatchHeight
5
- * Released under the MIT License.
6
- */
7
- (function (global, factory) {
8
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
9
- typeof define === 'function' && define.amd ? define(factory) :
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
- };
29
- }
30
-
31
- var errorThreshold = 1;
32
- var initialized = false;
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
- }
60
- };
61
- function 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();
82
- }
83
-
84
- var throttledUpdate = throttle(MatchHeight.update, 200);
85
- window.addEventListener('DOMContentLoaded', function onDomReady() {
86
- MatchHeight.init();
87
- window.removeEventListener('DOMContentLoaded', onDomReady);
88
- });
89
- window.addEventListener('load', function onLoad() {
90
- MatchHeight.update();
91
- window.removeEventListener('load', onLoad);
92
- });
93
- window.addEventListener('resize', throttledUpdate);
94
-
95
- return MatchHeight;
96
-
97
- }));
@@ -1,7 +0,0 @@
1
- /*!
2
- * @author yomotsu
3
- * MatchHeight
4
- * https://github.com/yomotsu/MatchHeight
5
- * Released under the MIT License.
6
- */
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}));
@@ -1,89 +0,0 @@
1
- /*!
2
- * @author yomotsu
3
- * MatchHeight
4
- * https://github.com/yomotsu/MatchHeight
5
- * Released under the MIT License.
6
- */
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
- };
23
- }
24
-
25
- var errorThreshold = 1;
26
- var initialized = false;
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
- }
54
- };
55
- function 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();
76
- }
77
-
78
- var throttledUpdate = throttle(MatchHeight.update, 200);
79
- window.addEventListener('DOMContentLoaded', function onDomReady() {
80
- MatchHeight.init();
81
- window.removeEventListener('DOMContentLoaded', onDomReady);
82
- });
83
- window.addEventListener('load', function onLoad() {
84
- MatchHeight.update();
85
- window.removeEventListener('load', onLoad);
86
- });
87
- window.addEventListener('resize', throttledUpdate);
88
-
89
- export { MatchHeight as default };
package/dist/main.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import MatchHeight from './MatchHeight.js';
2
- export default MatchHeight;
@@ -1,89 +0,0 @@
1
- type Item = {
2
- el: HTMLElement;
3
- top: number;
4
- height: number;
5
- }
6
-
7
- const errorThreshold = 1; // in px
8
- let initialized = false;
9
- let elements: NodeListOf<HTMLElement>;
10
- let remains: Item[];
11
-
12
- const MatchHeight = {
13
-
14
- init() {
15
-
16
- initialized = true;
17
- elements = document.querySelectorAll( '[data-mh]' );
18
- MatchHeight.update();
19
-
20
- },
21
-
22
- update() {
23
-
24
- if ( ! initialized ) {
25
-
26
- MatchHeight.init();
27
- return;
28
-
29
- }
30
-
31
- if ( elements.length === 0 ) return;
32
-
33
- remains = Array.prototype.map.call( elements, ( el: HTMLElement ): Item => {
34
-
35
- return {
36
- el,
37
- top: 0,
38
- height: 0,
39
- };
40
-
41
- } ) as Item[];
42
- // remove all height before
43
- remains.forEach( ( item ) => {
44
-
45
- item.el.style.minHeight = '';
46
-
47
- } );
48
- process();
49
-
50
- }
51
-
52
- };
53
-
54
- function process() {
55
-
56
- remains.forEach( ( item ) => {
57
-
58
- const bb = item.el.getBoundingClientRect();
59
-
60
- item.top = bb.top;
61
- item.height = bb.height;
62
-
63
- } );
64
-
65
- remains.sort( ( a, b ) => a.top - b.top );
66
-
67
- const processingTop = remains[ 0 ].top;
68
- const processingTargets = remains.filter( item => Math.abs( item.top - processingTop ) <= errorThreshold );
69
- const maxHeightInRow = Math.max( ...processingTargets.map( ( item ) => item.height ) );
70
-
71
- processingTargets.forEach( ( item ) => {
72
-
73
- const error = processingTop - item.top + errorThreshold;
74
- const paddingAndBorder =
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`;
80
-
81
- } );
82
-
83
- remains.splice( 0, processingTargets.length );
84
-
85
- if ( 0 < remains.length ) process();
86
-
87
- }
88
-
89
- export default MatchHeight;
package/src/main.ts DELETED
@@ -1,21 +0,0 @@
1
- import throttle from './throttle.js';
2
- import MatchHeight from './MatchHeight.js';
3
-
4
- const throttledUpdate = throttle( MatchHeight.update, 200 );
5
-
6
- window.addEventListener( 'DOMContentLoaded', function onDomReady() {
7
-
8
- MatchHeight.init();
9
- window.removeEventListener( 'DOMContentLoaded', onDomReady );
10
-
11
- } );
12
- window.addEventListener( 'load', function onLoad() {
13
-
14
- MatchHeight.update();
15
- window.removeEventListener( 'load', onLoad );
16
-
17
- } );
18
-
19
- window.addEventListener( 'resize', throttledUpdate );
20
-
21
- export default MatchHeight;